NSSDNResult.predict#

NSSDNResult.predict(endog, *, exog=None, time=None)[source]#

One-step conditional predictions over a sample.

Runs the trained network from its learned initial state under teacher forcing and returns, for each \(y_{i+1}\), the emission built from the realized values the alignment allows: through \(y_i\) under both alignments, which under the filtered one is the emission at \(i\),

\[\begin{split}\hat y_{i+1 \mid i} = \begin{cases} \hat y_i, & \text{filtered: the emission after } y_i,\\ \hat y_{i+1}, & \text{predicted: the row that targets } y_{i+1}. \end{cases}\end{split}\]

The published holdout protocol is res.predict(np.concatenate([train, holdout]))[-len(holdout):], the paper’s yhat[split - 1 : -1] against y[split:]: the network conditions on the realized holdout values one step at a time, which is a conditional one-step forecast and not a recursive one.

Parameters:
  • endog (ArrayLike) – The series, at least two observations, on the original scale.

  • exog (ArrayLike | None) – (len(endog), p) covariates aligned with endog; required when the fit used them.

  • time (ArrayLike | None) – (len(endog),) strictly increasing grid; the integers when None.

Return type:

NDArray[double]

Returns:

(len(endog) - 1,) predictions on the original scale, aligned with endog[1:].

Raises:
  • DimensionError – If endog is mis-shaped or too short, or if exog or time is misaligned or the covariate width differs from the fit’s.

  • NumericalError – If any input contains non-finite values.

  • SpecificationError – If time is not strictly increasing.

Example

On the fitted sample the predictions are the result’s own fittedvalues:

>>> 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()
>>> bool(np.allclose(res.predict(y), res.fittedvalues))
True