下面是一个简单的BP人工神经网络的例子,用matlab工具箱实现。
clc
%输入变量
sqrs=[0.110027 0.063019 0.105534 0.129025 0.157431 0.231472 0.092534 0.18466 0.101555 0.064493];%GDP
sqjdcs=[0.117404 0.113465 0.074107 0.371856 0.223811 0.183649 0.078254 0.171919 0.057375 0.023523];%贸易增长率
sqglmj=[510610 561100 617150 678947 740940 805370 868880 929340 984610 103260];%移民
banquan=[2930 3983 4700 5691 7783 9365 10401 10293 10471 11133];
tushuchukou=[740 802 885.16 945.64 1144.18 2061.77 1992.86 1689.42 1552.63 1493];
youke=[472 610 789 1022 1322 1710 2213 2863 3704 4792];
%输出变量
%glkyl=[0.53724 0.46553 0.39716 0.33198 0.26983 0.21059 0.15411 0.10027 0.04894 0.00547];
glkyl=[12.0127 16.0014 20.0065 23.3646 25.2955 25.0689 22.2091 16.6766 8.9552 1.0498];%million
glhyl=[1237 1379 1385 1399 1663 1714 1834 4322 8132 8936];
p=[sqrs;sqjdcs;sqglmj;banquan;tushuchukou;youke];
t=[glkyl;glhyl];
[pn,minp,maxp,tn,mint,maxt]=premnmx(p,t);
dx=[-1,1;-1,1;-1,1;-1,1;-1,1;-1,1];
net=newff(dx,[6,36,2],{'tansig','tansig','purelin'},'traingdx');
net.trainParam.show=1000;
net.trainParam.Lr=0.05;
net.trainParam.epochs=50000;
net.trainParam.goal=0.65*10^(-3);
net=train(net,pn,tn);
%和原始数据进行对比
an=sim(net,pn);
a=postmnmx(an,mint,maxt);
x=(1999:2:2017);
newk=a(1,:);
newh=a(2,:);
figure(2);
subplot(2,1,1);plot(x,newk,'r-o',x,glkyl,'b--+');
legend('the result of learning','original data');
xlabel('year');ylabel('polulation/million');
title('population of the chinese speaker');
subplot(2,1,2);plot(x,newh,'r-o',x,glhyl,'b--+');
legend('666','777');
xlabel('888');ylabel('999');
title('000');
%预测
pnew=[3504091 15019105
564241.8 814241.8
2042466 4660125
30000 45000
1023.35 1021.33
100000 100000];
pnewn=tramnmx(pnew,minp,maxp);
anewn=sim(net,pnewn);
anew = postmnmx(anewn,mint,maxt)
运行时出现了点问题,虽然能比较好的拟合原数据,但是对于matlab提醒的警告还是不明所以,望赐教!
本文通过Matlab工具箱实现了一个简单的BP人工神经网络模型,用于预测人口数量及其它相关指标,并展示了如何处理数据和训练网络的过程。
1万+

被折叠的 条评论
为什么被折叠?



