|
是这样的,给你个例子吧
- close all
- clear
- echo on
- clc
- %BP建模
- %原始数据归一化
- m_data=[1047.92 1047.83 0.39 0.39 1.0 3500 5075;
- 1047.83 1047.68 0.39 0.40 1.0 3452 4912;
- 1047.68 1047.52 0.40 0.41 1.0 3404 4749;
- 1047.52 1047.27 0.41 0.42 1.0 3356 4586;
- 1047.27 1047.41 0.42 0.43 1.0 3308 4423;
- 1046.73 1046.74 1.70 1.80 0.75 2733 2465;
- 1046.74 1046.82 1.80 1.78 0.75 2419 2185;
- 1046.82 1046.73 1.78 1.75 0.75 2105 1905;
- 1046.73 1046.48 1.75 1.85 0.70 1791 1625;
- 1046.48 1046.03 1.85 1.82 0.70 1477 1345;
- 1046.03 1045.33 1.82 1.68 0.70 1163 1065;
- 1045.33 1044.95 1.68 1.71 0.70 849 785;
- 1044.95 1045.21 1.71 1.72 0.70 533 508;
- 1045.21 1045.64 1.72 1.70 0.70 567 526;
- 1045.64 1045.44 1.70 1.69 0.70 601 544;
- 1045.44 1045.78 1.69 1.69 0.70 635 562;
- 1045.78 1046.20 1.69 1.52 0.75 667 580];
- %定义网络输入p和期望输出t
- pause
- clc
- p1=m_data(:,1:5);
- t1=m_data(:,6:7);
- p=p1';t=t1';
- [pn,minp,maxp,tn,mint,maxt]=premnmx(p,t)
- %设置网络隐单元的神经元数(5~30验证后5个最好)
- n=5;
- %建立相应的BP网络
- pause
- clc
- net=newff(minmax(pn),[n,2],{'tansig','purelin'},'traingdm');
- inputWeights=net.IW{1,1};
- inputbias=net.b{1};
- layerWeights=net.IW{1,1};
- layerbias=net.b{2};
- pause
- clc
- % 训练网络
- net.trainParam.show=50;
- net.trainParam.lr=0.05;
- net.trainParam.mc=0.9;
- net.trainParam.epochs=200000;
- net.trainParam.goal=1e-3;
- pause
- clc
- %调用TRAINGDM算法训练BP网络
- net=train(net,pn,tn);
- %对BP网络进行仿真
- A=sim(net,pn);
- E=A-tn;
- M=sse(E)
- N=mse(E)
- pause
- clc
- p2=[1046.20 1046.05 1.52 1.538 0.75;
- 1046.05 1046.85 1.538 1.510 0.75;
- 1046.85 1046.60 1.510 1.408 0.75;
- 1046.60 1046.77 1.408 1.403 0.75;
- 1046.77 1047.18 1.403 1.319 0.75];
- p2=p2';
- p2n=tramnmx(p2,minp,maxp);
- a2n=sim(net,p2n);
- a2=postmnmx(a2n,mint,maxt)
- echo off
- pause
- clc
复制代码 |
|