.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/glif_psc_double_alpha_neuron.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_glif_psc_double_alpha_neuron.py: Current-based generalized leaky integrate and fire (GLIF) neuron with double alpha synaptic function ------------------------------------------------------------------------------------------------------------- .. 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%2Fglif_psc_double_alpha_neuron.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. ---- Simple example of how to use the ``glif_psc_double_alpha`` neuron model that illustrates differences from the ``glif_psc`` neuron model. The behavior of the ``glif_psc_double_alpha`` neuron model is the same as the ``glif_psc`` neuron model, except that the synaptic currents are modeled as a double alpha function. Therefore, in this example, we only compare the difference in the synaptic currents between the two models. Compared to the single alpha function, the double alpha function has much more control over the shape of the tail of the synaptic current. Simple synaptic inputs are applied to the neuron and the resulting voltage and current traces are shown for the two models. .. GENERATED FROM PYTHON SOURCE LINES 41-43 First, we import all necessary modules to simulate, analyze and plot this example. .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python import matplotlib.gridspec as gridspec import matplotlib.pyplot as plt import nest .. GENERATED FROM PYTHON SOURCE LINES 49-50 We initialize NEST and set the simulation resolution. .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: Python nest.ResetKernel() resolution = 0.05 nest.resolution = resolution .. GENERATED FROM PYTHON SOURCE LINES 56-64 We also pre-define the synapse time constant arrays. In contrast to ``glif_psc`` models, ``glif_psc_double_alpha`` models have two components of synaptic currents, one for the fast component and the other for the slow component. The relative amplitude also needs to be set, so there are three parameters to define per receptor port. For this example, we keep the ``tau_syn_fast`` to 2 ms for simplicity, and vary the ``tau_syn_slow`` and ``amp_slow`` to illustrate how the parameters affect the shape of the synaptic currents. .. GENERATED FROM PYTHON SOURCE LINES 64-77 .. code-block:: Python tau_syn_glif_psc = [2.0, 2.0, 2.0] # value for the ``glif_psc`` model tau_syn_fast = [2.0, 2.0, 2.0] # common between 'timing' and 'amp' manipulations # for the slow component timing manipuation tau_syn_slow_timing = [4.0, 6.0, 8.0] amp_slow_timing = [0.5, 0.5, 0.5] # for the slow component amplitude manipulation tau_syn_slow_amp = [6.0, 6.0, 6.0] amp_slow_amp = [0.2, 0.5, 0.8] .. GENERATED FROM PYTHON SOURCE LINES 78-84 Now we create three neurons: ``glif_psc``, ``glif_psc_double_alpha_timing``, and ``glif_psc_double_alpha_amp``. The parameters for the ``glif_psc`` neuron are set as default. The parameters for the ``glif_psc_double_alpha_timing`` neuron are set to have the same ``tau_syn_fast`` as the ``glif_psc`` neuron, and the ``tau_syn_slow`` and ``amp_slow`` are set to the values defined above for the timing manipulation. .. GENERATED FROM PYTHON SOURCE LINES 84-121 .. code-block:: Python n_glif_psc = nest.Create( "glif_psc", params={ "spike_dependent_threshold": False, "after_spike_currents": False, "adapting_threshold": False, "tau_syn": tau_syn_glif_psc, }, ) n_glif_psc_double_alpha_timing = nest.Create( "glif_psc_double_alpha", params={ "spike_dependent_threshold": False, "after_spike_currents": False, "adapting_threshold": False, "tau_syn_fast": tau_syn_fast, "tau_syn_slow": tau_syn_slow_timing, "amp_slow": amp_slow_timing, }, ) n_glif_psc_double_alpha_amp = nest.Create( "glif_psc_double_alpha", params={ "spike_dependent_threshold": False, "after_spike_currents": False, "adapting_threshold": False, "tau_syn_fast": tau_syn_fast, "tau_syn_slow": tau_syn_slow_amp, "amp_slow": amp_slow_amp, }, ) neurons = n_glif_psc + n_glif_psc_double_alpha_timing + n_glif_psc_double_alpha_amp .. GENERATED FROM PYTHON SOURCE LINES 122-124 For the stimulation input to the ``glif_psc`` neurons, we create three excitation spike generators, each one with a single spike. .. GENERATED FROM PYTHON SOURCE LINES 124-129 .. code-block:: Python espike1 = nest.Create("spike_generator", params={"spike_times": [10.0], "spike_weights": [20.0]}) espike2 = nest.Create("spike_generator", params={"spike_times": [110.0], "spike_weights": [20.0]}) espike3 = nest.Create("spike_generator", params={"spike_times": [210.0], "spike_weights": [20.0]}) .. GENERATED FROM PYTHON SOURCE LINES 130-134 The generators are then connected to the neurons. Specification of the ``receptor_type`` uniquely defines the target receptor. We connect each of the spikes generator to a different receptor that have different parameters. .. GENERATED FROM PYTHON SOURCE LINES 134-139 .. code-block:: Python nest.Connect(espike1, neurons, syn_spec={"delay": resolution, "receptor_type": 1}) nest.Connect(espike2, neurons, syn_spec={"delay": resolution, "receptor_type": 2}) nest.Connect(espike3, neurons, syn_spec={"delay": resolution, "receptor_type": 3}) .. GENERATED FROM PYTHON SOURCE LINES 140-143 A ``multimeter`` is created and connected to the neurons. The parameters specified for the multimeter include the list of quantities that should be recorded and the time interval at which quantities are measured. .. GENERATED FROM PYTHON SOURCE LINES 143-153 .. code-block:: Python mm = nest.Create( "multimeter", params={ "interval": resolution, "record_from": ["V_m", "I_syn"], }, ) nest.Connect(mm, neurons) .. GENERATED FROM PYTHON SOURCE LINES 154-156 Run the simulation for 300 ms and retrieve recorded data from the multimeter and spike recorder. .. GENERATED FROM PYTHON SOURCE LINES 156-160 .. code-block:: Python nest.Simulate(300.0) data = mm.events .. GENERATED FROM PYTHON SOURCE LINES 161-165 We plot the time traces of the synaptic current and the membrane potential. Each input current is annotated with the corresponding parameter value of the receptor. The blue line is the synaptic current of the ``glif_psc`` neuron, and the red line is the synaptic current of the ``glif_psc_double_alpha`` neuron. .. GENERATED FROM PYTHON SOURCE LINES 165-213 .. code-block:: Python # defining the figure property for each parameter variation type, variation_types = ["timing", "amp"] annotate_variable = ["tau_syn_slow", "amp_slow"] annotate_values = [tau_syn_slow_timing, amp_slow_amp] fig_titles = [ "Variation of tau_syn_slow: tau_syn_fast = 2.0, amp_slow = 0.5", "Variation of amp_slow: tau_syn_fast = 2.0, tau_syn_slow = 6.0", ] senders = data["senders"] t = data["times"][senders == 1] for i, variation_type in enumerate(variation_types): plt.figure(variation_type, figsize=(10, 5)) gs = gridspec.GridSpec(2, 1, height_ratios=[1, 1]) data_types = ["I_syn", "V_m"] data_types_names = ["Synaptic current (pA)", "Membrane potential (mV)"] for j, data_type in enumerate(data_types): d = data[data_type] ax = plt.subplot(gs[j]) ax.plot(t, d[senders == 1], "b", label="glif_psc (tau_syn=2.0)") ax.plot(t, d[senders == 2 + i], "r", label="glif_psc_double_alpha") if j == 0: # place legend outside the plot ax.legend(bbox_to_anchor=(1.05, 1), loc="upper left", borderaxespad=0) else: ax.set_xlabel("time (ms)") ax.set_ylabel(data_types_names[j]) # now let's annotate each of the input with the corresponding parameter. spike_timings = [10.0, 110.0, 210.0] ax = plt.subplot(gs[0]) for j, spike_timing in enumerate(spike_timings): ax.annotate( f"{annotate_variable[i]}={annotate_values[i][j]}", xy=(spike_timing + 10, 20), xytext=(spike_timing + 10, 25), arrowprops=dict(arrowstyle="->", connectionstyle="arc3"), ) plt.title(fig_titles[i]) plt.tight_layout() plt.show() .. _sphx_glr_download_auto_examples_glif_psc_double_alpha_neuron.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: glif_psc_double_alpha_neuron.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: glif_psc_double_alpha_neuron.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_