RandLib 2.0.0
Probability distributions, fitting, and heavy-tail tools for C++20
Loading...
Searching...
No Matches
randlib::detail Namespace Reference

Classes

struct  BayesModel
 
struct  BayesModel< ExponentialRand< Real >, GammaRand< Real > >
 
struct  BayesModel< LogNormalRand< Real >, NormalInverseGammaRand< Real > >
 
struct  BayesModel< NormalRand< Real >, NormalInverseGammaRand< Real > >
 
struct  BayesModel< PoissonRand< Int >, GammaRand< double > >
 
struct  ChiSquaredBin
 
struct  ConditionalBayesModel
 
struct  ConditionalBayesModel< BinomialRand< Int >, BetaRand< double > >
 
struct  ConditionalBayesModel< LogNormalRand< Real >, InverseGammaRand< Real > >
 
struct  ConditionalBayesModel< LogNormalRand< Real >, NormalRand< Real > >
 
struct  ConditionalBayesModel< NegativeBinomialRand< Int, Shape >, BetaRand< double > >
 
struct  ConditionalBayesModel< NormalRand< Real >, InverseGammaRand< Real > >
 
struct  ConditionalBayesModel< NormalRand< Real >, NormalRand< Real > >
 
struct  ConditionalBayesModel< ParetoRand< Real >, GammaRand< Real > >
 
struct  ConditionalBayesModel< UniformRand< Real >, ParetoRand< Real > >
 
struct  ConditionalBayesModel< WeibullRand< Real >, InverseGammaRand< Real > >
 
class  EngineRef
 The EngineRef class
Non-owning, type-erased reference to any uniform random bit generator. More...
 
struct  FitModel
 
struct  FitModel< ArcsineRand< Real > >
 
struct  FitModel< BernoulliRand >
 
struct  FitModel< BetaPrimeRand< Real > >
 
struct  FitModel< BetaRand< Real > >
 
struct  FitModel< BinomialRand< Int > >
 
struct  FitModel< CauchyRand< Real > >
 
struct  FitModel< ChiSquaredRand< Real > >
 
struct  FitModel< DegenerateRand >
 
struct  FitModel< ErlangRand< Real > >
 
struct  FitModel< ExponentialRand< Real > >
 
struct  FitModel< FisherFRand< Real > >
 
struct  FitModel< FrechetRand< Real > >
 
struct  FitModel< GammaRand< Real > >
 
struct  FitModel< GeneralizedExtremeValueRand< Real > >
 
struct  FitModel< GeneralizedParetoRand< Real > >
 
struct  FitModel< GeometricRand< Int > >
 
struct  FitModel< GumbelRand< Real > >
 
struct  FitModel< InverseGammaRand< Real > >
 
struct  FitModel< InverseGaussianRand< Real > >
 
struct  FitModel< LaplaceRand< Real > >
 
struct  FitModel< LevyRand< Real > >
 
struct  FitModel< LogisticRand< Real > >
 
struct  FitModel< LogNormalRand< Real > >
 
struct  FitModel< LogStableRand< Real > >
 
struct  FitModel< NegativeBinomialRand< Int, Shape > >
 
struct  FitModel< NoncentralChiSquaredRand< Real > >
 
struct  FitModel< NoncentralTRand< Real > >
 
struct  FitModel< NormalRand< Real > >
 
struct  FitModel< ParetoRand< Real > >
 
struct  FitModel< PoissonRand< Int > >
 
struct  FitModel< RayleighRand< Real > >
 
struct  FitModel< StableCountRand< Real > >
 
struct  FitModel< StableRand< Real > >
 
struct  FitModel< StudentTRand< Real > >
 
struct  FitModel< UniformDiscreteRand< Int > >
 
struct  FitModel< UniformRand< Real > >
 
struct  FitModel< WeibullRand< Real > >
 
struct  FitParameter
 

Concepts

concept  ConjugateModel
 
concept  ConditionalConjugateModel
 
concept  FittableModel
 

Typedefs

using FixedParameterMap = std::map< std::string, double, std::less<> >
 

Functions

double stableTanHalfPi (double alpha)
 
