Memristor stdp rule

Hello, everybody! Can anybody help me with understanding of implementation of memristor-like stdp rule at Brian2.

Link to the article with equations Modeling the Dynamics of Spiking Networks with
Memristor-Based STDP to Solve Classification Tasks

Dear @mstimberg , can you help me with the implementation of this stdp rule in the synapse of the Brian2 simulator.

Hi @serge25. You can use the same approach I mentioned in this comment: Inhibitory STDP (Borges 2017 equations) - #2 by mstimberg By referring to the difference between lastspike_pre and lastspike_post, you get the \Delta t that you can then plug into the equations. Here’s an example (see the other comment for more explications about the code):

from brian2 import *

A_plus = 0.074; A_minus = -0.047
mu_plus = 26.7*ms; mu_minus = -22.3*ms
tau_plus = 9.3*ms; tau_minus = 10.8*ms

G = NeuronGroup(101, '''
spike_when : second (constant)
lastspike : second  # remove when model uses refractory
threshold='timestep(t, dt) == timestep(spike_when, dt)') # spike at pre-defined time
G.lastspike = -1e9*second
G.spike_when[0] = 100*ms
G.spike_when[1:] = np.linspace(0, 250, 100)*ms

S = Synapses(G, G, 'w : 1',
# the case of dt < 0
lastspike_pre = t
delta_t = (lastspike_post - lastspike_pre)
w += A_minus * w * (1 + tanh((delta_t - mu_minus)/tau_minus))
# the case of dt > 0
lastspike_post = t
delta_t = (lastspike_post - lastspike_pre)
w += A_plus * w * (1 + tanh(-(delta_t - mu_plus)/tau_plus))
S.connect(i=0, j=np.arange(1, 101))  # Connect first neuron to all other neurons
w_init = 0.4
S.w = w_init  # initial value for weights

# Plot difference to inital value
plt.plot((G.spike_when[1:] - G.spike_when[0])/ms, S.w[:] - w_init, color='r', label=f"w = {w_init:.2f}")
plt.axhline(linestyle=':', color='k')
plt.axvline(linestyle=':', color='k')


@mstimberg thank you very much.

Dear @mstimberg it is possible and how define lastspike for poisson group (at situation when we have stdp connection between PG and neuron group)?

Hi @serge25 . You cannot define lastspike for a PoissonGroup, but a PoissonGroup is just a convenience for a NeuronGroup with threshold='rand()<rates*dt', i.e. the following would work as a replacement:

poisson_group = NeuronGroup(N, ''''rates : Hz (constant)
                                   lastspike : second''',
                            reset='lastspike = t')
poisson_group.rates = ...
poisson_group.lastspike = -1e9*second