added exponential distrbution + tests

new shortest-path walker (still todo)
modified dijkstra-path (new helper methods)
This commit is contained in:
2016-02-07 13:32:19 +01:00
parent 5b35b5d3e0
commit 6346231a64
5 changed files with 339 additions and 5 deletions

View File

@@ -1,4 +1,52 @@
#ifndef EXPONENTIAL_H
#define EXPONENTIAL_H
#include <cmath>
#include <random>
namespace Distribution {
/** exponential distribution */
template <typename T> class Exponential {
private:
const T lambda;
std::minstd_rand gen;
std::exponential_distribution<T> dist;
public:
/** ctor */
Exponential(const T lambda) : lambda(lambda), dist(lambda) {
;
}
/** get probability for the given value */
T getProbability(const T val) const {
return getProbability(lambda, val);
}
/** get an exponentially 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 lambda, const T val) {
return (val < 0) ? (0) : (lambda * std::exp( -lambda * val ));
}
};
}
#endif // EXPONENTIAL_H