File: examples-misc_multipleclocks.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (63 lines) | stat: -rw-r--r-- 2,224 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
.. currentmodule:: brian

.. index::
   pair: example usage; NeuronGroup
   pair: example usage; run
   pair: example usage; show
   pair: example usage; network_operation
   pair: example usage; Clock
   pair: example usage; plot
   pair: example usage; StateMonitor

.. _example-misc_multipleclocks:

Example: multipleclocks (misc)
==============================

This example demonstrates using different clocks for different objects
in the network. The clock ``simclock`` is the clock used for the
underlying simulation. The clock ``monclock`` is the clock used for
monitoring the membrane potential. This monitoring takes place less
frequently than the simulation update step to save time and memory.
Finally, the clock ``inputclock`` controls when the external 'current'
``Iext`` should be updated. In this  case, we update it infrequently
so we can see the effect on the network.

This example also demonstrates the @network_operation decorator. A
function with this decorator will be run as part of the network
update step, in sync with the clock provided (or the default one
if none is provided).

::

    
    from brian import *
    # define the three clocks
    simclock = Clock(dt=0.1 * ms)
    monclock = Clock(dt=0.3 * ms)
    inputclock = Clock(dt=100 * ms)
    # simple leaky I&F model with external 'current' Iext as a parameter
    tau = 10 * ms
    eqs = '''
    dV/dt = (-V+Iext)/tau : volt
    Iext: volt
    '''
    # A single leaky I&F neuron with simclock as its clock
    G = NeuronGroup(1, model=eqs, reset=0 * mV, threshold=10 * mV, clock=simclock)
    G.V = 5 * mV
    # This function will be run in sync with inputclock i.e. every 100 ms
    @network_operation(clock=inputclock)
    def update_Iext():
        G.Iext = rand(len(G)) * 20 * mV
    # V is monitored in sync with monclock
    MV = StateMonitor(G, 'V', record=0, clock=monclock)
    # run and plot 
    run(1000 * ms)
    plot(MV.times / ms, MV[0] / mV)
    show()
    # You should see 10 different regions, sometimes Iext will be above threshold
    # in which case you will see regular spiking at different rates, and sometimes
    # it will be below threshold in which case you'll see exponential decay to that
    # value