Add aeon/forecasting/utils/_ar.py with numba implementations of the sample
autocovariance, Levinson-Durbin, Yule-Walker, Burg and least squares AR
estimation. Burg, Yule-Walker and least squares all return every order up to
the maximum in one pass (least squares through a single Cholesky
factorisation of shift-recurrence cross products), so order selection by AIC
costs about one fit. Add ARForecaster on top, with fixed or AIC-selected order.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reference Issues/PRs
Contributes to #3652. This adds the native Burg that the first item of #3652 needs. Moving
ARCoefficientTransformer, and with itRSTSF,RISTClassifierandRISTRegressor, onto the native Burg will be a follow-up.Replaces the earlier draft #3033.
What does this implement/fix? Explain your changes.
aeon/forecasting/utils/_ar.py: numba implementations of the pure AR estimators:autocovariance: the standard (biased) sample autocovariance, which guarantees a stationary Yule-Walker fit. The existing ACF transformers use a separate mean and variance per lag, which does not guarantee this.levinson_durbinandyule_walker.burg.ar_ols: least squares with intercept (conditional sum of squares).ar_forecast: runs the fitted recursion forward.Each estimator returns the coefficients of every order up to the maximum in one pass:
ar_olsuses one Cholesky factorisation of the cross-product matrix, because the models are nested. The cross products come from a shift recurrence in O(n·p) rather than O(n·p²).So selecting the order costs about the same as fitting one model.
ARForecaster(aeon.forecasting.stats):p, or chosen over0..max_pbycriterion:"aic"(default, as in R'sar),"bic"or"aicc". The defaultmax_pismin(n - 1, floor(10 log10 n)), as in R'sar."burg"(default; always stationary),"yule_walker"and"ols".predict(y): uses the lastpvalues ofy, with no refit.horizon > 1anditerative_forecastrun the recursion forward in one call.Agreement with statsmodels 0.15.0 on log(airline):
method="mle"),acovfandAutoRegOLS agree to 1e-13 or better.var.method = 1, σ²ₖ = σ²ₖ₋�(1 − κₖ²). statsmodels divides order k byn − k, which favoured larger orders under AIC: on white noise, order 0 was chosen less often than with Yule-Walker or OLS. With R's version, all three methods choose order 0 for 73% of white noise series of length 500, close to AIC's asymptotic rate.Results
Fit time on a simulated AR(2) series, with the order selected by AIC over 0..max_p:
ARForecaster().fitar_select_orderARIMA(2,0,0)this experiment identified the problem described in #3970
.