30 template <
class VarPolicy>
63 : var_estimator_(n_params)
66 , window_begin_{init_buffer}
67 , window_end_{warmup - term_buffer}
68 , init_buffer_{init_buffer}
69 , term_buffer_{term_buffer}
70 , window_base_{window_base}
78 window_base_ = warmup_;
83 else if (warmup_ < init_buffer_ + term_buffer_ + window_base_) {
84 init_buffer_ = 0.15 * warmup_;
85 term_buffer_ = 0.10 * warmup_;
86 window_base_ = warmup_ - init_buffer_ - term_buffer_;
89 window_begin_ = init_buffer_;
90 window_end_ = window_begin_ + window_base_;
91 size_t next_window_end = window_end_ + 2 * window_base_;
95 if (next_window_end > warmup_ - term_buffer_) {
96 window_end_ = warmup_ - term_buffer_;
103 template <
class MatType1,
class MatType2>
104 bool adapt(
const Eigen::MatrixBase<MatType1>& x,
105 Eigen::MatrixBase<MatType2>& var)
108 if (counter_ >= init_buffer_ &&
109 counter_ < warmup_ - term_buffer_) {
110 var_estimator_.update(x);
115 if (counter_ == window_end_ - 1) {
116 auto&& v = var_estimator_.get_variance();
117 double n = var_estimator_.get_n_samples();
119 var.array() = ( (n / ((n + 5.0) * (n - 1.))) * v.array() +
120 1e-3 * (5.0 / (n + 5.0)) );
121 var_estimator_.reset();
128 static_cast<void>(x);
129 static_cast<void>(var);
141 if (window_end_ == warmup_ - term_buffer_) {
return; }
143 size_t window_size = window_end_ - window_begin_;
144 window_begin_ = window_end_;
145 window_end_ = window_begin_ + 2 * window_size;
148 if (window_end_ == warmup_ - term_buffer_) {
return; }
150 size_t next_window_end = window_end_ + 4 * window_size;
151 if (next_window_end > warmup_ - term_buffer_) {
152 window_end_ = warmup_ - term_buffer_;
156 math::WelfordVar var_estimator_;
157 const size_t warmup_;
159 size_t window_begin_;