This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/math/distribution/Region.h

52 lines
1.0 KiB
C++

#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