Skip to content

Commit

Permalink
Spiros chv patch 1 (#105)
Browse files Browse the repository at this point in the history
* Update _config.yml

* fixes

* fixes

* fixes

* fixes

* fixes

* Process tutorial notebooks

---------

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
spirosChv and actions-user authored Jul 3, 2023
1 parent a6e8891 commit 7cab91d
Show file tree
Hide file tree
Showing 24 changed files with 579 additions and 543 deletions.
1 change: 1 addition & 0 deletions book/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ parse:
- amsmath
- dollarmath
- html_image
- substitution
sphinx:
config:
html_show_copyright: false
Expand Down
36 changes: 20 additions & 16 deletions tutorials/W0D2_PythonWorkshop2/W0D2_Tutorial1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
"source": [
"---\n",
"## Tutorial objectives\n",
"\n",
"We learned basic Python and NumPy concepts in the previous tutorial. These new and efficient coding techniques can be applied repeatedly in tutorials from the NMA course, and elsewhere.\n",
"\n",
"In this tutorial, we'll introduce spikes in our LIF neuron and evaluate the refractory period's effect in spiking dynamics!\n"
"In this tutorial, we'll introduce spikes in our LIF neuron and evaluate the refractory period's effect in spiking dynamics!"
]
},
{
Expand Down Expand Up @@ -296,7 +297,7 @@
"\n",
"<br>\n",
"\n",
"Another important statistic is the sample [histogram](https://en.wikipedia.org/wiki/Histogram). For our LIF neuron it provides an approximate representation of the distribution of membrane potential $V_m(t)$ at time $t=t_k\\in[0,t_{max}]$. For $N$ realizations $V\\left(t_k\\right)$ and $J$ bins is given by:\n",
"Another important statistic is the sample [histogram](https://en.wikipedia.org/wiki/Histogram). For our LIF neuron, it provides an approximate representation of the distribution of membrane potential $V_m(t)$ at time $t=t_k\\in[0,t_{max}]$. For $N$ realizations $V\\left(t_k\\right)$ and $J$ bins is given by:\n",
"\n",
"<br>\n",
"\\begin{equation}\n",
Expand Down Expand Up @@ -609,7 +610,7 @@
"execution": {}
},
"source": [
"A spike takes place whenever $V(t)$ crosses $V_{th}$. In that case, a spike is recorded and $V(t)$ resets to $V_{reset}$ value. This is summarized in the *reset condition*:\n",
"A spike occures whenever $V(t)$ crosses $V_{th}$. In that case, a spike is recorded, and $V(t)$ resets to $V_{reset}$ value. This is summarized in the *reset condition*:\n",
"\n",
"\\begin{equation}\n",
"V(t) = V_{reset}\\quad \\text{ if } V(t)\\geq V_{th}\n",
Expand Down Expand Up @@ -771,7 +772,7 @@
"for step, t in enumerate(t_range):\n",
"\n",
" # Skip first iteration\n",
" if step==0:\n",
" if step == 0:\n",
" continue\n",
"\n",
" # Compute v_n\n",
Expand Down Expand Up @@ -852,7 +853,7 @@
"for step, t in enumerate(t_range):\n",
"\n",
" # Skip first iteration\n",
" if step==0:\n",
" if step == 0:\n",
" continue\n",
"\n",
" # Compute v_n\n",
Expand Down Expand Up @@ -1004,7 +1005,7 @@
"execution": {}
},
"source": [
"Numpy arrays can be indexed by boolean arrays to select a subset of elements (also works with lists of booleans).\n",
"Boolean arrays can index NumPy arrays to select a subset of elements (also works with lists of booleans).\n",
"\n",
"The boolean array itself can be initiated by a condition, as shown in the example below.\n",
"\n",
Expand Down Expand Up @@ -1189,7 +1190,7 @@
},
"outputs": [],
"source": [
"# to_remove solutions\n",
"# to_remove solution\n",
"\n",
"# Set random number generator\n",
"np.random.seed(2020)\n",
Expand Down Expand Up @@ -1549,9 +1550,8 @@
},
"source": [
"## Coding Exercise 5: Investigating refactory periods\n",
"Investigate the effect of (absolute) refractory period $t_{ref}$ on the evolution of output rate $\\lambda(t)$. Add refractory period $t_{ref}=10$ ms after each spike, during which $V(t)$ is clamped to $V_{reset}$.\n",
"\n",
"\n"
"Investigate the effect of (absolute) refractory period $t_{ref}$ on the evolution of output rate $\\lambda(t)$. Add refractory period $t_{ref}=10$ ms after each spike, during which $V(t)$ is clamped to $V_{reset}$."
]
},
{
Expand Down Expand Up @@ -1697,13 +1697,13 @@
},
"source": [
"## Interactive Demo 1: Random refractory period\n",
"\n",
"In the following interactive demo, we will investigate the effect of random refractory periods. We will use random refactory periods $t_{ref}$ with\n",
"$t_{ref} = \\mu + \\sigma\\,\\mathcal{N}$, where $\\mathcal{N}$ is the [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution), $\\mu=0.01$ and $\\sigma=0.007$.\n",
"\n",
"Refractory period samples `t_ref` of size `n` is initialized with `np.random.normal`. We clip negative values to `0` with boolean indexes. (Why?) You can double click the cell to see the hidden code.\n",
"Refractory period samples `t_ref` of size `n` is initialized with `np.random.normal`. We clip negative values to `0` with boolean indexes. (Why?) You can double-click the cell to see the hidden code.\n",
"\n",
"You can play with the parameters mu and sigma and visualize the resulting simulation.\n",
"What is the effect of different $\\sigma$ values?\n"
"You can play with the parameters mu and sigma and visualize the resulting simulation. What is the effect of different $\\sigma$ values?"
]
},
{
Expand Down Expand Up @@ -1934,6 +1934,7 @@
},
"source": [
"## Coding Exercise 6: Rewriting code with functions\n",
"\n",
"We will now re-organize parts of the code from the previous exercise with functions. You need to complete the function `spike_clamp()` to update $V(t)$ and deal with spiking and refractoriness"
]
},
Expand All @@ -1953,7 +1954,7 @@
" v (numpy array of floats)\n",
" membrane potential at previous time step of shape (neurons)\n",
"\n",
" v (numpy array of floats)\n",
" i (numpy array of floats)\n",
" synaptic input at current time step of shape (neurons)\n",
"\n",
" dt (float)\n",
Expand All @@ -1967,6 +1968,7 @@
"\n",
" return v\n",
"\n",
"\n",
"def spike_clamp(v, delta_spike):\n",
" \"\"\"\n",
" Resets membrane potential of neurons if v>= vth\n",
Expand Down Expand Up @@ -2051,6 +2053,8 @@
},
"outputs": [],
"source": [
"# to_remove solution\n",
"\n",
"def ode_step(v, i, dt):\n",
" \"\"\"\n",
" Evolves membrane potential by one step of discrete time integration\n",
Expand All @@ -2059,7 +2063,7 @@
" v (numpy array of floats)\n",
" membrane potential at previous time step of shape (neurons)\n",
"\n",
" v (numpy array of floats)\n",
" i (numpy array of floats)\n",
" synaptic input at current time step of shape (neurons)\n",
"\n",
" dt (float)\n",
Expand All @@ -2073,7 +2077,7 @@
"\n",
" return v\n",
"\n",
"# to_remove solution\n",
"\n",
"def spike_clamp(v, delta_spike):\n",
" \"\"\"\n",
" Resets membrane potential of neurons if v>= vth\n",
Expand Down Expand Up @@ -2244,7 +2248,7 @@
"execution": {}
},
"source": [
"Using classes helps with code reuse and reliability. Well-designed classes are like black boxes in that they receive inputs and provide expected outputs. The details of how the class processes inputs and produces outputs are unimportant.\n",
"Using classes helps with code reuse and reliability. Well-designed classes are like black boxes, receiving inputs and providing expected outputs. The details of how the class processes inputs and produces outputs are unimportant.\n",
"\n",
"See additional details here: [A Beginner's Python Tutorial/Classes](https://en.wikibooks.org/wiki/A_Beginner%27s_Python_Tutorial/Classes)\n",
"\n",
Expand Down
46 changes: 26 additions & 20 deletions tutorials/W0D2_PythonWorkshop2/instructor/W0D2_Tutorial1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
"source": [
"---\n",
"## Tutorial objectives\n",
"\n",
"We learned basic Python and NumPy concepts in the previous tutorial. These new and efficient coding techniques can be applied repeatedly in tutorials from the NMA course, and elsewhere.\n",
"\n",
"In this tutorial, we'll introduce spikes in our LIF neuron and evaluate the refractory period's effect in spiking dynamics!\n"
"In this tutorial, we'll introduce spikes in our LIF neuron and evaluate the refractory period's effect in spiking dynamics!"
]
},
{
Expand Down Expand Up @@ -296,7 +297,7 @@
"\n",
"<br>\n",
"\n",
"Another important statistic is the sample [histogram](https://en.wikipedia.org/wiki/Histogram). For our LIF neuron it provides an approximate representation of the distribution of membrane potential $V_m(t)$ at time $t=t_k\\in[0,t_{max}]$. For $N$ realizations $V\\left(t_k\\right)$ and $J$ bins is given by:\n",
"Another important statistic is the sample [histogram](https://en.wikipedia.org/wiki/Histogram). For our LIF neuron, it provides an approximate representation of the distribution of membrane potential $V_m(t)$ at time $t=t_k\\in[0,t_{max}]$. For $N$ realizations $V\\left(t_k\\right)$ and $J$ bins is given by:\n",
"\n",
"<br>\n",
"\\begin{equation}\n",
Expand Down Expand Up @@ -611,7 +612,7 @@
"execution": {}
},
"source": [
"A spike takes place whenever $V(t)$ crosses $V_{th}$. In that case, a spike is recorded and $V(t)$ resets to $V_{reset}$ value. This is summarized in the *reset condition*:\n",
"A spike occures whenever $V(t)$ crosses $V_{th}$. In that case, a spike is recorded, and $V(t)$ resets to $V_{reset}$ value. This is summarized in the *reset condition*:\n",
"\n",
"\\begin{equation}\n",
"V(t) = V_{reset}\\quad \\text{ if } V(t)\\geq V_{th}\n",
Expand Down Expand Up @@ -773,7 +774,7 @@
"for step, t in enumerate(t_range):\n",
"\n",
" # Skip first iteration\n",
" if step==0:\n",
" if step == 0:\n",
" continue\n",
"\n",
" # Compute v_n\n",
Expand Down Expand Up @@ -856,7 +857,7 @@
"for step, t in enumerate(t_range):\n",
"\n",
" # Skip first iteration\n",
" if step==0:\n",
" if step == 0:\n",
" continue\n",
"\n",
" # Compute v_n\n",
Expand Down Expand Up @@ -1008,7 +1009,7 @@
"execution": {}
},
"source": [
"Numpy arrays can be indexed by boolean arrays to select a subset of elements (also works with lists of booleans).\n",
"Boolean arrays can index NumPy arrays to select a subset of elements (also works with lists of booleans).\n",
"\n",
"The boolean array itself can be initiated by a condition, as shown in the example below.\n",
"\n",
Expand Down Expand Up @@ -1195,7 +1196,7 @@
},
"outputs": [],
"source": [
"# to_remove solutions\n",
"# to_remove solution\n",
"\n",
"# Set random number generator\n",
"np.random.seed(2020)\n",
Expand Down Expand Up @@ -1557,9 +1558,8 @@
},
"source": [
"## Coding Exercise 5: Investigating refactory periods\n",
"Investigate the effect of (absolute) refractory period $t_{ref}$ on the evolution of output rate $\\lambda(t)$. Add refractory period $t_{ref}=10$ ms after each spike, during which $V(t)$ is clamped to $V_{reset}$.\n",
"\n",
"\n"
"Investigate the effect of (absolute) refractory period $t_{ref}$ on the evolution of output rate $\\lambda(t)$. Add refractory period $t_{ref}=10$ ms after each spike, during which $V(t)$ is clamped to $V_{reset}$."
]
},
{
Expand Down Expand Up @@ -1707,13 +1707,13 @@
},
"source": [
"## Interactive Demo 1: Random refractory period\n",
"\n",
"In the following interactive demo, we will investigate the effect of random refractory periods. We will use random refactory periods $t_{ref}$ with\n",
"$t_{ref} = \\mu + \\sigma\\,\\mathcal{N}$, where $\\mathcal{N}$ is the [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution), $\\mu=0.01$ and $\\sigma=0.007$.\n",
"\n",
"Refractory period samples `t_ref` of size `n` is initialized with `np.random.normal`. We clip negative values to `0` with boolean indexes. (Why?) You can double click the cell to see the hidden code.\n",
"Refractory period samples `t_ref` of size `n` is initialized with `np.random.normal`. We clip negative values to `0` with boolean indexes. (Why?) You can double-click the cell to see the hidden code.\n",
"\n",
"You can play with the parameters mu and sigma and visualize the resulting simulation.\n",
"What is the effect of different $\\sigma$ values?\n"
"You can play with the parameters mu and sigma and visualize the resulting simulation. What is the effect of different $\\sigma$ values?"
]
},
{
Expand Down Expand Up @@ -1944,17 +1944,18 @@
},
"source": [
"## Coding Exercise 6: Rewriting code with functions\n",
"\n",
"We will now re-organize parts of the code from the previous exercise with functions. You need to complete the function `spike_clamp()` to update $V(t)$ and deal with spiking and refractoriness"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"execution": {}
},
"outputs": [],
"source": [
"```python\n",
"def ode_step(v, i, dt):\n",
" \"\"\"\n",
" Evolves membrane potential by one step of discrete time integration\n",
Expand All @@ -1963,7 +1964,7 @@
" v (numpy array of floats)\n",
" membrane potential at previous time step of shape (neurons)\n",
"\n",
" v (numpy array of floats)\n",
" i (numpy array of floats)\n",
" synaptic input at current time step of shape (neurons)\n",
"\n",
" dt (float)\n",
Expand All @@ -1977,6 +1978,7 @@
"\n",
" return v\n",
"\n",
"\n",
"def spike_clamp(v, delta_spike):\n",
" \"\"\"\n",
" Resets membrane potential of neurons if v>= vth\n",
Expand Down Expand Up @@ -2050,7 +2052,9 @@
" last_spike[spiked] = t\n",
"\n",
"# Plot multiple realizations of Vm, spikes and mean spike rate\n",
"plot_all(t_range, v_n, raster)"
"plot_all(t_range, v_n, raster)\n",
"\n",
"```"
]
},
{
Expand All @@ -2061,6 +2065,8 @@
},
"outputs": [],
"source": [
"# to_remove solution\n",
"\n",
"def ode_step(v, i, dt):\n",
" \"\"\"\n",
" Evolves membrane potential by one step of discrete time integration\n",
Expand All @@ -2069,7 +2075,7 @@
" v (numpy array of floats)\n",
" membrane potential at previous time step of shape (neurons)\n",
"\n",
" v (numpy array of floats)\n",
" i (numpy array of floats)\n",
" synaptic input at current time step of shape (neurons)\n",
"\n",
" dt (float)\n",
Expand All @@ -2083,7 +2089,7 @@
"\n",
" return v\n",
"\n",
"# to_remove solution\n",
"\n",
"def spike_clamp(v, delta_spike):\n",
" \"\"\"\n",
" Resets membrane potential of neurons if v>= vth\n",
Expand Down Expand Up @@ -2254,7 +2260,7 @@
"execution": {}
},
"source": [
"Using classes helps with code reuse and reliability. Well-designed classes are like black boxes in that they receive inputs and provide expected outputs. The details of how the class processes inputs and produces outputs are unimportant.\n",
"Using classes helps with code reuse and reliability. Well-designed classes are like black boxes, receiving inputs and providing expected outputs. The details of how the class processes inputs and produces outputs are unimportant.\n",
"\n",
"See additional details here: [A Beginner's Python Tutorial/Classes](https://en.wikibooks.org/wiki/A_Beginner%27s_Python_Tutorial/Classes)\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
for step, t in enumerate(t_range):

# Skip first iteration
if step==0:
if step == 0:
continue

# Compute v_n
Expand Down
Loading

0 comments on commit 7cab91d

Please sign in to comment.