|
RandLib 2.0.0
Probability distributions, fitting, and heavy-tail tools for C++20
|
The ContinuousDistribution class
Abstract class for all continuous distributions.
More...
#include <continuous.hpp>


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 " |
The ContinuousDistribution class
Abstract class for all continuous distributions.
|
inlineprotected |
|
inlinevirtual |
|
overrideprotectedvirtual |
| funPtr | pointer on function g(x) with finite support which expected value should be returned |
| minPoint | min{x | g(x) ≠ 0} |
| maxPoint | max{x | g(x) ≠ 0} |
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 >.
|
inlinevirtual |
| x |
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 >.
|
overridevirtual |
| x | input parameter |
0/1
0/0
Implements randlib::UnivariateDistribution< RealType >.
|
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
| bool randlib::ContinuousDistribution< RealType >::KolmogorovSmirnovTest | ( | std::span< const RealType > | orderStatistic, |
| double | alpha | ||
| ) | const |
| orderStatistic | sample sorted in ascending order |
| alpha | level of test |
|
overridevirtual |
| sample |
Implements randlib::UnivariateDistribution< RealType >.
Reimplemented in randlib::UniformRand< RealType >.
|
pure virtual |
| x |
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 >.
|
overridevirtual |
| sample |
Implements randlib::UnivariateDistribution< RealType >.
Reimplemented in randlib::UniformRand< RealType >.
| void randlib::ContinuousDistribution< RealType >::LogProbabilityDensityFunction | ( | std::span< const RealType > | x, |
| std::span< double > | y | ||
| ) | const |
fill vector y with logf(x)
| x | |
| y |
|
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.
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 >.
| void randlib::ContinuousDistribution< RealType >::ProbabilityDensityFunction | ( | std::span< const RealType > | x, |
| std::span< double > | y | ||
| ) | const |
fill vector y with f(x)
| x | |
| y |
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
| p | |
| initValue | initial value of x |
Implements randlib::UnivariateDistribution< RealType >.
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
| p | |
| initValue | initial value of x |
Implements randlib::UnivariateDistribution< RealType >.
|
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.
| p | probability in (0, 1) |
| upperTail | search for S(x) = p instead of F(x) = p |
| guess | initial guess, or NaN |
| relativeStep | first step of the bracket expansion, relative to the guess |
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