| 1 |
#!/usr/bin/env python |
| 2 |
""" |
| 3 |
Late Emergence of the Whisker Direction Selectivity Map in the Rat Barrel Cortex. |
| 4 |
Kremer Y, Leger JF, Goodman DF, Brette R, Bourdieu L (2011). |
| 5 |
J Neurosci 31(29):10689-700. |
| 6 |
|
| 7 |
Development of direction maps with pinwheels in the barrel cortex. |
| 8 |
Whiskers are deflected with random moving bars. |
| 9 |
|
| 10 |
N.B.: network construction can be long. |
| 11 |
""" |
| 12 |
from brian2 import * |
| 13 |
import time |
| 14 |
|
| 15 |
t1 = time.time() |
| 16 |
|
| 17 |
# PARAMETERS |
| 18 |
# Neuron numbers |
| 19 |
M4, M23exc, M23inh = 22, 25, 12 # size of each barrel (in neurons) |
| 20 |
N4, N23exc, N23inh = M4**2, M23exc**2, M23inh**2 # neurons per barrel |
| 21 |
barrelarraysize = 5 # Choose 3 or 4 if memory error |
| 22 |
Nbarrels = barrelarraysize**2 |
| 23 |
# Stimulation |
| 24 |
stim_change_time = 5*ms |
| 25 |
Fmax = .5/stim_change_time # maximum firing rate in layer 4 (.5 spike / stimulation) |
| 26 |
# Neuron parameters |
| 27 |
taum, taue, taui = 10*ms, 2*ms, 25*ms |
| 28 |
El = -70*mV |
| 29 |
Vt, vt_inc, tauvt = -55*mV, 2*mV, 50*ms # adaptive threshold |
| 30 |
# STDP |
| 31 |
taup, taud = 5*ms, 25*ms |
| 32 |
Ap, Ad= .05, -.04 |
| 33 |
# EPSPs/IPSPs |
| 34 |
EPSP, IPSP = 1*mV, -1*mV |
| 35 |
EPSC = EPSP * (taue/taum)**(taum/(taue-taum)) |
| 36 |
IPSC = IPSP * (taui/taum)**(taum/(taui-taum)) |
| 37 |
Ap, Ad = Ap*EPSC, Ad*EPSC |
| 38 |
|
| 39 |
# Layer 4, models the input stimulus |
| 40 |
eqs_layer4 = ''' |
| 41 |
rate = int(is_active)*clip(cos(direction - selectivity), 0, inf)*Fmax: Hz |
| 42 |
is_active = abs((barrel_x + 0.5 - bar_x) * cos(direction) + (barrel_y + 0.5 - bar_y) * sin(direction)) < 0.5: boolean |
| 43 |
barrel_x : integer # The x index of the barrel |
| 44 |
barrel_y : integer # The y index of the barrel |
| 45 |
selectivity : 1 |
| 46 |
# Stimulus parameters (same for all neurons) |
| 47 |
bar_x = cos(direction)*(t - stim_start_time)/(5*ms) + stim_start_x : 1 (shared) |
| 48 |
bar_y = sin(direction)*(t - stim_start_time)/(5*ms) + stim_start_y : 1 (shared) |
| 49 |
direction : 1 (shared) # direction of the current stimulus |
| 50 |
stim_start_time : second (shared) # start time of the current stimulus |
| 51 |
stim_start_x : 1 (shared) # start position of the stimulus |
| 52 |
stim_start_y : 1 (shared) # start position of the stimulus |
| 53 |
''' |
| 54 |
layer4 = NeuronGroup(N4*Nbarrels, eqs_layer4, threshold='rand() < rate*dt', |
| 55 |
method='euler', name='layer4') |
| 56 |
layer4.barrel_x = '(i // N4) % barrelarraysize + 0.5' |
| 57 |
layer4.barrel_y = 'i // (barrelarraysize*N4) + 0.5' |
| 58 |
layer4.selectivity = '(i%N4)/(1.0*N4)*2*pi' # for each barrel, selectivity between 0 and 2*pi |
| 59 |
|
| 60 |
stimradius = (11+1)*.5 |
| 61 |
|
| 62 |
# Chose a new randomly oriented bar every 60ms |
| 63 |
runner_code = ''' |
| 64 |
direction = rand()*2*pi |
| 65 |
stim_start_x = barrelarraysize / 2.0 - cos(direction)*stimradius |
| 66 |
stim_start_y = barrelarraysize / 2.0 - sin(direction)*stimradius |
| 67 |
stim_start_time = t |
| 68 |
''' |
| 69 |
layer4.run_regularly(runner_code, dt=60*ms, when='start') |
| 70 |
|
| 71 |
# Layer 2/3 |
| 72 |
# Model: IF with adaptive threshold |
| 73 |
eqs_layer23 = ''' |
| 74 |
dv/dt=(ge+gi+El-v)/taum : volt |
| 75 |
dge/dt=-ge/taue : volt |
| 76 |
dgi/dt=-gi/taui : volt |
| 77 |
dvt/dt=(Vt-vt)/tauvt : volt # adaptation |
| 78 |
barrel_idx : integer |
| 79 |
x : 1 # in "barrel width" units |
| 80 |
y : 1 # in "barrel width" units |
| 81 |
''' |
| 82 |
layer23 = NeuronGroup(Nbarrels*(N23exc+N23inh), eqs_layer23, |
| 83 |
threshold='v>vt', reset='v = El; vt += vt_inc', |
| 84 |
refractory=2*ms, method='euler', name='layer23') |
| 85 |
layer23.v = El |
| 86 |
layer23.vt = Vt |
| 87 |
|
| 88 |
# Subgroups for excitatory and inhibitory neurons in layer 2/3 |
| 89 |
layer23exc = layer23[:Nbarrels*N23exc] |
| 90 |
layer23inh = layer23[Nbarrels*N23exc:] |
| 91 |
|
| 92 |
# Layer 2/3 excitatory |
| 93 |
# The units for x and y are the width/height of a single barrel |
| 94 |
layer23exc.x = '(i % (barrelarraysize*M23exc)) * (1.0/M23exc)' |
| 95 |
layer23exc.y = '(i // (barrelarraysize*M23exc)) * (1.0/M23exc)' |
| 96 |
layer23exc.barrel_idx = 'floor(x) + floor(y)*barrelarraysize' |
| 97 |
|
| 98 |
# Layer 2/3 inhibitory |
| 99 |
layer23inh.x = 'i % (barrelarraysize*M23inh) * (1.0/M23inh)' |
| 100 |
layer23inh.y = 'i // (barrelarraysize*M23inh) * (1.0/M23inh)' |
| 101 |
layer23inh.barrel_idx = 'floor(x) + floor(y)*barrelarraysize' |
| 102 |
|
| 103 |
print("Building synapses, please wait...") |
| 104 |
# Feedforward connections (plastic) |
| 105 |
feedforward = Synapses(layer4, layer23exc, |
| 106 |
model='''w:volt |
| 107 |
dA_source/dt = -A_source/taup : volt (event-driven) |
| 108 |
dA_target/dt = -A_target/taud : volt (event-driven)''', |
| 109 |
on_pre='''ge+=w |
| 110 |
A_source += Ap |
| 111 |
w = clip(w+A_target, 0*volt, EPSC)''', |
| 112 |
on_post=''' |
| 113 |
A_target += Ad |
| 114 |
w = clip(w+A_source, 0*volt, EPSC)''', |
| 115 |
name='feedforward') |
| 116 |
# Connect neurons in the same barrel with 50% probability |
| 117 |
feedforward.connect('(barrel_x_pre + barrelarraysize*barrel_y_pre) == barrel_idx_post', |
| 118 |
p=0.5) |
| 119 |
feedforward.w = EPSC*.5 |
| 120 |
|
| 121 |
print('excitatory lateral') |
| 122 |
# Excitatory lateral connections |
| 123 |
recurrent_exc = Synapses(layer23exc, layer23, model='w:volt', on_pre='ge+=w', |
| 124 |
name='recurrent_exc') |
| 125 |
recurrent_exc.connect(p='.15*exp(-.5*(((x_pre-x_post)/.4)**2+((y_pre-y_post)/.4)**2))') |
| 126 |
recurrent_exc.w['j<Nbarrels*N23exc'] = EPSC*.3 # excitatory->excitatory |
| 127 |
recurrent_exc.w['j>=Nbarrels*N23exc'] = EPSC # excitatory->inhibitory |
| 128 |
|
| 129 |
|
| 130 |
# Inhibitory lateral connections |
| 131 |
print('inhibitory lateral') |
| 132 |
recurrent_inh = Synapses(layer23inh, layer23exc, on_pre='gi+=IPSC', |
| 133 |
name='recurrent_inh') |
| 134 |
recurrent_inh.connect(p='exp(-.5*(((x_pre-x_post)/.2)**2+((y_pre-y_post)/.2)**2))') |
| 135 |
|
| 136 |
if get_device().__class__.__name__=='RuntimeDevice': |
| 137 |
print('Total number of connections') |
| 138 |
print('feedforward: %d' % len(feedforward)) |
| 139 |
print('recurrent exc: %d' % len(recurrent_exc)) |
| 140 |
print('recurrent inh: %d' % len(recurrent_inh)) |
| 141 |
|
| 142 |
t2 = time.time() |
| 143 |
print("Construction time: %.1fs" % (t2 - t1)) |
| 144 |
|
| 145 |
run(5*second, report='text') |
| 146 |
|
| 147 |
# Calculate the preferred direction of each cell in layer23 by doing a |
| 148 |
# vector average of the selectivity of the projecting layer4 cells, weighted |
| 149 |
# by the synaptic weight. |
| 150 |
_r = bincount(feedforward.j, |
| 151 |
weights=feedforward.w * cos(feedforward.selectivity_pre)/feedforward.N_incoming, |
| 152 |
minlength=len(layer23exc)) |
| 153 |
_i = bincount(feedforward.j, |
| 154 |
weights=feedforward.w * sin(feedforward.selectivity_pre)/feedforward.N_incoming, |
| 155 |
minlength=len(layer23exc)) |
| 156 |
selectivity_exc = (arctan2(_r, _i) % (2*pi))*180./pi |
| 157 |
|
| 158 |
|
| 159 |
scatter(layer23.x[:Nbarrels*N23exc], layer23.y[:Nbarrels*N23exc], |
| 160 |
c=selectivity_exc[:Nbarrels*N23exc], |
| 161 |
edgecolors='none', marker='s', cmap='hsv') |
| 162 |
vlines(np.arange(barrelarraysize), 0, barrelarraysize, 'k') |
| 163 |
hlines(np.arange(barrelarraysize), 0, barrelarraysize, 'k') |
| 164 |
clim(0, 360) |
| 165 |
colorbar() |
| 166 |
show() |