BP神经网络MATLAB代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
BP神经网络matlab代码
p=[284528334488;283344884554;448845542928;455429283497;29283497 2261;...
349722616921;226169211391;692113913580;139135804451;35804451 2636;...
445126363471;263634713854;347138543556;385435562659;35562659 4335;...
265943352882;433528824084;433528821999;288219992889;19992889 2175;...
288921752510;217525103409;251034093729;340937293489;37293489 3172;...
348931724568;317245684015;]';
%====期望输出=======
t=[4554292834972261692113913580445126363471385435562659... 4335288240841999288921752510340937293489317245684015... 3666];
ptest=[284528334488;283344884554;448845542928;455429283497;29283497 2261;...
349722616921;226169211391;692113913580;139135804451;35804451 2636;...
445126363471;263634713854;347138543556;385435562659;35562659 4335;...
265943352882;433528824084;433528821999;288219992889;19992889 2175;...
288921752510;217525103409;251034093729;340937293489;37293489 3172;...
348931724568;317245684015;456840153666]';
[pn,minp,maxp,tn,mint,maxt]=premnmx(p,t);%将数据归一化
NodeNum1=20;%隐层第一层节点数
NodeNum2=40;%隐层第二层节点数
TypeNum=1;%输出维数
TF1='tansig';
TF2='tansig';
TF3='tansig';
net=newff(minmax(pn),[NodeNum1,NodeNum2,TypeNum],{TF1TF2 TF3},'traingdx');
%网络创建traingdm
net.trainParam.show=50;
net.trainParam.epochs=50000;%训练次数设置
net.trainParam.goal=1e-5;%训练所要达到的精度
net.trainParam.lr=0.01;%学习速率
net=train(net,pn,tn);
p2n=tramnmx(ptest,minp,maxp);%测试数据的归一化
an=sim(net,p2n);
[a]=postmnmx(an,mint,maxt)%数据的反归一化,即最终想得到的预测结果
plot(1:length(t),t,'o',1:length(t)+1,a,'+');
title('o表示预测值---*表示实际值')
grid on
m=length(a);%向量a的长度
t1=[t,a(m)];
error=t1-a;%误差向量
figure
plot(1:length(error),error,'-.')
title('误差变化图')
grid on
%结束
下面的是我把索
%======ÔʼÊý¾ÝÊäÈë========
p=[0.0358680.0385570.0220440.0171700.0104820.0120810.0037350.004663;0.0388910.039778
0.0181150.0184190.0098570.0105140.0059380.006051;0.0374130.0384490.0185320.0171410.010221 0.0101030.0089230.009008;0.0332140.0371330.0206900.0145240.0111610.0106640.0066470.007862;
0.0375960.0379980.0201270.0186020.0104910.0116430.0055090.004373;0.0303130.0340310.018255 0.0163330.0080200.0091640.0066560.004936;0.0366990.0371520.0202510.0154910.0121800.012924 0.0075200.008002;...
0.2809400.1993590.1128910.0797500.0619890.0477980.0390930.035339;0.2352230.1675010.095537 0.0674510.0518210.0407670.0356960.028659;0.2258100.1612220.0914630.0637270.0492210.038668 0.0327730.030023;0.2282550.1619520.0921190.0654410.0509320.0381480.0341810.028801;0.230465 0.1639260.0936220.0676940.0514080.0377460.0347800.030020;0.2338510.1675610.0958520.068036 0.0507980.0399780.0350310.029043;0.2359590.1691130.0969030.0679360.0516860.0389350.034297 0.032020;...
0.0182320.0140600.0059230.0040330.0007420.0058400.0018000.002859;0.0155060.0211870.008724 0.0067840.0025160.0024680.0042380.001484;0.0109790.0114670.0035370.0045270.0016230.002313 0.0019850.000662;0.0175400.0188050.0032210.0079770.0036650.0057530.0042850.003807;0.008817 0.0126570.0024340.0065130.0011920.0019030.0049040.003188;0.0124950.0161250.0064830.005098 0.0047510.0014300.0042500.004460;0.0081280.0200870.0064080.0102490.0045140.0027180.002576 0.002896;]';
%====ÆÚÍûÊä³ö=======
t=[000000000000001010101010101001010101010101];
ptest=[0.0399850.0401500.0229320.0148890.0102450.0103300.0072850.008245;0.0395970.041301 0.0210420.0172060.0090620.0107090.0043790.007461;0.0347410.0382610.0230350.0185850.009328 0.0099880.0075210.006008;...
0.2468790.1764940.1022420.0713890.0571930.0403130.0368370.030813;0.2569540.1800370.101773 0.0723390.0572040.0444510.0373170.033529;0.2809400.1993590.1128910.0797500.0619890.047798 0.0390930.035339;...
0.0161200.0141350.0017940.0051930.0023760.0015300.0021690.001995;0.0163150.0207470.006796 0.0059240.0043230.0038880.0059570.002633;0.0024230.0293810.0174550.0108740.0032110.002222 0.0045590.002341;]';
[pn,minp,maxp,tn,mint,maxt]=premnmx(p,t);%½«Êý¾Ý¹éÒ»»¯NodeNum1=20;%Òþ²ãµÚÒ»²ã½ÚµãÊý
NodeNum2=40;%Òþ²ãµÚ¶þ²ã½ÚµãÊý
TypeNum=1;%Êä³öάÊý
TF1='tansig';