31template <
typename RealType>
49 static constexpr double edgeForGenerators = 8.0;
50 double logBetaFun = 0;
53 static double logStandardized(
double distance,
double complement);
59 } genCoef = {0, 0, 0};
62 BetaDistribution(
double shape1 = 1,
double shape2 = 1,
double minValue = 0,
double maxValue = 1);
68 [[nodiscard]] RealType
MinValue()
const override {
return a; }
69 [[nodiscard]] RealType
MaxValue()
const override {
return b; }
78 REJECTION_UNIFORM_EXTENDED,
88 GENERATOR_ID getIdOfUsedGenerator()
const
90 if (
alpha < 1 && beta < 1 && alpha + beta > 1)
91 return ATKINSON_WHITTAKER;
99 return REJECTION_UNIFORM;
101 return (
alpha < 2) ? REJECTION_UNIFORM_EXTENDED : REJECTION_NORMAL;
105 return (
alpha +
beta < 2) ? JOHNK : GAMMA_RATIO;
110 void setCoefficientsForGenerator();
132 [[nodiscard]]
inline double GetBeta() const noexcept {
return beta; }
142 [[nodiscard]]
double f(
const RealType &x)
const override;
143 [[nodiscard]]
double logf(
const RealType &x)
const override;
144 [[nodiscard]]
double F(
const RealType &x)
const override;
145 [[nodiscard]]
double S(
const RealType &x)
const override;
152 template <std::uniform_random_bit_generator G>
153 RealType variateRejectionUniform(G &g)
const;
159 template <std::uniform_random_bit_generator G>
160 RealType variateRejectionUniformExtended(G &g)
const;
166 template <std::uniform_random_bit_generator G>
167 RealType variateArcsine(G &g)
const;
173 template <std::uniform_random_bit_generator G>
174 RealType variateRejectionNormal(G &g)
const;
180 template <std::uniform_random_bit_generator G>
181 RealType variateJohnk(G &g)
const;
187 template <std::uniform_random_bit_generator G>
188 RealType variateCheng(G &g)
const;
194 template <std::uniform_random_bit_generator G>
195 RealType variateAtkinsonWhittaker(G &g)
const;
201 template <std::uniform_random_bit_generator G>
202 RealType variateGammaRatio(G &g)
const;
205 template <std::uniform_random_bit_generator G>
208 [[nodiscard]]
long double Mean()
const override;
213 [[nodiscard]]
long double Variance()
const override;
218 [[nodiscard]] RealType
Median()
const override;
219 [[nodiscard]] RealType
Mode()
const override;
220 [[nodiscard]]
long double Skewness()
const override;
232 std::complex<double>
CFImpl(
double t)
const override;
235 "Possibly one or more elements of the sample coincide with the lower boundary a.";
237 "Possibly one or more elements of the sample coincide with the upper boundary b.";
244template <
typename RealType>
248 BetaRand(
double shape1 = 1,
double shape2 = 1,
double minValue = 0,
double maxValue = 1)
252 [[nodiscard]] std::string
Name()
const override;
320 long double variance);
338template <
typename RealType>
342 ArcsineRand(
double shape = 0.5,
double minValue = 0,
double maxValue = 1)
346 [[nodiscard]] std::string
Name()
const override;
351 [[nodiscard]]
inline double GetShape() const noexcept {
return this->
beta; }
377template <
typename RealType>
380 double fixationIndex = 0.5, p = 0.5;
384 [[nodiscard]] std::string
Name()
const override;
388 [[nodiscard]]
inline double GetFrequency() const noexcept {
return p; }
402template <
typename RealType>
405 SetShapes(shape1, shape2);
406 SetSupport(minValue, maxValue);
409template <
typename RealType>
412 GENERATOR_ID
id = getIdOfUsedGenerator();
413 if (
id == REJECTION_NORMAL) {
414 double alpham1 = alpha - 1;
415 genCoef.s = alpham1 * std::log1pl(0.5 / alpham1) - 0.5;
416 genCoef.t = 1.0 / std::sqrt(8 * alpha - 4);
417 }
else if (
id == CHENG) {
418 genCoef.s = alpha + beta;
419 genCoef.t = std::min(alpha, beta);
421 genCoef.t = std::sqrt((2 * alpha * beta - genCoef.s) / (genCoef.s - 2));
422 genCoef.u = alpha + genCoef.t;
423 }
else if (
id == ATKINSON_WHITTAKER) {
424 genCoef.t = std::sqrt(alpha * (1 - alpha));
425 genCoef.t /= (genCoef.t + std::sqrt(beta * (1 - beta)));
426 genCoef.s = beta * genCoef.t;
427 genCoef.s /= (genCoef.s + alpha * (1 - genCoef.t));
431template <
typename RealType>
434 if (!(shape1 > 0 && shape2 > 0))
435 throw std::invalid_argument(
"Beta distribution: shapes should be positive");
436 GammaRV1.SetParameters(shape1, 1);
437 GammaRV2.SetParameters(shape2, 1);
438 alpha = GammaRV1.GetShape();
439 beta = GammaRV2.GetShape();
441 betaFun = std::exp(logBetaFun);
442 setCoefficientsForGenerator();
445template <
typename RealType>
448 if (!(minValue < maxValue))
449 throw std::invalid_argument(
"Beta distribution: minimum value should be smaller than maximum value");
455 logbma = std::log(bma);
458template <
typename RealType>
466 return (alpha > 1) ? 0 : INFINITY;
471 return (beta > 1) ? 0 : INFINITY;
473 return std::exp(logf(x));
476template <
typename RealType>
483 return std::log(beta / bma);
484 return (alpha > 1) ? -INFINITY : INFINITY;
488 return std::log(alpha / bma);
489 return (beta > 1) ? -INFINITY : INFINITY;
491 const double xSt = (x - a) * bmaInv, ySt = (b - x) * bmaInv;
492 double y = (alpha - 1) * logStandardized(xSt, ySt);
493 y += (beta - 1) * logStandardized(ySt, xSt);
494 return y - logBetaFun - logbma;
497template <
typename RealType>
501 return (complement < 0.5) ? std::log1p(-complement) : std::log(distance);
504template <
typename RealType>
512 double xSt = std::min((x - a) * bmaInv, 1.0), ySt = std::min((b - x) * bmaInv, 1.0);
514 if (alpha == beta && beta == 0.5)
517 return math::ibeta(xSt, alpha, beta, logBetaFun, logStandardized(xSt, ySt), logStandardized(ySt, xSt));
520template <
typename RealType>
528 double xSt = std::min((x - a) * bmaInv, 1.0), ySt = std::min((b - x) * bmaInv, 1.0);
530 if (alpha == beta && beta == 0.5)
533 return math::ibeta(ySt, beta, alpha, logBetaFun, logStandardized(ySt, xSt), logStandardized(xSt, ySt));
536template <
typename RealType>
537template <std::uniform_random_bit_generator G>
545template <
typename RealType>
546template <std::uniform_random_bit_generator G>
547RealType BetaDistribution<RealType>::variateRejectionUniform(G &g)
const
553 if (0.25 * V * V <= U - U * U)
555 }
while (++iter <= this->MAX_ITER_REJECTION);
556 throw std::runtime_error(
"Beta distribution: sampling failed");
559template <
typename RealType>
560template <std::uniform_random_bit_generator G>
561RealType BetaDistribution<RealType>::variateRejectionUniformExtended(G &g)
const
568 RealType edge = M_LN4 + std::log(U - U * U);
569 if (W >= (1.0 - alpha) * edge)
571 }
while (++iter <= this->MAX_ITER_REJECTION);
572 throw std::runtime_error(
"Beta distribution: sampling failed");
575template <
typename RealType>
576template <std::uniform_random_bit_generator G>
577RealType BetaDistribution<RealType>::variateRejectionNormal(G &g)
const
580 RealType N = 0, Z = 0;
581 RealType alpham1 = alpha - 1;
582 RealType alpha2m1 = alpha + alpham1;
587 }
while (Z >= alpha2m1);
590 RealType aux = 0.5 - alpham1 / (alpha2m1 - Z);
593 return 0.5 + N * genCoef.t;
594 aux = std::log1pl(-Z / alpha2m1);
598 return 0.5 + N * genCoef.t;
599 }
while (++iter <= this->MAX_ITER_REJECTION);
600 throw std::runtime_error(
"Beta distribution: sampling failed");
603template <
typename RealType>
604template <std::uniform_random_bit_generator G>
605RealType BetaDistribution<RealType>::variateJohnk(G &g)
const
607 RealType X = 0, Z = 0;
608 RealType W = 0, V = 0;
613 Z = X + std::exp(-V);
615 return (Z > 0) ? (X / Z) : (W < V);
619template <
typename RealType>
620template <std::uniform_random_bit_generator G>
621RealType BetaDistribution<RealType>::variateCheng(G &g)
const
627 RealType X = std::log(U / (1 - U)) / genCoef.t;
628 Y = alpha * std::exp(X);
629 R = 1.0 / (beta + Y);
633 T -= genCoef.s * std::log(genCoef.s * R);
638template <
typename RealType>
639template <std::uniform_random_bit_generator G>
640RealType BetaDistribution<RealType>::variateAtkinsonWhittaker(G &g)
const
646 if (U <= genCoef.s) {
647 RealType X = genCoef.t * std::pow(U / genCoef.s, 1.0 / alpha);
648 if (W >= (1.0 - beta) * std::log((1.0 - X) / (1.0 - genCoef.t)))
651 RealType X = 1.0 - (1.0 - genCoef.t) * std::pow((1.0 - U) / (1.0 - genCoef.s), 1.0 / beta);
652 if (W >= (1.0 - alpha) * std::log(X / genCoef.t))
655 }
while (++iter <= this->MAX_ITER_REJECTION);
656 throw std::runtime_error(
"Beta distribution: sampling failed");
659template <
typename RealType>
660template <std::uniform_random_bit_generator G>
661RealType BetaDistribution<RealType>::variateGammaRatio(G &g)
const
663 RealType Y = GammaRV1(g);
664 RealType Z = GammaRV2(g);
668template <
typename RealType>
669template <std::uniform_random_bit_generator G>
673 GENERATOR_ID
id = getIdOfUsedGenerator();
680 var = variateArcsine(g);
683 var = variateCheng(g);
685 case REJECTION_UNIFORM:
686 var = variateRejectionUniform(g);
688 case REJECTION_UNIFORM_EXTENDED:
689 var = variateRejectionUniformExtended(g);
691 case REJECTION_NORMAL:
692 var = variateRejectionNormal(g);
695 var = variateJohnk(g);
697 case ATKINSON_WHITTAKER:
698 var = variateAtkinsonWhittaker(g);
702 var = variateGammaRatio(g);
706 return a + bma * var;
709template <
typename RealType>
712 GENERATOR_ID
id = getIdOfUsedGenerator();
716 for (RealType &var : outputData)
717 var = detail::uniform01<RealType>(g);
720 for (RealType &var : outputData)
721 var = variateArcsine(g);
724 for (RealType &var : outputData)
725 var = variateCheng(g);
727 case REJECTION_UNIFORM: {
728 for (RealType &var : outputData)
729 var = variateRejectionUniform(g);
731 case REJECTION_UNIFORM_EXTENDED: {
732 for (RealType &var : outputData)
733 var = variateRejectionUniformExtended(g);
735 case REJECTION_NORMAL: {
736 for (RealType &var : outputData)
737 var = variateRejectionNormal(g);
740 for (RealType &var : outputData)
741 var = variateJohnk(g);
743 case ATKINSON_WHITTAKER: {
744 for (RealType &var : outputData)
745 var = variateAtkinsonWhittaker(g);
749 GammaRV1.Sample(g, outputData);
750 for (RealType &var : outputData)
751 var /= (var + GammaRV2(g));
756 for (RealType &var : outputData)
760template <
typename RealType>
763 double mean = alpha / (alpha + beta);
764 return a + bma * mean;
767template <
typename RealType>
773template <
typename RealType>
776 double var = alpha + beta;
777 var *= var * (var + 1);
778 var = alpha * beta / var;
779 return bma * bma * var;
782template <
typename RealType>
788template <
typename RealType>
792 return a + bma * 0.5;
797 if (alpha >= 1.0 && beta >= 1.0) {
798 double initValue = 3 * alpha - 1.0;
799 initValue /= 3 * (alpha + beta) - 2.0;
807template <
typename RealType>
812 mode = (beta > 1) ? (alpha - 1) / (alpha + beta - 2) : 1.0;
814 mode = (beta > 1) ? 0.0 : (alpha > beta);
815 return a + bma * mode;
818template <
typename RealType>
821 long double skewness = (alpha + beta + 1) / (alpha * beta);
822 skewness = std::sqrt(skewness);
823 skewness *= beta - alpha;
824 skewness /= alpha + beta + 2;
828template <
typename RealType>
831 long double sum = alpha + beta;
832 long double kurtosis = alpha - beta;
833 kurtosis *= kurtosis;
834 kurtosis *= (sum + 1);
835 kurtosis /= (alpha * beta * (sum + 2));
837 kurtosis /= (sum + 3);
841template <
typename RealType>
845 y += alpha * std::log(alpha);
846 y += beta * std::log(beta);
847 y -= (alpha + beta + 1) * std::log(alpha + beta);
853template <
typename RealType>
859 return a + bma * x * x;
865 return a - bma * std::expm1l(std::log1pl(-p) / beta);
867 return a + bma * std::pow(p, 1.0 / alpha);
871template <
typename RealType>
877 return a + bma * x * x;
883 return a - bma * std::expm1l(std::log(p) / beta);
885 return a + bma * std::exp(std::log1pl(-p) / alpha);
889template <
typename RealType>
893 if (alpha >= 1 && beta >= 1)
897 double sinZ = std::sin(z);
898 double cosZm1 = std::cos(z) - 1.0;
901 [
this, z, cosZm1](
double x) {
906 double y = std::cos(z * x) - 1;
907 y *= std::pow(x, alpha - 1);
909 return std::pow(1.0 - x, beta - 1) * y;
916 [
this, z, sinZ](
double x) {
921 double y = std::sin(z * x);
922 y *= std::pow(x, alpha - 1);
924 return std::pow(1.0 - x, beta - 1) * y;
929 std::complex<double> y(re, im);
930 double cosTA = std::cos(t * a), sinTA = std::sin(t * a);
931 return y * std::complex<double>(cosTA, sinTA) / betaFun;
934template <
typename RealType>
936template <
typename RealType>
940template <
typename RealType>
943 return "Beta(" + this->toStringWithPrecision(this->GetAlpha()) +
", " +
944 this->toStringWithPrecision(this->GetBeta()) +
", " + this->toStringWithPrecision(this->MinValue()) +
", " +
945 this->toStringWithPrecision(this->MaxValue()) +
")";
948template <
typename RealType>
951 double y = (x - this->a) * this->bmaInv;
952 return {std::log(y), std::log1pl(-y)};
955template <
typename RealType>
958 return {this->alpha, this->beta};
961template <
typename RealType>
964 return {sourceParameters.first - 1, sourceParameters.second - 1};
967template <
typename RealType>
970 return this->logbma +
math::logBeta(theta.first + 1, theta.second + 1);
973template <
typename RealType>
978 double psisum =
math::digamma(theta.first + theta.second + 2);
979 return {psi1 - psisum, psi2 - psisum};
982template <
typename RealType>
988template <
typename RealType>
992 for (RealType var : sample) {
993 RealType x = (var - this->a) * this->bmaInv;
996 return lnG / sample.size();
999template <
typename RealType>
1002 long double lnG1p = 0;
1003 for (RealType var : sample) {
1004 RealType x = (var - this->a) * this->bmaInv;
1005 lnG1p += std::log1pl(x);
1007 return lnG1p / sample.size();
1010template <
typename RealType>
1013 long double lnG1m = 0;
1014 for (RealType var : sample) {
1015 RealType x = (var - this->a) * this->bmaInv;
1016 lnG1m += std::log1pl(-x);
1018 return lnG1m / sample.size();
1021template <
typename RealType>
1024 if (meanNorm <= 0 || meanNorm >= 1)
1026 "Normalized mean of the sample should be in interval of (0, 1)");
1027 if (this->beta == 1.0) {
1029 SetShapes(-1.0 / lnG, this->beta);
1032 RealType shape = meanNorm;
1033 shape /= 1.0 - meanNorm;
1034 shape *= this->beta;
1036 if (!math::findRootNewtonFirstOrder<RealType>(
1037 [
this, lnG](
double x) {
1044 SetShapes(shape, this->beta);
1048template <
typename RealType>
1051 if (!this->allElementsAreNotSmallerThan(this->a, sample))
1053 this->LOWER_LIMIT_VIOLATION + this->toStringWithPrecision(this->a));
1054 if (!this->allElementsAreNotGreaterThan(this->b, sample))
1056 this->UPPER_LIMIT_VIOLATION + this->toStringWithPrecision(this->b));
1058 long double lnG = this->GetSampleLogMeanNorm(sample);
1059 if (!std::isfinite(lnG))
1061 long double mean = this->GetSampleMean(sample);
1063 mean *= this->bmaInv;
1064 FitAlpha(lnG, mean);
1067template <
typename RealType>
1070 if (meanNorm <= 0 || meanNorm >= 1)
1072 "Normalized mean of the sample should be in interval of (0, 1)");
1073 if (this->alpha == 1.0) {
1075 SetShapes(this->alpha, -1.0 / lnG1m);
1078 RealType shape = this->alpha / meanNorm - this->alpha;
1080 if (!math::findRootNewtonFirstOrder<RealType>(
1081 [
this, lnG1m](
double x) {
1088 this->SetShapes(this->alpha, shape);
1092template <
typename RealType>
1095 if (!this->allElementsAreNotSmallerThan(this->a, sample))
1097 this->LOWER_LIMIT_VIOLATION + this->toStringWithPrecision(this->a));
1098 if (!this->allElementsAreNotGreaterThan(this->b, sample))
1100 this->UPPER_LIMIT_VIOLATION + this->toStringWithPrecision(this->b));
1102 long double lnG1m = this->GetSampleLog1mMeanNorm(sample);
1103 if (!std::isfinite(lnG1m))
1105 long double mean = this->GetSampleMean(sample);
1107 mean *= this->bmaInv;
1108 FitBeta(lnG1m, mean);
1111template <
typename RealType>
1115 double scaledMean = (mean - this->a) * this->bmaInv;
1116 double scaledVar = variance * this->bmaInv * this->bmaInv;
1117 double temp = scaledMean * (1.0 - scaledMean) / scaledVar - 1.0;
1118 double shape1 = 0.001, shape2 = shape1;
1120 shape1 = scaledMean * temp;
1121 shape2 = (1.0 - scaledMean) * temp;
1123 DoublePair shapes = std::make_pair(shape1, shape2);
1128 double digammaAlphapBeta =
math::digamma(x.first + x.second);
1131 double first = lnG + digammaAlphapBeta - digammaAlpha;
1132 double second = lnG1m + digammaAlphapBeta - digammaBeta;
1139 DoublePair first = std::make_pair(trigammaAlphapBeta - trigammaAlpha, trigammaAlphapBeta);
1140 DoublePair second = std::make_pair(trigammaAlphapBeta, trigammaAlphapBeta - trigammaBeta);
1141 return std::make_tuple(first, second);
1145 SetShapes(shapes.first, shapes.second);
1148template <
typename RealType>
1151 if (!this->allElementsAreNotSmallerThan(this->a, sample))
1153 this->LOWER_LIMIT_VIOLATION + this->toStringWithPrecision(this->a));
1154 if (!this->allElementsAreNotGreaterThan(this->b, sample))
1156 this->UPPER_LIMIT_VIOLATION + this->toStringWithPrecision(this->b));
1158 long double lnG = this->GetSampleLogMeanNorm(sample);
1159 if (!std::isfinite(lnG))
1161 long double lnG1m = this->GetSampleLog1mMeanNorm(sample);
1162 if (!std::isfinite(lnG1m))
1166 DoublePair stats = this->GetSampleMeanAndVariance(sample);
1167 FitShapes(lnG, lnG1m, stats.first, stats.second);
1171template <
typename RealType>
1174 return "Arcsine(" + this->toStringWithPrecision(GetShape()) +
", " + this->toStringWithPrecision(this->MinValue()) +
1175 ", " + this->toStringWithPrecision(this->MaxValue()) +
")";
1178template <
typename RealType>
1184template <
typename RealType>
1188 if (!std::isfinite(shape))
1191 SetShape(shape > 0 ? shape : shape + 1);
1194template <
typename RealType>
1197 if (!this->allElementsAreNotSmallerThan(this->a, sample))
1199 this->LOWER_LIMIT_VIOLATION + this->toStringWithPrecision(this->a));
1200 if (!this->allElementsAreNotGreaterThan(this->b, sample))
1202 this->UPPER_LIMIT_VIOLATION + this->toStringWithPrecision(this->b));
1204 int n = sample.size();
1205 long double lnG = 0, lnG1m = 0;
1206 for (
double var : sample) {
1207 double x = (var - this->a) * this->bmaInv;
1209 lnG1m += std::log1pl(-x);
1211 if (!std::isfinite(lnG))
1213 if (!std::isfinite(lnG1m))
1217 FitShape(lnG, lnG1m);
1221template <
typename RealType>
1224 SetFixatingIndexAndFrequency(fixatingIndex, frequency);
1227template <
typename RealType>
1230 return "Balding-Nichols(" + this->toStringWithPrecision(GetFixatingIndex()) +
", " +
1231 this->toStringWithPrecision(GetFrequency()) +
")";
1234template <
typename RealType>
1237 if (!(fixatingIndex > 0 && fixatingIndex < 1))
1238 throw std::invalid_argument(
"Balding-Nichols distribution: fixation index should be in interval (0, 1)");
1239 if (!(frequency > 0 && frequency < 1))
1240 throw std::invalid_argument(
"Balding-Nichols distribution: frequency should be in interval (0, 1)");
1241 fixationIndex = fixatingIndex;
1244 double frac = (1.0 - fixationIndex) / fixationIndex, fracP = frac * p;
The ArcsineRand class Arcsine distribution.
Definition continuous/beta.hpp:340
void SetShape(double shape)
Definition continuous/beta.hpp:1179
void FitShape(long double lnG, long double lnG1m)
set α and β, estimated via maximum likelihood, using sufficient statistics instead of the whole sampl...
Definition continuous/beta.hpp:1185
std::string Name() const override
Definition continuous/beta.hpp:1172
ArcsineRand(double shape=0.5, double minValue=0, double maxValue=1)
Definition continuous/beta.hpp:342
double GetShape() const noexcept
Definition continuous/beta.hpp:351
The BaldingNicholsRand class Balding-Nichols distribution.
Definition continuous/beta.hpp:379
BaldingNicholsRand(double fixatingIndex, double frequency)
Definition continuous/beta.hpp:1222
double GetFixatingIndex() const noexcept
Definition continuous/beta.hpp:387
double GetFrequency() const noexcept
Definition continuous/beta.hpp:388
void SetFixatingIndexAndFrequency(double fixatingIndex, double frequency)
Definition continuous/beta.hpp:1235
std::string Name() const override
Definition continuous/beta.hpp:1228
The BetaDistribution class Abstract class for Beta distribution.
Definition continuous/beta.hpp:33
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition continuous/beta.hpp:808
Support SupportType() const override
Definition continuous/beta.hpp:67
RealType quantileImpl(double p) const override
Definition continuous/beta.hpp:854
double S(const RealType &x) const override
Definition continuous/beta.hpp:521
double logf(const RealType &x) const override
Definition continuous/beta.hpp:477
double alpha
first shape α
Definition continuous/beta.hpp:38
BetaDistribution(double shape1=1, double shape2=1, double minValue=0, double maxValue=1)
Definition continuous/beta.hpp:403
long double MeanAbsoluteDeviation() const
MeanAbsoluteDeviation.
Definition continuous/beta.hpp:842
virtual ~BetaDistribution()
Definition continuous/beta.hpp:65
double f(const RealType &x) const override
Definition continuous/beta.hpp:459
double GetAlpha() const noexcept
Definition continuous/beta.hpp:128
static constexpr char BETA_ZERO[]
Definition continuous/beta.hpp:236
RealType Median() const override
Definition continuous/beta.hpp:789
double b
max bound
Definition continuous/beta.hpp:41
long double ExcessKurtosis() const override
Definition continuous/beta.hpp:829
std::complex< double > CFImpl(double t) const override
Definition continuous/beta.hpp:890
double GetBetaFunction() const noexcept
Definition continuous/beta.hpp:136
double logbma
log(b-a)
Definition continuous/beta.hpp:44
double beta
second shape β
Definition continuous/beta.hpp:39
double GetLogBetaFunction() const noexcept
Definition continuous/beta.hpp:140
void SetSupport(double minValue, double maxValue)
Definition continuous/beta.hpp:446
long double Variance() const override
Definition continuous/beta.hpp:774
double bmaInv
1/(b-a)
Definition continuous/beta.hpp:43
long double Skewness() const override
Definition continuous/beta.hpp:819
double a
min bound
Definition continuous/beta.hpp:40
RealType MinValue() const override
Definition continuous/beta.hpp:68
long double Mean() const override
Definition continuous/beta.hpp:761
GammaRand< RealType > GammaRV2
Definition continuous/beta.hpp:46
RealType quantileImpl1m(double p) const override
Definition continuous/beta.hpp:872
long double GeometricMean() const
Definition continuous/beta.hpp:768
double bma
b-a
Definition continuous/beta.hpp:42
void SetShapes(double shape1, double shape2)
Definition continuous/beta.hpp:432
RealType operator()(G &g) const
Definition continuous/beta.hpp:670
RealType MaxValue() const override
Definition continuous/beta.hpp:69
static constexpr char ALPHA_ZERO[]
Definition continuous/beta.hpp:234
long double GeometricVariance() const
Definition continuous/beta.hpp:783
GammaRand< RealType > GammaRV1
Definition continuous/beta.hpp:46
double GetBeta() const noexcept
Definition continuous/beta.hpp:132
double F(const RealType &x) const override
Definition continuous/beta.hpp:505
The BetaRand class Beta distribution.
Definition continuous/beta.hpp:246
DoublePair SourceParameters() const override
Definition continuous/beta.hpp:956
std::string Name() const override
Definition continuous/beta.hpp:941
void FitAlpha(std::span< const RealType > sample)
set α, estimated via maximum likelihood
Definition continuous/beta.hpp:1049
DoublePair SourceToNatural(DoublePair sourceParameters) const override
Definition continuous/beta.hpp:962
double CarrierMeasure(RealType) const override
Definition continuous/beta.hpp:983
void FitAlpha(long double lnG, long double meanNorm)
set α, estimated via maximum likelihood, using sufficient statistics instead of the whole sample
Definition continuous/beta.hpp:1022
double LogNormalizer(DoublePair theta) const override
Definition continuous/beta.hpp:968
void FitShapes(std::span< const RealType > sample)
set α and β, estimated via maximum likelihood
Definition continuous/beta.hpp:1149
long double GetSampleLogMeanNorm(std::span< const RealType > sample) const
GetSampleLogMeanNorm.
Definition continuous/beta.hpp:989
DoublePair SufficientStatistic(RealType x) const override
Definition continuous/beta.hpp:949
void FitBeta(long double lnG1m, long double meanNorm)
set β, estimated via maximum likelihood, using sufficient statistics instead of the whole sample
Definition continuous/beta.hpp:1068
void FitBeta(std::span< const RealType > sample)
set β, estimated via maximum likelihood
Definition continuous/beta.hpp:1093
long double GetSampleLog1pMeanNorm(std::span< const RealType > sample) const
GetSampleLog1pMeanNorm.
Definition continuous/beta.hpp:1000
void FitShapes(long double lnG, long double lnG1m, long double mean, long double variance)
set α and β, estimated via maximum likelihood, using sufficient statistics instead of the whole sampl...
Definition continuous/beta.hpp:1112
DoublePair LogNormalizerGradient(DoublePair theta) const override
Definition continuous/beta.hpp:974
BetaRand(double shape1=1, double shape2=1, double minValue=0, double maxValue=1)
Definition continuous/beta.hpp:248
long double GetSampleLog1mMeanNorm(std::span< const RealType > sample) const
GetSampleLog1mMeanNorm.
Definition continuous/beta.hpp:1011
The ContinuousDistribution class Abstract class for all continuous distributions.
Definition continuous.hpp:22
RealType quantileImpl(double p, RealType initValue) const override
Definition continuous.hpp:140
RealType quantileImpl1m(double p, RealType initValue) const override
Definition continuous.hpp:152
Definition exponential_family.hpp:14
The GammaRand class Gamma distribution.
Definition continuous/gamma.hpp:295
virtual std::complex< double > CFImpl(double t) const
Definition univariate.hpp:365
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
#define RANDLIB_DETAIL_SUPPRESS_DEPRECATED_END
Definition fwd.hpp:26
#define RANDLIB_DETAIL_SUPPRESS_DEPRECATED_BEGIN
Definition fwd.hpp:25
#define RANDLIB_DEPRECATED_FIT_MEMBER
Definition fwd.hpp:9
constexpr long double inv_pi
Definition constants.hpp:24
constexpr long double ln2
Definition constants.hpp:18
constexpr long double pi
Definition constants.hpp:22
constexpr long double two_inv_pi
Definition constants.hpp:25
Real standardNormal(G &g)
Ziggurat algorithm of Marsaglia and Tsang with 256 layers and an explicit sign bit.
Definition variates.hpp:45
bool areClose(RealType a, RealType b, RealType eps=1e-6)
Definition functions.hpp:38
Real digamma(Real x)
Definition math/gamma.hpp:691
Real logBeta(Real a, std::type_identity_t< Real > b)
Calculate logarithm of beta function.
Definition math/beta.hpp:72
Real atan(Real x)
Definition functions.hpp:238
Real ibeta(Real x, std::type_identity_t< Real > a, std::type_identity_t< Real > b, std::type_identity_t< Real > logBetaFun, std::type_identity_t< Real > logX, std::type_identity_t< Real > log1mX)
Fast calculation of regularized beta function, using precalculated values.
Definition math/beta.hpp:250
Real trigamma(Real x)
Definition math/gamma.hpp:720
bool findRootNewtonFirstOrder2d(const std::function< DoublePair(DoublePair)> &funPtr, const std::function< std::tuple< DoublePair, DoublePair >(DoublePair)> &gradPtr, DoublePair &root, long double funTol=1e-10, long double stepTol=1e-6)
Newton's root-finding procedure for 2 functions of 2 parameters, using Jacobian matrix.
Definition roots.hpp:347
Real integrate(const F &f, std::type_identity_t< Real > a, std::type_identity_t< Real > b, std::type_identity_t< Real > tolerance=1e-11, int maxSubdivisions=512)
Global adaptive Gauss-Kronrod quadrature (QUADPACK QAG).
Definition quadrature.hpp:226
Definition bivariate_normal.hpp:10
@ WrongSample
the sample could not have been drawn from this distribution
@ NotApplicable
the method cannot be applied to this distribution or sample
@ WrongReturn
the method returned invalid parameters
@ Undefined
any other failure
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15
Pair< double > DoublePair
Definition fwd.hpp:39