{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Solution Exponential Integrate and Fire Neuron" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### first name: ...\n", "\n", "last name: ...\n", "\n", "sciper: ...\n", "\n", "date: ...\n", "\n", "*Your teammate*\n", "\n", "first name of your teammate: ...\n", "\n", "last name of your teammate: ...\n", "\n", "sciper of your teammate: ...\n", "\n", "\n", "** Remember **\n", "\n", "If you are asked for plots: The appearance of the plots (labelled axes, ** useful scaling **, etc.) is important!\n", "\n", "If you are asked for discussions: Answer in a precise way and try to be concise. \n", "\n", "\n", "** Submission **\n", "\n", "Rename this notebook to Ex1_FirstName_LastName_Sciper.ipynb and upload that single file on moodle before the deadline.\n", "\n", "Exercise instructions are given in this notebook file.\n", "\n", "** Rules: **\n", "\n", "1) You are strongly encouraged to work in groups of 2. You are allowed to work alone. Groups of 3 or more are NOT allowed\n", "\n", "2) If you work in a group of 2, BOTH people should upload the same notebook file \n", "\n", "3) If you work alone, you can't share your notebook file with anyone else\n", "\n", "4) Discussion between groups is encouraged, but you can't share your code or text\n", "\n", "5) The points assigned to each exercise are indicated in the notebook file\n", "\n", "6) You should upload a jupyter notebook file with all code run and picture visible. We are not going to run your notebook.\n", "\n", "7) Read carefully the instructions at the beginning of the notebook file, answer in a clear and concise way to open questions\n", "\n", "8) You have to understand every line of code you write in this notebook. We will ask you questions about your submission during a fraud detection session during the last week of the semester" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Ex. 3 The Exponential Integrate-and-Fire model\n", "\n", "The module [exponential_integrate_fire.exp_IF](https://neuronaldynamics-exercises.readthedocs.io/en/latest/modules/neurodynex.exponential_integrate_fire.html#module-neurodynex.exponential_integrate_fire.exp_IF) implements the dynamics given in the book [(equation 5.6)](https://neuronaldynamics.epfl.ch/online/Ch5.S2.html).\n", "\n", "To get started, use the following code. It follows a common pattern used in these exercises: use the input_factory to get a specific current, inject it into the neuron model we provide, and finally use the plot_tools to visualize the state variables:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "% matplotlib inline\n", "import brian2 as b2\n", "import matplotlib.pyplot as plt\n", "import neurodynex.exponential_integrate_fire.exp_IF as exp_IF\n", "from neurodynex.tools import plot_tools, input_factory\n", "\n", "\n", "input_current = input_factory.get_step_current(\n", " t_start=10, t_end=110, unit_time=b2.ms, amplitude=0.8 * b2.namp)\n", "\n", "state_monitor, spike_monitor = exp_IF.simulate_exponential_IF_neuron(\n", " I_stim=input_current, simulation_time=200*b2.ms)\n", "\n", "plot_tools.plot_voltage_and_current_traces(\n", " state_monitor, input_current,title=\"step current\", \n", " firing_threshold=exp_IF.FIRING_THRESHOLD_v_spike)\n", "print(\"nr of spikes: {}\".format(spike_monitor.count[0]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that you can change all parameters of the neuron by using the named parameters of the function [`simulate_exponential_IF_neuron()`](https://neuronaldynamics-exercises.readthedocs.io/en/latest/modules/neurodynex.exponential_integrate_fire.html#neurodynex.exponential_integrate_fire.exp_IF.simulate_exponential_IF_neuron). If you do not specify any parameter, the default values are used. You can access these variables in your code by prefixing them with the module name (for example `exp_IF.FIRING_THRESHOLD_v_spike`)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3.1 Rehobase Threshold [5 points]\n", "The goal of this exercise is to study the minimal current that can elicit a spike and to understand the different notions of a firing threshold. The Exponential-Integrate-and-Fire neuron model has two threshold related parameters. They correspond to the named parameters `v_spike` and `v_rheobase` in the function [`simulate_exponential_IF_neuron()`](https://neuronaldynamics-exercises.readthedocs.io/en/latest/modules/neurodynex.exponential_integrate_fire.html#neurodynex.exponential_integrate_fire.exp_IF.simulate_exponential_IF_neuron).\n", "\n", "\n", "Modify the code example given above: \n", "- Call `simulate_exponential_IF_neuron()` and set the function parameter `v_spike=+15mV` (which overrides the default value -30mV). What do you expect to happen? How many spikes will be generated? [max 2 lines, 1 point]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "your answer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Call `simulate_exponential_IF_neuron()` and set the function parameter `v_rheobase=-57mV` (which overrides the default value -55mV). What do you expect to happen? [max 2 lines, 1 point]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "your answer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using `v_rheobase=-57mV` for the rest of exercise 3,\n", "- Compute the minimal amplitude `I_rh` of a constant input current such that the neuron will elicit a spike. Insert your answer in the code below. If you are not sure what and how to compute `I_rh`, have a look at Figure 5.1 and the textbox “Rheobase threshold and interpretation of parameters” in the [book](https://neuronaldynamics.epfl.ch/online/Ch5.S2.html).[2 points]\n", "- Validate your result: Modify the code given above and inject a current of amplitude `I_rh` and 300 ms duration into the expIF neuron.[1 points]\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import brian2 as b2\n", "import neurodynex.exponential_integrate_fire.exp_IF as exp_IF\n", "\n", "I_rh = 0. # insert your expression here. For the variables we did not specified, do not just enter the default values but compute it using variables like exp_IF.V_REST " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "% matplotlib inline\n", "import brian2 as b2\n", "import neurodynex.exponential_integrate_fire.exp_IF as exp_IF\n", "from neurodynex.tools import plot_tools, input_factory\n", "\n", "# code here: \n", "# inject a current for 200ms. Set the maximal amplitude such that the neuron does NOT spike.\n", "# plot the current and the voltage." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3.2 Strength - Duration Curve [3+2 points]\n", "\n", "The minimal amplitude to elicit a spike depends on the duration of the current. For an infinitely long current, we’ve just calculated the rheobase current. For short pulses and step currents, we can “experimentally” determine the minimal currents. If we plot the amplitude versus duration, we get the strength-duration curve.\n", "\n", "Have a look at the following code: for the values `i = 0, 2` and `6` we did not provide the minimal amplitude, but the entries in `min_amp[i]` are set to 0. Complete the min_amp list.\n", "\n", "- Set the function parameter `v_rheobase=-57mV` \n", "- Set the index `i` to 0\n", "- Enter an informed guess into the min_amp table\n", "- Run the script\n", "- Depending on the plot, increase or decrease the amplitude, repeat until you just get one spike.\n", "- Do the same for `i = 2` and `i = 6`\n", "\n", "\n", "At the end of the script, the strength-duration curve is plotted. Discuss it. You may want to add a log-log plot to better see the asymptotic behaviour." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "% matplotlib inline\n", "import brian2 as b2\n", "import matplotlib.pyplot as plt\n", "import neurodynex.exponential_integrate_fire.exp_IF as exp_IF\n", "from neurodynex.tools import plot_tools, input_factory\n", "\n", "i=1 #change i and find the value that goes into min_amp\n", "durations = [1, 2, 5, 10, 20, 50, 100]\n", "min_amp = [0, 3.63, 0, 0.88, 0.55, 0.37,0]\n", "\n", "t=durations[i]\n", "I_amp = min_amp[i]*b2.namp\n", "title_txt = \"I_amp={}, t={}\".format(I_amp, t*b2.ms)\n", "\n", "input_current = input_factory.get_step_current(t_start=10, t_end=10+t-1, unit_time=b2.ms, amplitude=I_amp)\n", "\n", "state_monitor, spike_monitor = exp_IF.simulate_exponential_IF_neuron(I_stim=input_current, simulation_time=(t+25)*b2.ms)\n", "\n", "plot_tools.plot_voltage_and_current_traces(state_monitor, input_current,\n", " title=title_txt, firing_threshold=exp_IF.FIRING_THRESHOLD_v_spike,\n", " legend_location=2)\n", "print(\"nr of spikes: {}\".format(spike_monitor.count[0]))\n", "\n", "plt.figure()\n", "plt.plot(durations, min_amp)\n", "plt.title(\"Strength-Duration curve\")\n", "plt.xlabel(\"t [ms]\")\n", "plt.ylabel(\"min amplitude [nAmp]\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Describe your observations here [max 3 lines]\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Ex. 4. AdEx: the Adaptive Exponential Integrate-and-Fire model\n", "\n", "Use function [`AdEx.simulate_AdEx_neuron()`](https://neuronaldynamics-exercises.readthedocs.io/en/latest/modules/neurodynex.adex_model.html#neurodynex.adex_model.AdEx.simulate_AdEx_neuron) to run the model for different input currents and different parameters. Get started by running the following script:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "% matplotlib inline\n", "import brian2 as b2\n", "from neurodynex.adex_model import AdEx\n", "from neurodynex.tools import plot_tools, input_factory\n", "\n", "current = input_factory.get_step_current(10, 250, 1. * b2.ms, 65.0 * b2.pA)\n", "state_monitor, spike_monitor = AdEx.simulate_AdEx_neuron(I_stim=current, simulation_time=250 * b2.ms)\n", "plot_tools.plot_voltage_and_current_traces(state_monitor, current)\n", "print(\"nr of spikes: {}\".format(spike_monitor.count[0]))\n", "# AdEx.plot_adex_state(state_monitor)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4.1. Exercise: Adaptation and firing patterns [7 points]\n", "\n", "We have implemented an Exponential Integrate-and-Fire model with a single adaptation current\n", "$\\begin{split}\\left[\\begin{array}{ccll}\n", "{\\displaystyle \\tau_m \\frac{du}{dt}} &=& -(u-u_{rest}) + \\Delta_T exp(\\frac{u-\\vartheta_{rh}}{\\Delta_T}) - R w + R I(t) \\\\[.2cm]\n", "{\\displaystyle \\tau_w \\frac{dw}{dt}} &=& a (u-u_{rest}) -w + b \\tau_w \\sum_{t^{(f)}} \\delta (t - t^{(f)})\n", " \\\\[.2cm]\n", "\\end{array}\\right.\\end{split}$\n", "\n", "- When you simulate the model with the default parameters, it produces the voltage trace shown above. Describe that firing pattern. Use the terminology of Fig. 6.1 in [Chapter 6.1](https://neuronaldynamics.epfl.ch/online/Ch6.S1.html) [max 2 lines, 1 point]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "your answer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Call the function `AdEx.simulate_AdEx_neuron()` with different parameters and try to create adapting, bursting and irregular firing patterns. [3 points]\n", "\n", "**Note:** If you want to set a parameter to 0, Brian still expects a unit. Therefore use `a=0*b2.nS` instead of `a=0`.\n", "\n", "If you do not specify any parameter, the following default values are used:\n", "\n", "`MEMBRANE_TIME_SCALE_tau_m = 5 * b2.ms`\n", "\n", "`MEMBRANE_RESISTANCE_R = 500*b2.Mohm`\n", "\n", "`V_REST = -70.0 * b2.mV`\n", "\n", "`V_RESET = -51.0 * b2.mV`\n", "\n", "`RHEOBASE_THRESHOLD_v_rh = -50.0 * b2.mV`\n", "\n", "`SHARPNESS_delta_T = 2.0 * b2.mV`\n", "\n", "`ADAPTATION_VOLTAGE_COUPLING_a = 0.5 * b2.nS`\n", "\n", "`ADAPTATION_TIME_CONSTANT_tau_w = 100.0 * b2.ms`\n", "\n", "`SPIKE_TRIGGERED_ADAPTATION_INCREMENT_b = 7.0 * b2.pA`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# adapting firing pattern" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# bursting firing pattern" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# irregular firing pattern" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- In order to better understand the dynamics, it is useful to observe the joint evolution of `u` and `w` in a phase diagram. Use the function `AdEx.plot_adex_state()` to get more insights. Fig. 6.3 in Chapter 6 Section 2 shows the three trajectories in the phase diagram corresponding to the parameters choices you made in the previous exercise (for adapting, bursting and irregular firing patterns).\n", "- Comment on the difference between the three regimes, on the base of the face place [max 5 lines, 1+2 points]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# adapting firing pattern" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# bursting firing pattern" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# irregular firing pattern" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "your answer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4.2. Exercise: phase plane and nullclines [8 points]\n", "\n", "First, try to get some intuition on shape of nullclines by plotting or simply sketching them on a piece of paper and answering the following questions.\n", "Plot or sketch the u- and w- nullclines of the AdEx model (`I(t) = 0`)\n", "- How do the nullclines change with respect to `a`?\n", "- How do the nullclines change if a constant current `I(t) = c` is applied?\n", "- What is the interpretation of parameter `b`?\n", "- How do flow arrows change as tau_w gets bigger?\n", "\n", "[max 10 lines, 4 points]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "your answer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What would be the firing pattern if `a` is small (in the order of `0.01 nS`) ? To answer this, simulate the following 2 conditions [2 points] and write a short answer [max 5 lines, 2 points]:\n", "\n", "- A large jump `b` and a large time scale `tau_w`.\n", "- A small jump `b` and a small time scale `tau_w`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# A large jump b and a large time scale tau_w." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# A small jump b and a small time scale tau_w." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "your answer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Additional material:\n", "\n", "To learn more about the variety of patterns the relatively simple neuron model can reproduce, have a look the following publication: [Naud, R., Marcille, N., Clopath, C., Gerstner, W. (2008). Firing patterns in the adaptive exponential integrate-and-fire model. Biological cybernetics, 99(4-5), 335-347.](https://link.springer.com/article/10.1007/s00422-008-0264-7)" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 1 }