Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(models): improve the SES implementation #973

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

christophertitchen
Copy link

@christophertitchen christophertitchen commented Jan 27, 2025

Summary

  • Amend README.md to note support for in-sample fitted values for SimpleExponentialSmoothing, SimpleExponentialSmoothingOptimized, SeasonalExponentialSmoothing, and SeasonalExponentialSmoothingOptimized.
  • Set the first in-sample fitted value in _ses_fcst_mse to the first observation, rather than np.nan, to make it explicitly clear that the initial state is the first observation.
  • Improve the efficiency and performance of _ses_fcst_mse by, for example, pre-calculating the smoothing complement, $1 - \alpha$, and removing the unnecessary $n - 1$ copies of fitted values before assignment.
  • Improve the performance of _optimized_ses_forecast by changing from scipy.optimize.minimize to scipy.optimize.minimize_scalar. This uses Brent's method which is derivative-free and optimised for local one-dimensional optimisation problems like this, with guaranteed convergence within a reasonable number of evaluations. The convergence will also be superlinear for our strictly convex $C^2$ objective function when the minimum is at an interior point of the interval for $\alpha$, which will be the case particularly in SimpleExponentialSmoothingOptimized and SeasonalExponentialSmoothingOptimized, where $0 \lt \alpha \lt 1$. It should also be quite a bit faster even for the $0.1 \lt \alpha \lt 0.3$ bounds of ADIDA, Croston, and IMAPA. It also does not have the initialisation sensitivity that L-BFGS-B has (the initialisation of $\alpha$ was also out-of-bounds before for some reason).
  • Add a temporary benchmark to test_efficiency.py for CodSpeed.

Benchmarks

Memory Profile

Base

Head

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

codspeed-hq bot commented Jan 27, 2025

CodSpeed Performance Report

Merging #973 will not alter performance

Comparing christophertitchen:fix/ses-fitted (099d906) with main (fea7193)

Summary

✅ 6 untouched benchmarks

@jmoralez
Copy link
Member

jmoralez commented Feb 4, 2025

Thanks. Can you just elaborate on the following?

Set the first in-sample fitted value in _ses_fcst_mse to the first observation, rather than np.nan, to make it explicitly clear that the initial state is the first observation.

The fitted values are supposed to be the one-step ahead forecasts with an expanding training set, so the first value should be NaN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants