Last active
June 24, 2023 14:58
-
-
Save fschwar4/8e9044273716cfea5a76653daeb0d170 to your computer and use it in GitHub Desktop.
Calculate the local variation (Lv) as proposed in Shinomot et al. 2009. The Lv should be more robust than the coefficient of variation (Cv).
This file contains 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
import numpy as np | |
def cv(spike_train: np.ndarray) -> float: | |
"""Calculate coefficient of variation (Cv) of the interspike intervals. | |
$$\displaystyle{Cv = \frac{\sigma_{ISI}}{\mu_{ISI}}}$$ | |
Args: | |
spike_train (np.ndarray): Spike train. | |
Returns: | |
float: Coefficient of variation. | |
""" | |
_isi = np.diff(spike_train) | |
return np.std(_isi) / np.mean(_isi) |
This file contains 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
import numpy as np | |
def lv(spike_train: np.ndarray) -> float: | |
"""Calculate local variation (Lv) of ISI after Shinomoto et al. 2009. | |
$$\displaystyle{Lv = \frac{3}{n-1} \sum_{i=1}^{n-1} | |
{\left(1\frac{I_i - I_{i+1}}{I_{i} + I_{i+1}}\right)}^2}$$ | |
Args: | |
spike_train (np.ndarray): Spike train. | |
Returns: | |
float: Local variation. | |
References: | |
Shinomoto S, Kim H, Shimokawa T, Matsuno N, Funahashi S, et al. | |
(2009) Relating Neuronal Firing Patterns to Functional | |
Differentiation of Cerebral Cortex. PLOS Computational Biology | |
5(7): e1000433. https://doi.org/10.1371/journal.pcbi.1000433 | |
""" | |
_isi = np.diff(spike_train) | |
s_ = 3 / (len(_isi) - 1) | |
lv_us = np.sum((np.diff(_isi) / (_isi[:-1] + _isi[1:]))**2) | |
return s_ * lv_us |
This file contains 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
import numpy as np | |
def lvR(spike_train: np.ndarray, r: float) -> float: | |
"""Local variation revised (LVr) of ISI after Shinomoto et al. 2009. | |
This variant compensates for the refractory period by subtracting it. | |
Note: | |
To get useful results, the spike train and the refractory period | |
must be in the same unit (seconds or time steps). | |
$$\displaystyle{LvR = \frac{3}{n-1} \sum_{i=1}^{n-1} | |
\left(1 - \frac{4 I_i I_{i+1}}{(I_{i} + I_{i+1})^2}\right) | |
\left( 1 + \frac{4R}{I_i + I_{i+1}}\right)}$$ | |
Args: | |
spike_train (np.ndarray): Spike train. In seconds or time steps. | |
r (float): Refractory period in seconds or time steps. | |
Returns: | |
float: Local variation revised. | |
References: | |
Shinomoto S, Kim H, Shimokawa T, Matsuno N, Funahashi S, et al. | |
(2009) Relating Neuronal Firing Patterns to Functional | |
Differentiation of Cerebral Cortex. PLOS Computational Biology | |
5(7): e1000433. https://doi.org/10.1371/journal.pcbi.1000433 | |
""" | |
isi = np.diff(spike_train) | |
s_ = 3 / (len(isi) - 1) | |
si_ = isi[:-1] + isi[1:] | |
ft_ = 1 - ((4 * (isi[:-1] * isi[1:])) / si_**2) | |
st_ = 1 + ((4 * r) / si_) | |
return s_ * np.sum(ft_ * st_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment