自适应模糊神经网络MATLAB代码Word下载.docx
《自适应模糊神经网络MATLAB代码Word下载.docx》由会员分享,可在线阅读,更多相关《自适应模糊神经网络MATLAB代码Word下载.docx(5页珍藏版)》请在冰豆网上搜索。
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<
threshold
%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))<
dist
distIndex=j;
dist=abs(x(r)-c(r,j));
end;
ifdist<
=Kd(r)
ctemp=[ctemp;
c(r,distIndex)];
sigmatemp=[sigmatemp;
sigma(r,distIndex)];
x(r)];
dist];
c=[cctemp];
sigma=[sigmasigmatemp];
KeepSpinning=false;
u=u+1;
%Donothingandexitthewhile
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;
Q_next=eye(length(Q))*Q;
O_next=O;
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'
%Thisfunctionworkstoowithx
%(X=XandPsiisaMatrix)-GetsyouthewholeGreatPsi
%(X=xandPsiistherowrelatedtox)-Getsyoujustthecolumnrelatedwiththeobservation
function[GreatPsi]=GetMeGreatPsi(X,Psi)
%Psi-Inarowyougothroughtheneuronsandinacolumnyougothroughnumberof
%observations****Psi(#obs,IndexNeuron)****
GreatPsi=[];
[N,U]=size(Psi);
N
GreatPsiCol=[];
foru=1:
U
GreatPsiCol=[GreatPsiCol;
Psi(n,u)*[1;
x]];
GreatPsi=[GreatPsiGreatPsiCol];
function[phi,SumPhi]=GetM