welford mean: protect against negative variances

This commit is contained in:
Thomas Stastny 2022-09-28 17:48:53 +02:00 committed by Daniel Agar
parent fbef296890
commit dc7f29e2ec
No known key found for this signature in database
GPG Key ID: FD3CBA98017A69DE

View File

@ -58,6 +58,9 @@ public:
// M2 aggregates the squared distance from the mean
// count aggregates the number of samples seen so far
_M2 += delta.emult(new_value - _mean);
// protect against floating point precision causing negative variances
_M2 = matrix::max(_M2, {});
}
bool valid() const { return _count > 2; }