NSSDN.fit#
- NSSDN.fit()[source]#
Train the network on the sample and return the fitted result.
In order: the series is scaled (min-max to \([-1, 1]\) or left as is), the network is built and seeded, the teacher-forced inputs are laid out under the alignment, every stage of the schedule runs a fresh Adam optimizer for its steps on the staged criterion, the trained network is run once more over the sample to produce the paths, and the one-step residuals, their variance and the concentrated likelihood are formed from the emission rows the alignment designates as predictions.
- Return type:
- Returns:
The
NSSDNResult.- Raises:
NumericalError – If the loss becomes non-finite at any step; the message names the stage and step. Lower the learning rate or scale the series.
Example
>>> import numpy as np >>> y = np.sin(0.3 * np.arange(200.0)) >>> res = NSSDN(y, k=2, state_dim=8, schedule=(Stage(1e-2, 30),), seed=0).fit() >>> res.nobs, res.trend.shape, res.state.shape, res.fittedvalues.shape (199, (200,), (200, 8), (199,))
The same seed gives the same fit:
>>> again = NSSDN(y, k=2, state_dim=8, schedule=(Stage(1e-2, 30),), seed=0).fit() >>> bool(np.allclose(res.emission, again.emission)) True