Skip to content

[ENH] Add ARForecaster and native numba AR estimators - #3971

Draft
TonyBagnall wants to merge 3 commits into
mainfrom
ajb/ar-forecaster
Draft

TonyBagnall wants to merge 3 commits into
mainfrom
ajb/ar-forecaster

Conversation

@TonyBagnall

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Contributes to #3652. This adds the native Burg that the first item of #3652 needs. Moving ARCoefficientTransformer, and with it RSTSF, RISTClassifier and RISTRegressor, 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_durbin and yule_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:

  • Burg and Yule-Walker get this from the recursion.
  • ar_ols uses 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):

  • Order: fixed p, or chosen over 0..max_p by criterion: "aic" (default, as in R's ar), "bic" or "aicc". The default max_p is min(n - 1, floor(10 log10 n)), as in R's ar.
  • Methods: "burg" (default; always stationary), "yule_walker" and "ols".
  • Common sample for OLS: all orders are scored on the same observations, as in the AutoTAR fix, and the selected order is then refitted on all the rows it can use.
  • predict(y): uses the last p values of y, with no refit.
  • Longer horizons: horizon > 1 and iterative_forecast run the recursion forward in one call.

Agreement with statsmodels 0.15.0 on log(airline):

  • Burg coefficients and partial autocorrelations, Yule-Walker (method="mle"), acovf and AutoReg OLS agree to 1e-13 or better.
  • The tests check against hard-coded reference values, so they do not need statsmodels.
  • Exception: Burg's innovation variance uses R's default var.method = 1, σ²ₖ = σ²ₖ₋â‚�(1 − κₖ²). statsmodels divides order k by n − 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:

n max_p Burg (kernel) OLS (kernel) ARForecaster().fit statsmodels ar_select_order aeon ARIMA(2,0,0)
100 20 0.004 ms 0.012 ms 0.34 ms 9.5 ms 1.0 ms
1000 30 0.018 ms 0.063 ms 0.36 ms 487 ms 3.7 ms
10000 40 0.26 ms 0.58 ms 1.04 ms 11,600 ms 25.6 ms

this experiment identified the problem described in #3970

.

Tony Bagnall and others added 3 commits October 27, 2026 18:39
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>
np.dot in numba calls BLAS, which cost about 25 ms per call on series of
30,000 or more points. Compute the sum of squares in the same loop that
fills the error arrays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TonyBagnall TonyBagnall added the forecasting Forecasting package label Oct 27, 2026
@TonyBagnall
TonyBagnall marked this pull request as draft October 27, 2026 19:54
@aeon-actions-bot aeon-actions-bot Bot added the enhancement New feature, improvement request or other non-bug code enhancement label Oct 27, 2026
@aeon-actions-bot

Copy link
Copy Markdown
Contributor

Thank you for contributing to aeon

I have added the following labels to this PR based on the title: enhancement.
I would have added the following labels to this PR based on the changes made: forecasting, however some package labels are already present.

The Checks tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.

If our pre-commit code quality check fails, please run pre-commit locally and push the fixes to your PR branch.

Don't hesitate to ask questions on the aeon Discord channel if you have any.

PR CI actions

These checkboxes will add labels to enable or disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.

  • Run pre-commit checks for all files
  • Run mypy typecheck tests
  • Run all pytest tests and configurations
  • Run all notebook example tests
  • Run numba-disabled codecov tests
  • Disable numba cache loading
  • Regenerate expected results for testing
  • Push an empty commit to re-run CI checks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature, improvement request or other non-bug code enhancement forecasting Forecasting package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant