{ "cells": [ { "cell_type": "markdown", "id": "d88de07f", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "# _(Brette, Romain. 2004)_ LIF phase locking \n", "\n", "[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/brainpy/examples/blob/main/neurons/Romain_2004_LIF_phase_locking.ipynb)\n", "[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/brainpy/examples/blob/main/neurons/Romain_2004_LIF_phase_locking.ipynb)" ] }, { "cell_type": "markdown", "id": "4a786b2e", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "Implementation of the paper:\n", "\n", "- Brette, Romain. \"Dynamics of one-dimensional spiking neuron models.\" Journal of mathematical biology 48.1 (2004): 38-56.\n", "\n", "Author:\n", "\n", "- Chaoming Wang (chao.brain@qq.com)" ] }, { "cell_type": "code", "execution_count": 1, "id": "2b7ce7cc", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import brainpy as bp\n", "import brainpy.math as bm" ] }, { "cell_type": "code", "execution_count": 2, "id": "5b962198", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 3, "id": "ed85d1d9", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING:jax._src.lib.xla_bridge:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)\n" ] } ], "source": [ "# set parameters\n", "num = 2000\n", "tau = 100. # ms\n", "Vth = 1. # mV\n", "Vr = 0. # mV\n", "inputs = bm.linspace(2., 4., num)" ] }, { "cell_type": "code", "execution_count": 4, "id": "1467b69a", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "class LIF(bp.dyn.NeuDyn):\n", " def __init__(self, size, **kwargs):\n", " super(LIF, self).__init__(size, **kwargs)\n", " \n", " self.V = bm.Variable(bm.zeros(size))\n", " self.spike = bm.Variable(bm.zeros(size, dtype=bool))\n", " self.integral = bp.odeint(self.derivative)\n", "\n", " def derivative(self, V, t):\n", " return (-V + inputs + 2 * bm.sin(2 * bm.pi * t / tau)) / tau\n", "\n", " def update(self):\n", " tdi = bp.share.get_shargs()\n", " V = self.integral(self.V, tdi.t, tdi.dt)\n", " self.spike.value = V >= Vth\n", " self.V.value = bm.where(self.spike > 0., Vr, V)" ] }, { "cell_type": "code", "execution_count": 5, "id": "89d2a74f", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "group = LIF(num)\n", "runner = bp.DSRunner(group, monitors=['spike'])" ] }, { "cell_type": "code", "execution_count": 6, "id": "44143b20", "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1b387edcba2b4889853b747697a46d20", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/50000 [00:00" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "t = runner.run(duration=5 * 1000.)\n", "\n", "indices, times = bp.measure.raster_plot(runner.mon.spike, runner.mon.ts)\n", "\n", "# plt.plot((times % tau) / tau, inputs[indices], ',')\n", "\n", "spike_phases = (times % tau) / tau\n", "params = inputs[indices]\n", "plt.scatter(x=spike_phases, y=params, c=spike_phases,\n", " marker=',', s=0.1, cmap=\"coolwarm\")\n", "\n", "plt.xlabel('Spike phase')\n", "plt.ylabel('Parameter (input)')\n", "plt.show()" ] } ], "metadata": { "jupytext": { "formats": "ipynb,py:percent" }, "kernelspec": { "display_name": "brainpy", "language": "python", "name": "brainpy" }, "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.9.12" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }