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

조회 수: 4 (최근 30일)
Roberto
Roberto 2016년 6월 30일
댓글: Roberto 2016년 6월 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.
Roberto
Roberto 2016년 6월 30일
I'll accept your answer in a couple of days.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel and Cloud에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by