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:
@@ -6,5 +6,6 @@
|
||||
#include "distribution/Logistic.h"
|
||||
#include "distribution/Uniform.h"
|
||||
#include "distribution/VonMises.h"
|
||||
#include "distribution/Region.h"
|
||||
|
||||
#endif // DISTRIBUTIONS_H
|
||||
|
||||
@@ -47,6 +47,11 @@ public:
|
||||
;
|
||||
}
|
||||
|
||||
/** change the seed */
|
||||
void setSeed(const uint64_t seed) {
|
||||
gen.seed(seed);
|
||||
}
|
||||
|
||||
/** reset */
|
||||
void reset() {
|
||||
cumProbability = 0;
|
||||
|
||||
@@ -50,7 +50,8 @@ public:
|
||||
// interpolate
|
||||
const int idx1 = (idx2 > 0) ? (idx2 - 1) : (idx2);
|
||||
const float percent = (key - entries[idx1].key) / (float) (entries[idx2].key - entries[idx1].key);
|
||||
return entries[idx1].value + (entries[idx2].value - entries[idx1].value) * percent;
|
||||
const Value res = entries[idx1].value + (entries[idx2].value - entries[idx1].value) * percent;
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
43
math/Median.h
Normal file
43
math/Median.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef MEDIAN_H
|
||||
#define MEDIAN_H
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
template <typename Scalar> class Median {
|
||||
|
||||
private:
|
||||
|
||||
/** all scalar values in a sorted order (ascending) */
|
||||
std::vector<Scalar> sorted;
|
||||
|
||||
public:
|
||||
|
||||
/** add the given scalar value to the median calculation */
|
||||
void add(const Scalar value) {
|
||||
|
||||
const auto idx = std::upper_bound( sorted.begin(), sorted.end(), value );
|
||||
sorted.insert( idx, value );
|
||||
|
||||
}
|
||||
|
||||
/** get the median of all added values */
|
||||
float get() const {
|
||||
|
||||
if (sorted.size() % 2 == 1) { // odd
|
||||
|
||||
const int idx = sorted.size()/2;
|
||||
return sorted[idx];
|
||||
|
||||
} else { // even
|
||||
|
||||
const int idx0 = sorted.size()/2 - 1;
|
||||
return (sorted[idx0] + sorted[idx0+1]) / 2;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // MEDIAN_H
|
||||
@@ -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