1 #ifndef VTESTBED_CORE_YULE_WALKER_SOLVER_HH 2 #define VTESTBED_CORE_YULE_WALKER_SOLVER_HH 6 #include <vtestbed/base/blitz.hh> 7 #include <vtestbed/linalg/types.hh> 14 blitz::TinyVector<int,3>
15 chop_right(
const blitz::Array<T,3>& rhs, T eps);
17 blitz::TinyVector<int,4>
18 chop_right(
const blitz::Array<T,4>& rhs, T eps);
20 template <
class T,
int N>
22 autoregression_white_noise_variance(
23 const blitz::Array<T,N>& acf,
24 const blitz::Array<T,N>& phi
26 using blitz::RectDomain;
28 RectDomain<N> rect{{0}, phi.shape() - 1};
30 return variance - sum(phi*acf(rect));
45 template <
class T,
int N>
48 const blitz::Array<T,N>& acf,
49 const blitz::Array<T,N>& theta
53 const T& variance = *acf.data();
54 return variance / sum(pow2(theta));
57 template <
class T,
int N>
59 acf_variance(
const blitz::Array<T,N>& acf) {
63 template <
class T,
int N>
102 return this->
solve();
131 template <
class T,
int N>
149 T _varepsilon = T(1e-5);
155 bool _determinetheorder =
true;
161 T _chopepsilon = T(1e-10);
193 copy()
const override {
200 return this->_determinetheorder;
205 this->_determinetheorder = rhs;
209 do_not_determine_the_order() noexcept {
210 this->_determinetheorder =
false;
214 chop(
bool rhs) noexcept {
225 do_not_chop() noexcept {
232 return this->_chopepsilon;
237 this->_chopepsilon = rhs;
243 return this->_varepsilon;
248 this->_varepsilon = rhs;
253 this->_maxorder = rhs;
259 return this->_maxorder;
263 min_variance(T rhs) noexcept {
264 this->_minvariance = rhs;
268 min_variance() const noexcept {
269 return this->_minvariance;
275 variance_has_not_changed_much(T var0, T var1) noexcept {
276 return (this->_determinetheorder &&
277 std::abs(var1-var0) < this->_varepsilon) ||
278 (var1 > 0 && !(var1 > this->_minvariance));
287 template <
class T,
int N>
293 typedef blitz::Array<T,3> array_type;
294 typedef blitz::TinyVector<int,3> shape_type;
298 const array_type& _acf;
299 const shape_type& _arorder;
303 const array_type& acf,
304 const shape_type& ar_order
305 ): _acf(acf), _arorder(ar_order) {}
308 AC_matrix_block(
int i0,
int j0);
311 AC_matrix_block(
int i0);
321 typedef blitz::Array<T,4> array_type;
322 typedef blitz::TinyVector<int,4> shape_type;
326 const array_type& _acf;
327 const shape_type& _arorder;
331 const array_type& acf,
332 const shape_type& ar_order
333 ): _acf(acf), _arorder(ar_order) {}
336 AC_matrix_block(
int i0,
int j0,
int k0);
339 AC_matrix_block(
int i0,
int j0);
342 AC_matrix_block(
int i0);
348 template <
class T,
int N>
353 typedef blitz::TinyVector<int,N> shape_type;
361 shape_type _order{0};
362 T _chopepsilon = T(1e-10);
380 copy()
const override {
384 inline void order(
const shape_type& rhs) { this->_order = rhs; }
385 inline const shape_type& order()
const {
return this->_order; }
386 inline void chop(
bool rhs) { this->_chop = rhs; }
387 inline value_type chop_epsilon()
const {
return this->_chopepsilon; }
388 inline void chop_epsilon(
value_type rhs) { this->_chopepsilon = rhs; }
401 template <
class T,
int N>
412 typedef blitz::TinyVector<int,N> shape_type;
416 int _maxiterations = 1000;
417 T _maxresidual = T(1e-5);
418 T _minvarwn = T(1e-6);
419 T _epsvarwn = T(1e-5);
427 copy()
const override {
434 order(
const shape_type& rhs) {
439 inline const shape_type&
447 return this->_maxiterations;
452 this->_maxiterations = rhs;
456 max_residual() const noexcept {
457 return this->_maxresidual;
461 max_residual(T rhs) noexcept {
462 this->_maxresidual = rhs;
473 this->_minvarwn = rhs;
477 min_white_noise_variance() const noexcept {
478 return this->_minvarwn;
483 this->_epsvarwn = rhs;
489 return this->_epsvarwn;
498 #endif // vim:filetype=cpp bool determine_the_order() const noexcept
value_type chop_epsilon() const noexcept
int max_order() const noexcept
void min_white_noise_variance(T rhs) noexcept
Minimal white noise variance.
value_type white_noise_variance() const noexcept
T value_type
Array element type.
T variance(const Array< T, N > &rhs)
Sample variance.
int max_iterations() const noexcept
Maximum number of iterations.
array_type operator()()
Solve Yule—Walker system of equations.
const shape_type & order() const noexcept
Moving average model order.
Multi-dimensional solver that determines MA model coefficients from ACF.
array_type solve(array_type acf) override
Solve Yule—Walker system of equations.
bool chop() const noexcept
virtual array_type solve(array_type acf)=0
Solve Yule—Walker system of equations.
Autocovariate matrix generator that reduces the size of ACF to match AR model order.
value_type var_epsilon() const noexcept
array_type solve(array_type acf) override
Solve Yule—Walker system of equations.
blitz::Array< T, N > array_type
Three-dimensional array type.
Computes AR model coefficients using an order-recursvive method from .
array_type solve(array_type acf) override
Solve Yule—Walker system of equations.
T min_white_noise_variance_delta() const noexcept
Minimal white noise variance difference between iterations.
T moving_average_white_noise_variance(const blitz::Array< T, N > &acf, const blitz::Array< T, N > &theta)