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

#include <probdist.hpp>

Public Member Functions

double quantile_dist (double probability)
 Compute the quantile of the standard normal distribution. More...
 
double normal_PDF (double x, double mean, double stddev)
 Compute the probability density function (PDF) for the normal distribution. More...
 
double normal_CDF (double x, double mean, double stddev)
 Compute the cumulative distribution function (CDF) for the normal distribution. More...
 
double uniform_CDF (size_t k, size_t n)
 Compute the cumulative distribution function (CDF) for the uniform distribution. More...
 
double exp_PDF (double x, size_t k, double lambda)
 Compute the probability density function (PDF) for the exponential distribution. More...
 
double emp_CDF (const std::vector< double > &data, double x)
 Compute the empirical cumulative distribution function (CDF) for a given value. More...
 
double emp_PMF (const std::vector< double > &data, double x)
 Compute the empirical probability mass function (PMF) for a given value. More...
 
double inverse_emp_CDF (const std::vector< double > &data, double p)
 Compute the inverse of the empirical cumulative distribution function (CDF) for a given probability. More...
 
double mle (const std::vector< double > &data)
 Compute the Maximum Likelihood Estimate (MLE) for the mean of a dataset. More...
 
double mom (const std::vector< double > &data)
 Compute the method of moments (MOM) estimate for the mean of a dataset. More...
 
double mle_est (const std::vector< double > &data)
 Placeholder function for M-estimation. More...
 
double mumv (const std::vector< double > &data)
 Compute the Mean-Unbiased Minimum-Variance (MUMV) estimate for the mean of a dataset. More...
 
double median_uniased (const std::vector< double > &data)
 Compute the median-unbiased estimate for the median of a dataset. More...
 
std::pair< double, double > ConfidenceInterval (const std::vector< double > &data, double alpha)
 Compute the confidence interval for the mean of a dataset. More...
 
double Pivot (const std::vector< double > &data, double pivotFunction(const std::vector< double > &))
 Compute the value of a pivot function for interval estimation. More...
 
double PivotFunctionForConfidenceInterval (const std::vector< double > &data)
 Example pivot function for computing a confidence interval. More...
 
std::pair< double, double > LikelihoodInterval (const std::vector< double > &data, double alpha)
 Compute the likelihood interval for a given dataset and significance level. More...
 
std::pair< double, double > PredictionInterval (const std::vector< double > &data, double alpha)
 Compute the prediction interval for a given dataset and significance level. More...
 
std::pair< double, double > ToleranceInterval (const std::vector< double > &data, double alpha)
 Compute the tolerance interval for a given dataset and significance level. More...
 

Detailed Description

Definition at line 42 of file probdist.hpp.

Member Function Documentation

◆ ConfidenceInterval()

std::pair< double, double > gpmp::stats::ProbDist::ConfidenceInterval ( const std::vector< double > &  data,
double  alpha 
)

Compute the confidence interval for the mean of a dataset.

Parameters
dataThe dataset
alphaThe confidence level
Returns
A pair representing the lower and upper bounds of the confidence interval

Definition at line 253 of file probdist.cpp.

254  {
255  if (data.empty() || alpha <= 0.0 || alpha >= 1.0) {
256  return {0.0, 0.0}; // Invalid input, return an empty interval
257  }
258 
259  size_t n = data.size();
261  double mean = desc.mean_arith(data);
262  double stddev = desc.stdev(data, mean);
263 
264  // Assuming a normal distribution for simplicity
265  double z = quantile_dist(1 - alpha / 2.0);
266  double margin = z * stddev / std::sqrt(static_cast<double>(n));
267 
268  return {mean - margin, mean + margin};
269 }
A class providing methods for descriptive statistics.
Definition: describe.hpp:44
static double stdev(const std::vector< double > &data, double mean)
Calculates the standard deviation of a given dataset, given the mean.
Definition: describe.cpp:184
static double mean_arith(const std::vector< double > &data)
Calculates the arithmetic mean of a given dataset.
Definition: describe.cpp:52
double quantile_dist(double probability)
Compute the quantile of the standard normal distribution.
Definition: probdist.cpp:116

