Skip to content

Wrong computation of amplitude_cutoff in quality metrics #4352

Closed

Description

@ecobost

Although a bit hard to parse, I am positive amplitude_cutoff

def amplitude_cutoff(amplitudes, num_histogram_bins=500, histogram_smoothing_value=3, amplitudes_bins_min_ratio=5):

is currently computing the cutoff happening on the left side of the amplitude distribution (see figure below, right) but amplitudes are negative (or forced to be negative in L.876-883) and the expected cutoff would be on the right side, low amplitude spikes near zero values (Fig., middle), thus the current computation is not doing what it was intended to do.

Here's the current output for a couple of amplitude distribution examples (with ~15% cutoff) to show the issue.
Image

Activity

  1. ecobost commented on Jan 30, 2026

    @ecobost
    ContributorAuthor

    Delved deeper into this.

    Spikeinterface documentation for the function does say (source):

    To calculate the approximate fraction of missing spikes, we look at the height of the lowest amplitude bin, and count the number of spikes at the upper end of the distribution with amplitudes above a bin of similar height.

    which correctly describes the current method (i.e, find the cutoff on the left/lower side).

    Same with the documentation for noise_cutoff:

    For a given unit, the metric supposes that the lower bin of the amplitudes distribution will be high, i.e. will exhibit a sharp cut-off

    (source)
    Image
    (source)

    The works because IBL uses amplitudes "in absolute SI units" (perhaps from kilosort, akin to the amplitude_scalings in spikeinterface) which are positive only. This is why they also have a median(amplitude) > 50 threshold for "good" recordings (which again would not make sense if the amplitudes were negative).

    If amplitudes are negative (e.g., -100 to -10 μV): low (most negative) values (e.g., -90 to -100 μV) are high absolute amplitude so most stable spikes and high (least negative) values (e.g., -20 to -10 μV) are low absolute amplitude, "small spikes", near zero. Original source (Hill et al., 2011) agrees with this intuition:
    Image

    I propose, instead of modifying the methods which were designed to work for positive amplitudes (finding the cutoff on the left/lower side of the distribution), we invert negative amplitudes before sending them to these methods (Currently it is doing the opposite, see below, I presume, because SI uses mainly negative amplitudes by default):

    if sorting_analyzer.has_extension("spike_amplitudes"):
    extension = sorting_analyzer.get_extension("spike_amplitudes")
    all_amplitudes = extension.get_data()
    invert_amplitudes = np.median(all_amplitudes) > 0
    elif sorting_analyzer.has_extension("amplitude_scalings"):
    # amplitude scalings are positive, we need to invert them
    invert_amplitudes = True
    extension = sorting_analyzer.get_extension("amplitude_scalings")

  2. chrishalcrow commented on Jan 30, 2026

    @chrishalcrow
    Member

    Yes, historically this is ported from the allen SDK, which mostly used kilosort 2.5 amplitude output, which is more akin to amplitude scalings. And we were not careful enough in porting/testing. I don't mind which way we fix this. I think either is ok, as along as it's clear in the docstring of the function. @alejoe91 any thoughts on which way is a better way to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions