autoppl  v0.8
A C++ template library for probabilistic programming
step_adapter.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <cstddef>
3 #include <cmath>
4 
5 namespace ppl {
6 
10 struct StepConfig
11 {
12  double delta = 0.8;
13  double gamma = 0.05;
14  double t0 = 10.;
15  double kappa = 0.75;
16 };
17 
18 namespace mcmc {
19 
25 {
30  StepAdapter(double _log_eps)
31  {
32  init(_log_eps);
33  }
34 
38  void init(double _log_eps)
39  {
40  log_eps = _log_eps;
42  }
43 
47  void adapt(double alpha_ratio)
48  {
49  ++counter;
50  alpha_ratio = (alpha_ratio > 1) ? 1 : alpha_ratio;
51  const double adapt_ratio = 1./(counter + step_config.t0);
52  H_bar = (1 - adapt_ratio) * H_bar +
53  adapt_ratio * (step_config.delta - alpha_ratio);
54  log_eps = mu - std::sqrt(counter)/step_config.gamma * H_bar;
55  const double m_ratio = std::pow(counter, -step_config.kappa);
56  log_eps_bar = m_ratio * log_eps +
57  (1 - m_ratio) * log_eps_bar;
58  }
59 
63  void reset()
64  {
65  counter = 0;
66  log_eps_bar = 0.;
67  H_bar = 0.;
68  }
69 
70  size_t counter = 0;
71  double log_eps = 0.;
72  double log_eps_bar = 0.;
73  double H_bar = 0.;
74  double mu = 0.;
75  const double mu_constant = std::log(10);
77 };
78 
79 } // namespace mcmc
80 } // namespace ppl
ppl::mcmc::StepAdapter::init
void init(double _log_eps)
Definition: step_adapter.hpp:38
ppl::mcmc::StepAdapter::step_config
StepConfig step_config
Definition: step_adapter.hpp:76
ppl::mcmc::StepAdapter::counter
size_t counter
Definition: step_adapter.hpp:70
ppl::StepConfig::gamma
double gamma
Definition: step_adapter.hpp:13
ppl::mcmc::StepAdapter::H_bar
double H_bar
Definition: step_adapter.hpp:73
ppl::mcmc::StepAdapter
Definition: step_adapter.hpp:25
ppl::mcmc::StepAdapter::mu_constant
const double mu_constant
Definition: step_adapter.hpp:75
ppl::mcmc::StepAdapter::reset
void reset()
Definition: step_adapter.hpp:63
ppl::mcmc::StepAdapter::mu
double mu
Definition: step_adapter.hpp:74
ppl::StepConfig
Definition: step_adapter.hpp:11
ppl
Definition: bounded.hpp:11
ppl::StepConfig::delta
double delta
Definition: step_adapter.hpp:12
ppl::StepConfig::kappa
double kappa
Definition: step_adapter.hpp:15
ppl::mcmc::StepAdapter::log_eps_bar
double log_eps_bar
Definition: step_adapter.hpp:72
ppl::StepConfig::t0
double t0
Definition: step_adapter.hpp:14
ppl::mcmc::StepAdapter::log_eps
double log_eps
Definition: step_adapter.hpp:71
ppl::mcmc::StepAdapter::StepAdapter
StepAdapter(double _log_eps)
Definition: step_adapter.hpp:30
ppl::mcmc::StepAdapter::adapt
void adapt(double alpha_ratio)
Definition: step_adapter.hpp:47