.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/clopath_synapse_small_network.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_clopath_synapse_small_network.py: Clopath Rule: Bidirectional connections --------------------------------------- .. only:: html ---- Run this example as a Jupyter notebook: .. card:: :width: 25% :margin: 2 :text-align: center :link: https://lab.ebrains.eu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fnest%2Fnest-simulator-examples&urlpath=lab%2Ftree%2Fnest-simulator-examples%2Fnotebooks%2Fnotebooks%2Fclopath_synapse_small_network.ipynb&branch=main :link-alt: JupyterHub service .. image:: https://nest-simulator.org/TryItOnEBRAINS.png .. grid:: 1 1 1 1 :padding: 0 0 2 0 .. grid-item:: :class: sd-text-muted :margin: 0 0 3 0 :padding: 0 0 3 0 :columns: 4 See :ref:`our guide ` for more information and troubleshooting. ---- This script simulates a small network of ten excitatory and three inhibitory ``aeif_psc_delta_clopath`` neurons. The neurons are randomly connected and driven by 500 Poisson generators. The synapses from the Poisson generators to the excitatory population and those among the neurons of the network are Clopath synapses. The rate of the Poisson generators is modulated with a Gaussian profile whose center shifts randomly each 100 ms between ten equally spaced positions. This setup demonstrates that the Clopath synapse is able to establish bidirectional connections. The example is adapted from [1]_ (cf. fig. 5). References ~~~~~~~~~~ .. [1] Clopath C, Büsing L, Vasilaki E, Gerstner W (2010). Connectivity reflects coding: a model of voltage-based STDP with homeostasis. Nature Neuroscience 13:3, 344--352 .. GENERATED FROM PYTHON SOURCE LINES 43-50 .. code-block:: Python import random import matplotlib.pyplot as plt import nest import numpy as np .. GENERATED FROM PYTHON SOURCE LINES 51-52 Set the parameters .. GENERATED FROM PYTHON SOURCE LINES 52-88 .. code-block:: Python simulation_time = 1.0e4 resolution = 0.1 delay = resolution # Poisson_generator parameters pg_A = 30.0 # amplitude of Gaussian pg_sigma = 10.0 # std deviation nest.ResetKernel() nest.resolution = resolution # Create neurons and devices nrn_model = "aeif_psc_delta_clopath" nrn_params = { "V_m": -30.6, "g_L": 30.0, "w": 0.0, "tau_u_bar_plus": 7.0, "tau_u_bar_minus": 10.0, "tau_w": 144.0, "a": 4.0, "C_m": 281.0, "Delta_T": 2.0, "V_peak": 20.0, "t_clamp": 2.0, "A_LTP": 8.0e-6, "A_LTD": 14.0e-6, "A_LTD_const": False, "b": 0.0805, "u_ref_squared": 60.0**2, } pop_exc = nest.Create(nrn_model, 10, nrn_params) pop_inh = nest.Create(nrn_model, 3, nrn_params) .. GENERATED FROM PYTHON SOURCE LINES 89-91 We need parrot neurons since Poisson generators can only be connected with static connections .. GENERATED FROM PYTHON SOURCE LINES 91-96 .. code-block:: Python pop_input = nest.Create("parrot_neuron", 500) # helper neurons pg = nest.Create("poisson_generator", 500) wr = nest.Create("weight_recorder") .. GENERATED FROM PYTHON SOURCE LINES 97-98 First connect Poisson generators to helper neurons .. GENERATED FROM PYTHON SOURCE LINES 98-100 .. code-block:: Python nest.Connect(pg, pop_input, "one_to_one", {"synapse_model": "static_synapse", "weight": 1.0, "delay": delay}) .. GENERATED FROM PYTHON SOURCE LINES 101-102 Create all the connections .. GENERATED FROM PYTHON SOURCE LINES 102-133 .. code-block:: Python nest.CopyModel("clopath_synapse", "clopath_input_to_exc", {"Wmax": 3.0}) conn_dict_input_to_exc = {"rule": "all_to_all"} syn_dict_input_to_exc = { "synapse_model": "clopath_input_to_exc", "weight": nest.random.uniform(0.5, 2.0), "delay": delay, } nest.Connect(pop_input, pop_exc, conn_dict_input_to_exc, syn_dict_input_to_exc) # Create input->inh connections conn_dict_input_to_inh = {"rule": "all_to_all"} syn_dict_input_to_inh = {"synapse_model": "static_synapse", "weight": nest.random.uniform(0.0, 0.5), "delay": delay} nest.Connect(pop_input, pop_inh, conn_dict_input_to_inh, syn_dict_input_to_inh) # Create exc->exc connections nest.CopyModel("clopath_synapse", "clopath_exc_to_exc", {"Wmax": 0.75, "weight_recorder": wr}) syn_dict_exc_to_exc = {"synapse_model": "clopath_exc_to_exc", "weight": 0.25, "delay": delay} conn_dict_exc_to_exc = {"rule": "all_to_all", "allow_autapses": False} nest.Connect(pop_exc, pop_exc, conn_dict_exc_to_exc, syn_dict_exc_to_exc) # Create exc->inh connections syn_dict_exc_to_inh = {"synapse_model": "static_synapse", "weight": 1.0, "delay": delay} conn_dict_exc_to_inh = {"rule": "fixed_indegree", "indegree": 8} nest.Connect(pop_exc, pop_inh, conn_dict_exc_to_inh, syn_dict_exc_to_inh) # Create inh->exc connections syn_dict_inh_to_exc = {"synapse_model": "static_synapse", "weight": 1.0, "delay": delay} conn_dict_inh_to_exc = {"rule": "fixed_outdegree", "outdegree": 6} nest.Connect(pop_inh, pop_exc, conn_dict_inh_to_exc, syn_dict_inh_to_exc) .. GENERATED FROM PYTHON SOURCE LINES 134-135 Randomize the initial membrane potential .. GENERATED FROM PYTHON SOURCE LINES 135-139 .. code-block:: Python pop_exc.V_m = nest.random.normal(-60.0, 25.0) pop_inh.V_m = nest.random.normal(-60.0, 25.0) .. GENERATED FROM PYTHON SOURCE LINES 140-141 Simulation divided into intervals of 100ms for shifting the Gaussian .. GENERATED FROM PYTHON SOURCE LINES 141-153 .. code-block:: Python sim_interval = 100.0 for i in range(int(simulation_time / sim_interval)): # set rates of poisson generators rates = np.empty(500) # pg_mu will be randomly chosen out of 25,75,125,...,425,475 pg_mu = 25 + random.randint(0, 9) * 50 for j in range(500): rates[j] = pg_A * np.exp((-1 * (j - pg_mu) ** 2) / (2 * pg_sigma**2)) pg[j].rate = rates[j] * 1.75 nest.Simulate(sim_interval) .. GENERATED FROM PYTHON SOURCE LINES 154-155 Plot results .. GENERATED FROM PYTHON SOURCE LINES 155-195 .. code-block:: Python fig, ax = plt.subplots(1, sharex=False) # Plot synapse weights of the synapses within the excitatory population # Sort weights according to sender and reshape exc_conns = nest.GetConnections(pop_exc, pop_exc) exc_conns_senders = np.array(exc_conns.source) exc_conns_targets = np.array(exc_conns.target) exc_conns_weights = np.array(exc_conns.weight) idx_array = np.argsort(exc_conns_senders) targets = np.reshape(exc_conns_targets[idx_array], (10, 10 - 1)) weights = np.reshape(exc_conns_weights[idx_array], (10, 10 - 1)) # Sort according to target for i, (trgs, ws) in enumerate(zip(targets, weights)): idx_array = np.argsort(trgs) weights[i] = ws[idx_array] weight_matrix = np.zeros((10, 10)) tu9 = np.triu_indices_from(weights) tl9 = np.tril_indices_from(weights, -1) tu10 = np.triu_indices_from(weight_matrix, 1) tl10 = np.tril_indices_from(weight_matrix, -1) weight_matrix[tu10[0], tu10[1]] = weights[tu9[0], tu9[1]] weight_matrix[tl10[0], tl10[1]] = weights[tl9[0], tl9[1]] # Difference between initial and final value init_w_matrix = np.ones((10, 10)) * 0.25 init_w_matrix -= np.identity(10) * 0.25 cax = ax.imshow(weight_matrix - init_w_matrix) cbarB = fig.colorbar(cax, ax=ax) ax.set_xticks([0, 2, 4, 6, 8]) ax.set_xticklabels(["1", "3", "5", "7", "9"]) ax.set_yticks([0, 2, 4, 6, 8]) ax.set_xticklabels(["1", "3", "5", "7", "9"]) ax.set_xlabel("to neuron") ax.set_ylabel("from neuron") ax.set_title("Change of syn weights before and after simulation") plt.show() .. _sphx_glr_download_auto_examples_clopath_synapse_small_network.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: clopath_synapse_small_network.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: clopath_synapse_small_network.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_