openGPMP
Open Source Mathematics Package
Static Public Member Functions | List of all members
gpmp::stats::CDF Class Reference

Class providing methods for computing cumulative distribution functions (CDFs) More...

#include <cdfs.hpp>

Static Public Member Functions

static double bernoulli (double x, double p)
 Compute the cumulative distribution function (CDF) of the Bernoulli distribution. More...
 
static double beta (double x, double alpha, double beta)
 Compute the cumulative distribution function (CDF) of the beta distribution. More...
 
static double binomial (int k, int n, double p)
 Compute the cumulative distribution function (CDF) of the binomial distribution. More...
 
static double cauchy (double x, double x0, double gamma)
 Compute the cumulative distribution function (CDF) of the Cauchy distribution. More...
 
static double chi_squared (double x, double k)
 Compute the cumulative distribution function (CDF) of the chi-squared distribution. More...
 
static double exponential (double x, double lambda)
 Compute the cumulative distribution function (CDF) of the exponential distribution. More...
 
static double f (double x, double df1, double df2)
 Compute the cumulative distribution function (CDF) of the F distribution. More...
 
static double gamma (double x, double shape, double scale)
 Compute the cumulative distribution function (CDF) of the gamma distribution. More...
 
static double inverse_gamma (double x, double shape, double scale)
 Compute the cumulative distribution function (CDF) of the inverse-gamma distribution. More...
 
static double inverse_gaussian (double x, double mu, double lambda)
 Compute the cumulative distribution function (CDF) of the inverse-Gaussian distribution. More...
 
static double laplace (double x, double mu, double b)
 Compute the cumulative distribution function (CDF) of the Laplace distribution. More...
 
static double logistic (double x, double mu, double s)
 Compute the cumulative distribution function (CDF) of the logistic distribution. More...
 
static double log_normal (double x, double mu, double sigma)
 Compute the cumulative distribution function (CDF) of the log-normal distribution. More...
 
static double gaussian (double x, double mu, double sigma)
 Compute the cumulative distribution function (CDF) of the normal (Gaussian) distribution. More...
 
static double poisson (int k, double lambda)
 Compute the cumulative distribution function (CDF) of the Poisson distribution. More...
 
static double rademacher (double x)
 Compute the cumulative distribution function (CDF) of the Rademacher distribution. More...
 
static double student_t (double x, double df)
 Compute the cumulative distribution function (CDF) of Student's t distribution. More...
 
static double uniform (double x, double a, double b)
 Compute the cumulative distribution function (CDF) of the uniform distribution. More...
 
static double weibull (double x, double shape, double scale)
 Compute the cumulative distribution function (CDF) of the Weibull distribution. More...
 
static double normal_cdf (double x)
 Compute the cumulative distribution function (CDF) of the standard normal distribution. More...
 
static double incomplete_beta (double a, double b, double x)
 Compute the incomplete beta function. More...
 
static double incomplete_gamma (double a, double x)
 Compute the incomplete gamma function. More...
 

Detailed Description

Class providing methods for computing cumulative distribution functions (CDFs)

Definition at line 43 of file cdfs.hpp.

Member Function Documentation

◆ bernoulli()

double gpmp::stats::CDF::bernoulli ( double  x,
double  p 
)
static

Compute the cumulative distribution function (CDF) of the Bernoulli distribution.

Parameters
xThe value at which to evaluate the CDF
pThe probability parameter of the Bernoulli distribution
Returns
The CDF value at the given point

Definition at line 43 of file cdfs.cpp.

43  {
44  if (x < 0)
45  return 0.0;
46  else if (x < 1)
47  return 1 - (1 - p);
48  else
49  return 1.0;
50 }

Referenced by main().

◆ beta()

double gpmp::stats::CDF::beta ( double  x,
double  alpha,
double  beta 
)
static

Compute the cumulative distribution function (CDF) of the beta distribution.

Parameters
xThe value at which to evaluate the CDF
alphaThe alpha parameter of the beta distribution
betaThe beta parameter of the beta distribution
Returns
The CDF value at the given point

Definition at line 53 of file cdfs.cpp.

