-
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_name}") # e.g., "ETS(AAN)"
print(f"ETS type: {model.model_type}") # e.g., "AAN"
print(f"Alpha: {model.persistence_vector['persistence_level']:.3f}")
print(f"AICc: {model.aicc}")# 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 | Dampening 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 |
|---|---|---|---|---|
| - |
fit() result |
- | NDArray | Fits the model to the provided data |
forecast |
predict() result |
vector | NDArray | Point forecast for h steps ahead |
Read more in Fitted-Values-and-Forecasts.
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
modelName() |
model_name |
character | str | Full model name (e.g., "ETS(AAN)", "ETS(AAA)+ARIMA(1,1,1)") |
modelType() |
model_type |
character | str | ETS type code only (e.g., "AAN", "AAdN") |
timeElapsed |
time_elapsed |
difftime | float | Time elapsed for model estimation (seconds) |
call |
- | call | - | The function call used |
bounds |
- | character | - | Type of bounds used in estimation |
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
data |
data or actuals
|
matrix/ts | NDArray | In-sample data used for training |
holdout |
holdout_data |
vector/ts | NDArray/None | Holdout part of data |
fitted |
fitted |
vector | NDArray | Vector of fitted values |
residuals |
residuals |
vector | NDArray | Vector of residuals |
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
states |
states |
matrix | NDArray | Matrix of states over time |
persistence |
persistence_vector |
vector | Dict | Smoothing parameters for the estimated values of α, β, γ, δ |
phi |
phi_ |
numeric | float/None | Dampening parameter value (None if no dampening) |
transition |
transition |
matrix | NDArray | Transition matrix F |
measurement |
measurement |
matrix | NDArray | Measurement matrix W |
initial |
initial_value |
list | Dict | Initial state values dict |
initialEstimated |
- | vector | - | Which initials were estimated |
initialType |
initial_type |
character | str | 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 |
n_param |
matrix | Any | Parameter count information |
loss |
loss_ |
character | str | Loss function type used |
lossValue |
loss_value |
numeric | float | Value of the loss function |
logLik |
loglik |
numeric | float | Log-likelihood value |
distribution |
distribution_ |
character | str | Distribution function used |
scale |
scale or sigma
|
numeric | float | Scale parameter value |
AIC |
aic |
numeric | float | Akaike Information Criterion |
AICc |
aicc |
numeric | float | Corrected AIC |
BIC |
bic |
numeric | float | Bayesian Information Criterion |
BICc |
bicc |
numeric | float | Corrected BIC |
ICw |
- | vector | - | IC weights if combination was done |
| Element (R) | Element (Python) | Type (R) | Type (Python) | Description |
|---|---|---|---|---|
B |
coef or b_value
|
vector | NDArray | Vector of all estimated parameters |
occurrence |
- | oes object | - | OES model for intermittent demand |
formula |
- | formula | - | Formula for explanatory variables |
profile |
profile |
matrix | Any | Profile matrix used in construction |
profileInitial |
- | matrix | - | Initial profile matrix |
constant |
constant_value |
numeric | float/None | Constant/intercept term value |
lags |
lags_used |
vector | List | Vector of lags used |
lambda |
- | numeric | - | LASSO/RIDGE parameter |
res |
- | list | - | Optimisation result from nloptr()
|
other |
- | list | - | Additional parameters |
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 and type
model.model_name # Full name: "ETS(AAA)"
model.model_type # ETS code: "AAA"
# Smoothing parameters (dict with persistence_level, persistence_trend, persistence_seasonal)
model.persistence_vector
model.persistence_vector['persistence_level'] # alpha
# Dampening parameter (None if no damping)
model.phi_
# Initial states
model.initial_value
# Fitted values and residuals
model.fitted
model.residuals
# State matrix
model.states
# Information criteria
model.aic
model.aicc
model.bic
# All estimated parameters
model.coef
# Distribution and loss function (trailing _ for fitted values)
model.distribution_
model.loss_
model.loss_value
# Scale parameter
model.scale # or model.sigma- 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.
- ES - ETS wrapper of ADAM
- CES - Complex Exponential Smoothing
- SSARIMA - State Space ARIMA
- MSARIMA - Multiple Seasonal ARIMA
- Model-Specification - Model string notation and selection
- Orders-and-Lags - ARIMA orders and seasonal lags
- Loss-Functions - Loss function options
- Explanatory-Variables - Using external regressors
- Initialisation - State initialization methods
- Persistence - Smoothing parameters
- Bounds - Parameter restrictions