17template <
typename RealType>
29 FrechetRand(
double shape = 1,
double scale = 1,
double location = 0);
31 [[nodiscard]] std::string
Name()
const override;
33 [[nodiscard]] RealType
MinValue()
const override {
return m; }
34 [[nodiscard]] RealType
MaxValue()
const override {
return INFINITY; }
36 void SetParameters(
double shape,
double scale,
double location);
37 [[nodiscard]]
inline double GetShape() const noexcept {
return alpha; }
38 [[nodiscard]]
inline double GetScale() const noexcept {
return s; }
39 [[nodiscard]]
inline double GetLocation() const noexcept {
return m; }
41 [[nodiscard]]
double f(
const RealType &x)
const override;
42 [[nodiscard]]
double logf(
const RealType &x)
const override;
43 [[nodiscard]]
double F(
const RealType &x)
const override;
44 [[nodiscard]]
double S(
const RealType &x)
const override;
45 template <std::uniform_random_bit_generator G>
48 [[nodiscard]]
long double Mean()
const override;
49 [[nodiscard]]
long double Variance()
const override;
50 [[nodiscard]] RealType
Median()
const override;
51 [[nodiscard]] RealType
Mode()
const override;
52 [[nodiscard]]
long double Skewness()
const override;
56 RealType quantileImpl(
double p)
const override;
57 RealType quantileImpl1m(
double p)
const override;
58 std::complex<double> CFImpl(
double t)
const override;
61 [[nodiscard]]
long double Entropy()
const;
71template <
typename RealType>
74 SetParameters(shape, scale, location);
77template <
typename RealType>
80 return "Frechet(" + this->toStringWithPrecision(GetShape()) +
", " + this->toStringWithPrecision(GetScale()) +
81 ", " + this->toStringWithPrecision(GetLocation()) +
")";
84template <
typename RealType>
87 if (!std::isfinite(location))
88 throw std::invalid_argument(
"Frechet distribution: location should be finite");
90 throw std::invalid_argument(
"Frechet distribution: shape should be positive");
92 throw std::invalid_argument(
"Frechet distribution: scale should be positive");
94 alphaInv = 1.0 / alpha;
96 pdfCoef = std::log(alpha / s);
100template <
typename RealType>
103 return (x <= m) ? 0.0 : std::exp(logf(x));
106template <
typename RealType>
111 double xAdj = (x - m) / s;
112 double logxAdj = std::log(xAdj);
113 double a = alpha * logxAdj;
114 double expA = std::exp(-a);
115 return pdfCoef - a - expA - logxAdj;
118template <
typename RealType>
123 double xAdj = (x - m) / s;
124 double xPow = std::pow(xAdj, -alpha);
125 return std::exp(-xPow);
128template <
typename RealType>
133 double xAdj = (x - m) / s;
134 double xPow = std::pow(xAdj, -alpha);
135 return -std::expm1l(-xPow);
138template <
typename RealType>
139template <std::uniform_random_bit_generator G>
145template <
typename RealType>
150 return m + s * std::tgammal(1.0 - alphaInv);
153template <
typename RealType>
158 long double var = std::tgammal(1.0 - alphaInv);
160 var = std::tgammal(1.0 - 2 * alphaInv) - var;
164template <
typename RealType>
167 RealType y = -std::log(p);
168 y = s / std::pow(y, alphaInv);
172template <
typename RealType>
173RealType FrechetRand<RealType>::quantileImpl1m(
double p)
const
175 RealType y = -std::log1pl(-p);
176 y = s / std::pow(y, alphaInv);
180template <
typename RealType>
181std::complex<double> FrechetRand<RealType>::CFImpl(
double t)
const
183 return this->integrateCharacteristicFunction(t);
186template <
typename RealType>
192template <
typename RealType>
195 RealType y = alpha / (1.0 + alpha);
196 y = std::pow(y, alphaInv);
200template <
typename RealType>
205 long double x = std::tgammal(1.0 - alphaInv);
206 long double y = std::tgammal(1.0 - 2.0 * alphaInv);
207 long double z = std::tgammal(1.0 - 3.0 * alphaInv);
208 long double numerator = 2 * x * x - 3 * y;
211 long double denominator = y - x * x;
212 denominator = std::pow(denominator, 1.5);
213 return numerator / denominator;
216template <
typename RealType>
221 long double x = std::tgammal(1.0 - alphaInv);
222 long double y = std::tgammal(1.0 - 2.0 * alphaInv);
223 long double z = std::tgammal(1.0 - 3.0 * alphaInv);
224 long double w = std::tgammal(1.0 - 4.0 * alphaInv);
225 long double numerator = w - 4 * z * x + 3 * y * y;
226 long double denominator = y - x * x;
227 denominator *= denominator;
228 return numerator / denominator - 6.0;
231template <
typename RealType>
The ContinuousDistribution class Abstract class for all continuous distributions.
Definition continuous.hpp:22
The FrechetRand class Frechet distribution.
Definition frechet.hpp:19
FrechetRand(double shape=1, double scale=1, double location=0)
Definition frechet.hpp:72
double S(const RealType &x) const override
Definition frechet.hpp:129
long double ExcessKurtosis() const override
Definition frechet.hpp:217
RealType Median() const override
Definition frechet.hpp:187
double GetShape() const noexcept
Definition frechet.hpp:37
RealType MinValue() const override
Definition frechet.hpp:33
void SetParameters(double shape, double scale, double location)
Definition frechet.hpp:85
double GetScale() const noexcept
Definition frechet.hpp:38
long double Entropy() const
Definition frechet.hpp:232
double logf(const RealType &x) const override
Definition frechet.hpp:107
long double Mean() const override
Definition frechet.hpp:146
double GetLocation() const noexcept
Definition frechet.hpp:39
double F(const RealType &x) const override
Definition frechet.hpp:119
double f(const RealType &x) const override
Definition frechet.hpp:101
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition frechet.hpp:193
RealType operator()(G &g) const
Definition frechet.hpp:140
Support SupportType() const override
Definition frechet.hpp:32
long double Variance() const override
Definition frechet.hpp:154
std::string Name() const override
Definition frechet.hpp:78
long double Skewness() const override
Definition frechet.hpp:201
RealType MaxValue() const override
Definition frechet.hpp:34
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
constexpr long double ln2
Definition constants.hpp:18
constexpr long double egamma
Definition constants.hpp:36
Real standardNormal(G &g)
Ziggurat algorithm of Marsaglia and Tsang with 256 layers and an explicit sign bit.
Definition variates.hpp:45
Definition bivariate_normal.hpp:10
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15