KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE > Class Template Reference

#include <sample_step.h>

Inheritance diagram for Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >:
Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE > Real_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >

Public Types

typedef Abstract_hmc_step
< Model, CONSTRAINED_TARGET,
INCLUDE_ACCEPT_STEP,
REVERSIBLE > 
Parent
 
typedef Parent::Target_distribution Target_distribution
 
typedef Parent::Gradient Gradient
 
typedef Parent::Move_parameter Move_parameter
 
typedef Parent::Get_step_size Get_step_size
 
typedef Parent::Get_dimension Get_dimension
 
typedef Parent::Get_parameter Get_parameter
 
typedef Parent::Get_lower_bounds Get_lower_bounds
 
typedef Parent::Get_upper_bounds Get_upper_bounds
 
- Public Types inherited from Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >
typedef Model_evaluator< Model >
::Type 
Target_distribution
 
typedef
Model_parameter_evaluator
< Model >::Type 
Gradient
 
typedef Move_model_parameter
< Model >::Type 
Move_parameter
 
typedef
Model_parameter_evaluator
< Model >::Type 
Get_step_size
 
typedef Model_dimension< Model >
::Type 
Get_dimension
 
typedef Get_model_parameter
< Model >::Type 
Get_parameter
 
typedef
Model_parameter_evaluator
< Model >::Type 
Get_lower_bounds
 
typedef
Model_parameter_evaluator
< Model >::Type 
Get_upper_bounds
 

Public Member Functions

 Basic_hmc_step (const Target_distribution &log_target, int num_dynamics_steps, const Gradient &gradient, const Move_parameter &move_parameter, const Get_step_size &get_step_size, const Get_dimension &get_dimension, double alpha=0.0)
 Creates a Basic_hmc_step by initializing target and proposer functors (or functions) to the given arguments. More...
 
 Basic_hmc_step (const Target_distribution &log_target, int num_dynamics_steps, const Gradient &gradient, const Move_parameter &move_parameter, const Get_step_size &get_step_size, const Get_dimension &get_dimension, const Get_parameter &get_parameter, const Get_lower_bounds &get_lower_bounds, const Get_upper_bounds &get_upper_bounds, double alpha=0.0)
 
void record_extra (bool enable)
 
void set_post_move_callback (const boost::function2< void, Model &, kjb::Vector & > &f)
 Copy-constructor. More...
 
virtual ~Basic_hmc_step ()
 
virtual const Target_distributionget_log_target () const
 Returns a reference to the target distribution. Returned object must comply with the ModelEvaluator concept. More...
 
virtual const Gradientget_gradient () const
 Returns a reference to the mechanism to compute the gradient of the target distribution. More...
 
virtual const Move_parameterget_move_parameter () const
 Returns a reference to the parameter-changing mechanism. Must comply with the ChangeParameter concept. More...
 
virtual const Get_step_sizeget_step_size_function () const
 Returns a reference to the mechanism for choosing the neighborhoods for each parameters. More...
 
virtual const Get_dimensionget_dimension_function () const
 Returns a reference to the mechanism for computing the dimension of the model. More...
 
virtual bool record_extra () const
 if true is returned, the step log will contain metadata about the step More...
 
virtual const Get_parameterget_parameter_function () const
 Returns a reference to the mechanism for getting the value of a dimension of the model. More...
 
virtual const Get_lower_boundsget_lower_bounds_function () const
 Returns a reference to the mechanism for getting the lower bounds of a function. More...
 
virtual const Get_upper_boundsget_upper_bounds_function () const
 Returns a reference to the mechanism for getting the upper bounds of a function. More...
 
virtual void post_move_callback (Model &q, kjb::Vector &p) const
 
- Public Member Functions inherited from Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >
 BOOST_CONCEPT_ASSERT ((BaseModel< Model >))
 
 Abstract_hmc_step (int num_dynamics_steps, double alpha)
 
bool is_first_p_full (const bool alpha, const bool accept_step, const bool reversible)
 
bool is_last_p_ignored (const bool alpha, const bool accept_step, const bool reversible)
 
 Abstract_hmc_step (const Abstract_hmc_step &ahs)
 
virtual Step_log< Model > operator() (Model &q, double lt_q) const
 Runs a step of Hybrid Monte-Carlo (HMC) on a model m. More...
 
void set_temperature (const double T)
 
virtual ~Abstract_hmc_step ()
 

Protected Attributes

Target_distribution m_log_target
 
Gradient m_gradient
 
Move_parameter m_move_parameter
 
Get_step_size m_get_step_size
 
Get_dimension m_get_dimension
 
bool m_record_extra
 
Get_parameter m_get_parameter
 
Get_lower_bounds m_get_lower_bounds
 
Get_upper_bounds m_get_upper_bounds
 
boost::function2< void, Model
&, kjb::Vector & > 
m_post_move_callback
 
- Protected Attributes inherited from Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >
const int m_num_dynamics_steps
 The number of leapfrog steps in the trajectory, "choosing a suitable trajectory length is crucial if HMC is to explore the stae space systematically, rather than by a random walk". "For a problem thought to be airly difficult, a trajectory with m_length = 100 might be a suitable starting point. More...
 
double m_alpha
 Amount of stochastic update to apply to momentum. Set to zero for strict HMC. More...
 
