17template <
typename RealType>
25 double pdfCoef = 0, logpdfCoef = 0, expmScaledLambda = 0;
30 [[nodiscard]] std::string
Name()
const override;
33 [[nodiscard]]
inline double GetRate() const noexcept {
return lambda; }
35 [[nodiscard]]
double f(
const RealType &x)
const override;
36 [[nodiscard]]
double logf(
const RealType &x)
const override;
37 [[nodiscard]]
double F(
const RealType &x)
const override;
38 [[nodiscard]]
double S(
const RealType &x)
const override;
39 template <std::uniform_random_bit_generator G>
44 [[nodiscard]] RealType
Median()
const override;
45 [[nodiscard]] RealType
Mode()
const override;
50 std::complex<double>
CFImpl(
double t)
const override;
60template <
typename RealType>
67template <
typename RealType>
70 return "Wrapped Exponential(" + this->toStringWithPrecision(GetRate()) +
")";
73template <
typename RealType>
77 throw std::invalid_argument(
"Wrapped Exponential distribution: rate parameter should be positive");
79 logLambda = std::log(lambda);
81 expmScaledLambda = std::exp(-scaledLambda);
82 pdfCoef = -std::expm1l(-scaledLambda);
86template <
typename RealType>
89 return (x < this->MinValue() || x > this->MaxValue()) ? 0.0 : std::exp(logf(x));
92template <
typename RealType>
95 return (x < this->MinValue() || x > this->MaxValue()) ? -INFINITY : logLambda - lambda * x - logpdfCoef;
98template <
typename RealType>
103 return (x < this->MaxValue()) ? std::exp(
math::log1mexp(-lambda * x) - logpdfCoef) : 1.0;
106template <
typename RealType>
111 if (x >= this->MaxValue())
113 double y = std::expm1l(scaledLambda - lambda * x);
115 return expmScaledLambda * y;
118template <
typename RealType>
119template <std::uniform_random_bit_generator G>
125template <
typename RealType>
131template <
typename RealType>
134 return 1.0 - lambda / std::sqrt(1.0 + lambda * lambda);
137template <
typename RealType>
143template <
typename RealType>
149template <
typename RealType>
152 return -std::log1pl(-p * pdfCoef) / lambda;
155template <
typename RealType>
158 return -std::log(expmScaledLambda + p * pdfCoef) / lambda;
161template <
typename RealType>
165 std::complex<double> lambdaMinusIt(lambda, -t);
166 std::complex<double> wrap = 1.0 - std::exp(-lambdaMinusIt *
static_cast<double>(2 *
randlib::consts::pi));
167 return lambda * wrap / (lambdaMinusIt * pdfCoef);
The CircularDistribution class Abstract class for all continuous circular distributions.
Definition circular.hpp:19
The WrappedExponentialRand class Wrapped Exponential distribution.
Definition wrapped_exponential.hpp:19
RealType operator()(G &g) const
Definition wrapped_exponential.hpp:120
WrappedExponentialRand(double rate)
Definition wrapped_exponential.hpp:61
double f(const RealType &x) const override
Definition wrapped_exponential.hpp:87
double S(const RealType &x) const override
Definition wrapped_exponential.hpp:107
void SetRate(double rate)
Definition wrapped_exponential.hpp:74
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition wrapped_exponential.hpp:144
long double CircularMean() const override
Definition wrapped_exponential.hpp:126
std::string Name() const override
Definition wrapped_exponential.hpp:68
double logf(const RealType &x) const override
Definition wrapped_exponential.hpp:93
RealType quantileImpl(double p) const override
Definition wrapped_exponential.hpp:150
long double CircularVariance() const override
Definition wrapped_exponential.hpp:132
std::complex< double > CFImpl(double t) const override
Definition wrapped_exponential.hpp:162
RealType Median() const override
Definition wrapped_exponential.hpp:138
double F(const RealType &x) const override
Definition wrapped_exponential.hpp:99
RealType quantileImpl1m(double p) const override
Definition wrapped_exponential.hpp:156
double GetRate() const noexcept
Definition wrapped_exponential.hpp:33
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 half_pi
Definition constants.hpp:23
constexpr long double pi
Definition constants.hpp:22
Real standardNormal(G &g)
Ziggurat algorithm of Marsaglia and Tsang with 256 layers and an explicit sign bit.
Definition variates.hpp:45
Real log1mexp(Real x)
Definition functions.hpp:260
Real atan(Real x)
Definition functions.hpp:238
Real softplus(Real x)
Definition functions.hpp:252
Definition bivariate_normal.hpp:10