| 16 | | For these reasons, PyNN provides the \verb|Population| object, representing a group of neurons all of the same type (although possibly with cell-to-cell variations in the values of parameters), and the \verb|Projection| object, repesenting the set of connections between two \verb|Population|s. |
|---|
| 17 | | All the book-keeping code is contained within the object classes, which also provide functions ('methods') to perform commonly-used tasks, such as recording from a fixed number of cells within the population, chosen at random. |
|---|
| 18 | | |
|---|
| 19 | | By using the \verb|Population| and \verb|Projection| classes, less code needs to be written to create a given simulation, which means fewer-bugs and easier-to-understand scripts, plus, because the code for the classes is used in many different projects, bugs will be found more reliably, and the internal implementation of the classes optimized for performance. |
|---|
| 20 | | Of particular importance is that iterations over large numbers of cells or connections can be done in fast compiled code (within the simulator engines) rather than in comparatively slow Python code. |
|---|
| 21 | | |
|---|
| | 16 | \end{frame} |
|---|
| | 17 | |
|---|
| | 18 | |
|---|
| | 19 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 20 | \frametitle{Populations and Projections} |
|---|
| | 21 | |
|---|
| | 22 | For these reasons, PyNN provides: |
|---|
| | 23 | \begin{itemize} |
|---|
| | 24 | \item the \verb|Population| object, representing a group of neurons all of the same type (although possibly with cell-to-cell variations in the values of parameters) |
|---|
| | 25 | \item the \verb|Projection| object, repesenting the set of connections between two \verb|Population|s. |
|---|
| | 26 | \end{itemize} |
|---|
| | 27 | |
|---|
| | 28 | All the book-keeping code is contained within the object classes, which also provide methods to perform commonly-used tasks, such as recording from a fixed number of cells within the population, chosen at random. |
|---|
| | 29 | |
|---|
| | 30 | [Give a side by side example of the latter?] |
|---|
| | 31 | |
|---|
| | 32 | \end{frame} |
|---|
| | 33 | |
|---|
| | 34 | |
|---|
| | 35 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 36 | \frametitle{Populations and Projections} |
|---|
| | 37 | By using the \verb|Population| and \verb|Projection| classes: |
|---|
| | 38 | \begin{itemize} |
|---|
| | 39 | \item less code needs to be written to create a given simulation |
|---|
| | 40 | \item which means fewer-bugs and easier-to-understand scripts |
|---|
| | 41 | \item plus, because the code for the classes is used in many different projects, bugs will be found more reliably |
|---|
| | 42 | \item and the internal implementation of the classes optimized for performance, e.g. iterations over large numbers of cells or connections can be done in fast compiled code (within the simulator engines) rather than in comparatively slow Python code. |
|---|
| | 43 | \end{itemize} |
|---|
| 28 | | Some examples of creating a population of neurons (don't forget to call \verb|setup()| first). |
|---|
| 29 | | |
|---|
| 30 | | This creates a 10 x 10 array of \verb|IF_curr_exp| neurons with default parameters: |
|---|
| 31 | | \begin{verbatim} |
|---|
| 32 | | >>> p1 = Population((10,10), IF_curr_exp) |
|---|
| 33 | | \end{verbatim} |
|---|
| 34 | | This creates a 1D array of 100 spike sources, and gives it a label: |
|---|
| 35 | | \begin{verbatim} |
|---|
| 36 | | >>> p2 = Population(100, SpikeSourceArray, label="Input Population") |
|---|
| 37 | | \end{verbatim} |
|---|
| 38 | | This illustrates all the possible arguments of the \verb|Population| constructor, with argument names. |
|---|
| 39 | | It creates a 3D array of \verb|IF_cond_alpha| neurons, all with a spike threshold set to -55 mV and membrane time constant set to 10 ms: |
|---|
| 40 | | \begin{verbatim} |
|---|
| 41 | | >>> p3 = Population(dims=(3,4,5), cellclass=IF_cond_alpha, |
|---|
| 42 | | ... cellparams={'v_thresh': -55.0, 'tau_m': 10.0}, |
|---|
| 43 | | ... label="Column 1") |
|---|
| 44 | | \end{verbatim} |
|---|
| | 50 | Create a 10 x 10 array of \verb|IF_curr_exp| neurons with default parameters: |
|---|
| | 51 | \begin{verbatim} |
|---|
| | 52 | >>> p1 = Population((10,10), IF_curr_exp)\end{verbatim} |
|---|
| | 53 | Create a 1D array of 100 spike sources, and give it a label: |
|---|
| | 54 | \begin{verbatim} |
|---|
| | 55 | >>> p2 = Population(100, SpikeSourceArray, |
|---|
| | 56 | label="Input Population")\end{verbatim} |
|---|
| | 57 | Create a 3D array of \verb|IF_cond_alpha| neurons, all with a spike threshold set to -55 mV and membrane time constant set to 10 ms: |
|---|
| | 58 | \small |
|---|
| | 59 | \begin{verbatim} |
|---|
| | 60 | >>> p3 = Population(dims=(3,4,5), cellclass=IF_cond_alpha, |
|---|
| | 61 | ... cellparams={'v_thresh': -55, 'tau_m': 10}, |
|---|
| | 62 | ... label="Column 1") |
|---|
| | 63 | \end{verbatim} |
|---|
| | 64 | |
|---|
| | 65 | \end{frame} |
|---|
| | 66 | |
|---|
| | 67 | |
|---|
| | 68 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 69 | \frametitle{Creating \texttt{Population}s} |
|---|
| 59 | | The above examples all use PyNN standard cell models. It is also possible to use simulator-specific models, but in this case the \verb|cellclass| should be given as a string, e.g.: |
|---|
| 60 | | \begin{verbatim} |
|---|
| 61 | | >>> p4 = Population(20, 'iaf_neuron', cellparams={'Tau': 15.0, 'C': 0.001}) |
|---|
| | 84 | |
|---|
| | 85 | \end{frame} |
|---|
| | 86 | |
|---|
| | 87 | |
|---|
| | 88 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 89 | \frametitle{Creating \texttt{Population}s} |
|---|
| | 90 | The previous examples all use PyNN standard cell models. It is also possible to use simulator-specific models, but in this case the \verb|cellclass| should be given as a string, e.g.: |
|---|
| | 91 | \begin{verbatim} |
|---|
| | 92 | >>> p4 = Population(20, "iaf_neuron", |
|---|
| | 93 | cellparams={'Tau': 15.0, 'C': 0.001}) |
|---|
| 144 | | Setting random values |
|---|
| 145 | | --------------------- |
|---|
| 146 | | |
|---|
| 147 | | To set a parameter to values drawn from a random distribution, use the \verb|rset()| method with a \verb|RandomDistribution| object from the \verb|pyNN.random| module (see the chapter on random numbers for more details). |
|---|
| 148 | | The following example sets the initial membrane potential of each neuron to a value drawn from a uniform distribution between -70 mV and -55 mV: |
|---|
| 149 | | \begin{verbatim} |
|---|
| 150 | | >>> from pyNN.random import RandomDistribution |
|---|
| 151 | | >>> vinit_distr = RandomDistribution(distribution='uniform',parameters=[-70,-55]) |
|---|
| 152 | | >>> p1.rset('v_init', vinit_distr) |
|---|
| 153 | | \end{verbatim} |
|---|
| 154 | | Note that positional arguments can also be used. The following produces the same result as the above: |
|---|
| 155 | | \begin{verbatim} |
|---|
| 156 | | >>> vinit_distr = RandomDistribution('uniform', [-70,-55]) |
|---|
| 157 | | \end{verbatim}For the specific case of setting the initial membrane potential, there is a convenience method \verb|randomInit()|, e.g.: |
|---|
| 158 | | \begin{verbatim} |
|---|
| 159 | | >>> p1.randomInit(vinit_distr) |
|---|
| 160 | | \end{verbatim} |
|---|
| 161 | | \end{frame} |
|---|
| 162 | | |
|---|
| 163 | | |
|---|
| 164 | | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| 165 | | \frametitle{Setting values according to an array} |
|---|
| | 180 | \end{frame} |
|---|
| | 181 | |
|---|
| | 182 | |
|---|
| | 183 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 184 | \frametitle{Setting parameter values} |
|---|
| | 185 | \framesubtitle{Setting random values} |
|---|
| | 186 | |
|---|
| | 187 | To set a parameter to values drawn from a random distribution, use the \verb|rset()| method with a \verb|RandomDistribution| object from the \verb|pyNN.random| module. |
|---|
| | 188 | |
|---|
| | 189 | \vspace{1ex} |
|---|
| | 190 | |
|---|
| | 191 | Sets the initial membrane potential of each neuron to a value drawn from a uniform distribution between -70 mV and -55 mV: |
|---|
| | 192 | \begin{verbatim} |
|---|
| | 193 | >>> from pyNN.random import RandomDistribution |
|---|
| | 194 | >>> distr = RandomDistribution('uniform', [-70,-55]) |
|---|
| | 195 | >>> p1.rset('v_init', distr) |
|---|
| | 196 | \end{verbatim} |
|---|
| | 197 | For the specific case of setting the initial membrane potential, there is a convenience method \verb|randomInit()|, e.g.: |
|---|
| | 198 | \begin{verbatim} |
|---|
| | 199 | >>> p1.randomInit(distr) |
|---|
| | 200 | \end{verbatim} |
|---|
| | 201 | \end{frame} |
|---|
| | 202 | |
|---|
| | 203 | |
|---|
| | 204 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 205 | \frametitle{Setting parameter values} |
|---|
| | 206 | \framesubtitle{Setting values according to an array} |
|---|
| 229 | | Recording spike times is done with the method \verb|record()|. |
|---|
| 230 | | Recording membrane potential is done with the method \verb|record_v()|. |
|---|
| 231 | | Both methods have identical argument lists. |
|---|
| 232 | | Some examples: |
|---|
| 233 | | \begin{verbatim} |
|---|
| 234 | | >>> p1.record() # record from all neurons in the population |
|---|
| 235 | | >>> p1.record(10) # record from 10 neurons chosen at random |
|---|
| 236 | | >>> p1.record([p1[0,0], p1[0,1], p1[0,2]]) # record from specific neurons |
|---|
| 237 | | \end{verbatim} |
|---|
| | 283 | Recording spike times: \verb|record()| |
|---|
| | 284 | |
|---|
| | 285 | Recording membrane potential: \verb|record_v()| |
|---|
| | 286 | |
|---|
| | 287 | \vspace{1ex} |
|---|
| | 288 | |
|---|
| | 289 | Record from all neurons in the population |
|---|
| | 290 | \begin{verbatim} |
|---|
| | 291 | >>> p1.record() |
|---|
| | 292 | \end{verbatim} |
|---|
| | 293 | Record from 10 neurons chosen at random |
|---|
| | 294 | \begin{verbatim} |
|---|
| | 295 | >>> p1.record(10) |
|---|
| | 296 | \end{verbatim} |
|---|
| | 297 | Record from specific neurons |
|---|
| | 298 | \begin{verbatim} |
|---|
| | 299 | >>> p1.record([p1[0,0], p1[0,1], p1[0,2]]) |
|---|
| | 300 | \end{verbatim} |
|---|
| | 301 | \end{frame} |
|---|
| | 302 | |
|---|
| | 303 | |
|---|
| | 304 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 305 | \frametitle{Recording} |
|---|
| | 306 | |
|---|
| 298 | | A \verb|Projection| object is a container for all the synaptic connections between neurons in two \verb|Population|s, together with methods for setting synaptic weights and delays. |
|---|
| 299 | | A \verb|Projection| is created by specifying a pre-synaptic \verb|Population|, a post-synaptic \verb|Population| and a \verb|Connector| object, which determines |
|---|
| 300 | | the algorithm used to wire up the neurons, e.g.: |
|---|
| 301 | | \begin{verbatim} |
|---|
| 302 | | >>> prj2_1 = Projection(p2, p1, method=AllToAllConnector()) |
|---|
| 303 | | \end{verbatim} |
|---|
| 304 | | This connects \verb|p2| (pre-synaptic) to \verb|p1| (post-synaptic), using an '\verb|AllToAllConnector|' object, which connects every neuron in the pre-synaptic population to every neuron in the post-synaptic population. |
|---|
| 305 | | The currently available \verb|Connector| classes are explained below. It is fairly straightforward for a user to write a new \verb|Connector| class if they |
|---|
| 306 | | wish to use a connection algorithm not already available in PyNN. |
|---|
| 307 | | |
|---|
| | 374 | A \verb|Projection| object is a container for all the synaptic connections of a given type between neurons in two \verb|Population|s, together with methods for setting synaptic weights and delays. |
|---|
| | 375 | |
|---|
| | 376 | A \verb|Projection| is created by specifying |
|---|
| | 377 | \begin{itemize} |
|---|
| | 378 | \item a pre-synaptic \verb|Population| |
|---|
| | 379 | \item a post-synaptic \verb|Population| |
|---|
| | 380 | \item a \verb|Connector| object, which determines the algorithm used to wire up the neurons, |
|---|
| | 381 | \end{itemize} |
|---|
| | 382 | |
|---|
| | 383 | \begin{verbatim} |
|---|
| | 384 | >>> prj = Projection(p2, p1, AllToAllConnector())\end{verbatim} |
|---|
| | 385 | |
|---|
| | 386 | This connects \verb|p2| (pre-synaptic) to \verb|p1| (post-synaptic), using an \verb|AllToAllConnector| object, which connects every neuron in the pre-synaptic population to every neuron in the post-synaptic population. |
|---|
| 333 | | >>> invalid_prj = Projection(p2, p3, OneToOneConnector()) #doctest: +IGNORE_EXCEPTION_DETAIL |
|---|
| 334 | | Traceback (most recent call last): |
|---|
| 335 | | File "doctest.py", line 1212, in __run |
|---|
| 336 | | compileflags, 1) in test.globs |
|---|
| 337 | | File "<doctest highlevelapi.txt[49]>", line 1, in <module> |
|---|
| 338 | | invalid_prj = Projection(p2, p3, OneToOneConnector()) |
|---|
| 339 | | File "/home/andrew/dev/pyNN/neuron/__init__.py", line 1199, in __init__ |
|---|
| 340 | | hoc_commands += method.connect(self) |
|---|
| 341 | | File "/home/andrew/dev/pyNN/neuron/connectors.py", line 95, in connect |
|---|
| 342 | | raise Exception("OneToOneConnector does not support presynaptic and postsynaptic Populations of different sizes.") |
|---|
| 343 | | Exception: OneToOneConnector does not support presynaptic and postsynaptic Populations of different sizes. |
|---|
| 344 | | \end{verbatim} |
|---|
| 345 | | |
|---|
| | 414 | >>> prj = Projection(p2, p3, OneToOneConnector()) |
|---|
| | 415 | Traceback (most recent call last): |
|---|
| | 416 | . . . |
|---|
| | 417 | Exception: OneToOneConnector does not support presynaptic and postsynaptic Populations of different sizes. |
|---|
| | 418 | \end{verbatim} |
|---|
| | 419 | |
|---|
| | 420 | Planned extension: allow one-to-row, one-to-column connections, e.g. connecting a 3x5 Population to a 3x5x10 Population. |
|---|
| | 421 | |
|---|
| 365 | | |
|---|
| 366 | | For each pair of pre-post cells, the connection probability depends on distance. |
|---|
| 367 | | If positions in space have been specified using the \verb|positions()| method of the \verb|Population| class or the \verb|position| attributes of individual |
|---|
| 368 | | neurons, these positions are used to calculate distances. |
|---|
| 369 | | If not, the neuron addresses, i.e., the array coordinates, are used. |
|---|
| 370 | | |
|---|
| 371 | | The constructor requires a string \verb|d_expression|, which should be the right-hand side of a valid python expression for probability (i.e. returning a value between 0 and 1), involving '\verb|d|', e.g.: |
|---|
| 372 | | \begin{verbatim} |
|---|
| 373 | | >>> prj1_1b = Projection(p1, p1, DistanceDependentProbabilityConnector("exp(-abs(d))")) |
|---|
| 374 | | >>> prj3_3 = Projection(p3, p3, DistanceDependentProbabilityConnector("float(d<3)")) |
|---|
| 375 | | \end{verbatim} |
|---|
| 376 | | The first example connects neurons with an exponentially-decaying probability. |
|---|
| 377 | | The second example connects each neuron to all its neighbours within a range of 3 units (distance is in $\mu$m if positions have been specified, in array coordinate distance otherwise). |
|---|
| 378 | | |
|---|
| 379 | | The calculation of distance may be controlled by a number of further arguments. |
|---|
| 380 | | |
|---|
| 381 | | By default, the 3D distance between cell positions is used, but the \verb|axes| argument may be used to change this, e.g.: |
|---|
| 382 | | \begin{verbatim} |
|---|
| 383 | | >>> connector = DistanceDependentProbabilityConnector("exp(-abs(d))", axes='xy') |
|---|
| 384 | | \end{verbatim} |
|---|
| | 443 | For each pair of pre-post cells, the connection probability depends on distance (determined from the \verb|position| attributes of the neurons). |
|---|
| | 444 | |
|---|
| | 445 | The constructor requires a string \verb|d_expression|, which should be the right-hand side of a valid Python expression for probability (i.e. returning a value between 0 and 1), involving '\verb|d|'. |
|---|
| | 446 | |
|---|
| | 447 | \vspace{1ex} |
|---|
| | 448 | |
|---|
| | 449 | Connect neurons with an exponentially-decaying probability: |
|---|
| | 450 | \begin{small} |
|---|
| | 451 | \begin{verbatim} |
|---|
| | 452 | >>> DDPC = DistanceDependentProbabilityConnector |
|---|
| | 453 | >>> prj = Projection(p1, p1, |
|---|
| | 454 | DDPC("exp(-abs(d))"))\end{verbatim} |
|---|
| | 455 | \end{small} |
|---|
| | 456 | Connect each neuron to all its neighbours within a range of 30 $\mu$m: |
|---|
| | 457 | \begin{small} |
|---|
| | 458 | \begin{verbatim} |
|---|
| | 459 | >>> prj = Projection(p1, p1, |
|---|
| | 460 | DDPC("float(d<30)")) |
|---|
| | 461 | \end{verbatim} |
|---|
| | 462 | \end{small} |
|---|
| | 463 | \end{frame} |
|---|
| | 464 | |
|---|
| | 465 | |
|---|
| | 466 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 467 | \frametitle{Connecting neurons with a distance-dependent probability} |
|---|
| | 468 | |
|---|
| | 469 | \begin{itemize} |
|---|
| | 470 | \item By default, the 3D distance between cell positions is used, but the \verb|axes| argument may be used to change this: |
|---|
| | 471 | \begin{small} |
|---|
| | 472 | \begin{verbatim} |
|---|
| | 473 | >>> connector = DDPC("exp(-abs(d))", axes='xy')\end{verbatim} |
|---|
| | 474 | \end{small} |
|---|
| 387 | | Similarly, the origins of the coordinate systems of the two Populations and the relative scale of the two coordinate systems may be controlled using the \verb|offset| and \verb|scale_factor| arguments. This is useful when connecting brain regions that have very different sizes but that have a topographic mapping between them, e.g. retina to LGN to V1. |
|---|
| 388 | | |
|---|
| 389 | | In more abstract models, it is often useful to be able to avoid edge effects by specifying periodic boundary conditions, e.g.: |
|---|
| 390 | | \begin{verbatim} |
|---|
| 391 | | >>> connector = DistanceDependentProbabilityConnector("exp(-abs(d))", periodic_boundaries=(500, 500, 0)) |
|---|
| 392 | | \end{verbatim} |
|---|
| | 477 | \item The origins and relative scale of the coordinate systems of the two Populations may be controlled using the \verb|offset| and \verb|scale_factor| arguments. This is useful when connecting brain regions that have very different sizes but that have a topographic mapping between them, e.g. retina to LGN to V1. |
|---|
| | 478 | |
|---|
| | 479 | \item In more abstract models, it is often useful to be able to avoid edge effects by specifying periodic boundary conditions, e.g.: |
|---|
| | 480 | \begin{small} |
|---|
| | 481 | \begin{verbatim} |
|---|
| | 482 | >>> connector = DDPC("exp(-abs(d))", |
|---|
| | 483 | periodic_boundaries=(500, 500, 0))\end{verbatim} |
|---|
| | 484 | \end{small} |
|---|
| 410 | | >>> distr_npost = RandomDistribution(distribution='binomial', parameters=[100,0.3]) |
|---|
| 411 | | >>> prj2_1b = Projection(p2, p1, FixedNumberPostConector(n=distr_npost)) |
|---|
| 412 | | \end{verbatim} |
|---|
| 413 | | |
|---|
| 414 | | \end{frame} |
|---|
| 415 | | |
|---|
| 416 | | |
|---|
| 417 | | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| 418 | | \frametitle{Convergent/fan-in connections} |
|---|
| 419 | | |
|---|
| 420 | | |
|---|
| 421 | | The \verb|FixedNumberPreConnector| has the same arguments as \verb|FixedNumberPostConnector|, but of course it connects each *post*-synaptic neuron to \verb|n| *pre*-synaptic neurons, e.g.: |
|---|
| 422 | | \begin{verbatim} |
|---|
| 423 | | >>> prj2_1c = Projection(p2, p1, FixedNumberPreConnector(5)) |
|---|
| 424 | | >>> distr_npre = RandomDistribution(distribution='poisson', parameters=[5]) |
|---|
| 425 | | >>> prj2_1d = Projection(p2, p1, FixedNumberPreConnector(distr_npre)) |
|---|
| 426 | | \end{verbatim} |
|---|
| 427 | | |
|---|
| 428 | | \end{frame} |
|---|
| | 502 | >>> distr = RandomDistribution('binomial', [100,0.3]) |
|---|
| | 503 | >>> prj = Projection(p2, p1, |
|---|
| | 504 | FixedNumberPostConector(n=distr)) |
|---|
| | 505 | \end{verbatim} |
|---|
| | 506 | |
|---|
| | 507 | The \verb|FixedNumberPreConnector| behaves in an analogous manner. |
|---|
| | 508 | |
|---|
| | 509 | \end{frame} |
|---|
| | 510 | |
|---|
| 453 | | >>> conn_list = [ |
|---|
| 454 | | ... ((0,0), (0,0,0), 0.0, 0.1), |
|---|
| 455 | | ... ((0,0), (0,0,1), 0.0, 0.1), |
|---|
| 456 | | ... ((0,0), (0,0,2), 0.0, 0.1), |
|---|
| 457 | | ... ((0,1), (1,3,0), 0.0, 0.1) |
|---|
| 458 | | ... ] |
|---|
| 459 | | >>> prj1_3d = Projection(p1, p3, FromListConnector(conn_list)) |
|---|
| | 539 | >>> conn_list = [ |
|---|
| | 540 | ... ((0,0), (0,0,0), 0.0, 0.1), |
|---|
| | 541 | ... ((0,0), (0,0,1), 0.0, 0.1), |
|---|
| | 542 | ... ((0,0), (0,0,2), 0.0, 0.1), |
|---|
| | 543 | ... ((0,1), (1,3,0), 0.0, 0.1) |
|---|
| | 544 | ... ] |
|---|
| | 545 | >>> prj1_3d = Projection(p1, p3, |
|---|
| | 546 | FromListConnector(conn_list)) |
|---|
| 490 | | >>> delay_distr = RandomDistribution(distribution='gamma',parameters=[1,0.1]) |
|---|
| 491 | | >>> connector = FixedNumberPostConnector(n=20, delays=delay_distr) |
|---|
| 492 | | >>> prj2_1e = Projection(p2, p1, connector) |
|---|
| 493 | | \end{verbatim} |
|---|
| | 577 | >>> distr = RandomDistribution('gamma', [1,0.1]) |
|---|
| | 578 | >>> conn = FixedNumberPostConnector(n=20, delays=distr) |
|---|
| | 579 | >>> prj = Projection(p2, p1, conn)\end{verbatim} |
|---|
| 496 | | >>> weights = numpy.arange(1.1, 2.0, 0.9/60) |
|---|
| 497 | | >>> delays = 2*weights |
|---|
| 498 | | >>> connector = OneToOneConnector(weights=weights, delays=delays) |
|---|
| 499 | | >>> prj1_1d = Projection(p1, p1, connector) |
|---|
| 500 | | \end{verbatim} |
|---|
| 501 | | After creating the \verb|Projection|, to set the weights of all synaptic connections in a \verb|Projection| to a single value, use the \verb|setWeights()| method: |
|---|
| 502 | | \begin{verbatim} |
|---|
| 503 | | >>> prj1_1.setWeights(0.2) |
|---|
| 504 | | \end{verbatim} |
|---|
| 505 | | [Note: synaptic weights in PyNN are in nA for current-based synapses and µS for conductance-based synapses)]. |
|---|
| 506 | | |
|---|
| 507 | | To set different weights to different values, use \verb|setWeights()| with a list or 1D numpy array argument, where the length of the list/array is equal to the number of synapses, e.g.: |
|---|
| 508 | | \begin{verbatim} |
|---|
| 509 | | >>> weight_list = 0.1*numpy.ones(len(prj2_1)) |
|---|
| 510 | | >>> weight_list[0:5] = 0.2 |
|---|
| 511 | | >>> prj2_1.setWeights(weight_list) |
|---|
| 512 | | \end{verbatim} |
|---|
| 513 | | To set weights to random values, use the \verb|randomizeWeights()| method: |
|---|
| 514 | | \begin{verbatim} |
|---|
| 515 | | >>> weight_distr = RandomDistribution(distribution='gamma',parameters=[1,0.1]) |
|---|
| 516 | | >>> prj1_1.randomizeWeights(weight_distr) |
|---|
| 517 | | \end{verbatim} |
|---|
| 518 | | Setting delays works similarly: |
|---|
| 519 | | \begin{verbatim} |
|---|
| 520 | | >>> prj1_1.setDelays(0.6) |
|---|
| 521 | | >>> delay_list = 0.3*numpy.ones(len(prj2_1)) |
|---|
| 522 | | >>> delay_list[0:5] = 0.4 |
|---|
| 523 | | >>> prj2_1.setDelays(delay_list) |
|---|
| 524 | | >>> delay_distr = RandomDistribution(distribution='gamma',parameters=[2,0.2]) |
|---|
| 525 | | >>> prj1_1.randomizeDelays(delay_distr) |
|---|
| 526 | | \end{verbatim} |
|---|
| | 582 | >>> weights = numpy.arange(1.1, 2.0, 0.9/len(p1)) |
|---|
| | 583 | >>> delays = 2*weights |
|---|
| | 584 | >>> connector = OneToOneConnector(weights=weights, |
|---|
| | 585 | delays=delays) |
|---|
| | 586 | >>> prj = Projection(p1, p1, connector) |
|---|
| | 587 | \end{verbatim} |
|---|
| | 588 | |
|---|
| | 589 | \end{frame} |
|---|
| | 590 | |
|---|
| | 591 | |
|---|
| | 592 | \begin{frame}[fragile] % -------------------------------------------------------------------- |
|---|
| | 593 | \frametitle{Setting synaptic weights and delays} |
|---|
| | 594 | \framesubtitle{for an existing \texttt{Projection}} |
|---|
| | 595 | |
|---|
| | 596 | Set the weights of all synaptic connections in a \verb|Projection| to a single value: \begin{verbatim} |
|---|
| | 597 | >>> prj.setWeights(0.2)\end{verbatim} |
|---|
| | 598 | {\footnotesize[Units: nA for current-based synapses and µS for conductance-based synapses.]} |
|---|
| | 599 | |
|---|
| | 600 | Set different weights to different values: |
|---|
| | 601 | \begin{verbatim} |
|---|
| | 602 | >>> weight_list = 0.1*numpy.ones(len(prj)) |
|---|
| | 603 | >>> weight_list[0:5] = 0.2 |
|---|
| | 604 | >>> prj.setWeights(weight_list)\end{verbatim} |
|---|
| | 605 | |
|---|
| | 606 | Set weights to random values: |
|---|
| | 607 | \begin{verbatim} |
|---|
| | 608 | >>> weight_distr = RandomDistribution('gamma', [1,0.1]) |
|---|
| | 609 | >>> prj.randomizeWeights(weight_distr)\end{verbatim} |
|---|
| | 610 | |
|---|
| | 611 | Setting delays works similarly {\small(\verb|setDelays()|, \verb|randomizeDelays()|)}. |
|---|