.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/sensitivity_to_perturbation.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_sensitivity_to_perturbation.py: Sensitivity to perturbation --------------------------- .. 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%2Fsensitivity_to_perturbation.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 network in two successive trials, which are identical except for one extra input spike in the second realization (a small perturbation). The network consists of recurrent, randomly connected excitatory and inhibitory neurons. Its activity is driven by an external Poisson input provided to all neurons independently. In order to ensure that the network is reset appropriately between the trials, we do the following steps: - resetting the network - resetting the random network generator - resetting the internal clock - deleting all entries in the spike recorder - introducing a hyperpolarization phase between the trials (in order to avoid that spikes remaining in the NEST memory after the first simulation are fed into the second simulation) .. GENERATED FROM PYTHON SOURCE LINES 45-46 Importing all necessary modules for simulation, analysis and plotting. .. GENERATED FROM PYTHON SOURCE LINES 46-52 .. code-block:: Python import matplotlib.pyplot as plt import nest import numpy .. GENERATED FROM PYTHON SOURCE LINES 53-55 Here we define all parameters necessary for building and simulating the network. .. GENERATED FROM PYTHON SOURCE LINES 55-66 .. code-block:: Python # We start with the global network parameters. NE = 1000 # number of excitatory neurons NI = 250 # number of inhibitory neurons N = NE + NI # total number of neurons KE = 100 # excitatory in-degree KI = 25 # inhibitory in-degree .. GENERATED FROM PYTHON SOURCE LINES 67-70 Parameters specific for the neurons in the network. The default values of the reset potential ``E_L`` and the spiking threshold ``V_th`` are used to set the limits of the initial potential of the neurons. .. GENERATED FROM PYTHON SOURCE LINES 70-78 .. code-block:: Python neuron_model = "iaf_psc_delta" neuron_params = nest.GetDefaults(neuron_model) Vmin = neuron_params["E_L"] # minimum of initial potential distribution (mV) Vmax = neuron_params["V_th"] # maximum of initial potential distribution (mV) .. GENERATED FROM PYTHON SOURCE LINES 79-87 Synapse parameters. Changing the weights `J` in the network can lead to qualitatively different behaviors. If `J` is small (e.g. ``J = 0.1``), we are likely to observe a non-chaotic network behavior (after perturbation the network returns to its original activity). Increasing `J` (e.g ``J = 5.5``) leads to rather chaotic activity. Given that in this example the transition to chaos is probabilistic, we sometimes observe chaotic behavior for small weights (e.g. ``J = 0.5``) and non-chaotic behavior for strong weights (e.g. ``J = 5.4``). .. GENERATED FROM PYTHON SOURCE LINES 87-120 .. code-block:: Python J = 0.5 # excitatory synaptic weight (mV) g = 6.0 # relative inhibitory weight delay = 0.1 # spike transmission delay (ms) # External input parameters. Jext = 0.2 # PSP amplitude for external Poisson input (mV) rate_ext = 6500.0 # rate of the external Poisson input # Perturbation parameters. t_stim = 400.0 # perturbation time (time of the extra spike) Jstim = Jext # perturbation amplitude (mV) # Simulation parameters. T = 1000.0 # simulation time per trial (ms) fade_out = 2.0 * delay # fade out time (ms) dt = 0.01 # simulation time resolution (ms) seed_NEST = 30 # seed of random number generator in Nest seed_numpy = 30 # seed of random number generator in NumPy senders = [] spiketimes = [] .. GENERATED FROM PYTHON SOURCE LINES 121-217 .. code-block:: Python # we run the two simulations successively. After each simulation the # sender ids and spiketimes are stored in a list (``senders``, ``spiketimes``). for trial in [0, 1]: ############################################################################### # Before we build the network, we reset the simulation kernel to ensure # that previous NEST simulations in the Python shell will not disturb this # simulation and set the simulation resolution (later defined # synaptic delays cannot be smaller than the simulation resolution). nest.ResetKernel() nest.resolution = dt ############################################################################### # Now we start building the network and create excitatory and inhibitory nodes # and connect them. According to the connectivity specification, each neuron # is assigned random KE synapses from the excitatory population and random KI # synapses from the inhibitory population. nodes_ex = nest.Create(neuron_model, NE) nodes_in = nest.Create(neuron_model, NI) allnodes = nodes_ex + nodes_in nest.Connect( nodes_ex, allnodes, conn_spec={"rule": "fixed_indegree", "indegree": KE}, syn_spec={"weight": J, "delay": dt} ) nest.Connect( nodes_in, allnodes, conn_spec={"rule": "fixed_indegree", "indegree": KI}, syn_spec={"weight": -g * J, "delay": dt}, ) ############################################################################### # Afterwards we create a ``poisson_generator`` that provides spikes (the external # input) to the neurons until time ``T`` is reached. # Afterwards a ``dc_generator``, which is also connected to the whole population, # provides a strong hyperpolarization step for a short time period ``fade_out``. # # The ``fade_out`` period has to last at least twice as long as the simulation # resolution to suppress the neurons from firing. ext = nest.Create("poisson_generator", params={"rate": rate_ext, "stop": T}) nest.Connect(ext, allnodes, syn_spec={"weight": Jext, "delay": dt}) suppr = nest.Create("dc_generator", params={"amplitude": -1e16, "start": T, "stop": T + fade_out}) nest.Connect(suppr, allnodes) spikerecorder = nest.Create("spike_recorder") nest.Connect(allnodes, spikerecorder) ############################################################################### # We then create the ``spike_generator``, which provides the extra spike # (perturbation). stimulus = nest.Create("spike_generator") stimulus.spike_times = [] ############################################################################### # We need to reset the random number generator and the clock of # the simulation Kernel. In addition, we ensure that there is no spike left in # the spike recorder. nest.rng_seed = seed_NEST spikerecorder.n_events = 0 # We assign random initial membrane potentials to all neurons numpy.random.seed(seed_numpy) Vms = Vmin + (Vmax - Vmin) * numpy.random.rand(N) allnodes.V_m = Vms ############################################################################## # In the second trial, we add an extra input spike at time ``t_stim`` to the # neuron that fires first after perturbation time ``t_stim``. Thus, we make sure # that the perturbation is transmitted to the network before it fades away in # the perturbed neuron. (Single IAF-neurons are not chaotic.) if trial == 1: id_stim = [senders[0][spiketimes[0] > t_stim][0]] nest.Connect(stimulus, nest.NodeCollection(id_stim), syn_spec={"weight": Jstim, "delay": dt}) stimulus.spike_times = [t_stim] # Now we simulate the network and add a fade out period to discard # remaining spikes. nest.Simulate(T) nest.Simulate(fade_out) # Storing the data. senders += [spikerecorder.get("events", "senders")] spiketimes += [spikerecorder.get("events", "times")] .. GENERATED FROM PYTHON SOURCE LINES 218-220 We plot the spiking activity of the network (first trial in red, second trial in black). .. GENERATED FROM PYTHON SOURCE LINES 220-230 .. code-block:: Python plt.figure(1) plt.clf() plt.plot(spiketimes[0], senders[0], "ro", ms=4.0) plt.plot(spiketimes[1], senders[1], "ko", ms=2.0) plt.xlabel("time (ms)") plt.ylabel("neuron id") plt.xlim((0, T)) plt.ylim((0, N)) plt.show() .. _sphx_glr_download_auto_examples_sensitivity_to_perturbation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sensitivity_to_perturbation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sensitivity_to_perturbation.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_