Repository navigation
Add mel EDR, echo density and envelope losses (contributed by Riccardo Giampiccolo) - #257
Merged
Merged
Conversation
MatchMelEnergyDecayRelief: multi-resolution mel energy decay relief in dB, normalized L^p error (new RelativeError distance). MatchEchoDensity: MSE of a differentiable (sigmoid-thresholded) normalized echo density profile. Both are ports onto the Feature/Distance/Match pipeline, checked numerically against the original code; the EDP is vectorized with unfold and clamps sigma so silent windows no longer give NaN gradients. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MatchEnvelope: normalized L^2 error of a peak-follower envelope of h^2, zero-phase low-passed, from Riccardo's corrected version (release time in seconds, FIR length and band edges in Hz so defaults hold across rates). The per-sample peak-follower loop is replaced by a blockwise cummax and torchaudio's filtfilt by two conv1d calls; matches the original to 2e-8. Note that the mel EDR defaults were tuned at 16 kHz. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports three of the losses Riccardo Giampiccolo shared after DAFx into the composable
Matchframework.New
MatchMelEnergyDecayRelief: multi-resolution mel EDR (mel power spectrogram, backward-integrated over frames, dB with 80 dB floor), normalized L^p error averaged over resolutions. Defaults are Riccardo's.MatchEchoDensity: MSE of the differentiable normalized echo density profile (Abel & Huang with sigmoid threshold, kappa ramped 1e2 → 1e5).MatchEnvelope: normalized L² error of a peak-follower envelope of h² (release 0.28 ms), zero-phase low-passed (least-squares FIR, 3.2 → 4.8 kHz transition). Ported from Riccardo's corrected version, where the release time is in seconds and the FIR length and band edges are in Hz, so the defaults hold at any sample rate.PeakEnvelope,MelEnergyDecayReliefandEchoDensityProfilefeatures,RelativeErrordistance (|p-t|^p / mean|t|^p).Differences from the original
unfoldinstead of a per-sample Python loop. The profile is evaluated everyhopsamples, which defaults to a quarter window;hop=1matches the original exactly, but memory grows as nfft × window.sqrt. The original gives NaN gradients in any all-zero window, e.g. before an FDN's first delay.response.fs. The originalEDPLossalways assumed 16 kHz.cummax, and torchaudio'sfiltfiltby twoconv1dcalls. Relative difference from the original is 2e-8, and it runs 20–50× faster in the forward pass alone.Checked against the original code at 16 kHz: EDP max difference 2e-6, envelope 2e-8 relative (16 and 48 kHz), mel-EDR loss 0.198954 vs 0.198962, EDP loss 0.009212 vs 0.009211.
Not ported
EDCLoss(broadband linear EDC): covered byMatchEnergyDecay/energy_decay_curve+Match.ICLDLoss: specific to the FOA sound-field project. Riccardo confirmed thatgz = sin(az)should besin(el), and that comparing only the x/y pair was a choice to stay in the horizontal plane. Deferred to that project.Follow-up
Tests
tests/test_losses_features.py: both losses get finite gradients on silent inputs, EDP ≈ 1 on Gaussian noise and < 0.2 on a click train, and mel-EDR is zero on the target. The envelope's blockwisecummaxequals the sample-by-sample recursion, including across a gap longer than one block. The envelope loss is left out of the silent-target gradient test because an error relative to a silent target is undefined. The 3 failures intest_train.py(MPS device tests andtest_a_trained_rt_still_decays) also fail onmain.🤖 Generated with Claude Code