ref #39 #40 moved all stuff left in KLib into Indoor. We are now able to perform localization without the need of KLib. Only K::Gnuplot is needed for drawing, but this will be separated into an own project in the future

This commit is contained in:
toni
2017-11-15 17:43:32 +01:00
parent 72932ad90f
commit c8063bc862
35 changed files with 340 additions and 100 deletions

View File

@@ -3,7 +3,7 @@
#include <cmath>
#include <random>
#include "../Random.h"
#include "../random/RandomGenerator.h"
namespace Distribution {
@@ -14,7 +14,7 @@ namespace Distribution {
const T lambda;
RandomGenerator gen;
Random::RandomGenerator gen;
std::exponential_distribution<T> dist;
public:

View File

@@ -8,7 +8,7 @@
#include <eigen3/Eigen/Dense>
#include "../../Assertions.h"
#include "../Random.h"
#include "../random/RandomGenerator.h"
namespace Distribution {

View File

@@ -3,7 +3,7 @@
#include <cmath>
#include <random>
#include "../Random.h"
#include "../random/RandomGenerator.h"
#include "../../Assertions.h"
namespace Distribution {
@@ -17,7 +17,7 @@ namespace Distribution {
const T sigma;
const T _a;
RandomGenerator gen;
Random::RandomGenerator gen;
std::normal_distribution<T> dist;
public:

View File

@@ -0,0 +1,65 @@
#ifndef NORMALCDF_H
#define NORMALCDF_H
#include <algorithm>
#include <random>
#include "../../Assertions.h"
namespace Distribution {
/** cumulative density version of the normal distribution */
template <typename T> class NormalCDF {
private:
const T mu;
const T sigma;
static T RationalApproximation(T t)
{
// Abramowitz and Stegun formula 26.2.23.
// The absolute value of the error should be less than 4.5 e-4.
T c[] = {2.515517, 0.802853, 0.010328};
T d[] = {1.432788, 0.189269, 0.001308};
return t - ((c[2]*t + c[1])*t + c[0]) /
(((d[2]*t + d[1])*t + d[0])*t + 1.0);
}
public:
/** create a new normally distributed CDF */
NormalCDF(const T mu, const T sigma) : mu(mu), sigma(sigma) {
;
}
/** get the probability for val within the underlying CDF */
T getProbability(const T val) const {
return getProbability(mu, sigma, val);
}
/** calculate the probability within the underlying CDF */
static T getProbability(const T mu, const T sigma, const T val) {
return (1.0 + std::exp( (val - mu) / (sigma * std::sqrt(2)) ) ) / 2.0;
}
/** get the inverse CDF (https://en.wikipedia.org/wiki/Probit)*/
static T getProbit(T p){
Assert::isBetween(p, 0.0, 1.0, "value not between");
// See: https://www.johndcook.com/blog/normal_cdf_inverse/
if (p < 0.5)
{
// F^-1(p) = - G^-1(p)
return -RationalApproximation( sqrt(-2.0*log(p)) );
}
else
{
// F^-1(p) = G^-1(1-p)
return RationalApproximation( sqrt(-2.0*log(1-p)) );
}
}
};
}
#endif // NORMALCDF_H

View File

@@ -7,7 +7,7 @@
#include <eigen3/Eigen/Dense>
#include "../../Assertions.h"
#include "../Random.h"
#include "../random/RandomGenerator.h"
namespace Distribution {
@@ -24,7 +24,7 @@ namespace Distribution {
const Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigenSolver;
Eigen::MatrixXd transform; //can i make this const?
RandomGenerator gen;
Random::RandomGenerator gen;
std::normal_distribution<> dist;
public:

View File

@@ -4,7 +4,7 @@
#include <cmath>
#include <random>
#include "../Random.h"
#include "../random/RandomGenerator.h"
#include "../../Assertions.h"
#include "Normal.h"

View File

@@ -3,7 +3,7 @@
#include <cmath>
#include <random>
#include "../Random.h"
#include "../random/RandomGenerator.h"
#include "../../Assertions.h"
#include "Normal.h"

View File

@@ -3,7 +3,7 @@
#include <cmath>
#include <random>
#include "../Random.h"
#include "../random/RandomGenerator.h"
#include "../../Assertions.h"
#include "Normal.h"

View File

@@ -3,7 +3,7 @@
#include <cmath>
#include <random>
#include "../Random.h"
#include "../random/RandomGenerator.h"
#include <type_traits>
@@ -14,7 +14,7 @@ namespace Distribution {
private:
RandomGenerator gen;
Random::RandomGenerator gen;
/** depending on T, Dist is either a uniform_real or uniform_int distribution */
typedef typename std::conditional< std::is_floating_point<T>::value, std::uniform_real_distribution<T>, std::uniform_int_distribution<T> >::type Dist;