ART神经网络.docx
- 文档编号:4279585
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:8
- 大小:17.07KB
ART神经网络.docx
《ART神经网络.docx》由会员分享,可在线阅读,更多相关《ART神经网络.docx(8页珍藏版)》请在冰豆网上搜索。
ART神经网络
自适应共振理论ART(Adaptive Resonance Theory)模型是美国Boston大学的S.Grossberg和A.Carpenet在1976年提出的。
ART是一种自组织神经网络结构,是无教师的学习网络。
当在神经网络和环境有交互作用时,对环境信息的编码会自发地在神经网中产生,则认为神经网络在进行自组织活动。
ART就是这样一种能自组织地产生对环境认识编码的神经网络理论模型。
ART神经网络源程序:
/****************************************************************************
* *
* ADAPTIVERESONANCETHEORY(ART) NETWORK *
* *
*****************************************************************************/
#include
#include
#include
#include
#include
//DEFINES
#defineMAXCNEURONS75 //MAXCOMPARISONLAYERNEURONS
#defineMAXRNEURONS30 //MAXRECOGNITIONLAYERNEURONS
#defineMAXPATTERNS30 //MAXNUMBEROFPATTERNSINATRAININGSET
#defineVERBOSE 1
classARTNET
{
private:
doubleWb[MAXCNEURONS][MAXRNEURONS]; //Bottomupweightmatrix
int Wt[MAXRNEURONS][MAXCNEURONS]; //Topdown weightmatrix
int InData[MAXPATTERNS][MAXCNEURONS];//Arrayofinputvectorstobe
//presentedtothenetwork
int NumPatterns; //Numberofinputpatterns
doubleVigilThresh; //Vigilencethresholdvalue
doubleL; //ARTtrainingconst(seetext)
int M; //#ofneuronsinC-layer
int N; //#ofneuronsinR-layer
int XVect[MAXCNEURONS]; //CurrentinvectatC-layer.
int CVect[MAXCNEURONS]; //OutputvectorfromC-layer
int BestNeuron; //CurrentbestR-layerNeuron
int Reset; //Activewhenvigilencehas
// disabledsomeone
int RVect[MAXCNEURONS]; //OutputvectorfromR-layer
int PVect[MAXCNEURONS]; //WeightedOutputvectorfromR-layer
int Disabled[MAXRNEURONS]; //Resetswayofdisqualifyingneurons
int Trained[MAXRNEURONS]; //ToidentifyallocatedR-Neurons
void ClearPvect();
void ClearDisabled();
void RecoPhase(); //Recognitionphase
void CompPhase(); //Comparisonphase
void SearchPhase(); //SearchPhase
void RunCompLayer(); //Calccomparisonlayerby2/3rule
void RunRecoLayer(); //CalcrecognitionlayersR-vect
void Rvect2Pvect(int); //Distributewinnersresult
int Gain1(); //Complayergain
int Gain2(); //Recolayergain
doubleVigilence(); //Calcvigilencemetric
void InitWeights(); //Initializeweights
void Train(); //Weightadjustmentisdonehere
public:
ARTNET(void); //Constructor/initializations
int LoadInVects(char*Fname); //loadalldatavectors
void Run(inti); //Runnetw/ithpattern
void ShowWeights(); //displaytopdownand
// bottomupweights
void ShowInVect(); //Displaycurrentinputpattern
void ShowOutVect(); //P-vectorfromRecolayer(seetext)
};
//------------------------------------------------------------------------
//METHODDEFINITIONS
ARTNET:
:
ARTNET(){
inti;
L=2.0;
N=MAXRNEURONS;
for(i=0;i Trained[i]=0; Disabled[i]=0; }/*endfor*/ } int ARTNET: : LoadInVects(char*Fname){ FILE *PFILE; int i,j,k; PFILE=fopen(Fname,"r"); if(PFILE==NULL){ printf("\nUnabletoopenfile%s\n",Fname); exit(0); } fscanf(PFILE,"%d",&NumPatterns); //Howmanypatterns fscanf(PFILE,"%d",&M); //getwidthofinputvector fscanf(PFILE,"%lf",&VigilThresh); for(i=0;i for(j=0;j fscanf(PFILE,"%d",&k); //Readallthepatterndataand... InData[i][j]=k; // ...saveitforlater. }/*endfor*/ }/*endfor*/ InitWeights(); returnNumPatterns; } intARTNET: : Gain2(){ inti; for(i=0;i if(XVect[i]==1) return1; }/*endfor*/ } voidARTNET: : Rvect2Pvect(intbest){ inti; for(i=0;i PVect[i]=Wt[best][i]; }/*endfor*/ } intARTNET: : Gain1(){ inti,G; G=Gain2(); for(i=0;i if(RVect[i]==1) return0; }/*endfor*/ returnG; } voidARTNET: : RunCompLayer(){ inti,x; for(i=0;i x=XVect[i]+Gain1()+PVect[i]; if(x>=2){ CVect[i]=1; } else{ CVect[i]=0; }/*endif*/ }/*endfor*/ } double ARTNET: : Vigilence(){ inti; doubleS,K,D; //count#of1'sinp-vect&x-vect K=0.0; D=0.0; for(i=0;i K+=CVect[i]; D+=XVect[i]; }/*endfor*/ S=K/D; returnS; } voidARTNET: : RunRecoLayer(){ inti,j,k; doubleNet[MAXRNEURONS]; intBestNeruon=-1; doubleNetMax=-1; for(i=0;i Net[i]=0; for(j=0;j Net[i]+=Wb[i][j]*CVect[j]; }/*endfor*/ if((Net[i]>NetMax)&&(Disabled[i]==0)){//disabledneuronscantwin! BestNeuron=i; NetMax=Net[i]; } }/*endfor*/ for(k=0;k if(k==BestNeuron) RVect[k]=1; //Winnergets1 else RVect[k]=0; //lateralinhibitionkillstherest }/*endfor*/ } void ARTNET: : RecoPhase(){ inti; //FirstforceallR-layeroutputstozero for(i=0;i RVect[i]=0; }/*endfor*/ for(i=0;i PVect[i]=0; }/*endfor*/ //NowCalculateC-layeroutputs RunCompLayer(); //C-vectornowhastheresult RunRecoLayer(); //Calcdotprodw/botupweight&C Rvect2Pvect(BestNeuron); } void ARTNET: : CompPhase(){ doubleS; RunCompLayer(); //Cvector<-difbetween x&p S=Vigilence(); if(S Reset=1; RVect[BestNeuron]=0; Disabled[BestNeuron]=1; } else Reset=0; } void ARTNET: : SearchPhase(){ doubleS; while(Reset){ ClearPvect(); RunCompLayer(); //Xvect->Cvect RunRecoLayer(); //Findanewwinnerwithprevwinnersdisabled Rvect2Pvect(BestNeuron);//newpvectbasedonnewwinner S=Vigilence(); //calcvigilenceforthenewguy if(S Reset=1; // ifnotdisablehimtoo RVect[BestNeuron]=0; Disabled[BestNeuron]=1; } else Reset=0; //CurrentBestneuronisagoodwinner...Trainhim }/*endwhile*/ if(BestNeuron! =-1){ Train(); } else{ //Failedtoallocateaneuronforcurrentpattern. printf("OutofneuronsinF2\n"); }/*endif*/ ClearDisabled(); } voidARTNET: : ClearDisabled(){ inti; for(i=0;i Disabled[i]=0; }/*endfor*/ } voidARTNET: : ClearPvect(){ inti; for(i=0;i PVect[i]=0; }/*endfor*/ } voidARTNET: : Train(){ inti,z=0; for(i=0;i z+=CVect[i]; }/*endfor*/ for(i=0;i Wb[BestNeuron][i]=L*CVect[i]/(L-1+z); Wt[BestNeuron][i]=CVect[i]; }/*endfor*/ Trained[BestNeuron]=1; } voidARTNET: : Run(inttp){ inti,j; ClearPvect(); for(i=0;i XVect[i]=InData[tp][i]; }/*endfor*/ RecoPhase(); CompPhase(); SearchPhase(); } void ARTNET: : InitWeights(){ //Initializeweights inti,j; doubleb; for(i=0;i for(j=0;j Wt[i][j]=1; //Allinit'dto1 }/*endfor*/ }/*endfor*/ b=L/(L-1+M); for(i=0;i for(j=0;j Wb[i][j]=b; }/*endfor*/ }/*endfor*/ } voidARTNET: : ShowWeights(){ inti,j; printf("\nTopDownweights: \n"); for(i=0;i if(Trained[i]==1){ for(j=0;j printf("%d",Wt[i][j]); }/*endfor*/ printf("\n"); }/*endif*/ }/*endfor*/ printf("\nBottomupweights: \n"); for(i=0;i if(Trained[i]==1){ for(j=0;j printf("%f",Wb[i][j]); }/*endfor*/ printf("\n"); }/*endif*/ }/*endfor*/ } voidARTNET: : ShowInVect(){ inti; printf("BESTNEURON: %d\nIN: ",BestNeuron); for(i=0;i printf("%d",XVect[i]); }/*endfor*/ printf("\n"); } voidARTNET: : ShowOutVect(){ inti; printf("OUT: "); for(i=0;i printf("%d",CVect[i]); }/*endfor*/ printf("\n"); } //------------------------------------------------------------------------ ARTNET ART; /****************************************************************************** * MAIN * ******************************************************************************/ intmain(intargc,char*argv[]) { intTstSetSize; inti; if(argc>1){
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ART 神经网络