53  {
54  if (x <= 0)
55  return 0.0;
56  else if (x >= 1)
57  return 1.0;
58  else
59  return incomplete_beta(alpha, beta, x);
60 }
static double beta(double x, double alpha, double beta)
Compute the cumulative distribution function (CDF) of the beta distribution.
Definition: cdfs.cpp:53
static double incomplete_beta(double a, double b, double x)
Compute the incomplete beta function.
Definition: cdfs.cpp:201

Referenced by main().

◆ binomial()

double gpmp::stats::CDF::binomial ( int  k,
int  n,
double  p 
)
static

Compute the cumulative distribution function (CDF) of the binomial distribution.

Parameters
kThe number of successes
nThe number of trials
pThe probability of success in each trial
Returns
The CDF value at the given point

Definition at line 63 of file cdfs.cpp.

63  {
64  if (k < 0)
65  return 0.0;
66  else if (k >= n)
67  return 1.0;
68  else
69  return incomplete_beta(1.0 - p, n - k, k + 1);
70 }

Referenced by main().

◆ cauchy()

double gpmp::stats::CDF::cauchy ( double  x,
double  x0,
double  gamma 
)
static

Compute the cumulative distribution function (CDF) of the Cauchy distribution.

Parameters
xThe value at which to evaluate the CDF
x0The location parameter of the Cauchy distribution
gammaThe scale parameter of the Cauchy distribution
Returns
The CDF value at the given point

Definition at line 73 of file cdfs.cpp.

73  {
74  return 0.5 + atan((x - x0) / gamma) / M_PI;
75 }
static double gamma(double x, double shape, double scale)
Compute the cumulative distribution function (CDF) of the gamma distribution.
Definition: cdfs.cpp:102

Referenced by main().

◆ chi_squared()

double gpmp::stats::CDF::chi_squared ( double  x,
double  k 
)
static

Compute the cumulative distribution function (CDF) of the chi-squared distribution.

Parameters
xThe value at which to evaluate the CDF
kThe degrees of freedom parameter of the chi-squared distribution
Returns
The CDF value at the given point

Definition at line 78 of file cdfs.cpp.

78  {
79  if (x < 0)
80  return 0.0;
81  else
82  return incomplete_gamma(k / 2.0, x / 2.0);
83 }
static double incomplete_gamma(double a, double x)
Compute the incomplete gamma function.
Definition: cdfs.cpp:218

Referenced by main().

◆ exponential()

double gpmp::stats::CDF::exponential ( double  x,
double  lambda 
)
static

Compute the cumulative distribution function (CDF) of the exponential distribution.

Parameters
xThe value at which to evaluate the CDF
lambdaThe rate parameter of the exponential distribution
Returns
The CDF value at the given point

Definition at line 86 of file cdfs.cpp.

86  {
87  if (x < 0)
88  return 0.0;
89  else
90  return 1.0 - exp(-lambda * x);
91 }

Referenced by main().

◆ f()

double gpmp::stats::CDF::f ( double  x,
double  df1,
double  df2 
)
static

Compute the cumulative distribution function (CDF) of the F distribution.

Parameters
xThe value at which to evaluate the CDF
df1The numerator degrees of freedom parameter of the F distribution
df2The denominator degrees of freedom parameter of the F distribution
Returns
The CDF value at the given point

Definition at line 94 of file cdfs.cpp.

94  {
95  if (x <= 0)
96  return 0.0;
97  else
98  return incomplete_beta(df1 / 2.0, df2 / 2.0, df1 / (df1 + df2 * x));
99 }

Referenced by main().

◆ gamma()

double gpmp::stats::CDF::gamma ( double  x,
double  shape,
double  scale 
)
static

Compute the cumulative distribution function (CDF) of the gamma distribution.

Parameters
xThe value at which to evaluate the CDF
shapeThe shape parameter of the gamma distribution
scaleThe scale parameter of the gamma distribution
Returns
The CDF value at the given point

Definition at line 102 of file cdfs.cpp.

102  {
103  if (x < 0)
104  return 0.0;
105  else
106  return incomplete_gamma(shape, x / scale);
107 }

Referenced by main().

◆ gaussian()

double gpmp::stats::CDF::gaussian ( double  x,
double  mu,
double  sigma 
)
static

Compute the cumulative distribution function (CDF) of the normal (Gaussian) distribution.

Parameters
xThe value at which to evaluate the CDF
muThe mean parameter of the normal distribution
sigmaThe standard deviation parameter of the normal distribution
Returns
The CDF value at the given point

