Add fake percentile computation in util::statistics_lite based on normal distribution
This commit is contained in:
parent
100e2d6af8
commit
44d30a6f8d
1 changed files with 13 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/math/special_functions/erf.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
@ -52,6 +54,8 @@ namespace psemek::util
|
||||||
T min() const { return min_; }
|
T min() const { return min_; }
|
||||||
T max() const { return max_; }
|
T max() const { return max_; }
|
||||||
|
|
||||||
|
T percentile(double p) const;
|
||||||
|
|
||||||
template <typename H>
|
template <typename H>
|
||||||
friend statistics_lite<H> merge(statistics_lite<H> const & s1, statistics_lite<H> const & s2);
|
friend statistics_lite<H> merge(statistics_lite<H> const & s1, statistics_lite<H> const & s2);
|
||||||
|
|
||||||
|
|
@ -93,6 +97,15 @@ namespace psemek::util
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T statistics_lite<T>::percentile(double p) const
|
||||||
|
{
|
||||||
|
// Assume normal distribution
|
||||||
|
// TODO: use a better distribution, maybe maximizing entropy on [0, +inf)
|
||||||
|
// See https://en.wikipedia.org/wiki/Differential_entropy#Alternative_proof
|
||||||
|
return boost::math::erf_inv(2.0 * p - 1) * var() * std::sqrt(2.0) + mean();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
statistics_lite<T> merge(statistics_lite<T> const & s1, statistics_lite<T> const & s2)
|
statistics_lite<T> merge(statistics_lite<T> const & s1, statistics_lite<T> const & s2)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue