NSSDNResult.forecast#
- NSSDNResult.forecast(steps=1, *, exog=None, time=None)[source]#
Recursive multi-step forecast from the end of the fitted sample.
The network is warmed up on the sample under teacher forcing, the last observation \(y_{n-1}\) is fed as the first future input, and every later input is the previous emission,
\[h_{n+s} = F_\psi\bigl(h_{n+s-1}, \hat y_{n+s-1}, \Delta t_{n+s}\bigr), \qquad \theta_{n+s,k} = \theta_{n+s-1,k} + \omega_{n+s,k}\,\Delta t_{n+s}, \qquad s = 1, \ldots, S,\]with \(\hat y_{n} \equiv y_{n-1}\) for the first step. Error accumulates with the horizon; the validation notebook found this mode far weaker than the conditional one-step mode under the filtered alignment, and the paper reports both for that reason.
- Parameters:
steps (
int) – Periods ahead \(S\), at least one.exog (
ArrayLike|None) –(steps, p)future covariates; required when the fit used them. A one-dimensional array is reshaped to(steps, -1).time (
ArrayLike|None) –(steps,)future grid aftertime[-1]; defaults to continuing at the sample’s last step size, so a regular grid needs nothing.
- Return type:
- Returns:
(steps,)forecasts on the original scale.- Raises:
SpecificationError – If
stepsis not a positive integer, ortimedoes not havestepsentries.DimensionError – If the future covariates are missing or mis-shaped for a fit that used them.
Example
>>> import numpy as np >>> y = np.sin(0.2 * np.arange(120.0)) >>> res = NSSDN(y, k=2, state_dim=8, schedule=(Stage(1e-2, 20),), seed=0).fit() >>> res.forecast(3).shape, res.forecast(1).shape ((3,), (1,)) >>> res.forecast(0) Traceback (most recent call last): ... ns_sdn.exceptions.SpecificationError: steps must be a positive integer; got 0.