- 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
52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
#ifndef DIST_REGION_H
|
|
#define DIST_REGION_H
|
|
|
|
#include <cmath>
|
|
#include <random>
|
|
#include "../Random.h"
|
|
#include "../../Assertions.h"
|
|
#include "Normal.h"
|
|
|
|
namespace Distribution {
|
|
|
|
/** normal distribution */
|
|
template <typename T> class Region {
|
|
|
|
private:
|
|
|
|
const T mu;
|
|
const T a;
|
|
const T h;
|
|
const T sigma;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
Region(const T mu, const T a) : mu(mu), a(a), h(1.0/(2*2*a)), sigma(std::exp(0) / (2*h*std::sqrt(2*M_PI))) {
|
|
|
|
}
|
|
|
|
/** get probability for the given value */
|
|
T getProbability(const T val) const {
|
|
const T diff = std::abs(val - mu);
|
|
if (diff < a) {return h;}
|
|
//if (diff < a+b) {const float p = 1.0f-(diff-a)/b; return p*h;}
|
|
//return 0;
|
|
const T diff2 = ((val - mu) < 0) ? (val - mu + a) : (val - mu - a);
|
|
return Distribution::Normal<T>::getProbability(0, sigma, diff2) / 2;
|
|
|
|
}
|
|
|
|
/** get the probability for the given value */
|
|
static T getProbability(const T mu, const T a, const T val) {
|
|
Region<T> dist(mu, a);
|
|
return dist.getProbability(val);
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
#endif // DIST_REGION_H
|