autoppl  v0.8
A C++ template library for probabilistic programming
tree_utils.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <optional>
3 #include <functional>
4 #include <type_traits>
5 
6 namespace ppl {
7 namespace mcmc {
8 
12 template <class ADExprType
13  , class SubviewType
14  >
15 struct TreeInput
16 {
17  using ad_expr_t = ADExprType;
18  using subview_t = SubviewType;
19 
20  using ad_expr_ref_t = std::reference_wrapper<ad_expr_t>;
21  using subview_ref_t = std::reference_wrapper<subview_t>;
22 
23  TreeInput(ad_expr_t& ad_expr,
24  subview_t& theta,
25  subview_t& theta_adj,
26  subview_t& tp_adj,
27  subview_t& theta_prime,
28  subview_t& p_most,
29  subview_t& p_beg,
30  subview_t& p_end,
31  subview_t& p_beg_scaled,
32  subview_t& p_end_scaled,
33  subview_t& rho,
34  size_t& n_leapfrog,
35  double& log_sum_weight,
36  double& sum_metro_prob,
37  int8_t v,
38  double epsilon,
39  double ham
40  )
41  : ad_expr_ref{ad_expr}
42  , theta_ref{theta}
43  , theta_adj_ref{theta_adj}
44  , tp_adj_ref{tp_adj}
45  , theta_prime_ref{theta_prime}
46  , p_most_ref{p_most}
47  , p_beg_ref{p_beg}
48  , p_end_ref{p_end}
49  , p_beg_scaled_ref{p_beg_scaled}
50  , p_end_scaled_ref{p_end_scaled}
51  , rho_ref{rho}
52  , n_leapfrog_ref{n_leapfrog}
53  , log_sum_weight_ref{log_sum_weight}
54  , sum_metro_prob_ref{sum_metro_prob}
55  , v{v}
56  , epsilon{epsilon}
57  , ham{ham}
58  {}
59 
65  subview_ref_t p_most_ref; // either forward/backward-most momentum
66  subview_ref_t p_beg_ref; // begin new subtree (in the direction of v)
67  subview_ref_t p_end_ref; // end new subtree (in the direction of v)
71  std::reference_wrapper<size_t> n_leapfrog_ref;
72  std::reference_wrapper<double> log_sum_weight_ref;
73  std::reference_wrapper<double> sum_metro_prob_ref;
74  const int8_t v;
75  const double epsilon;
76  const double ham;
77 };
78 
82 struct TreeOutput
83 {
84  TreeOutput(bool _valid=true, double _potential=0.)
85  : valid{_valid}, potential{_potential}
86  {}
87 
88  bool valid;
89  double potential;
90 };
91 
92 } // namespace mcmc
93 } // namespace ppl
ppl::mcmc::TreeInput::p_end_scaled_ref
subview_ref_t p_end_scaled_ref
Definition: tree_utils.hpp:69
ppl::mcmc::TreeInput::theta_prime_ref
subview_ref_t theta_prime_ref
Definition: tree_utils.hpp:64
ppl::mcmc::TreeInput::sum_metro_prob_ref
std::reference_wrapper< double > sum_metro_prob_ref
Definition: tree_utils.hpp:73
ppl::mcmc::TreeInput::ad_expr_ref
ad_expr_ref_t ad_expr_ref
Definition: tree_utils.hpp:60
ppl::mcmc::TreeInput::ad_expr_t
ADExprType ad_expr_t
Definition: tree_utils.hpp:17
ppl::mcmc::TreeOutput
Definition: tree_utils.hpp:83
ppl::mcmc::TreeOutput::potential
double potential
Definition: tree_utils.hpp:89
ppl::mcmc::TreeInput::v
const int8_t v
Definition: tree_utils.hpp:74
ppl::mcmc::TreeInput::n_leapfrog_ref
std::reference_wrapper< size_t > n_leapfrog_ref
Definition: tree_utils.hpp:71
ppl::mcmc::TreeOutput::valid
bool valid
Definition: tree_utils.hpp:88
ppl::mcmc::TreeInput
Definition: tree_utils.hpp:16
ppl::mcmc::TreeInput::epsilon
const double epsilon
Definition: tree_utils.hpp:75
ppl::mcmc::TreeInput::ad_expr_ref_t
std::reference_wrapper< ad_expr_t > ad_expr_ref_t
Definition: tree_utils.hpp:20
ppl::mcmc::TreeInput::theta_ref
subview_ref_t theta_ref
Definition: tree_utils.hpp:61
ppl::mcmc::TreeInput::subview_t
SubviewType subview_t
Definition: tree_utils.hpp:18
ppl::mcmc::TreeInput::p_beg_scaled_ref
subview_ref_t p_beg_scaled_ref
Definition: tree_utils.hpp:68
ppl::mcmc::TreeInput::p_end_ref
subview_ref_t p_end_ref
Definition: tree_utils.hpp:67
ppl::mcmc::TreeInput::log_sum_weight_ref
std::reference_wrapper< double > log_sum_weight_ref
Definition: tree_utils.hpp:72
ppl::mcmc::TreeInput::rho_ref
subview_ref_t rho_ref
Definition: tree_utils.hpp:70
ppl
Definition: bounded.hpp:11
ppl::mcmc::TreeInput::TreeInput
TreeInput(ad_expr_t &ad_expr, subview_t &theta, subview_t &theta_adj, subview_t &tp_adj, subview_t &theta_prime, subview_t &p_most, subview_t &p_beg, subview_t &p_end, subview_t &p_beg_scaled, subview_t &p_end_scaled, subview_t &rho, size_t &n_leapfrog, double &log_sum_weight, double &sum_metro_prob, int8_t v, double epsilon, double ham)
Definition: tree_utils.hpp:23
ppl::mcmc::TreeInput::theta_adj_ref
subview_ref_t theta_adj_ref
Definition: tree_utils.hpp:62
ppl::mcmc::TreeInput::subview_ref_t
std::reference_wrapper< subview_t > subview_ref_t
Definition: tree_utils.hpp:21
ppl::mcmc::TreeOutput::TreeOutput
TreeOutput(bool _valid=true, double _potential=0.)
Definition: tree_utils.hpp:84
ppl::mcmc::TreeInput::p_beg_ref
subview_ref_t p_beg_ref
Definition: tree_utils.hpp:66
ppl::mcmc::TreeInput::tp_adj_ref
subview_ref_t tp_adj_ref
Definition: tree_utils.hpp:63
ppl::mcmc::TreeInput::ham
const double ham
Definition: tree_utils.hpp:76
ppl::mcmc::TreeInput::p_most_ref
subview_ref_t p_most_ref
Definition: tree_utils.hpp:65