_objectives#

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

a prediction loss plus drift and sparsity penalties.

The criterion is

\[\mathcal{L} = \mathcal{L}_{\mathrm{pred}}(\hat y - y) + \lambda_A \mathcal{P}_A + \lambda_\omega \mathcal{P}_\omega + \lambda_\theta \mathcal{P}_\theta + \lambda_B \mathcal{P}_B + \lambda_{\mathrm{sp}} \mathcal{P}_{\mathrm{sp}} + \lambda_{\mathrm{spec}} \mathcal{P}_{\mathrm{spec}},\]

with the prediction term the mean squared or Huber loss on the scaled residual and the penalties the TVP-VAR intuition that spectral parameters should move slowly: squared first differences of the gated amplitude and of the instantaneous frequency (the two the published run used), optional second differences of the phase, first differences of the trend, a group penalty that drives whole components to silence, and a power-spectrum match. The terms are written out on Penalties. All are evaluated on the scaled series and reported separately, unweighted, in the training history so a stage can be read as a trade-off, not a total.

Example

>>> import torch
>>> from ns_sdn.spectral_decomposition import Penalties
>>> paths = {
...     "yhat": torch.zeros(4), "amplitude": torch.ones(4, 2), "frequency": torch.ones(4, 2),
...     "phase": torch.zeros(4, 2), "trend": torch.zeros(4),
... }
>>> total, parts = _criterion(
...     torch.ones(4), paths, Penalties(), objective="mse", delta=1.0, nfft=8
... )
>>> float(total), sorted(parts)
(1.0, ['amplitude', 'frequency', 'prediction'])
Type:

The training criterion