ssmkit  master-68aed98
conditional.hpp
Go to the documentation of this file.
1 
7 #ifndef SSMPACK_DISTRIBUTION_PARAMETRIC_CONDITIONAL_HPP
8 #define SSMPACK_DISTRIBUTION_PARAMETRIC_CONDITIONAL_HPP
9 
10 #include <algorithm>
11 #include <type_traits>
12 #include <utility>
13 #include <vector>
14 
15 namespace ssmkit {
16 namespace distribution {
17 
33 template <typename TPDF, typename TParamMap>
34 class Conditional {
35  public:
45  Conditional(TPDF pdf, TParamMap map)
46  : pdf_(std::move(pdf)), map_(std::move(map)) {}
52  template <typename... Args>
53  auto random(const Args &... args) -> decltype(std::declval<TPDF>().random()) {
54  pdf_.parameterize(map_(args...));
55  return pdf_.random();
56  }
57 
64  template <typename... Args>
65  double likelihood(const decltype(std::declval<TPDF>().random()) &rv,
66  const Args &... args) {
67  pdf_.parameterize(map_(args...));
68  return pdf_.likelihood(rv);
69  }
70 
72  const TPDF & getPDF() const {return pdf_;}
74  const TParamMap & getParamMap() const {return map_;}
75  private:
77  TPDF pdf_;
79  TParamMap map_;
80 };
81 
91 template <class TPDF, class TParamMap>
93  return Conditional<TPDF, TParamMap>(std::move(pdf),
94  std::move(map));
95 }
96 
97 } // namespace distribution
98 } // namespace ssmkit
99 
100 #endif // SSMPACK_DISTRIBUTION_PARAMETRIC_CONDITIONAL_HPP
Conditional distribution function.
Definition: conditional.hpp:34
const TPDF & getPDF() const
Returns a reference to .
Definition: conditional.hpp:72
auto random(const Args &...args) -> decltype(std::declval< TPDF >().random())
Sample from distribution.
Definition: conditional.hpp:53
Conditional(TPDF pdf, TParamMap map)
Constructors returns a conditional distribution object.
Definition: conditional.hpp:45
Conditional< TPDF, TParamMap > makeConditional(TPDF pdf, TParamMap map)
Convenient builder that returns a conditional distribution object.
Definition: conditional.hpp:92
double likelihood(const decltype(std::declval< TPDF >().random())&rv, const Args &...args)
Calculate the likelihood of a random variable.
Definition: conditional.hpp:65
const TParamMap & getParamMap() const
Returns a reference to .
Definition: conditional.hpp:74