kjb::Vector p
 Momentum. More...
 
bool m_first_p_full
 Optimization constants. Set to false for true MCMC. More...
 
bool m_last_p_ignore
 
double m_temperature
 

Detailed Description

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
class Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >

Template Parameters
ModelThe model type. Must comply with HmcModel concept.
accept_stepDo a accept/reject step? This is true by default, which, if alpha = 0, makes this a true HMC step.

Basic_hmc_step is a functor that runs a single step of the generalized Hybrid Monte Carlo algorithm on a model.

This class is a subclass of the abstract class Abstract_hmc_step. It implements the get_* member functions from the abstract class in the obvious way: it returns references to private members of the correct types. These members are initialized from references received in the constructor.

Member Typedef Documentation

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Parent::Get_dimension Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Get_dimension
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Parent::Get_lower_bounds Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Get_lower_bounds
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Parent::Get_parameter Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Get_parameter
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Parent::Get_step_size Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Get_step_size
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Parent::Get_upper_bounds Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Get_upper_bounds
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Parent::Gradient Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Gradient
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Parent::Move_parameter Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Move_parameter
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Abstract_hmc_step<Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE> Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Parent
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
typedef Parent::Target_distribution Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Target_distribution

Constructor & Destructor Documentation

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Basic_hmc_step ( const Target_distribution log_target,
int  num_dynamics_steps,
const Gradient gradient,
const Move_parameter move_parameter,
const Get_step_size get_step_size,
const Get_dimension get_dimension,
double  alpha = 0.0 
)
inline

Creates a Basic_hmc_step by initializing target and proposer functors (or functions) to the given arguments.

Parameters
log_targetTarget_distribution object used to initialize internal target distribution used in operator().
num_dynamics_stepsNumber of dynamics steps to take before accepting/rejecting.
gradientMechanism to compute the gradient of the (log) target distribution.
move_parameterMechanism to change a parameter of the of the model by a certain amount.
get_step_sizeMechanism to get the etas; that is the sizes of the neighborhood used to compute the gradients.
get_dimensionMechanism to obtain the dimension of the model.
alphaParameter which controls how much randomness there is in the update of the momentum.
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::Basic_hmc_step ( const Target_distribution log_target,
int  num_dynamics_steps,
const Gradient gradient,
const Move_parameter move_parameter,
const Get_step_size get_step_size,
const Get_dimension get_dimension,
const Get_parameter get_parameter,
const Get_lower_bounds get_lower_bounds,
const Get_upper_bounds get_upper_bounds,
double  alpha = 0.0 
)
inline
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::~Basic_hmc_step ( )
inlinevirtual

Member Function Documentation

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual const Get_dimension& Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::get_dimension_function ( ) const
inlinevirtual

Returns a reference to the mechanism for computing the dimension of the model.

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual const Gradient& Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::get_gradient ( ) const
inlinevirtual

Returns a reference to the mechanism to compute the gradient of the target distribution.

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual const Target_distribution& Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::get_log_target ( ) const
inlinevirtual

Returns a reference to the target distribution. Returned object must comply with the ModelEvaluator concept.

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual const Get_lower_bounds& Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::get_lower_bounds_function ( ) const
inlinevirtual

Returns a reference to the mechanism for getting the lower bounds of a function.

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual const Move_parameter& Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::get_move_parameter ( ) const
inlinevirtual

Returns a reference to the parameter-changing mechanism. Must comply with the ChangeParameter concept.

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual const Get_parameter& Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::get_parameter_function ( ) const
inlinevirtual

Returns a reference to the mechanism for getting the value of a dimension of the model.

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual const Get_step_size& Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::get_step_size_function ( ) const
inlinevirtual

Returns a reference to the mechanism for choosing the neighborhoods for each parameters.

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual const Get_upper_bounds& Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::get_upper_bounds_function ( ) const
inlinevirtual

Returns a reference to the mechanism for getting the upper bounds of a function.

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual void Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::post_move_callback ( Model &  ,
kjb::Vector  
) const
inlinevirtual

Callback that occurs every time the model state is updated during leapfrom simulation of dynamics. This is useful to apply constraints to the model and/or momentum after they've been perturbed

Reimplemented from Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
void Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::record_extra ( bool  enable)
inline

Enable/disable recording of extra metadata in Step_log

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
virtual bool Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::record_extra ( ) const
inlinevirtual

if true is returned, the step log will contain metadata about the step

Implements Abstract_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >.

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
void Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::set_post_move_callback ( const boost::function2< void, Model &, kjb::Vector & > &  f)
inline

Copy-constructor.

Assignment

Member Data Documentation

template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Get_dimension Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_get_dimension
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Get_lower_bounds Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_get_lower_bounds
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Get_parameter Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_get_parameter
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Get_step_size Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_get_step_size
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Get_upper_bounds Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_get_upper_bounds
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Gradient Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_gradient
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Target_distribution Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_log_target
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
Move_parameter Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_move_parameter
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
boost::function2<void, Model&, kjb::Vector&> Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_post_move_callback
protected
template<typename Model, bool CONSTRAINED_TARGET = false, bool INCLUDE_ACCEPT_STEP = true, bool REVERSIBLE = true>
bool Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE >::m_record_extra
protected

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