22template <
typename RealType>
38 [[nodiscard]] std::string
Name()
const override;
40 [[nodiscard]] RealType
MinValue()
const override {
return -INFINITY; }
41 [[nodiscard]] RealType
MaxValue()
const override {
return INFINITY; }
43 void SetParameters(
double location,
double variance,
double rate);
44 [[nodiscard]]
inline double GetLocation()
const {
return X.GetLocation(); }
45 [[nodiscard]]
inline double GetScale()
const {
return X.GetScale(); }
46 [[nodiscard]]
inline double GetRate()
const {
return Y.GetRate(); }
50 double exponentialTerm(
const RealType &x)
const;
53 [[nodiscard]]
double f(
const RealType &x)
const override;
54 [[nodiscard]]
double logf(
const RealType &x)
const override;
55 [[nodiscard]]
double F(
const RealType &x)
const override;
56 [[nodiscard]]
double S(
const RealType &x)
const override;
57 template <std::uniform_random_bit_generator G>
60 template <std::uniform_random_bit_generator G>
63 [[nodiscard]]
long double Mean()
const override;
64 [[nodiscard]]
long double Variance()
const override;
65 [[nodiscard]]
long double Skewness()
const override;
69 std::complex<double> CFImpl(
double t)
const override;
77template <
typename RealType>
81 SetParameters(location, variance, rate);
84template <
typename RealType>
87 return "Exponentially modified Gaussian(" + this->toStringWithPrecision(GetLocation()) +
", " +
88 this->toStringWithPrecision(X.Variance()) +
", " + this->toStringWithPrecision(GetRate()) +
")";
91template <
typename RealType>
94 if (!std::isfinite(location))
95 throw std::invalid_argument(
"Exponentially modified Gaussian distribution: location should be finite");
97 throw std::invalid_argument(
"Exponentially modified Gaussian distribution: variance should be positive");
99 throw std::invalid_argument(
"Exponentially modified Gaussian distribution: rate should be positive");
101 X.SetLocation(location);
102 X.SetVariance(variance);
105 double mu = X.GetLocation();
106 double sigma = X.GetScale();
107 double beta = Y.GetRate();
108 double var = sigma * sigma;
109 a = 0.5 * beta * var;
116template <
typename RealType>
122 double z = (a - x) * b;
124 double w = (x - X.GetLocation()) * b;
125 return std::make_pair(0.5 * lambda *
math::erfcx(z), -w * w);
127 return std::make_pair(0.5 * lambda * std::erfc(z), lambda * (c - x));
130template <
typename RealType>
133 auto [y, exponent] = faux(x);
134 return y * std::exp(exponent);
137template <
typename RealType>
140 auto [y, exponent] = faux(x);
141 return std::log(y) + exponent;
144template <
typename RealType>
148 double w = (x - X.GetLocation()) / X.
GetScale();
151 return std::exp(v * (0.5 * v - w)) * X.F(x - v * X.GetScale());
154template <
typename RealType>
157 return std::max(X.F(x) - exponentialTerm(x), 0.0);
160template <
typename RealType>
163 return std::min(X.S(x) + exponentialTerm(x), 1.0);
166template <
typename RealType>
167template <std::uniform_random_bit_generator G>
173template <
typename RealType>
174template <std::uniform_random_bit_generator G>
180template <
typename RealType>
183 return X.Mean() + Y.Mean();
186template <
typename RealType>
189 return X.Variance() + Y.Variance();
192template <
typename RealType>
195 return X.
CF(t) * Y.CF(t);
198template <
typename RealType>
201 long double sigma = X.GetScale();
202 long double lambda = Y.GetRate();
203 long double tmp = 1.0 / (sigma * lambda);
204 long double tmpSq = tmp * tmp;
205 long double y = 1.0 + tmpSq;
212template <
typename RealType>
215 long double sigma = X.GetScale();
216 long double lambda = Y.GetRate();
217 long double tmp = 1.0 / (sigma * lambda);
219 long double numerator = 1.0 + 2.0 * tmp + 3.0 * tmp * tmp;
220 long double denominator = 1.0 + tmp;
221 denominator *= denominator;
222 long double y = numerator / denominator - 1.0;
The ContinuousDistribution class Abstract class for all continuous distributions.
Definition continuous.hpp:22
The ExponentialRand class Exponential distribution.
Definition exponential.hpp:28
The ExponentiallyModifiedGaussianRand class Exponentially-modified Gaussian distribution.
Definition exponentially_modified_gaussian.hpp:24
ExponentiallyModifiedGaussianRand(double location=0, double variance=1, double rate=1)
βσ
Definition exponentially_modified_gaussian.hpp:78
long double Mean() const override
Definition exponentially_modified_gaussian.hpp:181
long double ExcessKurtosis() const override
Definition exponentially_modified_gaussian.hpp:213
double F(const RealType &x) const override
Definition exponentially_modified_gaussian.hpp:155
Support SupportType() const override
Definition exponentially_modified_gaussian.hpp:39
RealType MaxValue() const override
Definition exponentially_modified_gaussian.hpp:41
double GetScale() const
Definition exponentially_modified_gaussian.hpp:45
std::string Name() const override
Definition exponentially_modified_gaussian.hpp:85
RealType MinValue() const override
Definition exponentially_modified_gaussian.hpp:40
long double Variance() const override
Definition exponentially_modified_gaussian.hpp:187
double GetLocation() const
Definition exponentially_modified_gaussian.hpp:44
long double Skewness() const override
Definition exponentially_modified_gaussian.hpp:199
void SetParameters(double location, double variance, double rate)
Definition exponentially_modified_gaussian.hpp:92
double f(const RealType &x) const override
Definition exponentially_modified_gaussian.hpp:131
double logf(const RealType &x) const override
Definition exponentially_modified_gaussian.hpp:138
double S(const RealType &x) const override
Definition exponentially_modified_gaussian.hpp:161
double GetRate() const
Definition exponentially_modified_gaussian.hpp:46
static RealType StandardVariate(G &g)
Definition exponentially_modified_gaussian.hpp:175
RealType operator()(G &g) const
Definition exponentially_modified_gaussian.hpp:168
The NormalRand class Normal distribution.
Definition normal.hpp:31
std::complex< double > CF(double t) const
Definition univariate.hpp:357
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
constexpr long double inv_sqrt2
Definition constants.hpp:28
Real standardNormal(G &g)
Ziggurat algorithm of Marsaglia and Tsang with 256 layers and an explicit sign bit.
Definition variates.hpp:45
Real erfcx(Real x)
Definition functions.hpp:525
Definition bivariate_normal.hpp:10
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15
Pair< double > DoublePair
Definition fwd.hpp:39