File: examples-misc_poisson.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 (65 lines) | stat: -rw-r--r-- 1,333 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
64
65
.. currentmodule:: brian

.. index::
   pair: example usage; raster_plot
   pair: example usage; SpikeMonitor
   pair: example usage; PoissonGroup
   pair: example usage; run
   pair: example usage; show

.. _example-misc_poisson:

Example: poisson (misc)
=======================

This example demonstrates the PoissonGroup object. Here we have
used a custom function to generate different rates at different
times.

This example also demonstrates a custom SpikeMonitor.

::

    #import brian_no_units # uncomment to run faster
    from brian import *
    
    # Rates
    
    r1 = arange(101, 201) * 0.1 * Hz
    r2 = arange(1, 101) * 0.1 * Hz
    
    def myrates(t):
        if t < 10 * second:
            return r1
        else:
            return r2
    # More compact: myrates=lambda t: (t<10*second and r1) or r2
    
    # Neuron group
    P = PoissonGroup(100, myrates)
    
    # Calculation of rates
    
    ns = zeros(len(P))
    
    def ratemonitor(spikes):
        ns[spikes] += 1
    
    Mf = SpikeMonitor(P, function=ratemonitor)
    M = SpikeMonitor(P)
    
    # Simulation and plotting
    
    run(10 * second)
    print "Rates after 10s:"
    print ns / (10 * second)
    
    ns[:] = 0
    run(10 * second)
    print "Rates after 20s:"
    print ns / (10 * second)
    
    raster_plot()
    show()