github.com/RhysU/ar
Autoregressive process modeling tools in header-only C++
Classes | Namespaces
ar.hpp File Reference
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <stdexcept>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

class  ar::predictor< Value, Index >
 Simulate an autoregressive model process with an InputIterator interface. More...
 
struct  ar::mean_subtracted
 Method-specific estimation variance routines following Broersen. More...
 
struct  ar::mean_retained
 Denotes the sample mean was retained in a signal during estimation. More...
 
struct  ar::estimation_method
 A parent type for autoregressive process parameter estimation techniques. More...
 
class  ar::YuleWalker< MeanHandling >
 Represents estimation by solving the Yule–Walker equations. More...
 
class  ar::Burg< MeanHandling >
 Represents estimation using Burg's recursive method. More...
 
class  ar::LSFB< MeanHandling >
 Represents forward and backward prediction least squares minimization. More...
 
class  ar::LSF< MeanHandling >
 Represents forward prediction least squares minimization. More...
 
struct  ar::empirical_variance_function< EstimationMethod, Result, Integer1, Integer2 >
 An STL-ready binary_function for a given method's empirical variance. More...
 
class  ar::empirical_variance_generator< EstimationMethod, Result, Integer1, Integer2 >
 An STL AdaptableGenerator for a given method's empirical variance. More...
 
class  ar::empirical_variance_iterator< EstimationMethod, Result, Integer1, Integer2 >
 An immutable RandomAccessIterator over a method's empirical variance sequence. More...
 
struct  ar::criterion
 Criteria for autoregressive model order selection following Broersen. More...
 
struct  ar::GIC< AlphaNumerator, AlphaDenominator >
 Represents the generalized information criterion (GIC). More...
 
struct  ar::AIC
 Represents the Akaike information criterion (AIC). More...
 
struct  ar::BIC
 Represents the consistent criterion BIC. More...
 
struct  ar::MCC
 Represents the minimally consistent criterion (MCC). More...
 
struct  ar::AICC
 Represents the asymptotically-corrected Akaike information criterion (AICC). More...
 
struct  ar::FIC< EstimationMethod, AlphaNumerator, AlphaDenominator >
 Represents the finite information criterion (FIC) as applied to a particular estimation_method. More...
 
struct  ar::FIC< YuleWalker< MeanHandling >, AlphaNumerator, AlphaDenominator >
 Represents the finite information criterion (FIC) as applied to the YuleWalker estimation_method. More...
 
struct  ar::FSIC< EstimationMethod >
 Represents the finite sample information criterion (FSIC) as applied to a particular estimation_method. More...
 
struct  ar::CIC< EstimationMethod >
 Represents the combined information criterion (CIC) as applied to a particular estimation_method. More...
 
struct  ar::best_model_function< EstimationMethod, Integer1, Integer2, Sequence1, Sequence2, Sequence3, Sequence4 >
 A template typedef and helper method returning a best_model implementation matching a model selection criterion provided at runtime. More...
 
class  ar::strided_adaptor< Iterator >
 An adapter to add striding over another (usually random access) iterator. More...
 

Namespaces

 ar
 Autoregressive process modeling tools in header-only C++.
 

Macros

#define AR_GCC_VERSION   (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
 Preprocessor macros to simplify implementation. More...
 
#define AR_STRINGIFY_HELPER(x)   #x
 Helper macro for implementing AR_STRINGIFY.
 
#define AR_STRINGIFY(x)   AR_STRINGIFY_HELPER(x)
 Expand and stringify the provided argument.
 
#define AR_ENSURE_MSGEXCEPT(expr, msg, except)   if (!(expr)) throw except(msg)
 Ensure that expr evaluates to boolean true at runtime. More...
 
#define AR_ENSURE_MSG(expr, msg)   AR_ENSURE_MSGEXCEPT(expr, msg, std::logic_error)
 Ensure that expr evaluates to boolean true at runtime. More...
 
#define AR_ENSURE(expr)   AR_ENSURE_MSG(expr, AR_STRINGIFY(expr)" false")
 Ensure that expr evaluates to boolean true at runtime. More...
 
#define AR_ENSURE_ARG(expr)   AR_ENSURE_MSGEXCEPT(expr, AR_STRINGIFY(expr)" false", std::invalid_argument)
 Ensure that the argument-related expr evaluates to boolean true at runtime. More...
 
