|
1 | | -Noise cutoff (not currently implemented) |
2 | | -======================================== |
| 1 | +Noise cutoff (:code:`noise_cutoff`) |
| 2 | +=================================== |
3 | 3 |
|
4 | 4 | Calculation |
5 | 5 | ----------- |
6 | 6 |
|
7 | 7 |
|
8 | | -Metric describing whether an amplitude distribution is cut off, similar to _amp_cutoff :ref:`amplitude cutoff <amp_cutoff>` but without a Gaussian assumption. |
9 | | -A histogram of amplitudes is created and quantifies the distance between the low tail, mean number of spikes and high tail in terms of standard deviations. |
| 8 | +Metric describing whether an amplitude distribution is cut off as it approaches zero, similar to :ref:`amplitude cutoff <amp_cutoff>` but without a Gaussian assumption. |
10 | 9 |
|
11 | | -A SpikeInterface implementation is not yet available. |
| 10 | +The **noise cutoff** metric assesses whether a unit’s spike‐amplitude distribution is truncated |
| 11 | +at the low-end, which may be due to the high amplitude detection threshold in the deconvolution step, |
| 12 | +i.e., if low‐amplitude spikes were missed. It does not assume a Gaussian shape; |
| 13 | +instead, it directly compares counts in the low‐amplitude bins to counts in high‐amplitude bins. |
| 14 | + |
| 15 | +1. **Build a histogram** |
| 16 | + |
| 17 | + For each unit, divide all amplitudes into ``n_bins`` equally spaced bins over the range of the amplitude. |
| 18 | + If the number of spikes is large, you may consider using a larger ``n_bins``. For a small number of spikes, consider a smaller ``n_bins``. |
| 19 | + Let :math:`n_i` denote the count in the :math:`i`-th bin. |
| 20 | + |
| 21 | +2. **Identify the “low” region** |
| 22 | + - Compute the amplitude value at the specified ``low_quantile`` (for example, 0.10 = 10th percentile), denoted as :math:`\text{amp}_{low}`. |
| 23 | + - Find all histogram bins whose upper edge is below that quantile value. These bins form the "low‐quantile region". |
| 24 | + - Compute |
| 25 | + |
| 26 | + .. math:: |
| 27 | + L_{\mathrm{bins}} = \bigl\{i : \text{upper_edge}_i \le \text{amp}_{low}\bigr\}, \quad |
| 28 | + \mu_{\mathrm{low}} = \frac{1}{|L_{\mathrm{bins}}|}\sum_{i\in L_{\mathrm{bins}}} n_i. |
| 29 | +
|
| 30 | +3. **Identify the “high” region** |
| 31 | + |
| 32 | + - Compute the amplitude value at the specified ``high_quantile`` (for example, 0.25 = top 25th percentile), denoted as :math:`\text{amp}_{high}`. |
| 33 | + - Find all histogram bins whose lower edge is greater than that quantile value. These bins form the "high‐quantile region". |
| 34 | + - Compute |
| 35 | + |
| 36 | + .. math:: |
| 37 | + H_{\mathrm{bins}} &= \bigl\{i : \text{lower_edge}_i \ge \text{amp}_{high}\bigr\}, \\ |
| 38 | + \mu_{\mathrm{high}} &= \frac{1}{|H_{\mathrm{bins}}|}\sum_{i\in H_{\mathrm{bins}}} n_i, \quad |
| 39 | + \sigma_{\mathrm{high}} = \sqrt{\frac{1}{|H_{\mathrm{bins}}|-1}\sum_{i\in H_{\mathrm{bins}}}\bigl(n_i-\mu_{\mathrm{high}} \bigr)^2}. |
| 40 | +
|
| 41 | +4. **Compute cutoff** |
| 42 | + |
| 43 | + The *cutoff* is given by how many standard deviations away the low-amplitude bins are from the high-amplitude bins, defined as |
| 44 | + |
| 45 | + .. math:: |
| 46 | + \mathrm{cutoff} = \frac{\mu_{\mathrm{low}} - \mu_{\mathrm{high}}}{\sigma_{\mathrm{high}}}. |
| 47 | +
|
| 48 | +
|
| 49 | + - If no low‐quantile bins exist, a warning is issued and ``cutoff = NaN``. |
| 50 | + - If no high‐quantile bins exist or :math:`\sigma_{\mathrm{high}} = 0`, a warning is issued and ``cutoff = NaN``. |
| 51 | + |
| 52 | +5. **Compute the low-to-peak ratio** |
| 53 | + |
| 54 | + - Let :math:`M = \max_i\,n_i` be the height of the largest bin in the histogram. |
| 55 | + - Define |
| 56 | + |
| 57 | + .. math:: |
| 58 | + \mathrm{ratio} = \frac{\mu_{\mathrm{low}}}{M}. |
| 59 | +
|
| 60 | +
|
| 61 | + - If there are no low bins, :math:`\mathrm{ratio} = NaN`. |
| 62 | + |
| 63 | + |
| 64 | +Together, ``(cutoff, ratio)`` quantify how suppressed the low‐end of the amplitude distribution is relative to the top quantile and to the peak. |
12 | 65 |
|
13 | 66 | Expectation and use |
14 | 67 | ------------------- |
15 | 68 |
|
16 | 69 | Noise cutoff attempts to describe whether an amplitude distribution is cut off. |
17 | | -The metric is loosely based on [Hill]_'s amplitude cutoff, but is here adapted (originally by [IBL]_) to avoid making the Gaussianity assumption on spike distributions. |
18 | | -Noise cutoff provides an estimate of false negative rate, so a lower value indicates fewer missed spikes (a more complete unit). |
| 70 | +Larger values of ``cutoff`` and ``ratio`` suggest that the distribution is cut-off. |
| 71 | +IBL uses the default value of 1 (equivalent to e.g. ``low_quantile=0.01, n_bins=100``) to choose the number of |
| 72 | +lower bins, with a suggested threshold of 5 for ``cutoff`` to determine whether a unit is cut off or not. |
| 73 | +In practice, the IBL threshold is quite conservative, and a lower threshold might work better for your data. |
| 74 | +We suggest plotting the data using the :py:func:`~spikeinterface.widgets.plot_amplitudes` widget to view your data when choosing your threshold. |
| 75 | +It is suggested to use this metric when the amplitude histogram is **unimodal**. |
| 76 | + |
| 77 | +The metric is loosely based on [Hill]_'s amplitude cutoff, but is here adapted (originally by [IBL2024]_) to avoid making the Gaussian assumption on spike distributions. |
| 78 | + |
| 79 | +Example code |
| 80 | +------------ |
| 81 | + |
| 82 | +.. code-block:: python |
| 83 | +
|
| 84 | + import numpy as np |
| 85 | + import matplotlib.pyplot as plt |
| 86 | + from spikeinterface.full as si |
| 87 | +
|
| 88 | + # Suppose `sorting_analyzer` has been computed with spike amplitudes: |
| 89 | + # Select units you are interested in visualizing |
| 90 | + unit_ids = ... |
| 91 | +
|
| 92 | + # Compute noise_cutoff: |
| 93 | + summary_dict = compute_noise_cutoff( |
| 94 | + sorting_analyzer=sorting_analyzer |
| 95 | + high_quantile=0.25, |
| 96 | + low_quantile=0.10, |
| 97 | + n_bins=100, |
| 98 | + unit_ids=unit_ids |
| 99 | + ) |
| 100 | +
|
| 101 | +Reference |
| 102 | +--------- |
| 103 | + |
| 104 | +.. autofunction:: spikeinterface.qualitymetrics.misc_metrics.compute_noise_cutoff |
| 105 | + |
| 106 | +Examples with plots |
| 107 | +------------------- |
| 108 | + |
| 109 | +Here is shown the histogram of two units, with the vertical lines separating low- and high-amplitude regions. |
| 110 | + |
| 111 | +- On the left, we have a unit with no truncation at the left end, and the cutoff and ratio are small. |
| 112 | +- On the right, we have a unit with truncation at -1, and the cutoff and ratio are much larger. |
19 | 113 |
|
| 114 | +.. image:: example_cutoff.png |
| 115 | + :width: 600 |
20 | 116 |
|
21 | 117 | Links to original implementations |
22 | 118 | --------------------------------- |
23 | 119 |
|
24 | 120 | * From `IBL implementation <https://github.com/int-brain-lab/ibllib/blob/2e1f91c622ba8dbd04fc53946c185c99451ce5d6/brainbox/metrics/single_units.py>`_ |
25 | 121 |
|
| 122 | +Note: Compared to the original implementation, we have added a comparison between the low-amplitude bins to the largest bin (``noise_ratio``). |
| 123 | +The selection of low-amplitude bins is based on the ``low_quantile`` rather than the number of bins. |
26 | 124 |
|
27 | 125 | Literature |
28 | 126 | ---------- |
29 | 127 |
|
30 | | -Metric introduced by [IBL]_ (adapted from [Hill]_'s amplitude cutoff metric). |
| 128 | +Metric introduced by [IBL2024]_. |
0 commit comments