ssmkit  master-68aed98
markov.hpp
Go to the documentation of this file.
1 
7 #ifndef SSMPACK_PROCESS_MARKOV_HPP
8 #define SSMPACK_PROCESS_MARKOV_HPP
9 
12 
13 #include <algorithm>
14 #include <cmath>
15 #include <type_traits>
16 #include <vector>
17 
18 namespace ssmkit {
19 namespace process {
20 
27 template <typename TPDF, typename TParamMap, typename TInitialPDF>
28 class Markov
29  : public BaseProcess<Markov<TPDF, TParamMap, TInitialPDF>> {
30  public:
31 
50  : cpdf_(std::move(cpdf)), init_pdf_(std::move(init_pdf)) {}
51 
61  auto initialize() -> decltype(std::declval<TPDF>().random()) {
62  state_ = init_pdf_.random();
63  return state_;
64  }
65 
75  template <typename... Args>
76  auto random(const Args &... args) -> decltype(std::declval<TPDF>().random()) {
77  state_ = cpdf_.random(state_, args...);
78  return state_; // why not returning reference?
79  }
80 
90  template <typename... Args>
91  double likelihood(const decltype(std::declval<TPDF>().random()) &rv,
92  const Args &... args) {
93  return cpdf_.likelihood(rv, state_, args...);
94  }
95 
98  cpdf_;}
99 
101  TInitialPDF & getInitialPDF() {return init_pdf_;}
102 
103  private:
107  TInitialPDF init_pdf_;
109  decltype(std::declval<TPDF>().random()) state_;
110 };
111 
121 template <typename TPDF, typename TParamMap, typename TInitialPDF>
122 Markov<TPDF, TParamMap, TInitialPDF>
123 makeMarkov(distribution::Conditional<TPDF, TParamMap> cpdf,
124  TInitialPDF init_pdf) {
126  cpdf, init_pdf);
127 }
128 
129 } // namespace process
130 } // namespace ssmkit
131 
132 #endif // SSMPACK_PROCESS_MARKOV_HPP
distribution::Conditional< TPDF, TParamMap > & getCPDF()
Returns a reference to internal CPDF.
Definition: markov.hpp:97
TInitialPDF & getInitialPDF()
Returns a reference to initial PDF.
Definition: markov.hpp:101
double likelihood(const decltype(std::declval< TPDF >().random())&rv, const Args &...args)
Calculate likelihood.
Definition: markov.hpp:91
Conditional distribution function.
Definition: conditional.hpp:34
auto random(const Args &...args) -> decltype(std::declval< TPDF >().random())
Sample from process.
Definition: markov.hpp:76
A first-order Markov process.
Definition: markov.hpp:28
Markov(distribution::Conditional< TPDF, TParamMap > cpdf, TInitialPDF init_pdf)
Constructor.
Definition: markov.hpp:49
auto initialize() -> decltype(std::declval< TPDF >().random())
initialize process
Definition: markov.hpp:61
Markov< TPDF, TParamMap, TInitialPDF > makeMarkov(distribution::Conditional< TPDF, TParamMap > cpdf, TInitialPDF init_pdf)
Convenient builder for Markov process.
Definition: markov.hpp:123