stepsize_adaptation.hpp
Go to the documentation of this file.
1 #ifndef STAN_MCMC_STEPSIZE_ADAPTATION_HPP
2 #define STAN_MCMC_STEPSIZE_ADAPTATION_HPP
3 
5 #include <cmath>
6 
7 namespace stan {
8 
9  namespace mcmc {
10 
12  public:
14  : mu_(0.5), delta_(0.5), gamma_(0.05),
15  kappa_(0.75), t0_(10) {
16  restart();
17  }
18 
19  void set_mu(double m) {
20  mu_ = m;
21  }
22 
23  void set_delta(double d) {
24  if (d > 0 && d < 1)
25  delta_ = d;
26  }
27 
28  void set_gamma(double g) {
29  if (g > 0)
30  gamma_ = g;
31  }
32 
33  void set_kappa(double k) {
34  if (k > 0)
35  kappa_ = k;
36  }
37  void set_t0(double t) {
38  if (t > 0)
39  t0_ = t;
40  }
41 
42  double get_mu() {
43  return mu_;
44  }
45 
46  double get_delta() {
47  return delta_;
48  }
49 
50  double get_gamma() {
51  return gamma_;
52  }
53 
54  double get_kappa() {
55  return kappa_;
56  }
57 
58  double get_t0() {
59  return t0_;
60  }
61 
62  void restart() {
63  counter_ = 0;
64  s_bar_ = 0;
65  x_bar_ = 0;
66  }
67 
68  void learn_stepsize(double& epsilon, double adapt_stat) {
69  ++counter_;
70 
71  adapt_stat = adapt_stat > 1 ? 1 : adapt_stat;
72 
73  // Nesterov Dual-Averaging of log(epsilon)
74  const double eta = 1.0 / (counter_ + t0_);
75 
76  s_bar_ = (1.0 - eta) * s_bar_ + eta * (delta_ - adapt_stat);
77 
78  const double x = mu_ - s_bar_ * std::sqrt(counter_) / gamma_;
79  const double x_eta = std::pow(counter_, - kappa_);
80 
81  x_bar_ = (1.0 - x_eta) * x_bar_ + x_eta * x;
82 
83  epsilon = std::exp(x);
84  }
85 
86  void complete_adaptation(double& epsilon) {
87  epsilon = std::exp(x_bar_);
88  }
89 
90  protected:
91  double counter_; // Adaptation iteration
92  double s_bar_; // Moving average statistic
93  double x_bar_; // Moving average parameter
94  double mu_; // Asymptotic mean of parameter
95  double delta_; // Target value of statistic
96  double gamma_; // Adaptation scaling
97  double kappa_; // Adaptation shrinkage
98  double t0_; // Effective starting iteration
99  };
100 
101  } // mcmc
102 
103 } // stan
104 
105 #endif
void complete_adaptation(double &epsilon)
T sqrt(T number)
Definition: d0nt_math.hpp:156
constexpr T pow(T x)
Definition: pow.h:75
void learn_stepsize(double &epsilon, double adapt_stat)
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
Float_t d
Definition: plot.C:236
double epsilon