<jupyter_start><jupyter_text>Mean firing rateThe simplest approach is to assume a stationary firing rate and only use the total number of spikes and the duration of the spike train to calculate the average number of spikes per time unit. This results in a single value for a given spiketrain.<jupyter_code>mean_frate1 = elephant.statistics.mean_firing_rate(spiketrain1)
mean_frate1.units = pq.Hz
print("The mean firing rate of spiketrain1 is", mean_frate1)

mean_frate2 = elephant.statistics.mean_firing_rate(spiketrain2)
mean_frate2.units = pq.Hz
print("The mean firing rate of spiketrain2 is", mean_frate2)
print("The mean firing rate of spiketrain1 is", elephant.statistics.mean_firing_rate(spiketrain1))
print("The mean firing rate of spiketrain2 is", elephant.statistics.mean_firing_rate(spiketrain2))<jupyter_output>The mean firing rate of spiketrain1 is 0.0086 1/ms
The mean firing rate of spiketrain2 is 0.0031 1/ms<jupyter_text>The mean firing rate of `spiketrain1` is higher than of `spiketrain2` as expected from the raster plot.Let’s quickly check the correctness of the `mean_firing_rate()` function by computing the firing rates manually:<jupyter_code>fr1 = len(spiketrain1) / (spiketrain1.t_stop - spiketrain1.t_start)
fr2 = len(spiketrain2) / (spiketrain2.t_stop - spiketrain2.t_start)
print("The mean firing rate of spiketrain1 is", fr1)
print("The mean firing rate of spiketrain2 is", fr2)<jupyter_output>The mean firing rate of spiketrain1 is 0.0086 1/ms
The mean firing rate of spiketrain2 is 0.0031 1/ms<jupyter_text>Additionally, the period within the spike train during which to estimate the firing rate can be further limited using the `t_start` and `t_stop` keyword arguments. Here, we limit the firing rate estimation to the first second of the spiketrain.<jupyter_code>elephant.statistics.mean_firing_rate(spiketrain1, t_start=0*pq.ms, t_stop=1000*pq.ms)<jupyter_output><empty_output><jupyter_text>Coefficient of Variation (CV)In this section we will numerically verify that the coefficient of variation (CV), a measure of the variability of inter-spike intervals, of a spike train that is modeled as a random (stochastic) Poisson process, is 1.Let us generate 100 independent Poisson spike trains for 100 seconds each with a rate of 10 Hz for which we later will calculate the CV. For simplicity, we will store the spike trains in a list.<jupyter_code>spiketrain_list = [
     elephant.spike_train_generation.homogeneous_poisson_process(rate=10.0*pq.Hz, 
                                                                 t_start=0.0*pq.s, 
                                                                 t_stop=100.0*pq.s)
     for _ in range(100)]
plt.figure(dpi=150)
plt.eventplot([st.magnitude for st in spiketrain_list], linelengths=0.75, linewidths=0.75, color='black')
plt.xlabel("Time, s")
plt.ylabel("Neuron id")
plt.xlim([0, 1])
plt.show()<jupyter_output><empty_output><jupyter_text>From the plot you can see the random nature of each Poisson spike train. Let us verify it numerically by calculating the distribution of the 100 CVs obtained from inter-spike intervals (ISIs) of these spike trains.For each spike train in our list, we first call the `isi()` function which returns an array of all N-1 ISIs for the N spikes in the input spike train. We then feed the list of ISIs into the `cv()` function, which returns a single value for the coefficient of variation:<jupyter_code>from elephant.statistics import isi, cv
cv_list = [cv(isi(spiketrain)) for spiketrain in spiketrain_list]
plt.figure(dpi=100)
plt.hist(cv_list)
plt.xlabel('CV')
plt.ylabel('count')
plt.title("Coefficient of Variation of homogeneous Poisson process")
plt.show()
print(np.mean(cv_list))<jupyter_output>0.9988464250640561
{'fraction_non_alphanumeric': 0.07603748326639893, 'fraction_numerical': 0.03159303882195449, 'mean_word_length': 4.78328173374613, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '583101', 'license': 'MIT', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1166, 'n_words': 417, 'path': 'notebooks/elephant.ipynb', 'repo_name': 'nicolossus/neuromodels', 'size': '3735'}