1# -*- coding: utf-8 -*-
2#
3# BrodyHopfield.py
4#
5# This file is part of NEST.
6#
7# Copyright (C) 2004 The NEST Initiative
8#
9# NEST is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 2 of the License, or
12# (at your option) any later version.
13#
14# NEST is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with NEST.  If not, see <http://www.gnu.org/licenses/>.
21
22
23"""
24Spike synchronization through subthreshold oscillation
25------------------------------------------------------
26
27This script reproduces the spike synchronization behavior
28of integrate-and-fire neurons in response to a subthreshold
29oscillation. This phenomenon is shown in Fig. 1 of [1]_
30
31Neurons receive a weak 35 Hz oscillation, a gaussian noise current
32and an increasing DC. The time-locking capability is shown to
33depend on the input current given. The result is then plotted using
34matplotlib. All parameters are taken from the above paper.
35
36References
37~~~~~~~~~~
38
39.. [1] Brody CD and Hopfield JJ (2003). Simple networks for
40       spike-timing-based computation, with application to olfactory
41       processing. Neuron 37, 843-852.
42
43"""
44
45#################################################################################
46# First, we import all necessary modules for simulation, analysis, and plotting.
47
48import nest
49import nest.raster_plot
50import matplotlib.pyplot as plt
51
52###############################################################################
53# Second, the simulation parameters are assigned to variables.
54
55N = 1000           # number of neurons
56bias_begin = 140.  # minimal value for the bias current injection [pA]
57bias_end = 200.    # maximal value for the bias current injection [pA]
58T = 600            # simulation time (ms)
59
60# parameters for the alternating-current generator
61driveparams = {'amplitude': 50., 'frequency': 35.}
62# parameters for the noise generator
63noiseparams = {'mean': 0.0, 'std': 200.}
64neuronparams = {'tau_m': 20.,  # membrane time constant
65                'V_th': 20.,  # threshold potential
66                'E_L': 10.,  # membrane resting potential
67                't_ref': 2.,  # refractory period
68                'V_reset': 0.,  # reset potential
69                'C_m': 200.,  # membrane capacitance
70                'V_m': 0.}      # initial membrane potential
71
72###############################################################################
73# Third, the nodes are created using ``Create``. We store the returned handles
74# in variables for later reference.
75
76neurons = nest.Create('iaf_psc_alpha', N)
77sr = nest.Create('spike_recorder')
78noise = nest.Create('noise_generator')
79drive = nest.Create('ac_generator')
80
81###############################################################################
82# Set the parameters specified above for the generators using ``set``.
83
84drive.set(driveparams)
85noise.set(noiseparams)
86
87###############################################################################
88# Set the parameters specified above for the neurons. Neurons get an internal
89# current. The first neuron additionally receives the current with amplitude
90# `bias_begin`, the last neuron with amplitude `bias_end`.
91
92neurons.set(neuronparams)
93neurons.I_e = [(n * (bias_end - bias_begin) / N + bias_begin)
94               for n in range(1, len(neurons) + 1)]
95
96###############################################################################
97# Connect alternating current and noise generators as well as
98# `spike_recorder`s to neurons
99
100nest.Connect(drive, neurons)
101nest.Connect(noise, neurons)
102nest.Connect(neurons, sr)
103
104###############################################################################
105# Simulate the network for time `T`.
106
107nest.Simulate(T)
108
109###############################################################################
110# Plot the raster plot of the neuronal spiking activity.
111
112nest.raster_plot.from_device(sr, hist=True)
113plt.show()
114