資源描述:
《Bp網(wǎng)絡(luò)算法源代碼.docx》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、機(jī)器學(xué)習(xí)作業(yè)(BP神經(jīng)網(wǎng)絡(luò))胡雷3#include#include#include#include#defineIN2//輸入向量維數(shù)#defineOUT2//輸出向量維數(shù)#defineNUM20//樣本數(shù)量#defineLoop_MAX//最大循環(huán)次數(shù)#definedot_MAX20//最大結(jié)點(diǎn)個(gè)數(shù)typedefstruct//bp人工神經(jīng)網(wǎng)絡(luò)結(jié)構(gòu){intdot;//隱層節(jié)點(diǎn)數(shù)doublev[IN][dot_MAX];//輸入層權(quán)矩陣doubleu[dot_MAX][dot_MAX];//隱藏層權(quán)
2、矩陣doublew[dot_MAX][OUT];//輸出層權(quán)矩陣doublerate;//學(xué)習(xí)率doubleerror;//允許誤差限}bp_net;doublev[IN][3]={0.5,0.4,0.1,0.2,0.6,0.2};//題目要求的權(quán)矩陣doubleu[3][3]={0.10,0.55,0.35,0.20,0.45,0.35,0.25,0.15,0.60};//同上doublew[3][OUT]={0.30,0.35,0.35,0.25,0.45,0.30};//同上doublefnet(doublenet)//Sigmoid函數(shù){return1/(1+
3、exp(-net));}voidInitialize_Bp(bp_net*bp)//初始化bp網(wǎng)絡(luò){printf("請輸入隱層結(jié)點(diǎn)數(shù):");scanf("%d",&(*bp).dot);printf("請輸入學(xué)習(xí)率:");scanf("%lf",&(*bp).rate);printf("請輸入允許誤差限:");scanf("%lf",&(*bp).error);inti,j,flag;start:printf("請選擇權(quán)矩陣輸入形式:1、隨機(jī)產(chǎn)生權(quán)矩陣2、手動(dòng)輸入權(quán)矩陣3、載入題目要求權(quán)矩陣");scanf("%d",&flag);if(f
4、lag==1){srand((unsigned)time(NULL));//隨機(jī)函數(shù)產(chǎn)生隨機(jī)權(quán)矩陣for(i=0;i5、e)(RAND_MAX);}elseif(flag==2){printf("輸入權(quán)矩陣:");for(i=0;i6、(*bp).w[i][j]);}elseif(flag==3){for(i=0;i7、