KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
abstract_dynamics.h
Go to the documentation of this file.
1 
2 /* $Id: abstract_dynamics.h 10645 2011-09-29 19:51:35Z predoehl $ */
3 
4 /* =========================================================================== *
5 |
6 | Copyright (c) 1994-2008 by Kobus Barnard (author).
7 |
8 | Personal and educational use of this code is granted, provided that this
9 | header is kept intact, and that the authorship is not misrepresented, that
10 | its use is acknowledged in publications, and relevant papers are cited.
11 |
12 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
13 |
14 | Please note that the code in this file has not necessarily been adequately
15 | tested. Naturally, there is no guarantee of performance, support, or fitness
16 | for any particular task. Nonetheless, I am interested in hearing about
17 | problems that you encounter.
18 |
19 | Author: Luca Del Pero
20 * =========================================================================== */
21 
22 #ifndef ABSTRACT_DYNAMICS_INCLUDED
23 #define ABSTRACT_DYNAMICS_INCLUDED
24 
25 #include "m_cpp/m_vector.h"
26 #include "prob_cpp/prob_sample.h"
28 
29 namespace kjb {
30 
37 {
38 public:
48  Abstract_dynamics(double ialpha = 0.99, unsigned int ikick = 0) : mv_gauss(NULL)
49  {
50  if(ialpha <0 || ialpha > 1)
51  {
52  throw kjb::Illegal_argument("Alpha must be between 0 and 1");
53  }
54  alpha = ialpha;
55  st_alpha = sqrt(1 - alpha*alpha);
56  kick = ikick;
57  }
58 
72  (
73  kjb::Vector iparameters,
74  kjb::Vector ideltas,
75  double ialpha = 0.99,
76  unsigned int ikick = 0
77  ) : mv_gauss(NULL)
78  {
79  if(ialpha <0 || ialpha > 1)
80  {
81  throw kjb::Illegal_argument("Alpha must be between 0 and 1");
82  }
83  if(ideltas.size() != iparameters.size())
84  {
85  KJB_THROW_2(Illegal_argument, "The number of delta steps does not match the number of parameters");
86  }
87  alpha = ialpha;
88  st_alpha = sqrt(1 - alpha*alpha);
89  kick = ikick;
90  parameters = iparameters;
91  deltas = ideltas;
92  }
93 
95 
97 
99  {
100  delete mv_gauss;
101  }
102 
105  void set_num_parameters(unsigned int num_params);
106 
107 protected:
108 
116  void run(unsigned int iterations);
117 
118  virtual void compute_energy_gradient() = 0;
119 
120  virtual void log_sample()
121  {
122  return;
123  }
124 
130 
131  /* @brief This vector will contain the gradient of the energy function,
132  * computed at every iteration
133  */
135 
136  /* @brief The following members are used during the sampling, and
137  * are class members for efficiency reasons. */
143 
144  /* @brief This parameter tweaks the contribution of the stochastic transition.
145  * If it is close to one, the random transition has little weight, and the dynamics
146  * mostly follow the momenta. The closer it gets to zero, the more the stochastic
147  * transitions will influence the selected trajectory.*/
148  double alpha;
149  double st_alpha;
150 
151  /* @brief This parameters is used to reset the momenta to the correct trajectory,
152  * thus eliminating the effect of the stochastic transitions. It specifies
153  * after how many transitions the momenta are to be reset. This was not fully tested */
154  unsigned int kick;
155 
156 };
157 
158 }
159 
160 #endif
161 
162 
void set_num_parameters(unsigned int num_params)
Sets the number of parameters we will be sampling over.
Definition: abstract_dynamics.cpp:78
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
Definition of various standard probability distributions.
double alpha
Definition: abstract_dynamics.h:148
virtual ~Abstract_dynamics()
Definition: abstract_dynamics.h:98
kjb::Vector parameters
The parameters to sample over.
Definition: abstract_dynamics.h:126
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
virtual void compute_energy_gradient()=0
unsigned int kick
Definition: abstract_dynamics.h:154
Abstract_dynamics(double ialpha=0.99, unsigned int ikick=0)
Definition: abstract_dynamics.h:48
double st_alpha
Definition: abstract_dynamics.h:149
void run(unsigned int iterations)
Implements stochastic dynamics sampling on a set of parameters. This implementation follows the algor...
Definition: abstract_dynamics.cpp:123
kjb::MV_gaussian_distribution * mv_gauss
Definition: abstract_dynamics.h:142
kjb::Vector temp_momenta
Definition: abstract_dynamics.h:140
kjb::Vector stochastic_momenta
Definition: abstract_dynamics.h:138
Multivariate Gaussian (normal) distribution.
Definition: prob_distribution.h:619
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
kjb::Vector gradients
Definition: abstract_dynamics.h:134
kjb::Vector stochastic_transition
Definition: abstract_dynamics.h:141
virtual void log_sample()
Definition: abstract_dynamics.h:120
Definition: abstract_dynamics.h:36
Sampling functionality for the different distributions defined in "prob_distributions.h".
kjb::Vector deltas
The size of the step to take in the gradient direction. This step size is different for each paramete...
Definition: abstract_dynamics.h:129
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
kjb::Vector momenta
Definition: abstract_dynamics.h:139
Abstract_dynamics & operator=(const Abstract_dynamics &src)
Definition: abstract_dynamics.cpp:51