pyFDN.FlatSpectrogram#

class pyFDN.FlatSpectrogram(*, nfft=(256, 512, 1024, 2048), overlap=0.75)[source]#

Flatness measured on multi-resolution smoothed spectra – colorless.

The multi-scale sibling of FlatMagnitude, and the one whose frequency resolution is its own business rather than the model’s. For each analysis window \(n\), the short-time magnitudes are averaged over frames into a smoothed (Welch) spectral estimate, which is then normalized by its own mean and fitted to flat:

\[P_n[f] = \sqrt{\big\langle |S_n[t, f]|^2 \big\rangle_t}, \qquad \mathcal{L} = \frac{1}{|W|} \sum_{n \in W} \Big\langle \Big( \frac{P_n[f]}{\langle P_n \rangle_f} - 1 \Big)^2 \Big\rangle_f\]

A short window smooths heavily and constrains the broad spectral tilt; a long one resolves individual modes. Because each scale is normalized by its own mean, the loss is invariant to overall gain – it fits spectral shape only, and needs no assumption that \(|H| \approx 1\). Averaging over frames before measuring flatness is the whole design (per-frame flatness rewards an impulsive, comb-filtered IR); see the design note.

Parameters:
  • nfft (tuple[int, ...]) – STFT window sizes, each no longer than the model’s nfft. The default spans a factor of eight, which is what makes the objective multi-scale; one window alone is just a smoothed FlatMagnitude.

  • overlap (float) – Fractional overlap between frames (0.75 -> hop of a quarter window).

Notes

The loss value is not comparable with FlatMagnitude’s (the smoothing removes most of the mode-to-mode fluctuation), but it is far more stable against the model’s nfft.

__init__(*, nfft=(256, 512, 1024, 2048), overlap=0.75)[source]#

Methods

__init__(*[, nfft, overlap])

check(model)

Preflight against the model it will train, before the first step.

terms()

Flatten into (weight, loss) leaves.

Attributes

name

Short label, used as the key in pyFDN.TrainLog.loss_log.