{ "cells": [ { "cell_type": "markdown", "id": "fe54e3d1", "metadata": {}, "source": [ "# *(Brette, et, al., 2007)* CUBA\n", "\n", "[![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/brainpy/examples/blob/main/ei_nets/Brette_2007_CUBA.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/ei_nets/Brette_2007_CUBA.ipynb)" ] }, { "cell_type": "markdown", "id": "cee95884", "metadata": {}, "source": [ "Implementation of the paper:\n", "\n", "- Brette, R., Rudolph, M., Carnevale, T., Hines, M., Beeman, D., Bower, J. M., et al. (2007), Simulation of networks of spiking neurons: a review of tools and strategies., J. Comput. Neurosci., 23, 3, 349–98\n", "\n", "which is based on the balanced network proposed by:\n", "\n", "- Vogels, T. P. and Abbott, L. F. (2005), Signal propagation and logic gating in networks of integrate-and-fire neurons., J. Neurosci., 25, 46, 10786–95\n", "\n", "Authors:\n", "\n", "- [Chaoming Wang](https://github.com/chaoming0625)" ] }, { "cell_type": "code", "execution_count": 1, "id": "f37db544", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:41.536851400Z", "start_time": "2023-08-27T07:17:40.387418300Z" } }, "outputs": [], "source": [ "import brainpy as bp\n", "import brainpy.math as bm\n", "import numpy as np\n", "\n", "bp.math.set_platform('cpu')" ] }, { "cell_type": "code", "execution_count": 2, "id": "25a6f75bf4a50015", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:41.552858300Z", "start_time": "2023-08-27T07:17:41.536851400Z" }, "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'2.4.4.post1'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bp.__version__" ] }, { "cell_type": "markdown", "id": "421f1b0a0a5cb54f", "metadata": { "collapsed": false }, "source": [ "## Old version" ] }, { "cell_type": "code", "execution_count": 3, "id": "4f2094f7add83134", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:41.596782900Z", "start_time": "2023-08-27T07:17:41.551420300Z" }, "collapsed": false }, "outputs": [], "source": [ "class CUBA(bp.DynSysGroup):\n", " def __init__(self, scale=1.0, method='exp_auto'):\n", " # network size\n", " num_exc = int(3200 * scale)\n", " num_inh = int(800 * scale)\n", "\n", " # neurons\n", " pars = dict(V_rest=-49, V_th=-50., V_reset=-60, tau=20., tau_ref=5.,\n", " V_initializer=bp.init.Normal(-55., 2.))\n", " E = bp.neurons.LIF(num_exc, **pars, method=method)\n", " I = bp.neurons.LIF(num_inh, **pars, method=method)\n", "\n", " # synapses\n", " we = 1.62 / scale # excitatory synaptic weight (voltage)\n", " wi = -9.0 / scale # inhibitory synaptic weight\n", " E2E = bp.synapses.Exponential(E, E, bp.conn.FixedProb(0.02),\n", " g_max=we, tau=5., method=method)\n", " E2I = bp.synapses.Exponential(E, I, bp.conn.FixedProb(0.02),\n", " g_max=we, tau=5., method=method)\n", " I2E = bp.synapses.Exponential(I, E, bp.conn.FixedProb(0.02),\n", " g_max=wi, tau=10., method=method)\n", " I2I = bp.synapses.Exponential(I, I, bp.conn.FixedProb(0.02),\n", " g_max=wi, tau=10., method=method)\n", "\n", " super(CUBA, self).__init__(E2E, E2I, I2E, I2I, E=E, I=I)" ] }, { "cell_type": "code", "execution_count": 4, "id": "cb710e03faba1b48", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:44.914816400Z", "start_time": "2023-08-27T07:17:41.568120300Z" }, "collapsed": false }, "outputs": [], "source": [ "# network\n", "net = CUBA()" ] }, { "cell_type": "code", "execution_count": 5, "id": "3a36b5f10ad49cc8", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:46.392512800Z", "start_time": "2023-08-27T07:17:44.916811300Z" }, "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a3a3235f045c47c0a64d507ca8db2443", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# visualization\n", "bp.visualize.raster_plot(runner.mon.ts, runner.mon['E.spike'], show=True)" ] }, { "cell_type": "markdown", "id": "692ff566982b844", "metadata": { "collapsed": false }, "source": [ "## New version (>= 2.4.0)" ] }, { "cell_type": "code", "execution_count": 7, "id": "c205da580562e9c2", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:46.842548500Z", "start_time": "2023-08-27T07:17:46.825493600Z" }, "collapsed": false }, "outputs": [], "source": [ "class ExponCUBA(bp.Projection):\n", " def __init__(self, pre, post, prob, g_max, tau):\n", " super().__init__()\n", " self.proj = bp.dyn.ProjAlignPostMg2(\n", " pre=pre,\n", " delay=None, \n", " comm=bp.dnn.EventCSRLinear(bp.conn.FixedProb(prob, pre=pre.num, post=post.num), g_max),\n", " syn=bp.dyn.Expon.desc(post.num, tau=tau),\n", " out=bp.dyn.CUBA.desc(),\n", " post=post,\n", " )" ] }, { "cell_type": "code", "execution_count": 8, "id": "81b65e2b", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:46.911676700Z", "start_time": "2023-08-27T07:17:46.846544800Z" } }, "outputs": [], "source": [ "class CUBA_Net(bp.DynSysGroup):\n", " def __init__(self, scale=1.0):\n", " super().__init__()\n", " \n", " # network size\n", " num_exc = int(3200 * scale)\n", " num_inh = int(800 * scale)\n", "\n", " # neurons\n", " pars = dict(V_rest=-49, V_th=-50., V_reset=-60, tau=20., tau_ref=5.,\n", " V_initializer=bp.init.Normal(-55., 2.))\n", " self.E = bp.dyn.LifRef(num_exc, **pars)\n", " self.I = bp.dyn.LifRef(num_inh, **pars)\n", "\n", " # synapses\n", " we = 1.62 / scale # excitatory synaptic weight (voltage)\n", " wi = -9.0 / scale # inhibitory synaptic weight\n", " self.E2E = ExponCUBA(self.E, self.E, 0.02, g_max=we, tau=5.)\n", " self.E2I = ExponCUBA(self.E, self.I, 0.02, g_max=we, tau=5.)\n", " self.I2E = ExponCUBA(self.I, self.E, 0.02, g_max=wi, tau=10.)\n", " self.I2I = ExponCUBA(self.I, self.I, 0.02, g_max=wi, tau=10.)\n", " \n", " def update(self, inp):\n", " self.E2E()\n", " self.E2I()\n", " self.I2E()\n", " self.I2I()\n", " self.E(inp)\n", " self.I(inp)\n", " return self.E.spike, self.I.spike" ] }, { "cell_type": "code", "execution_count": 9, "id": "b9382243", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:48.185389600Z", "start_time": "2023-08-27T07:17:46.858058200Z" } }, "outputs": [], "source": [ "# network\n", "net = CUBA_Net()" ] }, { "cell_type": "code", "execution_count": 10, "id": "551451d1", "metadata": { "ExecuteTime": { "end_time": "2023-08-27T07:17:49.176618500Z", "start_time": "2023-08-27T07:17:48.186389800Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "3beb5f58981745ffa614efdbd4136543", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/1000 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# visualization\n", "bp.visualize.raster_plot(indices * bm.get_dt(), e_sps, show=True)" ] } ], "metadata": { "jupytext": { "encoding": "# -*- coding: utf-8 -*-", "formats": "ipynb,py:percent" }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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 }