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

2 次查看(过去 30 天)
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?

采纳的回答

José-Luis
José-Luis 2016-6-30
编辑:José-Luis 2016-6-30
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 个评论
José-Luis
José-Luis 2016-6-30
When comparing, you should then use a tolerance, like they talk about in the link.
Please accept the answer that best solves your problem.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by