sunshihui 发表于 2007-6-22 12:09

请问这个小波神经网络的程序错在哪?

请大家帮忙啦!这个程序为什么总是运行不出正确的结果呢?神经网络的输出与目标输出相差很大。谢谢

x=[ 19.8917 16.2808 22.2224 16.0717 17.8691 12.7981 11.6043 12.8988 18.4110 17.4368;
    19.1342 14.6104 19.8101 13.2840 12.1585 10.7664 12.6901 15.111 13.141 16.4487;
      9.6716 9.4450 9.9055 9.2430 10.0547 10.6452 10.2499 11.2983 10.4624 9.9632;
      9.4330 10.3921 10.0609 10.5206 9.1803 10.2371 10.5343 10.2631 10.2719 9.2736;
    29.9170 26.5965 22.8898 26.7952 21.7638 30.5130 31.0358 28.4984 27.7854 28.6786;
    28.5360 30.4861 27.7885 28.1340 29.3324 30.7193 30.4177 30.5386 30.5750 27.4630;
       10.7219 7.5987 8.0846 8.2131 8.5336 10.8956 10.8594 8.1638 10.7377 9.8756;
       7.9529 10.2725 8.3521 11.1387 10.1894 10.8650 10.1113 9.8885 10.0000 10.004;
    12.9831 12.6390 12.6185 12.6408 10.8208 10.4561 10.4367 12.4510 11.0128 12.3837;
    10.8662 11.6558 10.1085 10.2818 10.5702 10.3314 10.4614 11.7346 11.0475 15.1164;
       5.1282 6.9760 6.7152 4.7649 6.8872 6.7611 5.7250 5.4827 5.7274 6.0614;
       5.7345 5.8635 5.8005 5.1034 6.7471 6.4253 6.5165 6.9120 6.4378 6.3798;
    15.4486 17.3852 14.1712 14.6508 15.0624 14.8967 14.1785 15.6898 14.6066 15.5064;
    16.5131 18.8169 15.9178 15.0329 16.5843 17.1968 10.2456 15.7955 15.4334 14.7432;
       6.1414 8.3191 7.3136 6.8468 7.1043 7.0853 7.3104 6.8028 6.5529 6.6630;
       5.0588 6.7975 8.4154 4.4592 7.0590 1.0127 0.3262 1.4759 1.2376 7.5029;
    26.0436 28.2930 28.3687 27.1387 26.6913 26.4928 27.1575 27.7601 27.4540 26.0560;
    25.3083 27.1988 28.9417 24.7508 27.8604 30.5241 30.3556 27.0853 31.7921 30.8844;
       16.0549 18.1943 20.1927 20.5722 19.3794 20.1827 20.2974 20.9010 20.5769 16.1162;
       17.6526 16.2548 16.6159 15.0318 17.7971 17.2108 16.1718 17.4304 18.4233 19.4123;
    7.5231 7.3226 .8652 7.6644 6.6875 7.3591 6.5625 7.6780 6.7393 7.0921;
    74.6882 8.1638 7.4766 7.0891 6.6601 7.0877 6.2299 6.4558 5.1413 6.5794;
       5.4792 6.2693 5.8401 5.4541 5.6617 6.2091 6.4636 5.0347 4.503 5.7210;
       5.3134 7.0937 8.6922 4.5062 4.0152 5.4075 6.1446 6.3364 5.5235 5.5722;
    5.5252 7.3749 8.9985 4.62006 1.8061 6.8186 6.3707 5.2579 5.8578 4.6108;
    16.1193 18.1845 17.0262 16.6733 17.265 20.0825 20.1092 20.3967 20.8891 18.055;
       19.88 17.2764 18.632 16.05 20.037 17.21 16.7 18.16 17.445 19.68;
       14.4257 13.70 12.2691 14.3216 12.679 12.1786 13.8886 12.8533 13.1923 12.7171;
    33.6485 32.5262 33.927 34.6319 31.8498 32.038 31.3701 31.1569 32.7590 32.6742;
    35.1597 30.8876 33.4379 32.4464 31.1129 31.0728 32.1052 31.2930 32.2615 32.4760;
      6.6346 6.0589 6.2431 5.3571 5.9921 5.2937 5.1710 5.3284 5.6069 7.1040;
      5.4407 7.2866 8.0032 6.4078 6.2213 7.4675 7.2509 7.7718 7.6010 6.1345;
    25.0303 26.7561 28.3516 26.3330 27.6622 30.6600 30.4558 31.2634 30.5331 26.4660;
    45.0678 46.7865 48.3778 44.4263 47.7725 51.1272 50.5207 48.3446 49.8874 47.6544;
      52.7252 54.6745 55.4729 54.5038 52.0513 50.0677 50.2413 53.04 56.651 57.6393;   
      50.0062 46.9215 48.6107 47.534 46.2806 48.2381 49.1702 48.2152 46.3313 40.1511;
    5.8878 7.9043 6.7423 5.7277 6.4762 7.3916 7.0843 7.0195 7.0058 5.2642;
    6.0775 6.9480 6.6915 6.8889 8.5127 7.1956 6.0742 6.9292 6.8391 6.6147;
         54.9137 56.6108 58.1802 54.5630 57.8270 58.9127 60.2622 51.3908 54.243 52.2967;
         56.7329 59.1903 58.3928 55.8589 56.0579 55.8650 54.0627 57.5779 58.6475 54.8504
    0.6780 0.3054 0.8216 1.3178 0.8981 1.3682 1.3749 1.2535 2.5545 1.2149;
    0.5570 0.7502 0.9534 0.9195 0.7383 0.9719 0.5168 0.6967 1.3284 1.3778;
      6.0369 8.1015 7.9654 7.8477.5907 8.1522 8.0781 8.3963 8.3942 7.5321;
      6.5061 8.8294 7.9547 6.0455 20.4370 8.6855 7.0918 7.9518 8.9786 7.9449;
    16.9512 18.0494 18.9335 14.8807 16.1185 16.8514 18.6105 17.3704 16.8718 20.5787;
    20.6055 17.5451 19.2977 19.7616 17.0923 18.1319 20.4369 18.1872 20.1992 17.7329;
      8.9762 8.0461 9.8778 10.9732 9.3081 10.3987 9.8011 10.4575 9.5207 9.7396;
      8.6947 9.0696 11.2269 9.1192 8.3338 10.3165 10.4650 10.9679 10.9560 8.2490;
    5.5467 5.9573 6.1776 4.8087 4.7146 6.4632 6.2195 5.4549 5.3643 5.9297;
    5.5185 6.3575 6.0199 4.9404 7.0526 7.1414 6.4765 6.5243 5.2816 4.7411];
