62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef DIST_REGION_H
|
||
#define DIST_REGION_H
|
||
|
||
#include <cmath>
|
||
#include <random>
|
||
#include "../random/RandomGenerator.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
|