![]() |
Stan
1.0
probability, sampling & optimization
|
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) |
Markov chain Monte Carlo samplers.
| 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.
| [in,out] | chains | The chains object to modify |
| chain | chain number | |
| filename | file name of a csv output file | |
| skip | number of variables to skip |
Definition at line 1788 of file chains.hpp.
| 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.
| dims | Sequence of dimensions. |
| idxs | Sequence of inndexes. |
| std::invalid_argument | If the sizes of the index and dimension sequences is different. |
| std::out_of_range | If one of the indexes is greater than or equal to the corresponding index. |
Definition at line 103 of file chains.hpp.
| 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], ...
| dims | Dimensions of array. |
| idxs | Indexes into array. |
| std::invalid_argument | If the dimensions and indexes are not the same size. |
| std::out_of_range | If an index is greater than or equal to the corresponding dimension. |
Definition at line 151 of file chains.hpp.
| 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.
| [in] | model | Probability model with gradients. |
| [in] | z | Integer parameters. |
| [in] | x | Real parameters |
| [in,out] | m | Momentum. |
| [in,out] | g | Gradient at x, z. |
| [in] | epsilon | Step size used in Hamiltonian dynamics. |
| [in,out] | error_msgs | Output stream for error messages. |
| [in,out] | output_msgs | Output stream for output messages. |
| 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.
| RNG | Type of random number geneation engine |
| x | Vector into which to write the permutation |
| n | Size of permutation to create |
| rng | Random-number generator. |
Definition at line 173 of file chains.hpp.
| 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.
| T | Type of elements to permute |
| pi | Permutation. |
| x_from | Vector of elements to permute |
| x_to | Vector into which permutation of elements is written |
| std::invalid_argument | If the permutation vector and source vector from which to copy are not the same size. |
Definition at line 203 of file chains.hpp.
| 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.
| [in] | filename | Name of a csv output file. |
| [in] | skip | Number of variables to skip |
| [out] | names | Names of the variables |
| [out] | dimss | Dimensions of the variables |
Definition at line 1759 of file chains.hpp.
| 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 |
||
| ) |
| int stan::mcmc::sample_unnorm_log | ( | std::vector< double > | probs, |
| boost::uniform_01< boost::mt19937 & > & | rand_uniform_01 | ||
| ) |
| 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.
| 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.
| dims | Dimensions of array. |
| idxs | Indexes into array. |
| std::invalid_argument | If the two arrays are different sizes. |
| std::out_of_range | If any of the indexes is greater than or equal to its correpsonding dimension. |
Definition at line 70 of file chains.hpp.
| void stan::mcmc::validate_prob | ( | double | p | ) |
Definition at line 49 of file chains.hpp.