1、#pragma hdrstop #include #include const A=30.0;const B=10.0; const MAX=500; /最大训练次数 const COEF=0.0035; /网络的学习效率 const BCOEF=0.001;/网络的阀值调整效率 const ERROR=0.002 ; / 网络训练中的允许误差 const ACCURACY=0.0005;/网络要求精度 double sample414=0,0,0,0,5,1,4,19.020,5,3,3,14.150,5,5,2,14.360,5,3,3,14.150,5,3,2,15.390, 5,3,2
2、,15.390,5,5,1,19.680,5,1,2,21.060, 5,3,3,14.150,5,5,4,12.680,5,5,2,14.360, 5,1,3,19.610,5,3,4,13.650,5,5,5,12.430, 5,1,4,19.020,5,1,4,19.020,5,3,5,13.390, 5,5,4,12.680,5,1,3,19.610,5,3,2,15.390, 1,3,1,11.110,1,5,2,6.521,1,1,3,10.190,1,3,4,6.043,1,5,5,5.242,1,5,3,5.724, 1,1,4,9.766,1,3,5,5.870,1,5,4,
3、5.406, 1,1,3,10.190,1,1,5,9.545,1,3,4,6.043,1,5,3,5.724,1,1,2,11.250,1,3,1,11.110, 1,3,3,6.380,1,5,2,6.521,1,1,1,16.000, 1,3,2,7.219,1,5,3,5.724; double w41010,wc41010,b410,bc410; double o410,netin410,d410,differ;/单个样本的误差 double is; /全体样本均方差 int count,a; void netout(int m, int n);/计算网络隐含层和输出层的输出 voi
4、d calculd(int m,int n); /计算网络的反向传播误差 void calcalwc(int m,int n);/计算网络权值的调整量 void calcaulbc(int m,int n); /计算网络阀值的调整量 void changew(int m,int n); /调整网络权值 void changeb(int m,int n);/调整网络阀值 void clearwc(int m,int n);/清除网络权值变化量 wc void clearbc(int m,int n);/清除网络阀值变化量 bc void initialw(void);/初始化 NN 网络权值 W
5、void initialb(void); /初始化 NN 网络阀值 void calculdiffer(void);/计算 NN 网络单个样本误差 void calculis(void);/计算 NN 网络全体样本误差 void trainNN(void);/训练 NN 网络 /*计算 NN 网络隐含层和输出层的输出 */void netout(int m,int n) int i,j,k; /隐含层各节点的的输出 for (j=1,i=2;jERROR) calculd(8,1); calculwc(8,1); calculbc(8,1); changw(8,1); changb(8,1); netout(8,1); calculdiffer(); printf(“This is %d times training NN.n“,time); calculis(); printf(“is=%fn“,is); if (istestm; ch=getchar(); o11=test1; o12=test2; o13=test3; netout(8,1); result=o31; printf(“Final result is %f.n“,result); printf(“Still test?Yes or Non“); ch=getchar(); return 0;