21template <
typename IntType>
34 [[nodiscard]] std::string
Name()
const override;
36 [[nodiscard]] IntType
MinValue()
const override {
return a; }
37 [[nodiscard]] IntType
MaxValue()
const override {
return b; }
41 [[nodiscard]]
double P(
const IntType &k)
const override;
42 [[nodiscard]]
double logP(
const IntType &k)
const override;
43 [[nodiscard]]
double F(
const IntType &k)
const override;
45 template <std::uniform_random_bit_generator G>
48 template <std::uniform_random_bit_generator G>
49 [[nodiscard]]
static IntType
StandardVariate(IntType minValue, IntType maxValue, G &g);
51 [[nodiscard]]
long double Mean()
const override;
52 [[nodiscard]]
long double Variance()
const override;
53 [[nodiscard]] IntType
Median()
const override;
54 [[nodiscard]] IntType
Mode()
const override;
55 [[nodiscard]]
long double Skewness()
const override;
59 std::complex<double> CFImpl(
double t)
const override;
62 [[nodiscard]]
long double Entropy()
const;
78template <
typename IntType>
81 SetBoundaries(minValue, maxValue);
84template <
typename IntType>
87 return "Uniform Discrete(" + this->toStringWithPrecision(MinValue()) +
", " +
88 this->toStringWithPrecision(MaxValue()) +
")";
91template <
typename IntType>
94 if (!(minValue <= maxValue))
95 throw std::invalid_argument(
96 "Uniform discrete distribution: minimum value shouldn't be greater than maximum value");
106template <
typename IntType>
109 return (k < a || k > b) ? 0.0 : nInv;
112template <
typename IntType>
115 return (k < a || k > b) ? -INFINITY : -logN;
118template <
typename IntType>
125 return (k - a + 1) * nInv;
128template <
typename IntType>
129template <std::uniform_random_bit_generator G>
135template <
typename IntType>
136template <std::uniform_random_bit_generator G>
139 if (maxValue <= minValue)
141 auto n =
static_cast<std::uint64_t
>(maxValue - minValue) + 1;
145template <
typename IntType>
148 return 0.5 * (b + a);
151template <
typename IntType>
156 return nm1 * np1 / 12;
159template <
typename IntType>
165template <
typename IntType>
169 return 0.5 * (a + b);
172template <
typename IntType>
178template <
typename IntType>
189template <
typename IntType>
193 const double reduced = std::remainder(t, period);
196 const double halfAngle = 0.5 * reduced;
197 const double amplitude = std::sin(n * halfAngle) / (n * std::sin(halfAngle));
198 const double phase = (0.5 *
static_cast<double>(a) + 0.5 *
static_cast<double>(b)) * reduced;
199 return amplitude * std::complex<double>(std::cos(phase), std::sin(phase));
202template <
typename IntType>
208template <
typename IntType>
211 bool sampleIsInsideInterval =
212 this->allElementsAreNotSmallerThan(a, sample) && this->allElementsAreNotGreaterThan(b, sample);
213 return sampleIsInsideInterval ? std::pow(n, -
static_cast<double>(sample.size())) : 0.0;
216template <
typename IntType>
219 bool sampleIsInsideInterval =
220 this->allElementsAreNotSmallerThan(a, sample) && this->allElementsAreNotGreaterThan(b, sample);
221 int sample_size = sample.size();
222 return sampleIsInsideInterval ? -sample_size * logN : -INFINITY;
225template <
typename IntType>
228 IntType minVar = *std::min_element(sample.begin(), sample.end());
229 IntType maxVar = *std::max_element(sample.begin(), sample.end());
230 this->SetBoundaries(minVar, maxVar);
The DiscreteDistribution class Abstract class for all discrete distributions.
Definition discrete.hpp:21
virtual void sample(detail::EngineRef g, std::span< T > outputData) const
Fills the output with variate(g); distributions with a faster bulk algorithm override it.
Definition distribution.hpp:66
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
#define RANDLIB_DEPRECATED_FIT_MEMBER
Definition fwd.hpp:9
constexpr long double pi
Definition constants.hpp:22
std::uint64_t uniformBelow(G &g, std::uint64_t n)
Definition engine/uniform.hpp:100
Definition bivariate_normal.hpp:10
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15