This commit is contained in:
toni
2018-01-24 11:44:59 +01:00
22 changed files with 1025 additions and 77 deletions

View File

@@ -11,5 +11,6 @@
#include "distribution/NormalN.h"
#include "distribution/Rectangular.h"
#include "distribution/NormalCDF.h"
#include "distribution/Const.h"
#endif // DISTRIBUTIONS_H

28
math/distribution/Const.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef DISTRIBUTION_CONST_H
#define DISTRIBUTION_CONST_H
namespace Distribution {
/** uniform distribution */
template <typename T> class Const {
const T val;
public:
/** ctor */
Const(const T val) : val(val) {
}
/** get a constant value */
T draw() {
return val;
}
};
}
#endif // DISTRIBUTION_CONST_H

View File

@@ -25,9 +25,11 @@ namespace Distribution {
/** ctor */
Normal(const T mu, const T sigma) :
mu(mu), sigma(sigma), _a(1.0 / (sigma * std::sqrt(2.0 * M_PI))), gen(RANDOM_SEED), dist(mu,sigma) {
}
#warning "analyze issue when coping an existing distribution and using draw() afterwards. this seems to yield issues"
/** ctor with seed */
Normal(const T mu, const T sigma, const uint32_t seed) :
mu(mu), sigma(sigma), _a(1.0 / (sigma * std::sqrt(2.0 * M_PI))), gen(seed), dist(mu,sigma) {
}
/** do not allow copy. this will not work as expected for std::normal_distribution when using draw() ?! */

View File

@@ -27,6 +27,12 @@ namespace Distribution {
Uniform(const T min, const T max) : gen(RANDOM_SEED), dist(min, max) {
}
/** ctor with seed */
Uniform(const T min, const T max, const uint32_t seed) : gen(seed), dist(min, max) {
}
/** get a uniformaly distributed random number */
T draw() {
return dist(gen);

View File

@@ -1,5 +1,5 @@
#ifndef RANDOM_Random::RandomGenerator_H
#define RANDOM_Random::RandomGenerator_H
#ifndef RANDOM_Random_RandomGenerator_H
#define RANDOM_Random_RandomGenerator_H
#include <random>
#include <chrono>
@@ -26,4 +26,4 @@ namespace Random {
}
#endif // K_MATH_RANDOM_Random::RandomGenerator_H
#endif // RANDOM_Random_RandomGenerator_H