File: examples-misc_stopping.txt

package info (click to toggle)
brian 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, stretch
  • size: 23,436 kB
  • sloc: python: 68,707; cpp: 29,040; ansic: 5,182; sh: 111; makefile: 61
file content (65 lines) | stat: -rw-r--r-- 1,814 bytes parent folder | download | duplicates (2)
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
64
65
.. currentmodule:: brian

.. index::
   pair: example usage; NeuronGroup
   pair: example usage; run
   pair: example usage; PopulationRateMonitor
   pair: example usage; Clock
   pair: example usage; network_operation
   pair: example usage; Connection
   pair: example usage; PoissonGroup

.. _example-misc_stopping:

Example: stopping (misc)
========================

Network to demonstrate stopping a simulation during a run

Have a fully connected network of integrate and fire neurons
with input fed by a group of Poisson neurons with a steadily
increasing rate, want to determine the point in time at which
the network of integrate and fire neurons switches from no
firing to all neurons firing, so we have a network_operation
called stop_condition that calls the stop() function if the
monitored network firing rate is above a minimum threshold.

::

    
    from brian import *
    
    clk = Clock()
    
    Vr = 0 * mV
    El = 0 * mV
    Vt = 10 * mV
    tau = 10 * ms
    weight = 0.2 * mV
    duration = 100 * msecond
    max_input_rate = 10000 * Hz
    num_input_neurons = 1000
    input_connection_p = 0.1
    rate_per_neuron = max_input_rate / (num_input_neurons * input_connection_p)
    
    P = PoissonGroup(num_input_neurons, lambda t: rate_per_neuron * (t / duration))
    
    G = NeuronGroup(1000, model='dV/dt=-(V-El)/tau : volt', threshold=Vt, reset=Vr)
    G.V = Vr + (Vt - Vr) * rand(len(G))
    
    CPG = Connection(P, G, weight=weight, sparseness=input_connection_p)
    
    CGG = Connection(G, G, weight=weight)
    
    MP = PopulationRateMonitor(G, bin=1 * ms)
    
    @network_operation
    def stop_condition():
        if MP.rate[-1] * Hz > 10 * Hz:
            stop()
    
    run(duration)
    
    print "Reached population rate>10 Hz by time", clk.t, "+/- 1 ms."