| 1 |
""" |
| 2 |
A simple example showing how string expressions can be used to implement |
| 3 |
spatial (deterministic or stochastic) connection patterns. |
| 4 |
""" |
| 5 |
from brian2 import * |
| 6 |
|
| 7 |
rows, cols = 20, 20 |
| 8 |
G = NeuronGroup(rows * cols, '''x : meter |
| 9 |
y : meter''') |
| 10 |
# initialize the grid positions |
| 11 |
grid_dist = 25*umeter |
| 12 |
G.x = '(i // rows) * grid_dist - rows/2.0 * grid_dist' |
| 13 |
G.y = '(i % rows) * grid_dist - cols/2.0 * grid_dist' |
| 14 |
|
| 15 |
# Deterministic connections |
| 16 |
distance = 120*umeter |
| 17 |
S_deterministic = Synapses(G, G) |
| 18 |
S_deterministic.connect('sqrt((x_pre - x_post)**2 + (y_pre - y_post)**2) < distance') |
| 19 |
|
| 20 |
# Random connections (no self-connections) |
| 21 |
S_stochastic = Synapses(G, G) |
| 22 |
S_stochastic.connect('i != j', |
| 23 |
p='1.5 * exp(-((x_pre-x_post)**2 + (y_pre-y_post)**2)/(2*(60*umeter)**2))') |
| 24 |
|
| 25 |
figure(figsize=(12, 6)) |
| 26 |
|
| 27 |
# Show the connections for some neurons in different colors |
| 28 |
for color in ['g', 'b', 'm']: |
| 29 |
subplot(1, 2, 1) |
| 30 |
neuron_idx = np.random.randint(0, rows*cols) |
| 31 |
plot(G.x[neuron_idx] / umeter, G.y[neuron_idx] / umeter, 'o', mec=color, |
| 32 |
mfc='none') |
| 33 |
plot(G.x[S_deterministic.j[neuron_idx, :]] / umeter, |
| 34 |
G.y[S_deterministic.j[neuron_idx, :]] / umeter, color + '.') |
| 35 |
subplot(1, 2, 2) |
| 36 |
plot(G.x[neuron_idx] / umeter, G.y[neuron_idx] / umeter, 'o', mec=color, |
| 37 |
mfc='none') |
| 38 |
plot(G.x[S_stochastic.j[neuron_idx, :]] / umeter, |
| 39 |
G.y[S_stochastic.j[neuron_idx, :]] / umeter, color + '.') |
| 40 |
|
| 41 |
for idx, t in enumerate(['determininstic connections', |
| 42 |
'random connections']): |
| 43 |
subplot(1, 2, idx + 1) |
| 44 |
xlim((-rows/2.0 * grid_dist) / umeter, (rows/2.0 * grid_dist) / umeter) |
| 45 |
ylim((-cols/2.0 * grid_dist) / umeter, (cols/2.0 * grid_dist) / umeter) |
| 46 |
title(t) |
| 47 |
xlabel('x') |
| 48 |
ylabel('y', rotation='horizontal') |
| 49 |
axis('equal') |
| 50 |
|
| 51 |
tight_layout() |
| 52 |
show() |