yinhexly 发表于 2007-1-24 22:14

多输入多输出的小波神经网络程序问题

clc
clear
%step 1=========================
%定义输入样本;
x=[9.8917 16.2808 22.2224 16.0717 7.8691 2.7981 1.6043 1.8988 0.4110 37.4368;
    9.1342 14.6104 19.8101 13.2840 12.1585 0.7664 2.6901 1.5111 1.3141 16.4487;
    9.6716 15.4450 20.9055 13.2430 10.0547 0.6452 0.2499 1.2983 0.4624 63.9632;
    9.4330 15.3921 21.0609 14.5206 9.1803 0.2371 0.5343 0.2631 0.2719 56.2736;
    9.9170 16.5965 22.8898 16.7952 11.7638 0.5130 1.0358 1.4984 2.7854 18.6786;
    12.5360 20.4861 27.7885 20.1340 9.3324 0.7193 0.4177 0.5386 0.5750 17.4630;
    10.7219 17.5987 24.0846 17.2131 8.5336 0.8956 0.8594 3.1638 0.7377 95.8756;
    7.9529 12.2725 16.3521 11.1387 10.1894 0.8650 1.1113 2.8885 1.0000 15.2124;
    12.9831 20.6390 27.6185 16.6408 9.8208 0.4561 0.4367 2.4510 1.0128 20.3837;
    8.8662 14.6558 20.1085 15.2818 10.5702 0.3314 0.4614 1.7346 1.0475 15.1164;
    5.1282 6.9760 8.7152 4.7649 6.8872 0.7611 0.7250 4.4827 0.7274 21.0614;
    5.7345 7.8635 9.8005 5.1034 9.7471 0.4253 0.5165 0.9120 0.4378 9.3798;
    5.4486 7.3852 9.1712 4.6508 15.0624 0.8967 0.1785 0.6898 0.6066 19.5064;
    6.5131 8.8169 10.9178 5.0329 21.5843 0.1968 0.2456 2.7955 0.4334 43.7432;
    6.1414 8.3191 10.3136 4.8468 14.1043 0.0853 0.3104 0.8028 0.5529 13.6630;
    5.0588 6.7975 8.4154 4.4592 7.0590 1.0127 0.3262 1.4759 1.2376 5.5029;
    6.0436 8.2930 10.3687 5.1387 5.6913 0.4928 0.1575 0.7601 0.4540 5.0560;
    5.3083 7.1988 8.9417 4.7508 17.8604 0.5241 0.3556 2.0853 1.7921 160.8844;
    6.0549 8.1943 10.1927 4.5722 14.3794 0.1827 0.2974 0.9010 0.5769 14.1162;
    7.6526 10.2548 12.6159 5.0318 9.7971 0.2108 0.1718 1.4304 0.4233 5.4123;
    5.5231 7.3226 8.8652 4.6644 2.6875 0.3591 0.5625 2.6780 0.7393 5.0921;
    4.6882 6.1638 7.4766 4.0891 1.6601 0.0877 0.2299 0.4558 0.1413 5.5794;
    5.4792 7.2693 8.8401 4.4541 1.6617 0.2091 0.4636 1.0347 2.3503 1.7210;
    5.3134 7.0937 8.6922 4.5062 4.0152 0.4075 0.1446 1.3364 0.5235 1.5722;
    5.5252 7.3749 8.9985 4.6200 1.8061 0.8186 0.3707 1.2579 0.8578 14.6108;
    6.1193 8.1845 10.0262 4.6733 1.7265 0.0825 0.1092 0.3967 0.8891 2.8055;
    5.4988 7.2764 8.8632 4.3605 2.3037 0.2721 0.4467 1.3816 1.1445 3.3968;
    4.4257 5.9067 7.2691 4.3216 1.2679 0.1786 0.8886 0.8533 0.1923 1.7171;
    5.6485 7.5262 9.1927 4.6319 1.8498 0.2038 1.3701 1.1569 0.7590 2.6742;
    5.1597 6.8876 8.4379 4.4464 24.1129 0.0728 0.1052 2.2930 0.2615 3.4760;
    6.6346 9.0589 11.2431 5.3571 11.9921 0.2937 0.1710 2.3284 3.6069 10.1040;
    5.4407 7.2866 9.0032 4.4078 9.2213 0.4675 0.2509 1.7718 0.6010 22.1345;
    5.0303 6.7561 8.3516 4.3330 13.6622 0.6600 0.4558 1.2634 0.5331 16.4660;
    5.0678 6.7865 8.3778 4.4263 7.7725 1.1272 0.5207 2.3446 0.8874 7.6544;
    5.1062 6.9215 8.6107 4.7534 6.2806 0.2381 0.1702 1.2152 0.3313 30.1511;
    5.8878 7.9043 9.7423 4.7277 4.4762 0.3916 1.0843 2.0195 1.0058 5.2642;
    5.0775 6.9480 8.6915 4.8889 8.5127 0.1956 1.0742 3.9292 0.8391 40.6147;
    5.7252 7.6745 9.4729 4.5038 9.0513 0.0677 0.2413 0.8304 0.6651 27.6393;
    4.9137 6.6108 8.1802 4.5630 7.8270 0.9127 0.2622 1.3908 0.3243 12.2967;
    4.6780 6.3054 7.8216 4.3178 8.8981 0.3682 0.3749 3.2535 2.5545 109.2149;
    5.5570 7.5502 9.3534 4.9195 7.7383 1.9719 0.5168 5.6967 1.3284 12.3778;
    6.0369 8.1015 9.9654 4.7847 11.5907 0.1522 0.0781 0.3963 0.3942 14.5321;
    6.5061 8.8294 10.9547 5.0455 20.4370 1.6855 1.0918 4.9518 2.9786 7.9449;
    5.9512 8.0494 9.9335 4.8807 10.1185 0.8514 0.6105 4.3704 3.8718 30.5787;
    5.6055 7.5451 9.2977 4.7616 11.0223 2.1319 0.4369 3.1872 2.1992 17.7329;
    5.9762 8.0461 9.8778 4.9732 12.3081 1.3987 0.8011 2.4575 1.5207 19.7396;
    6.6947 9.0696 11.2269 5.1192 13.3338 0.3165 0.4650 0.9679 0.9560 58.2490;
    5.5467 7.4573 9.1776 4.8087 4.7146 0.4632 0.2195 1.4549 1.3643 9.9297;
    5.5185 7.3575 9.0199 4.4404 3.0526 1.1414 1.4765 2.5243 3.2816 4.1411;
    6.7329 9.1903 11.3928 5.8589 11.0579 2.8650 4.0627 7.5779 8.6475 24.8504];
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 i=1:10
x(:,i)=(x(:,i)-0.9324*min(x(:,i)))/(1.0563*max(x(:,i))-0.9324*min(x(:,i)));
end
eta=0.02;
aerfa=0.935;                                                                                                                                                                                                            
%step 2=========================
%初始化连接权wjh(输出层和隐层的连接权);whi(隐层和输出层的连接权);
%假设小波函数节点数为:H个;样本数为P;
%输出节点数为:J个;输入节点数为:I个;
H=25;
P=10;
I=10;
J=5;
PP=2;
%初始化小波参数
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
oxjp=zeros(5*P,J);
for i=1:(5*P)
for j=1:J
oxjp(i,j)=oxjp(i,j)+fnn(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=;%保存每次的误差;
Err_rate=Err_NetOut/E_x;%保存每次的相对误差;

%Err_rate

%oxjp

%求detaj ,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));
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
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));
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=========================
%引入修正算法!!


