Hamiltonian Monte Carlo

randomnumbers.cpp File Reference
#include <cstdlib>
#include "randomnumbers.hpp"
#include "linearalgebra.hpp"
#include <cmath>
#include <utility>
#include <vector>
Include dependency graph for randomnumbers.cpp:

Go to the source code of this file.

Functions

double randf (double min, double max)
 Draw uniformly distributed samples between two numbers. More...
 
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...
 

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.