#!pip install ANNarchy
STDP - single synapse
This notebook demonstrates the online implementation of the spike time-dependent plasticity (STDP) rule for a pair of neurons.
import numpy as np
import ANNarchy as ann
import matplotlib.pyplot as plt
ANNarchy 4.8 (4.8.2) on darwin (posix).
The STDP learning rule maintains exponentially-decaying traces for the pre-synaptic and post-synaptic spikes.
\tau^+ \, \frac{d x(t)}{dt} = -x (t)
\tau^- \, \frac{d y(t)}{dt} = -x (t)
LTP and LTD occur at spike times depending on the corresponding traces.
- When a pre-synaptic spike occurs, x(t) is incremented and LTD is applied proportionally to y(t).
- When a post-synaptic spike occurs, y(t) is incremented and LTP is applied proportionally to x(t).
= ann.Synapse(
STDP = """
parameters tau_plus = 20.0 : projection ; tau_minus = 20.0 : projection
A_plus = 0.01 : projection ; A_minus = 0.01 : projection
w_min = 0.0 : projection ; w_max = 2.0 : projection
""",
= """
equations
tau_plus * dx/dt = -x : event-driven # pre-synaptic trace
tau_minus * dy/dt = -y : event-driven # post-synaptic trace
""",
="""
pre_spike
g_target += w
x += A_plus * w_max
w = clip(w - y, w_min , w_max) # LTD
""",
="""
post_spike
y += A_minus * w_max
w = clip(w + x, w_min , w_max) # LTP
"""
)
We create two dummy populations with one neuron each, whose spike times we can control.
= ann.SpikeSourceArray([[0.]])
pre = ann.SpikeSourceArray([[50.]]) post
We connect the population using a STDP synapse.
= ann.Projection(pre, post, 'exc', STDP)
proj 1.0) proj.connect_all_to_all(
<ANNarchy.core.Projection.Projection at 0x1291c8ec0>
compile() ann.
Compiling ... OK
The presynaptic neuron will fire at avrious times between 0 and 100 ms, while the postsynaptic neuron keeps firing at 50 ms.
= np.linspace(100.0, 0.0, 101) pre_times
= []
weight_changes for t_pre in pre_times:
# Reset the populations
pre.clear()
post.clear()= [[t_pre]]
pre.spike_times = [[50.0]]
post.spike_times
# Reset the traces
= 0.0
proj.x = 0.0
proj.y
# Weight before the simulation
= proj[0].w[0]
w_before
# Simulate long enough
105.0)
ann.simulate(
# Record weight change
= proj[0].w[0] - w_before
delta_w weight_changes.append(delta_w)
We can now plot the classical STDP figure:
=(10, 8))
plt.figure(figsize50. - pre_times, weight_changes, "*")
plt.plot(-50, 50], [0, 0], 'k')
plt.plot([0, 0], [min(weight_changes), max(weight_changes)], 'k')
plt.plot(["t_post - t_pre")
plt.xlabel("delta_w")
plt.ylabel( plt.show()