不同反向传播算法的性能比较绘图
Performance comparison plotting for different Back propagation algorithms
我正在为同一数据集实施各种反向传播算法并尝试比较性能。我从以下教程中获得了相同的帮助。
https://nl.mathworks.com/help/nnet/ug/choose-a-multilayer-neural-network-training-function.html
我试着画图:
- 每个算法的均方误差与执行时间
- 收敛所需时间与每种算法的均方误差收敛目标
已使用以下代码来创建我的神经网络并且愿意知道如何实现上述两个图。
%Data
x=0:0.2:6*pi; y=sin(x);
p=con2seq(x); t=con2seq(y);
% Networks
net1=feedforwardnet(20,'trainlm');
net2=feedforwardnet(20,'traingd');
net2.iw{1,1}=net1.iw{1,1}; %set the same weights and biases for the networks
net2.lw{2,1}=net1.lw{2,1};
net2.b{1}=net1.b{1};
net2.b{2}=net1.b{2};
%training and simulation
net1.trainParam.epochs=1; % set the number of epochs for the training
net2.trainParam.epochs=1;
net1=train(net1,p,t); % train the networks
net2=train(net2,p,t);
a11=sim(net1,p); a21=sim(net2,p); % simulate the networks with the input vector p
net1.trainParam.epochs=14;
net2.trainParam.epochs=14;
net1=train(net1,p,t);
net2=train(net2,p,t);
a12=sim(net1,p); a22=sim(net2,p);
net1.trainParam.epochs=985;
net2.trainParam.epochs=985;
net1=train(net1,p,t);
net2=train(net2,p,t);
a13=sim(net1,p); a23=sim(net2,p);
%plots
figure
subplot(3,3,1);
plot(x,y,'bx',x,cell2mat(a11),'r',x,cell2mat(a21),'g'); % plot the sine function and the output of the networks
title('1 epoch');
legend('target','trainlm','traingd');
subplot(3,3,2);
postregm(cell2mat(a11),y); % perform a linear regression analysis and plot the result
subplot(3,3,3);
postregm(cell2mat(a21),y);
%
subplot(3,3,4);
plot(x,y,'bx',x,cell2mat(a12),'r',x,cell2mat(a22),'g');
title('15 epochs');
legend('target','trainlm','traingd');
subplot(3,3,5);
postregm(cell2mat(a12),y);
subplot(3,3,6);
postregm(cell2mat(a22),y);
%
subplot(3,3,7);
plot(x,y,'bx',x,cell2mat(a13),'r',x,cell2mat(a23),'g');
title('1000 epochs');
legend('target','trainlm','traingd');
subplot(3,3,8);
postregm(cell2mat(a13),y);
subplot(3,3,9);
postregm(cell2mat(a23),y);
请注意,如果未指定误差度量,则默认使用 MSE。
训练时你可以这样做:
[net tr] = train(net, x, t);
然后绘制tr.perf
或tr.tperf
或tr.vperf
我正在为同一数据集实施各种反向传播算法并尝试比较性能。我从以下教程中获得了相同的帮助。
https://nl.mathworks.com/help/nnet/ug/choose-a-multilayer-neural-network-training-function.html
我试着画图:
- 每个算法的均方误差与执行时间
- 收敛所需时间与每种算法的均方误差收敛目标
已使用以下代码来创建我的神经网络并且愿意知道如何实现上述两个图。
%Data
x=0:0.2:6*pi; y=sin(x);
p=con2seq(x); t=con2seq(y);
% Networks
net1=feedforwardnet(20,'trainlm');
net2=feedforwardnet(20,'traingd');
net2.iw{1,1}=net1.iw{1,1}; %set the same weights and biases for the networks
net2.lw{2,1}=net1.lw{2,1};
net2.b{1}=net1.b{1};
net2.b{2}=net1.b{2};
%training and simulation
net1.trainParam.epochs=1; % set the number of epochs for the training
net2.trainParam.epochs=1;
net1=train(net1,p,t); % train the networks
net2=train(net2,p,t);
a11=sim(net1,p); a21=sim(net2,p); % simulate the networks with the input vector p
net1.trainParam.epochs=14;
net2.trainParam.epochs=14;
net1=train(net1,p,t);
net2=train(net2,p,t);
a12=sim(net1,p); a22=sim(net2,p);
net1.trainParam.epochs=985;
net2.trainParam.epochs=985;
net1=train(net1,p,t);
net2=train(net2,p,t);
a13=sim(net1,p); a23=sim(net2,p);
%plots
figure
subplot(3,3,1);
plot(x,y,'bx',x,cell2mat(a11),'r',x,cell2mat(a21),'g'); % plot the sine function and the output of the networks
title('1 epoch');
legend('target','trainlm','traingd');
subplot(3,3,2);
postregm(cell2mat(a11),y); % perform a linear regression analysis and plot the result
subplot(3,3,3);
postregm(cell2mat(a21),y);
%
subplot(3,3,4);
plot(x,y,'bx',x,cell2mat(a12),'r',x,cell2mat(a22),'g');
title('15 epochs');
legend('target','trainlm','traingd');
subplot(3,3,5);
postregm(cell2mat(a12),y);
subplot(3,3,6);
postregm(cell2mat(a22),y);
%
subplot(3,3,7);
plot(x,y,'bx',x,cell2mat(a13),'r',x,cell2mat(a23),'g');
title('1000 epochs');
legend('target','trainlm','traingd');
subplot(3,3,8);
postregm(cell2mat(a13),y);
subplot(3,3,9);
postregm(cell2mat(a23),y);
请注意,如果未指定误差度量,则默认使用 MSE。
训练时你可以这样做:
[net tr] = train(net, x, t);
然后绘制tr.perf
或tr.tperf
或tr.vperf