Fixed the running_stats object so that the variance can never be negative.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402366
This commit is contained in:
Davis King 2008-07-03 23:04:39 +00:00
parent 14ff48d30c
commit 3946767f6e

View File

@ -121,8 +121,14 @@ namespace dlib
<< "\n\tthis: " << this
);
const T temp = n/(n-1);
return temp*(sum_sqr - sum*sum);
T temp = n/(n-1);
temp = temp*(sum_sqr - sum*sum);
// make sure the variance is never negative. This might
// happen due to numerical errors.
if (temp >= 0)
return temp;
else
return 0;
}
T scale (