bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
bernoulli_dist.h
Go to the documentation of this file.
1#ifndef BERNOULLI_DIST_H
2#define BERNOULLI_DIST_H
3
5#include "bitrl/bitrl_types.h"
6
7#include <random>
8#include <vector>
9
10namespace bitrl
11{
12namespace utils::maths::stats
13{
14
19{
20public:
24 typedef bool result_type;
25
29 explicit BernoulliDist(real_t p = 0.5);
30
34 result_type sample() const;
35
39 result_type sample(uint_t seed) const;
40
44 std::vector<result_type> sample_many(uint_t size) const;
45
49 std::vector<result_type> sample_many(uint_t size, uint_t seed) const;
50
54 real_t mean() const { return p_; }
55
59 real_t variance() const { return p_ * (1.0 - p_); }
60
64 void reset() { dist_.reset(); }
65
69 void reset(real_t p);
70
71private:
72 real_t p_;
73 mutable std::bernoulli_distribution dist_;
74};
75
76}
77} // namespace bitrl
78
79#endif
class BernoulliDist. Wrapper to std::bernoulli_distribution
Definition bernoulli_dist.h:19
result_type sample() const
Sample from the distribution.
Definition bernoulli_dist.cpp:12
real_t mean() const
The mean value of the distribution.
Definition bernoulli_dist.h:54
void reset()
Reset the underlying distribution.
Definition bernoulli_dist.h:64
bool result_type
Definition bernoulli_dist.h:24
std::vector< result_type > sample_many(uint_t size) const
sample from the distribution
Definition bernoulli_dist.cpp:29
real_t variance() const
The STD of the distribution.
Definition bernoulli_dist.h:59
Definition bitrl_consts.h:14
double real_t
real_t
Definition bitrl_types.h:23
std::size_t uint_t
uint_t
Definition bitrl_types.h:43