double stableAtan (double value)
 
template<std::floating_point Real, std::uniform_random_bit_generator G>
Real standardExponential (G &g)
 Ziggurat algorithm of Marsaglia and Tsang with 256 layers.
 
template<std::floating_point Real, std::uniform_random_bit_generator G>
Real standardNormal (G &g)
 Ziggurat algorithm of Marsaglia and Tsang with 256 layers and an explicit sign bit.
 
template<typename IntType , std::uniform_random_bit_generator G>
IntType poissonVariate (double rate, G &g)
 Poisson variate for a rate that changes from call to call, as in mixtures: the setup is a few elementary functions instead of the incomplete gamma function of PoissonRand.
 
long double zetaTail (double exponent, long double firstTerm)
 
template<std::uniform_random_bit_generator G>
constexpr int engineBits () noexcept
 Number of uniformly distributed bits in one output of G: floor(log2(max - min + 1))
 
template<std::uniform_random_bit_generator G>
std::uint64_t randomBits (G &g, int count)
 
template<std::floating_point Real, std::uniform_random_bit_generator G>
Real uniform01 (G &g)
 
template<std::floating_point Real, std::uniform_random_bit_generator G>
Real uniform01Closed (G &g)
 k / (2^b - 1) for b = min(digits, 64) random bits: uniform on [0, 1]
 
template<std::floating_point Real, std::uniform_random_bit_generator G>
Real uniform01HalfClosed (G &g)
 k / 2^b for b = min(digits, 64) random bits: uniform on [0, 1)
 
template<std::uniform_random_bit_generator G>
std::uint64_t uniformBelow (G &g, std::uint64_t n)
 
double andersonDarlingCdf (double statistic)
 
double cvmCdfInfinite (double statistic)
 
double cvmEd2 (double value)
 
double cvmEd3 (double value)
 
double cvmCorrectionTerm (int k, double statistic)
 
double cvmCdf (double statistic, std::size_t sampleSize)
 
void mergeSparseBins (std::vector< ChiSquaredBin > &bins)
 
double toUnconstrained (double value, const FitParameter &parameter)
 
double fromUnconstrained (double value, const FitParameter &parameter)
 
bool withinBounds (double value, const FitParameter &parameter)
 
void requireMethod (Method method, std::string_view distribution, std::initializer_list< Method > supported={Method::MLE, Method::MethodOfMoments})
 
template<class Distribution >
bool requiresOptimization (Method method, const FixedParameterMap &fixed)
 
template<class T >
DoublePair sampleMeanAndVariance (std::span< const T > sample)
 
template<class T >
double sampleQuantile (std::span< const T > sample, double probability)
 
template<std::size_t Rows, std::size_t Columns>
double bilinearInterpolation (const std::array< double, Rows > &rowGrid, const std::array< double, Columns > &columnGrid, const std::array< std::array< double, Columns >, Rows > &values, double row, double column)
 
std::optional< int > fixedPositiveInteger (const FixedParameterMap &fixed, std::string_view name, std::string_view distribution)
 
std::vector< std::vector< double > > inverse (std::vector< std::vector< double > > matrix)
 
template<class Distribution , class LogLikelihood >
double negativeLogLikelihood (std::span< const double > parameters, const LogLikelihood &logLikelihood)
 
template<class Distribution , class Objective >
void addUncertainty (FitResult< Distribution > &result, std::span< const FitParameter > specifications, const Objective &naturalObjective)
 
template<class Distribution , class LogLikelihood >
FitResult< Distribution > fitLikelihood (std::span< const typename Distribution::value_type > initializationSample, FitOptions options, const LogLikelihood &logLikelihood, bool forceOptimization=false)
 
template<std::floating_point Real>
std::vector< Real > sortedTailSample (std::span< const Real > sample)
 
template<std::floating_point Real>
double hillFromSorted (std::span< const Real > sorted, std::size_t order)
 

Variables

constexpr std::size_t MAX_ITER_REJECTION = 1000
 Upper bound on the iterations of rejection samplers; reaching it means there is a bug.
 
