21template <
typename RealType>
42 [[nodiscard]] std::string
Name()
const override;
44 [[nodiscard]] RealType
MinValue()
const override {
return 0; }
45 [[nodiscard]] RealType
MaxValue()
const override {
return INFINITY; }
48 [[nodiscard]]
inline double GetShape() const noexcept {
return alpha; }
49 [[nodiscard]]
inline double GetRate() const noexcept {
return beta; }
50 [[nodiscard]]
inline double GetLogShape()
const {
return X.GetLogShape(); }
51 [[nodiscard]]
inline double GetLogRate()
const {
return X.GetLogRate(); }
53 [[nodiscard]]
double logf(
const RealType &x)
const override;
54 [[nodiscard]]
double F(
const RealType &x)
const override;
55 [[nodiscard]]
double S(
const RealType &x)
const override;
56 template <std::uniform_random_bit_generator G>
59 [[nodiscard]]
long double Mean()
const override;
60 [[nodiscard]]
long double Variance()
const override;
61 [[nodiscard]] RealType
Median()
const override;
62 [[nodiscard]] RealType
Mode()
const override;
63 [[nodiscard]]
long double Skewness()
const override;
67 RealType quantileImpl(
double p)
const override;
68 RealType quantileImpl1m(
double p)
const override;
69 std::complex<double> CFImpl(
double t)
const override;
80template <
typename RealType>
83 SetParameters(shape, rate);
86template <
typename RealType>
89 return "Inverse-Gamma(" + this->toStringWithPrecision(GetShape()) +
", " + this->toStringWithPrecision(GetRate()) +
93template <
typename RealType>
97 throw std::invalid_argument(
"Inverse-Gamma distribution: shape should be positive");
99 throw std::invalid_argument(
"Inverse-Gamma distribution: rate should be positive");
100 X.SetParameters(shape, rate);
101 alpha = X.GetShape();
103 pdfCoef = alpha * X.GetLogRate() - X.GetLogGammaShape();
106template <
typename RealType>
111 double logX = std::log(x);
112 double y = -(alpha - 1.0) * logX;
118template <
typename RealType>
121 return (x > 0.0) ? X.S(1.0 / x) : 0.0;
124template <
typename RealType>
127 return (x > 0.0) ? X.F(1.0 / x) : 1.0;
130template <
typename RealType>
131template <std::uniform_random_bit_generator G>
137template <
typename RealType>
141 for (RealType &var : outputData)
145template <
typename RealType>
148 return (alpha > 1) ? beta / (alpha - 1) : INFINITY;
151template <
typename RealType>
156 double var = beta / (alpha - 1);
158 return var / (alpha - 2);
161template <
typename RealType>
164 return 1.0 / X.Median();
167template <
typename RealType>
170 return beta / (alpha + 1);
173template <
typename RealType>
179template <
typename RealType>
180RealType InverseGammaRand<RealType>::quantileImpl1m(
double p)
const
182 return 1.0 / X.Quantile(p);
185template <
typename RealType>
186std::complex<double> InverseGammaRand<RealType>::CFImpl(
double t)
const
188 return this->integrateCharacteristicFunction(t);
191template <
typename RealType>
194 return (alpha > 3) ? 4 * std::sqrt(alpha - 2) / (alpha - 3) : INFINITY;
197template <
typename RealType>
202 long double numerator = 30 * alpha - 66.0;
203 long double denominator = (alpha - 3) * (alpha - 4);
204 return numerator / denominator;
The ContinuousDistribution class Abstract class for all continuous distributions.
Definition continuous.hpp:22
The GammaRand class Gamma distribution.
Definition continuous/gamma.hpp:295
The InverseGammaRand class Inverse-Gamma distribution.
Definition inverse_gamma.hpp:23
void SetParameters(double shape, double rate)
Definition inverse_gamma.hpp:94
InverseGammaRand(double shape=1, double rate=1)
Definition inverse_gamma.hpp:81
double GetLogRate() const
Definition inverse_gamma.hpp:51
double GetRate() const noexcept
Definition inverse_gamma.hpp:49
RealType MaxValue() const override
Definition inverse_gamma.hpp:45
double F(const RealType &x) const override
Definition inverse_gamma.hpp:119
double GetShape() const noexcept
Definition inverse_gamma.hpp:48
double GetLogShape() const
Definition inverse_gamma.hpp:50
std::string Name() const override
Definition inverse_gamma.hpp:87
RealType Median() const override
Definition inverse_gamma.hpp:162
double S(const RealType &x) const override
Definition inverse_gamma.hpp:125
long double Mean() const override
Definition inverse_gamma.hpp:146
long double Variance() const override
Definition inverse_gamma.hpp:152
static InverseGammaRand FromShapeRate(double shape, double rate)
Definition inverse_gamma.hpp:37
double logf(const RealType &x) const override
Definition inverse_gamma.hpp:107
Support SupportType() const override
Definition inverse_gamma.hpp:43
double GetLogGammaShape() const
Definition inverse_gamma.hpp:72
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition inverse_gamma.hpp:168
long double ExcessKurtosis() const override
Definition inverse_gamma.hpp:198
RealType MinValue() const override
Definition inverse_gamma.hpp:44
long double Skewness() const override
Definition inverse_gamma.hpp:192
RealType operator()(G &g) const
Definition inverse_gamma.hpp:132
void Sample(std::span< T > outputData) const
Fills the output with variates drawn with the engine of this object.
Definition distribution.hpp:139
T Quantile1m(double p) const
Definition univariate.hpp:324
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
Definition bivariate_normal.hpp:10
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15