1、private: double WbMAXCNEURONSMAXRNEURONS; / Bottom up weight matrix int WtMAXRNEURONSMAXCNEURONS; / Top down weight matrix InDataMAXPATTERNSMAXCNEURONS;/ Array of input vectors to be / presented to the network NumPatterns; / Number of input patterns double VigilThresh; / Vigilence threshold value do
2、uble L; / ART training const (see text) M; / # of neurons in C-layer N; / # of neurons in R-layer XVectMAXCNEURONS; / Current in vect at C-layer. CVectMAXCNEURONS; / Output vector from C-layer BestNeuron; / Current best R-layer Neuron Reset; / Active when vigilence has / disabled someone RVectMAXCNE
3、URONS; / Output vector from R-layer PVectMAXCNEURONS; / WeightedOutput vector from R-layer DisabledMAXRNEURONS; / Resets way of disqualifying neurons TrainedMAXRNEURONS; / To identify allocated R-Neurons void ClearPvect(); ClearDisabled(); RecoPhase(); / Recognition phase CompPhase(); / Comparison p
4、hase SearchPhase(); / Search Phase RunCompLayer(); / Calc comparison layer by 2/3 rule RunRecoLayer(); / Calc recognition layers R-vect Rvect2Pvect(int); / Distribute winners result Gain1(); / Comp layer gain Gain2(); / Reco layer gain double Vigilence(); / Calc vigilence metric InitWeights(); / Ini
5、tialize weights Train(); / Weight adjustment is done herepublic: ARTNET(void); / Constructor/initializations LoadInVects(char *Fname); / load all data vectors Run(int i); / Run net w/ ith pattern ShowWeights(); / display top down and bottom up weights ShowInVect(); / Display current input pattern Sh
6、owOutVect(); / P-vector from Reco layer(see text);/ -/ METHOD DEFINITIONSARTNET:ARTNET()int i;L=2.0;N=MAXRNEURONS;for (i=0; iN; i+) /Set all neurons to untrained and enabled Trainedi=0; Disabledi=0; /* endfor */int ARTNET:LoadInVects(char *Fname)FILE *PFILE; i,j,k;PFILE = fopen(Fname,r); if (PFILE=N
7、ULL) printf(nUnable to open file %sn,Fname); exit(0); fscanf(PFILE,%d,&NumPatterns); /How many patternsM); /get width of input vector%lfVigilThresh);NumPatterns; i+) for (j=0; j=2) CVecti=1; else CVecti=0; /* endif */doubleVigilence() double S,K,D;/ count # of 1s in p-vect & x-vectK=0.0;D=0.0; K+=CV
8、ecti; D+=XVecti;S=K/D;return S;RunRecoLayer() int i,j,k; double NetMAXRNEURONS; int BestNeruon=-1; double NetMax=-1; /Traverse all R-layer Neurons Neti=0; j+) / Do the product Neti +=Wbij*CVectj; if (NetiNetMax) & (Disabledi=0) /disabled neurons cant win! BestNeuron=i; NetMax=Neti;for (k=0; k k+) if
9、 (k=BestNeuron) RVectk=1; / Winner gets 1 else RVectk=0; / lateral inhibition kills the restvoidRecoPhase()/First force all R-layer outputs to zero RVecti=0; PVecti=0;/Now Calculate C-layer outputsRunCompLayer(); /C-vector now has the resultRunRecoLayer(); /Calc dot prod w/ bot up weight & CRvect2Pv
10、ect(BestNeuron);CompPhase() double S; /Cvector-dif between x & pS=Vigilence();if (S Cvect /Find a new winner with prev winners disabled Rvect2Pvect(BestNeuron); /new pvect based on new winner S=Vigilence(); /calc vigilence for the new guyVigilThresh) /check if he did ok if not disable him too /Curre
11、nt Best neuron is a good winner.Train him /* endwhile */if (BestNeuron!=-1) else /Failed to allocate a neuron for current pattern.Out of neurons in F2nClearDisabled();ClearDisabled() ClearPvect() Train() int i,z=0; z+=CVecti; WbBestNeuroni=L*CVecti/(L-1+z); WtBestNeuroni=CVecti;TrainedBestNeuron=1;R
12、un(int tp) int i,j;ClearPvect(); XVecti=InDatatpi;RecoPhase();CompPhase();SearchPhase();InitWeights() double b; / from R-neuron i / to C-neuron j Wtij= 1; / All initd to 1b=L/(L-1+M); / from C-neuron i / to R-neuron j Wbij= b;ShowWeights()printf(nTop Down weights:n if(Trainedi=1)%d ,Wtij);nBottom up weights:%f ,Wbij);ShowInVect()BEST NEURON:%dnIN: ,BestNeuron);,XVecti);ShowOutVect()OUT:,CVecti);ARTNET ART;/* MAIN*/int main(int argc, char *argv) int TstSetSize;if (argc1)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1