N-HiTS: neural hierarchical interpolation for time series forecasting.
Classes
N-HiTS: N-BEATS with multi-rate sampling and hierarchical interpolation.
N-HiTS keeps the doubly-residual skeleton of N-BEATS and adds the two ideas that make long horizons tractable. First, multi-rate signal sampling: each stack max-pools its input at a different rate before the fully connected trunk sees it, so a stack with a large pooling size literally cannot see high-frequency detail and is forced to model the slow component. Second, hierarchical interpolation: a stack predicts only a handful of knots and interpolates them up to the full horizon, so the number of parameters in the output layer no longer grows with the horizon.
Together the two make the stacks specialise by frequency — coarse stacks supply the smooth backbone, fine stacks the detail — while cutting both compute and parameter count against N-BEATS at long horizons. Remove either one and what remains is N-BEATS with extra steps.
__init__( self, lookback: int = 24, horizon: int = 8, pooling_sizes: Tuple[int, Ellipsis] = (), n_freq_downsample: Tuple[int, Ellipsis] = (), n_blocks: int = 1, n_layers: int = 2, hidden_size: int = 64, interpolation_mode: str = 'linear', backcast_loss_weight: float = 0.5, n_epochs: int = 100, batch_size: int = 32, learning_rate: float = 0.001, patience: int = 15, device: str = 'cpu', random_state: Optional[int] = None, )
Overview
-
Slide a
(lookback, horizon)window over the series and normalise
- For stack s, max-pool the incoming residual with kernel
- Run the pooled signal through a fully connected trunk and predict
- Interpolate both back to full resolution: the backcast to the lookback,
- Subtract the backcast, pass the residual on, and sum the forecasts.
Theory
Stack s first pools its input x_s at rate k_s,
which acts as an anti-alias filter: frequencies above 1/(2k_s) are removed before the trunk sees them. The trunk emits knots \theta_s \in \mathbb{R}^{\lceil H/r_s \rceil} that are expanded by a temporal interpolation operator g,
with g linear interpolation over the knot grid. Choosing r_s in step with k_s gives each stack a matched input and output bandwidth; the forecast is again the sum, \hat{y} = \sum_s \hat{y}_s, over residuals x_{s+1} = x_s - \hat{x}_s.
Parameters
lookback
horizon
pooling_sizes
n_freq_downsample
ceil(horizon / ratio) knots. Must be the same length as pooling_sizes.
n_blocks
n_layers
hidden_size
interpolation_mode
backcast_loss_weight
n_epochs
batch_size
learning_rate
patience
device
"cpu" because it is the only setting that gives bit-identical forecasts across machines; use "auto" when speed matters more than exact reproducibility.
random_state
Attributes
module_
lookback_
horizon_
n_windows_
offset_
scale_
series_
loss_curve_
n_epochs_run_
device_
Notes
Requires PyTorch: pip install 'tuiml[torch]'. The class imports, constructs, registers and reports its schema without torch; only fit needs it.
Complexity:
- Training: O(E \cdot W \cdot S \cdot B \cdot h^2) for
- Prediction: O(\lceil s / H \rceil \cdot S \cdot B \cdot h^2).
- Long horizons, where N-BEATS output layers become the bottleneck.
- Series with structure at clearly separated timescales.
- When you want N-BEATS accuracy at a fraction of the parameters.
- Not for very short series; a classical model will usually win.
References
See Also
>>> import numpy as np
>>> from tuiml.algorithms.timeseries.deep import NHITSForecaster
>>> from tuiml.utils.torch_backend import has_torch
>>> model = NHITSForecaster(lookback=24, horizon=6, random_state=0)
>>> model.pooling_sizes
(4, 2, 1)
>>> if has_torch():
... y = np.sin(np.arange(200) / 5.0)
... _ = model.fit(y)
... print(model.predict(steps=6).shape)
... else:
... print("(6,)")
(6,)
Functions
Return the length of a max-pooled sequence.
ceil_mode, so a partial final window still yields an output point and no data is silently dropped from the end of the lookback — the end being the part that matters most for a forecast.Parameters
length
pooling_size
Returns
length
>>> from tuiml.algorithms.timeseries.deep.nhits import pooled_length
>>> pooled_length(24, 4), pooled_length(10, 4), pooled_length(3, 8)
(6, 3, 1)
Return how many knots a stack predicts before interpolating up.
Parameters
horizon
downsample
Returns
n_knots
horizon.
>>> from tuiml.algorithms.timeseries.deep.nhits import interpolation_length
>>> interpolation_length(24, 8), interpolation_length(24, 1)
(3, 24)