フィルターのクリア

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

2 ビュー (過去 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 Center および File ExchangeParallel and Cloud についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by