-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsyn.py
More file actions
executable file
·89 lines (77 loc) · 2.93 KB
/
Copy pathsyn.py
File metadata and controls
executable file
·89 lines (77 loc) · 2.93 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from brian2 import *
from numpy.random import choice
def SynParams(
w_exc = 1.0,
w_inh = -1.0,
tau_exc = 10*ms,
tau_inh = 100*ms,
delay = 1*ms,
condition = 'i != j',
connectivity = 0.1):
return {'w_exc': w_exc, 'w_inh': w_inh, 'tau_exc': tau_exc, 'tau_inh': tau_inh,
'delay': delay, 'condition': condition, 'connectivity': connectivity}
def ExcitatorySynapses(neurons, params=SynParams(), dt=None):
return Synapses(neurons, dt=dt, namespace=params,
model="""
w : 1
dge_syn/dt = -ge_syn / tau_exc : 1
ge_post = ge_syn : 1 (summed)
""", pre="ge_syn = w", post="ge_syn = 0")
def InhibitorySynapses(neurons, params=SynParams(), dt=None):
return Synapses(neurons, dt=dt, namespace=params,
model="""
w : 1
dgi_syn/dt = -gi_syn / tau_inh : 1
gi_post = gi_syn : 1 (summed)
""", pre="gi_syn = w", post="gi_syn = 0")
def ConnectSparse(synapses, condition, connectivity, initial_w, delay):
synapses.connect(condition, p=connectivity)
synapses.w = initial_w
synapses.delay = delay
if __name__ == "__main__":
from lif import *
prefs.codegen.target = 'numpy'
defaultclock.dt = 1*ms
duration = 1*second
figure()
params = LifParams(constant_input=0.8)
params.update(SynParams())
neurons = LifNeurons(2, params)
synapses = ExcitatorySynapses(neurons, params)
synapses.connect(0, 1)
synapses.w = 2.0
spike_monitor = SpikeMonitor(neurons)
state_monitor = StateMonitor(neurons, 'v', record = True, when = 'thresholds')
network = Network()
network.add(neurons, synapses, spike_monitor, state_monitor)
network.run(duration, report='stdout', namespace={})
subplot(211)
title("Excitatory Synapse Induces Postsynaptic Spikes")
v = state_monitor.v[:]
for spike in zip(spike_monitor.i, spike_monitor.t):
v[spike[0], int(spike[1] / defaultclock.dt)] = params['eq_exc']
plot(state_monitor.t/ms, v[0], label = 'v0')
plot(state_monitor.t/ms, v[1], label = 'v1')
legend()
params = LifParams(constant_input=0.8)
params.update(SynParams())
neurons = LifNeurons(2, params)
synapses = InhibitorySynapses(neurons, params)
synapses.connect(0, 1)
synapses.w = -2.0
spike_monitor = SpikeMonitor(neurons)
state_monitor = StateMonitor(neurons, 'v', record=True, when='thresholds')
network = Network()
network.add(neurons, synapses, spike_monitor, state_monitor)
network.run(duration, report='stdout', namespace={})
subplot(212)
title("Inhibitory Synapse Prevents Postsynaptic Spikes")
v = state_monitor.v[:]
for spike in zip(spike_monitor.i, spike_monitor.t):
v[spike[0], int(spike[1] / defaultclock.dt)] = params['eq_exc']
plot(state_monitor.t/ms, v[0], label = 'v0')
plot(state_monitor.t/ms, v[1], label = 'v1')
legend()
show()