|
回复 楼主 chincat 的帖子
小波我不懂! 粗略看了下楼主的程序! 太乱了, 改成个人习惯
其中红色部分修改下, 就不会反复输出u=0!
clear all; P=3; m=1; n=10; N=1; 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; 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); 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+(d(p,i)-y(p,i))^2; end; end; 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; 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; 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
WW=WW-lin*EWW; W=W-lin*EW; a=a-lin*Ea; b=b-lin*Eb; epoch=epoch+1; % adjust of weight value
end
[ 本帖最后由 ChaChing 于 2009-1-4 23:36 编辑 ] |
|