ART神经网络Word文档格式.docx
《ART神经网络Word文档格式.docx》由会员分享,可在线阅读,更多相关《ART神经网络Word文档格式.docx(8页珍藏版)》请在冰豆网上搜索。
![ART神经网络Word文档格式.docx](https://file1.bdocx.com/fileroot1/2022-11/28/b9f5d226-652c-4e80-b60e-e794f69b9872/b9f5d226-652c-4e80-b60e-e794f69b98721.gif)
private:
doubleWb[MAXCNEURONS][MAXRNEURONS];
//Bottomupweightmatrix
int
Wt[MAXRNEURONS][MAXCNEURONS];
//Topdown
weightmatrix
InData[MAXPATTERNS][MAXCNEURONS];
//Arrayofinputvectorstobe
//presentedtothenetwork
NumPatterns;
//Numberofinputpatterns
doubleVigilThresh;
//Vigilencethresholdvalue
doubleL;
//ARTtrainingconst(seetext)
M;
//#ofneuronsinC-layer
N;
//#ofneuronsinR-layer
XVect[MAXCNEURONS];
//CurrentinvectatC-layer.
CVect[MAXCNEURONS];
//OutputvectorfromC-layer
BestNeuron;
//CurrentbestR-layerNeuron
Reset;
//Activewhenvigilencehas
//
disabledsomeone
RVect[MAXCNEURONS];
//OutputvectorfromR-layer
PVect[MAXCNEURONS];
//WeightedOutputvectorfromR-layer
Disabled[MAXRNEURONS];
//Resetswayofdisqualifyingneurons
Trained[MAXRNEURONS];
//ToidentifyallocatedR-Neurons
void
ClearPvect();
ClearDisabled();
RecoPhase();
//Recognitionphase
CompPhase();
//Comparisonphase
SearchPhase();
//SearchPhase
RunCompLayer();
//Calccomparisonlayerby2/3rule
RunRecoLayer();
//CalcrecognitionlayersR-vect
Rvect2Pvect(int);
//Distributewinnersresult
Gain1();
//Complayergain
Gain2();
//Recolayergain
doubleVigilence();
//Calcvigilencemetric
InitWeights();
//Initializeweights
Train();
//Weightadjustmentisdonehere
public:
ARTNET(void);
//Constructor/initializations
LoadInVects(char*Fname);
//loadalldatavectors
Run(inti);
//Runnetw/ithpattern
ShowWeights();
//displaytopdownand
bottomupweights
ShowInVect();
//Displaycurrentinputpattern
ShowOutVect();
//P-vectorfromRecolayer(seetext)
};
//------------------------------------------------------------------------
//METHODDEFINITIONS
ARTNET:
:
ARTNET(){
inti;
L=2.0;
N=MAXRNEURONS;
for(i=0;
i<
N;
i++){
//Setallneuronstountrainedandenabled
Trained[i]=0;
Disabled[i]=0;
}/*endfor*/
}
int
ARTNET:
LoadInVects(char*Fname){
FILE
*PFILE;
i,j,k;
PFILE=fopen(Fname,"
r"
);
if(PFILE==NULL){
printf("
\nUnabletoopenfile%s\n"
Fname);
exit(0);
}
fscanf(PFILE,"
%d"
&
NumPatterns);
//Howmanypatterns
M);
//getwidthofinputvector
%lf"
VigilThresh);
NumPatterns;
i++){
for(j=0;
j<
M;
j++){
fscanf(PFILE,"
k);
//Readallthepatterndataand...
InData[i][j]=k;
...saveitforlater.
InitWeights();
returnNumPatterns;
intARTNET:
Gain2(){
inti;
if(XVect[i]==1)
return1;
voidARTNET:
Rvect2Pvect(intbest){
PVect[i]=Wt[best][i];
Gain1(){
inti,G;
G=Gain2();
if(RVect[i]==1)
return0;
returnG;
RunCompLayer(){
inti,x;
x=XVect[i]+Gain1()+PVect[i];
if(x>
=2){
CVect[i]=1;
else{
CVect[i]=0;
}/*endif*/
double
Vigilence(){
doubleS,K,D;
//count#of1'
sinp-vect&
x-vect
K=0.0;
D=0.0;
K+=CVect[i];
D+=XVect[i];
S=K/D;
returnS;
RunRecoLayer(){
inti,j,k;
doubleNet[MAXRNEURONS];
intBestNeruon=-1;
doubleNetMax=-1;
//TraverseallR-layerNeurons
Net[i]=0;
j++){
//Dotheproduct
Net[i]+=Wb[i][j]*CVect[j];
if((Net[i]>
NetMax)&
&
(Disabled[i]==0)){//disabledneuronscantwin!
BestNeuron=i;
NetMax=Net[i];
for(k=0;
k<
k++){
if(k==BestNeuron)
RVect[k]=1;
//Winnergets1
else
RVect[k]=0;
//lateralinhibitionkillstherest
void
RecoPhase(){
//FirstforceallR-layeroutputstozero
RVect[i]=0;
PVect[i]=0;
//NowCalculateC-layeroutputs
RunCompLayer();
//C-vectornowhastheresult
RunRecoLayer();
//Calcdotprodw/botupweight&
C
Rvect2Pvect(BestNeuron);
CompPhase(){
doubleS;
//Cvector<
-difbetween
x&
p
S=Vigilence();
if(S<
VigilThresh){
Reset=1;
RVect[BestNeuron]=0;
Disabled[BestNeuron]=1;
else
Reset=0;
SearchPhase(){
while(Reset){
//Xvect->
Cvect
//Findanewwinnerwithprevwinnersdisabled
Rvect2Pvect(BestNeuron);
//newpvectbasedonnewwinner
S=Vigilence();
//calcvigilenceforthenewguy
VigilThresh){
//checkifhedidok
ifnotdisablehimtoo
//CurrentBestneuronisagoodwinner...Trainhim
}/*endwhile*/
if(BestNeuron!
=-1){
}
else{
//Failedtoallocateaneuronforcurrentpattern.
OutofneuronsinF2\n"
ClearDisabled();
ClearDisabled(){
ClearPvect(){
Train(){
inti,z=0;
z+=CVect[i];
Wb[BestNeuron][i]=L*CVect[i]/(L-1+z);
Wt[BestNeuron][i]=CVect[i];
Trained[BestNeuron]=1;
Run(inttp){
inti,j;
ClearPvect();
XVect[i]=InData[tp][i];
RecoPhase();
CompPhase();
SearchPhase();
InitWeights(){
doubleb;
//fromR-neuroni
//toC-neuronj
Wt[i][j]=1;
//Allinit'
dto1
b=L/(L-1+M);
//fromC-neuroni
//toR-neuronj
Wb[i][j]=b;
ShowWeights(){
printf("
\nTopDownweights:
\n"
if(Trained[i]==1){
%d"
Wt[i][j]);
\nBottomupweights:
%f"
Wb[i][j]);
ShowInVect(){
BESTNEURON:
%d\nIN:
"
BestNeuron);
XVect[i]);
ShowOutVect(){
OUT:
CVect[i]);
ARTNET
ART;
/******************************************************************************
MAIN
******************************************************************************/
intmain(intargc,char*argv[])
intTstSetSize;
if(argc>
1){