自适应模糊神经网络MATLAB代码.docx
- 文档编号:2496373
- 上传时间:2022-10-30
- 格式:DOCX
- 页数:5
- 大小:14.98KB
自适应模糊神经网络MATLAB代码.docx
《自适应模糊神经网络MATLAB代码.docx》由会员分享,可在线阅读,更多相关《自适应模糊神经网络MATLAB代码.docx(5页珍藏版)》请在冰豆网上搜索。
function[c,sigma,W_output]=SOFNN(X,d,Kd)
%SOFNNSelf-OrganizingFuzzyNeuralNetworks
%InputParameters
%X(r,n)-rthtraningdatafromnthobservation
%d(n)-thedesiredoutputofthenetwork(mustbearowvector)
%Kd(r)-predefineddistancethresholdfortherthinput
%OutputParameters
%c(IndexInputVariable,IndexNeuron)
%sigma(IndexInputVariable,IndexNeuron)
%W_outputisavector
%SettingupParametersforSOFNN
SigmaZero=4;
delta=0.12;
threshold=0.1354;
k_sigma=1.12;
%Formoreaccurateresultsuncommentthefollowing
%formatlong;
%ImplementationofaSOFNNmodel
[size_R,size_N]=size(X);
%size_R-thenumberofinputvariables
c=[];
sigma=[];
W_output=[];
u=0;%thenumberofneuronsinthestructure
Q=[];
O=[];
Psi=[];
forn=1:
size_N
x=X(:
n);
ifu==0%Noneuroninthestructure?
c=x;
sigma=SigmaZero*ones(size_R,1);
u=1;
Psi=GetMePsi(X,c,sigma);
[Q,O]=UpdateStructure(X,Psi,d);
pT_n=GetMeGreatPsi(x,Psi(n,:
))';
else
[Q,O,pT_n]=UpdateStructureRecursively(X,Psi,Q,O,d,n);
end;
KeepSpinning=true;
whileKeepSpinning
%Calculatetheerrorandif-partcriteria
ae=abs(d(n)-pT_n*O);%approximationerror
[phi,~]=GetMePhi(x,c,sigma);
[maxphi,maxindex]=max(phi);%maxindexreferstotheneuron'sindex
ifae>delta
ifmaxphi %enlargewidth [minsigma,minindex]=min(sigma(: maxindex)); sigma(minindex,maxindex)=k_sigma*minsigma; Psi=GetMePsi(X,c,sigma); [Q,O]=UpdateStructure(X,Psi,d); pT_n=GetMeGreatPsi(x,Psi(n,: ))'; else %Addanewneuronandupdatestructure ctemp=[]; sigmatemp=[]; dist=0; forr=1: size_R dist=abs(x(r)-c(r,1)); distIndex=1; forj=2: u ifabs(x(r)-c(r,j)) distIndex=j; dist=abs(x(r)-c(r,j)); end; end; ifdist<=Kd(r) ctemp=[ctemp;c(r,distIndex)]; sigmatemp=[sigmatemp;sigma(r,distIndex)]; else ctemp=[ctemp;x(r)]; sigmatemp=[sigmatemp;dist]; end; end; c=[cctemp]; sigma=[sigmasigmatemp]; Psi=GetMePsi(X,c,sigma); [Q,O]=UpdateStructure(X,Psi,d); KeepSpinning=false; u=u+1; end; else ifmaxphi %enlargewidth [minsigma,minindex]=min(sigma(: maxindex)); sigma(minindex,maxindex)=k_sigma*minsigma; Psi=GetMePsi(X,c,sigma); [Q,O]=UpdateStructure(X,Psi,d); pT_n=GetMeGreatPsi(x,Psi(n,: ))'; else %Donothingandexitthewhile KeepSpinning=false; end; end; end; end; W_output=O; end function[Q_next,O_next,pT_n]=UpdateStructureRecursively(X,Psi,Q,O,d,n) %O=O(t-1)O_next=O(t) p_n=GetMeGreatPsi(X(: n),Psi(n,: )); pT_n=p_n'; ee=abs(d(n)-pT_n*O);%|e(t)| temp=1+pT_n*Q*p_n; ae=abs(ee/temp); ifee>=ae L=Q*p_n*(temp)^(-1); Q_next=(eye(length(Q))-L*pT_n)*Q; O_next=O+L*ee; else Q_next=eye(length(Q))*Q; O_next=O; end; end function[Q,O]=UpdateStructure(X,Psi,d) GreatPsiBig=GetMeGreatPsi(X,Psi); %M=u*(r+1) %n-thenumberofobservations [M,~]=size(GreatPsiBig); %OthersWaysofgettingQ=[P^T(t)*P(t)]^-1 %************************************************************************** %opts.SYM=true; %Q=linsolve(GreatPsiBig*GreatPsiBig',eye(M),opts); % %Q=inv(GreatPsiBig*GreatPsiBig'); %Q=pinv(GreatPsiBig*GreatPsiBig'); %************************************************************************** Y=GreatPsiBig\eye(M); Q=GreatPsiBig'\Y; O=Q*GreatPsiBig*d'; end %Thisfunctionworkstoowithx %(X=XandPsiisaMatrix)-GetsyouthewholeGreatPsi %(X=xandPsiistherowrelatedtox)-Getsyoujustthecolumnrelatedwiththeobservation function[GreatPsi]=GetMeGreatPsi(X,Psi) %Psi-Inarowyougothroughtheneuronsandinacolumnyougothroughnumberof %observations****Psi(#obs,IndexNeuron)**** GreatPsi=[]; [N,U]=size(Psi); forn=1: N x=X(: n); GreatPsiCol=[]; foru=1: U GreatPsiCol=[GreatPsiCol;Psi(n,u)*[1;x]]; end; GreatPsi=[GreatPsiGreatPsiCol]; end; end function[phi,SumPhi]=GetM
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 自适应 模糊 神经网络 MATLAB 代码