31 void MathHelper::drawNormal(
const Eigen::VectorXd& mean,
const Eigen::MatrixXd& cov,
unsigned int amount, std::vector<Eigen::VectorXd>& samples)
33 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> solver(cov);
34 Eigen::MatrixXd t = solver.eigenvectors() * solver.eigenvalues().cwiseSqrt().asDiagonal();
35 std::default_random_engine generator(0);
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;
45 void MathHelper::calcHistogram(
double lower,
double upper,
unsigned int buckets, std::vector<double> in, std::vector<std::pair<double, double>>& out)
48 double range = std::abs(lower) + std::abs(upper);
49 double bucketsize = range / buckets;
51 for (
unsigned int i = 0; i < buckets; i++)
53 out.at(i).first = lower + (i * bucketsize);
56 for (
double sample: in)
58 if (lower <= sample && sample <= upper) {
59 unsigned int bucket = ((double) (sample - lower)) / bucketsize;
60 if (0 <= bucket && bucket < buckets) out.at(bucket).second++;
static void drawNormal(const Eigen::VectorXd &mean, const Eigen::MatrixXd &cov, unsigned int amount, std::vector< Eigen::VectorXd > &samples)
static void calcHistogram(double lower, double upper, unsigned int buckets, std::vector< double > in, std::vector< std::pair< double, double >> &out)