?? bpsan.m
字號:
clear
x1=linspace(0.0001,2*pi,11);
y1=linspace(0.0001,2*pi,11); %初始化輸入值X1 Y1
[x1,y1]=meshgrid(x1,y1);
d=(((sin(x1).*sin(y1))./(x1.*y1))+1)/2; %初始化輸出d
w1=[1.5844 1.6441;0.74448 0.78194;0.81343 -0.66575;-0.5737 0.83697;
0.28679 0.44245;-0.57636 -1.22;0.80707 0.43714;-1.0981 -0.52348;
0.088314 0.91418;1.5414 1.4782];
w2=[0.0026165 0.062183 -0.18009 0.13269 -0.80106 0.91097 0.66656 1.076 0.26821 -0.09642;
1.469 2.1851 2.1371 2.1563 2.322 2.4231 2.0501 1.6318 2.1855 2.2569;
0.38392 0.49159 -0.10762 0.39891 -1.1335 0.96899 -0.16392 1.0655 0.51813 -0.13409;
-0.34162 0.35435 1.5207 1.2232 0.52976 0.40887 0.56438 0.97029 0.65146 -0.53335;
1.7731 0.78681 0.58263 0.39657 0.30993 0.29067 0.76186 0.11722 0.47792 1.3413;
0.34715 0.318 0.66788 0.013305 -1.3114 0.57609 -0.014608 0.82558 0.097232 0.14029;
1.4849 2.3212 2.5465 1.779 1.5278 1.9225 1.8775 2.1854 1.9635 1.7167;
0.088449 0.60285 -0.17105 0.14084 -1.5647 1.3829 0.75604 1.258 0.019266 0.57361;
-0.037588 0.10421 1.332 1.0529 0.5272 0.4511 0.20397 0.7692 0.72259 0.64258;
0.14971 0.85889 1.1346 0.33761 0.84096 0.67127 0.49248 0.82315 0.60204 0.46487];
w3=[0.334 1.2414 1.3603 0.66309 0.82581 1.2749 1.3164 0.9459 1.2181 1.1524;
1.8235 -3.5995 0.8506 1.2803 1.0817 1.9224 -3.2308 1.695 1.8017 1.0148;
0.35978 1.2114 1.3228 0.7178 0.29287 1.0126 0.96484 0.48741 1.0844 0.63083;
1.1684 -3.5789 1.6871 1.04 1.3133 1.6784 -3.3743 1.4967 1.2023 1.7181;
1.0875 1.2495 1.4182 0.70555 0.74038 1.236 1.288 1.1203 0.49184 0.70146;
0.54223 -1.5256 0.90577 0.42566 1.5798 0.62715 -1.1558 0.75687 0.36601 0.29489;
0.40877 1.4886 1.3601 0.93316 1.2761 0.70218 1.1033 0.58111 1.3082 1.2868;
1.1168 -3.6942 1.116 1.7486 1.3142 1.1118 -2.7341 1.7122 1.2302 0.92108;
1.4936 -2.8798 0.88438 0.89626 1.6421 1.1088 -2.5408 1.6672 0.73539 0.90525;
0.6324 -1.8871 0.54249 0.93045 1.1186 0.74159 -2.158 1.3964 0.70555 0.76779];
w4=[2.9153 -6.1886 1.3527 -6.2903 2.7152 -3.3938 3.1009 -5.8818 -5.1855 -4.0715];
e=1.5;
step=0.0013; %初始化權值w1 w2 w3 w4 誤差e 學習率step
while e>0.007 %誤差精度
x11=reshape(x1,121,1);
y11=reshape(y1,121,1); %矩陣重置為121行1列
x=[x11';y11']; %合并輸入
s1=w1*x-1;
x2=1./(1+exp(-1*s1));
s2=w2*x2-1;
x3=1./(1+exp(-1*s2));
s3=w3*x3-1;
x4=1./(1+exp(-1*s3));
s4=w4*x4-1;
x5=1./(1+exp(-1*s4)); %計算輸出
d11=reshape(d,121,1);
e=0.5*(d11'-x5)*(d11'-x5)'; %計算誤差
disp(e); %顯示e
o4=(d11'-x5).*x5.*(1-x5)*1;
i4=x4*o4';
w4=w4+i4'.*step;
o3=x4.*(1-x4).*(w4'*o4)*1;
i3=x3*o3';
w3=w3+1*i3'*step;
o2=x3.*(1-x3).*(w3'*o3)*1;
i2=x2*o2';
w2=w2+1*i2'*step;
o1=x2.*(1-x2).*(w2'*o2)*1;
i1=x*o1';
w1=w1+1*i1'*step; %調整權值
end
xp=linspace(0.0001,2*pi,50);
yp=linspace(0.0001,2*pi,50);
[xp,yp]=meshgrid(xp,yp);
xp1=reshape(xp,2500,1);
yp1=reshape(yp,2500,1);
x=[xp1';yp1'];
s1=w1*x-1;
x2=1./(1+exp(-1*s1));
s2=w2*x2-1;
x3=1./(1+exp(-1*s2));
s3=w3*x3-1;
x4=1./(1+exp(-1*s3));
s4=w4*x4-1;
x5=1./(1+exp(-1*s4));
x5=reshape(x5,50,50);
mesh(xp,yp,x5); %繪圖程序
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -