Skip to content

Compute missing spikes on the right tail of amplitude distributions - #4353

Merged
alejoe91 merged 7 commits into
SpikeInterface:mainfrom
ecobost:fix_amplitude_cutoff
Feb 2, 2026
Merged

alejoe91 merged 7 commits into
SpikeInterface:mainfrom
ecobost:fix_amplitude_cutoff

Conversation

@ecobost

@ecobost ecobost commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4352

I also refactored the code to be more legible and fixed a couple of details:

  1. use mode='nearest' during smoothing, default of reflect causes the edge to be higher and the cutoff will be overestimated.
  2. Fix how the fraction is computed to be num_missing / (total_recorded + num_missing) vs. num_missing/total_recorded (as it was before) which also overestimates the cutoff.
  3. Increase the default bin size to 200, 100 is a bit too high variance.

Here's the output for some examples (at 15% cutoff now):
image
The right missing amplitudes (for the middle example) are now correctly estimated to ~15%. Left missing amplitudes say 0 (correctly) as that is not where the missing spikes are expected to be (but rather at low absolute values, so the right)

@chrishalcrow

Copy link
Copy Markdown
Member

Hello, thanks so much for finding this - I agree with your results. There's a similar metric called noise_cutoff that has a test which is meant to check for this error.

A similar, test for amp cutoff might be:

def test_amplitude_cutoff():
    """
    Generate two artificial gaussians, one truncated and one not. Check the metrics are higher for the truncated one.
    """
    np.random.seed(1)
    amplitudes = np.random.normal(-3, 1, 2000)
    amplitudes_trunc = amplitudes[amplitudes < -4]

    fraction_missing_1 = amplitude_cutoff(amplitudes=amplitudes, num_histogram_bins=20)
    fraction_missing_2 = amplitude_cutoff(amplitudes=amplitudes_trunc, num_histogram_bins=20)

    assert fraction_missing_1 < fraction_missing_2

Could you check that and add this in please?

@ecobost

ecobost commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @chrishalcrow

Test passed locally, added it to the PR.

@ecobost

ecobost commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

Updated PR so both amplitude_cutoff and noise_cutoff receive positive amplitudes (so cutoff is correctly computed on the left tail of the distribution). I still refactored amplitude_cutoff to fix the minor details I listed in the original PR comment.

Additionally, I changed to invert the amplitudes per unit as, when analyzer.compute('spike_amplitudes', peak_sign='both') is used some units have positive amplitude values and some negative ones.

@chrishalcrow Sorry for the double reviews (I just today noticed that noise_cutoff also has the same assumption of the cutoff being on the left/lower side, so i think this way to deal with it is probably better)

@alejoe91 alejoe91 added the metrics Related to metrics module label Feb 2, 2026

@alejoe91 alejoe91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for spotting, fixing, and improving the implementation @ecobost

@alejoe91
alejoe91 merged commit 02e0e97 into SpikeInterface:main Feb 2, 2026
13 checks passed
@ecobost
ecobost deleted the fix_amplitude_cutoff branch February 2, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

metrics Related to metrics module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong computation of amplitude_cutoff in quality metrics

3 participants