constexpr std::array< std::pair< long double, long double >, 257 > normalZiggurat
 (exp(-x^2 / 2), x) at the layer boundaries of the normal ziggurat
 
constexpr std::array< std::pair< long double, long double >, 257 > exponentialZiggurat
 (exp(-x), x) at the layer boundaries of the exponential ziggurat
 

Typedef Documentation

◆ FixedParameterMap

using randlib::detail::FixedParameterMap = typedef std::map<std::string, double, std::less<> >

Function Documentation

◆ addUncertainty()

template<class Distribution , class Objective >
void randlib::detail::addUncertainty ( FitResult< Distribution > &  result,
std::span< const FitParameter >  specifications,
const Objective &  naturalObjective 
)

◆ andersonDarlingCdf()

double randlib::detail::andersonDarlingCdf ( double  statistic)
inline

◆ bilinearInterpolation()

template<std::size_t Rows, std::size_t Columns>
double randlib::detail::bilinearInterpolation ( const std::array< double, Rows > &  rowGrid,
const std::array< double, Columns > &  columnGrid,
const std::array< std::array< double, Columns >, Rows > &  values,
double  row,
double  column 
)

◆ cvmCdf()

double randlib::detail::cvmCdf ( double  statistic,
std::size_t  sampleSize 
)
inline

◆ cvmCdfInfinite()

double randlib::detail::cvmCdfInfinite ( double  statistic)
inline

◆ cvmCorrectionTerm()

double randlib::detail::cvmCorrectionTerm ( int  k,
double  statistic 
)
inline

◆ cvmEd2()

double randlib::detail::cvmEd2 ( double  value)
inline

◆ cvmEd3()

double randlib::detail::cvmEd3 ( double  value)
inline

◆ engineBits()

template<std::uniform_random_bit_generator G>
constexpr int randlib::detail::engineBits ( )
constexprnoexcept

Number of uniformly distributed bits in one output of G: floor(log2(max - min + 1))

◆ fitLikelihood()

template<class Distribution , class LogLikelihood >
FitResult< Distribution > randlib::detail::fitLikelihood ( std::span< const typename Distribution::value_type >  initializationSample,
FitOptions  options,
const LogLikelihood &  logLikelihood,
bool  forceOptimization = false 
)

◆ fixedPositiveInteger()

std::optional< int > randlib::detail::fixedPositiveInteger ( const FixedParameterMap &  fixed,
std::string_view  name,
std::string_view  distribution 
)
inline

◆ fromUnconstrained()

double randlib::detail::fromUnconstrained ( double  value,
const FitParameter &  parameter 
)
inline

◆ hillFromSorted()

template<std::floating_point Real>
double randlib::detail::hillFromSorted ( std::span< const Real >  sorted,
std::size_t  order 
)

◆ inverse()

std::vector< std::vector< double > > randlib::detail::inverse ( std::vector< std::vector< double > >  matrix)
inline

◆ mergeSparseBins()

void randlib::detail::mergeSparseBins ( std::vector< ChiSquaredBin > &  bins)
inline

◆ negativeLogLikelihood()

template<class Distribution , class LogLikelihood >
double randlib::detail::negativeLogLikelihood ( std::span< const double >  parameters,
const LogLikelihood &  logLikelihood 
)

◆ poissonVariate()

template<typename IntType , std::uniform_random_bit_generator G>
IntType randlib::detail::poissonVariate ( double  rate,
G &  g 
)

Poisson variate for a rate that changes from call to call, as in mixtures: the setup is a few elementary functions instead of the incomplete gamma function of PoissonRand.

Below rate 10 it inverts the distribution function with the probability recurrence; above, it uses the transformed rejection with squeeze PTRS of Hörmann (1993), whose expected number of iterations is bounded uniformly in the rate.

Parameters
ratepositive rate
gengine
Returns
Poisson variate, saturated at the largest IntType

the tail beyond 1000 has probability below 1e-1400 for these rates; the bound only guards rounding

log P(x) through Stirling's series, free of the cancellation of x log(rate) and log(x!)

◆ randomBits()

