#ifndef DIST_REGION_H #define DIST_REGION_H #include #include #include "../Random.h" #include "../../Assertions.h" #include "Normal.h" namespace Distribution { /** normal distribution */ template 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::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 dist(mu, a); return dist.getProbability(val); } }; } #endif // DIST_REGION_H