Skip to content

Commit

Permalink
Copy examples to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jessica-mitchell committed Jan 26, 2024
1 parent 0abc938 commit 4729324
Show file tree
Hide file tree
Showing 186 changed files with 29,510 additions and 0 deletions.
176 changes: 176 additions & 0 deletions test-copies/notebooks/BrodyHopfield.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Spike synchronization through subthreshold oscillation\n\nThis script reproduces the spike synchronization behavior\nof integrate-and-fire neurons in response to a subthreshold\noscillation. This phenomenon is shown in Fig. 1 of [1]_\n\nNeurons receive a weak 35 Hz oscillation, a gaussian noise current\nand an increasing DC. The time-locking capability is shown to\ndepend on the input current given. The result is then plotted using\nmatplotlib. All parameters are taken from the above paper.\n\n## References\n\n.. [1] Brody CD and Hopfield JJ (2003). Simple networks for\n spike-timing-based computation, with application to olfactory\n processing. Neuron 37, 843-852.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, we import all necessary modules for simulation, analysis, and plotting.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nimport nest\nimport nest.raster_plot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Second, the simulation parameters are assigned to variables.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"N = 1000 # number of neurons\nbias_begin = 140.0 # minimal value for the bias current injection [pA]\nbias_end = 200.0 # maximal value for the bias current injection [pA]\nT = 600 # simulation time (ms)\n\n# parameters for the alternating-current generator\ndriveparams = {\"amplitude\": 50.0, \"frequency\": 35.0}\n# parameters for the noise generator\nnoiseparams = {\"mean\": 0.0, \"std\": 200.0}\nneuronparams = {\n \"tau_m\": 20.0, # membrane time constant\n \"V_th\": 20.0, # threshold potential\n \"E_L\": 10.0, # membrane resting potential\n \"t_ref\": 2.0, # refractory period\n \"V_reset\": 0.0, # reset potential\n \"C_m\": 200.0, # membrane capacitance\n \"V_m\": 0.0,\n} # initial membrane potential"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Third, the nodes are created using ``Create``. We store the returned handles\nin variables for later reference.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"neurons = nest.Create(\"iaf_psc_alpha\", N)\nsr = nest.Create(\"spike_recorder\")\nnoise = nest.Create(\"noise_generator\")\ndrive = nest.Create(\"ac_generator\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set the parameters specified above for the generators using ``set``.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"drive.set(driveparams)\nnoise.set(noiseparams)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set the parameters specified above for the neurons. Neurons get an internal\ncurrent. The first neuron additionally receives the current with amplitude\n``bias_begin``, the last neuron with amplitude ``bias_end``.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"neurons.set(neuronparams)\nneurons.I_e = [(n * (bias_end - bias_begin) / N + bias_begin) for n in range(1, len(neurons) + 1)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Connect alternating current and noise generators as well as\nspike_recorders to neurons\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"nest.Connect(drive, neurons)\nnest.Connect(noise, neurons)\nnest.Connect(neurons, sr)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Simulate the network for time ``T``.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"nest.Simulate(T)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the raster plot of the neuronal spiking activity.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"nest.raster_plot.from_device(sr, hist=True)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "EBRAINS-23.09",
"language": "python",
"name": "ebrains-23.09"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
114 changes: 114 additions & 0 deletions test-copies/notebooks/BrodyHopfield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# -*- coding: utf-8 -*-
#
# BrodyHopfield.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.


"""
Spike synchronization through subthreshold oscillation
------------------------------------------------------
This script reproduces the spike synchronization behavior
of integrate-and-fire neurons in response to a subthreshold
oscillation. This phenomenon is shown in Fig. 1 of [1]_
Neurons receive a weak 35 Hz oscillation, a gaussian noise current
and an increasing DC. The time-locking capability is shown to
depend on the input current given. The result is then plotted using
matplotlib. All parameters are taken from the above paper.
References
~~~~~~~~~~
.. [1] Brody CD and Hopfield JJ (2003). Simple networks for
spike-timing-based computation, with application to olfactory
processing. Neuron 37, 843-852.
"""

#################################################################################
# First, we import all necessary modules for simulation, analysis, and plotting.

import matplotlib.pyplot as plt
import nest
import nest.raster_plot

###############################################################################
# Second, the simulation parameters are assigned to variables.

N = 1000 # number of neurons
bias_begin = 140.0 # minimal value for the bias current injection [pA]
bias_end = 200.0 # maximal value for the bias current injection [pA]
T = 600 # simulation time (ms)

# parameters for the alternating-current generator
driveparams = {"amplitude": 50.0, "frequency": 35.0}
# parameters for the noise generator
noiseparams = {"mean": 0.0, "std": 200.0}
neuronparams = {
"tau_m": 20.0, # membrane time constant
"V_th": 20.0, # threshold potential
"E_L": 10.0, # membrane resting potential
"t_ref": 2.0, # refractory period
"V_reset": 0.0, # reset potential
"C_m": 200.0, # membrane capacitance
"V_m": 0.0,
} # initial membrane potential

###############################################################################
# Third, the nodes are created using ``Create``. We store the returned handles
# in variables for later reference.

neurons = nest.Create("iaf_psc_alpha", N)
sr = nest.Create("spike_recorder")
noise = nest.Create("noise_generator")
drive = nest.Create("ac_generator")

###############################################################################
# Set the parameters specified above for the generators using ``set``.

drive.set(driveparams)
noise.set(noiseparams)

###############################################################################
# Set the parameters specified above for the neurons. Neurons get an internal
# current. The first neuron additionally receives the current with amplitude
# ``bias_begin``, the last neuron with amplitude ``bias_end``.

neurons.set(neuronparams)
neurons.I_e = [(n * (bias_end - bias_begin) / N + bias_begin) for n in range(1, len(neurons) + 1)]

###############################################################################
# Connect alternating current and noise generators as well as
# spike_recorders to neurons

nest.Connect(drive, neurons)
nest.Connect(noise, neurons)
nest.Connect(neurons, sr)

###############################################################################
# Simulate the network for time ``T``.

nest.Simulate(T)

###############################################################################
# Plot the raster plot of the neuronal spiking activity.

nest.raster_plot.from_device(sr, hist=True)
plt.show()
Loading

0 comments on commit 4729324

Please sign in to comment.