_predictors#

ns_sdn.engine._internals._predictors = <module 'ns_sdn.engine._internals._predictors' from '/home/runner/work/ns-sdn/ns-sdn/src/ns_sdn/engine/_internals/_predictors.py'>[source]#

The fitted network as a numpy-facing object.

A predictor owns a trained _SpectralNetwork, the scaling constants it was trained under, the alignment it was trained with, and the configuration needed to rebuild it. It runs the network in its two modes and returns numpy paths, on the original scale unless asked for in training units, so nothing above this module touches torch. It pickles through the state dict, which is what lets a result be serialized without a reference to a live module.

The alignment is implemented here and nowhere else, as the layout of the teacher-forced inputs (_SpectralPredictor.inputs()): which observation sits in the input row at \(t\), which is the target, and what the first step size is. Everything downstream (the trainer, the network, the result) sees rows and targets and is alignment-agnostic.

Example

>>> import numpy as np
>>> from ns_sdn.spectral_decomposition import NSSDN, Stage
>>> y = np.sin(0.3 * np.arange(60.0))
>>> res = NSSDN(y, k=2, state_dim=8, schedule=(Stage(1e-2, 5),), seed=0).fit()
>>> pred = res.predictor
>>> pred.alignment, pred.mix.shape, pred.n_parameters == res.n_params
('filtered', (2,), True)
>>> x, dt, target = pred.inputs(y, None, np.arange(60.0))
>>> tuple(x.shape), float(dt[0]), bool(np.allclose(target.numpy(), pred.scale.transform(y)))
((60, 1), 0.0, True)