📄 backprop.h
字号:
//////////////////////////////////////////////
// Fully connected multilayered feed //
// forward artificial neural network using //
// Backpropogation algorithm for training. //
//////////////////////////////////////////////
#ifndef backprop_h
#define backprop_h
#include<iostream.h>
#include<math.h>
#include<assert.h>
#include<stdio.h>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
#define filesize 500
class exfile
{
public:
char *path;
double nfx,nfy,nfz;
double interval;
double *t;
int gotit;
int incount;
int prepoints;
double *x, *y,*z;
double losex,losey,losez,height,compx,compy;
double *datax,*predatax,*traindatax;
double *datay,*predatay,*traindatay;
double *dataz,*predataz,*traindataz;
double *wantedx,*wantedy,*wantedz;
ifstream infile;
ofstream outfile;
stringstream stream;
public:
exfile(double iv,double nx,double ny,double nz,
double lx,double ly,double lz,double ht,
double cpx,double cpy);
int opendata(char *path);
void readdata(char *pr);
void writedata(char *pw);
void maketd_pd(int inc);
void collide(int tp);
void update(double nextdatax,double nextdatay,double nextdataz,
int tp);
~exfile();
};
class CBackProp{
public:
// output of each neuron
double **out;
// delta error value for each neuron
double **delta;
// vector of weights for each neuron
double ***weight;
// no of layers in net
// including input layer
int numl;
// vector of numl elements for size
// of each layer
int *lsize;
// learning rate
double beta;
// momentum parameter
double alpha;
// storage for weight-change made
// in previous epoch
double ***prevDwt;
// squashing function
double sigmoid(double in);
public:
~CBackProp();
// initializes and allocates memory
CBackProp(int nl,int *sz,double b,double a);
// backpropogates error for one set of input
void bpgt(double *in,double *tgt);
// feed forwards activations for one set of inputs
void ffwd(double *in);
// returns mean square error of the net
double mse(double *tgt) const;
// returns i'th output of the net
double Out(int i) const;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -