RandLib 2.0.0
Probability distributions, fitting, and heavy-tail tools for C++20
Loading...
Searching...
No Matches
randlib::ProbabilityDistribution< T > Class Template Referenceabstract

The ProbabilityDistribution class
Abstract class for all probability distributions. More...

#include <distribution.hpp>

Inheritance diagram for randlib::ProbabilityDistribution< T >:

Public Types

using value_type = T
 

Public Member Functions

virtual ~ProbabilityDistribution ()=default
 
virtual std::string Name () const =0
 
virtual T MinValue () const =0
 
virtual T MaxValue () const =0
 
virtual double F (const T &x) const =0
 
void CumulativeDistributionFunction (std::span< const T > x, std::span< double > y) const
 
virtual double S (const T &x) const
 
void SurvivalFunction (std::span< const T > x, std::span< double > y) const
 
template<std::uniform_random_bit_generator G>
T operator() (G &g) const
 Draws a variate with the given engine through the virtual interface.
 
T Variate () const
 Uses the engine of this object, so it is not thread-safe for one object; use operator() with one engine per thread instead.
 
void Sample (std::span< T > outputData) const
 Fills the output with variates drawn with the engine of this object.
 
template<std::uniform_random_bit_generator G>
void Sample (G &g, std::span< T > outputData) const
 Fills the output with variates drawn with the given engine.
 
void Reseed (std::uint64_t seed)
 

Protected Member Functions

std::string toStringWithPrecision (const double a_value, const int n=6) const
 
 ProbabilityDistribution ()=default
 
DefaultEngine & engine () const
 
virtual T variate (detail::EngineRef g) const =0
 Every concrete distribution implements this by calling its templated operator()
 
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.
 
fit_error fitError (FitErrorCode code, const std::string &explanation) const
 

Static Protected Attributes

static constexpr size_t MAX_ITER_REJECTION = detail::MAX_ITER_REJECTION
 MAX_ITER_REJECTION upper boundary for maximum amount of iterations in rejection methods one thousand should be enough to be sure there is a bug (or rejection method is too slow to be used)
 
static constexpr char POSITIVITY_VIOLATION [] = "All elements should be positive"
 
static constexpr char NON_NEGATIVITY_VIOLATION [] = "All elements should be non-negative"
 
static constexpr char UPPER_LIMIT_VIOLATION [] = "No element should be greater than "
 
static constexpr char LOWER_LIMIT_VIOLATION [] = "No element should be smaller than "
 

Detailed Description

template<typename T>
class randlib::ProbabilityDistribution< T >

The ProbabilityDistribution class
Abstract class for all probability distributions.

Member Typedef Documentation

◆ value_type

template<typename T >
using randlib::ProbabilityDistribution< T >::value_type = T

Constructor & Destructor Documentation

◆ ProbabilityDistribution()

template<typename T >
randlib::ProbabilityDistribution< T >::ProbabilityDistribution ( )
protecteddefault

◆ ~ProbabilityDistribution()

template<typename T >
virtual randlib::ProbabilityDistribution< T >::~ProbabilityDistribution ( )
virtualdefault

Member Function Documentation

◆ CumulativeDistributionFunction()

template<typename T >
void randlib::ProbabilityDistribution< T >::CumulativeDistributionFunction ( std::span< const T >  x,
std::span< double >  y 
) const
Parameters
xinput vector
youtput vector: y = P(X ≤ x)

◆ engine()

template<typename T >
DefaultEngine & randlib::ProbabilityDistribution< T >::engine ( ) const
inlineprotected
Returns
the engine of this object, seeded with random_seed() on first use unless Reseed was called

◆ F()

template<typename T >
virtual double randlib::ProbabilityDistribution< T >::F ( const T &  x) const
pure virtual
Parameters
x
Returns
P(X ≤ x)

◆ fitError()

template<typename T >
fit_error randlib::ProbabilityDistribution< T >::fitError ( FitErrorCode  code,
const std::string &  explanation 
) const
protected
Parameters
codereason of the failure
explanationdetails
Returns
fit_error whose message names this distribution, the reason and the details

◆ MaxValue()

template<typename T >
virtual T randlib::ProbabilityDistribution< T >::MaxValue ( ) const
pure virtual
Returns
maximum possible value that can be achieved by random variable

Implemented in randlib::BetaDistribution< RealType >, randlib::BetaDistribution< double >, randlib::BetaPrimeRand< RealType >, randlib::CauchyRand< RealType >, randlib::DegenerateRand, randlib::ExponentiallyModifiedGaussianRand< RealType >, randlib::FisherFRand< RealType >, randlib::FrechetRand< RealType >, randlib::GammaDistribution< RealType >, randlib::GammaDistribution< double >, randlib::GammaDistribution< float >, randlib::GeneralizedExtremeValueRand< RealType >, randlib::GeneralizedParetoRand< RealType >, randlib::GeneralGeometricStableDistribution< RealType >, randlib::GumbelRand< RealType >, randlib::InverseGammaRand< RealType >, randlib::InverseGaussianRand< RealType >, randlib::IrwinHallRand< RealType >, randlib::KolmogorovSmirnovRand< RealType >, randlib::LogNormalRand< RealType >, randlib::LogStableRand< RealType >, randlib::LogisticRand< RealType >, randlib::MarchenkoPasturRand< RealType >, randlib::NakagamiDistribution< RealType >, randlib::NoncentralChiSquaredRand< RealType >, randlib::NoncentralTRand< RealType >, randlib::ParetoRand< RealType >, randlib::ParetoRand< double >, randlib::PlanckRand< RealType >, randlib::RaisedCosineDistribution< RealType >, randlib::RiceRand< RealType >, randlib::SechRand< RealType >, randlib::StableDistribution< RealType >, randlib::StableCountRand< RealType >, randlib::StudentTRand< RealType >, randlib::TriangularRand< RealType >, randlib::UniformRand< RealType >, randlib::WeibullRand< RealType >, randlib::WignerSemicircleRand< RealType >, randlib::BivariateDistribution< T1, T2, T >, randlib::BivariateDistribution< BinomialRand< IntType >, BinomialRand< IntType >, IntType >, randlib::BivariateDistribution< NormalRand< RealType >, NormalRand< RealType >, RealType >, randlib::BivariateDistribution< StudentTRand< RealType >, InverseGammaRand< RealType >, RealType >, randlib::BivariateDistribution< T1, T2, IntType >, randlib::BivariateDistribution< T1, T2, RealType >, randlib::CircularDistribution< RealType >, randlib::BetaBinomialRand< IntType >, randlib::BinomialDistribution< IntType >, randlib::BinomialDistribution< int >, randlib::CategoricalRand< IntType >, randlib::HyperGeometricRand< IntType >, randlib::LogarithmicRand< IntType >, randlib::NegativeBinomialDistribution< IntType, T >, randlib::NegativeHyperGeometricRand< IntType >, randlib::PoissonRand< IntType >, randlib::PoissonRand< int >, randlib::RademacherRand, randlib::SkellamRand< IntType >, randlib::UniformDiscreteRand< IntType >, randlib::YuleRand< IntType >, randlib::ZetaRand< IntType >, randlib::ZetaRand< long long int >, randlib::ZipfRand< IntType >, and randlib::CantorRand.

◆ MinValue()

template<typename T >
virtual T randlib::ProbabilityDistribution< T >::MinValue ( ) const
pure virtual
Returns
minimum possible value that can be achieved by random variable

Implemented in randlib::BetaDistribution< RealType >, randlib::BetaDistribution< double >, randlib::BetaPrimeRand< RealType >, randlib::CauchyRand< RealType >, randlib::DegenerateRand, randlib::ExponentiallyModifiedGaussianRand< RealType >, randlib::FisherFRand< RealType >, randlib::FrechetRand< RealType >, randlib::GammaDistribution< RealType >, randlib::GammaDistribution< double >, randlib::GammaDistribution< float >, randlib::GeneralizedExtremeValueRand< RealType >, randlib::GeneralizedParetoRand< RealType >, randlib::GeneralGeometricStableDistribution< RealType >, randlib::GumbelRand< RealType >, randlib::InverseGammaRand< RealType >, randlib::InverseGaussianRand< RealType >, randlib::IrwinHallRand< RealType >, randlib::KolmogorovSmirnovRand< RealType >, randlib::LogNormalRand< RealType >, randlib::LogStableRand< RealType >, randlib::LogisticRand< RealType >, randlib::MarchenkoPasturRand< RealType >, randlib::NakagamiDistribution< RealType >, randlib::NoncentralChiSquaredRand< RealType >, randlib::NoncentralTRand< RealType >, randlib::ParetoRand< RealType >, randlib::ParetoRand< double >, randlib::PlanckRand< RealType >, randlib::RaisedCosineDistribution< RealType >, randlib::RiceRand< RealType >, randlib::SechRand< RealType >, randlib::StableDistribution< RealType >, randlib::StableCountRand< RealType >, randlib::StudentTRand< RealType >, randlib::TriangularRand< RealType >, randlib::UniformRand< RealType >, randlib::WeibullRand< RealType >, randlib::WignerSemicircleRand< RealType >, randlib::BivariateDistribution< T1, T2, T >, randlib::BivariateDistribution< BinomialRand< IntType >, BinomialRand< IntType >, IntType >, randlib::BivariateDistribution< NormalRand< RealType >, NormalRand< RealType >, RealType >, randlib::BivariateDistribution< StudentTRand< RealType >, InverseGammaRand< RealType >, RealType >, randlib::BivariateDistribution< T1, T2, IntType >, randlib::BivariateDistribution< T1, T2, RealType >, randlib::CircularDistribution< RealType >, randlib::BetaBinomialRand< IntType >, randlib::BinomialDistribution< IntType >, randlib::BinomialDistribution< int >, randlib::CategoricalRand< IntType >, randlib::HyperGeometricRand< IntType >, randlib::LogarithmicRand< IntType >, randlib::NegativeBinomialDistribution< IntType, T >, randlib::NegativeHyperGeometricRand< IntType >, randlib::PoissonRand< IntType >, randlib::PoissonRand< int >, randlib::RademacherRand, randlib::SkellamRand< IntType >, randlib::UniformDiscreteRand< IntType >, randlib::YuleRand< IntType >, randlib::ZetaRand< IntType >, randlib::ZetaRand< long long int >, randlib::ZipfRand< IntType >, and randlib::CantorRand.

