Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ simulations
izhikevich15jun19
MATLAB/results/*.dat
NeuroML2/results/*.dat
*.npy
25,145 changes: 25,145 additions & 0 deletions AIBS.ipynb

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions NeuroML2/LEMS_2007One.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<Include file="Simulation.xml"/>


<izhikevich2007Cell id="RS" v0 = "-60mV" C="100 pF" k = "0.7 nS_per_mV"
vr = "-60 mV" vt = "-40 mV" vpeak = "35 mV"
a = "0.03 per_ms" b = "-2 nS" c = "-50 mV" d = "100 pA"/>
<izhikevich2007Cell id="RS" v0="-60 mV" C="100 pF" k="0.7 nS_per_mV"
vr="-60 mV" vt="-40 mV" vpeak="35 mV"
a="0.03 per_ms" b="-2 nS" c="-50 mV" d="100 pA"/>

<pulseGenerator id="RS_Iext" delay="0ms" duration="520ms" amplitude="100 pA"/>
<pulseGenerator id="RS_Iext" delay="500ms" duration="1000ms" amplitude="100.0 pA"/>


<network id="net1">
Expand All @@ -26,22 +26,22 @@
<!-- End of NeuroML2 content -->


<Simulation id="sim1" length="520ms" step="0.0025ms" target="net1">
<Simulation id="sim1" length="1600ms" step="0.0025ms" target="net1">


<Display id="d1" title="RS v" timeScale="1ms" xmin="-50" xmax="570" ymin="-80" ymax="50">
<Line id ="RS v" quantity="RS_pop[0]/v" scale="1mV" color="#0000ff" timeScale="1ms"/>
<Display id="d1" title="RS v" timeScale="1ms" xmin="-50" xmax="1650" ymin="-80" ymax="50">
<Line id="RS v" quantity="RS_pop[0]/v" scale="1mV" color="#0000ff" timeScale="1ms"/>
</Display>
<Display id="d2" title="RS u" timeScale="1ms" xmin="-50" xmax="570" ymin="-80" ymax="80">
<Line id ="RS u" quantity="RS_pop[0]/u" scale="1pA" color="#ff0000" timeScale="1ms"/>
<Display id="d2" title="RS u" timeScale="1ms" xmin="-50" xmax="1650" ymin="-80" ymax="80">
<Line id="RS u" quantity="RS_pop[0]/u" scale="1pA" color="#ff0000" timeScale="1ms"/>
</Display>


<OutputFile id="of0" fileName="results/RS_One.dat">
<OutputColumn id="v" quantity="RS_pop[0]/v" />
<OutputColumn id="u" quantity="RS_pop[0]/u" />
<OutputFile id="of0" fileName="RS_One.dat">
<OutputColumn id="v" quantity="RS_pop[0]/v"/>
<OutputColumn id="u" quantity="RS_pop[0]/u"/>
</OutputFile>

</Simulation>

</Lems>
</Lems>
2 changes: 1 addition & 1 deletion NeuroML2/WhichModel.nml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<neuroml xmlns="http://www.neuroml.org/schema/neuroml2"
<neuroml xmlns:prefix="http://www.neuroml.org/schema/neuroml2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 http://neuroml.svn.sourceforge.net/viewvc/neuroml/NeuroML2/Schemas/NeuroML2/NeuroML_v2alpha.xsd"
id="WhichModel">
Expand Down
300 changes: 300 additions & 0 deletions Optimize.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib notebook\n",
"import os,sys\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import quantities as pq\n",
"import sciunit\n",
"import neuronunit\n",
"from neuronunit import aibs\n",
"from neuronunit.models.reduced import ReducedModel"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# This example is from https://github.com/OpenSourceBrain/IzhikevichModel.\n",
"IZHIKEVICH_PATH = '/home/mnt/osb/IzhikevichModel' # Replace this the path to your \n",
" # working copy of \n",
" # github.com/OpenSourceBrain/IzhikevichModel. \n",
"LEMS_MODEL_PATH = os.path.join(IZHIKEVICH_PATH,'NeuroML2/LEMS_2007One.xml')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:allensdk.api.api:Downloading URL: http://api.brain-map.org/api/v2/data/query.json?q=model::Specimen,rma::criteria,[id$eq'354190013'],rma::include,structure,donor(transgenic_lines),specimen_tags,cell_soma_locations,ephys_features,data_sets,neuron_reconstructions,cell_reporter,rma::options[num_rows$eq'all']\n",
"INFO:allensdk.api.api:Downloading URL: http://api.brain-map.org/api/v2/data/query.json?q=model::EphysSweep,rma::criteria,[specimen_id$eq354190013],rma::options[num_rows$eq'all']\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Getting data values from neuroelectro.org\n",
"http://www.neuroelectro.org/api/1/nes/?e__name=Input+Resistance&nlex=nifext_50\n",
"Getting data values from neuroelectro.org\n",
"http://www.neuroelectro.org/api/1/nes/?e__name=Membrane+Time+Constant&nlex=nifext_50\n",
"Getting data values from neuroelectro.org\n",
"http://www.neuroelectro.org/api/1/nes/?e__name=Cell+Capacitance&nlex=nifext_50\n",
"Getting data values from neuroelectro.org\n",
"http://www.neuroelectro.org/api/1/nes/?e__name=Resting+membrane+potential&nlex=nifext_50\n",
"Getting data values from neuroelectro.org\n",
"http://www.neuroelectro.org/api/1/nes/?e__name=Spike+Half-Width&nlex=nifext_50\n",
"Getting data values from neuroelectro.org\n",
"http://www.neuroelectro.org/api/1/nes/?e__name=Spike+Amplitude&nlex=nifext_50\n",
"Getting data values from neuroelectro.org\n",
"http://www.neuroelectro.org/api/1/nes/?e__name=Spike+Threshold&nlex=nifext_50\n"
]
}
],
"source": [
"import quantities as pq\n",
"from neuronunit import tests as nu_tests, neuroelectro\n",
"neuron = {'nlex_id': 'nifext_50'} # Layer V pyramidal cell\n",
"tests = []\n",
"\n",
"dataset_id = 354190013 # Internal ID that AIBS uses for a particular Scnn1a-Tg2-Cre \n",
" # Primary visual area, layer 5 neuron.\n",
"observation = aibs.get_observation(dataset_id,'rheobase')\n",
"tests += [nu_tests.RheobaseTest(observation=observation)]\n",
" \n",
"test_class_params = [(nu_tests.InputResistanceTest,None),\n",
" (nu_tests.TimeConstantTest,None),\n",
" (nu_tests.CapacitanceTest,None),\n",
" (nu_tests.RestingPotentialTest,None),\n",
" (nu_tests.InjectedCurrentAPWidthTest,None),\n",
" (nu_tests.InjectedCurrentAPAmplitudeTest,None),\n",
" (nu_tests.InjectedCurrentAPThresholdTest,None)]\n",
"\n",
"for cls,params in test_class_params:\n",
" observation = cls.neuroelectro_summary_observation(neuron)\n",
" tests += [cls(observation,params=params)]\n",
" \n",
"def update_amplitude(test,tests,score):\n",
" rheobase = score.prediction['value']\n",
" for i in [5,6,7]:\n",
" print(tests[i])\n",
" # Set current injection to just suprathreshold\n",
" tests[i].params['injected_square_current']['amplitude'] = rheobase*1.01 \n",
" \n",
"hooks = {tests[0]:{'f':update_amplitude}}\n",
"suite = sciunit.TestSuite(\"vm_suite\",tests,hooks=hooks)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"model = ReducedModel(LEMS_MODEL_PATH,name='vanilla')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"SUO = '/home/mnt/scidash/sciunitopt'\n",
"if SUO not in sys.path:\n",
" sys.path.append(SUO)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from types import MethodType\n",
"def optimize(self,model,rov):\n",
" best_params = None\n",
" best_score = None\n",
" from deap_config_simple_sum import deap_capsule\n",
" dc=deap_capsule()\n",
" pop_size=12\n",
" ngen=5 \n",
" pop = dc.sciunit_optimize(self,LEMS_MODEL_PATH,pop_size,ngen,rov,\n",
" NDIM=2,OBJ_SIZE=2)\n",
" return pop#(best_params, best_score, model)\n",
"\n",
"my_test = tests[0]\n",
"my_test.verbose = False\n",
"my_test.optimize = MethodType(optimize, my_test) # Bind to the score."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Start of evolution\n",
"V_rest = -91.9; SortKey = 0.505\n",
"V_rest = -54.2; SortKey = 0.230\n",
"V_rest = -70.3; SortKey = 0.998\n",
"V_rest = -60.9; SortKey = 0.600\n",
"V_rest = -94.4; SortKey = 0.453\n",
"V_rest = -49.9; SortKey = 0.000\n",
"V_rest = -54.3; SortKey = 0.230\n",
"V_rest = -73.3; SortKey = 0.911\n",
"V_rest = -86.3; SortKey = 0.600\n",
"V_rest = -45.9; SortKey = 0.000\n",
"V_rest = -98.5; SortKey = 0.386\n",
"V_rest = -43.7; SortKey = 0.000\n",
"Evaluated individuals 12\n",
"-- Generation 0 --\n",
"V_rest = -60.9; SortKey = 0.600\n",
"V_rest = -60.9; SortKey = 0.600\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -73.3; SortKey = 0.911\n",
"V_rest = -91.9; SortKey = 0.505\n",
"V_rest = -86.8; SortKey = 0.600\n",
"V_rest = -69.7; SortKey = 0.966\n",
"V_rest = -94.4; SortKey = 0.453\n",
"V_rest = -49.9; SortKey = 0.000\n",
"V_rest = -86.3; SortKey = 0.600\n",
"V_rest = -60.9; SortKey = 0.600\n",
" Evaluated 11 individuals\n",
"-- Generation 1 --\n",
"V_rest = -73.3; SortKey = 0.911\n",
"V_rest = -60.9; SortKey = 0.600\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -69.7; SortKey = 0.966\n",
"V_rest = -91.6; SortKey = 0.505\n",
"V_rest = -70.9; SortKey = 0.998\n",
"V_rest = -69.7; SortKey = 0.966\n",
"V_rest = -60.9; SortKey = 0.600\n",
"V_rest = -69.4; SortKey = 0.966\n",
"V_rest = -94.7; SortKey = 0.453\n",
"V_rest = -73.2; SortKey = 0.911\n",
"V_rest = -70.7; SortKey = 0.998\n",
" Evaluated 12 individuals\n",
"-- Generation 2 --\n",
"V_rest = -69.4; SortKey = 0.966\n",
"V_rest = -69.7; SortKey = 0.966\n",
"V_rest = -70.9; SortKey = 0.998\n",
"V_rest = -70.7; SortKey = 0.998\n",
"V_rest = -74.3; SortKey = 0.883\n",
"V_rest = -73.3; SortKey = 0.911\n",
"V_rest = -60.9; SortKey = 0.600\n",
"V_rest = -70.7; SortKey = 0.998\n",
"V_rest = -69.4; SortKey = 0.966\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -63.8; SortKey = 0.741\n",
" Evaluated 11 individuals\n",
"-- Generation 3 --\n",
"V_rest = -61.7; SortKey = 0.651\n",
"V_rest = -69.5; SortKey = 0.966\n",
"V_rest = -69.4; SortKey = 0.966\n",
"V_rest = -70.9; SortKey = 0.998\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -69.8; SortKey = 0.966\n",
"V_rest = -69.7; SortKey = 0.966\n",
"V_rest = -70.6; SortKey = 0.998\n",
" Evaluated 8 individuals\n",
"-- Generation 4 --\n",
"V_rest = -70.9; SortKey = 0.998\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -70.9; SortKey = 0.998\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -69.8; SortKey = 0.966\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -70.6; SortKey = 0.998\n",
"V_rest = -70.9; SortKey = 0.998\n",
"V_rest = -70.7; SortKey = 0.998\n",
"V_rest = -70.9; SortKey = 0.998\n",
"V_rest = -70.6; SortKey = 0.998\n",
" Evaluated 12 individuals\n",
"gen\tevals\tstd \tmin \tavg \tmax \n",
"4 \t12 \t[ 0.0090403]\t[-0.99830022]\t[-0.99557446]\t[-0.96559118]\n"
]
}
],
"source": [
"rov = np.linspace(-100,-40,1000)\n",
"pop = my_test.optimize(model,rov)\n",
"#print('pareto front top value in pf hall of fame')\n",
"#print('best params',best_params,'best_score',best_score, 'model',model)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-70.63 mV\n"
]
}
],
"source": [
"print(\"%.2f mV\" % np.mean([p[0] for p in pop]))"
]
}
],
"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": 1
}
Loading