19template <
typename IntType>
29 [[nodiscard]] std::string
Name()
const override;
31 [[nodiscard]] IntType
MinValue()
const override {
return 1; }
32 [[nodiscard]] IntType
MaxValue()
const override {
return std::numeric_limits<IntType>::max(); }
37 [[nodiscard]]
double P(
const IntType &k)
const override;
38 [[nodiscard]]
double logP(
const IntType &k)
const override;
46 double betaFun(IntType a)
const;
49 [[nodiscard]]
double F(
const IntType &k)
const override;
50 [[nodiscard]]
double S(
const IntType &k)
const override;
51 template <std::uniform_random_bit_generator G>
54 [[nodiscard]]
long double Mean()
const override;
55 [[nodiscard]]
long double Variance()
const override;
56 [[nodiscard]] IntType
Mode()
const override;
59 std::complex<double> CFImpl(
double t)
const override;
69template <
typename IntType>
72 SetProbability(probability);
75template <
typename IntType>
78 return "Logarithmic(" + this->toStringWithPrecision(GetProbability()) +
")";
81template <
typename IntType>
84 if (!(probability > 0.0 && probability < 1.0))
85 throw std::invalid_argument(
"Logarithmic distribution: probability parameter should in interval (0, 1)");
87 logProb = std::log(p);
88 log1mProb = std::log1pl(-p);
91template <
typename IntType>
94 return (k < 1) ? 0.0 : -std::pow(p, k) / (k * log1mProb);
97template <
typename IntType>
100 return (k < 1) ? -INFINITY : k * logProb - std::log(-k * log1mProb);
103template <
typename IntType>
107 double denom = a + 2;
108 double sum = p * p / (a + 2) + p / (a + 1) + 1.0 / a;
112 add = std::exp(i * logProb) / (++denom);
116 return std::exp(a * logProb) * sum;
119template <
typename IntType>
122 return (k < 1) ? 0.0 : 1 + betaFun(k + 1) / log1mProb;
125template <
typename IntType>
128 return (k < 1) ? 1.0 : -betaFun(k + 1) / log1mProb;
131template <
typename IntType>
132template <std::uniform_random_bit_generator G>
141 double y = -std::expm1l(U * log1mProb);
146 return std::floor(1.0 + std::log(V) / std::log(y));
149template <
typename IntType>
152 return -p / (1.0 - p) / log1mProb;
155template <
typename IntType>
158 long double var = p / log1mProb + 1;
161 long double q = 1.0 - p;
162 return -var / (q * q);
165template <
typename IntType>
168 std::complex<double> y(std::cos(t), std::sin(t));
169 y = std::log(1.0 - p * y);
170 return y / log1mProb;
173template <
typename IntType>
The DiscreteDistribution class Abstract class for all discrete distributions.
Definition discrete.hpp:21
The LogarithmicRand class Logarithmic distribution.
Definition logarithmic.hpp:21
std::string Name() const override
Definition logarithmic.hpp:76
double P(const IntType &k) const override
Definition logarithmic.hpp:92
IntType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition logarithmic.hpp:174
IntType MinValue() const override
Definition logarithmic.hpp:31
Support SupportType() const override
Definition logarithmic.hpp:30
double GetProbability() const noexcept
Definition logarithmic.hpp:35
void SetProbability(double probability)
Definition logarithmic.hpp:82
LogarithmicRand(double probability)
Definition logarithmic.hpp:70
double S(const IntType &k) const override
Definition logarithmic.hpp:126
long double Variance() const override
Definition logarithmic.hpp:156
IntType operator()(G &g) const
Definition logarithmic.hpp:133
double logP(const IntType &k) const override
Definition logarithmic.hpp:98
long double Mean() const override
Definition logarithmic.hpp:150
double F(const IntType &k) const override
Definition logarithmic.hpp:120
IntType MaxValue() const override
Definition logarithmic.hpp:32
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
Real standardNormal(G &g)
Ziggurat algorithm of Marsaglia and Tsang with 256 layers and an explicit sign bit.
Definition variates.hpp:45
constexpr long double minimumTolerance
Definition constants.hpp:44
Definition bivariate_normal.hpp:10
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15