模式识别 神经网络识别MATLAB实现
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
模糊神经网络模式识别
function retstr = FnnTrain(dt,ld,tt,sp)
retstr=-1;
%%%% 输入参数赋值开始%%%%%%%%%%%%%%%%%%%%%%% % 方便调试程序用,程序调试时去掉这部分的注释
% dt=4; %学习阈值
% ld=0.05; %学习进度
% tt=10; %训练次数
% sp='data\sample.txt'; %一个点的监测数据
%%%% 输入参数赋值结束%%%%%%%%%%%%%%%%%%%%%%%% global recordDimention;
global sampleNumber;
global weightNumber;
global distanceThread;
global WW;
global learningDegree;
global epochsNumber;
distanceThread=dt;
learningDegree=ld;
traintimes=tt;
A=load(sp);
[Arow Acol]=size(A);
%样本个数
sampleNumber=Arow;
recordDimention=Acol;
disp(sampleNumber);
WW=A(1,:);
WW=[WW [1]];
weightNumber=1;
epochsNumber=1;
for jj=2:1:sampleNumber
TrainNN2(A(jj,:));
end
for jt=1:traintimes-1
for jt2=1:sampleNumber
TrainNN2(A(jj,:));
end
end
% 将训练结果写入权值文件
dlmwrite('data\w.dat',WW,'\t');
%
% 训练子函数
%
function TrainNN2(a)
global recordDimention;
global sampleNumber;
global weightNumber;
global distanceThread;
global WW;
global learningDegree;
global epochsNumber;
Ldistance=zeros(2,weightNumber);
for j1=1:weightNumber
Ldistance(2,j1)=j1;
end
% %%%%%输入输出空间的模糊分割
for j2=1:weightNumber
Lx=0;
for j3=1:recordDimention
Lx=Lx + (a(j3) - WW(j2,j3)) .* (a(j3) - WW(j2,j3));
end
Ldistance(1,j2)=sqrt(Lx);
end
% %%%%%计算模糊空间的距离
Lx1=Ldistance(1,1);
Lx2=Ldistance(2,1);
for j4=2:weightNumber
if(Ldistance(1,j4) Lx1=Ldistance(1,j4); Lx2=Ldistance(2,j4); end end % %%%%%修正模糊规则 updateW=0; nowWeight=Lx2; if(Lx1<=distanceThread) for j6=1:recordDimention WW(nowWeight,j6)=WW(nowWeight,j6) + learningDegree .* (a(j6) - WW(nowWeight,j6)); end WW(nowWeight,recordDimention+1)=WW(nowWeight,recordDimention+1)+1; updateW=1; end if( updateW==0) weightNumber=weightNumber+1; a=[a [1]]; WW=[WW;a]; end L-M神经网络算法之MATLAB实现1 %此为BP网络训练程序 function retstr = LmTrain(ModelNo,NetPara,TrainPara,InputFun,OutputFun,DataDir) NNTWARN OFF retstr=-1; %%%% 输入参数赋值开始%%%%%%%%%%%%%%%%%%%%%%% % 方便调试程序用,程序调试时去掉这部分的注释 ModelNo='1'; NetPara(1)=7; NetPara(2)=1; NetPara(3)=6; NetPara(4)=10; TrainPara(1)=25; TrainPara(2)=1000; TrainPara(3)=0.001; TrainPara(4)=0.001; TrainPara(5)=0.001; TrainPara(6)=10; TrainPara(7)=0.1; TrainPara(8)=1e10; DataDir='.'; InputFun = 'tansig'; OutputFun = 'purelin'; %%%% 输入参数赋值结束%%%%%%%%%%%%%%%%%%%%%%%% %保留原目录 olddir=pwd; %进入数据所在目录 cd(DataDir); deltalin(1); deltalog(1); deltatan(1); % 网络参数 InputDim=NetPara(1); %输入层节点数 OutputDim=NetPara(2); %输出层节点数