資源描述:
《c語(yǔ)言版bp神經(jīng)網(wǎng)絡(luò).doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、看到學(xué)生用Matlab做了BP神經(jīng)網(wǎng)絡(luò)應(yīng)用的程序,突然想起自己在上學(xué)時(shí)寫(xiě)了個(gè)BP的C語(yǔ)言版,現(xiàn)在真不知道當(dāng)時(shí)是怎么寫(xiě)出來(lái)的,這里放上來(lái)做一個(gè)紀(jì)念。#include#include#include#include#include#include#include#defineMAXWEIGHT((float)0.3)#defineSCALEWEIGHT((float)32767)#definen
2、InputNodes4#definenHiddenNodes8#definenOutputNodes3#definenPatterns15#definenIterations5000#defineESC27#defineERRORLEVEL0.0001#defineITEMS8typedeffloat*PFLOAT;typedefPFLOATVECTOR;typedefPFLOAT*MATRIX;voidVectorAllocate(VECTOR*vector,intnCols);voidAllocateCols(
3、PFLOATmatrix[],intnRows,intnCols);voidMatrixAllocate(MATRIX*pmatrix,intnRows,intnCols);voidMatrixFree(MATRIXmatrix,intnRows);MATRIXout0;MATRIXout1;MATRIXdelta1;MATRIXdelw1;MATRIXw1;MATRIXout2;MATRIXdelta2;MATRIXdelw2;MATRIXw2;MATRIXtarget;//VECTORPatternID;voi
4、dmain(){floateta=0.15,alpha=0.075;intnReportErrors=100;floatErrorLevel=ERRORLEVEL;charMonitorError=0;floaterror;registerinth;registerinti;registerintj;intp,q;//r;FILE*fpPattern,*fpWeightsOut,*fpResults,*fpError,*fpTest;MatrixAllocate(&out0,nPatterns,nInputNode
5、s);MatrixAllocate(&out1,nPatterns,nHiddenNodes);MatrixAllocate(&out2,nPatterns,nOutputNodes);MatrixAllocate(&delta2,nPatterns,nOutputNodes);MatrixAllocate(&delw2,nOutputNodes,nHiddenNodes+1);MatrixAllocate(&w2,nOutputNodes,nHiddenNodes+1);MatrixAllocate(&delta
6、1,nPatterns,nHiddenNodes);MatrixAllocate(&delw1,nHiddenNodes,nInputNodes+1);MatrixAllocate(&w1,nHiddenNodes,nInputNodes+1);MatrixAllocate(&target,nPatterns,nOutputNodes);//VectorAllocate(&PatternID,nPatterns);//初始化權(quán)值----------------------------------srand((uns
7、igned)time(NULL));for(h=0;h8、/SCALEWEIGHT);delw2[j][h]=0.0;}//輸入訓(xùn)練樣本-------------------------------if(fpPattern=fopen("input.txt","r"))for(p=0;p