Peri-Stimulus Time Histogram (PSTH) of CBGTC spike times

class analyseur.cbgtc.stats.psth.PSTH[source]

Bases: object

Computes for the Peri-Stimulus Time Histogram (PSTH using numpy.histogram) of spiking times from all neurons. This gives an overall temporal pattern of population activity with a picture in both temporal and rate.

Methods

Argument

compute_poolPSTH()

  • spiketimes_set: Dictionary returned
  • window [OPTIONAL]: Tuple (0, 10) seconds [default]

  • binsz [OPTIONAL]: 0.01 (= 100 per bin) [default]

  • neurons [OPTIONAL]: “all” [default] or a scalar or list: range(a, b) or [1, 4, 5, 9]

compute_avgPSTH()

  • spiketimes_set`: Dictionary returned
  • window [OPTIONAL]: Tuple (0, 10) seconds [default]

  • binsz [OPTIONAL]: 0.01 (= 100 per bin) [default]

  • neurons [OPTIONAL]: “all” [default] or a scalar or list: range(a, b) or [1, 4, 5, 9]

analyze_temporal()

  • desired_spiketimes_subset: a nested list of spike times used for computing the PSTH
  • popfirerates: array of population firing rate (at each bin)

  • bin_centers: array of bin centers

  • binsz: bin size used for the PSTH

  • stimulus_onset [OPTIONAL]: 0 [default]

analyze_rate()

  • desired_spiketimes_subset: a nested list of spike times used for computing the PSTH
  • true_avg_rate: dictionary of firing rates; see return value of compute()

  • popfirerates: array of population firing rate (at each bin)

  • window: window used for the PSTH

  • stimulus_onset [OPTIONAL]: 0 [default]

analyze_energy()

Use Cases

1. Pre-requisites

1.1. Import Modules

from analyseur.cbgtc.loader import LoadSpikeTimes
from analyseur.cbgtc.stats.psth import PSTH

1.2. Load file and get spike times

loadST = LoadSpikeTimes("spikes_GPi.csv")
spiketimes_superset = loadST.get_spiketimes_superset()

2. Cases

2.1. Compute PSTH (for all neurons)

B = PSTH.compute_poolPSTH(spiketimes_superset)
C = PSTH.compute_avgPSTH(spiketimes_superset)

2.2. Compute PSTH for chosen neurons with desired bin size

B = PSTH.compute_poolPSTH(spiketimes_superset, neurons=range(30, 120), binsz=0.1)

PSTH for neurons 30 to 120 with the bin size of 0.1 seconds.

2.3. Analytics: Get temporal features from the PSTH

[counts, bin_info, popfirerates,
true_avg_rate, desired_spiketimes_subset] = PSTH.compute_poolPSTH(spiketimes_superset)

temporal_features = PSTH.analyze_temporal(desired_spiketimes_subset,
                                          popfirerates=popfirerates,
                                          bin_centers=bin_info["bin_centers"],
                                          binsz=bin_info["binsz"],)

2.4. Analytics: Get rate-based features from the PSTH

rate_features = PSTH.analyze_rate(desired_spiketimes_subset,
                                  true_avg_rate=true_avg_rate,
                                  popfirerates=popfirerates,
                                  window=bin_info["window"],)

2.5. Analytics: Get energetics from the PSTH

energetics = PSTH.analyze_energy(true_avg_rate)

Possible Insights From Population PSTH

Insight

Meaning

“collective_timing”

when does the population (as whole) respond?

“pop_reliability”

how robust is the population spiking?

“info_redundancy”

how similarly/diversely do neurons (in population) respond?

“coding_strategy”

sparse or dense population spiking?

“population_dynamics”

how activity propagated through the network?

  • sparse coding is a measure of whether a few neurons do most of the firing

  • dense coding is a measure of whether the neurons firing in the population is evenly distributed

Mean of Individual Firing Rate vs Mean of Time-Varying Population Rate

True Average Firing Rate (or Mean of Individual Firing Rate) is

  • count each neuron’s spikes over entire time window

  • average across neurons (Hz)

Mean of Time-Varying Population Rate is

  • count population spikes per time (bin)

  • take each count per population size per bin (i.e instantaneous rate)

  • average cross time bins (Hz)

True Average Firing Rate

Population Rate (Time-Varying)

Mean of Population Rate

  • actual average firing rate of neurons

  • calculate population statistics

  • compare firing rates across populations

  • analyze temporal dynamics of population response
    • response latency, peak time, duration

  • study population activity evolving over time

  • average level of time-varying population signal

  • comparing temporal patterns (normalization)

  • is NOT neuron’s average firing rate

  • When firing rate is constant over time
    • Mean of Individual Firing Rate = Mean of Time-Varying Population Rate


static analyze_energy(true_avg_rate)[source]

Extracts energy features from the PSTH counts, i.e, analytics for metabolic efficiency of rate distribution.

Parameters:

true_avg_rate – returned using _compute_true_avg_firing_rate()

Returns:

dictionary

Dictionary key

Meaning

“total_population_activity”

-to do-

“max_entropy”

-to do-

“entropy”

-to do

“efficiency”

how efficiently are the rates distributed

“energy_per_bit”

metabolic cost per information bit

“dynamic_range”

-to do-


static analyze_rate(desired_spiketimes_subset, true_avg_rate=[], popfirerates=[], window=(), stimulus_onset=0)[source]

Extracts rate-based features from the PSTH counts

Parameters:

desired_spiketimes_subset – a nested list of spike times (for computing the PSTH) obtained using

get_desired_spiketimes_subset()

Parameters:
  • true_avg_rate – returned using _compute_true_avg_firing_rate()

  • popfirerates – array of population firing rate (at each bin) in the PSTH; see return values of compute_poolPSTH()

  • bin_centers – array of bin centers in the PSTH; see return values of compute_poolPSTH()

  • window – window used for the PSTH; see return values of compute_poolPSTH()

  • stimulus_onset – [OPTIONAL] 0 (default)

Returns:

dictionary

Dictionary key

Meaning

“mean_firing_rate”

average of each neuron’s rate

“std_firing_rate”

spread of the firing rates

“avg_time_vary_rate”

average of the time varying population signal

“mean_baseline_rate”

average spontaneous activity levels

“mean_response_rate”

average response strengths

“mean_rate_increase”

average absolute response magnitudes

“mean_fold_change”

average relative response magnitudes

“rate_heterogeneity”

measure of response heterogeneity

“response_reliability”

measure of response consistency

“active_fraction”

active neurons out of total neurons

“population_sparsity”

measure of concentration of firing rates across population

  • sparsity index (“population_sparsity”) is a measure of how concentrated or distributed the firing is across the neurons in the population


static analyze_temporal(desired_spiketimes_subset, popfirerates=[], bin_centers=[], binsz=None, stimulus_onset=0)[source]

Extracts temporal features from the PSTH counts

Parameters:

desired_spiketimes_subset – a nested list of spike times (for computing the PSTH) obtained using

get_desired_spiketimes_subset()

Parameters:
  • popfirerates – array of population firing rate (at each bin) in the PSTH; see return values of compute_poolPSTH()

  • bin_centers – array of bin centers in the PSTH; see return values of compute_poolPSTH()

  • binsz – bin size used for the PSTH; see return values of compute_poolPSTH()

  • stimulus_onset – [OPTIONAL] 0 (default)

Returns:

dictionary

Dictionary key

Meaning

“peak_latency”

when peak occurs

“response_latencies”

when responses begins

“response_duration”

how long it lasts

“response_sequence”

time span of first responses

“response_spread”

how synced are the neurons

“temporal_coordination”

coordination index

  • the temporal profile (full time course) is the value of the attribute :ivar popfirerates:


classmethod compute_avgPSTH(spiketimes_set, neurons=None, binsz=None, window=None)[source]
\[\overline{R}_k = \frac{1}{n_\text{nuc}} \sum_{i=1}^{n_\text{nuc}} R_{i,k}\]

is the average population PSTH of the firing rate \(R_{i,k} = C_{i,k}/\Delta t\) where

\[C_{i,k} = \sum_{t \in S_i}1(b_k \le t < b_{k+1})\]

is the PSTH count for bin \(k\) and \(i\)-th neuron having spike times \(S_i = \{t_{i1}, t_{i2}, \ldots, t_{iK_i}\}\) inside the window \(t \in [T_0, T_1]\), \(1(.)\) is the indicator function with bin width \(\Delta t\) and bin_edges

\[b_k = T_0 + k \Delta t\]

for \(k = 0,1,\ldots,K\).

Computation of Average of Individual Peri-Stimulus Time Histogram (Population PSTH).

Parameters:

spiketimes_set – Dictionary returned using get_spiketimes_superset()

or using get_spiketimes_subset()

Parameters:
  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • binsz – integer or float; 0.01 (= 100 per bin) [default]

  • neurons

    “all” [default] or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

Returns:

a tuple in the following order

  • array of the values (counts) of the histogram

  • dictionary of bin information
    • “window”: window used for computing the PSTH

    • “binsz”: bin size used for computing the PSTH

    • “bin_centers”: array of bin centers

    • “bins”: array of bins

  • array of population firing rate (at each bin)

  • dictionary of firing rates
    • “firing_rates”: array of firing rates for each neuron

    • “mean_firing_rate”: mean of the array of firing rates

    • “std_firing_rate”: standard deviation of the array of firing rates

  • a nested list of spike times used for computing the PSTH

The standard error across neurons is

\[\text{SEM}_k = \frac{\sigma_k}{\sqrt{n_\text{nuc}}}\]

where

\[\sigma_k = \sqrt{\frac{1}{n_\text{nuc}} \sum_{i=1}^{n_\text{nuc}}\left(R_{i,k} - \overline{R}_k\right)^2}\]

classmethod compute_poolPSTH(spiketimes_set, neurons=None, binsz=None, window=None)[source]
\[C_k = \sum_{t \in S_\text{pool}}1(b_k \le t < b_{k+1})\]

is the pooled spike train the PSTH count in bin \(k\) where

\[S_\text{pool} = \bigcup_{i=1}^{n_\text{nuc}}S_i\]

is the pooled spike train for spike times of the \(i\)-th neuron, \(S_i = \{t_{i1}, t_{i2}, \ldots, t_{iK_i}\}\) inside the window \(t \in [T_0, T_1]\), \(1(.)\) is the indicator function with bin width \(\Delta t\) and bin_edges

\[b_k = T_0 + k \Delta t\]

for \(k = 0,1,\ldots,K\).

Computation of Pooled Population Peri-Stimulus Time Histogram (PSTH) of all individual neurons.

Parameters:

spiketimes_set – Dictionary returned using get_spiketimes_superset()

or using get_spiketimes_subset()

Parameters:
  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • binsz – integer or float; 0.01 (= 100 per bin) [default]

  • neurons

    “all” or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

Returns:

a tuple in the following order

  • array of the values (counts) of the histogram

  • dictionary of bin information
    • “window”: window used for computing the PSTH

    • “binsz”: bin size used for computing the PSTH

    • “bin_centers”: array of bin centers

    • “bins”: array of bins

  • array of population firing rate (at each bin)

  • dictionary of firing rates
    • “firing_rates”: array of firing rates for each neuron

    • “mean_firing_rate”: mean of the array of firing rates

    • “std_firing_rate”: standard deviation of the array of firing rates

  • a nested list of spike times used for computing the PSTH

The time-varying population firing rate is

\[R_k = \frac{C_k}{n_\text{nuc} \Delta t}\]

for \(k\) bin.

While the true average firing rate (across neurons) is

\[\overline{r} = \frac{1}{N} \sum_{i=1}^{n_\text{nuc}}r_i\]

where \(r_i = n_i/(T_1 - T_0)\) for \(n_i\) number of spikes from \(i\)-th neuron in the window and standard deviation

\[\sigma_r = \sqrt{\frac{1}{N}\sum_{i=1}^{n_\text{nuc}}\left(r_i - \overline{r}\right)^2}\]