{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting lazyarray\n", " Downloading https://files.pythonhosted.org/packages/a0/c5/4cac8d8749bea1e675aa97232e7eaa1e340b5bd56a041268eb48c8dc523c/lazyarray-0.3.2.tar.gz\n", "Requirement already satisfied: numpy>=1.8 in /opt/conda/lib/python3.5/site-packages (from lazyarray) (1.12.1)\n", "Building wheels for collected packages: lazyarray\n", " Running setup.py bdist_wheel for lazyarray ... \u001b[?25l-\b \b\\\b \bdone\n", "\u001b[?25h Stored in directory: /home/jovyan/.cache/pip/wheels/b6/04/41/5fb855bf80313b5526e43e293153a1f8b7bce477a5b2d0f346\n", "Successfully built lazyarray\n", "\u001b[31mcffi 1.11.5 requires pycparser, which is not installed.\u001b[0m\n", "\u001b[31mcryptography 2.2.1 requires asn1crypto>=0.21.0, which is not installed.\u001b[0m\n", "\u001b[31mallensdk 0.14.2 has requirement pandas<0.20.0,>=0.16.2, but you'll have pandas 0.23.1 which is incompatible.\u001b[0m\n", "Installing collected packages: lazyarray\n", "Successfully installed lazyarray-0.3.2\n", "\u001b[33mYou are using pip version 10.0.1, however version 18.1 is available.\n", "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n" ] } ], "source": [ "!pip install lazyarray\n", "import numpy as np\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from neuronunit.optimization.model_parameters import reduced_dict, reduced_cells \n", "explore_param = {k:(np.min(v),np.max(v)) for k,v in reduced_dict.items()}\n", "#print(ontologies) \n", " " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", "\n", "electro_path = 'pipe_tests.p'\n", "purkinje = { 'nlex_id':'sao471801888'}#'NLXWIKI:sao471801888'} # purkinje\n", "fi_basket = {'nlex_id':'100201'}\n", "#pvis_cortex = {'nlex_id':'nifext_50'} # Layer V pyramidal cell\n", "olf_mitral = { 'nlex_id':'nifext_120'}\n", "ca1_pyr = { 'nlex_id':'830368389'}\n", "pipe = [ fi_basket, olf_mitral, ca1_pyr, purkinje ]\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "purkinje ={\"id\": 18, \"name\": \"Cerebellum Purkinje cell\", \"neuron_db_id\": 271, \"nlex_id\": \"sao471801888\"}\n", "fi_basket = {\"id\": 65, \"name\": \"Dentate gyrus basket cell\", \"neuron_db_id\": None, \"nlex_id\": \"nlx_cell_100201\"}\n", "pvis_cortex = {\"id\": 111, \"name\": \"Neocortex pyramidal cell layer 5-6\", \"neuron_db_id\": 265, \"nlex_id\": \"nifext_50\"}\n", "#does not have rheobase\n", "#olf_mitral = {\"id\": 129, \"name\": \"Olfactory bulb (main) mitral cell\", \"neuron_db_id\": 267, \"nlex_id\": \"nlx_anat_100201\"}\n", "ca1_pyr = {\"id\": 85, \"name\": \"Hippocampus CA1 pyramidal cell\", \"neuron_db_id\": 258, \"nlex_id\": \"sao830368389\"}\n", "pipe = [ fi_basket, ca1_pyr, purkinje, pvis_cortex]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "electro_tests = []\n", "electro_frame = {}\n", "\n", "#p_tests, p_observations = get_neab.get_neuron_criteria(olf_mitral)\n", "#electro_frame[p[\"name\"]] = p_observations#, p_tests))\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "electro_tests = []\n", "obs_frame = {}\n", "test_frame = {}\n", "import os\n", "import pickle\n", "try: \n", "\n", " electro_path = str(os.getcwd())+'all_tests.p'\n", "\n", " assert os.path.isfile(electro_path) == True\n", " with open(electro_path,'rb') as f:\n", " (obs_frame,test_frame) = pickle.load(f)\n", "\n", "except:\n", " for p in pipe:\n", " p_tests, p_observations = get_neab.get_neuron_criteria(p)\n", " obs_frame[p[\"name\"]] = p_observations#, p_tests))\n", " test_frame[p[\"name\"]] = p_tests#, p_tests))\n", " electro_path = str(os.getcwd())+'all_tests.p'\n", " with open(electro_path,'wb') as f:\n", " pickle.dump((obs_frame,test_frame),f)\n", "\n", "# print(test_frame)\n", " " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "dict_keys(['olf_mit', 'Hippocampus CA1 pyramidal cell', 'Neocortex pyramidal cell layer 5-6', 'Dentate gyrus basket cell', 'Cerebellum Purkinje cell'])\n" ] }, { "data": { "text/plain": [ "Cell Capacitance {'mean': 89.7960714285714 pF, 'n': 14, 'std': ...\n", "Input Resistance {'mean': 107.080327644332 Mohm, 'n': 113, 'std...\n", "Membrane Time Constant {'mean': 24.5021946169772 ms, 'n': 46, 'std': ...\n", "Resting membrane potential {'mean': -65.2261863636364 mV, 'n': 110, 'std'...\n", "Rheobase {'mean': 189.24 pA, 'n': 17, 'std': 287.163664...\n", "Spike Amplitude {'mean': 86.364525297619 mV, 'n': 64, 'std': 1...\n", "Spike Half-Width {'mean': 1.31895278450363 ms, 'n': 59, 'std': ...\n", "Spike Threshold {'mean': -47.5985714285714 mV, 'n': 70, 'std':...\n", "Name: Hippocampus CA1 pyramidal cell, dtype: object" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "from neuronunit.tests.fi import RheobaseTestP\n", "#obs_frame.pop(\"olf_mit\", 0)\n", "#test_frame.pop(\"olf_mit\", 0)\n", "\n", "for k,v in test_frame.items():\n", " if \"olf_mit\" not in k:\n", " obs = obs_frame[k]\n", " v[0] = RheobaseTestP(obs['Rheobase'])\n", "\n", "\n", "df = pd.DataFrame.from_dict(obs_frame)\n", "\n", "print(test_frame.keys())\n", "df['Hippocampus CA1 pyramidal cell']" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [], "source": [ "##### \n", "from neuronunit.optimization import optimization_management as om\n", "import pickle\n", "\n", "\n", "free_params = ['a','b','k','c','C','d','vPeak','vr']#vt','c','k','d']#,'vt','k','c','C']#,'C'] # this can only be odd numbers.\n", "\n", "##\n", "# Use information that is available\n", "##\n", "hc_ = reduced_cells['RS']\n", "\n", "hc_['vr'] = -65.2261863636364\n", "\n", "hc_['vPeak'] = hc_['vr'] + 86.364525297619\n", "\n", "explore_param['C'] = (hc_['C']-20,hc_['C']+20)\n", "explore_param['vr'] = (hc_['vr']-5,hc_['vr']+5)\n", "#hc = {}\n", "#hc['C'] = 89.7960714285714\n", "\n", "\n", "use_test = test_frame[\"Neocortex pyramidal cell layer 5-6\"]\n", "\n", "#from sciunit import scores# score_type \n", "\n", "#for t in use_test[::-1]:\n", "# t.score_type = scores.RatioScore\n", "#print(use_test)\n", "#reduced_tests = [use_test[0], use_test[-2], use_test[len(use_test)-1]]\n", "#bigger_tests = use_test[1:-2]\n", "#bigger_tests.insert(0,use_test[0])\n", "\n", "test_opt = {}\n", "import pickle\n", "\n", "with open('data_dump.p','wb') as f:\n", " pickle.dump(test_opt,f)\n", "\n", "\n", " \n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "RheobaseTestP\n", "{'mean': array(213.849583333333) * pA, 'n': 32, 'std': array(170.452454715608) * pA}\n" ] } ], "source": [ "#print(reduced_cells.keys())\n", "#print(test_frame.keys())\n", "use_test[0].observation\n", "#from neuronunit.tests import RheobaseP\n", "from neuronunit.tests.fi import RheobaseTestP# as discovery\n", "#print(use_test[1].observation)\n", "#print(use_test[3].name)\n", "print(use_test[0].name)\n", "\n", "rtp = RheobaseTestP(use_test[0].observation)\n", "use_test[0] = rtp\n", "print(use_test[0].observation)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "\"\\ntry:\\n import pickle\\n with open('data_dump.p','rb') as f:\\n test_opt = pickle.load(f)\\nexcept:\\n MU = 12\\n NGEN = 25\\n cnt = 1\\n for t in use_test: \\n if cnt==len(use_test):\\n MU = 12\\n NGEN = 20\\n\\n npcl, DO = om.run_ga(explore_param,NGEN,[t],free_params=free_params, NSGA = True, MU = MU)\\n else:\\n\\n npcl, DO = om.run_ga(explore_param,NGEN,[t],free_params=free_params, NSGA = True, MU = MU)\\n\\n test_opt[str(t)] = {'out':npcl}\\n\\n ranges = {}\\n stds = npcl['pop'][0].dtc.attrs\\n for k in npcl['pop'][0].dtc.attrs.keys(): \\n stds[k] = []\\n ranges[k] = []\\n\\n\\n for i in npcl['pop'][::5]:\\n for k,v in i.dtc.attrs.items():\\n stds[k].append(v)\\n ranges[k].append(v)\\n\\n for k in npcl['pop'][0].dtc.attrs.keys():\\n ranges[k] = (np.min(ranges[k][1::]),np.max(ranges[k][1::]))\\n\\n stds[k] = np.std(stds[k][1::])\\n test_opt[str(t)]['stds'] = stds \\n test_opt[str(t)]['ranges'] = ranges \\n\\n cnt+=1\\n \\n with open('data_dump.p','wb') as f:\\n pickle.dump(test_opt,f)\\n\"" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "'''\n", "try:\n", " import pickle\n", " with open('data_dump.p','rb') as f:\n", " test_opt = pickle.load(f)\n", "except:\n", " MU = 12\n", " NGEN = 25\n", " cnt = 1\n", " for t in use_test: \n", " if cnt==len(use_test):\n", " MU = 12\n", " NGEN = 20\n", "\n", " npcl, DO = om.run_ga(explore_param,NGEN,[t],free_params=free_params, NSGA = True, MU = MU)\n", " else:\n", "\n", " npcl, DO = om.run_ga(explore_param,NGEN,[t],free_params=free_params, NSGA = True, MU = MU)\n", "\n", " test_opt[str(t)] = {'out':npcl}\n", "\n", " ranges = {}\n", " stds = npcl['pop'][0].dtc.attrs\n", " for k in npcl['pop'][0].dtc.attrs.keys(): \n", " stds[k] = []\n", " ranges[k] = []\n", "\n", "\n", " for i in npcl['pop'][::5]:\n", " for k,v in i.dtc.attrs.items():\n", " stds[k].append(v)\n", " ranges[k].append(v)\n", "\n", " for k in npcl['pop'][0].dtc.attrs.keys():\n", " ranges[k] = (np.min(ranges[k][1::]),np.max(ranges[k][1::]))\n", "\n", " stds[k] = np.std(stds[k][1::])\n", " test_opt[str(t)]['stds'] = stds \n", " test_opt[str(t)]['ranges'] = ranges \n", "\n", " cnt+=1\n", " \n", " with open('data_dump.p','wb') as f:\n", " pickle.dump(test_opt,f)\n", "''' " ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "{'Cerebellum Purkinje cell': [,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ],\n", " 'Dentate gyrus basket cell': [,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ],\n", " 'Hippocampus CA1 pyramidal cell': [,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ],\n", " 'Neocortex pyramidal cell layer 5-6': [,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ],\n", " 'olf_mit': [,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ]}" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "reduced_cells.keys()\n", "test_frame.keys()\n", "test_frame.keys()\n", "test_frame['olf_mit'].insert(0,test_frame['Cerebellum Purkinje cell'][0])\n", "test_frame\n", "#pd.DataFrame(index=test_frame.keys(),columns=reduced_cells.keys())\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/conda/lib/python3.5/site-packages/sciunit/scores/complete.py:73: RuntimeWarning: divide by zero encountered in true_divide\n", " value = (p_value - o_mean)/o_std\n", "/home/jovyan/neuronunit/neuronunit/tests/passive.py:82: RuntimeWarning: overflow encountered in exp\n", " vm_fit[offset:,0] = a * np.exp(-t[offset:]/b) + c\n", "/home/jovyan/neuronunit/neuronunit/tests/passive.py:82: RuntimeWarning: overflow encountered in multiply\n", " vm_fit[offset:,0] = a * np.exp(-t[offset:]/b) + c\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
RSIBLTSTCTC_burst
olf_mit7.123227.378726.839686.791056.68538
Hippocampus CA1 pyramidal cell4.26525.845655.705275.746336.06554
Neocortex pyramidal cell layer 5-64.669675.838846.210746.364356.5461
Dentate gyrus basket cell5.335756.447026.037696.275356.38901
Cerebellum Purkinje cell6.043425.951735.472375.698255.53656
\n", "
" ], "text/plain": [ " RS IB LTS TC \\\n", "olf_mit 7.12322 7.37872 6.83968 6.79105 \n", "Hippocampus CA1 pyramidal cell 4.2652 5.84565 5.70527 5.74633 \n", "Neocortex pyramidal cell layer 5-6 4.66967 5.83884 6.21074 6.36435 \n", "Dentate gyrus basket cell 5.33575 6.44702 6.03769 6.27535 \n", "Cerebellum Purkinje cell 6.04342 5.95173 5.47237 5.69825 \n", "\n", " TC_burst \n", "olf_mit 6.68538 \n", "Hippocampus CA1 pyramidal cell 6.06554 \n", "Neocortex pyramidal cell layer 5-6 6.5461 \n", "Dentate gyrus basket cell 6.38901 \n", "Cerebellum Purkinje cell 5.53656 " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "from neuronunit.optimization.data_transport_container import DataTC\n", "from neuronunit.tests.fi import RheobaseTestP# as discovery\n", "from neuronunit.optimization.optimization_management import dtc_to_rheo, format_test, nunit_evaluation\n", "import quantities as pq\n", "from neuronunit.models.reduced import ReducedModel\n", "from neuronunit.optimization.model_parameters import model_params, path_params\n", "LEMS_MODEL_PATH = path_params['model_path']\n", "list_to_frame = []\n", "import pdb\n", "\n", "df = pd.DataFrame(index=test_frame.keys(),columns=reduced_cells.keys())\n", "\n", "for k,v in reduced_cells.items():\n", " temp = {}\n", " temp[str(v)] = {}\n", " dtc = DataTC()\n", " dtc.tests = use_test\n", " dtc.attrs = v \n", " dtc.backend = 'RAW'\n", " dtc.cell_name = 'vanilla'\n", "\n", "\n", " for key, use_test in test_frame.items():\n", " dtc.tests = use_test\n", " dtc = dtc_to_rheo(dtc)\n", " dtc = format_test(dtc)\n", "\n", " if dtc.rheobase is not None:\n", " if dtc.rheobase!=-1.0:\n", "\n", " \n", " dtc = nunit_evaluation(dtc)\n", " df[k][key] = dtc.get_ss()\n", " #temp[str(v)][str(key)] = dtc.get_ss()\n", "\n", "# list_to_frame.append(temp)\n", "#df = pd.DataFrame(list_to_frame)\n", "df\n", " #bridge_judge\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
RSIBLTSTCTC_burst
olf_mit7.123227.378726.839686.791056.68538
Hippocampus CA1 pyramidal cell4.26525.845655.705275.746336.06554
Neocortex pyramidal cell layer 5-64.669675.838846.210746.364356.5461
Dentate gyrus basket cell5.335756.447026.037696.275356.38901
Cerebellum Purkinje cell6.043425.951735.472375.698255.53656
\n", "
" ], "text/plain": [ " RS IB LTS TC \\\n", "olf_mit 7.12322 7.37872 6.83968 6.79105 \n", "Hippocampus CA1 pyramidal cell 4.2652 5.84565 5.70527 5.74633 \n", "Neocortex pyramidal cell layer 5-6 4.66967 5.83884 6.21074 6.36435 \n", "Dentate gyrus basket cell 5.33575 6.44702 6.03769 6.27535 \n", "Cerebellum Purkinje cell 6.04342 5.95173 5.47237 5.69825 \n", "\n", " TC_burst \n", "olf_mit 6.68538 \n", "Hippocampus CA1 pyramidal cell 6.06554 \n", "Neocortex pyramidal cell layer 5-6 6.5461 \n", "Dentate gyrus basket cell 6.38901 \n", "Cerebellum Purkinje cell 5.53656 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from neuronunit.tests import dm \n", "dmtests = dm.Druckmann2013Test\n", "d_tests = []\n", "for d in dir(dm):\n", " if \"Test\" in d:\n", " exec('d_tests.append(dm.'+str(d)+')')\n", "\n", " \n", "#print(d_tests)\n", "\n", "\n", "#from neuronunit.tests.dm import InputResistanceTest as DMInputResistanceTest\n", "#use_test.append(DMInputResistanceTest(injection_currents=[-11.0*pq.pA,-6*pq.pA,-1*pq.pA,]))\n", "#print(use_test)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['a', 'b', 'k', 'c', 'C', 'd', 'vPeak', 'vr']\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/jovyan/neuronunit/neuronunit/tests/passive.py:82: RuntimeWarning: overflow encountered in exp\n", " vm_fit[offset:,0] = a * np.exp(-t[offset:]/b) + c\n", "/home/jovyan/neuronunit/neuronunit/tests/passive.py:82: RuntimeWarning: overflow encountered in multiply\n", " vm_fit[offset:,0] = a * np.exp(-t[offset:]/b) + c\n", "INFO:__main__:gen\tnevals\tavg \tstd \tmin \tmax \n", "1 \t6 \t5.63008\t0.555441\t4.81908\t6.24896\n", "2 \t5 \t5.61101\t0.582143\t4.81122\t6.24476\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n", "got here a a a \n", "\n", "\n", "\n", "\n", " \n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "INFO:__main__:3 \t6 \t5.71771\t0.287229\t5.40427\t6.09923\n" ] } ], "source": [ "\n", "\n", "MU = 6\n", "NGEN = 200\n", "\n", "import pickle\n", "import numpy as np\n", "print(free_params)\n", " \n", "index, DO = om.run_ga(explore_param,NGEN,use_test,free_params=free_params, NSGA = False, MU = MU)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", "\n", "MU = 6\n", "NGEN = 200\n", "\n", "import pickle\n", "import numpy as np\n", "print(free_params)\n", " \n", "index, DO = om.run_ga(explore_param,NGEN,use_test,free_params=free_params, NSGA = False, MU = MU)\n", "'''\n", "MU = 6\n", "NGEN = 200\n", "\n", "import pickle\n", "\n", "import numpy as np\n", "try:\n", " with open('multi_objective.p','rb') as f:\n", " test_opt = pickle.load(f)\n", "except:\n", "\n", "for index, use_test in enumerate(test_frame.values()):\n", "\n", " if index % 2 == 0:\n", " index, DO = om.run_ga(explore_param,NGEN,use_test,free_params=free_params, NSGA = False, MU = MU)\n", " else:\n", " index, DO = om.run_ga(explore_param,NGEN,use_test,free_params=free_params, NSGA = False, MU = MU)\n", " #print(NSGA)\n", "\n", " print('can get as low as 2.70295, 2.70679')\n", "\n", " test_opt = {str('multi_objective')+str(index):npcl}\n", " with open('multi_objective.p','wb') as f:\n", " pickle.dump(test_opt,f)\n", "\n", "\n", "print(np.sum(list(test_opt['multi_objective']['pf'][2].dtc.scores.values())))\n", "print(np.sum(list(test_opt['multi_objective']['pf'][1].dtc.scores.values())))\n", "#print(np.sum(list(test_opt['multi_objective']['hof'][0].dtc.scores.values())))\n", "print(test_opt['multi_objective']['pf'][2].dtc.scores.items())\n", "print(test_opt['multi_objective']['pf'][1].dtc.scores.items())\n", "'''\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "test_opt.keys()\n", "for value in test_opt.values():\n", " value['stds']\n", " value['ranges']\n", " print(value['ranges']) \n", " print(value['stds'])\n", " \n", " #fig = pl.figure()\n", " #ax = pl.subplot(111)\n", " #ax.bar(range(len(value.keys())), values)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "with open('data_dump.p','rb') as f:\n", " test_opt = pickle.load(f)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "test_opt" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#errorbar\n", "#for \n", "import seaborn as sns\n", "from matplotlib.pyplot import errorbar\n", "import matplotlib.pyplot as plt\n", "\n", "fig0,ax0 = plt.subplots(dim,dim,figsize=(10,10))\n", "plt.figure(num=None, figsize=(11, 11), dpi=80, facecolor='w', edgecolor='k')\n", "\n", "for v in test_opt.values():\n", " x = 0\n", " labels = []\n", " plt.clf()\n", " for k_,v_ in v['ranges'].items(): \n", " #print(k_)\n", " value = v_\n", "\n", " y = np.mean(value)\n", " err = max(value)-min(value)\n", " errorbar(x, y, err, marker='s', mfc='red',\n", " mec='green', ms=2, mew=4,label='in '+str(k_))\n", " x+=1\n", " labels.append(k_)\n", " plt.xticks(np.arange(len(labels)), labels)\n", " ax0[i] = plt\n", "\n", " #plt.title(str(v))\n", "\n", "plt.show()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "\n", "from mpl_toolkits.mplot3d import Axes3D\n", "from sklearn.cluster import KMeans\n", "from sklearn import datasets\n", "import seaborn as sns; sns.set() # for plot styling\n", "dfs.replace([np.inf, -np.inf], np.nan)\n", "dfs = dfs.dropna()\n", "\n", "#X = dfs[['standard','sp','ss','info_density','gf','standard','uniqueness','info_density','penalty']]\n", "X = dfs[['standard','sp','ss']]\n", "\n", "X = X.as_matrix()\n", "#import pdb; pdb.set_trace()\n", "\n", "est = KMeans(n_clusters=3)\n", "\n", "est.fit(X)\n", "\n", "y_kmeans = est.predict(X)\n", "centers = est.cluster_centers_\n", "\n", "fignum = 1\n", "fig = plt.figure(fignum, figsize=(4, 3))\n", "ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=48, azim=134)\n", "ax.scatter(X[:, 0], X[:, 1], X[:, 2], c=y_kmeans, s=50)\n", "ax.scatter(centers[:, 0], centers[:, 1], centers[:, 2], c='black', s=200, alpha=0.5);\n", "ax.w_xaxis.set_ticklabels([])\n", "ax.w_yaxis.set_ticklabels([])\n", "ax.w_zaxis.set_ticklabels([])\n", "ax.set_xlabel('standard')\n", "ax.set_ylabel('subjectivity')\n", "ax.set_zlabel('sentiment polarity')\n", "#ax.set_title(titles[fignum - 1])\n", "#ax.dist = 12\n", "fignum = fignum + 1\n", "for x,i in enumerate(zip(y_kmeans,dfs['clue_words'])):\n", " try:\n", " print(i[0],i[1],dfs['link'][x],dfs['publication'][x],dfs['clue_links'][x],dfs['sp_norm'][x],dfs['ss_norm'][x],dfs['uniqueness'][x])\n", " except:\n", " print(i)\n", "\n", "fig.savefig('3dCluster.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# the parameter 'd' only seems important\n", "# C does not have to be too precise within a range." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "I consider the final gene populations for each of the eight tests. I compute the variance in each of the converged populations, I see that variance is low in many of the gene populations.\n", "\n", "When all variables are used to optomize only against one set of parameters, you expect their would be high variance in parameters, that don't matter much with respect to that error criteria (you expect redundancy of solutions).\n", "\n", "I compute std on errors over all the tests in order to estimate how amenable the problem is to multiobjective optimization." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from neuronunit.models.reduced import ReducedModel\n", "from neuronunit.optimization.model_parameters import model_params, path_params\n", "LEMS_MODEL_PATH = path_params['model_path']\n", "import quantities as pq\n", "plt.figure(num=None, figsize=(11, 11), dpi=80, facecolor='w', edgecolor='k')\n", "\n", "for k,v in test_opt.items(): \n", " model = ReducedModel(LEMS_MODEL_PATH, name= str('vanilla'), backend=('RAW'))\n", " model.attrs = v['out']['pf'][1].dtc.attrs\n", " print(str(k), v['out']['pf'][1].dtc.get_ss())#fitness)\n", " iparams = {}\n", " iparams['injected_square_current'] = {}\n", " iparams['injected_square_current']['amplitude'] =v['out']['pf'][1].rheobase['value']*pq.pA\n", " #['amplitude'] = dtc.vtest[k]['injected_square_current']['amplitude']\n", " DELAY = 100.0*pq.ms\n", " DURATION = 1000.0*pq.ms\n", " iparams['injected_square_current']['delay'] = DELAY\n", " iparams['injected_square_current']['duration'] = int(DURATION)\n", "\n", " model.inject_square_current(iparams)\n", "\n", " plt.plot(model.get_membrane_potential().times,model.get_membrane_potential(),label=str(k))\n", " plt.legend()\n", "plt.show()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "'''\n", "#print([i.fitness.values for i in test_opt['t'][0]['pop']])#.keys()\n", "print(np.std([i[0] for i in test_opt['t'][0]['pop'][0:5]]))#.keys()\n", "print(np.std([i[1] for i in test_opt['t'][0]['pop'][0:5]]))#.keys()\n", "print(np.std([i[2] for i in test_opt['t'][0]['pop'][0:5]]))#.keys()\n", "print(np.std([i[3] for i in test_opt['t'][0]['pop'][0:5]]))#.keys()\n", "print(test_opt['t'][0]['pop'][0][0])\n", "print(test_opt['t'][0]['pop'][0][1])\n", "test_opt['t'][0]['pop'][0].dtc.attrs\n", "'''" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", "#values = { k:v for v in npcl['pop'][i].dtc.attrs.items() for i in npcl['pop'] }\n", "#print(values) \n", "#print(stds.keys())\n", "#stds\n", "#dtc.variances[k] for k in dtc.attrs.keys() " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", "DO.seed_pop = npcl['pf'][0:MU]\n", "npcl, DO = om.run_ga(explore_param,10,reduced_tests,free_params=free_params,hc = hc, NSGA = False, MU = MU, seed_pop = DO.seed_pop)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "attrs_here = npcl['hardened'][0][0].attrs\n", "attrs_here.update(hc)\n", "attrs_here\n", "scores = npcl['hof'][0].dtc.scores\n", "print(scores)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#\n", "use_test = test_frame[\"Neocortex pyramidal cell layer 5-6\"]\n", "reduced_tests = [use_test[0], use_test[-1], use_test[len(use_test)-1]]\n", "bigger_tests = use_test[1:-2]\n", "bigger_tests.insert(0,use_test[0])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#bigger_tests = bigger_tests[-1::]\n", "print(bigger_tests)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "DO.seed_pop = npcl['hof'][0:MU]\n", "reduced_tests = [use_test[0], use_test[-1], use_test[len(use_test)-1]]\n", "npcl, DO = om.run_ga(explore_param,10,bigger_tests,free_params=free_params,hc = hc, NSGA = False, MU = MU)#, seed_pop = DO.seed_pop)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(npcl['hardened'][0][0].attrs)\n", "print(npcl['hardened'][0][0].scores)\n", "print(npcl['pf'][0].fitness.values)\n", "print(npcl['hof'][0].dtc.scores)\n", "\n", "#for t in use_test:\n", "# print(t.name)\n", " \n", " \n", "pop" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# From the scores printed above, it looks like certain error criteria, are in conflict with each other.\n", "\n", "Tests, that are amenable to co-optimization appear to be:\n", "* Width test\n", "* Input resistance tets\n", "* Resting Potential Test,\n", "* Capicitance test.\n", "* Time constant\n", "\n", "Tests/criteria that seem in compatible with the above include: \n", "* Rheobase, \n", "* InjectedCurrentAPThresholdTest\n", "* InjectedCurrentAPAmplitudeTest\n", "\n", "Therefore a reduced set of lists is made to check if the bottom three are at least amenable to optimization togethor." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from sklearn.cluster import KMeans\n", "est = KMeans(n_clusters=2)\n", "est.fit(X)\n", "y_kmeans = est.predict(X)\n", "\n", "centers = est.cluster_centers_\n", "\n", "fig = plt.figure(fignum,figsize=(4,3))\n", "ax = Axes3D(fig,rect=[0,0,.95,1],elav=48,azim=134)\n", "ax.scatter(X[:,0],X[:,1],X[:,2],c=y_kmeans,s=50),\n", "ax.scatter(centres[:,0],centres[:,1],centres[:,2],c='black',s=200,alpha=0.5)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", "print(reduced_tests)\n", "print(bigger_tests)\n", "\n", "DO.seed_pop = npcl['pf'][0:MU]\n", "npcl, DO = om.run_ga(explore_param,10,reduced_tests,free_params=free_params,hc = hc, NSGA = True, MU = 12)#, seed_pop = DO.seed_pop)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pickle\n", "import copy\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "#from neuronunit.optimization.optimization_management import wave_measure\n", "from neuronunit.models.reduced import ReducedModel\n", "from neuronunit.optimization.model_parameters import model_params, path_params\n", "LEMS_MODEL_PATH = path_params['model_path']\n", "import neuronunit.optimization as opt\n", "import quantities as pq\n", "fig = plt.figure()\n", "\n", "plt.clf()\n", "\n", "from neuronunit.optimization.data_transport_container import DataTC\n", "model = ReducedModel(LEMS_MODEL_PATH,name = str('vanilla'),backend = ('RAW'))\n", "for i in npcl['pf'][0:2]:\n", " iparams = {}\n", " iparams['injected_square_current'] = {}\n", " iparams['injected_square_current']['amplitude'] =i.dtc.rheobase\n", " model = None\n", " model = ReducedModel(LEMS_MODEL_PATH,name = str('vanilla'),backend = ('RAW'))\n", " model.set_attrs(i.dtc.attrs)\n", "\n", " #['amplitude'] = dtc.vtest[k]['injected_square_current']['amplitude']\n", " DELAY = 100.0*pq.ms\n", " DURATION = 1000.0*pq.ms\n", " iparams['injected_square_current']['delay'] = DELAY\n", " iparams['injected_square_current']['duration'] = int(DURATION)\n", " model.inject_square_current(iparams)\n", " n_spikes = len(model.get_spike_train())\n", " if n_spikes:\n", " print(n_spikes)\n", " #print(i[0].scores['RheobaseTestP']*pq.pA)\n", " plt.plot(model.get_membrane_potential().times,model.get_membrane_potential())#,label='ground truth')\n", " plt.legend()\n", "\n", "#gca().set_axis_off()\n", "#subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, \n", "# hspace = 0, wspace = 0)\n", "#margins(0,0)\n", "#gca().xaxis.set_major_locator(NullLocator())\n", "#gca().yaxis.set_major_locator(NullLocator())\n", "\n", "plt.subplots_adjust(left=0.0, right=1.0, top=0.9, bottom=0.1)\n", "fig.tight_layout()\n", "plt.show()\n", "\n", "fig.savefig(\"single_trace.png\", bbox_inches = 'tight',\n", " pad_inches = 0)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pickle\n", "import copy\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot\n", "\n", "\n", "from neuronunit.models.reduced import ReducedModel\n", "from neuronunit.optimization.model_parameters import model_params, path_params\n", "LEMS_MODEL_PATH = path_params['model_path']\n", "import neuronunit.optimization as opt\n", "import quantities as pq\n", "fig = plt.figure()\n", "\n", "plt.clf()\n", "\n", "from neuronunit.optimization.data_transport_container import DataTC\n", "for i in npcl['hardened']:\n", " iparams = {}\n", " iparams['injected_square_current'] = {}\n", " iparams['injected_square_current']['amplitude'] = i[0].rheobase\n", " model = None\n", " model = ReducedModel(LEMS_MODEL_PATH,name = str('vanilla'),backend = ('RAW'))\n", " model.set_attrs(i[0].attrs)\n", "\n", " #['amplitude'] = dtc.vtest[k]['injected_square_current']['amplitude']\n", " DELAY = 100.0*pq.ms\n", " DURATION = 1000.0*pq.ms\n", " iparams['injected_square_current']['delay'] = DELAY\n", " iparams['injected_square_current']['duration'] = int(DURATION)\n", " model.inject_square_current(iparams)\n", " n_spikes = len(model.get_spike_train())\n", " if n_spikes:\n", " print(n_spikes)\n", " print(i[0].scores['RheobaseTestP']*pq.pA)\n", " plt.plot(model.get_membrane_potential().times,model.get_membrane_potential())#,label='ground truth')\n", " plt.legend()\n", "\n", "#gca().set_axis_off()\n", "#subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, \n", "# hspace = 0, wspace = 0)\n", "#margins(0,0)\n", "#gca().xaxis.set_major_locator(NullLocator())\n", "#gca().yaxis.set_major_locator(NullLocator())\n", "\n", "plt.subplots_adjust(left=0.0, right=1.0, top=0.9, bottom=0.1)\n", "fig.tight_layout()\n", "plt.show()\n", "\n", "fig.savefig(\"single_trace.png\", bbox_inches = 'tight',\n", " pad_inches = 0)\n", "\n", "\n", "'''\n", "hc = {}\n", "\n", "#free_params = ['c','k']\n", "for k,v in explore_param.items():\n", " if k not in free_params:\n", " hc[k] = v\n", "constants = npcl['hardened'][0][0].attrs\n", "hc.update(constants) \n", "npcl, _ = om.run_ga(explore_param,20,test_frame[\"Neocortex pyramidal cell layer 5-6\"],free_params=free_params,hc = hc, NSGA = True)\n", "'''" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", "free_params = ['a','b','k']#vt','c','k','d']#,'vt','k','c','C']#,'C'] # this can only be odd numbers.\n", "\n", "##\n", "# Use information that is available\n", "##\n", "hc = reduced_cells['RS']\n", "\n", "hc['vr'] = -65.2261863636364\n", "\n", "hc['vPeak'] = hc['vr'] + 86.364525297619\n", "hc['C'] = 89.7960714285714\n", "hc.pop('a',0)\n", "hc.pop('b',0)\n", "hc.pop('k',0)\n", "hc.pop('c',0)\n", "hc.pop('d',0)\n", " \n", "use_test = test_frame[\"Neocortex pyramidal cell layer 5-6\"]\n", "DO.seed_pop = npcl['pf']\n", "ga_out = DO.run(max_ngen = 15)\n", "'''\n", "hc = {}\n", "\n", "free_params = ['C']\n", "\n", "for k,v in explore_param.items():\n", " if k not in free_params:\n", " hc[k] = v\n", "#,'vt','k','c','C']#,'C'] # this can only be odd numbers\n", "constants = npcl['hardened'][0][0].attrs\n", "hc.update(constants) \n", "npcl, _ = om.run_ga(explore_param,20,test_frame[\"Neocortex pyramidal cell layer 5-6\"],free_params=free_params,hc = hc, NSGA = True)\n", "'''" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "'''\n", "import pandas\n", " \n", "try:\n", " ne_raw = pandas.read_csv('article_ephys_metadata_curated.csv', delimiter='\\t')\n", " !ls -ltr *.csv\n", "except:\n", " !wget https://neuroelectro.org/static/src/article_ephys_metadata_curated.csv\n", " ne_raw = pandas.read_csv('article_ephys_metadata_curated.csv', delimiter='\\t')\n", "\n", "blah = ne_raw[ne_raw['NeuronName'].str.match('Hippocampus CA1 pyramidal cell')]\n", "#ne_raw['NeuronName']\n", "#ne_raw['cell\\ capacitance']\n", "#blah = ne_raw[ne_raw['NeuronName'].str.match('Hippocampus CA1 pyramidal cell')]\n", "\n", "print([i for i in blah.columns])\n", "#rint(blah['rheobase'])\n", "#print(blah)\n", "#for i in ne_raw.columns:#['NeuronName']:\n", "# print(i)\n", "\n", "#ne_raw['NeuronName'][85]\n", "#blah = ne_raw[ne_raw['TableID'].str.match('85')]\n", "#ne_raw['n'] = 84\n", "#here = ne_raw[ne_raw['Index']==85]\n", "here = ne_raw[ne_raw['TableID']==18]\n", "\n", "print(here['rheo_raw'])\n", "#!wget https://neuroelectro.org/apica/1/n/\n", "'''" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ca1 = ne_raw[ne_raw['NeuronName'].str.match('Hippocampus CA1 pyramidal cell')]\n", "ca1['rheo']" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", " \n", "test_frame[\"Dentate gyrus basket cell\"][0].observation['std'] = test_frame[\"Dentate gyrus basket cell\"][0].observation['mean']\n", "for t in test_frame[\"Dentate gyrus basket cell\"]:\n", " print(t.name)\n", "\n", " print(t.observation)\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "'''\n", "Inibitory Neuron\n", "This can't pass the Rheobase test\n", "''' " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", "from neuronunit.optimization import optimization_management as om\n", "import pickle\n", "\n", "free_params = ['a','vr','b','vt','vPeak','c','k']\n", "for k,v in explore_param.items():\n", " if k not in free_params:\n", " hc[k] = v\n", "use_test = test_frame[\"Dentate gyrus basket cell\"]\n", "bcell, _ = om.run_ga(explore_param,20,use_test,free_params=free_params,hc = hc, NSGA = True, MU = 4)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\n", " \n", "#test_frame[\"Dentate gyrus basket cell\"][0].observation['std'] = test_frame[\"Dentate gyrus basket cell\"][0].observation['mean']\n", "for t in test_frame[\"Hippocampus CA1 pyramidal cell\"]:\n", " print(t.name)\n", "\n", " print(t.observation)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "use_test = test_frame[\"Hippocampus CA1 pyramidal cell\"]\n", "bcell, _ = om.run_ga(explore_param,20,use_test,free_params=free_params,hc = hc, NSGA = True, MU = 10)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pickle\n", "import copy\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "from neuronunit.models.reduced import ReducedModel\n", "from neuronunit.optimization.model_parameters import model_params, path_params\n", "LEMS_MODEL_PATH = path_params['model_path']\n", "import neuronunit.optimization as opt\n", "import quantities as pq\n", "fig = plt.figure()\n", "\n", "plt.clf()\n", "\n", "from neuronunit.optimization.data_transport_container import DataTC\n", "for i in bcell['hardened'][0:6]:\n", " iparams = {}\n", " iparams['injected_square_current'] = {}\n", " iparams['injected_square_current']['amplitude'] =i[0].rheobase\n", " model = None\n", " model = ReducedModel(LEMS_MODEL_PATH,name = str('vanilla'),backend = ('RAW'))\n", " model.set_attrs(i[0].attrs)\n", "\n", " #['amplitude'] = dtc.vtest[k]['injected_square_current']['amplitude']\n", " DELAY = 100.0*pq.ms\n", " DURATION = 1000.0*pq.ms\n", " iparams['injected_square_current']['delay'] = DELAY\n", " iparams['injected_square_current']['duration'] = int(DURATION)\n", " model.inject_square_current(iparams)\n", " n_spikes = len(model.get_spike_train())\n", " if n_spikes:\n", " print(n_spikes)\n", " print(i[0].scores['RheobaseTestP']*pq.pA)\n", " plt.plot(model.get_membrane_potential().times,model.get_membrane_potential())#,label='ground truth')\n", " plt.legend()\n", "\n", "#gca().set_axis_off()\n", "#subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, \n", "# hspace = 0, wspace = 0)\n", "#margins(0,0)\n", "#gca().xaxis.set_major_locator(NullLocator())\n", "#gca().yaxis.set_major_locator(NullLocator())\n", "\n", "plt.subplots_adjust(left=0.0, right=1.0, top=0.9, bottom=0.1)\n", "fig.tight_layout()\n", "plt.show()\n", "\n", "fig.savefig(\"single_trace.png\", bbox_inches = 'tight',\n", " pad_inches = 0)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "use_test = test_frame[\"Hippocampus CA1 pyramidal cell\"]\n", "bcell, _ = om.run_ga(explore_param,20,use_test,free_params=free_params,hc = hc, NSGA = True, MU = 10)\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.5.2" } }, "nbformat": 4, "nbformat_minor": 2 }