Debian Codegraph @

examples/synapses/homeostatic_stdp_at_inhibitory_synapes.py

raw
1 #!/usr/bin/env python
2
3 """
4 This script implements a homeostatic STDP rule for inhibitory
5 synapses onto excitatory neurons presented in Zenke et al. (2015) and
6 explained in detail in the accompanying supplementary information.
7
8 In essence, the magnitude and sign of the STDP kernel at inhibitory
9 synapses targeting excitatory neurons is modulated by a global factor
10 G, which corresponds to the difference between the average firing rate
11 of the excitatory postsynaptic neurons and a target firing rate
12 :math:`\gamma`. If the average firing rate of excitatory neurons exceeds the
13 target firing rate, pre/post pairings (and post/pre pairings) at
14 inhibitory synapses connecting to excitatory neurons result in
15 potentiation; depression of the inhibitory synapses occurs when the
16 excitatory neurons are unable to match the desired target rate.
17
18 The script emulates classic STDP protocols, simulating a connected
19 presynaptic and postsynaptic neuron pair with precisely controlled
20 spike times, and a large, independently firing population of
21 excitatory neurons.
22
23 Paul Brodersen, 2025
24
25 Reference:
26 Zenke, Friedemann, Everton J. Agnes, and Wulfram Gerstner.
27 "Diverse Synaptic Plasticity Mechanisms Orchestrated to Form and
28 Retrieve Memories in Spiking Neural Networks." Nature Communications 6,
29 no. 1 (April 21, 2015): 6922. https://doi.org/10.1038/ncomms7922.
30 """
31
32 import numpy as np
33 import matplotlib.pyplot as plt
34 import brian2 as b2
35
36 net = b2.Network()
37
38 # excitatory neuron population
39 epoch_length = 1 * b2.second
40 spike_rate = np.arange(0, 12.5, 2.5)
41 total_epochs = len(spike_rate)
42 population_spike_rate = b2.TimedArray(spike_rate * b2.Hz, dt=epoch_length)
43 population_size = 1000
44 spike_generators = b2.PoissonGroup(population_size, rates="population_spike_rate(t)")
45 net.add(spike_generators)
46
47 # global factor G
48 gamma = 5 * b2.Hz
49 tau_H = 0.1 * b2.second # NB: value in Zenke et al (2015) is 10 seconds; reduced here to allow for shorter simulations
50 global_factor_model = """
51 G = H - gamma : Hz
52 dH/dt = -H/tau_H : Hz
53 """
54 global_factor = b2.NeuronGroup(1, model=global_factor_model)
55 net.add(global_factor)
56 spike_aggregator = b2.Synapses(spike_generators, global_factor, on_pre="H_post += 1/(tau_H * population_size)")
57 spike_aggregator.connect()
58 net.add(spike_aggregator)
59
60 # pre-synaptic neuron
61 spike_times = epoch_length * (np.arange(total_epochs) + 0.5)
62 spike_indices = np.zeros_like(spike_times / b2.second)
63 presynaptic_neuron = b2.SpikeGeneratorGroup(1, spike_indices, spike_times)
64 net.add(presynaptic_neuron)
65
66 # postsynaptic neuron
67 delay = 1 * b2.msecond
68 postsynaptic_neuron = b2.SpikeGeneratorGroup(1, spike_indices, spike_times + delay)
69 net.add(postsynaptic_neuron)
70
71 # synapse
72 tau_stdp = 20. * b2.msecond
73 eta = 1. * b2.nsiemens * b2.second
74 synapse_model = """
75 G : Hz (linked)
76 wij : siemens
77 dzi/dt = -zi / tau_stdp : 1 (event-driven)
78 dzj/dt = -zj / tau_stdp : 1 (event-driven)
79 """
80 on_pre = """
81 zj += 1.
82 wij += eta * G * (zi + 1)
83 """
84 on_post = """
85 zi += 1.
86 wij += eta * G * zj
87 """
88 synapse = b2.Synapses(
89 presynaptic_neuron, postsynaptic_neuron,
90 model=synapse_model, on_pre=on_pre, on_post=on_post
91 )
92 synapse.connect(i=0, j=0)
93 synapse.G = b2.linked_var(global_factor, "G")
94 synapse.wij = 0 * b2.nsiemens
95 net.add(synapse)
96
97 # monitor
98 monitor = b2.StateMonitor(synapse, ["G", "wij"], record=True, dt=1*b2.msecond)
99 net.add(monitor)
100
101 # run
102 net.run(total_epochs * epoch_length)
103
104 # analysis
105 G = np.squeeze(monitor.G / b2.Hz)
106 wij = np.squeeze(monitor.wij / b2.nsiemens)
107 time = np.squeeze(monitor.t / b2.ms)
108 spike_times = spike_times / b2.ms
109
110 # visualize experimental protocol
111 fig, axes = plt.subplots(2, 1, sharex=True)
112 fig.suptitle("Experimental protocol")
113 axes[0].plot(time, G)
114 axes[0].set_ylabel("G [Hz]")
115 axes[1].plot(time, wij)
116 axes[1].set_ylabel("Weight [nS]")
117 for ax in axes:
118 ax.vlines(spike_times, *ax.get_ylim(), color="gray", linestyle=":", label="Pre/post spike pairings")
119 axes[0].legend(loc="upper left")
120 axes[-1].set_xlabel("Time [ms]")
121
122 # plot relationship between G and \Delta wij
123 g = np.zeros_like(spike_times)
124 dw = np.zeros_like(spike_times)
125 for ii, spike_time in enumerate(spike_times):
126 g[ii] = G[np.argmin(np.abs(time - spike_time))]
127 w0 = wij[np.argmin(np.abs(time - spike_time - 10))]
128 w1 = wij[np.argmin(np.abs(time - spike_time + 10))]
129 dw[ii] = w1 - w0
130
131 fig, ax = plt.subplots()
132 ax.plot(g, dw, 'o')
133 ax.set_xlabel("G [Hz]")
134 ax.set_ylabel(r"$\Delta$weight [nS]")
135 ax.set_title("Weight change modulation")
136
137 plt.show()