49 t = fmaf(a, 0.0f - a, 1.0f);
51 if (fabsf(t) > 6.125f) {
53 p = fmaf(p, t, 2.93243101e-8f);
54 p = fmaf(p, t, 1.22150334e-6f);
55 p = fmaf(p, t, 2.84108955e-5f);
56 p = fmaf(p, t, 3.93552968e-4f);
57 p = fmaf(p, t, 3.02698812e-3f);
58 p = fmaf(p, t, 4.83185798e-3f);
59 p = fmaf(p, t, -2.64646143e-1f);
60 p = fmaf(p, t, 8.40016484e-1f);
63 p = fmaf(p, t, 1.43285448e-7f);
64 p = fmaf(p, t, 1.22774793e-6f);
65 p = fmaf(p, t, 1.12963626e-7f);
66 p = fmaf(p, t, -5.61530760e-5f);
67 p = fmaf(p, t, -1.47697632e-4f);
68 p = fmaf(p, t, 2.31468678e-3f);
69 p = fmaf(p, t, 1.15392581e-2f);
70 p = fmaf(p, t, -2.32015476e-1f);
71 p = fmaf(p, t, 8.86226892e-1f);
83 if (m < 0.666666667f) {
94 r = fmaf(r, s, -0.121484190f);
95 t = fmaf(t, s, 0.139814854f);
96 r = fmaf(r, s, -0.166846052f);
97 t = fmaf(t, s, 0.200120345f);
98 r = fmaf(r, s, -0.249996200f);
100 r = fmaf(r, m, 0.333331972f);
101 r = fmaf(r, m, -0.500000000f);
103 r = fmaf(i, 0.693147182f, r);
104 if (!((a > 0.0f) && (a <= 3.40282346e+38f))) {
109 if (fabs(a - 0.0f) < std::numeric_limits<double>::epsilon()) {
117 if (probability <= 0.0 || probability >= 1.0) {
122 double z = std::sqrt(2.0) *
erfinv(2.0 * probability - 1.0);
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);
139 return 0.5 * (1.0 + std::erf((x - mean) / (stddev * std::sqrt(2.0))));
143 if (k == 0 || k > n) {
147 return static_cast<double>(k) / (n + 1);
165 return (k / lambda) * exp(-k * x);
171 for (
const auto &value : data) {
177 return static_cast<double>(count) / data.size();
182 size_t count = std::count(data.begin(), data.end(), x);
183 return static_cast<double>(count) / data.size();
188 if (data.empty() || p < 0.0 || p > 1.0) {
192 std::vector<double> sortedData = data;
193 std::sort(sortedData.begin(), sortedData.end());
195 size_t index =
static_cast<size_t>(p * (data.size() - 1));
196 return sortedData[index];
204 double sum = std::accumulate(data.begin(), data.end(), 0.0);
205 return sum / data.size();
215 double variance = desc.
variance(data, mean);
217 return mean - variance / 2.0;
231 double sum = std::accumulate(data.begin(), data.end(), 0.0);
232 return sum / data.size();
240 std::vector<double> sortedData = data;
241 std::sort(sortedData.begin(), sortedData.end());
243 size_t size = sortedData.size();
245 return (sortedData[size / 2 - 1] + sortedData[size / 2]) / 2.0;
247 return sortedData[size / 2];
252 std::pair<double, double>
255 if (data.empty() || alpha <= 0.0 || alpha >= 1.0) {
259 size_t n = data.size();
262 double stddev = desc.
stdev(data, mean);
265 double z = quantile_dist(1 - alpha / 2.0);
266 double margin = z * stddev / std::sqrt(
static_cast<double>(n));
268 return {mean - margin, mean + margin};
272 const std::vector<double> &data,
273 double pivotFunction(
const std::vector<double> &)) {
278 return pivotFunction(data);
283 const std::vector<double> &data) {
284 size_t n = data.size();
288 double stddev = desc.
stdev(data, mean);
290 return mean + 2 * stddev / std::sqrt(
static_cast<double>(n));
293 std::pair<double, double>
298 if (data.empty() || alpha <= 0.0 || alpha >= 1.0) {
303 double lowerBound = 0.0;
304 double upperBound = 1.0;
306 return {lowerBound, upperBound};
309 std::pair<double, double>
312 if (data.empty() || alpha <= 0.0 || alpha >= 1.0) {
317 double lowerBound = 0.0;
318 double upperBound = 1.0;
320 return {lowerBound, upperBound};
323 std::pair<double, double>
326 if (data.empty() || alpha <= 0.0 || alpha >= 1.0) {
331 double lowerBound = 0.0;
332 double upperBound = 1.0;
334 return {lowerBound, upperBound};
A class providing methods for descriptive statistics.
static double stdev(const std::vector< double > &data, double mean)
Calculates the standard deviation of a given dataset, given the mean.
static double variance(const std::vector< double > &data, double mean)
Calculates the variance of a given dataset, given the mean.
static double mean_arith(const std::vector< double > &data)
Calculates the arithmetic mean of a given dataset.
double exp_PDF(double x, size_t k, double lambda)
Compute the probability density function (PDF) for the exponential distribution.
double normal_PDF(double x, double mean, double stddev)
Compute the probability density function (PDF) for the normal distribution.
double mle(const std::vector< double > &data)
Compute the Maximum Likelihood Estimate (MLE) for the mean of a dataset.
double mle_est(const std::vector< double > &data)
Placeholder function for M-estimation.
double emp_CDF(const std::vector< double > &data, double x)
Compute the empirical cumulative distribution function (CDF) for a given value.
std::pair< double, double > LikelihoodInterval(const std::vector< double > &data, double alpha)
Compute the likelihood interval for a given dataset and significance level.
double Pivot(const std::vector< double > &data, double pivotFunction(const std::vector< double > &))
Compute the value of a pivot function for interval estimation.
std::pair< double, double > PredictionInterval(const std::vector< double > &data, double alpha)
Compute the prediction interval for a given dataset and significance level.
double normal_CDF(double x, double mean, double stddev)
Compute the cumulative distribution function (CDF) for the normal distribution.
double uniform_CDF(size_t k, size_t n)
Compute the cumulative distribution function (CDF) for the uniform distribution.
double quantile_dist(double probability)
Compute the quantile of the standard normal distribution.
double median_uniased(const std::vector< double > &data)
Compute the median-unbiased estimate for the median of a dataset.
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.
double emp_PMF(const std::vector< double > &data, double x)
Compute the empirical probability mass function (PMF) for a given value.
double mom(const std::vector< double > &data)
Compute the method of moments (MOM) estimate for the mean of a dataset.
std::pair< double, double > ConfidenceInterval(const std::vector< double > &data, double alpha)
Compute the confidence interval for the mean of a dataset.
std::pair< double, double > ToleranceInterval(const std::vector< double > &data, double alpha)
Compute the tolerance interval for a given dataset and significance level.
double mumv(const std::vector< double > &data)
Compute the Mean-Unbiased Minimum-Variance (MUMV) estimate for the mean of a dataset.
double PivotFunctionForConfidenceInterval(const std::vector< double > &data)
Example pivot function for computing a confidence interval.