




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、'* ADAPTIVE RESONANCE THEORY (ARTN) ETWORK*#include <stdio.h>#include <stdlib.h> #include <string.h> #include <conio.h> #include <math.h>/ DEFINES#define MAXCNEURONS 75/ MAX COMPARISON LAYER NEURONS#define MAXRNEURONS 30/ MAX RECOGNITION LAYER NEURONS#define MAXPATT
2、ERNS 30#define VERBOSE 1/ MAX NUMBER OF PATTERNS IN A TRAINING SETclass ARTNET private:double WbMAXCNEURONSMAXRNEURONS; / Bottom up weight matrixintWtMAXRNEURONSMAXCNEURONS; / Top down weight matrixintInDataMAXPATTERNSMAXCNEURONS;/ Array of input vectors to be/ presented to the networkintNumPatterns
3、;/ Number of input patternsdouble VigilThresh;/ Vigilence threshold valuedouble L;/ ART training const (see text)intM;/ # of neurons in C-layerintN;/ # of neurons in R-layerintXVectMAXCNEURONS;/ Current in vect at C-CVectMAXCNEURONS;/ Output vector from C-layerintBestNeuron;/ Current best R
4、-layer NeuronintReset;/ Active when vigilence has/ disabled someoneintRVectMAXCNEURONS;/ Output vector from R-layerintPVectMAXCNEURONS;/ WeightedOutput vector from R-layerintDisabledMAXRNEURONS;/ Resets way of disqualifying neuronsintTrainedMAXRNEURONS;/ To identify allocated R-NeuronsvoidClearPvect
5、();voidClearDisabled();voidRecoPhase();/ Recognition phasevoidCompPhase();/ Comparison phasevoidSearchPhase();/ Search PhasevoidRunCompLayer();/ Calc comparison layer by 2/3 rulevoidRunRecoLayer();/ Calc recognition layers R-vectvoidRvect2Pvect(int);/ Distribute winners resultintGain1();/ Comp layer
6、 gainintGain2();/ Reco layer gaindouble Vigilence();/ Calc vigilence metricvoidInitWeights();/ Initialize weightsvoidTrain();/ Weight adjustment is done herepublic:ARTNET(void);/ Constructor/initializationsintLoadInVects(char *Fname);/ load all data vectorsvoidRun(int i);/ Run net w/ ith patternvoid
7、ShowWeights();/ display top down and/ bottom up weightsvoidShowInVect();/ Display current input patternvoidShowOutVect();/ P-vector from Reco layer(see text);/ / METHOD DEFINITIONSARTNET:ARTNET()int i;L=2.0;N=MAXRNEURONS;for (i=0; i<N; i+) /Set all neurons to untrained and enabledTrainedi=0;Disab
8、ledi=0; /* endfor */int ARTNET:LoadInVects(char *Fname)FILE *PFILE;int i,j,k;PFILE = fopen(Fname,"r");if (PFILE=NULL) printf("nUnable to open file %sn",Fname);exit(0); fscanf(PFILE,"%d",&NumPatterns); fscanf(PFILE,"%d",&M); fscanf(PFILE,"%lf"
9、,&VigilThresh); for (i=0; i<NumPatterns; i+) for (j=0; j<M; j+) fscanf(PFILE,"%d",&k);/How many patterns/get width of input vector/Read all the pattern data and.InDataij=k; /* endfor */ /* endfor */ InitWeights(); return NumPatterns; int ARTNET:Gain2() int i;for (i=0; i<M;
10、 i+) if (XVecti=1) return 1; /* endfor */ / .save it for later.void ARTNET:Rvect2Pvect(int best) int i;for (i=0; i<M; i+) PVecti= Wtbesti; /* endfor */int ARTNET:Gain1()int i,G;G=Gain2();for (i=0; i<M; i+) if (RVecti=1)return 0; /* endfor */return G;void ARTNET:RunCompLayer()int i,x;for (i=0;
11、i<M; i+) x=XVecti+Gain1()+PVecti;if (x>=2) CVecti=1;else CVecti=0; /* endif */ /* endfor */double ARTNET:Vigilence()int i;double S,K,D;/ count # of 1's in p-vect & x-vectK=0.0;D=0.0;for (i=0; i<M; i+) K+=CVecti;D+=XVecti; /* endfor */S=K/D;return S;void ARTNET:RunRecoLayer()int i,j,
12、k;double NetMAXRNEURONS;int BestNeruon=-1;double NetMax=-1;for (i=0; i<N; i+) /Traverse all R-layer NeuronsNeti=0;for (j=0; j<M; j+) / Do the productNeti +=Wbij*CVectj; /* endfor */if (Neti>NetMax) && (Disabledi=0) /disabled neurons cant win! BestNeuron=i;NetMax=Neti; /* endfor */fo
13、r (k=0; k<N; k+) if (k=BestNeuron)RVectk=1;/ Winner gets 1elseRVectk=0; / lateral inhibition kills the rest /* endfor */void ARTNET:RecoPhase()int i;/First force all R-layer outputs to zerofor (i=0; i<N; i+) RVecti=0; /* endfor */ for (i=0; i<M; i+) PVecti=0; /* endfor */Now Calculate C-lay
14、er outputsRunCompLayer(); /C-vector now has the result RunRecoLayer();/Calc dot prod w/ bot up weight & CRvect2Pvect(BestNeuron);void ARTNET:CompPhase()double S;RunCompLayer();/Cvector<-dif between x & pS=Vigilence();if (S<VigilThresh)Reset=1;RVectBestNeuron=0;DisabledBestNeuron=1;else
15、Reset=0;void ARTNET:SearchPhase() double S;while (Reset) ClearPvect();RunCompLayer(); /Xvect -> CvectRunRecoLayer();/Find a new winner with prev winners disabledRvect2Pvect(BestNeuron); /new pvect based on new winner S=Vigilence(); /calc vigilence for the new guy if (S<VigilThresh) /check if h
16、e did okReset=1; / if not disable him too RVectBestNeuron=0;DisabledBestNeuron=1;elseReset=0;/Current Best neuron is a good winner.Train him /* endwhile */if (BestNeuron!=-1) Train();else /Failed to allocate a neuron for current pattern.printf("Out of neurons in F2n"); /* endif */ClearDisa
17、bled();void ARTNET:ClearDisabled() int i;for (i=0; i<M; i+) Disabledi=0; /* endfor */void ARTNET:ClearPvect() int i;for (i=0; i<M; i+) PVecti=0; /* endfor */void ARTNET:Train()int i,z=0;for (i=0; i<M; i+) z+=CVecti; /* endfor */for (i=0; i<M; i+) WbBestNeuroni=L*CVecti/(L-1+z);WtBestNeur
18、oni=CVecti; /* endfor */TrainedBestNeuron=1;void ARTNET:Run(int tp)int i,j;ClearPvect();for (i=0; i<M; i+) XVecti=InDatatpi; /* endfor */RecoPhase();CompPhase(); SearchPhase();/ Initialize weights/ from R-neuron i/ to C-neuron j/ All init'd to 1/ from C-neuron i / to R-neuron jvoid ARTNET:Ini
19、tWeights() int i,j;double b;for (i=0; i<N; i+) for (j=0; j<M; j+) Wtij= 1; /* endfor */ /* endfor */ b=L/(L-1+M); for (i=0; i<N; i+) for (j=0; j<M; j+) Wbij= b; /* endfor */ /* endfor */void ARTNET:ShowWeights() int i,j;printf("nTop Down weights:n"); for (i=0; i<N; i+) if(Tr
20、ainedi=1) for (j=0; j<M; j+) printf("%d ",Wtij); /* endfor */ printf("n"); /* endif */ /* endfor */ printf("nBottom up weights:n"); for (i=0; i<N; i+) if(Trainedi=1) for (j=0; j<M; j+) printf("%f ",Wbij); /* endfor */ printf("n"); /* endif */ /* endfor */void ARTNET:ShowInVe
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度廠房出租合同(含金融融資支持)
- 2025年度車輛進(jìn)出口損害賠償協(xié)議范本
- 2025房產(chǎn)中介合伙人投資合作及退出機(jī)制合同
- 2025年理發(fā)、美容服務(wù)項(xiàng)目建議書
- 提高護(hù)理文書書寫規(guī)范的實(shí)施措施計(jì)劃
- 倉庫節(jié)能降耗工作的總結(jié)與展望計(jì)劃
- 新年自我反思與成長(zhǎng)計(jì)劃
- 創(chuàng)造多元環(huán)境培養(yǎng)幼兒園小班的藝術(shù)表達(dá)能力計(jì)劃
- 調(diào)整工作節(jié)奏的方法計(jì)劃
- 經(jīng)驗(yàn)教訓(xùn)與未來目標(biāo)的思考計(jì)劃
- 新鮮牛肉購銷合同模板
- 2024中科院心理咨詢師考試復(fù)習(xí)題庫(官方版)-下多選題
- 2024年內(nèi)蒙古呼和浩特市中考文科綜合試題卷(含答案)
- 流行性感冒診療方案1
- 第10課 人類社會(huì)及其發(fā)展規(guī)律-【中職專用】2024年中職思想政治《哲學(xué)與人生》金牌課件(高教版2023·基礎(chǔ)模塊)
- 燒烤店選址標(biāo)準(zhǔn)
- 中國餐飲供應(yīng)鏈行業(yè)現(xiàn)狀及趨勢(shì)(附市場(chǎng)規(guī)模、產(chǎn)業(yè)鏈及重點(diǎn)企業(yè))
- 深度學(xué)習(xí)視角下“尺規(guī)作圖”教學(xué)策略
- 溫度均勻性測(cè)試報(bào)告
- 會(huì)陰擦洗課件
- 呼吸道疾病的健康宣教
評(píng)論
0/150
提交評(píng)論