1#ifndef BITSIM_MATHS_STATISTICS_DISTRIBUTIONS_BETA_DIST_H
2#define BITSIM_MATHS_STATISTICS_DISTRIBUTIONS_BETA_DIST_H
7#include <boost/random/beta_distribution.hpp>
22template <
typename RealType = real_t>
class BetaDist
25 static_assert(std::is_floating_point<RealType>::value,
"Not a floating point type");
66 result_type mean()
const {
return dist_.alpha() / (dist_.alpha() + dist_.beta()); }
101 mutable boost::random::beta_distribution<RealType> dist_;
104template <
typename RealType>
112 dist_ = boost::random::beta_distribution<RealType>(a, b);
117 auto a = dist_.alpha();
118 auto b = dist_.beta();
119 return a * b / (
maths::sqr(a + b) * (a + b + 1));
125 std::random_device rd{};
126 std::mt19937 gen{rd()};
133 std::mt19937 gen{seed};
137template <
typename RealType>
141 std::vector<RealType> samples(size);
142 std::random_device rd{};
143 std::mt19937 gen{rd()};
145 for (
uint_t i = 0; i < size; ++i)
147 samples[i] = dist_(gen);
153template <
typename RealType>
157 std::vector<RealType> samples(size);
158 std::mt19937 gen(seed);
160 for (
uint_t i = 0; i < size; ++i)
162 samples[i] = dist_(gen);
171 auto alpha = dist_.alpha();
172 auto beta = dist_.beta();
174 return std::pow(x,
alpha - 1) * std::pow(1.0 - x,
beta - 1.0) / beta_func;
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
result_type beta() const
Returns the beta parameter of the distribution.
Definition beta_dist.h:82
BetaDist(result_type alpha=1.0, result_type std=1.0)
Constructor.
Definition beta_dist.h:105
std::vector< result_type > sample_many(uint_t size) const
sample from the distribution
Definition beta_dist.h:138
result_type sample() const
Sample from the distribution.
Definition beta_dist.h:122
RealType result_type
The return type every time we call pdf, sample.
Definition beta_dist.h:30
result_type mean() const
The mean value of the distribution see https://en.wikipedia.org/wiki/Beta_distribution.
Definition beta_dist.h:66
result_type pdf(result_type x) const
compute the value of the PDF at the given point
Definition beta_dist.h:168
result_type variance() const
The variance of the distribution. see https://en.wikipedia.org/wiki/Beta_distribution.
Definition beta_dist.h:115
result_type alpha() const
Returns the alpha parameter of the distribution.
Definition beta_dist.h:77
void reset()
Reset the underlying distribution.
Definition beta_dist.h:87
Definition bernoulli_dist.cpp:6
T sqr(const T &v)
Definition math_utils.h:60
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40