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
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include "../Math.h"
|
||||
#include "../DrawList.h"
|
||||
|
||||
namespace Distribution {
|
||||
|
||||
@@ -38,6 +39,29 @@ namespace Distribution {
|
||||
return samples[idx];
|
||||
}
|
||||
|
||||
/** get a DrawList for this LUT to draw random values out of it */
|
||||
DrawList<Scalar> getDrawList() {
|
||||
DrawList<Scalar> dl;
|
||||
for (int idx = 0; idx < (int) samples.size(); ++idx) {
|
||||
const Scalar val = idxToVal(idx);
|
||||
const Scalar prob = samples[idx];
|
||||
dl.add(val, prob);
|
||||
}
|
||||
return dl;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/** convert value [min:max] to index [0:numSamples] */
|
||||
inline int valToIdx(const Scalar val) const {
|
||||
return ((val - min) * numSamples / diff);
|
||||
}
|
||||
|
||||
/** convert index [0:numSamples] to value [min:max] */
|
||||
inline Scalar idxToVal(const int idx) const {
|
||||
return min + (idx * diff / numSamples);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** build the look-up-table */
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
#include <random>
|
||||
#include "../Random.h"
|
||||
#include "../../Assertions.h"
|
||||
|
||||
namespace Distribution {
|
||||
|
||||
@@ -46,6 +47,7 @@ namespace Distribution {
|
||||
|
||||
/** 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);
|
||||
|
||||
51
math/distribution/Region.h
Normal file
51
math/distribution/Region.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user