Stan  1.0
probability, sampling & optimization
Classes | Functions
stan::mcmc Namespace Reference

Markov chain Monte Carlo samplers. More...

Classes

class  adaptive_cdhmc
 Adaptive "constant distance" Hamiltonian Monte Carlo (CDHMC) sampler. More...
 
class  adaptive_hmc
 Adaptive Hamiltonian Monte Carlo (HMC) sampler. More...
 
class  adaptive_sampler
 An abstract base class for adaptive samplers. More...
 
class  chains
 An mcmc::chains object stores parameter names and dimensionalities along with samples from multiple chains. More...
 
class  DualAverage
 Implements Nesterov's dual average algorithm. More...
 
class  hmc
 Hamiltonian Monte Carlo (HMC) sampler. More...
 
class  hmc_base
 
class  nuts
 No-U-Turn Sampler (NUTS). More...
 
class  nuts_diag
 No-U-Turn Sampler (NUTS) with varying step sizes. More...
 
class  sample
 Representation of a MCMC sample. More...
 

Functions

const std::vector< std::string > & test_match_return_names (const std::vector< std::string > &names, const std::vector< std::vector< size_t > > &dimss)
 
void validate_prob (double p)
 
void validate_dims_idxs (const std::vector< size_t > &dims, const std::vector< size_t > &idxs)
 Validate the specified indexes with respect to the specified dimensions. More...
 
size_t get_offset (const std::vector< size_t > &dims, const std::vector< size_t > &idxs)
 Return the offset in last-index major indexing for the specified indexes given the specified number of dimensions. More...
 
void increment_indexes (const std::vector< size_t > &dims, std::vector< size_t > &idxs)
 Increments the specified indexes to refer to the next value in an array given by the specified dimensions. More...
 
template<class RNG >
void permutation (std::vector< size_t > &x, size_t n, RNG &rng)
 Write a permutation into the specified vector of the specified size using the specified Boost random number generator. More...
 
template<typename T >
void permute (const std::vector< size_t > &pi, const std::vector< T > &x_from, std::vector< T > &x_to)
 Write the specified permutation of the first vector into the second vector. More...
 
void read_variables (const std::string filename, const size_t skip, std::vector< std::string > &names, std::vector< std::vector< size_t > > &dimss)
 Reads variable names and dims from a csv output file. More...
 
template<typename RNG >
size_t add_chain (stan::mcmc::chains< RNG > &chains, const size_t chain, const std::string filename, const size_t skip)
 Adds a chain from a csv file. More...
 
void write_error_msgs (std::ostream *error_msgs, const std::domain_error &e)
 
double leapfrog (stan::model::prob_grad &model, std::vector< int > z, std::vector< double > &x, std::vector< double > &m, std::vector< double > &g, double epsilon, std::ostream *error_msgs=0, std::ostream *output_msgs=0)
 Computes the log probability for a single leapfrog step in Hamiltonian Monte Carlo. More...
 
double rescaled_leapfrog (stan::model::prob_grad &model, std::vector< int > z, const std::vector< double > &step_sizes, std::vector< double > &x, std::vector< double > &m, std::vector< double > &g, double epsilon, std::ostream *error_msgs=0, std::ostream *output_msgs=0)
 
int sample_unnorm_log (std::vector< double > probs, boost::uniform_01< boost::mt19937 & > &rand_uniform_01)
 

Detailed Description

Markov chain Monte Carlo samplers.

Function Documentation

◆ add_chain()

template<typename RNG >
size_t stan::mcmc::add_chain ( stan::mcmc::chains< RNG > &  chains,
const size_t  chain,
const std::string  filename,
const size_t  skip 
)

Adds a chain from a csv file.

Parameters
[in,out]chainsThe chains object to modify
chainchain number
filenamefile name of a csv output file
skipnumber of variables to skip
Returns
number of samples added

Definition at line 1788 of file chains.hpp.

◆ get_offset()

size_t stan::mcmc::get_offset ( const std::vector< size_t > &  dims,
const std::vector< size_t > &  idxs 
)

Return the offset in last-index major indexing for the specified indexes given the specified number of dimensions.

If both sequences are empty, the index returned is 0.

Parameters
dimsSequence of dimensions.
idxsSequence of inndexes.
Returns
Offset of indexes given dimensions.
Exceptions
std::invalid_argumentIf the sizes of the index and dimension sequences is different.
std::out_of_rangeIf one of the indexes is greater than or equal to the corresponding index.

Definition at line 103 of file chains.hpp.

◆ increment_indexes()

void stan::mcmc::increment_indexes ( const std::vector< size_t > &  dims,
std::vector< size_t > &  idxs 
)

Increments the specified indexes to refer to the next value in an array given by the specified dimensions.

The indexing is in last-index major order, which is column-major for matrices.

