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

The ContinuousDistribution class
Abstract class for all continuous distributions. More...

#include <continuous.hpp>

Inheritance diagram for randlib::ContinuousDistribution< RealType >:
Collaboration diagram for randlib::ContinuousDistribution< RealType >:

Public Member Functions

virtual ~ContinuousDistribution ()
 
virtual double f (const RealType &x) const
 
virtual double logf (const RealType &x) const =0
 
void ProbabilityDensityFunction (std::span< const RealType > x, std::span< double > y) const
 fill vector y with f(x)
 
void LogProbabilityDensityFunction (std::span< const RealType > x, std::span< double > y) const
 fill vector y with logf(x)
 
RealType Mode () const override
 Mode is the value, which has the largest probability to happen, or, in the case of continuous distribution, has the largest value of density function.
 
double Hazard (const RealType &x) const override
 
double LikelihoodFunction (std::span< const RealType > sample) const override
 
double LogLikelihoodFunction (std::span< const RealType > sample) const override
 
bool KolmogorovSmirnovTest (std::span< const RealType > orderStatistic, double alpha) const
 
- Public Member Functions inherited from randlib::UnivariateDistribution< RealType >
virtual ~UnivariateDistribution ()
 
virtual Support SupportType () const=0
 
bool isLeftBounded () const
 
bool isRightBounded () const
 
virtual long double Mean () const=0
 
virtual long double Variance () const=0
 
RealType Quantile (double p) const
 
RealType Quantile1m (double p) const
 
void QuantileFunction (std::span< const double > p, std::span< RealType > y) const
 
void QuantileFunction1m (std::span< const double > p, std::span< RealType > y) const
 
std::complex< double > CF (double t) const
 
void CharacteristicFunction (std::span< const double > t, std::span< std::complex< double > > y) const
 
void HazardFunction (std::span< const RealType > x, std::span< double > y) const
 
virtual RealType Median () const
 
virtual long double Skewness () const
 
virtual long double Kurtosis () const
 
virtual long double ExcessKurtosis () const
 
virtual long double SecondMoment () const
 
virtual long double ThirdMoment () const
 
virtual long double FourthMoment () const
 
- Public Member Functions inherited from randlib::ProbabilityDistribution< T >
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

 ContinuousDistribution ()
 
std::complex< double > integrateCharacteristicFunction (double t) const
 
RealType quantileImpl (double p, RealType initValue) const override
 
RealType quantileImpl (double p) const override
 
RealType quantileImpl1m (double p, RealType initValue) const override
 
RealType quantileImpl1m (double p) const override
 
long double ExpectedValue (const std::function< double(RealType)> &funPtr, RealType minPoint, RealType maxPoint) const override
 
RealType searchQuantile (double p, bool upperTail, RealType guess, double relativeStep=1e-3) const
 Deterministic root search for the quantile: brackets the root, starting from the guess when it is finite, then refines it with the Illinois variant of regula falsi (on a logarithmic scale for small p), falling back to bisection whenever the bracket does not halve.
 
- Protected Member Functions inherited from randlib::UnivariateDistribution< RealType >
 UnivariateDistribution ()
 
virtual std::complex< double > CFImpl (double t) const
 
- Protected Member Functions inherited from randlib::ProbabilityDistribution< T >
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
 

Additional Inherited Members

- Public Types inherited from randlib::ProbabilityDistribution< T >
using value_type = T
 
- Static Public Member Functions inherited from randlib::UnivariateDistribution< RealType >
static long double GetSampleSum (std::span< const RealType > sample)
 
static long double GetSampleMean (std::span< const RealType > sample)
 
static long double GetSampleLogMean (std::span< const RealType > sample)
 
static long double GetSampleVariance (std::span< const RealType > sample, double mean)
 
static long double GetSampleLogVariance (std::span< const RealType > sample, double logMean)
 
static LongDoublePair GetSampleMeanAndVariance (std::span< const RealType > sample)
 
static LongDoublePair GetSampleLogMeanAndVariance (std::span< const RealType > sample)
 
static std::tuple< long double, long double, long double, long double > GetSampleStatistics (std::span< const RealType > sample)
 
- Static Protected Member Functions inherited from randlib::UnivariateDistribution< RealType >
static bool allElementsAreNotGreaterThan (RealType value, std::span< const RealType > sample)
 
static bool allElementsAreNotSmallerThan (RealType value, std::span< const RealType > sample)
 
static bool allElementsAreNonNegative (std::span< const RealType > sample)
 
static bool allElementsArePositive (std::span< const RealType > sample)
 
- Static Protected Attributes inherited from randlib::ProbabilityDistribution< T >
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 RealType>
class randlib::ContinuousDistribution< RealType >

The ContinuousDistribution class
Abstract class for all continuous distributions.

Constructor & Destructor Documentation

◆ ContinuousDistribution()

template<typename RealType >
randlib::ContinuousDistribution< RealType >::ContinuousDistribution ( )
inlineprotected

◆ ~ContinuousDistribution()

template<typename RealType >
virtual randlib::ContinuousDistribution< RealType >::~ContinuousDistribution ( )
inlinevirtual

Member Function Documentation

◆ ExpectedValue()

template<typename RealType >
long double randlib::ContinuousDistribution< RealType >::ExpectedValue ( const std::function< double(RealType)> &  funPtr,
RealType  minPoint,
RealType  maxPoint 
) const
overrideprotectedvirtual
Parameters
funPtrpointer on function g(x) with finite support which expected value should be returned
minPointmin{x | g(x) ≠ 0}
maxPointmax{x | g(x) ≠ 0}
Returns
E[g(x)]

attempt to calculate expected value by numerical method use for distributions w/o explicit formula

Each side of the median is mapped by x = c ± s u / (1 - u) with the bulk scale s = 1 / f(c), so that a narrow peak far from the origin is resolved and infinite tails become finite intervals

Implements randlib::UnivariateDistribution< RealType >.

◆ f()

template<typename RealType >
virtual double randlib::ContinuousDistribution< RealType >::f ( const RealType &  x) const
inlinevirtual
Parameters
x
Returns
probability density function

Reimplemented in randlib::BetaDistribution< double >, randlib::DegenerateRand, randlib::GammaDistribution< double >, randlib::ParetoRand< double >, randlib::GammaDistribution< float >, randlib::VonMisesRand< RealType >, randlib::WrappedExponentialRand< RealType >, randlib::BetaDistribution< RealType >, randlib::BetaPrimeRand< RealType >, randlib::CauchyRand< RealType >, randlib::ExponentialRand< RealType >, randlib::ExponentiallyModifiedGaussianRand< RealType >, randlib::FisherFRand< RealType >, randlib::FrechetRand< RealType >, randlib::GammaDistribution< RealType >, randlib::GeneralizedExtremeValueRand< RealType >, randlib::GeneralizedParetoRand< RealType >, randlib::GeneralGeometricStableDistribution< RealType >, randlib::GumbelRand< RealType >, randlib::InverseGaussianRand< RealType >, randlib::IrwinHallRand< RealType >, randlib::KolmogorovSmirnovRand< RealType >, randlib::AsymmetricLaplaceDistribution< RealType >, randlib::LevyRand< RealType >, randlib::LogNormalRand< RealType >, randlib::LogStableRand< RealType >, randlib::LogisticRand< RealType >, randlib::MarchenkoPasturRand< RealType >, randlib::NakagamiDistribution< RealType >, randlib::MaxwellBoltzmannRand< RealType >, randlib::RayleighRand< RealType >, randlib::NoncentralChiSquaredRand< RealType >, randlib::NoncentralTRand< RealType >, randlib::NormalRand< RealType >, randlib::ParetoRand< RealType >, 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 >, and randlib::WignerSemicircleRand< RealType >.

◆ Hazard()

template<typename RealType >
double randlib::ContinuousDistribution< RealType >::Hazard ( const RealType &  x) const
overridevirtual
Parameters
xinput parameter
Returns
hazard function

0/1

0/0

Implements randlib::UnivariateDistribution< RealType >.

◆ integrateCharacteristicFunction()

template<typename RealType >
std::complex< double > randlib::ContinuousDistribution< RealType >::integrateCharacteristicFunction ( double  t) const
protected

Within δ = 1e-11 / t of the end a of the support e^{itx} = e^{ita} to that accuracy, so the mass there enters as F(a + δ) e^{ita}, whatever its singularity. The walk over half-periods starts where the remaining mass begins and stops when the survival function bounds the rest, so that a bulk many periods above the end of the support is not skipped as negligible

◆ KolmogorovSmirnovTest()

template<typename RealType >
bool randlib::ContinuousDistribution< RealType >::KolmogorovSmirnovTest ( std::span< const RealType >  orderStatistic,
double  alpha 
) const
Parameters
orderStatisticsample sorted in ascending order
alphalevel of test
Returns
true if sample is from this distribution according to asymptotic KS-test, false otherwise

◆ LikelihoodFunction()

template<typename RealType >
double randlib::ContinuousDistribution< RealType >::LikelihoodFunction ( std::span< const RealType >  sample) const
overridevirtual
Parameters
sample
Returns
likelihood function for given sample

Implements randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ logf()

template<typename RealType >
virtual double randlib::ContinuousDistribution< RealType >::logf ( const RealType &  x) const
pure virtual
Parameters
x
Returns
logarithm of probability density function