References gpmp::stats::Describe::mean_arith(), and gpmp::stats::Describe::stdev().

◆ emp_CDF()

double gpmp::stats::ProbDist::emp_CDF ( const std::vector< double > &  data,
double  x 
)

Compute the empirical cumulative distribution function (CDF) for a given value.

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

Definition at line 168 of file probdist.cpp.

169  {
170  size_t count = 0;
171  for (const auto &value : data) {
172  if (value <= x) {
173  count++;
174  }
175  }
176 
177  return static_cast<double>(count) / data.size();
178 }

◆ emp_PMF()

double gpmp::stats::ProbDist::emp_PMF ( const std::vector< double > &  data,
double  x 
)

Compute the empirical probability mass function (PMF) for a given value.

Parameters
dataThe dataset
xThe value at which to evaluate the empirical PMF
Returns
The empirical PMF value at the given point

Definition at line 180 of file probdist.cpp.

181  {
182  size_t count = std::count(data.begin(), data.end(), x);
183  return static_cast<double>(count) / data.size();
184 }

◆ exp_PDF()

double gpmp::stats::ProbDist::exp_PDF ( double  x,
size_t  k,
double  lambda 
)

Compute the probability density function (PDF) for the exponential distribution.

Parameters
xThe value at which to evaluate the PDF
kThe shape parameter of the distribution
lambdaThe rate parameter of the distribution
Returns
The PDF value at the given point

Definition at line 150 of file probdist.cpp.

150  {
151  // Check if k is valid (k must be 1 for exponential distribution)
152  if (k != 1) {
153  // Return 0 if k is not 1, as exponential distribution is only defined
154  // for k = 1
155  return 0.0;
156  }
157 
158  // Check if lambda is non-positive
159  if (lambda <= 0) {
160  // Return 0 if lambda is non-positive
161  return 0.0;
162  }
163 
164  // Calculate the exponential PDF
165  return (k / lambda) * exp(-k * x);
166 }

◆ inverse_emp_CDF()

double gpmp::stats::ProbDist::inverse_emp_CDF ( const std::vector< double > &  data,
double  p 
)

Compute the inverse of the empirical cumulative distribution function (CDF) for a given probability.

Parameters
dataThe dataset
pThe probability value between 0 and 1
Returns
The value at which the empirical CDF is equal to or greater than the given probability

Definition at line 186 of file probdist.cpp.

187  {
188  if (data.empty() || p < 0.0 || p > 1.0) {
189  return 0.0; // Invalid input, return 0
190  }
191 
192  std::vector<double> sortedData = data;
193  std::sort(sortedData.begin(), sortedData.end());
194 
195  size_t index = static_cast<size_t>(p * (data.size() - 1));
196  return sortedData[index];
197 }

◆ LikelihoodInterval()

std::pair< double, double > gpmp::stats::ProbDist::LikelihoodInterval ( const std::vector< double > &  data,
double  alpha 
)

Compute the likelihood interval for a given dataset and significance level.

Parameters
dataThe dataset
alphaThe significance level
Returns
A pair representing the lower and upper bounds of the likelihood interval

Definition at line 294 of file probdist.cpp.

295  {
296  // Example implementation, this needs to be adapted based on the specific
297  // likelihood function
298  if (data.empty() || alpha <= 0.0 || alpha >= 1.0) {
299  return {0.0, 0.0}; // Invalid input, return an empty interval
300  }
301 
302  // Placeholder, implement likelihood function and find confidence bounds
303  double lowerBound = 0.0;
304  double upperBound = 1.0;
305 
306  return {lowerBound, upperBound};
307 }

◆ median_uniased()

double gpmp::stats::ProbDist::median_uniased ( const std::vector< double > &  data)

Compute the median-unbiased estimate for the median of a dataset.

Parameters
dataThe dataset
Returns
The median-unbiased estimate for the median

Definition at line 235 of file probdist.cpp.

