#!pip install ANNarchy
PyNN and Brian examples
import numpy as np
import matplotlib.pyplot as plt
import ANNarchy as ann
=0.1) ann.setup(dt
ANNarchy 4.8 (4.8.2) on darwin (posix).
IF_curr_alpha
Simple network with a Poisson spike source projecting to a pair of IF_curr_alpha neurons.
This is a reimplementation of the PyNN example:
http://www.neuralensemble.org/trac/PyNN/wiki/Examples/simpleNetwork
# Parameters
= 1000.0
tstop = 100.0
rate
# Create the Poisson spikes
= int(2*tstop*rate/1000.0)
number 26278342)
np.random.seed(= np.add.accumulate(np.random.exponential(1000.0/rate, size=number))
spike_times
# Input population
= ann.SpikeSourceArray(list(spike_times))
inp
# Output population
= ann.Population(2, ann.IF_curr_alpha)
pop = 2.0,
pop.tau_refrac = -50.0,
pop.v_thresh = 2.0,
pop.tau_syn_E = 2.0
pop.tau_syn_I
# Excitatory projection
= ann.Projection(inp, pop, 'exc')
proj =1.0)
proj.connect_all_to_all(weights
# Monitor
= ann.Monitor(pop, ['spike', 'v'])
m
# Compile the network
= ann.Network()
net
net.add([inp, pop, proj, m])compile()
net.
# Simulate
net.simulate(tstop)= net.get(m).get()
data
# Plot the results
=(12, 8))
plt.figure(figsize*np.arange(tstop/ann.dt()), data['v'][:, 0])
plt.plot(ann.dt()'Time (ms)')
plt.xlabel('Vm (mV)')
plt.ylabel(-66.0, -48.0])
plt.ylim(['Simple Network')
plt.title( plt.show()
Compiling network 1... OK
IF_cond_exp
A single IF neuron with exponential, conductance-based synapses, fed by two spike sources.
This is a reimplementation of the PyNN example:
http://www.neuralensemble.org/trac/PyNN/wiki/Examples/IF_cond_exp
# Parameters
= 200.0
tstop
# Input populations with predetermined spike times
= ann.SpikeSourceArray(spike_times= [float(i) for i in range(5,105,10)] )
spike_sourceE = ann.SpikeSourceArray(spike_times= [float(i) for i in range(155,255,10)])
spike_sourceI
# Population with one IF_cond_exp neuron
= ann.Population(1, ann.IF_cond_exp)
ifcell set(
ifcell.'i_offset' : 0.1, 'tau_refrac' : 3.0,
{ 'v_thresh' : -51.0, 'tau_syn_E' : 2.0,
'tau_syn_I': 5.0, 'v_reset' : -70.0,
'e_rev_E' : 0., 'e_rev_I' : -80.0 } )
# Projections
= ann.Projection(spike_sourceE, ifcell, 'exc')
connE =0.006, delays=2.0)
connE.connect_all_to_all(weights
= ann.Projection(spike_sourceI, ifcell, 'inh')
connI =0.02, delays=4.0)
connI.connect_all_to_all(weights
# Monitor
= ann.Monitor(ifcell, ['spike', 'v'])
m
# Compile the network
= ann.Network()
net
net.add([spike_sourceE, spike_sourceI, ifcell, connE, connI, m])compile()
net.
# Simulate
net.simulate(tstop)= net.get(m).get()
data
# Show the result
=(12, 8))
plt.figure(figsize*np.arange(tstop/ann.dt()), data['v'][:, 0])
plt.plot(ann.dt()'Time (ms)')
plt.xlabel('Vm (mV)')
plt.ylabel(-66.0, -61.0])
plt.ylim(['IF_cond_exp')
plt.title( plt.show()
Compiling network 1... OK
EIF_cond_exp
Network of EIF neurons with exponentially decreasing conductance-based synapses.
This is a reimplementation of the Brian example:
http://brian.readthedocs.org/en/1.4.1/examples-misc_expIF_network.html
= ann.Neuron(
EIF = """
parameters v_rest = -70.0 : population
cm = 0.2 : population
tau_m = 10.0 : population
tau_syn_E = 5.0 : population
tau_syn_I = 10.0 : population
e_rev_E = 0.0 : population
e_rev_I = -80.0 : population
delta_T = 3.0 : population
v_thresh = -55.0 : population
v_reset = -70.0 : population
v_spike = -20.0 : population
""",
="""
equations dv/dt = (v_rest - v + delta_T * exp( (v-v_thresh)/delta_T) )/tau_m + ( g_exc * (e_rev_E - v) + g_inh * (e_rev_I - v) )/cm
tau_syn_E * dg_exc/dt = - g_exc
tau_syn_I * dg_inh/dt = - g_inh
""",
= """
spike v > v_spike
""",
= """
reset v = v_reset
""",
= 2.0
refractory
)
# Poisson inputs
= ann.PoissonPopulation(geometry=200, rates="if t < 200.0 : 2000.0 else : 0.0")
i_exc = ann.PoissonPopulation(geometry=200, rates="if t < 100.0 : 2000.0 else : 0.0")
i_inh
# Main population
= ann.Population(geometry=4000, neuron=EIF)
P
# Subpopulations
= P[:3200]
Pe = P[3200:]
Pi
# Projections
= 1.5 / 1000.0 # excitatory synaptic weight
we = 2.5 * we # inhibitory synaptic weight
wi
= ann.Projection(Pe, P, 'exc')
Ce =we, probability=0.05)
Ce.connect_fixed_probability(weights
= ann.Projection(Pi, P, 'inh')
Ci =wi, probability=0.05)
Ci.connect_fixed_probability(weights
= ann.Projection(i_exc, P[:200], 'exc') # inputs to excitatory cells
Ie =we)
Ie.connect_one_to_one(weights
= ann.Projection(i_inh, P[3200:3400], 'exc')# inputs to inhibitory cells
Ii =we)
Ii.connect_one_to_one(weights
# Initialization of variables
= -70.0 + 10.0 * np.random.rand(P.size)
P.v = (np.random.randn(P.size) * 2.0 + 5.0) * we
P.g_exc = (np.random.randn(P.size) * 2.0 + 5.0) * wi
P.g_inh
# Monitor
= ann.Monitor(P, 'spike')
m
# Compile the Network
= ann.Network()
net
net.add([P, i_exc, i_inh, Ce, Ci, Ie, Ii, m])compile()
net.
# Simulate
500.0, measure_time=True)
net.simulate(
# Retrieve recordings
= net.get(m).get()
data = net.get(m).raster_plot(data['spike'])
t, n
=(12, 8))
plt.figure(figsize'.', markersize=0.2)
plt.plot(t, n, plt.show()
Compiling network 3... OK
Simulating 0.5 seconds of the network 3 took 1.0771634578704834 seconds.
AEIF_cond_exp
Adaptive exponential integrate-and-fire model.
http://www.scholarpedia.org/article/Adaptive_exponential_integrate-and-fire_model
Model introduced in:
Brette R. and Gerstner W. (2005), Adaptive Exponential Integrate-and-Fire Model as an Effective Description of Neuronal Activity, J. Neurophysiol. 94: 3637 - 3642.
This is a reimplementation of the Brian example:
https://brian.readthedocs.io/en/stable/examples-frompapers_Brette_Gerstner_2005.html
# Create a population with one AdEx neuron
= ann.Population(geometry=1, neuron=ann.EIF_cond_exp_isfa_ista)
pop
# Regular spiking (paper)
= 144.0, 4.0, 0.0805, -70.6
pop.tau_w, pop.a, pop.b, pop.v_reset
# Bursting
#pop.tau_w, pop.a, pop.b, pop.v_reset = 20.0, 4.0, 0.5, pop.v_thresh + 5.0
# Fast spiking
#pop.tau_w, pop.a, pop.b, pop.v_reset = 144.0, 2000.0*pop.cm/144.0, 0.0, -70.6
# Monitor
= ann.Monitor(pop, ['spike', 'v', 'w'])
m
# Compile the network
= ann.Network()
net
net.add([pop, m])compile()
net.
# Add current of 1 nA and simulate
20.0)
net.simulate(= 1.0
net.get(pop).i_offset 100.0)
net.simulate(= 0.0
net.get(pop).i_offset 20.0)
net.simulate(
# Retrieve the results
= net.get(m).get()
data = data['spike'][0]
spikes = data['v'][:, 0]
v = data['w'][:, 0]
w if len(spikes)>0:
= 20.0
v[spikes]
# Plot the activity
=(12, 8))
plt.figure(figsize2,1,1)
plt.subplot(*np.arange(140.0/ann.dt()), v)
plt.plot(ann.dt()'v')
plt.ylabel('Adaptive exponential integrate-and-fire')
plt.title(2,1,2)
plt.subplot(*np.arange(140.0/ann.dt()), w)
plt.plot(ann.dt()'Time (ms)')
plt.xlabel('w')
plt.ylabel( plt.show()
Compiling network 4... OK
Non-linear synapses
A single IF neuron with two non-linear NMDA synapses.
This is a reimplementation of the Brian example:
http://brian.readthedocs.org/en/latest/examples-synapses_nonlinear_synapses.html
# Neurons
= ann.Neuron(equations="dv/dt = 0.1", spike="v>1.0", reset="v=0.0")
Linear = ann.Neuron(equations="dv/dt = 0.1*(g_exc -v)", spike="v>2.0", reset="v=0.0")
Integrator
# Non-linear synapse
= ann.Synapse(
NMDA = """
parameters tau = 10.0 : projection
""",
= """
equations tau * dx/dt = -x
tau * dg/dt = -g + x * (1 -g)
""",
= "x += w",
pre_spike = "g"
psp
)
# Populations
input = ann.Population(geometry=2, neuron=Linear)
input.v = [0.0, 0.5]
= ann.Population(geometry=1, neuron=Integrator)
pop
# Projection
= ann.Projection(
proj =input, post=pop, target='exc',
pre=NMDA)
synapse=[[1.0, 10.0]])
proj.connect_from_matrix(weights
# Monitors
= ann.Monitor(pop, 'v')
m = ann.Monitor(proj, 'g')
w
# Compile the network
= ann.Network()
net input, pop, proj, m, w])
net.add([compile()
net.
# Simulate for 100 ms
100.0)
net.simulate(
# Retrieve recordings
= net.get(m).get('v')[:, 0]
v = net.get(w).get('g')[:, 0, :]
s
# Plot the recordings
=(12, 8))
plt.figure(figsize
2,1,1)
plt.subplot(0])
plt.plot(s[:, 1])
plt.plot(s[:, "Time (ms)")
plt.xlabel("Conductance")
plt.xlabel(
2,1,2)
plt.subplot(
plt.plot(v)"Time (ms)")
plt.xlabel("Membrane potential")
plt.xlabel( plt.show()
WARNING: Monitor(): it is a bad idea to record synaptic variables of a projection at each time step!
WARNING: Monitor(): it is a bad idea to record synaptic variables of a projection at each time step!
Compiling network 5... OK
STP
Network (CUBA) with short-term synaptic plasticity for excitatory synapses (depressing at long timescales, facilitating at short timescales).
Adapted from :
https://brian.readthedocs.io/en/stable/examples-synapses_short_term_plasticity2.html
= 1000.0
duration
= ann.Neuron(
LIF = """
parameters tau_m = 20.0 : population
tau_e = 5.0 : population
tau_i = 10.0 : population
E_rest = -49.0 : population
E_thresh = -50.0 : population
E_reset = -60.0 : population
""",
= """
equations tau_m * dv/dt = E_rest -v + g_exc - g_inh
tau_e * dg_exc/dt = -g_exc
tau_i * dg_inh/dt = -g_inh
""",
= "v > E_thresh",
spike = "v = E_reset"
reset
)
= ann.Synapse(
STP = """
parameters tau_rec = 200.0 : projection
tau_facil = 20.0 : projection
U = 0.2 : projection
""",
= """
equations dx/dt = (1 - x)/tau_rec : init = 1.0, event-driven
du/dt = (U - u)/tau_facil : init = 0.2, event-driven
""",
="""
pre_spike g_target += w * u * x
x *= (1 - u)
u += U * (1 - u)
"""
)
# Population
= ann.Population(geometry=4000, neuron=LIF)
P = ann.Uniform(-60.0, -50.0)
P.v = P[:3200]
Pe = P[3200:]
Pi
# Projections
= ann.Projection(pre=Pe, post=P, target='exc', synapse = STP)
con_e =1.62, probability=0.02)
con_e.connect_fixed_probability(weights
= ann.Projection(pre=Pi, post=P, target='inh')
con_i =9.0, probability=0.02)
con_i.connect_fixed_probability(weights
# Monitor
= ann.Monitor(P, 'spike')
m
# Compile the network
= ann.Network()
net
net.add([P, con_e, con_i, m])compile()
net.
# Simulate without plasticity
=True)
net.simulate(duration, measure_time
= net.get(m).get()
data = net.get(m).raster_plot(data['spike'])
t, n = net.get(m).population_rate(data['spike'], 5.0)
rates print('Total number of spikes: ' + str(len(t)))
=(12, 8))
plt.figure(figsize211)
plt.subplot('.')
plt.plot(t, n, 'Time (ms)')
plt.xlabel('Neuron number')
plt.ylabel(212)
plt.subplot(*ann.dt(), rates)
plt.plot(np.arange(rates.size) plt.show()
Compiling network 6... OK
Simulating 1.0 seconds of the network 6 took 0.31792426109313965 seconds.
Total number of spikes: 14115