神经网络bp函数拟合不准。
Show older comments
初学神经网络试着玩下函数拟合,
随便写个函数y=x1.*x1-x2.^3+3*x1.*x2-2*x2+1;
之后用x1x2和计算的y值反推上函数(就是明知道函数是啥,就想用神经网络再给算出来)
训练数据经过神经网络算的结果与预期值相差不大;
!!!关键是换用其他数据后结果偏差的完全没法看,
最可气的是把没问题的训练数据的前50组重新作为新输入给网络计算结果又差的不能看
求大神解释!代码如下:
x1=unifrnd(-5,5,100,1);%随机生成100*1阵
x2=unifrnd(-5,5,100,1);
y=x1.*x1-x2.^3+3*x1.*x2-2*x2+1;%目标输出
in=[x1,x2]';%目标输入
net=newff(minmax(in),[9,9,9,9,1],{'tansig','tansig','tansig','tansig','purelin'},'trainlm','learngdm','msereg');
net=init(net);
net.performFcn='sse';
net.trainParam.goal=0.01;
net.trainParam.show=20;
net.trainParam.epochs=50000;
net.trainParam.mc=0.95;
[net,tr]=train(net,in,y');
Y=sim(net,in);
plot(y'-Y)
x3=unifrnd(-5,5,100,1);%随机再生成一组数据验证函数准确性
x4=unifrnd(-5,5,100,1);
y2=x3.*x3-x4.^3+3*x3.*x4-2*x4+1;
in2=[x3,x4]';
Y2=net(in2);%把新输入用网络计算出输出
plot(y2'-Y2)%绘制误差图
Answers (0)
Categories
Find more on Two y-axis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!