8#include <boost/random/beta_distribution.hpp>
15namespace utils::maths::stats
23template <
typename RealType = real_t>
class BetaDist
26 static_assert(std::is_floating_point<RealType>::value,
"Not a floating point type");
67 result_type mean()
const {
return dist_.alpha() / (dist_.alpha() + dist_.beta()); }
102 mutable boost::random::beta_distribution<RealType> dist_;
105template <
typename RealType>
113 dist_ = boost::random::beta_distribution<RealType>(
a,
b);
118 auto a = dist_.alpha();
119 auto b = dist_.beta();
126 std::random_device
rd{};
127 std::mt19937
gen{
rd()};
134 std::mt19937
gen{seed};
138template <
typename RealType>
142 std::vector<RealType>
samples(size);
143 std::random_device
rd{};
144 std::mt19937
gen{
rd()};
154template <
typename RealType>
158 std::vector<RealType>
samples(size);
159 std::mt19937
gen(seed);
172 auto alpha = dist_.alpha();
173 auto beta = dist_.beta();
175 return std::pow(x, alpha - 1) * std::pow(1.0 - x, beta - 1.0) /
beta_func;
The beta distribution is a real-valued distribution which produces values in the range [0,...
Definition beta_dist.h:24
result_type alpha() const
Returns the alpha parameter of the distribution.
Definition beta_dist.h:78
result_type beta() const
Returns the beta parameter of the distribution.
Definition beta_dist.h:83
result_type variance() const
The variance of the distribution. see https://en.wikipedia.org/wiki/Beta_distribution.
Definition beta_dist.h:116
RealType result_type
Definition beta_dist.h:31
result_type sample() const
Sample from the distribution.
Definition beta_dist.h:123
void reset()
Reset the underlying distribution.
Definition beta_dist.h:88
result_type pdf(result_type x) const
compute the value of the PDF at the given point
Definition beta_dist.h:169
std::vector< result_type > sample_many(uint_t size) const
sample from the distribution
Definition beta_dist.h:139
BetaDist(result_type alpha=1.0, result_type std=1.0)
Constructor.
Definition beta_dist.h:106
result_type mean() const
The mean value of the distribution see https://en.wikipedia.org/wiki/Beta_distribution.
Definition beta_dist.h:67
T sqr(const T &v)
Definition math_utils.h:61
OutT resolve(const std::string &name, const std::map< std::string, std::any > &input)
Definition std_map_utils.h:25
Definition bitrl_consts.h:14
std::size_t uint_t
uint_t
Definition bitrl_types.h:43