Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ps_point.hpp
Go to the documentation of this file.
1 #ifndef STAN__MCMC__PS_POINT__BETA
2 #define STAN__MCMC__PS_POINT__BETA
3 
4 #include <fstream>
5 #include <string>
6 #include <boost/lexical_cast.hpp>
7 
8 #include <vector>
10 
11 namespace stan {
12 
13  namespace mcmc {
14 
15  // Point in a generic phase space
16  class ps_point {
17  friend class ps_point_test;
18 
19  public:
20 
21  ps_point(int n): q(n), p(n), V(0), g(n) {};
22 
23  ps_point(const ps_point& z): q(z.q.size()), p(z.p.size()), V(z.V), g(z.g.size())
24  {
25  fast_vector_copy_<double>(q, z.q);
26  fast_vector_copy_<double>(p, z.p);
27  fast_vector_copy_<double>(g, z.g);
28  }
29 
30 
32  {
33 
34  if(this == &z) 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 
47  Eigen::VectorXd q;
48  Eigen::VectorXd p;
49 
50  double V;
51  Eigen::VectorXd g;
52 
53  virtual void get_param_names(std::vector<std::string>& model_names,
54  std::vector<std::string>& names) {
55  for(int i = 0; i < q.size(); ++i)
56  names.push_back(model_names.at(i));
57  for(int i = 0; i < q.size(); ++i)
58  names.push_back(std::string("p_") + model_names.at(i));
59  for(int i = 0; i < q.size(); ++i)
60  names.push_back(std::string("g_") + model_names.at(i));
61  }
62 
63  virtual void get_params(std::vector<double>& values) {
64  for(int i = 0; i < q.size(); ++i)
65  values.push_back(q(i));
66  for(int i = 0; i < q.size(); ++i)
67  values.push_back(p(i));
68  for(int i = 0; i < q.size(); ++i)
69  values.push_back(g(i));
70  }
71 
72  virtual void write_metric(std::ostream* o) {
73  if(!o) return;
74  *o << "# No free parameters for unit metric" << std::endl;
75  }
76 
77  protected:
78 
79  template <typename T>
80  static inline void fast_vector_copy_(Eigen::Matrix<T, Eigen::Dynamic, 1>& v_to,
81  const Eigen::Matrix<T, Eigen::Dynamic, 1>& v_from) {
82  int sz = v_from.size();
83  v_to.resize(sz);
84  if (sz > 0) std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
85  }
86 
87  template <typename T>
88  static inline void fast_matrix_copy_(Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& v_to,
89  const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& v_from) {
90  int nr = v_from.rows();
91  int nc = v_from.cols();
92  v_to.resize(nr, nc);
93  if (nr > 0 && nc > 0) std::memcpy(&v_to(0), &v_from(0), v_from.size() * sizeof(double));
94  }
95 
96  };
97 
98  } // mcmc
99 
100 } // stan
101 
102 
103 #endif
virtual void get_params(std::vector< double > &values)
Definition: ps_point.hpp:63
ps_point & operator=(const ps_point &z)
Definition: ps_point.hpp:31
static void fast_vector_copy_(Eigen::Matrix< T, Eigen::Dynamic, 1 > &v_to, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v_from)
Definition: ps_point.hpp:80
virtual void write_metric(std::ostream *o)
Definition: ps_point.hpp:72
virtual void get_param_names(std::vector< std::string > &model_names, std::vector< std::string > &names)
Definition: ps_point.hpp:53
Eigen::VectorXd q
Definition: ps_point.hpp:47
Eigen::VectorXd p
Definition: ps_point.hpp:48
static void fast_matrix_copy_(Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &v_to, const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &v_from)
Definition: ps_point.hpp:88
Eigen::VectorXd g
Definition: ps_point.hpp:51
int size(const std::vector< T > &x)
Definition: size.hpp:11
ps_point(const ps_point &z)
Definition: ps_point.hpp:23
friend class ps_point_test
Definition: ps_point.hpp:17

     [ Stan Home Page ] © 2011–2014, Stan Development Team.