Implemented in randlib::BetaDistribution< double >, randlib::DegenerateRand, randlib::GammaDistribution< double >, randlib::ParetoRand< double >, randlib::GammaDistribution< float >, randlib::VonMisesRand< RealType >, randlib::WrappedExponentialRand< RealType >, randlib::BetaDistribution< RealType >, randlib::BetaPrimeRand< RealType >, randlib::ExponentialRand< RealType >, randlib::ExponentiallyModifiedGaussianRand< RealType >, randlib::FisherFRand< RealType >, randlib::FrechetRand< RealType >, randlib::GammaDistribution< RealType >, 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::AsymmetricLaplaceDistribution< RealType >, randlib::LevyRand< RealType >, randlib::LogNormalRand< RealType >, randlib::LogStableRand< RealType >, randlib::LogisticRand< RealType >, randlib::MarchenkoPasturRand< RealType >, randlib::NakagamiDistribution< RealType >, randlib::NoncentralChiSquaredRand< RealType >, randlib::NoncentralTRand< RealType >, randlib::NormalRand< RealType >, randlib::ParetoRand< RealType >, 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 >, and randlib::WignerSemicircleRand< RealType >.

◆ LogLikelihoodFunction()

template<typename RealType >
double randlib::ContinuousDistribution< RealType >::LogLikelihoodFunction ( std::span< const RealType >  sample) const
overridevirtual
Parameters
sample
Returns
logarithm of likelihood function for given sample

Implements randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ LogProbabilityDensityFunction()

template<typename RealType >
void randlib::ContinuousDistribution< RealType >::LogProbabilityDensityFunction ( std::span< const RealType >  x,
std::span< double >  y 
) const

fill vector y with logf(x)

Parameters
x
y

◆ Mode()

template<typename RealType >
RealType randlib::ContinuousDistribution< RealType >::Mode ( ) const
overridevirtual

Mode is the value, which has the largest probability to happen, or, in the case of continuous distribution, has the largest value of density function.

Returns
mode. In case, when it's not unique, return any of them.

good starting point

this shouldn't be nan or inf

Implements randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::VonMisesRand< RealType >, randlib::WrappedExponentialRand< RealType >, randlib::DegenerateRand, 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::MaxwellBoltzmannRand< RealType >, randlib::RayleighRand< RealType >, randlib::NoncentralChiSquaredRand< 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 >, and randlib::WignerSemicircleRand< RealType >.

◆ ProbabilityDensityFunction()

template<typename RealType >
void randlib::ContinuousDistribution< RealType >::ProbabilityDensityFunction ( std::span< const RealType >  x,
std::span< double >  y 
) const

fill vector y with f(x)

Parameters
x
y

◆ quantileImpl() [1/2]

template<typename RealType >
RealType randlib::ContinuousDistribution< RealType >::quantileImpl ( double  p) const
overrideprotectedvirtual

◆ quantileImpl() [2/2]

template<typename RealType >
RealType randlib::ContinuousDistribution< RealType >::quantileImpl ( double  p,
RealType  initValue 
) const
overrideprotectedvirtual
Parameters
p
initValueinitial value of x
Returns
such x that F(x) = p

Implements randlib::UnivariateDistribution< RealType >.

◆ quantileImpl1m() [1/2]

template<typename RealType >
RealType randlib::ContinuousDistribution< RealType >::quantileImpl1m ( double  p) const
overrideprotectedvirtual

◆ quantileImpl1m() [2/2]

template<typename RealType >
RealType randlib::ContinuousDistribution< RealType >::quantileImpl1m ( double  p,
RealType  initValue 
) const
overrideprotectedvirtual
Parameters
p
initValueinitial value of x
Returns
such x that F(x) = 1 - p

Implements randlib::UnivariateDistribution< RealType >.

◆ searchQuantile()

template<typename RealType >
RealType randlib::ContinuousDistribution< RealType >::searchQuantile ( double  p,
bool  upperTail,
RealType  guess,
double  relativeStep = 1e-3 
) const
protected

Deterministic root search for the quantile: brackets the root, starting from the guess when it is finite, then refines it with the Illinois variant of regula falsi (on a logarithmic scale for small p), falling back to bisection whenever the bracket does not halve.

It stops when the bracket cannot shrink in floating point.

Parameters
pprobability in (0, 1)
upperTailsearch for S(x) = p instead of F(x) = p
guessinitial guess, or NaN
relativeStepfirst step of the bracket expansion, relative to the guess
Returns
such x that F(x) = p (or S(x) = p)

Solve in the tail with the smaller probability: 1 - p is exact for p ≥ 1/2, and F (or S) cannot resolve a probability close to 1 as well as the other tail resolves 1 - p

g increases through zero at the quantile; for small p it is compared on a log scale

Bracket [a, b] with g(a) < 0 <= g(b), expanding geometrically from the guess, from a finite end of the support, or from 0

Bisection point: geometric in the distance to a finite support end while the bracket spans orders of magnitude, arithmetic otherwise

While the bracket spans orders of magnitude or g is infinite at an end, split it geometrically; then TOMS 748 refines it to full precision


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