-
Notifications
You must be signed in to change notification settings - Fork 22
ADAM
ADAM is the primary unified framework in the smooth package, combining ETS (Error-Trend-Seasonal), ARIMA, and regression components into a single state-space model using the Single Source of Error (SSOE) approach.
The ADAM model is specified in state-space form as:
y_t = o_t(w(v_{t-l}, x_t) + r(v_{t-l})ε_t)
v_t = f(v_{t-l}, a_{t-1}) + g(v_{t-l}, a_{t-1}, x_t)ε_t
Where:
-
y_t: Observed value at time t -
o_t: Occurrence indicator (for intermittent data) -
v_t: State vector (level, trend, seasonal, ARIMA components, regression parameters) -
l: Vector of lags -
x_t: Vector of exogenous variables -
w(·): Measurement function -
r(·): Error function (additive or multiplicative) -
f(·): Transition function (state evolution) -
g(·): Persistence function (smoothing parameters) -
ε_t: Error term
- Unified Framework: Seamlessly combines ETS, ARIMA and regression in a single model
- Multiple Seasonality: Supports multiple seasonal periods (e.g., daily + weekly)
- Automatic Selection: Branch & Bound algorithm for efficient model selection
- Flexible Distributions: Normal, Laplace, Gamma, Log-Normal, Inverse Gaussian, S, Generalized Normal
- Intermittent Demand: Built-in occurrence models for sparse data
- External Regressors: Include covariates with adaptive or fixed coefficients
Models are specified using a three-letter (or four-letter in case of damped trend) string "ETS":
- E (Error): "A" (Additive), "M" (Multiplicative)
- T (Trend): "N" (None), "A" (Additive), "Ad" (Additive Damped), "M" (Multiplicative), "Md" (Multiplicative Damped)
- S (Seasonal): "N" (None), "A" (Additive), "M" (Multiplicative)
Examples:
-
model="ANN": Simple Exponential Smoothing -
model="AAN": Holt's Linear Trend -
model="AAdA": Holt-Winters Additive with damped trend -
model="MAM": Multiplicative Holt-Winters
Read more about ETS in Svetunkov (2023), Chapters 4 - 7.
-
"ZZZ": Select best model using Branch & Bound -
"XXX": Select only additive components -
"YYY": Select only multiplicative components -
"ZXZ": Auto-select error and seasonal, additive trend only (default, safer) -
"FFF": Full search across all 30 ETS model types -
"PPP": Check pure additive and pure multiplicative models only -
"SSS": Pool of safe models from the forecast package. Letters can be substituted with "X" and "Y" to narrow the pool down. -
"CCC": AIC-based combination of ETS models. Also supports narrower pools, e.g. "CCN". - Vector of models, e.g.
c("ANN","AAN","AAA")- will test models in the specified pool.
Model selection is explained in Svetunkov (2023), Section 15.1.
Specified via list in orders, e.g. orders=list(ar=c(1,2), i=c(1,1), ma=c(2,2)). Requires lags to be specified explicitly.
To switch off ARIMA, provide model="NNN" in the adam() call.
Note: Python does not support ARIMA at the moment.
Read more about ARIMA in Svetunkov (2023), Chapter 8 and Chapter 9.
Main loss functions (see Supported Loss Functions subsection below for more):
-
"likelihood": Maximum likelihood (default) -
"MSE": Mean Squared Error -
"MAE": Mean Absolute Error -
"HAM": Half-Absolute Moment -
"LASSO": use LASSO to shrink the parameters of the model; -
"RIDGE": use RIDGE to shrink the parameters of the model; -
"GTMSE": Geometric Trace Mean Squared Error, -
"GPL": Generalised Predictive Likelihood, - custom loss - define your own loss function and use it in the model estimation.
Read more about loss functions in Svetunkov (2023), Chapter 11.
Fixed smoothing parameters can be provided:
Python usage:
model = ADAM(
model="AAA",
lags=12,
persistence={"alpha": 0.3, "beta": 0.1, "gamma": 0.05}
)R usage:
model = adam(y, model="AAA", lags=12,
persistence=list(alpha=0.3, beta=0.1, gamma=0.05))-
alpha: Level smoothing (0 to 1) -
beta: Trend smoothing (0 to alpha) -
gamma: Seasonal smoothing (0 to 1-alpha)
If some of parameters are not provided, they will be estimated.
-
"backcasting": Use backcasting (default, faster) -
"optimal": Optimize all initial states -
"two-stage": Backcast then optimize -
"complete": Pure backcasting without optimization - provided: User can provide a vector or a list of parameters for the function to use.
More detailed explanation of those is provided in Section 11.4 of Svetunkov (2023).
from smooth import ADAM
import numpy as np
# Sample data
y = np.array([112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 104, 118] * 3)
# Automatic model selection
model = ADAM(model="ZXZ", lags=12, ic="AICc")
model.fit(y)
# Model output
print(model)
# Generate forecasts with intervals
forecasts = model.predict(h=12, calculate_intervals=True, level=0.95)
# Access fitted parameters
print(f"Model: {model.model_type_dict['model']}")
print(f"Alpha: {model.persistence_level_:.3f}")
print(f"AICc: {model.ic_selection}")# 1. Automatic Forecasting
model = ADAM(model="ZXZ", lags=12)
# 2. Multiple Seasonality (hourly with daily/weekly)
model = ADAM(model="AAA", lags=[24, 168])
# 3. Advanced loss functions. Mean Absolute Error
model = ADAM(model="AAA", lags=12, loss="MAE")
# 4. Advanced loss functions. Multistep loss
model = ADAM(model="AAA", lags=12, loss="GTMSE", h=12)
# 5. Custom loss functions
def loss_function(actual, fitted, B):
return np.mean(np.abs(actual - fitted)^3)
model = ADAM(model="AAA", lags=12, loss=loss_function)library(smooth)
# Automatic model selection
model <- adam(y, model="ZZZ", lags=12)
print(model)
forecast(model, h=12)
# Pure MSARIMA
model <- adam(y, model="NNN", orders=list(ar=c(1,1), i=c(1,1), ma=c(1,1)), lags=c(1,12))
# ETS(A,A,N) With external regressors
ourData <- cbind(y, X)
model <- adam(ourData, model="AAN", formula=y~x1+x2)
# ETS(A,A,N) + AR(1) with holdout of 18 last observations
model <- adam(y, model="AAN", orders=c(1,0,0), h=18, holdout=TRUE)| Parameter | Type (R) | Type (Python) | Default | Description |
|---|---|---|---|---|
model |
character/vector | str/List[str] | "ZXZ" | Model specification string or list |
lags |
numeric vector | int/List[int]/None | frequency(y) |
Seasonal period(s) |
orders |
list | - | NULL/None | ARIMA orders (R only) |
| Parameter | Type (R) | Type (Python) | Default | Description |
|---|---|---|---|---|
distribution |
character | str/None | "default" | Error distribution |
loss |
character | str | "likelihood" | Loss function for estimation |
ic |
character | str | "AICc" | Information criterion for model selection |
bounds |
character | str | "usual" | Parameter bounds type |
initial |
character/list/vector | str/Dict/None | "backcasting" | Initialization method |
persistence |
list/vector | Dict[str, float]/None | NULL/None | Fixed smoothing parameters |
phi |
numeric | float/None | NULL/None | Damping parameter |
h |
integer | int/None | 0 | Forecast horizon |
holdout |
logical | bool | FALSE | Use holdout validation |
-
"likelihood": Maximum likelihood (default) -
"MSE","MAE","HAM": Standard error measures -
"MSEh","MAEh","HAMh": Multi-step versions -
"TMSE","TMAE","THAM": Trace versions -
"GTMSE","GTAME","GTHAM": Geometric trace versions -
"GPL": Generalised Predictive Likelihood -
"LASSO","RIDGE": Regularization
-
"dnorm": Normal (default for additive errors) -
"dgamma": Gamma (default for multiplicative errors) -
"dlaplace": Laplace (heavy-tailed) -
"dlnorm": Log-Normal (positive data) -
"dinvgauss": Inverse Gaussian -
"ds": S distribution (extremely heavy-tailed) -
"dgnorm": Generalized Normal
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
model |
model_type_dict['model'] |
character | str | Name of the constructed model |
timeElapsed |
- | difftime | - | Time elapsed for model estimation |
call |
- | call | - | The function call used |
bounds |
- | character | - | Type of bounds used in estimation |
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
data |
- | matrix/ts | - | In-sample data used for training |
holdout |
- | vector/ts | - | Holdout part of data |
fitted |
prepared_model['y_fitted'] |
vector | NDArray | Vector of fitted values |
residuals |
prepared_model['residuals'] |
vector | NDArray | Vector of residuals |
forecast |
predict() result |
vector | NDArray | Point forecast for h steps ahead |
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
states |
adam_created['mat_vt'] |
matrix | NDArray | Matrix of states |
persistence |
persistence_level_, persistence_trend_, persistence_seasonal_
|
vector | float/List[float] | Smoothing parameters (α, β, γ) |
phi |
phi_ |
numeric | float | Damping parameter value |
transition |
adam_created['mat_f'] |
matrix | NDArray | Transition matrix F |
measurement |
adam_created['mat_wt'] |
matrix | NDArray | Measurement matrix w |
initial |
initial_states_ |
list | NDArray | Initial state values |
initialEstimated |
- | vector | - | Which initials were estimated |
initialType |
- | character | - | Initialization method used |
| Element (R) | Type (R) | Description |
|---|---|---|
orders |
list | ARIMA orders used |
arma |
list | List of AR/MA parameters |
constant |
numeric | Constant/drift value |
lags |
vector | Vector of lags used |
lagsAll |
vector | Vector of internal lags |
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
nParam |
- | matrix | - | Matrix of estimated/provided parameters count |
loss |
- | character | - | Loss function type used |
lossValue |
- | numeric | - | Value of the loss function |
logLik |
- | numeric | - | Log-likelihood value |
distribution |
- | character | - | Distribution function used |
scale |
- | numeric | - | Scale parameter value |
ICs |
ic_selection |
vector | float | Information criterion value |
ICw |
- | vector | - | IC weights if combination was done |
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
B |
adam_estimated['B'] |
vector | NDArray | Vector of all estimated parameters |
occurrence |
- | oes object | - | OES model for intermittent demand |
formula |
- | formula | - | Formula for explanatory variables |
profile |
- | matrix | - | Profile matrix used in construction |
profileInitial |
- | matrix | - | Initial profile matrix |
lambda |
- | numeric | - | LASSO/RIDGE parameter |
res |
- | list | - | Optimisation result from nloptr()
|
other |
- | list | - | Additional parameters |
| - | model_type_dict |
- | Dict | Complete model specification |
model <- adam(y, model="AAA", lags=12)
# Model name
modelName(model)
# Type of the ETS model
modelType(model)
# ARIMA orders and lags
orders(model)
lags(model)
# Smoothing parameters
model$persistence
# Initial states
model$initial
# Fitted values and residuals
fitted(model)
residuals(model)
# State matrix
model$states
# Information criteria (via methods)
AIC(model)
BIC(model)
logLik(model)
# Coefficients
coef(model)
# Summary with confidence intervals
summary(model)model = ADAM(model="AAA", lags=[12])
model.fit(y)
# Model name
model.model_type_dict['model']
# Smoothing parameters
model.persistence_level_
model.persistence_trend_
model.persistence_seasonal_
# Damping parameter
model.phi_
# Initial states
model.initial_states_
# Fitted values and residuals
model.prepared_model['y_fitted']
model.prepared_model['residuals']
# State matrix
model.adam_created['mat_vt']
# Information criterion
model.ic_selection
# All estimated parameters
model.adam_estimated['B']- Svetunkov, I. (2023). Forecasting and Analytics with the Augmented Dynamic Adaptive Model (ADAM). Chapman and Hall/CRC. Online book: https://openforecast.org/adam/
- Hyndman, R.J., et al. (2008). Forecasting with Exponential Smoothing: The State Space Approach. Springer.