36 GaussianDistribution::GaussianDistribution(
const double mean,
const double standardDeviation) {
38 p_stdev = standardDeviation;
50 double GaussianDistribution::Probability(
const double value) {
52 return std::exp(-0.5 * std::pow((value - p_mean) / p_stdev, 2)) / (std::sqrt(2 *
PI) * p_stdev);
64 double GaussianDistribution::CumulativeDistribution(
const double value) {
66 if(value == DBL_MIN) {
69 else if(value == DBL_MAX) {
75 double x = (value - p_mean) / p_stdev;
82 for(
int n = 0; pre != sum; n++) {
85 sum += std::pow(x, 2 * n + 1) / (fact * (2 * n + 1) * std::pow(-2.0, n));
90 return 50.0 + 100.0 / std::sqrt(2.0 *
PI) * sum;
106 double GaussianDistribution::InverseCumulativeDistribution(
const double percent) {
108 static double lowCutoff = 2.425;
109 static double highCutoff = 97.575;
111 if((percent < 0.0) || (percent > 100.0)) {
112 string m =
"Argument percent outside of the range 0 to 100 in";
113 m +=
" [GaussianDistribution::InverseCumulativeDistribution]";
125 else if(percent == 100.0) {
129 if(percent < lowCutoff) {
130 double q = std::sqrt(-2.0 * std::log(percent / 100.0));
133 else if(percent < highCutoff) {
134 double q = percent / 100.0 - 0.5,
139 double q = std::sqrt(-2.0 * std::log(1.0 - percent / 100.0));
140 x = -1.0 * C(q) / D(q);
145 double e = CumulativeDistribution(p_stdev * x + p_mean) - percent;
146 double u = e * std::sqrt(2.0 *
PI) * std::exp(-0.5 * x * x);
147 x = x - u / (1 + 0.5 * x * u);
149 return p_stdev * x + p_mean;
156 double GaussianDistribution::A(
const double x) {
157 static const double a[6] = { -39.69683028665376,
165 return((((a[0] * x + a[1]) * x + a[2]) * x + a[3]) * x + a[4]) * x + a[5];
168 double GaussianDistribution::B(
const double x) {
169 static const double b[6] = { -54.47609879822406,
177 return((((b[0] * x + b[1]) * x + b[2]) * x + b[3]) * x + b[4]) * x + b[5];
180 double GaussianDistribution::C(
const double x) {
181 static const double c[6] = { -0.007784894002430293,
189 return((((c[0] * x + c[1]) * x + c[2]) * x + c[3]) * x + c[4]) * x + c[5];
192 double GaussianDistribution::D(
const double x) {
193 static const double d[5] = { 0.007784695709041462,
200 return(((d[0] * x + d[1]) * x + d[2]) * x + d[3]) * x + d[4];
const double PI
The mathematical constant PI.
Namespace for the standard library.
#define _FILEINFO_
Macro for the filename and line number.
Namespace for ISIS/Bullet specific routines.