bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bernoulli_dist.h
Go to the documentation of this file.
1#ifndef BITSIM_MATHS_STATISTICS_DISTRIBUTIONS_BERNOULLI_DIST_H
2#define BITSIM_MATHS_STATISTICS_DISTRIBUTIONS_BERNOULLI_DIST_H
3
5
6#include <random>
7#include <vector>
8
9namespace bitsim
10{
11namespace maths::stats
12{
13
18{
19 public:
23 using result_type = bool;
24
28 explicit BernoulliDist(real_t p = 0.5);
29
33 result_type sample() const;
34
38 result_type sample(uint_t seed) const;
39
43 std::vector<result_type> sample_many(uint_t size) const;
44
48 std::vector<result_type> sample_many(uint_t size, uint_t seed) const;
49
53 real_t mean() const { return p_; }
54
58 real_t variance() const { return p_ * (1.0 - p_); }
59
63 void reset() { dist_.reset(); }
64
68 void reset(real_t p);
69
70 private:
71 real_t p_;
72 mutable std::bernoulli_distribution dist_;
73};
74
75} // namespace maths::stats
76} // namespace bitsim
77
78#endif // BITSIM_MATHS_STATISTICS_DISTRIBUTIONS_BERNOULLI_DIST_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
result_type sample() const
Sample from the distribution.
Definition bernoulli_dist.cpp:10
std::vector< result_type > sample_many(uint_t size) const
sample from the distribution
Definition bernoulli_dist.cpp:27
void reset()
Reset the underlying distribution.
Definition bernoulli_dist.h:63
real_t variance() const
The STD of the distribution.
Definition bernoulli_dist.h:58
real_t mean() const
The mean value of the distribution.
Definition bernoulli_dist.h:53
bool result_type
The return type every time we call pdf, sample.
Definition bernoulli_dist.h:23
BernoulliDist(real_t p=0.5)
Constructor.
Definition bernoulli_dist.cpp:8
Definition bernoulli_dist.cpp:6
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20