#define AR_ENSURE_EXCEPT(expr, except)   AR_ENSURE_MSGEXCEPT(expr, AR_STRINGIFY(expr)" false", except)
 Ensure that expr evaluates to boolean true at runtime. More...
 

Functions

template<typename InputIterator , typename OutputType1 , typename OutputType2 >
std::size_t ar::welford_nvariance (InputIterator first, InputIterator last, OutputType1 &mean, OutputType2 &nvar)
 Stable, one-pass algorithms for computing variances and covariances. More...
 
template<typename InputIterator , typename OutputType1 , typename OutputType2 >
std::size_t ar::welford_variance_population (InputIterator first, InputIterator last, OutputType1 &mean, OutputType2 &var)
 Compute the mean and population variance using Welford's algorithm. More...
 
template<typename InputIterator , typename OutputType1 , typename OutputType2 >
std::size_t ar::welford_variance_sample (InputIterator first, InputIterator last, OutputType1 &mean, OutputType2 &var)
 Compute the mean and sample variance using Welford's algorithm. More...
 
template<typename InputIterator1 , typename InputIterator2 , typename OutputType1 , typename OutputType2 , typename OutputType3 >
std::size_t ar::welford_ncovariance (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType1 &mean1, OutputType2 &mean2, OutputType3 &ncovar)
 Compute means and the number of samples, N, times the population covariance using Welford's algorithm. More...
 
template<typename InputIterator1 , typename InputIterator2 , typename OutputType1 , typename OutputType2 , typename OutputType3 >
std::size_t ar::welford_covariance_population (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType1 &mean1, OutputType2 &mean2, OutputType3 &covar)
 Compute means and the population covariance using Welford's algorithm. More...
 
template<typename InputIterator1 , typename InputIterator2 , typename OutputType1 , typename OutputType2 , typename OutputType3 >
std::size_t ar::welford_covariance_sample (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType1 &mean1, OutputType2 &mean2, OutputType3 &covar)
 Compute means and the sample covariance using Welford's algorithm. More...
 
template<typename InputIterator , typename ValueType >
ValueType ar::welford_inner_product (InputIterator first, InputIterator last, ValueType init)
 Compute the inner product of [first, last) with itself using welford_nvariance. More...
 
template<typename InputIterator1 , typename InputIterator2 , typename ValueType >
ValueType ar::welford_inner_product (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, ValueType init)
 Compute the inner product of [first1, last1) against [first2, ...) using welford_ncovariance. More...
 
template<typename ValueType , typename InputIterator1 , typename InputIterator2 >
ValueType ar::negative_half_reflection_coefficient (InputIterator1 a_first, InputIterator1 a_last, InputIterator2 b_first)
 Algorithms for autoregressive parameter estimation and manipulation. More...
 
template<class InputIterator , class Value , class OutputIterator1 , class OutputIterator2 , class OutputIterator3 , class OutputIterator4 , class Vector >
std::size_t ar::burg_method (InputIterator data_first, InputIterator data_last, Value &mean, std::size_t &maxorder, OutputIterator1 params_first, OutputIterator2 sigma2e_first, OutputIterator3 gain_first, OutputIterator4 autocor_first, const bool subtract_mean, const bool hierarchy, Vector &f, Vector &b, Vector &Ak, Vector &ac)
 Fit an autoregressive model to stationary time series data using Burg's method. More...
 
template<class InputIterator , class Value , class OutputIterator1 , class OutputIterator2 , class OutputIterator3 , class OutputIterator4 >
std::size_t ar::burg_method (InputIterator data_first, InputIterator data_last, Value &mean, std::size_t &maxorder, OutputIterator1 params_first, OutputIterator2 sigma2e_first, OutputIterator3 gain_first, OutputIterator4 autocor_first, const bool subtract_mean=false, const bool hierarchy=false)
 Fit an autoregressive model to stationary time series data using Burg's method. More...
 
template<class RandomAccessIterator , class InputIterator , class Value >
predictor< typename std::iterator_traits< RandomAccessIterator >::value_type > ar::autocorrelation (RandomAccessIterator params_first, RandomAccessIterator params_last, Value gain, InputIterator autocor_first)
 Construct an iterator over the autocorrelation function \(\rho_k\) given process parameters and initial conditions. More...
 
