File: examples-frompapers_Kremer_et_al_2011.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 (187 lines) | stat: -rw-r--r-- 7,201 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
.. currentmodule:: brian

.. index::
   pair: example usage; figure
   pair: example usage; show
   pair: example usage; flatten
   pair: example usage; plot
   pair: example usage; imshow
   pair: example usage; hist
   pair: example usage; PoissonGroup
   pair: example usage; real
   pair: example usage; run
   pair: example usage; around
   pair: example usage; imag
   pair: example usage; ExponentialSTDP
   pair: example usage; Connection
   pair: example usage; ones
   pair: example usage; hsv
   pair: example usage; linspace
   pair: example usage; NeuronGroup
   pair: example usage; network_operation
   pair: example usage; colorbar
   pair: example usage; meshgrid
   pair: example usage; exp
   pair: example usage; mean

.. _example-frompapers_Kremer_et_al_2011:

Example: Kremer_et_al_2011 (frompapers)
=======================================

Late Emergence of the Whisker Direction Selectivity Map in the Rat Barrel Cortex
Kremer Y, Leger JF, Goodman DF, Brette R, Bourdieu L (2011). J Neurosci 31(29):10689-700.

Development of direction maps with pinwheels in the barrel cortex.
Whiskers are deflected with random moving bars.
N.B.: network construction can be long.

In this version, STDP is faster than in the paper so that the script runs in just a
few minutes.

