]> git.localhorst.tv Git - blobs.git/blob - src/math/Distribution.hpp
7f444f80b6065e703751d1912e9feea33462798e
[blobs.git] / src / math / Distribution.hpp
1 #ifndef BLOBS_MATH_DISTRIBUTION_HPP_
2 #define BLOBS_MATH_DISTRIBUTION_HPP_
3
4 #include <cmath>
5
6
7 namespace blobs {
8 namespace math {
9
10 class Distribution {
11
12 public:
13         Distribution(double mean = 0.0, double stddev = 1.0) noexcept
14         : mean(mean)
15         , stddev(stddev)
16         { }
17
18 public:
19         double Mean() const noexcept { return mean; }
20         double StandardDeviation() const noexcept { return stddev; }
21         double Variance() const noexcept { return stddev * stddev; }
22
23         /// convert uniform random value in [-1,1] to fake normal distribution
24         /// in [mean - 2 stdddev,mean + 2 stddev]
25         double FakeNormal(double uniform) const noexcept {
26                 return mean + (uniform * uniform * stddev) + std::abs(uniform * uniform * uniform) * stddev;
27         }
28
29 private:
30         double mean;
31         double stddev;
32
33 };
34
35 }
36 }
37
38 #endif