template<class Value >
Value ar::decorrelation_time (const std::size_t N, predictor< Value > rho, const bool abs_rho=false)
 Compute the decorrelation time for variance of the mean given autocorrelation details. More...
 
template<class Value >
Value ar::decorrelation_time (const std::size_t N, predictor< Value > rho1, predictor< Value > rho2, const bool abs_rho=false)
 Compute the decorrelation time for a covariance given autocorrelation details from two processes. More...
 
template<class RandomAccessIterator , class InputIterator , class OutputIterator >
void ar::zohar_linear_solve (RandomAccessIterator a_first, RandomAccessIterator a_last, RandomAccessIterator r_first, InputIterator d_first, OutputIterator s_first)
 Solve a Toeplitz set of linear equations. More...
 
template<class RandomAccessIterator , class ForwardIterator >
void ar::zohar_linear_solve (RandomAccessIterator a_first, RandomAccessIterator a_last, RandomAccessIterator r_first, ForwardIterator d_first)
 Solve a Toeplitz set of linear equations in-place. More...
 
template<class RandomAccessIterator , class ForwardIterator >
void ar::zohar_linear_solve (RandomAccessIterator a_first, RandomAccessIterator a_last, ForwardIterator d_first)
 Solve a real-valued, symmetric Toeplitz set of linear equations in-place. More...
 
template<class Criterion , typename Result , typename Integer1 , typename Integer2 >
Result ar::evaluate (Result sigma2e, Integer1 N, Integer2 p)
 Evaluate a given criterion for N samples and model order p. More...
 
template<class Criterion , typename Integer1 , typename Integer2 , class InputIterator , class OutputIterator >
std::iterator_traits< InputIterator >::difference_type ar::evaluate_models (Integer1 N, Integer2 ordfirst, InputIterator first, InputIterator last, OutputIterator crit)
 Algorithmic helpers for autoregressive model order selection. More...
 
template<class Criterion , typename Integer1 , typename Integer2 , class Sequence1 , class Sequence2 , class Sequence3 , class Sequence4 , class OutputIterator >
Sequence1::difference_type ar::best_model (Integer1 N, Integer2 minorder, Sequence1 &params, Sequence2 &sigma2e, Sequence3 &gain, Sequence4 &autocor, OutputIterator crit)
 Obtain the best model according to criterion applied to \(\sigma^2_\epsilon\) given a hierarchy of candidates. More...
 
template<class Criterion , typename Integer1 , typename Integer2 , class InputIterator >
std::iterator_traits< InputIterator >::difference_type ar::evaluate_models (Integer1 N, Integer2 ordfirst, InputIterator first, InputIterator last)
 Find the index of the best model from a hierarchy of candidates according to a criterion given \(\sigma^2_\epsilon\) for each model. More...
 
template<class Criterion , typename Integer1 , typename Integer2 , class Sequence1 , class Sequence2 , class Sequence3 , class Sequence4 >
Sequence1::difference_type ar::best_model (Integer1 N, Integer2 minorder, Sequence1 &params, Sequence2 &sigma2e, Sequence3 &gain, Sequence4 &autocor)
 Obtain the best model according to criterion applied to \(\sigma^2_\epsilon\) given a hierarchy of candidates. More...
 
template<typename InputIterator , typename OutputType1 , typename OutputType2 >
std::size_t ar::welford_nvariance (InputIterator first, InputIterator last, OutputType1 &mean, OutputType2 &nvar)
 Stable, one-pass algorithms for computing variances and covariances. More...
 
template<typename InputIterator , typename OutputType1 , typename OutputType2 >
std::size_t ar::welford_variance_population (InputIterator first, InputIterator last, OutputType1 &mean, OutputType2 &var)
 Compute the mean and population variance using Welford's algorithm. More...
 
template<typename InputIterator , typename OutputType1 , typename OutputType2 >
std::size_t ar::welford_variance_sample (InputIterator first, InputIterator last, OutputType1 &mean, OutputType2 &var)
 Compute the mean and sample variance using Welford's algorithm. More...
 
template<typename InputIterator1 , typename InputIterator2 , typename OutputType1 , typename OutputType2 , typename OutputType3 >
std::size_t ar::welford_ncovariance (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType1 &mean1, OutputType2 &mean2, OutputType3 &ncovar)
 Compute means and the number of samples, N, times the population covariance using Welford's algorithm. More...
 
