clear
echo on
clc
%BP建模
%原始数据归一化
m_data=[1.5 0.08 3.8;
1.33 0.08 2.88;
1.20 0.08 2.43;
1.11 0.08 2.10;
1.50 0.12 3.30;
1.33 0.12 2.54;
1.20 0.12 2.12;
1.11 0.12 1.90;
1.50 0.16 3.00;
1.33 0.16 2.32;
1.20 0.16 1.95;
1.11 0.16 1.71;
1.50 0.20 2.80;
1.33 0.20 2.18;
1.20 0.20 1.84;
1.11 0.20 1.62;
1.50 0.24 2.67;
1.33 0.24 2.08;
1.20 0.24 1.77;
1.11 0.24 1.56;
1.50 0.28 2.57;
1.33 0.28 2.00;
1.20 0.28 1.70;
1.11 0.28 1.50;
1.50 0.32 2.48;
1.33 0.32 1.95;
1.20 0.32 1.66;
1.11 0.32 1.47;
1.50 0.36 2.40;
1.33 0.36 1.90;
1.20 0.36 1.63;
1.11 0.36 1.44;
1.50 0.40 2.36;
1.33 0.40 1.88;
1.20 0.40 1.59;
1.11 0.40 1.41;
1.50 0.44 2.31;
1.33 0.44 1.85;
1.20 0.44 1.56;
1.11 0.44 1.39;
1.50 0.48 2.27;
1.33 0.48 1.80;
1.20 0.48 1.53;
1.11 0.48 1.37;
1.50 0.52 2.21;
1.33 0.52 1.76;
1.20 0.52 1.49;
1.11 0.52 1.33];
%定义网络输入p和期望输出t
pause
clc
p1=m_data(:,1:2);
t1=m_data(:,3);
p=p1';t=t1';
[pn,minp,maxp,tn,mint,maxt]=premnmx(p,t)
%设置网络隐单元的神经元数(5~30验证后5个最好)
n=7;
%建立相应的BP网络
pause
clc
net=newff(minmax(pn),[n,1],{'logsig','purelin'},'trainlm');
inputWeights=net.IW{1,1};
inputbias=net.b{1};
layerWeights=net.LW{2,1};
layerbias=net.b{2};
pause
clc
% 训练网络
net.trainParam.show=10;
net.trainParam.lr=0.02;
net.trainParam.mc=0.9;
net.trainParam.epochs=2000;
net.trainParam.goal=1e-5;
pause
clc
%调用TRAINGDM算法训练BP网络
net=train(net,pn,tn);
[x2,y2]=meshgrid(1.1:0.05:1.5,0.08:0.05:0.52);
p3=[x2,y2];
x3=x2(:)';y3=y2(:)';
p4=[x3;y3];
p4n=tramnmx(p4,minp,maxp);
a4n=sim(net,p4n);
a4=postmnmx(a4n,mint,maxt);
figure;surf(p4,a4)
我已经用神经网络模拟出函数形势了,现在要画出函数的二维图和三维图,该怎么办啊,我上面的语句画出图了但是不对,好像是因为数据归依化的原因,能不能麻烦帮我看一下啊,哪错了,先谢谢了啊 |