⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nntest1.c

📁 基于MATLAB完成的神经网络源程序 大家
💻 C
字号:
/*--------------------------------------------------------------------------*
 * Gregory Stevens                                                   7/1/93 *
 *                               NNTEST1.C                                  *
 *                                                                          *
 *   This is a test file to test the nn*.c series with back-propagation.    *
 * This file demonstrates learning of a linear function using 1 input, 1    *
 * output net, with the output node having a linear activation function.    *
 * For this file, the following parameters in the following files should be *
 * set:                                                                     *
 *      NNPARAMS.C : INPUT_LAYER_SIZE   1                                   *
 *                   OUTPUT_LAYER_SIZE  1                                   *
 *                   NUM_HIDDEN_LAYERS  0                                   *
 *                                                                          *
 *      NNINPUTS.C : NUM_PATTERNS  5                                        *
 *                                                                          *
 *      NNSTRUCT.C : InitNet()  ...should set output nodes as linear...     *
 *                                                                          *
 *      NNBKPROP.C : EPSILON 0.25  (recommended...this is what I used)      *
 *                                                                          *
 *  Everything else can be left unchanged.  The input files should each     *
 * consist of five real numbers, where they are in matching order of input  *
 * and desired output.  The output of this file simply lists the input,     *
 * weight, output, threshhold, desired output.  It pauses at each training  *
 * epoch.                                                                   *
 *                                                                          *
 *  NOTE: This file does not test the use of testing novel inputs after     *
 * training, and thus does not test InitInPatterns(1) [with parameter 1].   *
 * See nnsim1.c for that.                                                   *
 *--------------------------------------------------------------------------*/
#include "nnbkprop.c"                /* to chain it to the nn*.c utilities  */
#include <math.h>                    /* for the exp() for logistic units    */

#define NUM_ITS 10                   /* iterations before it stops          */

/*  MAIN PROGRAM  */

void main()
{
  int Pattern;                         /* for looping through patterns   */
  int Layer;                           /* for looping through layers     */
  int LCV;                             /* for looping training sets      */
  NNETtype Net;
  PATTERNtype InPatterns, OutPattern;

  Net = InitNet( NUMNODES );            /* initializes the network        */
  InPatterns = InitInPatterns(0);       /* loads input patterns from file */
  OutPattern = InitOutPatterns();       /* loads output patterns from file*/

  for (LCV=0; (LCV < NUM_ITS); ++LCV)   /* loop through a training set    */
    {
      for (Pattern=0; (Pattern<NUM_PATTERNS); ++Pattern)
         {
            /* FORWARD PROPAGATION */
            Net = UpDateInputAct( InPatterns, Pattern, Net );
            for (Layer=1; (Layer<NUMLAYERS); ++Layer)
              {
                 Net = UpDateLayerAct( Net, Layer );
              }

            /* OUTPUT PRINTS */
            printf( "Input: %4.2f  ", Net.unit[0][0].state );
            printf( "Weight:%4.2f  ", Net.unit[1][0].weights[0]);
            printf( "Output:%4.2f  ", Net.unit[1][0].state  );
            printf( "Thresh:%4.2f  ", Net.unit[1][0].thresh );
            printf( "Goal: %4.2f\n",  OutPattern.p[Pattern][0] );

            /* BACKWARD PROPAGATION */
            Net = UpDateWeightandThresh( Net, OutPattern, Pattern );
         }
      getc(stdin);           /* pause inbetween training epochs */
      printf( "\n" );    /* skip a line  */
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -