MathHelper.cpp
Go to the documentation of this file.
1 
18 #include "helper/MathHelper.h"
19 #include <random>
20 
22 
24  {
25  }
26 
28  {
29  }
30 
31  void MathHelper::drawNormal(const Eigen::VectorXd& mean, const Eigen::MatrixXd& cov, unsigned int amount, std::vector<Eigen::VectorXd>& samples)
32  {
33  Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> solver(cov);
34  Eigen::MatrixXd t = solver.eigenvectors() * solver.eigenvalues().cwiseSqrt().asDiagonal();
35  std::default_random_engine generator(0); // set fixed seed so the same data gets plotted the same way every time
36  std::normal_distribution<double> distr;
37  samples.resize(amount);
38  for (unsigned int i = 0; i < amount; i++) {
39  Eigen::VectorXd randomvect(mean.size());
40  for (unsigned int i = 0; i < randomvect.size(); i++) randomvect[i] = distr(generator);
41  samples.at(i) = mean + t * randomvect;
42  }
43  }
44 
45  void MathHelper::calcHistogram(double lower, double upper, unsigned int buckets, std::vector<double> in, std::vector<std::pair<double, double>>& out)
46  {
47  out.resize(buckets);
48  double range = std::abs(lower) + std::abs(upper);
49  double bucketsize = range / buckets;
50 
51  for (unsigned int i = 0; i < buckets; i++)
52  {
53  out.at(i).first = lower + (i * bucketsize);
54  out.at(i).second = 0;
55  }
56  for (double sample: in)
57  {
58  if (lower <= sample && sample <= upper) {
59  unsigned int bucket = ((double) (sample - lower)) / bucketsize;
60  if (0 <= bucket && bucket < buckets) out.at(bucket).second++;
61  }
62  }
63  }
64 
65 }
static void drawNormal(const Eigen::VectorXd &mean, const Eigen::MatrixXd &cov, unsigned int amount, std::vector< Eigen::VectorXd > &samples)
Definition: MathHelper.cpp:31
static void calcHistogram(double lower, double upper, unsigned int buckets, std::vector< double > in, std::vector< std::pair< double, double >> &out)
Definition: MathHelper.cpp:45


asr_psm
Author(s): Braun Kai, Gehrung Joachim, Heizmann Heinrich, Meißner Pascal
autogenerated on Fri Nov 15 2019 03:57:54