資源描述:
《bp神經(jīng)網(wǎng)絡詳細步驟c實現(xiàn).doc》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在工程資料-天天文庫。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem;usingSystem.IO;usingSystem.Text;namespaceBpANNet{//////BpNet的摘要說明。///publicclassBpNet{publicintinNum;//輸入節(jié)點數(shù)inthideNum;//隱層節(jié)點數(shù)publicintoutNum;//輸出層節(jié)點數(shù)publicints
2、ampleNum;//樣本總數(shù)RandomR;double[]x;//輸入節(jié)點的輸入數(shù)據(jù)double[]x1;//隱層節(jié)點的輸出double[]x2;//輸出節(jié)點的輸出double[]o1;//隱層的輸入double[]o2;//輸出層的輸入publicdouble[,]w;//權(quán)值矩陣w,這是輸入層與隱藏層之間的權(quán)值矩陣publicdouble[,]v;//權(quán)值矩陣V,這是隱藏層與輸出層之間的權(quán)值矩陣publicdouble[,]dw;//權(quán)值矩陣wpublicdouble[,]dv;//權(quán)值矩陣Vpublicdoublerate
3、;//學習率publicdouble[]b1;//隱層閾值矩陣publicdouble[]b2;//輸出層閾值矩陣publicdouble[]db1;//隱層閾值矩陣publicdouble[]db2;//輸出層閾值矩陣double[]pp;//隱藏層的誤差double[]qq;//輸出層的誤差double[]yd;//輸出層的教師數(shù)據(jù),所謂教師數(shù)據(jù)就是實際數(shù)據(jù)而已!publicdoublee;//均方誤差doublein_rate;//歸一化比例系數(shù)//用于確定隱藏層的神經(jīng)細胞數(shù)publicintcomputeHideNum(in
4、tm,intn){doubles=Math.Sqrt(0.43*m*n+0.12*n*n+2.54*m+0.77*n+0.35)+0.51;intss=Convert.ToInt32(s);return((s-(double)ss)>0.5)?ss+1:ss;}publicBpNet(double[,]p,double[,]t){//構(gòu)造函數(shù)邏輯R=newRandom();this.inNum=p.GetLength(1);this.outNum=t.GetLength(1);this.hideNum=computeHideNum(
5、inNum,outNum);//this.hideNum=18;this.sampleNum=p.GetLength(0);Console.WriteLine("輸入節(jié)點數(shù)目:"+inNum);Console.WriteLine("隱層節(jié)點數(shù)目:"+hideNum);Console.WriteLine("輸出層節(jié)點數(shù)目:"+outNum);Console.ReadLine();//將這些矩陣規(guī)定好矩陣大小x=newdouble[inNum];x1=newdouble[hideNum];x2=newdouble[outNum];o1=
6、newdouble[hideNum];o2=newdouble[outNum];w=newdouble[inNum,hideNum];//權(quán)值矩陣w,這是輸入層與隱藏層之間的權(quán)值矩陣v=newdouble[hideNum,outNum];dw=newdouble[inNum,hideNum];dv=newdouble[hideNum,outNum];//閾值b1=newdouble[hideNum];b2=newdouble[outNum];db1=newdouble[hideNum];db2=newdouble[outNum];/
7、/誤差pp=newdouble[hideNum];//隱藏層的誤差qq=newdouble[outNum];//輸出層的誤差yd=newdouble[outNum];//輸出層的教師數(shù)據(jù)//初始化wfor(inti=0;i8、+){v[i,j]=(R.NextDouble()*2-1.0)/2;}}rate=0.8;e=0.0;in_rate=1.0;?}//訓練函數(shù)publicvoidtrain(double[,]p,double[,]t){e=0.0;