Stan  1.0
probability, sampling & optimization
Public Member Functions | List of all members
stan::mcmc::hmc Class Reference

Hamiltonian Monte Carlo (HMC) sampler. More...

#include <hmc.hpp>

Inheritance diagram for stan::mcmc::hmc:
stan::mcmc::adaptive_sampler

Public Member Functions

 hmc (stan::model::prob_grad &model, double epsilon, int L, unsigned int random_seed=static_cast< unsigned int >(std::time(0)))
 Constructs a Hamiltonian Monte Carlo (HMC) sampler for the specified model, using the specified step size and number of leapfrog steps, with the specified random seed for randomization. More...
 
virtual ~hmc ()
 Destructor. More...
 
virtual void set_params (const std::vector< double > &x, const std::vector< int > &z)
 Set the model real and integer parameters to the specified values. More...
 
virtual void set_params_r (const std::vector< double > &x)
 Set the model real parameters to the specified values and update gradients and log probability to match. More...
 
virtual void set_params_i (const std::vector< int > &z)
 Set the model real parameters to the specified values and update gradients and log probability to match. More...
 
virtual sample next_impl ()
 Return the next sample. More...
 
- Public Member Functions inherited from stan::mcmc::adaptive_sampler
 adaptive_sampler (bool adapt, std::ostream *error_msgs=0, std::ostream *output_msgs=0)
 Constructs an adaptive sampler with specified adaptation status. More...
 
virtual ~adaptive_sampler ()
 Destructor. More...
 
void set_error_stream (std::ostream &error_msgs)
 Set the stream into which errors will be written as the sampler runs. More...
 
void unset_error_stream ()
 Unset the stream into which errors are written to 0 so that error messages are ignored. More...
 
void set_output_stream (std::ostream &output_msgs)
 Set the stream into which output will be written as the sampler runs. More...
 
void unset_output_stream ()
 Unset the stream into which errors are written to 0 so that output messages are ignored. More...
 
sample next ()
 Returns the next sample from this sampler. More...
 
virtual void find_reasonable_parameters ()
 Find a reasonable initial setting for the adaptable parameters. More...
 
virtual void get_parameters (std::vector< double > &params)
 Sets the specified parameter vector to the sequence of tunable parameters for this sampler. More...
 
double mean_stat ()
 Returns the value of the statistic we are trying to coerce. More...
 
void set_mean_stat (double v)
 Sets the mean statistic to the specified value. More...
 
void update_mean_stat (double avg_eta, double adapt_stat)
 Updates the mean statistic given the specified adaptation statistic and weighting. More...
 
unsigned int nfevals ()
 Returns the number of times that the (possibly unnormalized) log probability function has been evaluated by this sampler. More...
 
void nfevals_plus_eq (int n)
 Add the specified number of evaluations to the number of function evaluations. More...
 
int n_steps ()
 Return the number of iterations for this sampler. More...
 
int n_adapt_steps ()
 Return how many iterations parameter adaptation has happened for. More...
 
virtual void adapt_on ()
 Turn on parameter adaptation. More...
 
virtual void adapt_off ()
 Turn off parameter adaption. More...
 
bool adapting ()
 Return whether or not parameter adaptation is on. More...
 
virtual void write_sampler_params (std::ostream &o)
 Write out any sampler-specific parameters for output. More...
 
virtual void write_adaptation_params (std::ostream &o)
 Use this method to write the adaptation parameters into the output. More...
 
virtual void write_sampler_param_names (std::ostream &o)
 Write out any sampler-specific parameter names for output. More...
 
virtual void get_sampler_param_names (std::vector< std::string > &names)
 Get any sampler-specific parameter namess. More...
 
virtual void get_sampler_params (std::vector< double > &values)
 Get any sampler-specific parameters. More...
 

Additional Inherited Members

- Protected Attributes inherited from stan::mcmc::adaptive_sampler
bool _adapt
 
unsigned int _n_steps
 
int _n_adapt_steps
 
unsigned int _nfevals
 
double _mean_stat
 
std::ostream * _error_msgs
 
std::ostream * _output_msgs
 

Detailed Description

Hamiltonian Monte Carlo (HMC) sampler.

The HMC sampler requires a probability model with the ability to compute gradients, characterized as an instance of prob_grad.

Samples from the sampler are returned through the base class sampler.

Definition at line 34 of file hmc.hpp.

Constructor & Destructor Documentation

◆ hmc()

stan::mcmc::hmc::hmc ( stan::model::prob_grad model,
double  epsilon,
int  L,
unsigned int  random_seed = static_cast<unsigned int>(std::time(0)) 
)
inline

Constructs a Hamiltonian Monte Carlo (HMC) sampler for the specified model, using the specified step size and number of leapfrog steps, with the specified random seed for randomization.

If the same seed is used twice, the series of samples should be the same. This property is most helpful for testing. If no random seed is specified, the std::time(0) function is called from the ctime library.

Parameters
modelProbability model with gradients.
epsilonHamiltonian dynamics simulation step size.
LNumber of leapfrog steps per simulation.
random_seedSeed for random number generator; optional, if not specified, generate new seed based on system time.

Definition at line 68 of file hmc.hpp.

◆ ~hmc()

virtual stan::mcmc::hmc::~hmc ( )
inlinevirtual

Destructor.

The implementation for this class is a no-op.

Definition at line 95 of file hmc.hpp.

Member Function Documentation

◆ next_impl()

virtual sample stan::mcmc::hmc::next_impl ( )
inlinevirtual

Return the next sample.

Returns
The next sample.

Implements stan::mcmc::adaptive_sampler.

Definition at line 159 of file hmc.hpp.

◆ set_params()

virtual void stan::mcmc::hmc::set_params ( const std::vector< double > &  x,
const std::vector< int > &  z 
)
inlinevirtual

Set the model real and integer parameters to the specified values.


This method will typically be used to set the parameters by the client of this class after initialization.

Parameters
xReal parameters.
zInteger parameters.
Exceptions
std::invalid_argumentif x or z do not match size of parameters specified by the model.

Implements stan::mcmc::adaptive_sampler.

Definition at line 110 of file hmc.hpp.

◆ set_params_i()

virtual void stan::mcmc::hmc::set_params_i ( const std::vector< int > &  z)
inlinevirtual

Set the model real parameters to the specified values and update gradients and log probability to match.

This method will typically be used to set the parameters by the client of this class after initialization.

Parameters
zInteger parameters.
Exceptions
std::invalid_argumentif the number of integer parameters does not match the number of parameters defined by the model.

Definition at line 147 of file hmc.hpp.

◆ set_params_r()

virtual void stan::mcmc::hmc::set_params_r ( const std::vector< double > &  x)
inlinevirtual

Set the model real parameters to the specified values and update gradients and log probability to match.

This method will typically be used to set the parameters by the client of this class after initialization.

Parameters
xReal parameters.
Exceptions
std::invalid_argumentif the number of real parameters does not match the number of parameters defined by the model.

Definition at line 129 of file hmc.hpp.


The documentation for this class was generated from the following file:

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