Definition at line 147 of file cdfs.cpp.

147  {
148  return 0.5 * (1 + erf((x - mu) / (sigma * sqrt(2))));
149 }

Referenced by main().

◆ incomplete_beta()

double gpmp::stats::CDF::incomplete_beta ( double  a,
double  b,
double  x 
)
static

Compute the incomplete beta function.

Parameters
aThe first parameter of the incomplete beta function
bThe second parameter of the incomplete beta function
xThe value at which to evaluate the incomplete beta function
Returns
The value of the incomplete beta function at the given point

Definition at line 201 of file cdfs.cpp.

201  {
202  const int maxIterations = 1000;
203  const double epsilon = 1e-12;
204  double result = 0.0;
205  double term = 1.0;
206  for (int k = 0; k < maxIterations; ++k) {
207  term *=
208  (k == 0 ? 1.0
209  : (a + k - 1) * (b - k) / (a + b + k - 1) * x / (k + 1));
210  result += term;
211  if (std::abs(term) < epsilon * std::abs(result))
212  break;
213  }
214  return result * std::pow(x, a) * std::pow(1 - x, b) / (a * std::beta(a, b));
215 }

◆ incomplete_gamma()

double gpmp::stats::CDF::incomplete_gamma ( double  a,
double  x 
)
static

Compute the incomplete gamma function.

Parameters
aThe shape parameter of the incomplete gamma function
xThe value at which to evaluate the incomplete gamma function
Returns
The value of the incomplete gamma function at the given point

Definition at line 218 of file cdfs.cpp.

218  {
219  const int maxIterations = 1000;
220  const double epsilon = 1e-12;
221  double result = 0.0;
222  double term = 1.0;
223  for (int k = 0; k < maxIterations; ++k) {
224  term *= x / (a + k);
225  result += term;
226  if (std::abs(term) < epsilon * std::abs(result))
227  break;
228  }
229  return exp(-x) * std::pow(x, a) * result / std::tgamma(a);
230 }

◆ inverse_gamma()

double gpmp::stats::CDF::inverse_gamma ( double  x,
double  shape,
double  scale 
)
static

Compute the cumulative distribution function (CDF) of the inverse-gamma distribution.

Parameters
xThe value at which to evaluate the CDF
shapeThe shape parameter of the inverse-gamma distribution
scaleThe scale parameter of the inverse-gamma distribution
Returns
The CDF value at the given point

Definition at line 110 of file cdfs.cpp.

110  {
111  if (x <= 0)
112  return 0.0;
113  else
114  return 1.0 - incomplete_gamma(shape, scale / x);
115 }

Referenced by main().

◆ inverse_gaussian()

double gpmp::stats::CDF::inverse_gaussian ( double  x,
double  mu,
double  lambda 
)
static

Compute the cumulative distribution function (CDF) of the inverse-Gaussian distribution.

Parameters
xThe value at which to evaluate the CDF
muThe mean parameter of the inverse-Gaussian distribution
lambdaThe shape parameter of the inverse-Gaussian distribution
Returns
The CDF value at the given point

Definition at line 118 of file cdfs.cpp.

118  {
119  if (x <= 0)
120  return 0.0;
121  else
122  return normal_cdf(sqrt(lambda / x) * (x / mu - 1.0));
123 }
static double normal_cdf(double x)
Compute the cumulative distribution function (CDF) of the standard normal distribution.
Definition: cdfs.cpp:196

Referenced by main().

◆ laplace()

double gpmp::stats::CDF::laplace ( double  x,
double  mu,
double  b 
)
static

Compute the cumulative distribution function (CDF) of the Laplace distribution.

Parameters
xThe value at which to evaluate the CDF
muThe location parameter of the Laplace distribution
bThe scale parameter of the Laplace distribution
Returns
The CDF value at the given point

Definition at line 126 of file cdfs.cpp.

126  {
127  if (x < mu)
128  return 0.5 * exp((x - mu) / b);
129  else
130  return 1.0 - 0.5 * exp(-(x - mu) / b);
131 }

Referenced by main().

◆ log_normal()

double gpmp::stats::CDF::log_normal ( double  x,
double  mu,
double  sigma 
)
static