◆ Name()

template<typename T >
virtual std::string randlib::ProbabilityDistribution< T >::Name ( ) const
pure virtual
Returns
title of distribution, for instance "Normal(0, 1)"

Implemented in randlib::BivariateNormalRand< RealType >, randlib::NormalInverseGammaRand< RealType >, randlib::TrinomialRand< IntType >, randlib::VonMisesRand< RealType >, randlib::WrappedExponentialRand< RealType >, randlib::BetaRand< RealType >, randlib::BetaRand< double >, randlib::ArcsineRand< RealType >, randlib::BaldingNicholsRand< RealType >, randlib::BetaPrimeRand< RealType >, randlib::CauchyRand< RealType >, randlib::DegenerateRand, randlib::ExponentialRand< RealType >, randlib::ExponentiallyModifiedGaussianRand< RealType >, randlib::FisherFRand< RealType >, randlib::FrechetRand< RealType >, randlib::GammaRand< RealType >, randlib::GammaRand< double >, randlib::GammaRand< float >, randlib::ChiSquaredRand< RealType >, randlib::ErlangRand< RealType >, randlib::GeneralizedExtremeValueRand< RealType >, randlib::GeneralizedParetoRand< RealType >, randlib::GeometricStableRand< RealType >, randlib::GumbelRand< RealType >, randlib::InverseGammaRand< RealType >, randlib::InverseGaussianRand< RealType >, randlib::IrwinHallRand< RealType >, randlib::KolmogorovSmirnovRand< RealType >, randlib::CenteredAsymmetricLaplaceRand< RealType >, randlib::AsymmetricLaplaceRand< RealType >, randlib::LaplaceRand< RealType >, randlib::LevyRand< RealType >, randlib::LogNormalRand< RealType >, randlib::LogStableRand< RealType >, randlib::LogisticRand< RealType >, randlib::MarchenkoPasturRand< RealType >, randlib::NakagamiRand< RealType >, randlib::ChiRand< RealType >, randlib::MaxwellBoltzmannRand< RealType >, randlib::RayleighRand< RealType >, randlib::NoncentralChiSquaredRand< RealType >, randlib::NoncentralTRand< RealType >, randlib::NormalRand< RealType >, randlib::ParetoRand< RealType >, randlib::ParetoRand< double >, randlib::PlanckRand< RealType >, randlib::RaisedCosineRand< RealType >, randlib::RaabGreenRand< RealType >, randlib::RiceRand< RealType >, randlib::SechRand< RealType >, randlib::StableRand< RealType >, randlib::HoltsmarkRand< RealType >, randlib::LandauRand< RealType >, randlib::StableCountRand< RealType >, randlib::StudentTRand< RealType >, randlib::TriangularRand< RealType >, randlib::UniformRand< RealType >, randlib::WeibullRand< RealType >, randlib::WignerSemicircleRand< RealType >, randlib::BernoulliRand, randlib::BetaBinomialRand< IntType >, randlib::BinomialRand< IntType >, randlib::CategoricalRand< IntType >, randlib::GeometricRand< IntType >, randlib::GeometricRand< int >, randlib::HyperGeometricRand< IntType >, randlib::LogarithmicRand< IntType >, randlib::NegativeBinomialRand< IntType, T >, randlib::NegativeHyperGeometricRand< IntType >, randlib::PoissonRand< IntType >, randlib::PoissonRand< int >, randlib::RademacherRand, randlib::SkellamRand< IntType >, randlib::UniformDiscreteRand< IntType >, randlib::YuleRand< IntType >, randlib::ZetaRand< IntType >, randlib::ZetaRand< long long int >, randlib::ZipfRand< IntType >, and randlib::CantorRand.