235  {
236  if (data.empty()) {
237  return 0.0; // Invalid input, return 0
238  }
239 
240  std::vector<double> sortedData = data;
241  std::sort(sortedData.begin(), sortedData.end());
242 
243  size_t size = sortedData.size();
244  if (size % 2 == 0) {
245  return (sortedData[size / 2 - 1] + sortedData[size / 2]) / 2.0;
246  } else {
247  return sortedData[size / 2];
248  }
249 }

◆ mle()

double gpmp::stats::ProbDist::mle ( const std::vector< double > &  data)

Compute the Maximum Likelihood Estimate (MLE) for the mean of a dataset.

Parameters
dataThe dataset
Returns
The MLE estimate for the mean

Definition at line 199 of file probdist.cpp.

199  {
200  if (data.empty()) {
201  return 0.0; // Invalid input, return 0
202  }
203 
204  double sum = std::accumulate(data.begin(), data.end(), 0.0);
205  return sum / data.size();
206 }

◆ mle_est()

double gpmp::stats::ProbDist::mle_est ( const std::vector< double > &  data)

Placeholder function for M-estimation.

Parameters
dataThe dataset
Returns
The M-estimation result

Definition at line 220 of file probdist.cpp.

220  {
221  // This is a placeholder, you can replace it with a specific M-estimation
222  // method
223  return mle(data);
224 }
double mle(const std::vector< double > &data)
Compute the Maximum Likelihood Estimate (MLE) for the mean of a dataset.
Definition: probdist.cpp:199

◆ mom()

double gpmp::stats::ProbDist::mom ( const std::vector< double > &  data)

Compute the method of moments (MOM) estimate for the mean of a dataset.

Parameters
dataThe dataset
Returns
The MOM estimate for the mean

Definition at line 208 of file probdist.cpp.

208  {
209  if (data.empty()) {
210  return 0.0; // Invalid input, return 0
211  }
213 
214  double mean = desc.mean_arith(data);
215  double variance = desc.variance(data, mean);
216 
217  return mean - variance / 2.0;
218 }
static double variance(const std::vector< double > &data, double mean)
Calculates the variance of a given dataset, given the mean.
Definition: describe.cpp:194

References gpmp::stats::Describe::mean_arith(), and gpmp::stats::Describe::variance().

◆ mumv()

double gpmp::stats::ProbDist::mumv ( const std::vector< double > &  data)

Compute the Mean-Unbiased Minimum-Variance (MUMV) estimate for the mean of a dataset.

Parameters
dataThe dataset
Returns
The MUMV estimate for the mean

Definition at line 226 of file probdist.cpp.

226  {
227  if (data.empty()) {
228  return 0.0; // Invalid input, return 0
229  }
230 
231  double sum = std::accumulate(data.begin(), data.end(), 0.0);
232  return sum / data.size();
233 }

◆ normal_CDF()

double gpmp::stats::ProbDist::normal_CDF ( double  x,
double  mean,
double  stddev 
)

Compute the cumulative distribution function (CDF) for the normal distribution.

Parameters
xThe value at which to evaluate the CDF
meanThe mean of the distribution
stddevThe standard deviation of the distribution
Returns
The CDF value at the given point

Definition at line 135 of file probdist.cpp.

135  {
136  // Implement the cumulative distribution function (CDF) for the normal
137  // distribution You can use standard libraries or existing implementations
138  // for this calculation Example using C++ standard library:
139  return 0.5 * (1.0 + std::erf((x - mean) / (stddev * std::sqrt(2.0))));
140 }

◆ normal_PDF()

double gpmp::stats::ProbDist::normal_PDF ( double  x,
double  mean,
double  stddev 
)

Compute the probability density function (PDF) for the normal distribution.

Parameters
xThe value at which to evaluate the PDF
meanThe mean of the distribution
stddevThe standard deviation of the distribution
Returns
The PDF value at the given point

Definition at line 127 of file probdist.cpp.

127  {
128  // Implement the probability density function (PDF) for the normal
129  // distribution You can use standard libraries or existing implementations
130  // for this calculation Example using C++ standard library:
131  double exponent = -0.5 * std::pow((x - mean) / stddev, 2.0);
132  return (1.0 / (stddev * std::sqrt(2.0 * M_PI))) * std::exp(exponent);
133 }

