1 #ifndef STAN_MCMC_HMC_BASE_HMC_HPP
2 #define STAN_MCMC_HMC_BASE_HMC_HPP
7 #include <boost/math/special_functions/fpclassify.hpp>
8 #include <boost/random/variate_generator.hpp>
9 #include <boost/random/uniform_01.hpp>
19 template <
class Model,
20 template<
class,
class>
class Hamiltonian,
21 template<
class>
class Integrator,
27 z_(model.num_params_r()),
38 std::stringstream nominal_stepsize;
40 writer(nominal_stepsize.str());
41 z_.write_metric(writer);
45 std::vector<std::string>& names) {
46 z_.get_param_names(model_names, names);
50 z_.get_params(values);
53 void seed(
const Eigen::VectorXd& q) {
80 info_writer, error_writer);
83 if (boost::math::isnan(h))
84 h = std::numeric_limits<double>::infinity();
86 double delta_H = H0 - h;
88 int direction = delta_H > std::log(0.8) ? 1 : -1;
91 this->
z_.ps_point::operator=(z_init);
100 info_writer, error_writer);
103 if (boost::math::isnan(h))
104 h = std::numeric_limits<double>::infinity();
106 double delta_H = H0 - h;
108 if ((direction == 1) && !(delta_H > std::log(0.8)))
110 else if ((direction == -1) && !(delta_H < std::log(0.8)))
119 throw std::runtime_error(
"Posterior is improper. "
120 "Please check your model.");
122 throw std::runtime_error(
"No acceptably small step size could "
123 "be found. Perhaps the posterior is "
127 this->
z_.ps_point::operator=(z_init);
130 typename Hamiltonian<Model, BaseRNG>::PointType&
z() {
164 typename Hamiltonian<Model, BaseRNG>::PointType
z_;
Hamiltonian< Model, BaseRNG >::PointType z_
void get_sampler_diagnostics(std::vector< double > &values)
void init_hamiltonian(interface_callbacks::writer::base_writer &info_writer, interface_callbacks::writer::base_writer &error_writer)
Probability, optimization and sampling library.
virtual void set_nominal_stepsize(double e)
Point in a generic phase space.
void get_sampler_diagnostic_names(std::vector< std::string > &model_names, std::vector< std::string > &names)
virtual void set_stepsize_jitter(double j)
base_writer is an abstract base class defining the interface for Stan writer callbacks.
double get_current_stepsize()
void seed(const Eigen::VectorXd &q)
base_hmc(const Model &model, BaseRNG &rng)
double get_stepsize_jitter()
double get_nominal_stepsize()
boost::uniform_01< BaseRNG & > rand_uniform_
Hamiltonian< Model, BaseRNG >::PointType & z()
Hamiltonian< Model, BaseRNG > hamiltonian_
Integrator< Hamiltonian< Model, BaseRNG > > integrator_
void init_stepsize(interface_callbacks::writer::base_writer &info_writer, interface_callbacks::writer::base_writer &error_writer)
void write_sampler_state(interface_callbacks::writer::base_writer &writer)