![]() |
Fleet
0.0.9
Inference in the LOT
|
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"

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 > | |
| T | normal_lpdf (T x, T mu=0.0, T sd=1.0) |
| template<typename T > | |
| T | normal_cdf (T x, T mu, T sd) |
| template<typename T > | |
| T | random_t (T nu) |
| template<typename T > | |
| T | t_lpdf (T x, T nu) |
| double | random_cauchy () |
| template<typename T > | |
| T | cauchy_lpdf (T x, T loc=0.0, T gamma=1.0) |
| template<typename T > | |
| T | laplace_lpdf (T x, T mu=0.0, T b=1.0) |
| template<typename T > | |
| T | random_exponential (T l=1.0) |
| template<typename T > | |
| 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 > | |
| T | myrandom (T max) |
| template<typename T > | |
| 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 &)) |
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.
| 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 | ||
| ) |
| T cauchy_lpdf | ( | T | x, |
| T | loc = 0.0, |
||
| T | gamma = 1.0 |
||
| ) |
Compute the log PDF of a cauchy distribution
| x | - value |
| loc | - location |
| gamma | - scale |
| bool flip | ( | float | p = 0.5 | ) |
Random bool
| double geometric_lpdf | ( | size_t | k, |
| double | p | ||
| ) |
| T laplace_lpdf | ( | T | x, |
| T | mu = 0.0, |
||
| T | b = 1.0 |
||
| ) |
Compute the log PDF of a laplace distribution
| x | |
| mu | |
| sd |
| double lp_sample_eq | ( | const t & | x, |
| const T & | s, | ||
| std::function< double(const t &)> & | f = [](const t& v){return 1.0;} |
||
| ) |
| double lp_sample_eq | ( | const t & | x, |
| const T & | s, | ||
| double(*)(const t &) | f | ||
| ) |
| double lp_sample_one | ( | const t & | x, |
| const T & | s, | ||
| std::function< double(const t &)> & | f = [](const t& v){return 1.0;} |
||
| ) |
| double lp_sample_one | ( | const t & | x, |
| const T & | s, | ||
| double(*)(const t &) | f | ||
| ) |
| std::pair<t*,double> max_of | ( | const T & | s, |
| const std::function< double(const t &)> & | f | ||
| ) |
| T myrandom | ( | T | max | ) |
My own random integer distribution, going [0,max-1]
| max |
| T myrandom | ( | T | min, |
| T | max | ||
| ) |
Random integer distribution [min,max-1]
| min | |
| max |
| T normal_cdf | ( | T | x, |
| T | mu, | ||
| T | sd | ||
| ) |
| T normal_lpdf | ( | T | x, |
| T | mu = 0.0, |
||
| T | sd = 1.0 |
||
| ) |
Compute the log PDF of a normal distribution
| x | |
| mu | |
| sd |
| double random_cauchy | ( | ) |
Generate a random sample from a standard cauchy
| T random_exponential | ( | T | l = 1.0 | ) |
Random sample from an exponential distribution
| x | |
| mu | |
| sd |
| double random_gamma | ( | double | a, |
| double | b | ||
| ) |
| std::vector<int> random_int_vector | ( | int | min, |
| int | max, | ||
| size_t | n | ||
| ) |
Random vector of N ints in [min,max-1]
| min | |
| max |
| T random_laplace | ( | T | mu = 0.0, |
| T | b = 1.0 |
||
| ) |
Random sample from laplace distribution
| x | |
| mu | |
| sd |
| std::vector<t> random_multinomial | ( | t | a, |
| size_t | len | ||
| ) |
Generate a random vector from a multinomial, with constant alpha
| alpha | |
| len |
| 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.
| double random_normal | ( | double | mu = 0, |
| double | sd = 1.0 |
||
| ) |
| T random_t | ( | T | nu | ) |
| int rbinomial | ( | const int | n, |
| const double | p | ||
| ) |
| 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<t*,double> sample | ( | const T & | s, |
| const std::function< double(const t &)> & | f = [](const t& v){return 1.0;} |
||
| ) |
| std::pair<t*,double> sample | ( | const T & | s, |
| double(*)(const t &) | f | ||
| ) |
| 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;} |
||
| ) |
| std::pair<t*,double> sample_lp | ( | const T & | s, |
| double | z, | ||
| const std::function< double(const t &)> & | f = [](const t& v){return 0.0;} |
||
| ) |
| std::pair<t*,double> sample_lp | ( | const T & | s, |
| const std::function< double(const t &)> & | f = [](const t& v){return 0.0;} |
||
| ) |
| double sample_lp_z | ( | const T & | s, |
| const std::function< double(const t &)> & | f | ||
| ) |
Sample but where f gives LOG probabilities
| 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.
| s | - a collection of objects |
| f | - a function to map over s to get each probability |
| T t_lpdf | ( | T | x, |
| T | nu | ||
| ) |
| double uniform | ( | ) |
Sample from a uniform distribution
| double uniform | ( | const double | a, |
| const double | b | ||
| ) |
1.8.13