⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 train_zaixian_1.m

📁 基于matlab的神经网络训练方法
💻 M
字号:
%加入动量项-在线处理-1个隐含层
q1=8;
clear oj ok of oo  wji wkj  b1 b2  deltak deltao yy result epoch count1 count2
ceshiyangben=ccc;
P=ceshiyangben';
Ir=0.121;%学习速率
err_goal=0.00121;arfa=0% 15  17 
 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%对样本进行归一化

wji=0.1*rands(q1,13); wkj=0.1*rands(3,q1);
b1=0.1*rands(q1,1);b2=0.1*rands(3,1);;%—随机给定隐含层、输出层偏值 
E=[ ];%记录每次训练的误差初始化
max_epoch=178;CCji=zeros(q1,13);CCkj=zeros(3,q1); 
for I=1:10
    for i=1:m
    netj=wji*P(:,i)-b1;
    oj=logsig(netj);
     netk=wkj*oj-b2;
    ok=logsig(netk);
    errr=T(:,i)-ok;    E=[E sse];
    sse=mse(errr);
   deltao=ok.*(ones(3,1)-ok).*errr;
   deltaj=oj.*(ones(q1,1)-oj).*(wkj'*deltao);
   deltawji=(deltaj*P(:,i)');
   wji=wji+Ir*deltawji+arfa*CCji;
   b1=b1+Ir*deltaj;CCji=deltawji;
   deltawkj=(ok*deltaj');
   wkj=wkj+Ir*deltawkj+arfa*CCkj; 
   b2=b2+Ir*deltao;CCkj=deltawkj;
    end
end 

for i=1:m
 netjj=wji*P(:,i);
    ojj=logsig(netjj-b1);
     netkk=wkj*oj;
    ooo(:,i)=logsig(netkk-b2);
end
  for j=1:s2
        for i=1:178
    yy(j,i)=round(ooo(j,i));
    end
end
count1=zeros(1,3);
count2=zeros(1,3);
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
subplot(2,1,1);plot(E,'r-')
subplot(2,1,2);plot(result)




  
  
      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -