/* ****************************************************************** * HISTORY * 15-Oct-94 Jeff Shufelt (js), Carnegie Mellon University * Prepared for 15-681, Fall 1994. * ****************************************************************** */ #ifndef _BACKPROP_H_ #define _BACKPROP_H_ #define BIGRND 0x7fffffff /*** The neural network data structure. The network is assumed to be a fully-connected feedforward three-layer network or four-layer network with a recurrent context layer between the input an hidden layers. Unit 0 in each layer of units is the threshold unit; this means that the remaining units are indexed from 1 to n, inclusive. ***/ typedef struct { int input_n; /* number of input units */ int context_n; /* number of context units */ int hidden_n; /* number of hidden units */ int output_n; /* number of output units */ double *input_units; /* the input units */ double *context_units; /* the context units */ double *hidden_units; /* the hidden units */ double *output_units; /* the output units */ double *context_delta; /* storage for context unit error */ double *hidden_delta; /* storage for hidden unit error */ double *output_delta; /* storage for output unit error */ double *target; /* storage for target vector */ double **input_weights; /* weights from input to hidden layer */ double **context_weights; /* weights from context to hidden layer */ double **hidden_weights; /* weights from hidden to output layer */ /*** The next three are for momentum ***/ double **input_prev_weights; /* previous change on input to hidden wgt */ double **context_prev_weights;/* previous change on context to hidden wgt */ double **hidden_prev_weights; /* previous change on hidden to output wgt */ } BPNN; /*** User-level functions ***/ void fastcopy(char *, double *, int); void fastcopy(double *, double *, int); void fastcopy(double *,char *,unsigned long); void bpnn_initialize(unsigned int); BPNN *bpnn_internal_create(int,int,int,int); BPNN *bpnn_create(int,int,int); BPNN *bpnn_create(int,int,int,int); //with recurrent context layer void bpnn_free(BPNN *); void bpnn_train(BPNN *,double,double,double *,double *); void bpnn_trainrec(BPNN *,double,double,double *,double *,double *); void bpnn_feedforward(BPNN *); void bpnn_adjust_weights(double *,int,double *,int,double **,double **,double,double); void bpnn_context_error(double *,int,double *,int,double **,double *,double *); void bpnn_hidden_error(double *,int,double *,int,double **,double *,double *); void bpnn_output_error(double *,double *,double *,int,double *); void bpnn_layerforward(double *,double *,double **,int,int); void bpnn_layerrecforward(double *,double *,double **,int,int); void bpnn_save(BPNN *,char *); BPNN *bpnn_read(char *); double drnd(); double dpn1(); double squash(double); double *alloc_1d_dbl(int); double **alloc_2d_dbl(int,int); void bpnn_randomize_weights(double**,int,int); void bpnn_zero_weights(double **,int,int); #endif