Skip to content

[ENH] Add FourTheta forecaster - #3983

Draft
TonyBagnall wants to merge 3 commits into
mainfrom
ajb/four-theta
Draft

TonyBagnall wants to merge 3 commits into
mainfrom
ajb/four-theta

Conversation

@TonyBagnall

Copy link
Copy Markdown
Contributor

resolves #3982

Adds aeon.forecasting.stats.FourTheta, the generalised Theta method of Spiliotis, Assimakopoulos & Makridakis (2020). aeon has classic Theta and DOTM, but nothing with exponential trends, multiplicative expressions or per-series model selection. The method beats classic Theta at every frequency in the paper.

The class follows the authors' AutoTheta R code: 3 candidates per series, or 5 if it tests as seasonal, from a pool of 8, with θ in [1, 3] chosen by in-sample MAE. It is named after the authors' FourTheta function, because statsforecast's AutoTheta is a different algorithm.

Changes

  • aeon/forecasting/stats/_four_theta.py: the forecaster.
  • aeon/forecasting/utils/_brent.py: Brent's method, matching R's optimize evaluation by evaluation. It uses reverse communication because numba cannot cache a function that takes a function argument
  • aeon/forecasting/utils/_seasonality.py: _seasonal_decompose_numba and _seasonal_forecast moved from _dotm.py, plus a new acf_seasonal_test. DOTM calls the test on the differenced series, FourTheta on the raw series. DOTM's test gave identical results to the old version on 5,000 random series.

Why it is fast

R reruns decompose, lm and a Nelder-Mead ets at every θ evaluation. Here each is computed once per candidate. With α fixed the SES errors are linear in the initial level, so l0 is solved in closed form and SES reduces to a 1D search.

Benchmark

Full M4 against the authors' actual submission (submission-005, which used their 12-model M4 code):

sMAPE aeon sMAPE 005 MASE aeon MASE 005 OWA aeon OWA 005 ms per series
Yearly 13.783 13.804 3.183 3.184 0.822 0.823 0.3
Quarterly 10.127 10.128 1.179 1.178 0.890 0.890 0.9
Monthly 13.125 13.142 0.960 0.959 0.906 0.906 1.6
Weekly 8.987 8.990 2.486 2.488 0.938 0.939 5.0
Daily 3.021 3.028 3.230 3.232 0.989 0.990 17.7
Hourly 17.761 17.756 1.809 1.808 0.861 0.860 6.8
All 12.134 12.148 1.629 1.628 0.873 0.874 1.9

Timings in this table were taken with 16 processes. Equivalence holds at every frequency on both metrics (TOST on per-series log ratios, ±5% margin): overall ratios to 005 are 0.9996 for sMAPE and 1.0006 for MASE. All forecasts are finite.

The authors' AutoTheta R code (R 4.5.3, forecast 9.0.2) on 600 yearly, quarterly and monthly series:

  • aeon and R select the same model on 91% of yearly, 92% of quarterly and 89% of monthly series. Mean sMAPE and MASE are within 0.3% at each frequency.
  • R's own M4 script on forecast 9.0.2 differs from the 2018 submission by a similar amount, so the remaining gap looks like optimiser noise.

Single-threaded:

ms per series
Theta 0.04
FourTheta 0.8
statsforecast AutoTheta 7.8
aeon AutoETS 11.4

On a shared 60-series subset, FourTheta took 1.1 ms and R AutoTheta 465 ms, a ratio of about 440.

Deliberate differences from the R code

  • Forecasts are floored at zero only if the training data are non-negative. R floors unconditionally, on the mean scaled series, which reverses the floor for a negative mean.
  • A candidate that cannot be computed is skipped. A A Exp with non-positive adjusted data takes the log of a negative in R, which recycles a shorter vector with only a warning. This occurred in the benchmark sample.
  • The seasonal test is always evaluated at the seasonal lag. R's acf silently returns NA, meaning not seasonal, when m > 10 log10(n).
  • A series with mean zero is not scaled.
  • SES SSE was never more than 1.3e-6 relative above R's on 600 series, and was up to 12.8% lower where R's Nelder-Mead stopped short.

Review carefully

  • _brent.py reverse communication, and whether it should be a public utility.
  • predict(y) returns the stored forecast, as ETS does, and ignores y.
  • Prediction intervals (eq. 12 of the paper) are not included because aeon forecasters have no interval API. residuals_ is stored so they can be added.
  • The test fixtures came from R and the tests do not need R. Fixture rtol is 2e-3 because α and l0 differ slightly.

This pull request includes code written with the assistance of AI.
The code has not yet been reviewed by a human.

🤖 Generated with Claude Code

Tony Bagnall and others added 2 commits November 1, 2026 15:46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aeon-actions-bot aeon-actions-bot Bot added enhancement New feature, improvement request or other non-bug code enhancement forecasting Forecasting package labels Nov 1, 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 have added the following labels to this PR based on the changes made: forecasting. Feel free to change these if they do not properly represent the PR.

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.

[ENH] Implement 4Theta forecaster

1 participant