Skip to content

Commit

Permalink
Added spike train example
Browse files Browse the repository at this point in the history
  • Loading branch information
miladh committed Nov 30, 2018
1 parent c35bbd8 commit b7965a1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
Binary file added docs/images/generate_spiketrain.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/raster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Natural scenes
:maxdepth: 1

examples/natural_stimulus
examples/generate_spiketrain
32 changes: 32 additions & 0 deletions docs/source/examples/generate_spiketrain.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. _generate_spiketrain:

Generate spike trains
=====================

In this example a static image is shown in 80 ms after a 40 ms delay.

.. literalinclude:: ../../../examples/generate_spiketrain.py
:language: python
:lines: 1-26

The calculated rates can be converted to spikes via a nonstationary Poisson process:

.. literalinclude:: ../../../examples/generate_spiketrain.py
:language: python
:lines: 28-42

In the animation below the generated spikes at each location are shown as dots:

.. figure:: ../../images/generate_spiketrain.gif
:scale: 100 %
:align: center

A simple raster plot of individual locations can be created using:

.. literalinclude:: ../../../examples/generate_spiketrain.py
:language: python
:lines: 44

.. figure:: ../../images/raster.png
:scale: 100 %
:align: center
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Examples
* :ref:`einevoll_2012`.

* :ref:`natural_stimulus`.
* :ref:`generate_spiketrain`.



Expand Down
13 changes: 8 additions & 5 deletions examples/generate_spiketrain.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import pylgn
import pylgn.kernels.spatial as spl
import pylgn.kernels.temporal as tpl
import pylgn.tools as tls
import quantities as pq

# create network
network = pylgn.Network()

# create integrator
integrator = network.create_integrator(nt=7, nr=7, dt=1*pq.ms, dr=1*pq.deg)
integrator = network.create_integrator(nt=7, nr=7, dt=2*pq.ms, dr=0.4*pq.deg)

# create kernels
Wg_r = spl.create_dog_ft()
Expand All @@ -19,15 +18,17 @@

# create stimulus
stimulus = pylgn.stimulus.create_natural_image(filenames="natural_scene.png",
delay=10*pq.ms,
duration=50*pq.ms)
delay=40*pq.ms,
duration=80*pq.ms)
network.set_stimulus(stimulus, compute_fft=True)

# compute
network.compute_response(ganglion)
rates = ganglion.response

import pylgn.tools as tls

# apply static nonlinearity and scale rates
rates = ganglion.response
rates = tls.heaviside_nonlinearity(rates)
rates = tls.scale_rates(rates, 60*pq.Hz)

Expand All @@ -39,3 +40,5 @@
times=integrator.times,
positions=integrator.positions,
title="Spike activity")

pylgn.plot.raster_plot(spike_trains.flatten()[::200])

0 comments on commit b7965a1

Please sign in to comment.