::

    from brian import *
    
    # Uncomment if you have a C compiler
    # set_global_preferences(useweave=True,usecodegen=True,usecodegenweave=True,usenewpropagate=True,usecstdp=True)
    
    # PARAMETERS
    # Neuron numbers
    M4,M23exc,M23inh=22,25,12 # side of each barrel (in neurons)
    N4,N23exc,N23inh=M4**2,M23exc**2,M23inh**2 # neurons per barrel
    barrelarraysize=5 # Choose 3 or 4 if memory error
    Nbarrels=barrelarraysize**2
    # Stimulation
    stim_change_time = 5*ms
    Fmax=.5/stim_change_time # maximum firing rate in layer 4 (.5 spike / stimulation)
    # Neuron parameters
    taum,taue,taui=10*ms,2*ms,25*ms
    El=-70*mV
    Vt,vt_inc,tauvt=-55*mV,2*mV,50*ms # adaptive threshold
    # STDP
    taup,taud=5*ms,25*ms
    Ap,Ad=.05,-.04
    # EPSPs/IPSPs
    EPSP,IPSP = 1*mV,-1*mV
    EPSC = EPSP * (taue/taum)**(taum/(taue-taum))
    IPSC = IPSP * (taui/taum)**(taum/(taui-taum))
    # Model: IF with adaptive threshold
    eqs='''
    dv/dt=(ge+gi+El-v)/taum : volt
    dge/dt=-ge/taue : volt
    dgi/dt=-gi/taui : volt
    dvt/dt=(Vt-vt)/tauvt : volt # adaptation
    x : 1
    y : 1
    '''
    # Tuning curve
    tuning=lambda theta:clip(cos(theta),0,Inf)*Fmax
    
    # Layer 4
    layer4=PoissonGroup(N4*Nbarrels)
    barrels4 = dict(((i, j), layer4.subgroup(N4)) for i in xrange(barrelarraysize) for j in xrange(barrelarraysize))
    barrels4active = dict((ij, False) for ij in barrels4)
    barrelindices = dict((ij, slice(b._origin, b._origin+len(b))) for ij, b in barrels4.iteritems())
    layer4.selectivity = zeros(len(layer4))
    for (i, j), inds in barrelindices.iteritems():
        layer4.selectivity[inds]=linspace(0,2*pi,N4)
    
    # Layer 2/3
    layer23=NeuronGroup(Nbarrels*(N23exc+N23inh),model=eqs,threshold='v>vt',reset='v=El;vt+=vt_inc',refractory=2*ms)
    layer23.v=El
    layer23.vt=Vt
    
    # Layer 2/3 excitatory
    layer23exc=layer23.subgroup(Nbarrels*N23exc)
    x,y=meshgrid(arange(M23exc)*1./M23exc,arange(M23exc)*1./M23exc)
    x,y=x.flatten(),y.flatten()
    barrels23 = dict(((i, j), layer23exc.subgroup(N23exc)) for i in xrange(barrelarraysize) for j in xrange(barrelarraysize))
    for i in range(barrelarraysize):
        for j in range(barrelarraysize):
            barrels23[i,j].x=x+i
            barrels23[i,j].y=y+j
    
    # Layer 2/3 inhibitory
    layer23inh=layer23.subgroup(Nbarrels*N23inh)
    x,y=meshgrid(arange(M23inh)*1./M23inh,arange(M23inh)*1./M23inh)
    x,y=x.flatten(),y.flatten()
    barrels23inh = dict(((i, j), layer23inh.subgroup(N23inh)) for i in xrange(barrelarraysize) for j in xrange(barrelarraysize))
    for i in range(barrelarraysize):
        for j in range(barrelarraysize):
            barrels23inh[i,j].x=x+i
            barrels23inh[i,j].y=y+j
    
    print "Building synapses, please wait..."
    # Feedforward connections
    feedforward=Connection(layer4,layer23exc,'ge')
    for i in range(barrelarraysize):
        for j in range(barrelarraysize):
            feedforward.connect_random(barrels4[i,j],barrels23[i,j],sparseness=.5,weight=EPSC*.5)
    stdp=ExponentialSTDP(feedforward,taup,taud,Ap,Ad,wmax=EPSC)
    
    # Excitatory lateral connections
    recurrent_exc=Connection(layer23exc,layer23,'ge')
    recurrent_exc.connect_random(layer23exc,layer23exc,weight=EPSC*.3,
                                 sparseness=lambda i,j:.15*exp(-.5*(((layer23exc.x[i]-layer23exc.x[j])/.4)**2+((layer23exc.y[i]-layer23exc.y[j])/.4)**2)))
    recurrent_exc.connect_random(layer23exc,layer23inh,weight=EPSC,
                                 sparseness=lambda i,j:.15*exp(-.5*(((layer23exc.x[i]-layer23inh.x[j])/.4)**2+((layer23exc.y[i]-layer23inh.y[j])/.4)**2)))
    
    # Inhibitory lateral connections
    recurrent_inh=Connection(layer23inh,layer23exc,'gi')
    recurrent_inh.connect_random(layer23inh,layer23exc,weight=IPSC,
                             sparseness=lambda i,j:exp(-.5*(((layer23inh.x[i]-layer23exc.x[j])/.2)**2+((layer23inh.y[i]-layer23exc.y[j])/.2)**2)))
    
    # Stimulation
    stimspeed = 1./stim_change_time # speed at which the bar of stimulation moves
    direction = 0.0
    stimzonecentre = ones(2)*barrelarraysize/2.
    stimcentre,stimnorm = zeros(2),zeros(2)
    stimradius = (11*stim_change_time*stimspeed+1)*.5
    stimradius2 = stimradius**2
    
    def new_direction():
        global direction
        direction = rand()*2*pi
        stimnorm[:] = (cos(direction), sin(direction))
        stimcentre[:] = stimzonecentre-stimnorm*stimradius
    
    @network_operation
    def stimulation():
        global direction, stimcentre
        stimcentre += stimspeed*stimnorm*defaultclock.dt
        if sum((stimcentre-stimzonecentre)**2)>stimradius2:
            new_direction()
        for (i, j), b in barrels4.iteritems():
            whiskerpos = array([i,j], dtype=float)+0.5
            isactive = abs(dot(whiskerpos-stimcentre, stimnorm))<.5
            if barrels4active[i, j]!=isactive:
                barrels4active[i, j] = isactive
                b.rate = float(isactive)*tuning(layer4.selectivity[barrelindices[i, j]]-direction)
    
    new_direction()
    
    run(5*second,report='text')
    
    figure()
    # Preferred direction
    selectivity=array([mean(array(feedforward[:,i].todense())*exp(layer4.selectivity*1j)) for i in range(len(layer23exc))])
    selectivity=(arctan2(selectivity.imag,selectivity.real) % (2*pi))*180./pi
    
    I=zeros((barrelarraysize*M23exc,barrelarraysize*M23exc))
    ix=array(around(layer23exc.x*M23exc),dtype=int)
    iy=array(around(layer23exc.y*M23exc),dtype=int)
    I[iy,ix]=selectivity
    imshow(I)
    hsv()
    colorbar()
    for i in range(1,barrelarraysize+1):
        plot([i*max(ix)/barrelarraysize,i*max(ix)/barrelarraysize],[0,max(iy)],'k')
        plot([0,max(ix)],[i*max(iy)/barrelarraysize,i*max(iy)/barrelarraysize],'k')
    
    figure()
    hist(selectivity)
    
    show()