template<typename InputIterator1 , typename InputIterator2 , typename OutputType1 , typename OutputType2 , typename OutputType3 >
std::size_t ar::welford_covariance_population (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType1 &mean1, OutputType2 &mean2, OutputType3 &covar)
 Compute means and the population covariance using Welford's algorithm. More...
 
template<typename InputIterator1 , typename InputIterator2 , typename OutputType1 , typename OutputType2 , typename OutputType3 >
std::size_t ar::welford_covariance_sample (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputType1 &mean1, OutputType2 &mean2, OutputType3 &covar)
 Compute means and the sample covariance using Welford's algorithm. More...
 
template<typename InputIterator , typename ValueType >
ValueType ar::welford_inner_product (InputIterator first, InputIterator last, ValueType init)
 Compute the inner product of [first, last) with itself using welford_nvariance. More...
 
template<typename InputIterator1 , typename InputIterator2 , typename ValueType >
ValueType ar::welford_inner_product (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, ValueType init)
 Compute the inner product of [first1, last1) against [first2, ...) using welford_ncovariance. More...
 
template<typename ValueType , typename InputIterator1 , typename InputIterator2 >
ValueType ar::negative_half_reflection_coefficient (InputIterator1 a_first, InputIterator1 a_last, InputIterator2 b_first)
 Algorithms for autoregressive parameter estimation and manipulation. More...
 
template<class InputIterator , class Value , class OutputIterator1 , class OutputIterator2 , class OutputIterator3 , class OutputIterator4 , class Vector >
std::size_t ar::burg_method (InputIterator data_first, InputIterator data_last, Value &mean, std::size_t &maxorder, OutputIterator1 params_first, OutputIterator2 sigma2e_first, OutputIterator3 gain_first, OutputIterator4 autocor_first, const bool subtract_mean, const bool hierarchy, Vector &f, Vector &b, Vector &Ak, Vector &ac)
 Fit an autoregressive model to stationary time series data using Burg's method. More...
 
template<class InputIterator , class Value , class OutputIterator1 , class OutputIterator2 , class OutputIterator3 , class OutputIterator4 >
std::size_t ar::burg_method (InputIterator data_first, InputIterator data_last, Value &mean, std::size_t &maxorder, OutputIterator1 params_first, OutputIterator2 sigma2e_first, OutputIterator3 gain_first, OutputIterator4 autocor_first, const bool subtract_mean=false, const bool hierarchy=false)
 Fit an autoregressive model to stationary time series data using Burg's method. More...
 
template<class RandomAccessIterator , class InputIterator , class Value >
predictor< typename std::iterator_traits< RandomAccessIterator >::value_type > ar::autocorrelation (RandomAccessIterator params_first, RandomAccessIterator params_last, Value gain, InputIterator autocor_first)
 Construct an iterator over the autocorrelation function \(\rho_k\) given process parameters and initial conditions. More...
 
template<class Value >
Value ar::decorrelation_time (const std::size_t N, predictor< Value > rho, const bool abs_rho=false)
 Compute the decorrelation time for variance of the mean given autocorrelation details. More...
 
template<class Value >
Value ar::decorrelation_time (const std::size_t N, predictor< Value > rho1, predictor< Value > rho2, const bool abs_rho=false)
 Compute the decorrelation time for a covariance given autocorrelation details from two processes. More...
 
template<class RandomAccessIterator , class InputIterator , class OutputIterator >
void ar::zohar_linear_solve (RandomAccessIterator a_first, RandomAccessIterator a_last, RandomAccessIterator r_first, InputIterator d_first, OutputIterator s_first)
 Solve a Toeplitz set of linear equations. More...
 
template<class RandomAccessIterator , class ForwardIterator >
void ar::zohar_linear_solve (RandomAccessIterator a_first, RandomAccessIterator a_last, RandomAccessIterator r_first, ForwardIterator d_first)
 Solve a Toeplitz set of linear equations in-place. More...
 
template<class RandomAccessIterator , class ForwardIterator >
void ar::zohar_linear_solve (RandomAccessIterator a_first, RandomAccessIterator a_last, ForwardIterator d_first)
 Solve a real-valued, symmetric Toeplitz set of linear equations in-place. More...
 
template<class Criterion , typename Result , typename Integer1 , typename Integer2 >
Result ar::evaluate (Result sigma2e, Integer1 N, Integer2 p)
 Evaluate a given criterion for N samples and model order p. More...
 
