Skip to content

Commit

Permalink
welford mean: protect against negative variances
Browse files Browse the repository at this point in the history
  • Loading branch information
tstastny authored and dagar committed Oct 5, 2022
1 parent fbef296 commit dc7f29e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/mathlib/math/WelfordMean.hpp
Expand Up @@ -58,6 +58,9 @@ class WelfordMean
// 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; }
Expand Down

0 comments on commit dc7f29e

Please sign in to comment.