This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/math/distribution/Normal.h
FrankE a2c9e575a2 huge commit
- worked on about everything
- grid walker using plugable modules
- wifi models
- new distributions
- worked on geometric data-structures
- added typesafe timestamps
- worked on grid-building
- added sensor-classes
- added sensor analysis (step-detection, turn-detection)
- offline data reader
- many test-cases
2016-08-29 08:18:44 +02:00

61 lines
1.2 KiB
C++

#ifndef NORMAL_H
#define NORMAL_H
#include <cmath>
#include <random>
#include "../Random.h"
#include "../../Assertions.h"
namespace Distribution {
/** normal distribution */
template <typename T> class Normal {
private:
const T mu;
const T sigma;
const T _a;
RandomGenerator gen;
std::normal_distribution<T> dist;
public:
/** ctor */
Normal(const T mu, const T sigma) :
mu(mu), sigma(sigma), _a(1.0 / (sigma * std::sqrt(2.0 * M_PI))), gen(RANDOM_SEED), dist(mu,sigma) {
}
/** get probability for the given value */
T getProbability(const T val) const {
const T b = -0.5 * ((val-mu)/sigma) * ((val-mu)/sigma);
return _a * std::exp(b);
}
/** get a normally distributed random number */
T draw() {
return dist(gen);
}
/** set the seed to use */
void setSeed(const long seed) {
gen.seed(seed);
}
/** get the probability for the given value */
static T getProbability(const T mu, const T sigma, const T val) {
Assert::isTrue(sigma > 0, "sigma must be >= 0");
const T a = 1.0 / (sigma * std::sqrt(2.0 * M_PI));
const T b = -0.5 * ((val-mu)/sigma) * ((val-mu)/sigma);
return a * std::exp(b);
}
};
}
#endif // NORMAL_H