版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 弱電設(shè)備出租合同范例
- 工程型材購(gòu)銷(xiāo)合同范例
- 大興機(jī)場(chǎng)商貿(mào)合同范例
- 小型裝修施工合同模板
- 工程竣工審計(jì)合同范例
- 儀器購(gòu)買(mǎi)培訓(xùn)合同范例
- 戀愛(ài)贈(zèng)與車(chē)子合同范例
- 2024年上??瓦\(yùn)從業(yè)資格證考試模擬
- 2024年??赾1客運(yùn)資格證模擬考試題
- 2024年長(zhǎng)治道路客運(yùn)從業(yè)資格證考試模擬試題
- JIS G4304-2021 熱軋不銹鋼板材、薄板材和帶材
- 鋼筋直螺紋連接課件PPT
- 2022年中級(jí)經(jīng)濟(jì)師-人力資源管理專(zhuān)業(yè)押題模擬試卷3套及答案解析
- 小學(xué)綜合實(shí)踐活動(dòng)《認(rèn)識(shí)校園植物》優(yōu)秀PPT課件
- XRD在薄膜材料研究中應(yīng)用
- 變壓器專(zhuān)業(yè)詞匯英文翻譯
- 藏傳佛教英文詞匯
- 鐵路雜費(fèi)收費(fèi)項(xiàng)目和標(biāo)準(zhǔn)
- 定量訂貨與定期訂貨習(xí)題練習(xí).
- 某溝塘清淤回填施工專(zhuān)項(xiàng)方案
- 廉政風(fēng)險(xiǎn)防控臺(tái)賬
評(píng)論
0/150
提交評(píng)論