Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
windowed_adaptation.hpp
Go to the documentation of this file.
1 #ifndef STAN__MCMC__WINDOWED__ADAPTATION__BETA
2 #define STAN__MCMC__WINDOWED__ADAPTATION__BETA
3 
4 #include <ostream>
5 #include <string>
6 
8 
9 namespace stan {
10 
11  namespace mcmc {
12 
14 
15  public:
16 
17  windowed_adaptation(std::string name): estimator_name_(name) {
18  num_warmup_ = 0;
22 
23  restart();
24  }
25 
26  void restart() {
30  }
31 
32  void set_window_params(unsigned int num_warmup,
33  unsigned int init_buffer,
34  unsigned int term_buffer,
35  unsigned int base_window,
36  std::ostream* e = 0) {
37 
38  if (num_warmup < 20) {
39  if (e) {
40  *e << "WARNING: No " << estimator_name_ << " estimation is" << std::endl;
41  *e << " performed for num_warmup < 20" << std::endl << std::endl;
42  }
43  return;
44  }
45 
46  if (init_buffer + base_window + term_buffer > num_warmup) {
47 
48  if (e) {
49  *e << "WARNING: The initial buffer, adaptation window, and terminal buffer" << std::endl;
50  *e << " overflow the total number of warmup iterations." << std::endl;
51  }
52 
53  num_warmup_ = num_warmup;
54  adapt_init_buffer_ = 0.15 * num_warmup;
55  adapt_term_buffer_ = 0.10 * num_warmup;
57 
58  if(e) {
59  *e << " Defaulting to a 15%/75%/10% partition," << std::endl;
60  *e << " init_buffer = " << adapt_init_buffer_ << std::endl;
61  *e << " adapt_window = " << adapt_base_window_ << std::endl;
62  *e << " term_buffer = " << adapt_term_buffer_ << std::endl << std::endl;
63  }
64 
65  return;
66 
67  }
68 
69  num_warmup_ = num_warmup;
70  adapt_init_buffer_ = init_buffer;
71  adapt_term_buffer_ = term_buffer;
72  adapt_base_window_ = base_window;
73  restart();
74 
75  }
76 
81  }
82 
86  }
87 
89 
91 
92  adapt_window_size_ *= 2;
94 
96 
97  // Bounday of the following window, not the window just computed
98  unsigned int next_window_boundary = adapt_next_window_ + 2 * adapt_window_size_;
99 
100  // If the following window overtakes the full adaptation window,
101  // then stretch the current window to the end of the full window
102  if (next_window_boundary >= num_warmup_ - adapt_term_buffer_) {
104  }
105 
106  }
107 
108  protected:
109 
110  std::string estimator_name_;
111 
112  unsigned int num_warmup_;
113  unsigned int adapt_init_buffer_;
114  unsigned int adapt_term_buffer_;
115  unsigned int adapt_base_window_;
116 
117  unsigned int adapt_window_counter_;
118  unsigned int adapt_next_window_;
119  unsigned int adapt_window_size_;
120 
121  };
122 
123  } // mcmc
124 
125 } // stan
126 
127 #endif
void set_window_params(unsigned int num_warmup, unsigned int init_buffer, unsigned int term_buffer, unsigned int base_window, std::ostream *e=0)
double e()
Return the base of the natural logarithm.
Definition: constants.hpp:86

     [ Stan Home Page ] © 2011–2014, Stan Development Team.