template<class Criterion , typename Integer1 , typename Integer2 , class InputIterator , class OutputIterator >
std::iterator_traits< InputIterator >::difference_type ar::evaluate_models (Integer1 N, Integer2 ordfirst, InputIterator first, InputIterator last, OutputIterator crit)
 Algorithmic helpers for autoregressive model order selection. More...
 
template<class Criterion , typename Integer1 , typename Integer2 , class Sequence1 , class Sequence2 , class Sequence3 , class Sequence4 , class OutputIterator >
Sequence1::difference_type ar::best_model (Integer1 N, Integer2 minorder, Sequence1 &params, Sequence2 &sigma2e, Sequence3 &gain, Sequence4 &autocor, OutputIterator crit)
 Obtain the best model according to criterion applied to \(\sigma^2_\epsilon\) given a hierarchy of candidates. More...
 
template<class Criterion , typename Integer1 , typename Integer2 , class InputIterator >
std::iterator_traits< InputIterator >::difference_type ar::evaluate_models (Integer1 N, Integer2 ordfirst, InputIterator first, InputIterator last)
 Find the index of the best model from a hierarchy of candidates according to a criterion given \(\sigma^2_\epsilon\) for each model. More...
 
template<class Criterion , typename Integer1 , typename Integer2 , class Sequence1 , class Sequence2 , class Sequence3 , class Sequence4 >
Sequence1::difference_type ar::best_model (Integer1 N, Integer2 minorder, Sequence1 &params, Sequence2 &sigma2e, Sequence3 &gain, Sequence4 &autocor)
 Obtain the best model according to criterion applied to \(\sigma^2_\epsilon\) given a hierarchy of candidates. More...
 

Detailed Description

Autoregressive process modeling tools in header-only C++.

Definition in file ar.hpp.

Macro Definition Documentation

◆ AR_ENSURE

#define AR_ENSURE (   expr)    AR_ENSURE_MSG(expr, AR_STRINGIFY(expr)" false")

Ensure that expr evaluates to boolean true at runtime.

If expr evaluates to boolean false, then a std::logic_error is thrown.

This macro is intended for assert-like checks which should always be performed regardless of whether or not NDEBUG is #defined.

Definition at line 123 of file ar.hpp.

◆ AR_ENSURE_ARG

#define AR_ENSURE_ARG (   expr)    AR_ENSURE_MSGEXCEPT(expr, AR_STRINGIFY(expr)" false", std::invalid_argument)

Ensure that the argument-related expr evaluates to boolean true at runtime.

If expr evaluates to boolean false, then a std::invalid_argument is thrown.

This macro is intended for assert-like checks which should always be performed regardless of whether or not NDEBUG is #defined.

Definition at line 134 of file ar.hpp.

◆ AR_ENSURE_EXCEPT

#define AR_ENSURE_EXCEPT (   expr,
  except 
)    AR_ENSURE_MSGEXCEPT(expr, AR_STRINGIFY(expr)" false", except)

Ensure that expr evaluates to boolean true at runtime.

If expr evaluates to boolean false, then an exception except is thrown.

This macro is intended for assert-like checks which should always be performed regardless of whether or not NDEBUG is #defined.

Definition at line 144 of file ar.hpp.

◆ AR_ENSURE_MSG

#define AR_ENSURE_MSG (   expr,
  msg 
)    AR_ENSURE_MSGEXCEPT(expr, msg, std::logic_error)

Ensure that expr evaluates to boolean true at runtime.

If expr evaluates to boolean false, then a std::logic_error is thrown with message msg.

This macro is intended for assert-like checks which should always be performed regardless of whether or not NDEBUG is #defined.

Definition at line 113 of file ar.hpp.

◆ AR_ENSURE_MSGEXCEPT

#define AR_ENSURE_MSGEXCEPT (   expr,
  msg,
  except 
)    if (!(expr)) throw except(msg)

Ensure that expr evaluates to boolean true at runtime.

If expr evaluates to boolean false, then an exception except is thrown with message msg.

This macro is intended for assert-like checks which should always be performed regardless of whether or not NDEBUG is #defined.

Definition at line 102 of file ar.hpp.

◆ AR_GCC_VERSION

#define AR_GCC_VERSION   (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)

Preprocessor macros to simplify implementation.

Helper for defining GCC version checks.

Definition at line 85 of file ar.hpp.