The first index in the sequence is all zeroes. Incrementing the last index, whose values are the dimensions minus one, returns the all-zero matrix.

Given dims == (2,2,2), the sequence of indexes are

[0 0 0], [1 0 0], [0 1 0], [1 1 0], [0 0 1], [1 0 1], [0 1 1], [1 1 1], [0 0 0], [1 0 0], ...

Parameters
dimsDimensions of array.
idxsIndexes into array.
Exceptions
std::invalid_argumentIf the dimensions and indexes are not the same size.
std::out_of_rangeIf an index is greater than or equal to the corresponding dimension.

Definition at line 151 of file chains.hpp.

◆ leapfrog()

double stan::mcmc::leapfrog ( stan::model::prob_grad model,
std::vector< int >  z,
std::vector< double > &  x,
std::vector< double > &  m,
std::vector< double > &  g,
double  epsilon,
std::ostream *  error_msgs = 0,
std::ostream *  output_msgs = 0 
)

Computes the log probability for a single leapfrog step in Hamiltonian Monte Carlo.

If a domain error occurs when calling the model's grad_log_prob(), this function returns -inf. Domain errors can occur when distribution functions are called with parameters out of support.

Parameters
[in]modelProbability model with gradients.
[in]zInteger parameters.
[in]xReal parameters
[in,out]mMomentum.
[in,out]gGradient at x, z.
[in]epsilonStep size used in Hamiltonian dynamics.
[in,out]error_msgsOutput stream for error messages.
[in,out]output_msgsOutput stream for output messages.
Returns
the log probability of x and m.

Definition at line 57 of file util.hpp.

◆ permutation()

template<class RNG >
void stan::mcmc::permutation ( std::vector< size_t > &  x,
size_t  n,
RNG &  rng 
)

Write a permutation into the specified vector of the specified size using the specified Boost random number generator.

The vector will be resized to the specified size.

Template Parameters
RNGType of random number geneation engine
Parameters
xVector into which to write the permutation
nSize of permutation to create
rngRandom-number generator.

Definition at line 173 of file chains.hpp.

◆ permute()

template<typename T >
void stan::mcmc::permute ( const std::vector< size_t > &  pi,
const std::vector< T > &  x_from,
std::vector< T > &  x_to 
)

Write the specified permutation of the first vector into the second vector.

The second vector will be resized to the size of the permutation.

Template Parameters
TType of elements to permute
Parameters
piPermutation.
x_fromVector of elements to permute
x_toVector into which permutation of elements is written
Exceptions
std::invalid_argumentIf the permutation vector and source vector from which to copy are not the same size.

Definition at line 203 of file chains.hpp.

◆ read_variables()

void stan::mcmc::read_variables ( const std::string  filename,
const size_t  skip,
std::vector< std::string > &  names,
std::vector< std::vector< size_t > > &  dimss 
)

Reads variable names and dims from a csv output file.

Parameters
[in]filenameName of a csv output file.
[in]skipNumber of variables to skip
[out]namesNames of the variables
[out]dimssDimensions of the variables

Definition at line 1759 of file chains.hpp.

◆ rescaled_leapfrog()

double stan::mcmc::rescaled_leapfrog ( stan::model::prob_grad model,
std::vector< int >  z,
const std::vector< double > &  step_sizes,
std::vector< double > &  x,
std::vector< double > &  m,
std::vector< double > &  g,
double  epsilon,
std::ostream *  error_msgs = 0,
std::ostream *  output_msgs = 0 
)

Definition at line 79 of file util.hpp.

◆ sample_unnorm_log()

int stan::mcmc::sample_unnorm_log ( std::vector< double >  probs,
boost::uniform_01< boost::mt19937 & > &  rand_uniform_01 
)

Definition at line 103 of file util.hpp.

◆ test_match_return_names()

const std::vector<std::string>& stan::mcmc::test_match_return_names ( const std::vector< std::string > &  names,
const std::vector< std::vector< size_t > > &  dimss 
)

Definition at line 38 of file chains.hpp.

◆ validate_dims_idxs()

void stan::mcmc::validate_dims_idxs ( const std::vector< size_t > &  dims,
const std::vector< size_t > &  idxs 
)

Validate the specified indexes with respect to the specified dimensions.

Parameters
dimsDimensions of array.
idxsIndexes into array.
Exceptions
std::invalid_argumentIf the two arrays are different sizes.
std::out_of_rangeIf any of the indexes is greater than or equal to its correpsonding dimension.

Definition at line 70 of file chains.hpp.

◆ validate_prob()

void stan::mcmc::validate_prob ( double  p)

Definition at line 49 of file chains.hpp.

◆ write_error_msgs()

void stan::mcmc::write_error_msgs ( std::ostream *  error_msgs,
const std::domain_error &  e 
)

Definition at line 19 of file util.hpp.


     [ Stan Home Page ] © 2011–2012, Stan Development Team.