Version 11.4 by adavison on 2021/09/30 14:18

Show last authors
1 (% class="box warningmessage" %)
2 (((
3 tutorial under development
4 )))
5
6 == Learning objectives ==
7
8 In this tutorial, you will learn how to build a simple network of integrate-and-fire neurons using PyNN, how to run simulation experiments with this network using different simulators, and how to visualize the data generated by these experiments.
9
10 == Audience ==
11
12 This tutorial is intended for people with at least a basic knowledge of neuroscience (high school level or above) and basic familiarity with the Python programming language. It should also be helpful for people who already have advanced knowledge of neuroscience and neural simulation, who simply wish to learn how to use PyNN, and how it differs from other simulation tools they know.
13
14 == Prerequisites ==
15
16 To follow this tutorial, you need a basic knowledge of neuroscience (high-school level or greater), basic familiarity with the Python programming language, and either a computer with PyNN, NEST, NEURON and Brian 2 installed, or an EBRAINS account and basic familiarity with Jupyter notebooks. If you don't have these tools installed, see one of our previous tutorials which guide you through the installation.
17
18 == Format ==
19
20 This tutorial will be a video combining slides, animations, and screencast elements. The intended duration is 10 minutes.
21
22 == Script ==
23
24 (% class="box successmessage" %)
25 (((
26 **Slide** showing tutorial title, PyNN logo, link to PyNN service page.
27 )))
28
29 Hello, my name is X.
30
31 This video is one of a series of tutorials for PyNN, which is Python software for modelling and simulating spiking neural networks.
32
33 For a list of the other tutorials in this series, you can visit ebrains.eu/service/pynn, that's p-y-n-n.
34
35 (% class="box successmessage" %)
36 (((
37 **Slide** listing learning objectives
38 )))
39
40 In this tutorial, you will learn the basics of PyNN: how to build a simple network of integrate-and-fire neurons using PyNN, how to run simulation experiments with this network using different simulators, and how to visualize the data generated by these experiments.
41
42 (% class="box successmessage" %)
43 (((
44 **Slide** listing prerequisites
45 )))
46
47 To follow this tutorial, you need a basic knowledge of neuroscience (high-school level or greater), basic familiarity with the Python programming language, and you should have already followed our earlier tutorial video which guides you through the installation process.
48
49 This video covers PyNN 0.10. If you've installed a more recent version of PyNN, you might want to look for an updated version of this video.
50
51 (% class="box successmessage" %)
52 (((
53 **Slide** showing animation of leaky integrate-and-fire model
54 )))
55
56 PyNN is a tool for building models of nervous systems, and parts of nervous systems, at the level of individual neurons and synapses.
57
58 We'll start off creating a group of 100 neurons, using a really simple model of a neuron, the leaky integrate-and-fire model.
59
60 When we inject positive current into this model, either from an electrode or from an excitatory synapse, it increases the voltage across the cell membrane, until the voltage reaches a certain threshold.
61
62 At that point, the neuron produces an action potential, also called a spike, and the membrane voltage is reset.
63
64 (% class="box infomessage" %)
65 (((
66 **Screencast** - blank document in editor
67 )))
68
69 In this video, you'll see my editor on the left, and on the right my terminal and my file browser. I'll be writing code in the editor, and then running my scripts in the terminal. You're welcome to follow along~-~--you can pause the video at any time if I'm going too fast~-~--or you can just watch.
70
71 Let's start by writing a docstring, "Simple network model using PyNN".
72
73 For now, we're going to use the NEST simulator to simulate this model, so we import the PyNN-for-NEST module.
74
75 Like with any numerical model, we need to break time down into small steps, so let's set that up with steps of 0.1 milliseconds.
76
77 (% class="box infomessage" %)
78 (((
79 **Screencast** - current state of editor
80 \\(% style="color:#e74c3c" %)"""Simple network model using PyNN"""
81 \\import pyNN.nest as sim
82 sim.setup(timestep=0.1)
83 )))
84
85 PyNN comes with a selection of integrate-and-fire models. We're going to use the IF_curr_exp model, where "IF" is for integrate-and-fire, "curr" means that synaptic responses are changes in current, and "exp" means that the shape of the current is a decaying exponential function.
86
87 This is where we set the parameters of the model: the resting membrane potential is -65 millivolts, the spike threshold is -55 millivolts, the reset voltage after a spike is again -65 millivolts, the refractory period after a spike is one millisecond, the membrane time constant is 10 milliseconds, and the membrane capacitance is 1 nanofarad. We're also going to inject a constant bias current of 0.1 nanoamps into these neurons, so that we get some action potentials.
88
89 (% class="box infomessage" %)
90 (((
91 **Screencast** - current state of editor
92 \\(% style="color:#000000" %)"""Simple network model using PyNN"""
93 \\import pyNN.nest as sim
94 sim.setup(timestep=0.1)(%%)
95 (% style="color:#e74c3c" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, t_refrac=1, tau_m=10, cm=1, i_offset=0.1)
96 )))
97
98 Let's create 100 of these neurons, then we're going to record the membrane voltage, and run a simulation for 100 milliseconds.
99
100 (% class="box infomessage" %)
101 (((
102 **Screencast** - current state of editor
103 \\(% style="color:#000000" %)"""Simple network model using PyNN"""
104 \\import pyNN.nest as sim
105 sim.setup(timestep=0.1)(%%)
106 (% style="color:#000000" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
107 (% style="color:#e74c3c" %)population1 = sim.Population(100, cell_type, label="Population 1")
108 population1.record("v")
109 sim.run(100.0)(%%)
110 \\**Run script in terminal**
111 )))
112
113 PyNN has some built-in tools for making simple plots, so let's import those, and plot the membrane voltage of the zeroth neuron in our population (remember Python starts counting at zero).
114
115 (% class="box infomessage" %)
116 (((
117 **Screencast** - current state of editor
118 \\(% style="color:#000000" %)"""Simple network model using PyNN"""
119 \\import pyNN.nest as sim(%%)
120 (% style="color:#e74c3c" %)from pyNN.utility.plotting import Figure, Panel(%%)
121 (% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
122 (% style="color:#000000" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
123 (% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")
124 population1.record("v")
125 sim.run(100.0)(%%)
126 (% style="color:#e74c3c" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
127 Figure(
128 Panel(
129 data_v[:, 0],
130 xticks=True, xlabel="Time (ms)",
131 yticks=True, ylabel="Membrane potential (mV)"
132 ),
133 title="Response of neuron #0",
134 annotations="Simulated with NEST"
135 ).show()(%%)
136 \\**Run script in terminal, show figure**
137 )))
138
139 As you'd expect, the bias current causes the membrane voltage to increase until it reaches threshold~-~--it doesn't increase in a straight line because it's a //leaky// integrate-and-fire neuron~-~--then once it hits the threshold the voltage is reset, and then stays at the same level for a short time~-~--this is the refractory period~-~--before it starts to increase again.
140
141 Now, all 100 neurons in our population are identical, so if we plotted the first neuron, the second neuron, ..., we'd get the same trace.
142
143 (% class="box infomessage" %)
144 (((
145 **Screencast** - current state of editor
146 \\(% style="color:#000000" %)"""Simple network model using PyNN"""
147 \\import pyNN.nest as sim(%%)
148 (% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
149 (% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
150 (% style="color:#000000" %)cell_type  = sim.IF_curr_exp(v_rest=-65, v_thresh=-55, v_reset=-65, t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
151 (% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")
152 population1.record("v")
153 sim.run(100.0)(%%)
154 (% style="color:#000000" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
155 Figure(
156 Panel(
157 data_v[:, (% style="color:#e74c3c" %)0:5(% style="color:#000000" %)],
158 xticks=True, xlabel="Time (ms)",
159 yticks=True, ylabel="Membrane potential (mV)"
160 ),
161 title="Response of (% style="color:#e74c3c" %)first five neurons(% style="color:#000000" %)",
162 annotations="Simulated with NEST"
163 ).show()(%%)
164 \\**Run script in terminal, show figure**
165 )))
166
167 Let's change that. In nature every neuron is a little bit different, so let's set the resting membrane potential and the spike threshold randomly from a Gaussian distribution.
168
169 (% class="box infomessage" %)
170 (((
171 **Screencast** - current state of editor
172 \\(% style="color:#000000" %)"""Simple network model using PyNN"""
173 \\import pyNN.nest as sim(%%)
174 (% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
175 (% style="color:#e74c3c" %)from pyNN.random import RandomDistribution(%%)
176 (% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
177 (% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
178 (% style="color:#e74c3c" %) v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}),
179 v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}),
180 v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%)
181 (% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
182 (% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")
183 population1.record("v")
184 sim.run(100.0)(%%)
185 (% style="color:#000000" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
186 Figure(
187 Panel(
188 data_v[:, 0:5],
189 xticks=True, xlabel="Time (ms)",
190 yticks=True, ylabel="Membrane potential (mV)"
191 ),
192 title="Response of first five neurons (% style="color:#e74c3c" %)with heterogeneous parameters(% style="color:#000000" %)",
193 annotations="Simulated with NEST"
194 ).show()(%%)
195 \\**Run script in terminal, show figure**
196 )))
197
198 Now if we run our simulation again, we can see the effect of this heterogeneity in the neuron population.
199
200 (% class="box successmessage" %)
201 (((
202 **Slide** showing addition of second population, and of connections between them
203 )))
204
205 (% class="wikigeneratedid" %)
206 So far we have a population of neurons, but there are no connections between them, we don't have a network. Let's add a second population of the same size as the first, but we'll set the offset current to zero, so they don't fire action potentials spontaneously.
207
208 (% class="box infomessage" %)
209 (((
210 **Screencast** - current state of editor
211 \\(% style="color:#000000" %)"""Simple network model using PyNN"""
212 \\import pyNN.nest as sim(%%)
213 (% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
214 (% style="color:#000000" %)from pyNN.random import RandomDistribution(%%)
215 (% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
216 (% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
217 (% style="color:#e74c3c" %) (% style="color:#000000" %)v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}),
218 v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}),
219 v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%)
220 (% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
221 (% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%)
222 (% style="color:#e74c3c" %)population2 = sim.Population(100, cell_type, label="Population 2")
223 population2.set(i_offset=0)(%%)
224 (% style="color:#000000" %)population1.record("v")(%%)
225 (% style="color:#e74c3c" %)population2.record("v")(%%)
226 (% style="color:#000000" %)sim.run(100.0)(%%)
227 (% style="color:#000000" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
228 Figure(
229 Panel(
230 data_v[:, 0:5],
231 xticks=True, xlabel="Time (ms)",
232 yticks=True, ylabel="Membrane potential (mV)"
233 ),
234 title="Response of first five neurons with heterogeneous parameters",
235 annotations="Simulated with NEST"
236 ).show()(%%)
237 \\**Run script in terminal, show figure**
238 )))
239
240 Now we want to create synaptic connections between the neurons in Population 1 and those in Population 2. There are lots of different ways these could be connected.
241
242 (% class="box successmessage" %)
243 (((
244 **Slide** showing all-to-all connections
245 )))
246
247 We could connect all neurons in Population 1 to all those in Population 2.
248
249 (% class="box successmessage" %)
250 (((
251 **Slide** showing random connections
252 )))
253
254 We could connect the populations randomly, in several different ways.
255
256 (% class="box successmessage" %)
257 (((
258 **Slide** showing distance-dependent connections
259 )))
260
261 (% class="wikigeneratedid" %)
262 We could connect the populations randomly, but with a probability of connection that depends on the distance between the neurons.
263
264 (% class="box successmessage" %)
265 (((
266 **Slide** showing explicit lists of connections
267 )))
268
269 (% class="wikigeneratedid" %)
270 Or we could connect the neurons in a very specific manner, based on an explicit list of connections.
271
272 (% class="wikigeneratedid" %)
273 Just as PyNN provides a variety of neuron models, so it comes with a range of connection algorithms built in. You can also add your own connection methods.
274
275 (% class="box successmessage" %)
276 (((
277 **Slide** showing addition of second population, and of connections between them, labelled as a Projection.
278 )))
279
280 (% class="wikigeneratedid" %)
281 In PyNN, we call a group of connections between two populations a _Projection_. To create a Projection, we need to specify the presynaptic population, the postsynaptic population, the connection algorithm, and the synapse model. Here we're using the simplest synapse model available in PyNN, for which the synaptic weight is constant over time, there is no plasticity.
282
283 (% class="box infomessage" %)
284 (((
285 **Screencast** - current state of editor
286 \\(% style="color:#000000" %)"""Simple network model using PyNN"""
287 \\import pyNN.nest as sim(%%)
288 (% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%)
289 (% style="color:#000000" %)from pyNN.random import RandomDistribution(%%)
290 (% style="color:#000000" %)sim.setup(timestep=0.1)(%%)
291 (% style="color:#000000" %)cell_type  = sim.IF_curr_exp(
292 (% style="color:#e74c3c" %) (% style="color:#000000" %)v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}),
293 v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}),
294 v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%)
295 (% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%)
296 (% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%)
297 (% style="color:#000000" %)population2 = sim.Population(100, cell_type, label="Population 2")
298 population2.set(i_offset=0)
299 population1.record("v")
300 population2.record("v")(%%)
301 (% style="color:#e74c3c" %)connection_algorithm = sim.FixedProbabilityConnector(p=0.5)
302 synapse_type = sim.StaticSynapse(weight=0.5, delay=0.5)
303 connections = sim.Projection(population1, population2, connection_algorithm, synapse_type)(%%)
304 (% style="color:#000000" %)sim.run(100.0)(%%)
305 (% style="color:#000000" %)data_v = population1.get_data().segments[0].filter(name='v')[0]
306 Figure(
307 Panel(
308 data_v[:, 0:5],
309 xticks=True, xlabel="Time (ms)",
310 yticks=True, ylabel="Membrane potential (mV)"
311 ),
312 title="Response of first five neurons with heterogeneous parameters",
313 annotations="Simulated with NEST"
314 ).show()(%%)
315 \\**Run script in terminal, show figure**
316 )))
317
318 (% class="wikigeneratedid" id="HSummary28Inthistutorial2CyouhavelearnedtodoX202629" %)
319 (% class="small" %)**Summary (In this tutorial, you have learned to do X…)**
320
321 .
322
323 (% class="wikigeneratedid" id="HAcknowledgementsifappropriate" %)
324 (% class="small" %)**Acknowledgements if appropriate**
325
326 .
327
328 (% class="wikigeneratedid" id="HReferencestowebsites28Formoreinformation2Cvisitusat202629" %)
329 (% class="small" %)**References to websites (For more information, visit us at…)**
330
331 .
332
333 (% class="wikigeneratedid" id="HContactinformation28Forquestions2Ccontactusat202629" %)
334 (% class="small" %)**Contact information (For questions, contact us at…)**
335
336 .