◆ Pivot()

double gpmp::stats::ProbDist::Pivot ( const std::vector< double > &  data,
double   pivotFunctionconst std::vector< double > & 
)

Compute the value of a pivot function for interval estimation.

Parameters
dataThe dataset
pivotFunctionThe pivot function to evaluate
Returns
The value of the pivot function

Definition at line 271 of file probdist.cpp.

273  {
274  if (data.empty()) {
275  return 0.0; // Invalid input, return 0
276  }
277 
278  return pivotFunction(data);
279 }

◆ PivotFunctionForConfidenceInterval()

double gpmp::stats::ProbDist::PivotFunctionForConfidenceInterval ( const std::vector< double > &  data)

Example pivot function for computing a confidence interval.

Parameters
dataThe dataset
Returns
The value of the pivot function for a confidence interval

Definition at line 282 of file probdist.cpp.

283  {
284  size_t n = data.size();
285 
287  double mean = desc.mean_arith(data);
288  double stddev = desc.stdev(data, mean);
289 
290  return mean + 2 * stddev / std::sqrt(static_cast<double>(n));
291 }

References gpmp::stats::Describe::mean_arith(), and gpmp::stats::Describe::stdev().

◆ PredictionInterval()

std::pair< double, double > gpmp::stats::ProbDist::PredictionInterval ( const std::vector< double > &  data,
double  alpha 
)

Compute the prediction interval for a given dataset and significance level.

Parameters
dataThe dataset
alphaThe significance level
Returns
A pair representing the lower and upper bounds of the prediction interval

Definition at line 310 of file probdist.cpp.

311  {
312  if (data.empty() || alpha <= 0.0 || alpha >= 1.0) {
313  return {0.0, 0.0}; // Invalid input, return an empty interval
314  }
315 
316  // Placeholder, implement prediction interval calculation
317  double lowerBound = 0.0;
318  double upperBound = 1.0;
319 
320  return {lowerBound, upperBound};
321 }

◆ quantile_dist()

double gpmp::stats::ProbDist::quantile_dist ( double  probability)

Compute the quantile of the standard normal distribution.

Parameters
probabilityThe probability value between 0 and 1
Returns
The quantile corresponding to the given probability

Definition at line 116 of file probdist.cpp.

116  {
117  if (probability <= 0.0 || probability >= 1.0) {
118  return 0.0; // Invalid input, return 0
119  }
120 
121  // Using erfinv for older C++ standards
122  double z = std::sqrt(2.0) * erfinv(2.0 * probability - 1.0);
123 
124  return z;
125 }
float erfinv(float a)
Definition: probdist.cpp:47

References erfinv().

◆ ToleranceInterval()

std::pair< double, double > gpmp::stats::ProbDist::ToleranceInterval ( const std::vector< double > &  data,
double  alpha 
)

Compute the tolerance interval for a given dataset and significance level.

Parameters
dataThe dataset
alphaThe significance level
Returns
A pair representing the lower and upper bounds of the tolerance interval

Definition at line 324 of file probdist.cpp.

325  {
326  if (data.empty() || alpha <= 0.0 || alpha >= 1.0) {
327  return {0.0, 0.0}; // Invalid input, return an empty interval
328  }
329 
330  // Placeholder, implement tolerance interval calculation
331  double lowerBound = 0.0;
332  double upperBound = 1.0;
333 
334  return {lowerBound, upperBound};
335 }

◆ uniform_CDF()

double gpmp::stats::ProbDist::uniform_CDF ( size_t  k,
size_t  n 
)

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

Parameters
kThe value at which to evaluate the CDF
nThe maximum value in the uniform distribution
Returns
The CDF value at the given point

Definition at line 142 of file probdist.cpp.

142  {
143  if (k == 0 || k > n) {
144  return 0.0; // Invalid input, return 0
145  }
146 
147  return static_cast<double>(k) / (n + 1);
148 }

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