小波神經網絡MATLAB程序
阿新 • • 發佈:2019-03-09
dea epo apt cap incr ram del radi 易懂 %y(P,N) output of network
%d(P,N) ideal output of network
% phi(P,n) ouput of hidden node wavelet funciton
%W(N,n)weight value between ouput and hidden
%WW(n,m) weight value between hidden and input node
x=[4;5;6]
d=[1.3;3.6;6.7]
W=rand(N,n)
WW=rand(n,m)
a=ones(1,n)
for j=1:n
b(j)=j*P/n;
end
%%%%%%%%%%%%%%%%%%
%EW(N,n) gradient of W
%EWW(n,m) gradient of WW
%Ea(n) gradient of a
%Eb(n) gradient of b
%%%%%%%%%%%%%%]
epoch=1;
epo=100;
error=0.05;
err=0.01;
delta =1;
lin=0.5;
while (error>=err & epoch<=epo)
u=0;%u is the middle variant
%caculation of net input
for p=1:P
for j=1:n
u=0;
for k=1:m
u=u+WW(j,k)*x(p,k);
end
net(p,j)=u;
end
end
%calculation of morlet 0r mexican wavelet output
for p=1:P
for j=1:n
u=net(p,j);
u=(u-b(j))/a(j);
phi(p,j)=cos(1.75*u)*exp(-u*u/2); %morlet wavelet
%phi(p,j)=(1-u^2)*exp(-u*u/2); %mexican hat wavelet
end
end
%calculation of output of network
for p=1:P
for i=1:N
u=0;
for j=1:n
u=u+W(i,j)*phi(p,j);
end
y(p,i)=delta*abs(u);
end
end
%calculation of error of output
u=0;
for p=1:P
for i=1:N
u=u+abs(d(p,i)*log(y(p,i))+(1-d(p,i)*log(1-y(p,i))));
%u=u+(d(p,i)-y(p,i))^2;
end
end
%u=u/2
error=u;
%calculate of gradient of network
for i=1:N
for j=1:n
u=0;
for p=1:P
u=u+(d(p,i)-y(p,i))*phi(p,j);
end
EW(i,j)=u;
%EW(i,j)=-u;%the resule would be wrong
end
end
for j=1:n
for k=1:m
u=0
for p=1:P
for i=1:N
u=u+(d(p,i)-y(p,i))*W(i,j)*phi(p,j)*x(p,k)/a(j) ;
end
end
EWW(j,k)=u;
%EWW(j,k)=u the result would be wrong
end
end
for j=1:n
u=0
for p=1:P
for i=1:N
u=u+(d(p,i)-y(p,i))*W(i,j)*phi(p,j)/a(j) ;
end
end
Eb(j)=u;
end
for j=1:n
u=0
for p=1:P
for i=1:N
u=u+(d(p,i)-y(p,i))*W(i,j)*phi(p,j)*((net(p,j)-b(j))/b(j))/a(j) ;
end
end
Ea(j)=u;
end
%adjust of weight value
WW=WW-lin*EWW;
W=W-lin*EW;
a=a-lin*Ea;
b=b-lin*Eb;
%number of epoch increase by 1
epoch=epoch+1;
end
分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!http://www.captainbed.net
clear all
%initiate of data
P=3 %numberof sample
m=1%number of input node
n=10%number of hidden node
N=1%number of ouptut node
%
%a(n) b(n) scale and shifting parameter matrix
%x(P,m) input matrix of P sample
%net(P,n) ouput of hidden node
%d(P,N) ideal output of network
% phi(P,n) ouput of hidden node wavelet funciton
%W(N,n)weight value between ouput and hidden
%WW(n,m) weight value between hidden and input node
x=[4;5;6]
d=[1.3;3.6;6.7]
W=rand(N,n)
WW=rand(n,m)
a=ones(1,n)
for j=1:n
b(j)=j*P/n;
end
%%%%%%%%%%%%%%%%%%
%EWW(n,m) gradient of WW
%Ea(n) gradient of a
%Eb(n) gradient of b
%%%%%%%%%%%%%%]
epoch=1;
epo=100;
error=0.05;
err=0.01;
delta =1;
lin=0.5;
while (error>=err & epoch<=epo)
u=0;%u is the middle variant
%caculation of net input
for p=1:P
for j=1:n
u=0;
u=u+WW(j,k)*x(p,k);
end
net(p,j)=u;
end
end
%calculation of morlet 0r mexican wavelet output
for p=1:P
for j=1:n
u=net(p,j);
u=(u-b(j))/a(j);
phi(p,j)=cos(1.75*u)*exp(-u*u/2); %morlet wavelet
%phi(p,j)=(1-u^2)*exp(-u*u/2); %mexican hat wavelet
end
end
%calculation of output of network
for p=1:P
for i=1:N
u=0;
for j=1:n
u=u+W(i,j)*phi(p,j);
end
y(p,i)=delta*abs(u);
end
end
%calculation of error of output
u=0;
for p=1:P
for i=1:N
u=u+abs(d(p,i)*log(y(p,i))+(1-d(p,i)*log(1-y(p,i))));
%u=u+(d(p,i)-y(p,i))^2;
end
end
%u=u/2
error=u;
%calculate of gradient of network
for i=1:N
for j=1:n
u=0;
for p=1:P
u=u+(d(p,i)-y(p,i))*phi(p,j);
end
EW(i,j)=u;
%EW(i,j)=-u;%the resule would be wrong
end
end
for j=1:n
for k=1:m
u=0
for p=1:P
for i=1:N
u=u+(d(p,i)-y(p,i))*W(i,j)*phi(p,j)*x(p,k)/a(j) ;
end
end
EWW(j,k)=u;
%EWW(j,k)=u the result would be wrong
end
end
for j=1:n
u=0
for p=1:P
for i=1:N
u=u+(d(p,i)-y(p,i))*W(i,j)*phi(p,j)/a(j) ;
end
end
Eb(j)=u;
end
for j=1:n
u=0
for p=1:P
for i=1:N
u=u+(d(p,i)-y(p,i))*W(i,j)*phi(p,j)*((net(p,j)-b(j))/b(j))/a(j) ;
end
end
Ea(j)=u;
end
%adjust of weight value
WW=WW-lin*EWW;
W=W-lin*EW;
a=a-lin*Ea;
b=b-lin*Eb;
%number of epoch increase by 1
epoch=epoch+1;
end
再分享一下我老師大神的人工智能教程吧。零基礎!通俗易懂!風趣幽默!還帶黃段子!希望你也加入到我們人工智能的隊伍中來!http://www.captainbed.net
小波神經網絡MATLAB程序