%判断所有的样本是否计算完==================================
if Err_NetOut(end)>0.05
flag=flag+1;
else
figure;
plot(Err_NetOut);
title('误差曲线');
disp('目标达到');
disp(oxjp);   
end
if count>2000
figure;
plot(Err_NetOut);
title('误差曲线');
disp('目标未达到');
disp(oxjp);
return;
end

帮忙看看为什么不能运行?

xjzuo 发表于 2007-1-25 10:45

可以参考一下Matlab版的回复.

qianliqq 发表于 2007-1-30 23:32

我最近也在写神经网络的仿真程序,回头参考看看你这个

gghhjj 发表于 2007-2-1 18:15

原帖由 xjzuo 于 2007-1-25 10:45 发表
可以参考一下Matlab版的回复.

支持,请勿重复发帖,没有什么意义

sunshihui 发表于 2007-6-22 15:01

到哪里去看这个程序的错误呢?什么MATLAB版呀?这里不就是吗?

咕噜噜 发表于 2007-6-22 15:28

回复 #5 sunshihui 的帖子

这里是振动基础部分的数学与非线性数学版块,与我们这个板块同一级别有matlab版块,在数学软件区域,找一下啊

[ 本帖最后由 咕噜噜 于 2007-6-22 15:29 编辑 ]

gghhjj 发表于 2007-6-23 06:11

建议版主转移到matlab版或者人工智能版
页: [1]
查看完整版本: 多输入多输出的小波神经网络程序问题