Changes for page 03. Building and simulating a simple model
Last modified by adavison on 2022/10/04 13:55
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -106,264 +106,37 @@ 106 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 107 (% style="color:#e74c3c" %)population1 = sim.Population(100, cell_type, label="Population 1") 108 108 population1.record("v") 109 -sim.run(100.0)(%%) 110 -\\**Run script in terminal** 109 +sim.run(100.0) 111 111 ))) 112 112 113 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 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 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 140 141 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 142 143 -(% class="box infomessage" %) 144 -((( 145 -**Screencast** - changes in editor 146 - 118 +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, and let's plot membrane voltage from _all_ the neurons. 147 147 148 -**...** 149 -(% style="color:#000000" %)Figure( 150 - Panel( 151 - data_v[:, (% style="color:#e74c3c" %)0:5(% style="color:#000000" %)], 152 - xticks=True, xlabel="Time (ms)", 153 - yticks=True, ylabel="Membrane potential (mV)" 154 - ), 155 - title="Response of (% style="color:#e74c3c" %)first five neurons(% style="color:#000000" %)", 156 - annotations="Simulated with NEST" 157 -).show()(%%) 158 -\\**Run script in terminal, show figure** 159 -))) 160 - 161 -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. 162 - 163 -(% class="box infomessage" %) 164 -((( 165 -**Screencast** - changes in editor 166 -\\(% style="color:#000000" %)"""Simple network model using PyNN""" 167 -\\import pyNN.nest as sim(%%) 168 -(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%) 169 -(% style="color:#e74c3c" %)from pyNN.random import RandomDistribution(%%) 170 -(% style="color:#000000" %)sim.setup(timestep=0.1)(%%) 171 -(% style="color:#000000" %)cell_type = sim.IF_curr_exp( 172 - (% style="color:#e74c3c" %) v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), 173 - v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}), 174 - v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%) 175 -(% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%) 176 - 177 - 178 -**...** 179 - 180 - 181 -(% style="color:#000000" %)Figure( 182 - Panel( 183 - data_v[:, 0:5], 184 - xticks=True, xlabel="Time (ms)", 185 - yticks=True, ylabel="Membrane potential (mV)" 186 - ), 187 - title="Response of first five neurons (% style="color:#e74c3c" %)with heterogeneous parameters(% style="color:#000000" %)", 188 - annotations="Simulated with NEST" 189 -).show()(%%) 190 -\\**Run script in terminal, show figure** 191 -))) 192 - 193 193 Now if we run our simulation again, we can see the effect of this heterogeneity in the neuron population. 194 194 195 -(% class="box successmessage" %) 196 -((( 197 -**Slide** showing addition of second population, and of connections between them 198 -))) 122 +TO BE COMPLETED 199 199 200 -(% class="wikigeneratedid" %) 201 - Sofar we have a populationof neurons, but therearenoconnectionsbetweenthem, we don't have a network. Let'sadda second populationof the samesizes the first, but we'll set the offset current to zero, so theydon'tfire actionpotentialsspontaneously.124 +(% class="wikigeneratedid" id="HSummary28Inthistutorial2CyouhavelearnedtodoX202629" %) 125 +(% class="small" %)**Summary (In this tutorial, you have learned to do X…)** 202 202 203 -(% class="box infomessage" %) 204 -((( 205 -**Screencast** - changes in editor 206 -\\**...** 207 -(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%) 208 -(% style="color:#e74c3c" %)population2 = sim.Population(100, cell_type, label="Population 2") 209 -population2.set(i_offset=0)(%%) 210 -(% style="color:#000000" %)population1.record("v")(%%) 211 -(% style="color:#e74c3c" %)population2.record("v")(%%) 212 -(% style="color:#000000" %)sim.run(100.0)(%%) 213 -**...** 214 -))) 127 +. 215 215 216 -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. 129 +(% class="wikigeneratedid" id="HAcknowledgementsifappropriate" %) 130 +(% class="small" %)**Acknowledgements if appropriate** 217 217 218 -(% class="box successmessage" %) 219 -((( 220 -**Slide** showing all-to-all connections 221 -))) 132 +. 222 222 223 -We could connect all neurons in Population 1 to all those in Population 2. 134 +(% class="wikigeneratedid" id="HReferencestowebsites28Formoreinformation2Cvisitusat202629" %) 135 +(% class="small" %)**References to websites (For more information, visit us at…)** 224 224 225 -(% class="box successmessage" %) 226 -((( 227 -**Slide** showing random connections 228 -))) 137 +. 229 229 230 -We could connect the populations randomly, in several different ways. 139 +(% class="wikigeneratedid" id="HContactinformation28Forquestions2Ccontactusat202629" %) 140 +(% class="small" %)**Contact information (For questions, contact us at…)** 231 231 232 -(% class="box successmessage" %) 233 -((( 234 -**Slide** showing distance-dependent connections 235 -))) 236 - 237 -(% class="wikigeneratedid" %) 238 -We could connect the populations randomly, but with a probability of connection that depends on the distance between the neurons. 239 - 240 -(% class="box successmessage" %) 241 -((( 242 -**Slide** showing explicit lists of connections 243 -))) 244 - 245 -(% class="wikigeneratedid" %) 246 -Or we could connect the neurons in a very specific manner, based on an explicit list of connections. 247 - 248 -(% class="wikigeneratedid" %) 249 -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. 250 - 251 -(% class="box successmessage" %) 252 -((( 253 -**Slide** showing addition of second population, and of connections between them, labelled as a Projection. 254 -))) 255 - 256 -(% class="wikigeneratedid" %) 257 -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. 258 - 259 -(% class="box infomessage" %) 260 -((( 261 -**Screencast** - changes in editor 262 - 263 - 264 -**...** 265 -(% style="color:#000000" %)population2.record("v")(%%) 266 -(% style="color:#e74c3c" %)connection_algorithm = sim.FixedProbabilityConnector(p=0.5) 267 -synapse_type = sim.StaticSynapse(weight=0.5, delay=0.5) 268 -connections = sim.Projection(population1, population2, connection_algorithm, synapse_type)(%%) 269 -(% style="color:#000000" %)sim.run(100.0)(%%) 270 -**...** 271 -))) 272 - 273 -(% class="wikigeneratedid" %) 274 -Finally, let's update our figure, by adding a second panel to show the responses of Population 2. 275 - 276 -(% class="box infomessage" %) 277 -((( 278 -**Screencast** - changes in editor 279 -\\**...** 280 -(% style="color:#000000" %)sim.run(100.0)(%%) 281 -(% style="color:#e74c3c" %)data1_v(% style="color:#000000" %) = population1.get_data().segments[0].filter(name='v')[0](%%) 282 -(% style="color:#e74c3c" %)data2_v = population2.get_data().segments[0].filter(name='v')[0](%%) 283 -(% style="color:#000000" %)Figure( 284 - Panel( 285 - (% style="color:#e74c3c" %)data1_v(% style="color:#000000" %)[:, 0:5], 286 - xticks=True, (% style="color:#e74c3c" %)--xlabel="Time (ms)",--(%%) 287 -(% style="color:#000000" %) yticks=True, ylabel="Membrane potential (mV)" 288 - ), 289 - (% style="color:#e74c3c" %)Panel( 290 - data2_v[:, 0:5], 291 - xticks=True, xlabel="Time (ms)", 292 - yticks=True" 293 - ),(%%) 294 -(% style="color:#000000" %) title="Response of (% style="color:#e74c3c" %)simple network(% style="color:#000000" %)", 295 - annotations="Simulated with NEST" 296 -).show() 297 - 298 -**Run script in terminal, show figure** 299 -))) 300 - 301 -(% class="wikigeneratedid" %) 302 -and there we have it, our simple neuronal network of integrate-and-fire neurons, written in PyNN, simulated with NEST. If you prefer to use the NEURON simulator, PyNN makes this very simple, we import the PyNN-for-NEURON module instead. 303 - 304 -(% class="box infomessage" %) 305 -((( 306 -**Screencast** - final state of editor 307 -\\(% style="color:#000000" %)"""Simple network model using PyNN""" 308 -\\import pyNN.(% style="color:#e74c3c" %)neuron(% style="color:#000000" %) as sim(%%) 309 -(% style="color:#000000" %)from pyNN.utility.plotting import Figure, Panel(%%) 310 -(% style="color:#000000" %)from pyNN.random import RandomDistribution(%%) 311 -(% style="color:#000000" %)sim.setup(timestep=0.1)(%%) 312 -(% style="color:#000000" %)cell_type = sim.IF_curr_exp( 313 - (% style="color:#e74c3c" %) (% style="color:#000000" %)v_rest=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), 314 - v_thresh=RandomDistribution('normal', {'mu': -55.0, 'sigma': 1.0}), 315 - v_reset=RandomDistribution('normal', {'mu': -65.0, 'sigma': 1.0}), (%%) 316 -(% style="color:#000000" %) t_refrac=1, tau_m=10, cm=1, i_offset=0.1)(%%) 317 -(% style="color:#000000" %)population1 = sim.Population(100, cell_type, label="Population 1")(%%) 318 -(% style="color:#000000" %)population2 = sim.Population(100, cell_type, label="Population 2") 319 -population2.set(i_offset=0) 320 -population1.record("v") 321 -population2.record("v")(%%) 322 -(% style="color:#000000" %)connection_algorithm = sim.FixedProbabilityConnector(p=0.5) 323 -synapse_type = sim.StaticSynapse(weight=0.5, delay=0.5) 324 -connections = sim.Projection(population1, population2, connection_algorithm, synapse_type)(%%) 325 -(% style="color:#000000" %)sim.run(100.0)(%%) 326 -(% style="color:#000000" %)data1_v = population1.get_data().segments[0].filter(name='v')[0] 327 -data2_v = population2.get_data().segments[0].filter(name='v')[0] 328 -Figure( 329 - Panel( 330 - data1_v[:, 0:5], 331 - xticks=True, 332 - yticks=True, ylabel="Membrane potential (mV)" 333 - ), 334 - Panel( 335 - data2_v[:, 0:5], 336 - xticks=True, xlabel="Time (ms)", 337 - yticks=True" 338 - ),(%%) 339 -(% style="color:#000000" %) title="Response of simple network", 340 - annotations="Simulated with (% style="color:#e74c3c" %)NEURON(% style="color:#000000" %)" 341 -).show() 342 - 343 -**Run script in terminal, show figure** 344 -))) 345 - 346 -(% class="wikigeneratedid" %) 347 -As you would hope, NEST and NEURON give essentially identical results. 348 - 349 -(% class="box successmessage" %) 350 -((( 351 -**Slide** recap of learning objectives 352 -))) 353 - 354 -That is the end of this tutorial, in which I've demonstrated how to build a simple network using PyNN, and to simulate it using two different simulators, NEST and NEURON. 355 - 356 -Of course, PyNN allows you to create much more complex networks than this, with more realistic neuron models, synaptic plasticity, spatial structure, and so on. You can also use other simulators, such as Brian or SpiNNaker, and you can run simulations in parallel on clusters or supercomputers. 357 - 358 -We will be releasing a series of tutorials, throughout the rest of 2021 and 2022, to introduce these more advanced features of PyNN, so keep an eye on the EBRAINS website. 359 - 360 -(% class="box successmessage" %) 361 -((( 362 -**Slide** acknowledgements, contact information 363 -))) 364 - 365 -(% class="wikigeneratedid" %) 366 -PyNN has been developed by many different people, with financial support from several different organisations. I'd like to mention in particular the CNRS and the European Commission, through the FACETS, BrainScaleS and Human Brain Project grants. 367 - 368 -(% class="wikigeneratedid" %) 369 -For more information visit neuralensemble.org/PyNN. If you have questions you can contact us through the PyNN Github project, the NeuralEnsemble forum, EBRAINS support, or the EBRAINS Community. 142 +.