]> git.localhorst.tv Git - blobs.git/blob - src/math/Distribution.hpp
introduce random genetic mutations
[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         void Mean(double m) noexcept { mean = m; }
20         double Mean() const noexcept { return mean; }
21         void StandardDeviation(double d) noexcept { stddev = d; }
22         double StandardDeviation() const noexcept { return stddev; }
23         double Variance() const noexcept { return stddev * stddev; }
24
25         /// convert uniform random value in [-1,1] to fake normal distribution
26         /// in [mean - 2 stdddev,mean + 2 stddev]
27         double FakeNormal(double uniform) const noexcept {
28                 return mean + (uniform * uniform * stddev) + std::abs(uniform * uniform * uniform) * stddev;
29         }
30
31 private:
32         double mean;
33         double stddev;
34
35 };
36
37 }
38 }
39
40 #endif