started removing KLib related code:
- assertions - distributions new helper methods worked on stairs worked on grid-walkers worked on navigation
This commit is contained in:
4
math/distribution/Exponential.h
Normal file
4
math/distribution/Exponential.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef EXPONENTIAL_H
|
||||
#define EXPONENTIAL_H
|
||||
|
||||
#endif // EXPONENTIAL_H
|
||||
54
math/distribution/Exponential.h.autosave
Normal file
54
math/distribution/Exponential.h.autosave
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef EXPONENTIAL_H
|
||||
#define EXPONENTIAL_H
|
||||
|
||||
#include <cmath>
|
||||
#include <random>
|
||||
|
||||
namespace Distribution {
|
||||
|
||||
template <typename T> class Exponential {
|
||||
|
||||
private:
|
||||
|
||||
T lambda;
|
||||
|
||||
std::minstd_rand gen;
|
||||
std::exponential_distribution<T> dist;
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
Exponential(const T lambda) : lambda(lambda), gen(1234), dist(lambda) {
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/** get probability for the given value */
|
||||
T getProbability(const T val) const {
|
||||
return lambda * std::exp(-lambda * val);
|
||||
}
|
||||
|
||||
/** 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 double getProbability(const double lambda, const double val) {
|
||||
return lambda * std::exp(-lambda * val);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // EXPONENTIAL_H
|
||||
22
math/distribution/Logistic.h
Normal file
22
math/distribution/Logistic.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef LOGISTIC_H
|
||||
#define LOGISTIC_H
|
||||
|
||||
|
||||
namespace Distribution {
|
||||
|
||||
// https://de.wikipedia.org/wiki/Logistische_Verteilung
|
||||
template <typename T> class Logistic {
|
||||
|
||||
public:
|
||||
|
||||
/** alpha = move the center, beta = slope */
|
||||
static T getCDF(const T x, const T alpha, const T beta) {
|
||||
return 1 / (1 + std::exp( -((x-alpha)/beta) ) );
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LOGISTIC_H
|
||||
57
math/distribution/Normal.h
Normal file
57
math/distribution/Normal.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef NORMAL_H
|
||||
#define NORMAL_H
|
||||
|
||||
#include <cmath>
|
||||
#include <random>
|
||||
|
||||
namespace Distribution {
|
||||
|
||||
/** normal distribution */
|
||||
template <typename T> class Normal {
|
||||
|
||||
private:
|
||||
|
||||
const T mu;
|
||||
const T sigma;
|
||||
const T _a;
|
||||
|
||||
std::minstd_rand 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(1234), 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) {
|
||||
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
|
||||
Reference in New Issue
Block a user