{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# _(Diesmann, et, al., 1999)_ Synfire Chains\n", "\n", "[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/brainpy/examples/blob/main/oscillation_synchronization/Diesmann_1999_synfire_chains.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/oscillation_synchronization/Diesmann_1999_synfire_chains.ipynb)" ] }, { "cell_type": "markdown", "metadata": { "lines_to_next_cell": 0 }, "source": [ "Implementation of the paper:\n", "\n", "- Diesmann, Markus, Marc-Oliver Gewaltig, and Ad Aertsen. \"Stable propagation of synchronous spiking in cortical neural networks.\" Nature 402.6761 (1999): 529-533.\n", "\n", "Author: [Chaoming Wang](mailto:chao.brain@qq.com)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T03:57:10.673040700Z", "start_time": "2023-07-22T03:57:10.012474800Z" } }, "outputs": [], "source": [ "import brainpy as bp\n", "import brainpy.math as bm\n", "\n", "bp.math.set_platform('cpu')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T03:59:35.279583600Z", "start_time": "2023-07-22T03:59:35.261647900Z" }, "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'2.4.3'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bp.__version__" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T03:57:10.679313300Z", "start_time": "2023-07-22T03:57:10.675439200Z" }, "lines_to_next_cell": 2 }, "outputs": [], "source": [ "duration = 100. # ms\n", "\n", "# Neuron model parameters\n", "Vr = -70. # mV\n", "Vt = -55. # mV\n", "tau_m = 10. # ms\n", "tau_ref = 1. # ms\n", "tau_psp = 0.325 # ms\n", "weight = 4.86 # mV\n", "noise = 39.24 # mV\n", "\n", "# Neuron groups\n", "n_groups = 10\n", "group_size = 100\n", "spike_sigma = 1.\n", "\n", "# Synapse parameter\n", "delay = 5.0 # ms" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T03:57:10.699542700Z", "start_time": "2023-07-22T03:57:10.683658500Z" } }, "outputs": [], "source": [ "# neuron model\n", "# ------------\n", "\n", "\n", "class Groups(bp.dyn.NeuDyn):\n", " def __init__(self, size, **kwargs):\n", " super(Groups, self).__init__(size, **kwargs)\n", "\n", " self.V = bm.Variable(Vr + bm.random.random(self.num) * (Vt - Vr))\n", " self.x = bm.Variable(bm.zeros(self.num))\n", " self.y = bm.Variable(bm.zeros(self.num))\n", " self.spike = bm.Variable(bm.zeros(self.num, dtype=bool))\n", " self.refractory = bm.Variable(bm.zeros(self.num, dtype=bool))\n", " self.t_last_spike = bm.Variable(bm.ones(self.num) * -1e7)\n", "\n", " # integral functions\n", " self.int_V = bp.odeint(lambda V, t, x: (-(V - Vr) + x) / tau_m)\n", " self.int_x = bp.odeint(lambda x, t, y: (-x + y) / tau_psp)\n", " self.int_y = bp.sdeint(f=lambda y, t: -y / tau_psp + 25.27,\n", " g=lambda y, t: noise)\n", "\n", " def update(self):\n", " tdi = bp.share.get_shargs()\n", " self.x[:] = self.int_x(self.x, tdi.t, self.y, tdi.dt)\n", " self.y[:] = self.int_y(self.y, tdi.t, tdi.dt)\n", " in_ref = (tdi.t - self.t_last_spike) < tau_ref\n", " V = self.int_V(self.V, tdi.t, self.x, tdi.dt)\n", " V = bm.where(in_ref, self.V, V)\n", " self.spike.value = V >= Vt\n", " self.t_last_spike.value = bm.where(self.spike, tdi.t, self.t_last_spike)\n", " self.V.value = bm.where(self.spike, Vr, V)\n", " self.refractory.value = bm.logical_or(in_ref, self.spike)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T03:57:10.717168700Z", "start_time": "2023-07-22T03:57:10.699542700Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "d:\\codes\\projects\\brainpy\\brainpy\\_src\\deprecations.py:86: DeprecationWarning: brainpy.TwoEndConn is deprecated. Use brainpy.synapses.TwoEndConn instead.\n", " _deprecate(message)\n" ] } ], "source": [ "# synaptic model\n", "# ---------------\n", "\n", "class SynBetweenGroups(bp.TwoEndConn):\n", " def __init__(self, group, ext_group, **kwargs):\n", " super(SynBetweenGroups, self).__init__(group, group, **kwargs)\n", "\n", " self.group = group\n", " self.ext = ext_group\n", "\n", " # variables\n", " self.delay_step = int(delay/bm.get_dt())\n", " self.g = bm.LengthDelay(bm.zeros(self.group.num), self.delay_step)\n", "\n", " def update(self):\n", " # synapse model between external and group 1\n", " g = bm.zeros(self.group.num)\n", " g[:group_size] = weight * self.ext.spike.sum()\n", " # feed-forward connection\n", " for i in range(1, n_groups):\n", " s1 = (i - 1) * group_size\n", " s2 = i * group_size\n", " s3 = (i + 1) * group_size\n", " g[s2: s3] = weight * self.group.spike[s1: s2].sum()\n", " # delay push\n", " self.g.update(g)\n", " # delay pull\n", " self.group.y += self.g(self.delay_step)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T03:57:10.751984600Z", "start_time": "2023-07-22T03:57:10.717168700Z" } }, "outputs": [], "source": [ "# network running\n", "# ---------------\n", "\n", "def run_network(spike_num=48):\n", " bm.random.seed(123)\n", " times = bm.random.randn(spike_num) * spike_sigma + 20\n", " ext_group = bp.neurons.SpikeTimeGroup(spike_num, times=times, indices=bm.arange(spike_num))\n", " group = Groups(size=n_groups * group_size)\n", " syn_conn = SynBetweenGroups(group, ext_group)\n", " net = bp.Network(ext_group=ext_group, syn_conn=syn_conn, group=group)\n", "\n", " # simulation\n", " runner = bp.DSRunner(net, monitors=['group.spike'])\n", " runner.run(duration)\n", "\n", " # visualization\n", " bp.visualize.raster_plot(runner.mon.ts, runner.mon['group.spike'],\n", " xlim=(0, duration), show=True)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T03:57:11.941024200Z", "start_time": "2023-07-22T03:57:10.736317100Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6ff0601a769d4afc8d02edaa45948d36", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "run_network(spike_num=51)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When external spike num is 44, the synchronous excitation disperses and eventually dies out." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2023-07-22T03:57:12.873764900Z", "start_time": "2023-07-22T03:57:11.941024200Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "37317a4cebd7454185c03df265c774bc", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "run_network(spike_num=44)" ] } ], "metadata": { "hide_input": false, "jupytext": { "formats": "ipynb,auto: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": false, "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 }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }