Debian Codegraph @

docs_sphinx/user/refractoriness.rst

raw
1 Refractoriness
2 ==============
3
4 .. contents::
5 :local:
6 :depth: 1
7
8
9 Brian allows you to model the absolute refractory period of a neuron in a flexible
10 way. The definition of refractoriness consists of two components: the amount of time
11 after a spike that a neuron is considered to be refractory, and what changes in the
12 neuron during the refractoriness.
13
14 Defining the refractory period
15 ------------------------------
16
17 The refractory period is specified by the ``refractory`` keyword in the
18 `NeuronGroup` initializer. In the simplest case, this is simply a fixed time,
19 valid for all neurons::
20
21 G = NeuronGroup(N, model='...', threshold='...', reset='...',
22 refractory=2*ms)
23
24 Alternatively, it can be a string expression that evaluates to a time. This
25 expression will be evaluated after every spike and allows for a varying
26 refractory period. For example, the following will set the refractory period
27 to a random duration between 1ms and 3ms after every spike::
28
29 G = NeuronGroup(N, model='...', threshold='...', reset='...',
30 refractory='(1 + 2*rand())*ms')
31
32 In general, modelling a refractory period that varies across neurons involves
33 declaring a state variable that stores the refractory period per neuron as a
34 model parameter. The refractory expression can then refer to this parameter::
35
36 G = NeuronGroup(N, model='''...
37 ref : second''', threshold='...',
38 reset='...', refractory='ref')
39 # Set the refractory period for each cell
40 G.ref = ...
41
42 This state variable can also be a dynamic variable itself. For example, it can
43 serve as an adaptation mechanism by increasing it after every spike and letting
44 it relax back to a steady-state value between spikes::
45
46 refractory_0 = 2*ms
47 tau_refractory = 50*ms
48 G = NeuronGroup(N, model='''...
49 dref/dt = (refractory_0 - ref) / tau_refractory : second''',
50 threshold='...', refractory='ref',
51 reset='''...
52 ref += 1*ms''')
53 G.ref = refractory_0
54
55 In some cases, the condition for leaving the refractory period is not easily
56 expressed as a certain time span. For example, in a Hodgkin-Huxley type model the
57 threshold is only used for *counting* spikes and the refractoriness is used to
58 prevent the count of multiple spikes for a single threshold crossing (the threshold
59 condition would evaluate to ``True`` for several time points). When a neuron
60 should leave the refractory period is not easily expressed as a time span but
61 more naturally as a condition that the neuron should remain refractory for as
62 long as it stays above the threshold. This can be achieved by using a string
63 expression for the ``refractory`` keyword that evaluates to a boolean condition::
64
65 G = NeuronGroup(N, model='...', threshold='v > -20*mV',
66 refractory='v >= -20*mV')
67
68 The ``refractory`` keyword should be read as "stay refractory as long as the
69 condition remains true". In fact, specifying a time span for the refractoriness
70 will be automatically transformed into a logical expression using the current
71 time ``t`` and the time of the last spike ``lastspike``. Specifying
72 ``refractory=2*ms`` is basically equivalent to specifying
73 ``refractory='(t - lastspike) <= 2*ms'``. However, this expression can give
74 inconsistent results for the common case that the refractory period is a
75 multiple of the simulation timestep. Due to floating point impreciseness, the
76 actual value of ``t - lastspike`` can be slightly above or below a multiple of
77 the simulation time step; comparing it directly to the refractory period can
78 therefore lead to an end of the refractory one time step sooner or later. To
79 avoid this issue, the actual code used for the above example is equivalent to
80 ``refractory='timestep(t - lastspike, dt) <= timestep(2*ms, dt)'``. The
81 `~brian2.core.functions.timestep` function is provided by Brian and takes care of
82 converting a time into a time step in a safe way.
83
84 .. versionadded:: 2.1.3
85 The `timestep` function is now used to avoid floating point issues in the
86 refractoriness calculation. To restore the previous behaviour, set the
87 `legacy.refractory_timing` preference to ``True``.
88
89 Defining model behaviour during refractoriness
90 ----------------------------------------------
91
92 The refractoriness definition as described above only has a single
93 effect by itself: threshold crossings during the refractory period are ignored.
94 In the following model, the variable ``v`` continues to update during the
95 refractory period but it does not elicit a spike if it crosses the threshold::
96
97 G = NeuronGroup(N, 'dv/dt = -v / tau : 1',
98 threshold='v > 1', reset='v=0',
99 refractory=2*ms)
100
101 There is also a second implementation of refractoriness that is
102 supported by Brian, one or several state variables can be clamped during the
103 refractory period. To model this kind of behaviour, variables that should
104 stop being updated during refractoriness can be marked with the
105 ``(unless refractory)`` flag::
106
107 G = NeuronGroup(N, '''dv/dt = -(v + w)/ tau_v : 1 (unless refractory)
108 dw/dt = -w / tau_w : 1''',
109 threshold='v > 1', reset='v=0; w+=0.1', refractory=2*ms)
110
111 In the above model, the ``v`` variable is clamped at 0 for 2ms after a spike but
112 the adaptation variable ``w`` continues to update during this time. In
113 addition, a variable of a neuron that is in its refractory period is
114 *read-only*: incoming synapses or other code will have no effect on the
115 value of ``v`` until it leaves its refractory period.
116
117 .. admonition:: The following topics are not essential for beginners.
118
119 |
120
121
122 Arbitrary refractoriness
123 ------------------------
124
125 In fact, arbitrary behaviours can be defined using Brian's refractoriness
126 mechanism.
127
128 A `NeuronGroup` with refractoriness automatically defines two variables:
129
130 ``not_refractory``
131 A boolean variable stating whether a neuron is allowed to spike.
132
133 ``lastspike``
134 The time of the last spike of the neuron.
135
136 The variable ``not_refractory`` is updated at every time step by checking the
137 refractoriness condition -- for a refractoriness defined by a time period, this
138 means comparing ``lastspike`` to the current time ``t``. The ``not_refractory``
139 variable is then used to implement
140 the refractoriness behaviour. Specifically, the ``threshold`` condition
141 is replaced by ``threshold and not_refractory`` and differential equations
142 that are marked as ``(unless refractory)`` are multiplied by
143 ``int(not_refractory)`` (so that they have the value 0 when the neuron is
144 refractory).
145
146 This ``not_refractory`` variable is also available to the user
147 to define more sophisticated refractoriness behaviour.
148 For example, the following code updates the
149 ``w`` variable with a different time constant during refractoriness::
150
151 G = NeuronGroup(N, '''dv/dt = -(v + w)/ tau_v : 1 (unless refractory)
152 dw/dt = (-w / tau_active)*int(not_refractory) + (-w / tau_ref)*(1 - int(not_refractory)) : 1''',
153 threshold='v > 1', reset='v=0; w+=0.1', refractory=2*ms)