Fleet  0.0.9
Inference in the LOT
Functions
Random.h File Reference

This is a thread_local rng whose first object is used to see others (in other threads). This way, we can have thread_local rngs that all are seeded deterministcally in Fleet via –seed=X. More...

#include <fstream>
#include <random>
#include <functional>
#include "Errors.h"
#include "Numerics.h"
#include "Rng.h"
Include dependency graph for Random.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double uniform ()
 
double uniform (const double a, const double b)
 
bool flip (float p=0.5)
 
int rbinomial (const int n, const double p)
 
double random_normal (double mu=0, double sd=1.0)
 
template<typename T >
normal_lpdf (T x, T mu=0.0, T sd=1.0)
 
template<typename T >
normal_cdf (T x, T mu, T sd)
 
template<typename T >
random_t (T nu)
 
template<typename T >
t_lpdf (T x, T nu)
 
double random_cauchy ()
 
template<typename T >
cauchy_lpdf (T x, T loc=0.0, T gamma=1.0)
 
template<typename T >
laplace_lpdf (T x, T mu=0.0, T b=1.0)
 
template<typename T >
random_exponential (T l=1.0)
 
template<typename T >
random_laplace (T mu=0.0, T b=1.0)
 
double geometric_lpdf (size_t k, double p)
 
double random_gamma (double a, double b)
 
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)
 
std::vector< int > random_int_vector (int min, int max, size_t n)
 
std::vector< bool > random_nonempty_subset (const size_t n, const double p)
 Returns a random nonempty subset of n elements, as a vector<bool> of length n with trues for elements in the subset and falses otherwise. Each element is included with probability p. More...
 
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, double z, 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, const std::function< double(const t &)> &f=[](const t &v){return 1.0;})
 
template<typename t , typename T >
double sample_lp_z (const T &s, const std::function< double(const t &)> &f)
 
template<typename t , typename T >
std::pair< t *, double > sample_lp (const T &s, double z, const std::function< double(const t &)> &f=[](const t &v){return 0.0;})
 
template<typename t , typename T >
std::pair< t *, double > sample_lp (const T &s, const std::function< double(const t &)> &f=[](const t &v){return 0.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 &))
 

Detailed Description

This is a thread_local rng whose first object is used to see others (in other threads). This way, we can have thread_local rngs that all are seeded deterministcally in Fleet via –seed=X.

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()

template<typename T >
T cauchy_lpdf ( x,
loc = 0.0,
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

◆ geometric_lpdf()

double geometric_lpdf ( size_t  k,
double  p 
)

◆ laplace_lpdf()

template<typename T >
T laplace_lpdf ( x,
mu = 0.0,
b = 1.0 
)

Compute the log PDF of a laplace distribution

Parameters
x
mu
sd
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_cdf()

template<typename T >
T normal_cdf ( x,
mu,
sd 
)

◆ normal_lpdf()

template<typename T >
T normal_lpdf ( x,
mu = 0.0,
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_exponential()

template<typename T >
T random_exponential ( l = 1.0)

Random sample from an exponential distribution

Parameters
x
mu
sd
Returns

◆ random_gamma()

double random_gamma ( double  a,
double  b 
)

◆ random_int_vector()

std::vector<int> random_int_vector ( int  min,
int  max,
size_t  n 
)

Random vector of N ints in [min,max-1]

Parameters
min
max
Returns

◆ random_laplace()

template<typename T >
T random_laplace ( mu = 0.0,
b = 1.0 
)

Random sample from laplace distribution

Parameters
x
mu
sd
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

◆ random_nonempty_subset()

std::vector<bool> random_nonempty_subset ( const size_t  n,
const double  p 
)

Returns a random nonempty subset of n elements, as a vector<bool> of length n with trues for elements in the subset and falses otherwise. Each element is included with probability p.

◆ random_normal()

double random_normal ( double  mu = 0,
double  sd = 1.0 
)

◆ random_t()

template<typename T >
T random_t ( nu)

◆ rbinomial()

int rbinomial ( const int  n,
const double  p 
)

◆ sample() [1/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() [2/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() [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_lp() [1/2]

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

◆ sample_lp() [2/2]

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

◆ sample_lp_z()

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

Sample but where f gives LOG probabilities

Returns

◆ 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

◆ t_lpdf()

template<typename T >
T t_lpdf ( x,
nu 
)

◆ uniform() [1/2]

double uniform ( )

Sample from a uniform distribution

Returns

◆ uniform() [2/2]

double uniform ( const double  a,
const double  b 
)