#include <GaussDistribution.h>
Public Member Functions | |
GaussDistribution (double precision=1e-4) | |
GaussDistribution (double mean, double stddev, double precision=1e-4) | |
bool | isValid () |
double | mean () |
double | part (double a) |
calculate the integral from -inf to a | |
double | partSigma (double a) |
calculate the integral from -inf to mean+a*stddev | |
double | prob (double a, double b) |
double | rho (double val) |
returns the density of probability for value val | |
void | setMean (double m) |
void | setStddev (double s) |
double | stddev () |
~GaussDistribution () | |
Protected Member Functions | |
double | _calcErrorFunction (double z) |
Calculate the prob integral between -infinity and z by Taylor serie. | |
Protected Attributes | |
double | _inv_stddev |
double | _mean |
double | _precision |
internal precision limit for Taylor serie |
QGpCoreTools::GaussDistribution::GaussDistribution | ( | double | precision = 1e-4 | ) |
precision is the maximum tolerated difference accepted for probabilities mean and sigma are set to 0
References _inv_stddev, _mean, _precision, and TRACE.
{ TRACE; _precision=precision; _mean=0; _inv_stddev=0; }
QGpCoreTools::GaussDistribution::GaussDistribution | ( | double | mean, |
double | stddev, | ||
double | precision = 1e-4 |
||
) |
Initialize the distribution by its basic parameters: mean or x0 stddev or sigma precision is the maximum tolerated difference accepted for probabilities
References _inv_stddev, _mean, _precision, mean(), stddev(), and TRACE.
{ TRACE; _mean=mean; _inv_stddev=1.0/stddev; _precision=precision; }
double QGpCoreTools::GaussDistribution::_calcErrorFunction | ( | double | z | ) | [protected] |
Calculate the prob integral between -infinity and z by Taylor serie.
References _precision, and TRACE.
{ TRACE; /* returns the value of intergral(-inf,z)[exp(-z^2/2)/sqrt(2*pi)] =1/2+1/sqrt(2*pi)*Somme(k=0,+inf)[((-1)^k*z^(2*k+1))/((2*k+1)*2^k*k!)] we calculate it by recurrence: Somme=Somme[n(k)/(2*k+1)] where n(k)=-n(k-1)*z^2/(2*k) with n(0)=z */ if(z<-5) return 0; if(z>5) return 1; double serie=0,dserie=1e99,n=z; int k=0; while(dserie>_precision || dserie<-_precision) { dserie=n/((k << 1)+1); serie+=dserie; k++; n=-n*z*z/(2*k); } return 0.5+0.398942280402*serie; }
bool QGpCoreTools::GaussDistribution::isValid | ( | ) | [inline] |
{return _inv_stddev!=0;}
double QGpCoreTools::GaussDistribution::mean | ( | ) | [inline] |
Referenced by GaussDistribution(), and QGpCoreTools::Random::normal().
{return _mean;}
double QGpCoreTools::GaussDistribution::part | ( | double | a | ) | [inline] |
calculate the integral from -inf to a
Referenced by StatGridAnalyser::on_freqScroll_valueChanged().
{ return _calcErrorFunction((a-_mean)*_inv_stddev); }
double QGpCoreTools::GaussDistribution::partSigma | ( | double | a | ) | [inline] |
calculate the integral from -inf to mean+a*stddev
{return _calcErrorFunction(a);}
double QGpCoreTools::GaussDistribution::prob | ( | double | a, |
double | b | ||
) | [inline] |
Return the probability of interval [a,b] calculate the integral from -inf to a and from -inf to b
{ return (_calcErrorFunction((b-_mean)*_inv_stddev) -_calcErrorFunction((a-_mean)*_inv_stddev)); }
double QGpCoreTools::GaussDistribution::rho | ( | double | val | ) |
returns the density of probability for value val
References _inv_stddev, _mean, QGpCoreTools::exp(), and TRACE.
Referenced by StatGridAnalyser::on_freqScroll_valueChanged().
{ TRACE; double delta=val-_mean; // 1/sqrt(2*M_PI)=0.398942280402 return 0.398942280402*_inv_stddev*exp(-delta*delta*0.5*_inv_stddev*_inv_stddev); }
void QGpCoreTools::GaussDistribution::setMean | ( | double | m | ) | [inline] |
{_mean=m;}
void QGpCoreTools::GaussDistribution::setStddev | ( | double | s | ) | [inline] |
{_inv_stddev=1.0/s;}
double QGpCoreTools::GaussDistribution::stddev | ( | ) | [inline] |
Referenced by GaussDistribution(), and QGpCoreTools::Random::normal().
{return 1.0/_inv_stddev;}
double QGpCoreTools::GaussDistribution::_inv_stddev [protected] |
Referenced by GaussDistribution(), and rho().
double QGpCoreTools::GaussDistribution::_mean [protected] |
Referenced by GaussDistribution(), and rho().
double QGpCoreTools::GaussDistribution::_precision [protected] |
internal precision limit for Taylor serie
Referenced by _calcErrorFunction(), and GaussDistribution().