add Bessel's correction to stdev calculation

Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
This commit is contained in:
slaren 2023-08-16 00:25:59 +02:00 committed by GitHub
parent 6ab6971242
commit 52b94f42c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -63,7 +63,7 @@ T stddev(const std::vector<T>& v) {
} }
T mean = avg(v); T mean = avg(v);
T sq_sum = std::inner_product(v.begin(), v.end(), v.begin(), T(0)); T sq_sum = std::inner_product(v.begin(), v.end(), v.begin(), T(0));
T stdev = std::sqrt(sq_sum / (T)v.size() - mean * mean); T stdev = std::sqrt(sq_sum / (T)(v.size() - 1) - mean * mean * (T)v.size() / (T)(v.size() - 1));
return stdev; return stdev;
} }