29template <
typename RealType>
59 [[nodiscard]] RealType
MinValue()
const override {
return 0; }
60 [[nodiscard]] RealType
MaxValue()
const override {
return INFINITY; }
86 [[nodiscard]]
inline double GetRate() const noexcept {
return beta; }
104 [[nodiscard]]
double f(
const RealType &x)
const override;
105 [[nodiscard]]
double logf(
const RealType &x)
const override;
106 [[nodiscard]]
double F(
const RealType &x)
const override;
107 double logF(
const RealType &x)
const;
108 [[nodiscard]]
double S(
const RealType &x)
const override;
109 double logS(
const RealType &x)
const;
115 ONE_AND_A_HALF_SHAPE,
125 static GENERATOR_ID getIdOfUsedGenerator(
double shape)
130 return INTEGER_SHAPE;
132 return ONE_AND_A_HALF_SHAPE;
133 if (shape > 1.0 && shape < 1.2)
135 return MARSAGLIA_TSANG;
142 template <std::uniform_random_bit_generator G>
143 static RealType variateThroughExponentialSum(
int shape, G &g);
147 template <std::uniform_random_bit_generator G>
148 static RealType variateForShapeOneAndAHalf(G &g);
152 template <std::uniform_random_bit_generator G>
153 RealType variateBest(G &g)
const;
158 template <std::uniform_random_bit_generator G>
159 static RealType variateAhrensDieter(
double shape, G &g);
164 template <std::uniform_random_bit_generator G>
165 static RealType variateFishman(
double shape, G &g);
170 template <std::uniform_random_bit_generator G>
171 static RealType variateMarsagliaTsang(
double shape, G &g);
179 template <std::uniform_random_bit_generator G>
187 template <std::uniform_random_bit_generator G>
188 [[nodiscard]]
static RealType
Variate(
double shape,
double rate, G &g);
190 template <std::uniform_random_bit_generator G>
196 [[nodiscard]]
long double Mean()
const override;
204 [[nodiscard]]
long double Variance()
const override;
209 [[nodiscard]] RealType
Mode()
const override;
210 [[nodiscard]] RealType
Median()
const override;
211 [[nodiscard]]
long double Skewness()
const override;
216 RealType initRootForSmallP(
double r)
const;
217 RealType initRootForLargeP(
double logQ)
const;
218 RealType initRootForLargeShape(
double p)
const;
219 RealType initRootForLargeShape1m(
double p)
const;
220 RealType quantileInitialGuess(
double p)
const;
221 RealType quantileInitialGuess1m(
double p)
const;
228 double df(RealType x)
const;
234 double dfDivf(RealType x)
const;
235 RealType quantileImpl(
double p, RealType initValue)
const override;
236 RealType quantileImpl(
double p)
const override;
237 RealType quantileImpl1m(
double p, RealType initValue)
const override;
238 RealType quantileImpl1m(
double p)
const override;
240 std::complex<double> CFImpl(
double t)
const override;
243template <
typename RealType>
250template <
typename RealType>
293template <
typename RealType>
314 throw std::invalid_argument(
"Gamma distribution: scale should be positive");
317 [[nodiscard]] std::string
Name()
const override;
353template <
typename RealType>
358 [[nodiscard]] std::string
Name()
const override;
360 [[nodiscard]]
inline size_t GetDegree()
const {
return static_cast<int>(2 * this->
alpha); }
373template <
typename RealType>
386 throw std::invalid_argument(
"Erlang distribution: scale should be positive");
389 [[nodiscard]] std::string
Name()
const override;
403template <
typename RealType>
406 SetParameters(shape, rate);
409template <
typename RealType>
413 throw std::invalid_argument(
"Gamma distribution: shape should be positive, but it's equal to " +
414 std::to_string(shape));
416 throw std::invalid_argument(
"Gamma distribution: rate should be positive, but it's equal to " +
417 std::to_string(rate));
419 this->alpha = shape > 0 ? shape : 1.0;
421 this->beta = (rate > 0.0) ? rate : 1.0;
422 theta = 1.0 / this->beta;
424 lgammaAlpha = std::lgammal(this->alpha);
425 logAlpha = std::log(this->alpha);
426 this->logBeta = std::log(this->beta);
427 pdfCoef = -lgammaAlpha + this->alpha * this->logBeta;
429 if (getIdOfUsedGenerator(this->alpha) == SMALL_SHAPE) {
431 genCoef.t = 0.5 * std::log1pl(-alpha);
432 genCoef.t = 0.07 + 0.75 * std::exp(genCoef.t);
433 genCoef.b = 1.0 + std::exp(-genCoef.t) * this->alpha / genCoef.t;
437template <
typename RealType>
440 SetParameters(shape, this->beta);
443template <
typename RealType>
449 if (this->alpha > 1.0)
451 return (this->alpha == 1.0) ? this->beta : INFINITY;
453 return std::exp(logf(x));
456template <
typename RealType>
462 if (this->alpha > 1.0)
464 return (this->alpha == 1.0) ? this->logBeta : INFINITY;
466 double y = (this->alpha - 1.0) * std::log(x);
472template <
typename RealType>
475 return (x > 0.0) ?
math::pgamma(this->alpha, x * this->beta, logAlpha, lgammaAlpha) : 0.0;
478template <
typename RealType>
481 return (x > 0.0) ?
math::lpgamma(this->alpha, x * this->beta, logAlpha, lgammaAlpha) : -INFINITY;
484template <
typename RealType>
487 return (x > 0.0) ?
math::qgamma(this->alpha, x * this->beta, logAlpha, lgammaAlpha) : 1.0;
490template <
typename RealType>
493 return (x > 0.0) ?
math::lqgamma(this->alpha, x * this->beta, logAlpha, lgammaAlpha) : 0.0;
496template <
typename RealType>
497template <std::uniform_random_bit_generator G>
501 for (
int i = 0; i < shape; ++i)
506template <
typename RealType>
507template <std::uniform_random_bit_generator G>
508RealType GammaDistribution<RealType>::variateForShapeOneAndAHalf(G &g)
512 return W + 0.5 * N * N;
515template <
typename RealType>
516template <std::uniform_random_bit_generator G>
517RealType GammaDistribution<RealType>::variateBest(G &g)
const
526 X = genCoef.t * std::pow(V, 1.0 / this->alpha);
527 if (W <= (2.0 - X) / (2.0 + X) || W <= std::exp(-X))
530 X = -std::log(genCoef.t * (genCoef.b - V) / this->alpha);
531 double Y = X / genCoef.t;
532 if (W * (this->alpha + Y - this->alpha * Y) <= 1 || W <= std::pow(Y, this->alpha - 1))
535 }
while (++iter <= ProbabilityDistribution<RealType>::MAX_ITER_REJECTION);
536 throw std::runtime_error(
"Gamma distribution: sampling failed");
539template <
typename RealType>
540template <std::uniform_random_bit_generator G>
541RealType GammaDistribution<RealType>::variateAhrensDieter(
double shape, G &g)
546 double shapeInv = 1.0 / shape;
550 double p = shape * t * U;
553 X = std::pow(p, shapeInv);
557 X = -std::log(t * (1 - U));
558 if ((1 - shape) * std::log(X) <= W)
561 }
while (++iter <= ProbabilityDistribution<RealType>::MAX_ITER_REJECTION);
562 throw std::runtime_error(
"Gamma distribution: sampling failed");
565template <
typename RealType>
566template <std::uniform_random_bit_generator G>
567RealType GammaDistribution<RealType>::variateFishman(
double shape, G &g)
571 double shapem1 = shape - 1;
575 }
while (W2 < shapem1 * (W1 - std::log(W1) - 1));
579template <
typename RealType>
580template <std::uniform_random_bit_generator G>
581RealType GammaDistribution<RealType>::variateMarsagliaTsang(
double shape, G &g)
584 RealType d = shape - 1.0 / 3;
585 RealType c = 3 * std::sqrt(d);
592 RealType v = 1 + N / c;
596 if (U < 1.0 - 0.331 * N * N || std::log(U) < 0.5 * N + d * (1.0 - v + std::log(v))) {
599 }
while (++iter <= ProbabilityDistribution<RealType>::MAX_ITER_REJECTION);
600 throw std::runtime_error(
"Gamma distribution: sampling failed");
603template <
typename RealType>
604template <std::uniform_random_bit_generator G>
608 throw std::invalid_argument(
"Gamma distribution: shape should be positive");
610 GENERATOR_ID genId = getIdOfUsedGenerator(shape);
614 return variateThroughExponentialSum(std::round(shape), g);
615 case ONE_AND_A_HALF_SHAPE:
616 return variateForShapeOneAndAHalf(g);
618 return variateAhrensDieter(shape, g);
620 return variateFishman(shape, g);
621 case MARSAGLIA_TSANG:
622 return variateMarsagliaTsang(shape, g);
624 throw std::runtime_error(
"Gamma distribution: invalid generator id");
628template <
typename RealType>
629template <std::uniform_random_bit_generator G>
633 throw std::invalid_argument(
"Gamma distribution: shape should be positive");
635 throw std::invalid_argument(
"Gamma distribution: rate should be positive");
636 return StandardVariate(shape, g) / rate;
639template <
typename RealType>
640template <std::uniform_random_bit_generator G>
643 GENERATOR_ID genId = getIdOfUsedGenerator(this->alpha);
647 return theta * variateThroughExponentialSum(this->alpha, g);
648 case ONE_AND_A_HALF_SHAPE:
649 return theta * variateForShapeOneAndAHalf(g);
651 return theta * variateBest(g);
653 return theta * variateFishman(this->alpha, g);
654 case MARSAGLIA_TSANG:
655 return theta * variateMarsagliaTsang(this->alpha, g);
657 throw std::runtime_error(
"Gamma distribution: invalid generator id");
661template <
typename RealType>
664 GENERATOR_ID genId = getIdOfUsedGenerator(this->alpha);
668 for (RealType &var : outputData)
669 var = theta * variateThroughExponentialSum(this->alpha, g);
671 case ONE_AND_A_HALF_SHAPE:
672 for (RealType &var : outputData)
673 var = theta * variateForShapeOneAndAHalf(g);
676 for (RealType &var : outputData)
677 var = theta * variateBest(g);
680 for (RealType &var : outputData)
681 var = theta * variateFishman(this->alpha, g);
683 case MARSAGLIA_TSANG:
684 for (RealType &var : outputData)
685 var = theta * variateMarsagliaTsang(this->alpha, g);
692template <
typename RealType>
695 return this->alpha * theta;
698template <
typename RealType>
701 return this->digammaAlpha - this->logBeta;
704template <
typename RealType>
707 return this->alpha * theta * theta;
710template <
typename RealType>
716template <
typename RealType>
719 return (this->alpha <= 1) ? 0 : (this->alpha - 1) * theta;
722template <
typename RealType>
728template <
typename RealType>
731 return 2.0l / std::sqrt(this->alpha);
734template <
typename RealType>
737 return 6.0l / this->alpha;
740template <
typename RealType>
747 double denominator = this->alpha + 1;
748 c[3] = 1.0 / denominator;
750 denominator *= denominator;
751 denominator *= this->alpha + 2;
752 c[2] = 0.5 * (3 * this->alpha + 5) / denominator;
754 denominator *= 3 * (this->alpha + 1) * (this->alpha + 3);
755 c[1] = 8 * this->alpha + 33;
760 denominator *= 8 * (this->alpha + 1) * (this->alpha + 2) * (this->alpha + 4);
761 c[0] = 125 * this->alpha + 1179;
770 for (
int i = 0; i != 5; ++i) {
777template <
typename RealType>
778RealType GammaDistribution<RealType>::initRootForLargeP(
double logQ)
const
781 double x = (logQ + lgammaAlpha) / this->alpha;
782 x = -std::exp(x) / this->alpha;
786template <
typename RealType>
787RealType GammaDistribution<RealType>::initRootForLargeShape(
double p)
const
792 double lambda = x * x / this->alpha + 1;
793 lambda = -std::exp(-lambda);
795 return lambda * this->alpha;
798template <
typename RealType>
799RealType GammaDistribution<RealType>::initRootForLargeShape1m(
double p)
const
804 double lambda = x * x / this->alpha + 1;
805 lambda = -std::exp(-lambda);
807 return lambda * this->alpha;
810template <
typename RealType>
811RealType GammaDistribution<RealType>::quantileInitialGuess(
double p)
const
819 if (this->alpha < 10) {
820 double r = std::log(p * this->alpha) + lgammaAlpha;
821 r = std::exp(r / this->alpha);
823 if (r < 0.2 * (this->alpha + 1)) {
824 guess = initRootForSmallP(r);
826 double logQ = std::log1pl(-p);
828 double maxBoundary1 = -0.5 * this->alpha - logAlpha - lgammaAlpha;
830 double maxBoundary2 = this->alpha * (logAlpha - 1) - lgammaAlpha;
832 if (logQ < std::min(maxBoundary1, maxBoundary2))
833 guess = initRootForLargeP(logQ);
834 else if (this->alpha < 1)
837 guess = initRootForLargeShape(p);
840 guess = initRootForLargeShape(p);
841 return guess / this->beta;
844template <
typename RealType>
845RealType GammaDistribution<RealType>::quantileInitialGuess1m(
double p)
const
847 if (this->alpha < 10) {
848 double logQ = std::log(p);
850 double maxBoundary1 = -0.5 * this->alpha - logAlpha - lgammaAlpha;
852 double maxBoundary2 = this->alpha * (logAlpha - 1) - lgammaAlpha;
854 if (logQ < std::min(maxBoundary1, maxBoundary2))
855 return initRootForLargeP(logQ) / this->beta;
857 return initRootForLargeShape1m(p) / this->beta;
859 return quantileInitialGuess(1.0 - p);
862template <
typename RealType>
863double GammaDistribution<RealType>::df(RealType x)
const
865 double z = (this->alpha - 1) - this->beta * x;
866 double y = (this->alpha - 2) * std::log(x);
869 return z * std::exp(y);
872template <
typename RealType>
873double GammaDistribution<RealType>::dfDivf(RealType x)
const
875 return x / (this->alpha - 1 - this->beta * x);
878template <
typename RealType>
879RealType GammaDistribution<RealType>::quantileImpl(
double p, RealType initValue)
const
884template <
typename RealType>
885RealType GammaDistribution<RealType>::quantileImpl(
double p)
const
887 return (this->alpha == 1.0) ? -theta * std::log1pl(-p) : quantileImpl(p, quantileInitialGuess(p));
890template <
typename RealType>
891RealType GammaDistribution<RealType>::quantileImpl1m(
double p, RealType initValue)
const
896template <
typename RealType>
897RealType GammaDistribution<RealType>::quantileImpl1m(
double p)
const
899 return (this->alpha == 1.0) ? -theta * std::log(p) : quantileImpl1m(p, quantileInitialGuess1m(p));
902template <
typename RealType>
903std::complex<double> GammaDistribution<RealType>::CFImpl(
double t)
const
905 return std::pow(std::complex<double>(1.0, -theta * t), -alpha);
909template <
typename RealType>
912 this->SetParameters(this->alpha, rate);
915template <
typename RealType>
918 SetRate(1.0 / scale);
921template <
typename RealType>
925 if (!this->allElementsArePositive(sample))
927 double mean = this->GetSampleMean(sample);
928 double coef = this->alpha - (unbiased ? 1.0 / sample.size() : 0.0);
929 this->SetParameters(this->alpha, coef / mean);
932template <
typename RealType>
938 if (!this->allElementsArePositive(sample))
940 double kappa = priorDistribution.
GetShape();
941 double gamma = priorDistribution.
GetRate();
942 double newShape = this->alpha * sample.size() + kappa;
943 double newRate = this->GetSampleSum(sample) + gamma;
945 this->SetParameters(this->alpha, MAP ? posteriorDistribution.
Mode() : posteriorDistribution.
Mean());
946 return posteriorDistribution;
950template <
typename RealType>
953 return "Gamma(" + this->toStringWithPrecision(this->GetShape()) +
", " +
954 this->toStringWithPrecision(this->GetRate()) +
")";
957template <
typename RealType>
961 if (!this->allElementsArePositive(sample))
965 double shape = this->GetSampleMean(sample) * this->beta;
967 double s = this->GetSampleLogMean(sample) + this->logBeta;
968 if (!math::findRootNewtonFirstOrder<double>(
976 SetParameters(shape, this->beta);
979template <
typename RealType>
983 if (!this->allElementsArePositive(sample))
987 double average = this->GetSampleMean(sample);
988 double s = std::log(average) - this->GetSampleLogMean(sample);
989 double sm3 = s - 3.0, sp12 = 12.0 * s;
990 double shape = sm3 * sm3 + 2 * sp12;
991 shape = std::sqrt(shape);
995 if (!math::findRootNewtonFirstOrder<double>(
1004 SetParameters(shape, shape / average);
1007template <
typename RealType>
1010 return {std::log(x), x};
1013template <
typename RealType>
1016 return {this->alpha, this->beta};
1019template <
typename RealType>
1022 double shape = sourceParameters.first;
1023 double rate = sourceParameters.second;
1024 return {shape - 1, -rate};
1027template <
typename RealType>
1030 double shape = parameters.first + 1, rate = -parameters.second;
1031 double F = std::lgamma(shape);
1032 F -= shape * std::log(rate);
1036template <
typename RealType>
1039 double shape = parameters.first + 1, rate = -parameters.second;
1041 double gradF2 = shape / rate;
1042 return {gradF1, gradF2};
1045template <
typename RealType>
1051template <
typename RealType>
1054 double shapeq = parameters.first + 1, rateq = -parameters.second;
1055 double H = std::lgamma(shapeq);
1056 H -= shapeq * std::log(rateq);
1057 H -= (shapeq - 1) * (this->digammaAlpha - this->logBeta);
1058 H += rateq * this->alpha / this->beta;
1062template <
typename RealType>
1065 double H = this->lgammaAlpha;
1067 H -= (this->alpha - 1) * this->digammaAlpha;
1073template <
typename RealType>
1076 return "Chi-squared(" + this->toStringWithPrecision(GetDegree()) +
")";
1079template <
typename RealType>
1086template <
typename RealType>
1089 return "Erlang(" + this->toStringWithPrecision(this->GetShape()) +
", " +
1090 this->toStringWithPrecision(this->GetRate()) +
")";
1093template <
typename RealType>
1099template <
typename RealType>
1102 SetParameters(shape, this->beta);
The ChiSquaredRand class Chi-squared distribution.
Definition continuous/gamma.hpp:355
size_t GetDegree() const
Definition continuous/gamma.hpp:360
void SetDegree(size_t degree)
Definition continuous/gamma.hpp:1080
ChiSquaredRand(size_t degree=1)
Definition continuous/gamma.hpp:357
std::string Name() const override
Definition continuous/gamma.hpp:1074
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
The ErlangRand class Erlang distibution.
Definition continuous/gamma.hpp:375
static ErlangRand FromShapeScale(int shape, double scale)
Definition continuous/gamma.hpp:383
void SetParameters(size_t shape, double rate)
Definition continuous/gamma.hpp:1094
ErlangRand(int shape=1, double rate=1)
Definition continuous/gamma.hpp:377
std::string Name() const override
Definition continuous/gamma.hpp:1087
static ErlangRand FromShapeRate(int shape, double rate)
Definition continuous/gamma.hpp:380
void SetShape(size_t shape)
Definition continuous/gamma.hpp:1100
Definition exponential_family.hpp:14
The FreeRateGammaDistribution class Abstract class for Gamma distribution with arbitrary scale/rate...
Definition continuous/gamma.hpp:252
void SetRate(double rate)
set rate β
Definition continuous/gamma.hpp:910
void SetScale(double scale)
set scale θ = 1/β
Definition continuous/gamma.hpp:916
GammaRand< RealType > FitRateBayes(std::span< const RealType > sample, const GammaDistribution< RealType > &priorDistribution, bool MAP=false)
set rate, returned by bayesian estimation
Definition continuous/gamma.hpp:934
void FitRate(std::span< const RealType > sample, bool unbiased=false)
set rate, estimated via maximum-likelihood method if unbiased = false, otherwise set rate,...
Definition continuous/gamma.hpp:922
FreeRateGammaDistribution(double shape, double rate)
Definition continuous/gamma.hpp:254
The GammaDistribution class Abstract class for Gamma distribution.
Definition continuous/gamma.hpp:31
double beta
rate β
Definition continuous/gamma.hpp:37
RealType operator()(G &g) const
Definition continuous/gamma.hpp:641
Support SupportType() const override
Definition continuous/gamma.hpp:58
long double Variance() const override
Definition continuous/gamma.hpp:705
RealType Median() const override
Definition continuous/gamma.hpp:723
double digammaAlpha
ψ(α)
Definition continuous/gamma.hpp:43
long double GeometricMean() const
Definition continuous/gamma.hpp:699
double logBeta
log(β)
Definition continuous/gamma.hpp:42
double alpha
shape α
Definition continuous/gamma.hpp:36
static RealType StandardVariate(double shape, G &g)
Definition continuous/gamma.hpp:605
double GetLogRate() const noexcept
Definition continuous/gamma.hpp:102
double F(const RealType &x) const override
Definition continuous/gamma.hpp:473
double pdfCoef
α * log(β) - log(Γ(α))
Definition continuous/gamma.hpp:40
double GetShape() const noexcept
Definition continuous/gamma.hpp:78
void SetShape(double shape)
SetShape.
Definition continuous/gamma.hpp:438
RealType MinValue() const override
Definition continuous/gamma.hpp:59
double theta
scale θ = 1/β
Definition continuous/gamma.hpp:38
double GetLogGammaShape() const noexcept
Definition continuous/gamma.hpp:90
long double Mean() const override
Definition continuous/gamma.hpp:693
long double ExcessKurtosis() const override
Definition continuous/gamma.hpp:735
double GetLogShape() const noexcept
Definition continuous/gamma.hpp:94
void SetParameters(double shape, double rate)
Definition continuous/gamma.hpp:410
double GetDigammaShape() const noexcept
Definition continuous/gamma.hpp:98
double lgammaAlpha
log(Γ(α))
Definition continuous/gamma.hpp:39
static RealType Variate(double shape, double rate, G &g)
Definition continuous/gamma.hpp:630
RealType MaxValue() const override
Definition continuous/gamma.hpp:60
double GetScale() const noexcept
Definition continuous/gamma.hpp:82
double logF(const RealType &x) const
Definition continuous/gamma.hpp:479
long double GeometricVariance() const
Definition continuous/gamma.hpp:711
double GetRate() const noexcept
Definition continuous/gamma.hpp:86
double logAlpha
log(α)
Definition continuous/gamma.hpp:41
virtual ~GammaDistribution()
Definition continuous/gamma.hpp:56
double logf(const RealType &x) const override
Definition continuous/gamma.hpp:457
GammaDistribution(double shape, double rate)
Definition continuous/gamma.hpp:404
double logS(const RealType &x) const
Definition continuous/gamma.hpp:491
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition continuous/gamma.hpp:717
long double Skewness() const override
Definition continuous/gamma.hpp:729
double f(const RealType &x) const override
Definition continuous/gamma.hpp:444
double S(const RealType &x) const override
Definition continuous/gamma.hpp:485
The GammaRand class Gamma distribution.
Definition continuous/gamma.hpp:295
void Fit(std::span< const RealType > sample)
set shape and rate, estimated via maximum-likelihood method
Definition continuous/gamma.hpp:980
DoublePair SourceToNatural(DoublePair sourceParameters) const override
Definition continuous/gamma.hpp:1020
double CrossEntropyAdjusted(DoublePair parameters) const override
Definition continuous/gamma.hpp:1052
static GammaRand FromShapeScale(double shape, double scale)
Definition continuous/gamma.hpp:311
DoublePair LogNormalizerGradient(DoublePair parameters) const override
Definition continuous/gamma.hpp:1037
std::string Name() const override
Definition continuous/gamma.hpp:951
double EntropyAdjusted() const override
Definition continuous/gamma.hpp:1063
double CarrierMeasure(RealType) const override
Definition continuous/gamma.hpp:1046
void FitShape(std::span< const RealType > sample)
set shape, estimated via maximum-likelihood method
Definition continuous/gamma.hpp:958
GammaRand(double shape=1, double rate=1)
Definition continuous/gamma.hpp:297
static GammaRand FromShapeRate(double shape, double rate)
Definition continuous/gamma.hpp:304
double LogNormalizer(DoublePair parameters) const override
Definition continuous/gamma.hpp:1028
DoublePair SourceParameters() const override
Definition continuous/gamma.hpp:1014
DoublePair SufficientStatistic(RealType x) const override
Definition continuous/gamma.hpp:1008
T Variate() const
Uses the engine of this object, so it is not thread-safe for one object; use operator() with one engi...
Definition distribution.hpp:133
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
#define RANDLIB_DEPRECATED_FIT_MEMBER
Definition fwd.hpp:9
constexpr long double ln2
Definition constants.hpp:18
constexpr long double egamma
Definition constants.hpp:36
constexpr long double inv_e
Definition constants.hpp:35
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 qgamma(std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logA, std::type_identity_t< Real > lgammaA)
Calculate upper regularized incomplete gamma function, accelerated by using precalculated values of l...
Definition math/gamma.hpp:938
Real digamma(Real x)
Definition math/gamma.hpp:691
Real lpgamma(std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logA, std::type_identity_t< Real > lgammaA)
Calculate logarithm of lower incomplete gamma function, accelerated by using precalculated value of l...
Definition math/gamma.hpp:875
Real W0Lambert(Real x, std::type_identity_t< Real > epsilon=Real{1e-11})
Definition functions.hpp:689
Real Wm1Lambert(Real x, std::type_identity_t< Real > epsilon=Real{1e-11})
Definition functions.hpp:722
Real trigamma(Real x)
Definition math/gamma.hpp:720
Real lqgamma(std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logA, std::type_identity_t< Real > lgammaA)
Calculate logarithm of upper incomplete gamma function, accelerated by using precalculated values of ...
Definition math/gamma.hpp:917
Real pgamma(std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logA, std::type_identity_t< Real > lgammaA)
Calculate lower regularized incomplete gamma function, accelerated by using precalculated value of lo...
Definition math/gamma.hpp:896
Real digammamLog(Real x)
Definition math/gamma.hpp:710
Real erfcinv(Real p)
Definition functions.hpp:485
Definition bivariate_normal.hpp:10
@ WrongSample
the sample could not have been drawn from this distribution
@ Undefined
any other failure
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15
Pair< double > DoublePair
Definition fwd.hpp:39