KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sample_real.h
Go to the documentation of this file.
1 /* $Id: sample_real.h 17393 2014-08-23 20:19:14Z predoehl $ */
2 /* =========================================================================== *
3  |
4  | Copyright (c) 1994-2010 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Ernesto Brau
18  * =========================================================================== */
19 
20 #ifndef SAMPLE_REAL_H_INCLUDED
21 #define SAMPLE_REAL_H_INCLUDED
22 
23 #include "sample_cpp/sample_step.h"
25 #include "l/l_sys_lib.h"
26 
31 template<class Model>
32 inline
33 double get_real_model_parameter(const Model& m, int i)
34 {
35  using namespace kjb_c;
36  ASSERT(i == 0);
37  return m;
38 }
39 
44 template<class Model>
45 inline
46 void set_real_model_parameter(Model& m, int i, double x)
47 {
48  using namespace kjb_c;
49  ASSERT(i == 0);
50  m = x;
51 }
52 
58 template<class Model>
59 inline
60 void move_real_model_parameter(Model& m, int i, double x)
61 {
62  Move_model_parameter_as_plus<Model> mmpap(set_real_model_parameter<Model>,
63  get_real_model_parameter<Model>);
64  mmpap(m, i, x);
65 }
66 
67 
72 template<class Model>
73 inline
74 int get_real_model_dimension(const Model& /*m*/)
75 {
76  return 1;
77 }
78 
84 template<typename Model>
86 {
87 public:
89 
92 
102  (
103  const Target_distribution& log_target,
104  const Get_neighborhood& get_neighborhood
105  ) :
106  Parent
107  (
108  log_target,
109  move_real_model_parameter<Model>,
110  get_neighborhood,
111  get_real_model_dimension<Model>
112  )
113  {}
122  (
123  const Target_distribution& log_target,
124  double neighborhood
125  ) :
126  Parent
127  (
128  log_target,
129  move_real_model_parameter<Model>,
131  get_real_model_dimension<Model>
132  )
133  {}
134 };
135 
146 template<typename Model,
147  bool CONSTRAINED_TARGET = false,
148  bool INCLUDE_ACCEPT_STEP = true,
149  bool REVERSIBLE = true>
150 class Real_hmc_step : public Basic_hmc_step<Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE>
151 {
152 public:
154 
156  typedef typename Parent::Gradient Gradient;
160 
177  (
178  const Target_distribution& log_target,
179  int num_dynamics_steps,
180  const Gradient& gradient,
181  const Get_step_size& get_step_size,
182  double alpha = 0.0
183  ) :
184  Parent(log_target,
185  num_dynamics_steps,
186  gradient,
187  move_real_model_parameter<Model>,
188  get_step_size,
189  get_real_model_dimension<Model>,
190  alpha)
191  {}
192 
208  (
209  const Target_distribution& log_target,
210  int num_dynamics_steps,
211  const Gradient& gradient,
212  double step_size,
213  double alpha = 0.0
214  ) :
215  Parent(log_target,
216  num_dynamics_steps,
217  gradient,
218  move_real_model_parameter<Model>,
220  get_real_model_dimension<Model>,
221  alpha)
222  {}
223 
239  (
240  const Target_distribution& log_target,
241  int num_dynamics_steps,
242  const Gradient& gradient,
243  double step_size,
244  double lower_bound,
245  double upper_bound,
246  double alpha = 0.0
247  ) :
248  Parent(log_target,
249  num_dynamics_steps,
250  gradient,
251  move_real_model_parameter<Model>,
253  get_real_model_dimension<Model>,
254  get_real_model_parameter<Model>,
257  alpha)
258  {}
259 
260  virtual ~Real_hmc_step()
261  {}
262 };
263 
274 template<class Model, bool REVERSIBLE = true>
276 {
278 };
279 
280 #endif /*SAMPLE_REAL_H_INCLUDED */
281 
Parent::Target_distribution Target_distribution
Definition: sample_real.h:90
Parent::Get_lower_bounds Get_lower_bounds
Definition: sample_step.h:1076
Real_hmc_step< Model, false, REVERSIBLE > Type
Definition: sample_real.h:277
Approximates the gradient of a target distribution, evaluated at a certain location. The model in question must be a vector model.
Definition: sample_real.h:85
int get_real_model_dimension(const Model &)
Dimension for any model that implements the size() member function.
Definition: sample_real.h:74
Parent::Get_upper_bounds Get_upper_bounds
Definition: sample_step.h:1077
Parent::Gradient Gradient
Definition: sample_real.h:156
Definition: sample_step.h:1062
Real_numerical_gradient(const Target_distribution &log_target, const Get_neighborhood &get_neighborhood)
Construct this functor.
Definition: sample_real.h:102
#define ASSERT(condition, message)
Definition: Assert.h:45
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
void set_real_model_parameter(Model &m, int i, double x)
Parameter setter for anything that implements operator[].
Definition: sample_real.h:46
Parent::Target_distribution Target_distribution
Definition: sample_real.h:155
double get_real_model_parameter(const Model &m, int i)
Parameter getter for anything that implements operator[].
Definition: sample_real.h:33
Parent::Get_step_size Get_step_size
Definition: sample_step.h:1071
Parent::Get_lower_bounds Get_lower_bounds
Definition: sample_real.h:158
Parent::Get_neighborhood Get_neighborhood
Definition: sample_real.h:91
Model_parameter_evaluator< Model >::Type Get_neighborhood
Definition: sample_default.h:104
Default move function; uses '+'.
Definition: sample_default.h:37
x
Definition: APPgetLargeConnectedEdges.m:100
Model_evaluator< Model >::Type Target_distribution
Definition: sample_default.h:102
Definition: sample_real.h:275
Definition: sample_real.h:150
Returns the same result no matter what model is received.
Definition: sample_default.h:68
virtual ~Real_hmc_step()
Definition: sample_real.h:260
Numerical_gradient< Model > Parent
Definition: sample_real.h:88
Parent::Gradient Gradient
Definition: sample_step.h:1069
void move_real_model_parameter(Model &m, int i, double x)
Parameter mover for anything that implements operator[] and whose elements are double.
Definition: sample_real.h:60
Real_hmc_step(const Target_distribution &log_target, int num_dynamics_steps, const Gradient &gradient, const Get_step_size &get_step_size, double alpha=0.0)
Creates a Real_hmc_step.
Definition: sample_real.h:177
Parent::Target_distribution Target_distribution
Definition: sample_step.h:1068
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
for m
Definition: APPgetLargeConnectedEdges.m:64
Basic_hmc_step< Model, CONSTRAINED_TARGET, INCLUDE_ACCEPT_STEP, REVERSIBLE > Parent
Definition: sample_real.h:153
Parent::Get_step_size Get_step_size
Definition: sample_real.h:157
Parent::Get_upper_bounds Get_upper_bounds
Definition: sample_real.h:159
Approximates the gradient and/or curvature of a target distribution, evaluated at a certain location...
Definition: sample_default.h:99