{ "cells": [ { "cell_type": "markdown", "metadata": { "heading_collapsed": false, "level": 1 }, "source": [ "
\n", "\"The\n", "\"binder\n", "
\n", "\n", "# Brian demo\n", "\n", "The code below shows a demonstration of Brian in action with a simple graphical interface. Run the cell below by clicking on it and hitting `CTRL+ENTER`. You can change the parameters of the model with the sliders, and immediately see the change in behaviour.\n", "\n", "The model is a group of $N$ source neurons that fire Poisson spikes with a rate $R_\\mathrm{max}(1+\\sin(2\\pi f t))/2$, connected via synapses to a target neuron. Each source neuron has a probability $p$ of being connected, and synapses have a certain fixed weight $w$. The target neuron has two variables, the membrane potential $V$ and the adaptation potential $V_t$ that evolve according to the differential equations:\n", "\n", "$$\\tau\\frac{\\mathrm{d}V}{\\mathrm{dt}}=-V$$\n", "\n", "$$\\tau_t\\frac{\\mathrm{d}V_t}{\\mathrm{dt}}=1-V_t$$\n", "\n", "Each time the event $V>V_t$ occurs, the neuron spikes and $V$ is reset to 0, while $V_t$ increases by $\\delta_t$.\n", "\n", "This model is implemented with the following code:\n", "\n", "```python\n", "G = PoissonGroup(N, rates='R_max*0.5*(1+sin(2*pi*f*t))')\n", "eqs = '''\n", "dV/dt = -V/tau : 1\n", "dVt/dt = (1-Vt)/tau_t : 1\n", "'''\n", "H = NeuronGroup(1, eqs, threshold='V>Vt', reset='V=0; Vt += delta_t', method='linear')\n", "H.Vt = 1\n", "S = Synapses(G, H, on_pre='V += w')\n", "S.connect(p=p)\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline\n", "from brian2 import *\n", "from brian2tools import *\n", "import ipywidgets as ipw\n", "prefs.codegen.target = 'numpy'\n", "\n", "def model(N=20, R_max=150, f=10, w=0.1, p=0.5, tau=5, tau_t=50, delta_t=0.1):\n", " # Get parameters\n", " R_max = R_max*Hz\n", " f = f*Hz\n", " tau = tau*ms\n", " tau_t = tau_t*ms\n", " duration = 200*ms\n", " \n", " # Simulation code\n", " G = PoissonGroup(N, rates='R_max*0.5*(1+sin(2*pi*f*t))')\n", " eqs = '''\n", " dV/dt = -V/tau : 1\n", " dVt/dt = (1-Vt)/tau_t : 1\n", " '''\n", " H = NeuronGroup(1, eqs, threshold='V>Vt', reset='V=0; Vt += delta_t', method='linear')\n", " H.Vt = 1\n", " S = Synapses(G, H, on_pre='V += w')\n", " S.connect(p=p)\n", " # Run it\n", " MG = SpikeMonitor(G)\n", " MH = StateMonitor(H, ('V', 'Vt'), record=True)\n", " run(duration)\n", " \n", " # Plotting code\n", " figure(figsize=(15, 4))\n", " subplot(131)\n", " brian_plot(MG)\n", " title('Source neurons (Poisson)')\n", " subplot(132)\n", " plot(zeros(N), arange(N), 'ob')\n", " plot([0, 1], [S.i, ones(len(S.i))*N/2.], '-k')\n", " plot([1], [N/2.], 'og')\n", " xlim(-0.1, 1.1)\n", " ylim(-1, N)\n", " axis('off')\n", " title('Synapses')\n", " subplot(133)\n", " plot(MH.t, MH.V[0], label='V')\n", " plot(MH.t, MH.Vt[0], label='Vt')\n", " legend(loc='upper left')\n", " title('Target neuron')\n", " \n", "layout = ipw.Layout(width='100%')\n", "style = {'description_width': 'initial'}\n", "ipw.interact(model,\n", " N=ipw.IntSlider(value=20, min=5, max=100, step=5, continuous_update=False,\n", " description=\"Number of source neurons\", style=style, layout=layout),\n", " R_max=ipw.FloatSlider(value=300, min=0, max=500, step=10, continuous_update=False,\n", " description=r\"Source neuron max firing rate (Hz)\", style=style, layout=layout),\n", " f=ipw.FloatSlider(value=10, min=1, max=50, step=1, continuous_update=False,\n", " description=r\"Source neuron frequency (Hz)\", style=style, layout=layout),\n", " p=ipw.FloatSlider(value=0.5, min=0, max=1, step=0.01, continuous_update=False,\n", " description=r\"Synapse probability\", style=style, layout=layout),\n", " w=ipw.FloatSlider(value=0.3, min=0, max=1, step=0.01, continuous_update=False,\n", " description=r\"Synapse weight\", style=style, layout=layout),\n", " tau=ipw.FloatSlider(value=5, min=1, max=50, step=1, continuous_update=False,\n", " description=r\"Target neuron membrane time constant (ms)\", style=style, layout=layout),\n", " tau_t=ipw.FloatSlider(value=30, min=5, max=500, step=5, continuous_update=False,\n", " description=r\"Target neuron adaptation constant (ms)\", style=style, layout=layout),\n", " delta_t=ipw.FloatSlider(value=1.0, min=0, max=20, step=0.1, continuous_update=False,\n", " description=r\"Target neuron adaptation strength\", style=style, layout=layout),\n", " );" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.3" } }, "nbformat": 4, "nbformat_minor": 1 }