This serves as a simple notebook for implementing the different kinds of Firing Rate Approximation Functions as defined in 1.2 - Spike Trains and Firing Rates.

In most cases you would be doing this for multiple Neurons, but here we will just do one like the Textbook’s figures.

Module Imports:

Python
Output

Defining the Data

Here we define our model parameters for the test, we dont want anything too big so we will just do 10 seconds, 1 neuron( you can adjust if you like), and a time resolution of 1 ms.

Python
Output

Creating Spike Trains

This won’t be as accurate as a “real” dataset, but numpy has a capable seed random number generator that creates realistic data for this case:

Python
Output

Raster Spike Train Graph

Without any kind of rate approximation, let’s get a sense of what the data looks like.

Python
Output

Discrete Bin Graph

One way to approximate the firing rate is through the use of binning. This procedure generates an estimate of the firing rate that is a piecewise constant function of time, something of a histogram.

Because spike counts can take only integer values, the rates computed by this method will always be integer multiples of , and thus they only take discrete values.

For this approach, we will use bins of size .

Python
Output

Sliding Window Rectangular

Placement of bins introduces a new issue, as the firing rate estimate now depends not only on the size of the time bins, but also their placement. We dont want this to be arbitrary, so we can instead use a single bin and slide it across the timeframe.

This will yield a hopefully higher approximation resolution, but since it is still a rectangular window it will have those same jagged edges as the previous method.

The firing rate approximated this way will be expressed as the sum of a window function over time

where is a list of times , and is the number of spikes.

In this case, our sliding window function is defined as:

Python
Output

Sliding Window Gaussian

The next step after this is quite clear - the sliding window provides the precision we need, but due to the rectangular shape it retains those jagged edges from the bin method.

For our Gaussian Kernel, we will use the following formula:

Python
Output

Causal Window Function

For biological neurons, however, the firing rate is not symmetric around the spike time. The firing rate is often higher before the spike than after it. This is due to the refractory period of the neuron, which is a period of time after a spike during which the neuron is less likely to fire again.

A postsynaptic neuron monitoring the spike train of a presynaptic cell has access only to spikes that have previously occurred. Therefore, an approximation of the firing rate at a given time should use a window function that “vanishes” when its argument is negative. We call this window function a causal.

For this, we will use one called the function:

Where the notation represents the half-wave rectification operation, aka only positives:

Python
Output

You will note that this tends to peak later than the previous approximations when a temporally symmetric window function is used.