1 #ifndef __STAN__MCMC__ADAPTIVE_HMC_H__
2 #define __STAN__MCMC__ADAPTIVE_HMC_H__
9 #include <boost/random/mersenne_twister.hpp>
10 #include <boost/random/normal_distribution.hpp>
11 #include <boost/random/uniform_01.hpp>
12 #include <boost/random/variate_generator.hpp>
40 template <
class BaseRNG = boost::mt19937>
80 double epsilon_pm = 0.0,
81 bool epsilon_adapt =
true,
84 BaseRNG rand_int = BaseRNG(std::time(0)),
85 const std::vector<double>* params_r = 0,
86 const std::vector<int>* params_i = 0)
126 for (
size_t i = 0; i < m.size(); ++i)
130 std::vector<double> g_new(this->
_g);
131 std::vector<double> x_new(this->
_x);
132 double logp_new = -1e100;
138 double range = high - low;
142 for (
unsigned int l = 0; l < _L; ++l)
148 double dH = H_new - H;
152 this->
_logp = logp_new;
157 if (adapt_stat != adapt_stat)
160 double adapt_g = adapt_stat - this->
_delta;
161 std::vector<double> gvec(1, -adapt_g);
162 std::vector<double> result;
166 std::vector<double> result;
169 double avg_eta = 1.0 / this->
n_steps();
188 names.push_back(
"stepsize__");
void update(const std::vector< double > &g, std::vector< double > &xk)
Produces the next iterate xk given the current gradient g.
void xbar(std::vector< double > &xbar)
Get the exponentially weighted moving average of all previous iterates.
Adaptive Hamiltonian Monte Carlo (HMC) sampler.
adaptive_hmc(stan::model::prob_grad &model, int L, double epsilon=-1, double epsilon_pm=0.0, bool epsilon_adapt=true, double delta=0.651, double gamma=0.05, BaseRNG rand_int=BaseRNG(std::time(0)), const std::vector< double > *params_r=0, const std::vector< int > *params_i=0)
Construct an adaptive Hamiltonian Monte Carlo (HMC) sampler for the specified model,...
virtual void get_sampler_param_names(std::vector< std::string > &names)
Get any sampler-specific parameter namess.
virtual void write_sampler_param_names(std::ostream &o)
Write out any sampler-specific parameter names for output.
~adaptive_hmc()
Destructor.
virtual void write_sampler_params(std::ostream &o)
Write out any sampler-specific parameters for output.
virtual sample next_impl()
Returns the next sample.
virtual void get_sampler_params(std::vector< double > &values)
Get any sampler-specific parameters.
std::ostream * _output_msgs
bool adapting()
Return whether or not parameter adaptation is on.
int n_steps()
Return the number of iterations for this sampler.
void update_mean_stat(double avg_eta, double adapt_stat)
Updates the mean statistic given the specified adaptation statistic and weighting.
std::ostream * _error_msgs
void nfevals_plus_eq(int n)
Add the specified number of evaluations to the number of function evaluations.
boost::uniform_01< boost::mt19937 & > _rand_uniform_01
stan::model::prob_grad & _model
void adaptation_init(double epsilon_scale)
boost::variate_generator< boost::mt19937 &, boost::normal_distribution<> > _rand_unit_norm
Representation of a MCMC sample.
The prob_grad class represents densities with fixed numbers of discrete and scalar parameters and the...
virtual size_t num_params_r()
var exp(const var &a)
Return the exponentiation of the specified variable (cmath).
double epsilon()
Return minimum positive number representable.
int min(const std::vector< int > &x)
Returns the minimum coefficient in the specified column vector.
double dot_self(const Eigen::Matrix< double, R, C > &v)
Returns the dot product of the specified vector with itself.
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.
Probability, optimization and sampling library.