📄 train_zaixian_2.m
字号:
%加入动量项-在线处理-2个隐含层
clear oj ok of oo wji wkj wfk wof b1 b2 b3 b4 deltak deltai yy result epoch
ceshiyangben=ccc;
P=ceshiyangben';
Ir=0.0121;%学习速率
err_goal=0.05;arfa=0.07;
for i=1:59
target(i,:)=[0 0 1];
end
for i=60:131
target(i,:)=[0 1 0];
end
for i=132:178
target(i,:)=[1 0 0];
end
T=target';%目标向量生成
[m,n]=size(ceshiyangben);[s2,s1]=size(T);
for i=1:n
A=mean2(ceshiyangben(:,i));
B=std(ceshiyangben(:,i));
ceshiyangben(:,i)=(ceshiyangben(:,i)-A)./B;
end%对样本进行归一化
q1=11;q2=5;
wji=0.1*rands(q1,13); wkj=0.1*rands(q2,q1); wok=0.1*rands(3,q2);
b1=0.1*rands(q1,1);b2=0.1*rands(q2,1);b3=0.1*rands(3,1);;%—随机给定隐含层、输出层偏值
E=[ ];%记录每次训练的误差初始化
max_epoch=178;CCji=zeros(q1,13);CCkj=zeros(q2,q1);CCok=zeros(3,q2);
for I=1:1000
for i=1:m
netj=wji*P(:,i)-b1;
oj=logsig(netj);
netk=wkj*oj-b2;
ok=logsig(netk);
neto=wok*ok-b3;
oo=logsig(neto);
errr=T(:,i)-oo;
sse=mse(errr);
deltao=oo.*(ones(3,1)-oo).*errr;
deltak=ok.*(ones(q2,1)-ok).*(wok'*deltao);
deltaj=oj.*(ones(q1,1)-oj).*(wkj'*deltak);
deltawji=(deltaj*P(:,i)');
wji=wji+Ir*deltawji+arfa*CCji
b1=b1+Ir*deltaj;CCji=deltawji;
deltawkj=(deltak*oj');wkj=wkj+Ir*deltawkj+arfa*CCkj; b2=b2+Ir*deltak;CCkj=deltawkj;
deltawok=(deltao*ok');wok=wok+Ir*deltawok+arfa*CCok; b3=b3+Ir*deltao; CCok=deltawok;
end
end
for i=1:m
netjj=wji*P(i,:)';
ojj=logsig(netjj-b1);
netkk=wkj*oj;
okk=logsig(netkk-b2);
netff=wfk*ok;
off=logsig(netff-b3);
netoo=wof*off;
ooo(:,i)=logsig(netoo-b4);
end
for j=1:s2
for i=1:178
yy(j,i)=round(ooo(j,i));
end
end
for h=1:178
if yy(:,h)==T(:,h)
if h<=59
result(1,h)=1;count1(1,1)=count1(1,1)+1;
elseif h<=131&h>59
result(1,h)=2;count1(1,2)=count1(1,2)+1;
elseif h<=178&h>131
result(1,h)=3;count1(1,3)=count1(1,3)+1;
end
else
result(1,h)=0;
end
end
for hh=1:178
if yy(:,hh)==[0 0 1]'
count2(1,1)=count2(1,1)+1;
elseif yy(:,hh)==[0 1 0]'
count2(1,2)=count2(1,2)+1;
elseif yy(:,hh)==[1 0 0]'
count2(1,3)=count2(1,3)+1;
end
end
Re=count1./[59 72 47]
Pr=count1./count2
plot(E,'r-')
figure
plot(result)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -