Skip to content

Commit

Permalink
Respond to review
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishalcrow committed Jul 2, 2024
1 parent 2bd0633 commit d1ea215
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions doc/modules/qualitymetrics/isi_violations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ Different formulas have been developed, but all require:
- :math:`T` the duration of the recording in seconds.
- :math:`N` the number of spikes in the unit's spike train.
- :math:`t_r` the duration of the unit's refractory period in seconds.
- :math:`n_v` the number of violations of the refractory period.

Calculation from the [UMS]_ package
-----------------------------------

Originally implemented in the `rpv_contamination` calculation of the UltraMegaSort2000 package: `<https://github.com/danamics/UMS2K/blob/master/quality_measures/rpv_contamination.m>`_.

In this method the number of spikes whose refractory period are violated, denoted :math:`n_v`, is used.

Here, the refactory period :math:`t_r` is adjusted to take account of the data recording system's minimum possible refactory
period. E.g. if a system has a sampling rate of :math:`f \text{ Hz}`, the closest that two spikes from the same unit can possibly
be is :math:`1/f \, \text{s}`. Hence the refactory period :math:`t_r` is the expected biological threshold minus this minimum possible
Expand All @@ -40,15 +41,17 @@ The contamination rate is calculated to be
Calculation from the [Llobet]_ paper
------------------------------------

In this method the number spikes which violate other spikes' refractory periods, denoted :math:`\tilde{n}_v`, is used.

The estimated contamination :math:`C` is calculated in 2 extreme scenarios. In the first, the contaminant spikes
are completely random (or come from an infinite number of other neurons). In the second, the contaminant spikes
come from a single other neuron. In these scenarios, the contamination rate is

.. math::
C = \frac{FP}{TP + FP} \approx \begin{cases}
1 - \sqrt{1 - \frac{n_v T}{N^2 t_r}} \text{ for the case of random contamination} \\
\frac{1}{2} \left( 1 - \sqrt{1 - \frac{2 n_v T}{N^2 t_r}} \right) \text{ for the case of 1 contaminant neuron}
1 - \sqrt{1 - \frac{\tilde{n}_v T}{N^2 t_r}} \text{ for the case of random contamination} \\
\frac{1}{2} \left( 1 - \sqrt{1 - \frac{2 \tilde{n}_v T}{N^2 t_r}} \right) \text{ for the case of 1 contaminant neuron}
\end{cases}
Where :math:`TP` is the number of true positives (detected spikes that come from the neuron) and :math:`FP` is the number of false positives (detected spikes that don't come from the neuron).
Expand Down
3 changes: 2 additions & 1 deletion doc/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ or :code:`compute_quality_metrics()` methods, please include the citations for t
important for your research:

- :code:`amplitude_cutoff` [Hill]_
- :code:`amplitude_median` or :code:`sliding_rp_violation` [IBL]_
- :code:`amplitude_median` [IBL]_
- :code:`sliding_rp_violation` [IBL]_
- :code:`drift` [Siegle]_
- :code:`isi_violation` [UMS]_
- :code:`rp_violation` [Llobet]_
Expand Down
9 changes: 5 additions & 4 deletions src/spikeinterface/qualitymetrics/misc_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,11 @@ def compute_isi_violations(sorting_analyzer, isi_threshold_ms=1.5, min_isi_ms=0,
Notes
-----
The returned ISI violations ratio measures the approximate fraction of spikes in each
unit which are contaminted. This interpretation is good when the ratio is small, and
becomes worse as it grows. In cases of highly contaminated units, the ISI violations
ratio can sometimes be greater than 1.
The returned ISI violations ratio approximates the fraction of spikes in each
unit which are contaminted. The formulation assumes that the contaminating spikes
are statistically independent from the other spikes in that cluster. This
approximation can break down in reality, especially for highly contaminated units.
See the discussion in Section 4.1 of [Llobet]_ for more details.
This method counts the number of spikes whose isi is violated. If there are three
spikes within `isi_threshold_ms`, the first and second are violated. Hence there are two
Expand Down

0 comments on commit d1ea215

Please sign in to comment.