研发埠
标题:
[人工智能] 有没有神经网络实例,可以学习一下怎么编程?
[打印本页]
作者:
刘晓强
时间:
2013-8-16 09:28
标题:
[人工智能] 有没有神经网络实例,可以学习一下怎么编程?
作者:
秦晓蕊
时间:
2013-8-16 09:35
clear%数据输入huanghe_p=[370503434575490420560640558343326405446423422697598377435472451667601689541485425389382707422];huanghe_t=[5157135867537205677179878104894535896395685959828495196156525999418939997587016305615201040 535];%归一化处理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=[p(1:5);p(6:10);p(11:15);p(16:20)];tn=[t(1:5);t(6:10);t(11:15);t(16:20)];for i=1:length(s) net=newff(minmax(pn),[s(i),4],{'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),[no,4],{'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=[p(11:15);p(16:20);p(21:25);p(26:30)];yuce=sim(net,input);%结果反归一化y1=[y(1,
y(2,
y(3,
y(4,
];yuce1=[yuce(1,
yuce(2,
yuce(3,
yuce(4,
];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:')
欢迎光临 研发埠 (http://bbs.yanfabu.com/)
Powered by Discuz! X3.2