Theoretica
A C++ numerical and automatic mathematical library
sampling.h File Reference

Sampling from probability distributions. More...

#include "../core/function.h"
#include "./prng.h"

Go to the source code of this file.

Classes

struct  theoretica::pdf_sampler
 A probability density function sampler which generates pseudorandom numbers following asymptotically a given distribution \(f(x; \vec \theta)\). More...
 

Namespaces

 theoretica
 Main namespace of the library which contains all functions and objects.
 

Typedefs

using theoretica::pdf_sampling_function = real(*)(const std::vector< real > &, PRNG &)
 A p.d.f sampling function taking as input the parameters of the distribution and a pseudorandom number generator.
 

Functions

real theoretica::rand_uniform (real a, real b, PRNG &g, uint64_t prec=STATISTICS_RAND_PREC)
 Generate a pseudorandom real number in [a, b] using a preexisting generator. More...
 
real theoretica::rand_uniform (const std::vector< real > &theta, PRNG &g)
 Wrapper for rand_uniform(real, real, PRNG) More...
 
real theoretica::rand_cointoss (PRNG &g)
 Coin toss random generator. More...
 
real theoretica::rand_cointoss (const std::vector< real > &theta, PRNG &g)
 Wrapper for rand_cointoss(PRNG) More...
 
real theoretica::rand_diceroll (unsigned int faces, PRNG &g)
 Dice roll random generator. More...
 
real theoretica::rand_diceroll (const std::vector< real > &theta, PRNG &g)
 Wrapper for rand_diceroll(PRNG) More...
 
real theoretica::rand_trycatch (stat_function f, const vec< real > &theta, real x1, real x2, real y1, real y2, PRNG &g, unsigned int max_iter=STATISTICS_TRYANDCATCH_ITER)
 Generate a pseudorandom value following any probability distribution function using the Try-and-Catch (rejection) algorithm. More...
 
real theoretica::rand_rejectsamp (stat_function f, const vec< real > &theta, real_function p, real_function Pinv, PRNG &g, unsigned int max_tries=100)
 Generate a random number following any given distribution using rejection sampling. More...
 
real theoretica::rand_gaussian_polar (real mean, real sigma, PRNG &g)
 Generate a random number following a Gaussian distribution using Marsaglia's polar method. More...
 
real theoretica::rand_gaussian_boxmuller (real mean, real sigma, PRNG &g)
 Generate a random number following a Gaussian distribution using the Box-Muller method. More...
 
real theoretica::rand_gaussian_clt (real mean, real sigma, PRNG &g)
 Generate a random number in a range following a Gaussian distribution by exploiting the Central Limit Theorem. More...
 
real theoretica::rand_gaussian_clt (real mean, real sigma, PRNG &g, unsigned int N)
 Generate a random number in a range following a Gaussian distribution by exploiting the Central Limit Theorem. More...
 
real theoretica::rand_gaussian (real mean, real sigma, PRNG &g)
 Generate a random number following a Gaussian distribution using the best available algorithm.
 
real theoretica::rand_gaussian (const std::vector< real > &theta, PRNG &g)
 Wrapper for rand_gaussian(real, real, PRNG) More...
 
real theoretica::rand_exponential (real lambda, PRNG &g)
 Generate a random number following an exponential distribution using the quantile (inverse) function method.
 
real theoretica::rand_exponential (const std::vector< real > &theta, PRNG &g)
 Wrapper for rand_exponential(real, PRNG) More...
 
real theoretica::rand_rayleigh (real sigma, PRNG &g)
 Generate a random number following a Rayleigh distribution using the quantile (inverse) function method.
 
real theoretica::rand_rayleigh (const std::vector< real > &theta, PRNG &g)
 Wrapper for rand_rayleigh(real, PRNG) More...
 
real theoretica::rand_cauchy (real mu, real alpha, PRNG &g)
 Generate a random number following a Cauchy distribution using the quantile (inverse) function method.
 
real theoretica::rand_cauchy (const std::vector< real > &theta, PRNG &g)
 Wrapper for rand_cauchy(real, real, PRNG) More...
 
real theoretica::rand_laplace (real mu, real b, PRNG &g)
 Generate a random number following a Laplace distribution using the quantile (inverse) function method.
 
real theoretica::rand_laplace (const std::vector< real > &theta, PRNG &g)
 Generate a random number following a Laplace distribution using the quantile (inverse) function method.
 
real theoretica::rand_pareto (real x_m, real alpha, PRNG &g)
 Generate a random number following a Pareto distribution using the quantile (inverse) function method.
 
real theoretica::rand_pareto (const std::vector< real > &theta, PRNG &g)
 Wrapper for rand_pareto(real, real, PRNG) More...
 
real theoretica::metropolis (real_function pdf, pdf_sampler &g, real x0, PRNG &rnd, unsigned int depth=STATISTICS_METROPOLIS_DEPTH)
 Metropolis algorithm for distribution sampling using a symmetric proposal distribution. More...
 
real theoretica::metropolis (real_function pdf, pdf_sampler &g, real x0, unsigned int depth=STATISTICS_METROPOLIS_DEPTH)
 Metropolis algorithm for distribution sampling using a symmetric proposal distribution. More...
 

Detailed Description

Sampling from probability distributions.