28template <
typename RealType>
34 UniformRand(
double minValue = 0,
double maxValue = 1);
35 [[nodiscard]] std::string
Name()
const override;
40 [[nodiscard]] RealType
MinValue()
const override {
return this->
a; }
41 [[nodiscard]] RealType
MaxValue()
const override {
return this->
b; }
43 [[nodiscard]]
double f(
const RealType &x)
const override;
44 [[nodiscard]]
double logf(
const RealType &x)
const override;
45 [[nodiscard]]
double F(
const RealType &x)
const override;
46 [[nodiscard]]
double S(
const RealType &x)
const override;
47 template <std::uniform_random_bit_generator G>
54 template <std::uniform_random_bit_generator G>
61 template <std::uniform_random_bit_generator G>
68 template <std::uniform_random_bit_generator G>
71 [[nodiscard]]
long double Mean()
const override;
72 [[nodiscard]]
long double Variance()
const override;
73 [[nodiscard]] RealType
Median()
const override;
74 [[nodiscard]] RealType
Mode()
const override;
75 [[nodiscard]]
long double Skewness()
const override;
79 RealType quantileImpl(
double p)
const override;
80 RealType quantileImpl1m(
double p)
const override;
82 std::complex<double> CFImpl(
double t)
const override;
84 static constexpr char TOO_LARGE_A[] =
85 "Minimum element of the sample is smaller than lower boundary returned by method: ";
86 static constexpr char TOO_SMALL_B[] =
87 "Maximum element of the sample is greater than upper boundary returned by method: ";
90 [[nodiscard]]
long double Entropy()
const;
92 [[nodiscard]]
double LikelihoodFunction(std::span<const RealType> sample)
const override;
135template <
typename RealType>
141template <
typename RealType>
144 return "Uniform(" + this->toStringWithPrecision(MinValue()) +
", " + this->toStringWithPrecision(MaxValue()) +
")";
147template <
typename RealType>
150 return (x < this->a || x > this->b) ? 0.0 : this->bmaInv;
153template <
typename RealType>
156 return (x < this->a || x > this->b) ? -INFINITY : -this->logbma;
159template <
typename RealType>
164 return (x > this->b) ? 1.0 : this->bmaInv * (x - this->a);
167template <
typename RealType>
172 return (x > this->b) ? 0.0 : this->bmaInv * (this->b - x);
175template <
typename RealType>
176template <std::uniform_random_bit_generator G>
179 return this->a + StandardVariate(g) * this->bma;
182template <
typename RealType>
183template <std::uniform_random_bit_generator G>
189template <
typename RealType>
190template <std::uniform_random_bit_generator G>
196template <
typename RealType>
197template <std::uniform_random_bit_generator G>
203template <
typename RealType>
206 return 0.5 * (this->b + this->a);
209template <
typename RealType>
212 return this->bma * this->bma / 12;
215template <
typename RealType>
218 return 0.5 * (this->b + this->a);
221template <
typename RealType>
225 return 0.5 * (this->b + this->a);
228template <
typename RealType>
234template <
typename RealType>
240template <
typename RealType>
243 return this->a + this->bma * p;
246template <
typename RealType>
247RealType UniformRand<RealType>::quantileImpl1m(
double p)
const
249 return this->b - this->bma * p;
252template <
typename RealType>
253std::complex<double> UniformRand<RealType>::CFImpl(
double t)
const
255 double cosX = std::cos(t * this->b), sinX = std::sin(t * this->b);
256 double cosY = std::cos(t * this->a), sinY = std::sin(t * this->a);
257 std::complex<double> numerator(cosX - cosY, sinX - sinY);
258 std::complex<double> denominator(0, t * this->bma);
259 return numerator / denominator;
262template <
typename RealType>
265 return (this->b == this->a) ? -INFINITY : std::log(this->bma);
268template <
typename RealType>
271 bool sampleIsInsideInterval =
272 this->allElementsAreNotSmallerThan(this->a, sample) && this->allElementsAreNotGreaterThan(this->b, sample);
273 return sampleIsInsideInterval ? std::pow(this->bma, -
static_cast<double>(sample.size())) : 0.0;
276template <
typename RealType>
279 bool sampleIsInsideInterval =
280 this->allElementsAreNotSmallerThan(this->a, sample) && this->allElementsAreNotGreaterThan(this->b, sample);
281 int sample_size = sample.size();
282 return sampleIsInsideInterval ? -sample_size * this->logbma : -INFINITY;
285template <
typename RealType>
287template <
typename RealType>
290template <
typename RealType>
293 if (!this->allElementsAreNotGreaterThan(this->b, sample))
295 this->UPPER_LIMIT_VIOLATION + this->toStringWithPrecision(this->b));
296 RealType minVar = *std::min_element(sample.begin(), sample.end());
298 if (unbiased ==
true) {
299 int n = sample.size();
301 RealType minVarAdj = (minVar * (n + 1) - this->b) / n;
302 if (!this->allElementsAreNotSmallerThan(minVarAdj, sample))
304 SetSupport(minVarAdj, this->b);
306 SetSupport(minVar, this->b);
310template <
typename RealType>
313 if (!this->allElementsAreNotSmallerThan(this->a, sample))
315 this->LOWER_LIMIT_VIOLATION + this->toStringWithPrecision(this->a));
316 RealType maxVar = *std::max_element(sample.begin(), sample.end());
318 if (unbiased ==
true) {
319 int n = sample.size();
321 RealType maxVarAdj = (maxVar * (n + 1) - this->a) / n;
322 if (!this->allElementsAreNotGreaterThan(maxVarAdj, sample))
324 SetSupport(this->a, maxVarAdj);
326 SetSupport(this->a, maxVar);
330template <
typename RealType>
333 double minVar = *std::min_element(sample.begin(), sample.end());
334 double maxVar = *std::max_element(sample.begin(), sample.end());
335 if (unbiased ==
true) {
336 int n = sample.size();
338 RealType minVarAdj = (minVar * n - maxVar) / (n - 1);
340 RealType maxVarAdj = (maxVar * n - minVar) / (n - 1);
341 if (!this->allElementsAreNotSmallerThan(minVarAdj, sample))
343 if (!this->allElementsAreNotGreaterThan(maxVarAdj, sample))
345 SetSupport(minVarAdj, maxVarAdj);
347 SetSupport(minVar, maxVar);
351template <
typename RealType>
355 if (!this->allElementsAreNotSmallerThan(this->a, sample))
357 this->LOWER_LIMIT_VIOLATION + this->toStringWithPrecision(this->a));
358 double maxVar = *std::max_element(sample.begin(), sample.end());
359 int n = sample.size();
360 double newShape = priorDistribution.
GetShape() + n;
361 double newScale = std::max(priorDistribution.
GetScale(), maxVar - this->a);
363 double theta = MAP ? posteriorDistribution.
Mode() : posteriorDistribution.
Mean();
364 SetSupport(this->a, this->a + theta);
365 return posteriorDistribution;
The BetaDistribution class Abstract class for Beta distribution.
Definition continuous/beta.hpp:33
double b
max bound
Definition continuous/beta.hpp:41
void SetSupport(double minValue, double maxValue)
Definition continuous/beta.hpp:446
double a
min bound
Definition continuous/beta.hpp:40
The ParetoRand class Pareto distribution.
Definition pareto.hpp:24
double GetScale() const noexcept
Definition pareto.hpp:44
double GetShape() const noexcept
Definition pareto.hpp:43
long double Mean() const override
Definition pareto.hpp:244
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition pareto.hpp:267
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
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
@ WrongSample
the sample could not have been drawn from this distribution
@ WrongReturn
the method returned invalid parameters
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15