[人工智能] 有没有神经网络实例,可以学习一下怎么编程?
clear%数据输入huanghe_p=;huanghe_t=;%归一化处理p=(huanghe_p-min(huanghe_p))/(max(huanghe_p)-min(huanghe_p));t=(huanghe_t-min(huanghe_t))/(max(huanghe_t)-min(huanghe_t));%数据输入2:网络有关参数EPOCHS=10000;GOAL=0.000005;%建立bp神经网络,并训练,仿真。其中输入为p,输出为t%-------------------------隐层神经元确定-----------------------------s=3:15;%s 为常向量,表示神经元的个数res=zeros(size(s));%res将要存储误差向量,这里先置零pn=;tn=;for i=1:length(s) net=newff(minmax(pn),,{'tansig','purelin'},'trainlm'); net.iw{1,1}=zeros(size(net.iw{1,1}))+0.5; net.lw{2,1}=zeros(size(net.lw{2,1}))+0.75; net.b{1,1}=zeros(size(net.b{1,1}))+0.5; net.b{2,1}=zeros(size(net.b{2,1})); net.trainParam.epochs=EPOCHS; net.trainParam.goal =GOAL; net=train(net,pn,tn); y=sim(net,pn);e=tn-y;error=mse(e,net);res(i)=norm(error);end%选取最优神经元数,number为使得误差最小的隐层神经元个数number=find(res==min(res));if(length(number)>1) no=number(1)else no=numberendclear error,res%选定隐层神经元数目后,建立网络,训练仿真。net=newff(minmax(pn),,{'tansig','purelin'},'trainlm'); net.iw{1,1}=zeros(size(net.iw{1,1}))+0.5; net.lw{2,1}=zeros(size(net.lw{2,1}))+0.75; net.b{1,1}=zeros(size(net.b{1,1}))+0.5; net.b{2,1}=zeros(size(net.b{2,1})); net.trainParam.epochs=EPOCHS; net.trainParam.goal =GOAL;net=train(net,pn,tn);y=sim(net,pn);e=tn-y;error=mse(e,net)%error为网络的误差向量r=norm(error);%r为网络的整体误差save net %保存最好的网络%预测input=;yuce=sim(net,input);%结果反归一化y1=;yuce1=;t1=y1*(max(huanghe_t(1:20))-min(huanghe_t(1:20)))+min(huanghe_t(1:20));yuce2=yuce1*(max(huanghe_t(1:20))-min(huanghe_t(1:20)))+min(huanghe_t(1:20));%计算误差wucha=abs(t1-huanghe_t(1:20))./huanghe_t(1:20)b=minmax(wucha);average_wucha=mean(wucha);%作图figure(1)plot(1:20,huanghe_t(1:20),'*-',1:20,t1,'o:')figure(2)plot(1:20,huanghe_t(11:30),'*-',1:20,yuce2,'o:')
页:
[1]