template<std::uniform_random_bit_generator G>
std::uint64_t randlib::detail::randomBits ( G &  g,
int  count 
)
Parameters
gany uniform random bit generator, including those whose range is not a power of two
countnumber of bits, from 1 to 64
Returns
count independent uniform random bits, taken from the high end of the engine outputs

◆ requireMethod()

void randlib::detail::requireMethod ( Method  method,
std::string_view  distribution,
std::initializer_list< Method >  supported = {Method::MLE, Method::MethodOfMoments} 
)
inline

◆ requiresOptimization()

template<class Distribution >
bool randlib::detail::requiresOptimization ( Method  method,
const FixedParameterMap &  fixed 
)

◆ sampleMeanAndVariance()

template<class T >
DoublePair randlib::detail::sampleMeanAndVariance ( std::span< const T >  sample)

◆ sampleQuantile()

template<class T >
double randlib::detail::sampleQuantile ( std::span< const T >  sample,
double  probability 
)

◆ sortedTailSample()

template<std::floating_point Real>
std::vector< Real > randlib::detail::sortedTailSample ( std::span< const Real >  sample)

◆ stableAtan()

double randlib::detail::stableAtan ( double  value)
inline

◆ stableTanHalfPi()

double randlib::detail::stableTanHalfPi ( double  alpha)
inline

◆ standardExponential()

template<std::floating_point Real, std::uniform_random_bit_generator G>
Real randlib::detail::standardExponential ( G &  g)

Ziggurat algorithm of Marsaglia and Tsang with 256 layers.

Returns
Exp(1) variate

◆ standardNormal()

template<std::floating_point Real, std::uniform_random_bit_generator G>
Real randlib::detail::standardNormal ( G &  g)

Ziggurat algorithm of Marsaglia and Tsang with 256 layers and an explicit sign bit.

Returns
N(0, 1) variate

Marsaglia's method for the tail beyond r: accept x if E > x^2 / 2

◆ toUnconstrained()

double randlib::detail::toUnconstrained ( double  value,
const FitParameter &  parameter 
)
inline

◆ uniform01()

template<std::floating_point Real, std::uniform_random_bit_generator G>
Real randlib::detail::uniform01 ( G &  g)
Returns
(k + 1/2) / 2^b for b = digits - 1 random bits k: uniform on (0, 1) with the full resolution of Real, never 0 and never 1

◆ uniform01Closed()

template<std::floating_point Real, std::uniform_random_bit_generator G>
Real randlib::detail::uniform01Closed ( G &  g)

k / (2^b - 1) for b = min(digits, 64) random bits: uniform on [0, 1]

◆ uniform01HalfClosed()

template<std::floating_point Real, std::uniform_random_bit_generator G>
Real randlib::detail::uniform01HalfClosed ( G &  g)

k / 2^b for b = min(digits, 64) random bits: uniform on [0, 1)

◆ uniformBelow()

template<std::uniform_random_bit_generator G>
std::uint64_t randlib::detail::uniformBelow ( G &  g,
std::uint64_t  n 
)
Parameters
guniform random bit generator
npositive number of outcomes
Returns
uniform integer in [0, n), without modulo bias: 64-bit values below 2^64 mod n are rejected

◆ withinBounds()

bool randlib::detail::withinBounds ( double  value,
const FitParameter &  parameter 
)
inline

◆ zetaTail()

long double randlib::detail::zetaTail ( double  exponent,
long double  firstTerm 
)
inline

Variable Documentation

◆ exponentialZiggurat

constexpr std::array<std::pair<long double, long double>, 257> randlib::detail::exponentialZiggurat
inlineconstexpr

(exp(-x), x) at the layer boundaries of the exponential ziggurat

◆ MAX_ITER_REJECTION

constexpr std::size_t randlib::detail::MAX_ITER_REJECTION = 1000
inlineconstexpr

Upper bound on the iterations of rejection samplers; reaching it means there is a bug.

◆ normalZiggurat

constexpr std::array<std::pair<long double, long double>, 257> randlib::detail::normalZiggurat
inlineconstexpr

(exp(-x^2 / 2), x) at the layer boundaries of the normal ziggurat