Skip to content

Instantly share code, notes, and snippets.

@thesamovar
Last active June 6, 2017 11:00
Show Gist options
  • Save thesamovar/1d12ba3c84c0b80b3370a25e7208eacb to your computer and use it in GitHub Desktop.
Save thesamovar/1d12ba3c84c0b80b3370a25e7208eacb to your computer and use it in GitHub Desktop.
Synaptic scaling hack for Brian 2
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true,
"level": 7
},
"outputs": [],
"source": [
"from brian2 import *\n",
"prefs.codegen.target = 'numpy'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true,
"level": 7
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 1.42080708 2.11369193]\n",
"<neurongroup_1.wsum: array([ 1.42080708, 2.11369193])>\n"
]
}
],
"source": [
"start_scope()\n",
"\n",
"eqs_G = '''\n",
"dv/dt = -v/(10*ms) : 1\n",
"'''\n",
"G = NeuronGroup(3, eqs_G, threshold='v>1', reset='v=0',\n",
" events={'compute_wsum': 'True'})\n",
"eqs_H = '''\n",
"dv/dt = -v/(10*ms) : 1\n",
"wsum : 1\n",
"'''\n",
"H = NeuronGroup(2, eqs_H, threshold='v>1', reset='v=0')\n",
"H.run_regularly('wsum = 0')\n",
"S = Synapses(G, H, 'w : 1', on_pre={'pre': 'v += w',\n",
" 'wsum': 'wsum += w'},\n",
" on_event={'pre':'spike', 'wsum': 'compute_wsum'})\n",
"S.wsum.order = -1\n",
"S.connect()\n",
"S.w = 'rand()'\n",
"\n",
"run(1*ms)\n",
"\n",
"M = zeros((3, 2))\n",
"M[S.i, S.j] = S.w\n",
"print sum(M, axis=0)\n",
"print H.wsum"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python [default]",
"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": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment