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

The GammaDistribution class
Abstract class for Gamma distribution. More...

#include <gamma.hpp>

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

Public Member Functions

virtual ~GammaDistribution ()
 
Support SupportType () const override
 
RealType MinValue () const override
 
RealType MaxValue () const override
 
double GetShape () const noexcept
 
double GetScale () const noexcept
 
double GetRate () const noexcept
 
double GetLogGammaShape () const noexcept
 
double GetLogShape () const noexcept
 
double GetDigammaShape () const noexcept
 
double GetLogRate () const noexcept
 
double f (const RealType &x) const override
 
double logf (const RealType &x) const override
 
double F (const RealType &x) const override
 
double logF (const RealType &x) const
 
double S (const RealType &x) const override
 
double logS (const RealType &x) const
 
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 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.
 
RealType Median () const override
 
long double Skewness () const override
 
long double ExcessKurtosis () const override
 
- 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)
 
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)
 

Static Public Member Functions

template<std::uniform_random_bit_generator G>
static RealType StandardVariate (double shape, G &g)
 
template<std::uniform_random_bit_generator G>
static RealType Variate (double shape, double rate, G &g)
 
- 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)
 

Protected Member Functions

 GammaDistribution (double shape, double rate)
 
void SetParameters (double shape, double rate)
 
void SetShape (double shape)
 SetShape.
 
- Protected Member Functions inherited from randlib::ContinuousDistribution< RealType >
 ContinuousDistribution ()
 
std::complex< double > integrateCharacteristicFunction (double t) const
 
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
 shape α
 
double beta = 1
 rate β
 
double theta = 1
 scale θ = 1/β
 
double lgammaAlpha = 0
 log(Γ(α))
 
double pdfCoef = 0
 α * log(β) - log(Γ(α))
 
double logAlpha = 0
 log(α)
 
double logBeta = 0
 log(β)
 
double digammaAlpha = -randlib::consts::egamma
 ψ(α)
 

Additional Inherited Members

- Public Types inherited from randlib::ProbabilityDistribution< T >
using value_type = T
 
- 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::GammaDistribution< RealType >

The GammaDistribution class
Abstract class for Gamma distribution.

f(x | α, β) = β^α / Γ(α) * x^(α-1) * exp(-βx), where Γ(α) denotes Gamma function

Notation X ~ Γ(α, β)

Related distributions:
σX ~ Γ(α, σβ)
If X ~ Γ(1, β), then X ~ Exp(β)
If X ~ Γ(0.5 * n, 0.5), then X ~ χ^2(n)
If X ~ Γ(k, β) for integer k, then X ~ Erlang(k, β)

Constructor & Destructor Documentation

◆ GammaDistribution()

template<typename RealType >
randlib::GammaDistribution< RealType >::GammaDistribution ( double  shape,
double  rate 
)
protected

◆ ~GammaDistribution()

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

Member Function Documentation

◆ ExcessKurtosis()

template<typename RealType >
long double randlib::GammaDistribution< 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 >.

◆ f()

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

Reimplemented from randlib::ContinuousDistribution< RealType >.

◆ F()

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

◆ GeometricMean()

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

◆ GeometricVariance()

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

◆ GetDigammaShape()

template<typename RealType >
double randlib::GammaDistribution< RealType >::GetDigammaShape ( ) const
inlinenoexcept
Returns
ψ(α)

◆ GetLogGammaShape()

template<typename RealType >
double randlib::GammaDistribution< RealType >::GetLogGammaShape ( ) const
inlinenoexcept
Returns
log(Γ(α))

◆ GetLogRate()

template<typename RealType >
double randlib::GammaDistribution< RealType >::GetLogRate ( ) const
inlinenoexcept
Returns
log(β)

◆ GetLogShape()

template<typename RealType >
double randlib::GammaDistribution< RealType >::GetLogShape ( ) const
inlinenoexcept
Returns
log(α)

◆ GetRate()

template<typename RealType >
double randlib::GammaDistribution< RealType >::GetRate ( ) const
inlinenoexcept
Returns
β

◆ GetScale()

template<typename RealType >
double randlib::GammaDistribution< RealType >::GetScale ( ) const
inlinenoexcept
Returns
θ = 1/β

◆ GetShape()

template<typename RealType >
double randlib::GammaDistribution< RealType >::GetShape ( ) const
inlinenoexcept
Returns
α

◆ logF()

template<typename RealType >
double randlib::GammaDistribution< RealType >::logF ( const RealType &  x) const

◆ logf()

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

Implements randlib::ContinuousDistribution< RealType >.

◆ logS()

template<typename RealType >
double randlib::GammaDistribution< RealType >::logS ( const RealType &  x) const

◆ MaxValue()

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

Implements randlib::ProbabilityDistribution< T >.

◆ Mean()

template<typename RealType >
long double randlib::GammaDistribution< RealType >::Mean ( ) const
overridevirtual

◆ Median()

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

Reimplemented from randlib::UnivariateDistribution< RealType >.

◆ MinValue()

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

Implements randlib::ProbabilityDistribution< T >.

◆ Mode()

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

Reimplemented from randlib::ContinuousDistribution< RealType >.

◆ operator()()

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

◆ S()

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

◆ SetParameters()

template<typename RealType >
void randlib::GammaDistribution< RealType >::SetParameters ( double  shape,
double  rate 
)
protected
Parameters
shapeα
rateβ

set constants for generator

◆ SetShape()

template<typename RealType >
void randlib::GammaDistribution< RealType >::SetShape ( double  shape)
protected

SetShape.

Parameters
shapeα

◆ Skewness()

template<typename RealType >
long double randlib::GammaDistribution< 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 >.

◆ StandardVariate()

template<typename RealType >
template<std::uniform_random_bit_generator G>
RealType randlib::GammaDistribution< RealType >::StandardVariate ( double  shape,
G &  g 
)
static
Parameters
shapeα
guniform random bit generator
Returns
gamma variate with shape α and unity rate

◆ SupportType()

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

Implements randlib::UnivariateDistribution< RealType >.

◆ Variance()

template<typename RealType >
long double randlib::GammaDistribution< RealType >::Variance ( ) const
overridevirtual

◆ Variate()

template<typename RealType >
template<std::uniform_random_bit_generator G>
RealType randlib::GammaDistribution< RealType >::Variate ( double  shape,
double  rate,
G &  g 
)
static
Parameters
shapeα
rateβ
guniform random bit generator
Returns
gamma variate with shape α and rate β

Member Data Documentation

◆ alpha

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

shape α

◆ beta

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

rate β

◆ digammaAlpha

template<typename RealType >
double randlib::GammaDistribution< RealType >::digammaAlpha = -randlib::consts::egamma
protected

ψ(α)

◆ lgammaAlpha

template<typename RealType >
double randlib::GammaDistribution< RealType >::lgammaAlpha = 0
protected

log(Γ(α))

◆ logAlpha

template<typename RealType >
double randlib::GammaDistribution< RealType >::logAlpha = 0
protected

log(α)

◆ logBeta

template<typename RealType >
double randlib::GammaDistribution< RealType >::logBeta = 0
protected

log(β)

◆ pdfCoef

template<typename RealType >
double randlib::GammaDistribution< RealType >::pdfCoef = 0
protected

α * log(β) - log(Γ(α))

◆ theta

template<typename RealType >
double randlib::GammaDistribution< RealType >::theta = 1
protected

scale θ = 1/β


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