◆ operator()()

template<typename T >
template<std::uniform_random_bit_generator G>
T randlib::ProbabilityDistribution< T >::operator() ( G &  g) const
inline

Draws a variate with the given engine through the virtual interface.

Concrete distribution classes hide it with a fully templated version, which is faster.

Parameters
gany uniform random bit generator, such as std::mt19937 or DefaultEngine
Returns
random variable

◆ Reseed()

template<typename T >
void randlib::ProbabilityDistribution< T >::Reseed ( std::uint64_t  seed)
inline
Parameters
seedseed of the engine of this object

◆ S()

template<typename T >
double randlib::ProbabilityDistribution< T >::S ( const T &  x) const
virtual
Parameters
x
Returns
P(X > x)

◆ sample()

template<typename T >
virtual void randlib::ProbabilityDistribution< T >::sample ( detail::EngineRef  g,
std::span< T >  outputData 
) const
inlineprotectedvirtual

Fills the output with variate(g); distributions with a faster bulk algorithm override it.

Parameters
gengine
outputData

◆ Sample() [1/2]

template<typename T >
template<std::uniform_random_bit_generator G>
void randlib::ProbabilityDistribution< T >::Sample ( G &  g,
std::span< T >  outputData 
) const
inline

Fills the output with variates drawn with the given engine.

Parameters
gany uniform random bit generator
outputData

◆ Sample() [2/2]

template<typename T >
void randlib::ProbabilityDistribution< T >::Sample ( std::span< T >  outputData) const
inline

Fills the output with variates drawn with the engine of this object.

Parameters
outputData

◆ SurvivalFunction()

template<typename T >
void randlib::ProbabilityDistribution< T >::SurvivalFunction ( std::span< const T >  x,
std::span< double >  y 
) const
Parameters
xinput vector
youtput vector: y = P(X > x)

◆ toStringWithPrecision()

template<typename T >
std::string randlib::ProbabilityDistribution< T >::toStringWithPrecision ( const double  a_value,
const int  n = 6 
) const
protected

◆ Variate()

template<typename T >
T randlib::ProbabilityDistribution< T >::Variate ( ) const
inline

Uses the engine of this object, so it is not thread-safe for one object; use operator() with one engine per thread instead.

Returns
random variable

◆ variate()

template<typename T >
virtual T randlib::ProbabilityDistribution< T >::variate ( detail::EngineRef  g) const
protectedpure virtual

Every concrete distribution implements this by calling its templated operator()

Parameters
gengine
Returns
random variable

Member Data Documentation

◆ LOWER_LIMIT_VIOLATION

template<typename T >
constexpr char randlib::ProbabilityDistribution< T >::LOWER_LIMIT_VIOLATION = "No element should be smaller than "
staticconstexprprotected

◆ MAX_ITER_REJECTION

template<typename T >
constexpr size_t randlib::ProbabilityDistribution< T >::MAX_ITER_REJECTION = detail::MAX_ITER_REJECTION
staticconstexprprotected

MAX_ITER_REJECTION upper boundary for maximum amount of iterations in rejection methods one thousand should be enough to be sure there is a bug (or rejection method is too slow to be used)

◆ NON_NEGATIVITY_VIOLATION

template<typename T >
constexpr char randlib::ProbabilityDistribution< T >::NON_NEGATIVITY_VIOLATION = "All elements should be non-negative"
staticconstexprprotected

◆ POSITIVITY_VIOLATION

template<typename T >
constexpr char randlib::ProbabilityDistribution< T >::POSITIVITY_VIOLATION = "All elements should be positive"
staticconstexprprotected

◆ UPPER_LIMIT_VIOLATION

template<typename T >
constexpr char randlib::ProbabilityDistribution< T >::UPPER_LIMIT_VIOLATION = "No element should be greater than "
staticconstexprprotected

The documentation for this class was generated from the following file: