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

The BetaDistribution class
Abstract class for Beta distribution. More...

#include <beta.hpp>

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

Public Member Functions

virtual ~BetaDistribution ()
 
Support SupportType () const override
 
RealType MinValue () const override
 
RealType MaxValue () const override
 
double GetAlpha () const noexcept
 
double GetBeta () const noexcept
 
double GetBetaFunction () const noexcept
 
double GetLogBetaFunction () const noexcept
 
double f (const RealType &x) const override
 
double logf (const RealType &x) const override
 
double F (const RealType &x) const override
 
double S (const RealType &x) const override
 
template<std::uniform_random_bit_generator G>
RealType operator() (G &g) const
 
long double Mean () const override
 
long double GeometricMean () const
 
long double Variance () const override
 
long double GeometricVariance () const
 
RealType Median () const override
 
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.
 
long double Skewness () const override
 
long double ExcessKurtosis () const override
 
long double MeanAbsoluteDeviation () const
 MeanAbsoluteDeviation.
 
- Public Member Functions inherited from randlib::ContinuousDistribution< RealType >
virtual ~ContinuousDistribution ()
 
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 ()
 
bool isLeftBounded () const
 
bool isRightBounded () const
 
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 long double Kurtosis () 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 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

 BetaDistribution (double shape1=1, double shape2=1, double minValue=0, double maxValue=1)
 
void SetShapes (double shape1, double shape2)
 
void SetSupport (double minValue, double maxValue)
 
RealType quantileImpl (double p) const override
 
RealType quantileImpl1m (double p) const override
 
std::complex< double > CFImpl (double t) const override
 
- Protected Member Functions inherited from randlib::ContinuousDistribution< RealType >
 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 ()
 
- 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 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
 

Protected Attributes

double alpha = 1
 first shape α
 
double beta = 1
 second shape β
 
double a = 0
 min bound
 
double b = 1
 max bound
 
double bma = 1
 b-a
 
double bmaInv = 1
 1/(b-a)
 
double logbma = 0
 log(b-a)
 
GammaRand< RealType > GammaRV1 {}
 
GammaRand< RealType > GammaRV2 {}
 

Static Protected Attributes

static constexpr char ALPHA_ZERO []
 
static constexpr char BETA_ZERO []
 
- 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 "
 

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)
 

Detailed Description

template<typename RealType>
class randlib::BetaDistribution< RealType >

The BetaDistribution class
Abstract class for Beta distribution.

f(x | α, β) = y^{α-1} (1-y)^{β-1} / B(α, β),
where y = (x-a)/(b-a) and B(α, β) denotes Beta function

Notation: X ~ B(α, β, a, b) or X ~ B(α, β) for a=0 and b=1

Related distributions (a=0, b=1):
1 − X ~ B(β, α)
X / (1 - X) ~ B'(α, β)
X = Y / (Y + Z), where Y ~ Γ(α) and Z ~ Γ(β)
βX / α(1 - X) ~ F(2α, 2β)

Constructor & Destructor Documentation

◆ BetaDistribution()

template<typename RealType >
randlib::BetaDistribution< RealType >::BetaDistribution ( double  shape1 = 1,
double  shape2 = 1,
double  minValue = 0,
double  maxValue = 1 
)
protected

◆ ~BetaDistribution()

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

Member Function Documentation

◆ CFImpl()

template<typename RealType >
std::complex< double > randlib::BetaDistribution< RealType >::CFImpl ( double  t) const
overrideprotectedvirtual
Parameters
t
Returns
characteristic function implementation (inverse Fourier transform of pdf)

if we don't have singularity points, we can use direct integration

Reimplemented from randlib::UnivariateDistribution< RealType >.

◆ ExcessKurtosis()

template<typename RealType >
long double randlib::BetaDistribution< RealType >::ExcessKurtosis ( ) const
overridevirtual
Returns
E[((X - μ) / σ) ^ 4] - 3 (fourth moment around the mean divided by the square of the variance of the probability distribution minus 3)

var is finite, so is mu

Reimplemented from randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ f()

template<typename RealType >
double randlib::BetaDistribution< RealType >::f ( const RealType &  x) const
overridevirtual
Parameters
x
Returns
probability density function

Reimplemented from randlib::ContinuousDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ F()

template<typename RealType >
double randlib::BetaDistribution< RealType >::F ( const RealType &  x) const
override

Standardize: distances to both ends are exact, unlike 1 minus the standardized value

Workaround known case

◆ GeometricMean()

template<typename RealType >
long double randlib::BetaDistribution< RealType >::GeometricMean ( ) const
Returns
E[ln(X)]

◆ GeometricVariance()

template<typename RealType >
long double randlib::BetaDistribution< RealType >::GeometricVariance ( ) const
Returns
Var(ln(X))

◆ GetAlpha()

template<typename RealType >
double randlib::BetaDistribution< RealType >::GetAlpha ( ) const
inlinenoexcept
Returns
first shape α

◆ GetBeta()

template<typename RealType >
double randlib::BetaDistribution< RealType >::GetBeta ( ) const
inlinenoexcept
Returns
second shape β

◆ GetBetaFunction()

template<typename RealType >
double randlib::BetaDistribution< RealType >::GetBetaFunction ( ) const
inlinenoexcept
Returns
B(α, β)

◆ GetLogBetaFunction()

template<typename RealType >
double randlib::BetaDistribution< RealType >::GetLogBetaFunction ( ) const
inlinenoexcept
Returns
log(B(α, β))

◆ logf()

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

Implements randlib::ContinuousDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ MaxValue()

template<typename RealType >
RealType randlib::BetaDistribution< RealType >::MaxValue ( ) const
inlineoverridevirtual
Returns
maximum possible value that can be achieved by random variable

Implements randlib::ProbabilityDistribution< T >.

Reimplemented in randlib::UniformRand< RealType >.

◆ Mean()

template<typename RealType >
long double randlib::BetaDistribution< RealType >::Mean ( ) const
overridevirtual
Returns
Mathematical expectation

Implements randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ MeanAbsoluteDeviation()

template<typename RealType >
long double randlib::BetaDistribution< RealType >::MeanAbsoluteDeviation ( ) const

MeanAbsoluteDeviation.

Returns
E[|X - E[X]|]

◆ Median()

template<typename RealType >
RealType randlib::BetaDistribution< RealType >::Median ( ) const
overridevirtual
Returns
such x that F(x) = 0.5

Reimplemented from randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ MinValue()

template<typename RealType >
RealType randlib::BetaDistribution< RealType >::MinValue ( ) const
inlineoverridevirtual
Returns
minimum possible value that can be achieved by random variable

Implements randlib::ProbabilityDistribution< T >.

Reimplemented in randlib::UniformRand< RealType >.

◆ Mode()

template<typename RealType >
RealType randlib::BetaDistribution< 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.

Implements randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ operator()()

template<typename RealType >
template<std::uniform_random_bit_generator G>
RealType randlib::BetaDistribution< RealType >::operator() ( G &  g) const

◆ quantileImpl()

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

◆ quantileImpl1m()

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

◆ S()

template<typename RealType >
double randlib::BetaDistribution< RealType >::S ( const RealType &  x) const
override

Standardize: distances to both ends are exact, unlike 1 minus the standardized value

Workaround known case

◆ SetShapes()

template<typename RealType >
void randlib::BetaDistribution< RealType >::SetShapes ( double  shape1,
double  shape2 
)
protected
Parameters
shape1α
shape2β

◆ SetSupport()

template<typename RealType >
void randlib::BetaDistribution< RealType >::SetSupport ( double  minValue,
double  maxValue 
)
protected
Parameters
minValuea
maxValueb

◆ Skewness()

template<typename RealType >
long double randlib::BetaDistribution< RealType >::Skewness ( ) const
overridevirtual
Returns
E[((X - μ) / σ) ^ 3] where μ is central moment and σ is standard deviation

var is finite, so is mu

Reimplemented from randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ SupportType()

template<typename RealType >
Support randlib::BetaDistribution< RealType >::SupportType ( ) const
inlineoverridevirtual
Returns
type of support

Implements randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

◆ Variance()

template<typename RealType >
long double randlib::BetaDistribution< RealType >::Variance ( ) const
overridevirtual
Returns
Variance of random variable

Implements randlib::UnivariateDistribution< RealType >.

Reimplemented in randlib::UniformRand< RealType >.

Member Data Documentation

◆ a

template<typename RealType >
double randlib::BetaDistribution< RealType >::a = 0
protected

min bound

◆ alpha

template<typename RealType >
double randlib::BetaDistribution< RealType >::alpha = 1
protected

first shape α

◆ ALPHA_ZERO

template<typename RealType >
constexpr char randlib::BetaDistribution< RealType >::ALPHA_ZERO
staticconstexprprotected
Initial value:
=
"Possibly one or more elements of the sample coincide with the lower boundary a."

◆ b

template<typename RealType >
double randlib::BetaDistribution< RealType >::b = 1
protected

max bound

◆ beta

template<typename RealType >
double randlib::BetaDistribution< RealType >::beta = 1
protected

second shape β

◆ BETA_ZERO

template<typename RealType >
constexpr char randlib::BetaDistribution< RealType >::BETA_ZERO
staticconstexprprotected
Initial value:
=
"Possibly one or more elements of the sample coincide with the upper boundary b."

◆ bma

template<typename RealType >
double randlib::BetaDistribution< RealType >::bma = 1
protected

b-a

◆ bmaInv

template<typename RealType >
double randlib::BetaDistribution< RealType >::bmaInv = 1
protected

1/(b-a)

◆ GammaRV1

template<typename RealType >
GammaRand<RealType> randlib::BetaDistribution< RealType >::GammaRV1 {}
protected

◆ GammaRV2

template<typename RealType >
GammaRand<RealType> randlib::BetaDistribution< RealType >::GammaRV2 {}
protected

◆ logbma

template<typename RealType >
double randlib::BetaDistribution< RealType >::logbma = 0
protected

log(b-a)


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