targ=[1 0 0 0 0;1 0 0 0 0;1 0 0 0 0;1 0 0 0 0;1 0 0 0 0;
    1 0 0 0 0;1 0 0 0 0;1 0 0 0 0;1 0 0 0 0;1 0 0 0 0;
    0 1 0 0 0;0 1 0 0 0;0 1 0 0 0;0 1 0 0 0;0 1 0 0 0;
    0 1 0 0 0;0 1 0 0 0;0 1 0 0 0;0 1 0 0 0;0 1 0 0 0;
    0 0 1 0 0;0 0 1 0 0;0 0 1 0 0;0 0 1 0 0;0 0 1 0 0;
    0 0 1 0 0;0 0 1 0 0;0 0 1 0 0;0 0 1 0 0;0 0 1 0 0;
    0 0 0 1 0;0 0 0 1 0;0 0 0 1 0;0 0 0 1 0;0 0 0 1 0;
    0 0 0 1 0;0 0 0 1 0;0 0 0 1 0;0 0 0 1 0;0 0 0 1 0;
    0 0 0 0 1;0 0 0 0 1;0 0 0 0 1;0 0 0 0 1;0 0 0 0 1;
    0 0 0 0 1;0 0 0 0 1;0 0 0 0 1;0 0 0 0 1;0 0 0 0 1];
for s=1:10
x(:,s)=(x(:,s)-0.9324*min(x(:,s)))/(1.0563*max(x(:,s))-0.9324*min(x(:,s))); %归一化,对同一个节点的所有输入进行归一。
end
eta=0.005;
aerfa=0.935;                                                                                                                                                                                                         
%step 2=========================
%初始化连接权wjh(输出层和隐层的连接权);whi(隐层和输出层的连接权);
%假设小波函数节点数为:H个;样本数为P;
%输出节点数为:J个;输入节点数为:I个;
H=25;
P=10;
I=10;
J=5;
%初始化小波参数
b=rand(H,1);
a=rand(H,1);
%初始化权系数;
whi=rand(I,H);
wjh=rand(H,J);
%阈值初始化;
b1=rand(H,1);
b2=rand(J,1);
p=0;
%保存的误差;
count=0;
Err_NetOut=[];
flag=1;
while flag>0
flag=0;
count=count+1;
%step 3=================================
xhp1=zeros(5*P,H);
for i=1:(5*P)
for h=1:H
xhp1(i,h)=xhp1(i,h)+x(i,:)*whi(:,h);
ixhp(i,h)=xhp1(i,h)+b1(h);
end      
end
for i=1:(5*P)
for h=1:H
oxhp(i,h)=fai((ixhp(i,h)-b(h))/a(h));
end
end
%step 4====================================
ixjp1=zeros(5*P,H);
for i=1:(5*P)
for j=1:J
ixjp1(i,j)=ixjp1(i,j)+oxhp(i,:)*wjh(:,j);
ixjp(i,j)=ixjp1(i,j)+b2(j);
end   
end
for s=1:5
ixjp(:,s)=(ixjp(:,s)-0.9324*min(ixjp(:,s)))/(1.0563*max(ixjp(:,s))-0.9324*min(ixjp(:,s)));
end
oxjp=zeros(5*P,J);
for i=1:(5*P)
for j=1:J
oxjp(i,j)=oxjp(i,j)+fnn1(ixjp(i,j));
end
end
%step 5==保存每次误差=====
err=oxjp-targ;
wuchayy=1/2*sumsqr(max(abs(err(:,:))));
%E_x=1/2*sumsqr(x);
Err_NetOut=;%保存每次的误差;
%求detaj ,detawjh,detab2==================================
detaj=zeros(J,1);
for j=1:J
for i=1:(5*P)
detaj(j)=detaj(j)-(oxjp(i,j)-targ(i,j))*oxjp(i,j)*(1-oxjp(i,j));% -(oxjp(i,j)-targ(i,j))*oxjp(i,j)*(1-oxjp(i,j)); %
end
end   
oxhp1=oxhp';
for j=1:J
for h=1:H
detawjh(h,j)=eta*oxhp1(h,j)*detaj(j);
end
end
detab2=eta*detaj;   
%求detah, detawhi detab1 detab detaa;========================
sum=zeros(1,H);
wjh1=wjh';
for h=1:H
for j=1:J
for i=1:(5*P)
sum(h)=detaj(j)*wjh1(j,h)*diffai((ixhp(i,h)-b(h))/a(h))/a(h)+sum(h);
end      
end
end
detah=sum;
x1=x';
detawhi=zeros(I,H);
for h=1:H
for i=1:I
for k=1:(5*P)
detawhi(i,h)=eta*x1(i,k)*detah(h);% +detawhi(i,h);
end
end
end      
detab1=eta*detah;
detab=-eta*detah;
detaa=zeros(1,H);
for h=1:H
for i=1:(5*P)
detaa(h)=detaa(h)-eta*detah(h)*((ixhp(i,h)-b(h))/a(h)); %-eta*detah(h)*((ixhp(i,h)-b(h))/a(h));%
end
end   
%step 6=========================
%引入动量因子aerfa,修正各个系数==========================
wjh=wjh+(1+aerfa)*detawjh;
whi=whi+(1+aerfa)*detawhi;
a=a+(1+aerfa)*detaa';
b=b+(1+aerfa)*detab';
b1=b1+(1+aerfa)*detab1';
b2=b2+(1+aerfa)*detab2;
%%step 7============判断所有的样本是否计算完
p=p+1;
if p<=P
flag=flag+1;
else
if Err_NetOut(end)>0.05
flag=flag+1;
else
figure;
plot(Err_NetOut);
title('误差曲线');
disp('目标达到');
disp(oxjp);   
disp(wuchayy);
end
end
if count>500
figure;
plot(Err_NetOut);
title('误差曲线');
disp('目标未达到');
disp(oxjp);
disp(wuchayy);
break;
end
end

[ 本帖最后由 eight 于 2007-6-24 23:13 编辑 ]

sunshihui 发表于 2007-6-22 14:05

请教各位了,大家帮忙看下吧!:loveliness:

sunshihui 发表于 2007-6-22 14:58

各位高手请帮忙吧,不知道为什么,网络输出都在0.5左右的?
页: [1]
查看完整版本: 请问这个小波神经网络的程序错在哪?