




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中国聚乙烯土工膜专用料行业调查报告
- 2025年中国无线音频设备行业发展监测及投资规划建议报告
- 2025年中国机夹行业市场发展前景及发展趋势与投资战略研究报告
- 2025-2030年中国摩托车大踏板行业深度研究分析报告
- 中国不锈钢波纹管补偿器市场供需现状及投资战略研究报告
- 中国热镀锌钢行业市场调查报告
- 2025年中国果蔬行业市场调查研究及投资前景预测报告
- 中国自动搬运机械手行业市场规模及未来投资方向研究报告
- 安全生产管理绩效考核方案
- 突发事件及应急预案
- 医院员工网络安全培训
- 2024年民族宗教政策法规宣传月知识竞赛考试题库(含答案)
- JT-T-480-2002交通工程土工合成材料 土工格栅
- 国企招聘中层领导笔试试题
- GB/T 30420.3-2023缝制机械术语第3部分:铺布裁剪设备术语
- 钢板折边机完整版本
- 味精(鸡精)批发合同书
- 2014科学调查体验活动培训
- 国家开放大学2023年7月期末统一试《22417客户关系管理》试题及答案-开放专科
- 水环境综合治理服务方案(技术标)
- 中国高铁发展史
评论
0/150
提交评论