ns_sdn.spectral_state#

Spectral-state coordinates: the decomposition read as a time-local measure.

At each step the fitted network places power

\[p_{t,k} = \bigl(|w_k|\, g_{t,k}\, A_{t,k}\bigr)^2,\]

the squared amplitude of its contribution, at frequency \(\omega_{t,k}\). Normalizing gives a probability measure on the frequency axis,

\[\mu_t = \sum_{k=1}^{K} w_{t,k}\,\delta_{\omega_{t,k}}, \qquad w_{t,k} = \frac{p_{t,k}}{\sum_{j=1}^{K} p_{t,j}},\]

and every coordinate here is a functional of \(\mu_t\):

  • its position, the power-weighted centroid \(\bar\omega_t = \sum_k w_{t,k}\,\omega_{t,k}\);

  • its spread, the power-weighted dispersion \(s_t = \bigl(\sum_k w_{t,k}(\omega_{t,k} - \bar\omega_t)^2\bigr)^{1/2}\);

  • its effective rank, the exponential of the spectral entropy \(N_t = \exp H_t\) with \(H_t = -\sum_k w_{t,k}\log w_{t,k}\), and the inverse participation ratio \(P_t = 1 / \sum_k w_{t,k}^2\), both in \([1, K]\);

  • its motion, the 1-Wasserstein distance between consecutive measures per unit time, \(v_t = W_1(\mu_t, \mu_{t-1}) / \Delta t_t\), split into the distance due to frequencies moving under frozen weights and the distance due to weights moving under frozen frequencies.

The two-axis reading of spectral compression is a joint contraction of dispersion and effective count. A contribution cross-correlation and the disentanglement score it implies are reported alongside, because the measure alone cannot tell converged frequencies from redundant components: two components at the same frequency with the same phase are one component counted twice, and the score is what says so.

These are diagnostics of a model trained on the prediction criterion alone; nothing here enters a loss. Frequencies and weights of a component whose weight falls below active_threshold are unidentified (a silent component’s frequency head receives no gradient from the prediction term), and the active mask says which rows a per-component reading should trust.

References

Villani, C. (2009). Optimal Transport: Old and New. Springer. Chapter 6, for the one-dimensional Wasserstein distance as the \(L^1\) distance between distribution functions.

Huang, N. E. et al. (1998). The empirical mode decomposition and the Hilbert spectrum for nonlinear and non-stationary time series analysis. Proc. R. Soc. A, 454, 903-995. For the instantaneous frequency as the object of a time-local spectral reading.

Example

>>> import numpy as np
>>> from ns_sdn.spectral_decomposition import NSSDN, Stage
>>> y = np.sin(0.3 * np.arange(240.0)) + 0.5 * np.sin(0.07 * np.arange(240.0))
>>> res = NSSDN(y, k=3, state_dim=8, schedule=(Stage(1e-2, 40),), seed=0).fit()
>>> state = res.spectral_state()
>>> state.weight.shape, state.velocity.shape, bool(np.all(state.effective_count <= 3.0))
((240, 3), (239,), True)

Classes#

SpectralState

The spectral-state coordinates of a fitted decomposition.