Hamiltonian Monte Carlo

randomnumbers.hpp File Reference

Set of functions to draw from (multivariate, correlated) normal distributions. More...

#include <vector>
Include dependency graph for randomnumbers.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double randn (double mean, double stdv)
 Draws from Gaussian \( \mathcal{N} (\mu,\sigma) \) (mean, standard deviation) using Box-Müller transform. More...
 
std::vector< double > randn (std::vector< double > means, std::vector< double > stdv)
 Draws from uncorrelated Gaussians \( \mathcal{N} (\boldsymbol \mu,\boldsymbol{\sigma}) \) (vectors of mean, standard deviation) using Box-Müller transform. Loops over both vectors and calls randn(double mean, double stdv) every iteration. More...
 
std::vector< double > randn (std::vector< double > stdv)
 Draws zero-mean samples from uncorrelated Gaussians \( \mathcal{N} (\boldsymbol 0,\boldsymbol{\sigma}) \) (standard deviation) using Box-Müller transform. Loops over both vectors and calls randn(double mean, double stdv) every iteration. More...
 
std::vector< double > randn_Cholesky (std::vector< double > mean, std::vector< std::vector< double >> CholeskyLower_CovarianceMatrix)
 Drawing non-zero mean samples from an \( n \) dimensional correlated Gaussian. Invokes randn_Cholesky(std::vector<std::vector<double>> CholeskyLower_CovarianceMatrix) and adds mean. More...
 
std::vector< double > randn_Cholesky (std::vector< std::vector< double >> CholeskyLower_CovarianceMatrix)
 Drawing non-zero mean samples from an \( n \) dimensional correlated Gaussian. This algorithm uses the lower Cholesky matrix of the (positive definite Hermitian) covariance matrix to transform (affine transform) n uncorrelated samples with standard deviation 1 to the right covariances. The mean is assumed zero. More...
 
std::vector< double > randn (std::vector< std::vector< double >> DiagonalCovarianceMatrix)
 Drawing n zero mean samples from \( \mathcal{N} (\boldsymbol 0,\boldsymbol{\sigma}) \). No correlation is present between the parameters. More...
 
double randf (double min, double max)
 Draw uniformly distributed samples between two numbers. More...
 

Variables

const double PI = 3.14159265358979323846264338327
 

Detailed Description

Set of functions to draw from (multivariate, correlated) normal distributions.

This set of functions allows one to sample from mutliple types of normal distributions. All are based on a uniform number generator which transforms to normally distributed samples using the Box-Müller transform.

Definition in file randomnumbers.hpp.

Function Documentation

◆ randf()

double randf ( double  min,
double  max 
)

Draw uniformly distributed samples between two numbers.

Parameters
minMinimum of the distribution.
maxMaximum of the distribution.
Returns
Sample.

Definition at line 13 of file randomnumbers.cpp.

◆ randn() [1/4]

double randn ( double  mean,
double  stdv 
)

Draws from Gaussian \( \mathcal{N} (\mu,\sigma) \) (mean, standard deviation) using Box-Müller transform.

Parameters
meandouble containing \( \mu \)
stdvdouble containing \( \sigma \)
Returns
double, sample from the distribution

Definition at line 17 of file randomnumbers.cpp.

◆ randn() [2/4]

std::vector<double> randn ( std::vector< double >  means,
std::vector< double >  stdv 
)

Draws from uncorrelated Gaussians \( \mathcal{N} (\boldsymbol \mu,\boldsymbol{\sigma}) \) (vectors of mean, standard deviation) using Box-Müller transform. Loops over both vectors and calls randn(double mean, double stdv) every iteration.

Parameters
meanvector containing \( \mu_i \)
stdvvector containing \( \sigma_i \)
Returns
Vector of samples from the distributions.

Definition at line 30 of file randomnumbers.cpp.

◆ randn() [3/4]

std::vector<double> randn ( std::vector< double >  stdv)

Draws zero-mean samples from uncorrelated Gaussians \( \mathcal{N} (\boldsymbol 0,\boldsymbol{\sigma}) \) (standard deviation) using Box-Müller transform. Loops over both vectors and calls randn(double mean, double stdv) every iteration.

Parameters
stdvvector containing \( \sigma_i \)
Returns
Vector of samples from the distributions.

Definition at line 36 of file randomnumbers.cpp.

◆ randn() [4/4]

std::vector<double> randn ( std::vector< std::vector< double >>  DiagonalCovarianceMatrix)

Drawing n zero mean samples from \( \mathcal{N} (\boldsymbol 0,\boldsymbol{\sigma}) \). No correlation is present between the parameters.

Parameters
DiagonalCovarianceMatrixMatrix containing on the diagonal the variance, or standard deviation squared.
Returns
Vector containing n samples.

Definition at line 62 of file randomnumbers.cpp.

◆ randn_Cholesky() [1/2]

std::vector<double> randn_Cholesky ( std::vector< double >  mean,
std::vector< std::vector< double >>  CholeskyLower_CovarianceMatrix 
)

Drawing non-zero mean samples from an \( n \) dimensional correlated Gaussian. Invokes randn_Cholesky(std::vector<std::vector<double>> CholeskyLower_CovarianceMatrix) and adds mean.

Parameters
meanvector containing \( n \) means.
CholeskyLower_CovarianceMatrixMatrix containing the n x n Lower Cholesky matrix of the n x n covariance matrix \( \boldsymbol \Sigma \), must be square and lower triangular.
Returns
Vector containing the non-zero mean correlated samples.

Definition at line 47 of file randomnumbers.cpp.

◆ randn_Cholesky() [2/2]

std::vector<double> randn_Cholesky ( std::vector< std::vector< double >>  CholeskyLower_CovarianceMatrix)

Drawing non-zero mean samples from an \( n \) dimensional correlated Gaussian. This algorithm uses the lower Cholesky matrix of the (positive definite Hermitian) covariance matrix to transform (affine transform) n uncorrelated samples with standard deviation 1 to the right covariances. The mean is assumed zero.

Parameters
CholeskyLower_CovarianceMatrixMatrix containing the n x n Lower Cholesky matrix of the n x n covariance matrix \( \boldsymbol \Sigma \), must be square and lower triangular.
Returns
Vector containing the zero mean correlated samples.

Definition at line 51 of file randomnumbers.cpp.

Variable Documentation

◆ PI

const double PI = 3.14159265358979323846264338327

Definition at line 18 of file randomnumbers.hpp.