Compute the cumulative distribution function (CDF) of the log-normal distribution.

Parameters
xThe value at which to evaluate the CDF
muThe mean parameter of the log-normal distribution
sigmaThe standard deviation parameter of the log-normal distribution
Returns
The CDF value at the given point

Definition at line 139 of file cdfs.cpp.

139  {
140  if (x <= 0)
141  return 0.0;
142  else
143  return 0.5 + 0.5 * erf((log(x) - mu) / (sqrt(2.0) * sigma));
144 }

Referenced by main().

◆ logistic()

double gpmp::stats::CDF::logistic ( double  x,
double  mu,
double  s 
)
static

Compute the cumulative distribution function (CDF) of the logistic distribution.

Parameters
xThe value at which to evaluate the CDF
muThe location parameter of the logistic distribution
sThe scale parameter of the logistic distribution
Returns
The CDF value at the given point

Definition at line 134 of file cdfs.cpp.

134  {
135  return 1.0 / (1.0 + exp(-(x - mu) / s));
136 }

Referenced by main().

◆ normal_cdf()

double gpmp::stats::CDF::normal_cdf ( double  x)
static

Compute the cumulative distribution function (CDF) of the standard normal distribution.

Parameters
xThe value at which to evaluate the CDF
Returns
The CDF value at the given point

Definition at line 196 of file cdfs.cpp.

196  {
197  return 0.5 * (1 + erf(x / sqrt(2.0)));
198 }

◆ poisson()

double gpmp::stats::CDF::poisson ( int  k,
double  lambda 
)
static

Compute the cumulative distribution function (CDF) of the Poisson distribution.

Parameters
kThe number of occurrences
lambdaThe rate parameter of the Poisson distribution
Returns
The CDF value at the given point

Definition at line 152 of file cdfs.cpp.

152  {
153  if (k < 0)
154  return 0.0;
155  else
156  return incomplete_gamma(k + 1, lambda);
157 }

Referenced by main().

◆ rademacher()

double gpmp::stats::CDF::rademacher ( double  x)
static

Compute the cumulative distribution function (CDF) of the Rademacher distribution.

Parameters
xThe value at which to evaluate the CDF
Returns
The CDF value at the given point

Definition at line 160 of file cdfs.cpp.

160  {
161  if (x < 0)
162  return 0.0;
163  else if (x < 0.5)
164  return 0.0;
165  else
166  return 1.0;
167 }

Referenced by main().

◆ student_t()

double gpmp::stats::CDF::student_t ( double  x,
double  df 
)
static

Compute the cumulative distribution function (CDF) of Student's t distribution.

Parameters
xThe value at which to evaluate the CDF
dfThe degrees of freedom parameter of Student's t distribution
Returns
The CDF value at the given point

Definition at line 170 of file cdfs.cpp.

170  {
171  if (df <= 0)
172  return NAN;
173  return 0.5 + 0.5 * std::tgamma((df + 1) / 2) * std::hypot(1, x / sqrt(df)) /
174  (sqrt(df) * std::tgamma(df / 2));
175 }

Referenced by main().

◆ uniform()

double gpmp::stats::CDF::uniform ( double  x,
double  a,
double  b 
)
static

Compute the cumulative distribution function (CDF) of the uniform distribution.

Parameters
xThe value at which to evaluate the CDF
aThe minimum value of the uniform distribution
bThe maximum value of the uniform distribution
Returns
The CDF value at the given point

Definition at line 178 of file cdfs.cpp.

178  {
179  if (x < a)
180  return 0.0;
181  else if (x < b)
182  return (x - a) / (b - a);
183  else
184  return 1.0;
185 }

Referenced by main().

◆ weibull()

double gpmp::stats::CDF::weibull ( double  x,
double  shape,
double  scale 
)
static

Compute the cumulative distribution function (CDF) of the Weibull distribution.

Parameters
xThe value at which to evaluate the CDF
shapeThe shape parameter of the Weibull distribution
scaleThe scale parameter of the Weibull distribution
Returns
The CDF value at the given point

Definition at line 188 of file cdfs.cpp.

188  {
189  if (x < 0)
190  return 0.0;
191  else
192  return 1.0 - exp(-pow(x / scale, shape));
193 }

Referenced by main().


The documentation for this class was generated from the following files: