How can I get a decent number of samples VS train error graph in neural networks?

1 view (last 30 days)
Hello;
I am trying to obtain the graph for number of samples VS training error. The graph I would like to have is like this
I am trying to do this by using the batch training with 'trainlm' algorithm. The code I have written is the following:
clc, clear all, close all;
for ctr=1:20
% number of samples is ctr
input = linspace(-3,3,ctr);
Target = tanh(input);
% define the net
net=feedforwardnet(1,'trainlm');
% initialize the net
net = init(net);
% parameters are choosen
net.trainParam.epochs = 20;
net.trainParam.max_fail = 6;
% train the net
[net,tr]=train(net,input,Target);
% simulate the net
Y=sim(net,input);
% record the errors and corresponding number of samples
tperf(ctr) = tr.best_tperf;
bestperf(ctr) = tr.best_perf;
end
plot(tperf) xlabel('number of samples'); ylabel('error'); hold on plot(bestperf) legend('tperf','bestperf')
As you can see the error values are saved into an array with corresponding number of samples. However I end up with the graph like that:
It really makes sense that as the number of samples increases the training error will converge to some number, however I cannot do it in my code.
I am looking for your answer.
Yours Sincerely.

Answers (0)

Categories

Find more on Sequence and Numeric Feature Data Workflows 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!