Gaussian.h
Go to the documentation of this file.
1 
18 #pragma once
19 
20 #include <boost/shared_ptr.hpp>
21 #include <iostream>
22 #include <iomanip>
23 #include <string>
24 #include <map>
25 #include <random>
26 #include <cmath>
27 
28 namespace ASR
29 {
30 
31  class Gaussian
32  {
33  private:
34  double mean;
35  double var;
36 
37  public:
38 
45  Gaussian(double mean, double variance)
46  {
47  this->mean = mean;
48  this->var = variance;
49  }
50 
51 
58  {
59  std::random_device rd;
60  std::mt19937 gen(rd());
61 
62  // values near the mean are the most likely
63  // standard deviation affects the dispersion of generated values from the mean
64  std::normal_distribution<> d(mean, var);
65 
66  return d(gen);
67  }
68 
74  void sampleRandomValues(std::vector<float> &v, int n)
75  {
76  assert(n > 0);
77  //assert(v != nullptr);
78 
79  std::random_device rd;
80  std::mt19937 gen(rd());
81 
82  // values near the mean are the most likely
83  // standard deviation affects the dispersion of generated values from the mean
84  std::normal_distribution<> d(mean, var);
85 
86  for (int i = 0; i < n; i++)
87  {
88  v.push_back( d(gen) );
89  }
90  }
91 
92 
93 
94  private:
99  void test()
100  {
101  std::random_device rd;
102  std::mt19937 gen(rd());
103  std::normal_distribution<> d(mean, var);
104 
105  std::map<int, int> hist;
106  for(int n=0; n<10000; ++n)
107  {
108  ++hist[std::round(d(gen))];
109  }
110  for(auto p : hist)
111  {
112  std::cout << std::fixed << std::setprecision(1) << std::setw(2)
113  << p.first << ' ' << std::string(p.second/200, '*') << '\n';
114  }
115  }
116 
117 
118  };
119 
121 
122 
123 
124 }
d
Gaussian(double mean, double variance)
Definition: Gaussian.h:45
double mean
Definition: Gaussian.h:34
boost::shared_ptr< Gaussian > GaussianPtr
Definition: Gaussian.h:120
double var
Definition: Gaussian.h:35
float sampleRandomValue()
Definition: Gaussian.h:57
void sampleRandomValues(std::vector< float > &v, int n)
Definition: Gaussian.h:74
void test()
Definition: Gaussian.h:99


asr_recognizer_prediction_psm
Author(s): Braun Kai, Meißner Pascal
autogenerated on Wed Feb 19 2020 03:31:28