Mean square error (MSE) and performance in training record not correct?

2 vues (au cours des 30 derniers jours)
Roberto
Roberto le 30 Juin 2016
Commenté : Roberto le 30 Juin 2016
I noticed that performances in the training record of a neural network are always consistently different from perfomances calculated manually. It looks like the numbers in training record are not calculated directly with the performance function of the net. Here's some code:
First, I train a neural network
x = (0:0.1:10);
t = sin(x);
net = fitnet(6);
[net,trainingrecord] = train(net,x,t);
y = net(x);
then I manually calculate the performance of the net on the test sample
for i = 1:size(trainingrecord.testInd,2)
test_y(i) = y(1,trainingrecord.testInd(i));
test_t(i) = t(1,trainingrecord.testInd(i));
end;
manualperf = 0;
for i = 1:size(trainingrecord.testInd,2)
manualperf = manualperf + (test_y(i)-test_t(i))^2;
end;
manualperf = manualperf/size(trainingrecord.testInd,2);
This is the same performance, calculated by perform function and they are exactly the same:
autoperf = perform(net,test_y,test_t);
isequal(autoperf,manualperf)
ans =
1
But they both differ from trainingrecord.best_tperf
>> autoperf
autoperf =
1.129785002584019e-06
>> manualperf
manualperf =
1.129785002584019e-06
>> tr.best_tperf
ans =
1.129785002584038e-06
>> isequal(autoperf,manualperf,trainingrecord.best_tperf)
ans =
0
It looks like the performance in the training record is not calculated straightfowardly by calling the perform function or maybe there is some kind of error accumulated through the code. Any ideas?

Réponse acceptée

José-Luis
José-Luis le 30 Juin 2016
Modifié(e) : José-Luis le 30 Juin 2016
It appears to be well within the realm of numerical precision. You shouldn't be comparing doubles directly. It will break your heart. The fact that the first comparison worked might be a small miracle in and of itself.
Please read the part about comparing floating point numbers in the above link.
  3 commentaires
José-Luis
José-Luis le 30 Juin 2016
When comparing, you should then use a tolerance, like they talk about in the link.
Please accept the answer that best solves your problem.
Roberto
Roberto le 30 Juin 2016
I'll accept your answer in a couple of days.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Sequence and Numeric Feature Data Workflows dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by