ps_point.hpp
Go to the documentation of this file.
1 #ifndef STAN_MCMC_HMC_HAMILTONIANS_PS_POINT_HPP
2 #define STAN_MCMC_HMC_HAMILTONIANS_PS_POINT_HPP
3 
6 #include <boost/lexical_cast.hpp>
7 #include <Eigen/Dense>
8 #include <string>
9 #include <vector>
10 
11 namespace stan {
12  namespace mcmc {
13  using Eigen::Dynamic;
14 
15  /**
16  * Point in a generic phase space
17  */
18  class ps_point {
19  friend class ps_point_test;
20 
21  public:
22  explicit ps_point(int n)
23  : q(n), p(n), V(0), g(n) {}
24 
26  : q(z.q.size()), p(z.p.size()), V(z.V), g(z.g.size()) {
27  fast_vector_copy_<double>(q, z.q);
28  fast_vector_copy_<double>(p, z.p);
29  fast_vector_copy_<double>(g, z.g);
30  }
31 
33  if (this == &z)
34  return *this;
35 
36  fast_vector_copy_<double>(q, z.q);
37 
38  V = z.V;
39 
40  fast_vector_copy_<double>(p, z.p);
41  fast_vector_copy_<double>(g, z.g);
42 
43  return *this;
44  }
45 
46  Eigen::VectorXd q;
47  Eigen::VectorXd p;
48 
49  double V;
50  Eigen::VectorXd g;
51 
52  virtual void get_param_names(std::vector<std::string>& model_names,
53  std::vector<std::string>& names) {
54  for (int i = 0; i < q.size(); ++i)
55  names.push_back(model_names.at(i));
56  for (int i = 0; i < q.size(); ++i)
57  names.push_back(std::string("p_") + model_names.at(i));
58  for (int i = 0; i < q.size(); ++i)
59  names.push_back(std::string("g_") + model_names.at(i));
60  }
61 
62  virtual void get_params(std::vector<double>& values) {
63  for (int i = 0; i < q.size(); ++i)
64  values.push_back(q(i));
65  for (int i = 0; i < q.size(); ++i)
66  values.push_back(p(i));
67  for (int i = 0; i < q.size(); ++i)
68  values.push_back(g(i));
69  }
70 
71  /**
72  * Writes the metric
73  *
74  * @param writer writer callback
75  */
76  virtual inline void
78 
79  protected:
80  template <typename T>
81  static inline void
82  fast_vector_copy_(Eigen::Matrix<T, Dynamic, 1>& v_to,
83  const Eigen::Matrix<T, Dynamic, 1>& v_from) {
84  int sz = v_from.size();
85  v_to.resize(sz);
86  if (sz > 0)
87  std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
88  }
89 
90  template <typename T>
91  static inline void
92  fast_matrix_copy_(Eigen::Matrix<T, Dynamic, Dynamic>& v_to,
93  const Eigen::Matrix<T, Dynamic, Dynamic>& v_from) {
94  int nr = v_from.rows();
95  int nc = v_from.cols();
96  v_to.resize(nr, nc);
97  if (nr > 0 && nc > 0)
98  std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
99  }
100  };
101 
102  } // mcmc
103 } // stan
104 #endif
virtual void get_params(std::vector< double > &values)
Definition: ps_point.hpp:62
ps_point & operator=(const ps_point &z)
Definition: ps_point.hpp:32
const char * p
Definition: xmltok.h:285
virtual void get_param_names(std::vector< std::string > &model_names, std::vector< std::string > &names)
Definition: ps_point.hpp:52
Eigen::VectorXd q
Definition: ps_point.hpp:46
Eigen::VectorXd p
Definition: ps_point.hpp:47
z
Definition: test.py:28
Eigen::VectorXd g
Definition: ps_point.hpp:50
ps_point(const ps_point &z)
Definition: ps_point.hpp:25
enum BeamMode nc
static void fast_matrix_copy_(Eigen::Matrix< T, Dynamic, Dynamic > &v_to, const Eigen::Matrix< T, Dynamic, Dynamic > &v_from)
Definition: ps_point.hpp:92
static void fast_vector_copy_(Eigen::Matrix< T, Dynamic, 1 > &v_to, const Eigen::Matrix< T, Dynamic, 1 > &v_from)
Definition: ps_point.hpp:82
virtual void write_metric(stan::callbacks::writer &writer)
Definition: ps_point.hpp:77
enum BeamMode string