Fleet  0.0.9
Inference in the LOT
Functions | Variables
Random.h File Reference
#include <random>
#include <functional>
#include "Errors.h"
#include "Numerics.h"

Go to the source code of this file.

Functions

thread_local std::mt19937 rng (rd())
 
thread_local std::uniform_real_distribution< double > uniform_dist (0.0, 1.0)
 
thread_local std::normal_distribution< float > normal (0.0, 1.0)
 
double uniform ()
 
double cauchy_lpdf (double x, double loc=0.0, double gamma=1.0)
 
double normal_lpdf (double x, double mu=0.0, double sd=1.0)
 
double random_cauchy ()
 
template<typename t >
std::vector< t > random_multinomial (t a, size_t len)
 
template<typename T >
myrandom (T max)
 
template<typename T >
myrandom (T min, T max)
 
bool flip (float p=0.5)
 
template<typename t , typename T >
double sample_z (const T &s, const std::function< double(const t &)> &f)
 
template<typename t , typename T >
std::pair< t *, double > sample (const T &s, const std::function< double(const t &)> &f=[](const t &v){return 1.0;})
 
template<typename t , typename T >
std::pair< t *, double > sample (const T &s, double z, const std::function< double(const t &)> &f=[](const t &v){return 1.0;})
 
std::pair< int, double > sample_int (unsigned int max, const std::function< double(const int)> &f=[](const int v){return 1.0;})
 
std::pair< int, double > sample_int_lp (unsigned int max, const std::function< double(const int)> &f=[](const int v){return 1.0;})
 
template<typename t , typename T >
std::pair< size_t, double > arg_max (const T &s, const std::function< double(const t &)> &f)
 
std::pair< size_t, double > arg_max_int (unsigned int max, const std::function< double(const int)> &f)
 
template<typename t , typename T >
std::pair< t *, double > max_of (const T &s, const std::function< double(const t &)> &f)
 
template<typename t , typename T >
std::pair< t *, double > sample (const T &s, double(*f)(const t &))
 
template<typename t , typename T >
double lp_sample_eq (const t &x, const T &s, std::function< double(const t &)> &f=[](const t &v){return 1.0;})
 
template<typename t , typename T >
double lp_sample_eq (const t &x, const T &s, double(*f)(const t &))
 
template<typename t , typename T >
double lp_sample_one (const t &x, const T &s, std::function< double(const t &)> &f=[](const t &v){return 1.0;})
 
template<typename t , typename T >
double lp_sample_one (const t &x, const T &s, double(*f)(const t &))
 

Variables

thread_local std::random_device rd
 

Function Documentation

§ arg_max()

template<typename t , typename T >
std::pair<size_t,double> arg_max ( const T &  s,
const std::function< double(const t &)> &  f 
)

§ arg_max_int()

std::pair<size_t,double> arg_max_int ( unsigned int  max,
const std::function< double(const int)> &  f 
)

§ cauchy_lpdf()

double cauchy_lpdf ( double  x,
double  loc = 0.0,
double  gamma = 1.0 
)

Compute the log PDF of a cauchy distribution

Parameters
x- value
loc- location
gamma- scale
Returns

§ flip()

bool flip ( float  p = 0.5)

Random bool

Returns

§ lp_sample_eq() [1/2]

template<typename t , typename T >
double lp_sample_eq ( const t &  x,
const T &  s,
std::function< double(const t &)> &  f = [](const t& v){return 1.0;} 
)

§ lp_sample_eq() [2/2]

template<typename t , typename T >
double lp_sample_eq ( const t &  x,
const T &  s,
double(*)(const t &)  f 
)

§ lp_sample_one() [1/2]

template<typename t , typename T >
double lp_sample_one ( const t &  x,
const T &  s,
std::function< double(const t &)> &  f = [](const t& v){return 1.0;} 
)

§ lp_sample_one() [2/2]

template<typename t , typename T >
double lp_sample_one ( const t &  x,
const T &  s,
double(*)(const t &)  f 
)

§ max_of()

template<typename t , typename T >
std::pair<t*,double> max_of ( const T &  s,
const std::function< double(const t &)> &  f 
)

§ myrandom() [1/2]

template<typename T >
T myrandom ( max)

My own random integer distribution, going [0,max-1]

Parameters
max
Returns

§ myrandom() [2/2]

template<typename T >
T myrandom ( min,
max 
)

Random integer distribution [min,max-1]

Parameters
min
max
Returns

§ normal()

thread_local std::normal_distribution<float> normal ( 0.  0,
1.  0 
)

§ normal_lpdf()

double normal_lpdf ( double  x,
double  mu = 0.0,
double  sd = 1.0 
)

Compute the log PDF of a normal distribution

Parameters
x
mu
sd
Returns

§ random_cauchy()

double random_cauchy ( )

Generate a random sample from a standard cauchy

Returns

§ random_multinomial()

template<typename t >
std::vector<t> random_multinomial ( a,
size_t  len 
)

Generate a random vector from a multinomial, with constant alpha

Parameters
alpha
len
Returns

§ rng()

thread_local std::mt19937 rng ( rd()  )

§ sample() [1/3]

template<typename t , typename T >
std::pair<t*,double> sample ( const T &  s,
const std::function< double(const t &)> &  f = [](const t& v){return 1.0;} 
)

§ sample() [2/3]

template<typename t , typename T >
std::pair<t*,double> sample ( const T &  s,
double  z,
const std::function< double(const t &)> &  f = [](const t& v){return 1.0;} 
)

§ sample() [3/3]

template<typename t , typename T >
std::pair<t*,double> sample ( const T &  s,
double(*)(const t &)  f 
)

§ sample_int()

std::pair<int,double> sample_int ( unsigned int  max,
const std::function< double(const int)> &  f = [](const int v){return 1.0;} 
)

§ sample_int_lp()

std::pair<int,double> sample_int_lp ( unsigned int  max,
const std::function< double(const int)> &  f = [](const int v){return 1.0;} 
)

§ sample_z()

template<typename t , typename T >
double sample_z ( const T &  s,
const std::function< double(const t &)> &  f 
)

If f specifies the probability (NOT log probability) of each element of s, compute the normalizing constant.

Parameters
s- a collection of objects
f- a function to map over s to get each probability
Returns

§ uniform()

double uniform ( )

Sample from a uniform distribution

Returns

§ uniform_dist()

thread_local std::uniform_real_distribution<double> uniform_dist ( 0.  0,
1.  0 
)

Variable Documentation

§ rd

thread_local std::random_device rd