Created
July 18, 2016 07:20
-
-
Save quaquel/e738e170282a6226fcedae0d5878c10b to your computer and use it in GitHub Desktop.
api options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# current API updated to use parameters instead" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from ema_workbench.em_framework import (ModelEnsemble, RealParameter,\n", | |
" TimeSeriesOutcome)\n", | |
"from ema_workbench.util import ema_logging, save_results\n", | |
"from ema_workbench.connectors.vensim import VensimModelStructureInterface \n", | |
"\n", | |
"class FluModel(VensimModelStructureInterface):\n", | |
" #base case model\n", | |
" model_file = r'\\FLUvensimV1basecase.vpm'\n", | |
" \n", | |
" #outcomes\n", | |
" outcomes = [TimeSeriesOutcome('deceased population region 1'),\n", | |
" TimeSeriesOutcome('infected fraction R1')]\n", | |
" \n", | |
" #Plain Parametric Uncertainties \n", | |
" uncertainties = [\n", | |
" RealParameter(\"additional seasonal immune population fraction R1\", \n", | |
" 0, 0.5),\n", | |
" RealParameter(\"additional seasonal immune population fraction R2\",\n", | |
" 0, 0.5),\n", | |
" RealParameter(\"fatality ratio region 1\", 0.0001, 0.1),\n", | |
" RealParameter(\"fatality rate region 2\", 0.0001, 0.1),\n", | |
" RealParameter(\"initial immune fraction of the population of region 1\",\n", | |
" 0, 0.5),\n", | |
" RealParameter(\"initial immune fraction of the population of region 2\",\n", | |
" 0, 0.5),\n", | |
" RealParameter(\"normal interregional contact rate\", 0, 0.9),\n", | |
" RealParameter(\"permanent immune population fraction R1\", 0, 0.5),\n", | |
" RealParameter(\"permanent immune population fraction R2\", 0, 0.5),\n", | |
" RealParameter(\"recovery time region 1\", 0.1, 0.75),\n", | |
" RealParameter(\"recovery time region 2\", 0.1, 0.75),\n", | |
" RealParameter(\"susceptible to immune population delay time region 1\", \n", | |
" 0.5,2),\n", | |
" RealParameter(\"susceptible to immune population delay time region 2\",\n", | |
" 0.5,2),\n", | |
" RealParameter(\"root contact rate region 1\", 0.01, 5),\n", | |
" RealParameter(\"root contact ratio region 2\", 0.01, 5),\n", | |
" RealParameter(\"infection ratio region 1\", 0, 0.15),\n", | |
" RealParameter(\"infection rate region 2\", 0, 0.15),\n", | |
" RealParameter(\"normal contact rate region 1\", 10, 100),\n", | |
" RealParameter(\"normal contact rate region 2\", 10, 200)]\n", | |
"\n", | |
"if __name__ == \"__main__\":\n", | |
" ema_logging.log_to_stderr(ema_logging.INFO)\n", | |
" \n", | |
" model = FluModel(r'./models/flu', \"flucase\")\n", | |
" ensemble = ModelEnsemble()\n", | |
" ensemble.model_structure = model\n", | |
" \n", | |
" #turn on parallel processing\n", | |
" ensemble.parallel = True \n", | |
" \n", | |
" # run 1000 experiments\n", | |
" nr_runs = 1000\n", | |
" results = ensemble.perform_experiments(nr_runs)\n", | |
" \n", | |
" # save the results\n", | |
" save_results(results, r'./data/{} flu cases.tar.gz'.format(nr_runs))\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# alternative API proposal" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from ema_workbench.em_framework import (ModelEnsemble, RealParameter,\n", | |
" TimeSeriesOutcome)\n", | |
"from ema_workbench.util import ema_logging, save_results\n", | |
"from ema_workbench.connectors.vensim import VensimModelStructureInterface \n", | |
"\n", | |
"if __name__ == \"__main__\":\n", | |
"\n", | |
" ema_logging.log_to_stderr(ema_logging.INFO)\n", | |
" \n", | |
" # model specification\n", | |
" msi = VensimModelStructureInterface(\"flucase\", wd=r'./models/flu')\n", | |
" msi.model_file = r'\\FLUvensimV1basecase.vpm'\n", | |
" msi.outcomes = [TimeSeriesOutcome('deceased population region 1'),\n", | |
" TimeSeriesOutcome('infected fraction R1')]\n", | |
" msi.uncertainties = [\n", | |
" RealParameter(\"additional seasonal immune population fraction R1\", \n", | |
" 0, 0.5),\n", | |
" RealParameter(\"additional seasonal immune population fraction R2\",\n", | |
" 0, 0.5),\n", | |
" RealParameter(\"fatality ratio region 1\", 0.0001, 0.1),\n", | |
" RealParameter(\"fatality rate region 2\", 0.0001, 0.1),\n", | |
" RealParameter(\"initial immune fraction of the population of region 1\",\n", | |
" 0, 0.5),\n", | |
" RealParameter(\"initial immune fraction of the population of region 2\",\n", | |
" 0, 0.5),\n", | |
" RealParameter(\"normal interregional contact rate\", 0, 0.9),\n", | |
" RealParameter(\"permanent immune population fraction R1\", 0, 0.5),\n", | |
" RealParameter(\"permanent immune population fraction R2\", 0, 0.5),\n", | |
" RealParameter(\"recovery time region 1\", 0.1, 0.75),\n", | |
" RealParameter(\"recovery time region 2\", 0.1, 0.75),\n", | |
" RealParameter(\"susceptible to immune population delay time region 1\", \n", | |
" 0.5,2),\n", | |
" RealParameter(\"susceptible to immune population delay time region 2\",\n", | |
" 0.5,2),\n", | |
" RealParameter(\"root contact rate region 1\", 0.01, 5),\n", | |
" RealParameter(\"root contact ratio region 2\", 0.01, 5),\n", | |
" RealParameter(\"infection ratio region 1\", 0, 0.15),\n", | |
" RealParameter(\"infection rate region 2\", 0, 0.15),\n", | |
" RealParameter(\"normal contact rate region 1\", 10, 100),\n", | |
" RealParameter(\"normal contact rate region 2\", 10, 200)]\n", | |
"\n", | |
" # setup ensemble\n", | |
" ensemble = ModelEnsemble()\n", | |
" ensemble.model_structure = msi\n", | |
" \n", | |
" #turn on parallel processing\n", | |
" ensemble.parallel = True \n", | |
" \n", | |
" # run 1000 experiments\n", | |
" nr_runs = 1000\n", | |
" results = ensemble.perform_experiments(nr_runs)\n", | |
" \n", | |
" # save the results\n", | |
" save_results(results, r'./data/{} flu cases.tar.gz'.format(nr_runs))\n", | |
"\n" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"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" | |
}, | |
"toc": { | |
"toc_cell": false, | |
"toc_number_sections": true, | |
"toc_threshold": 6, | |
"toc_window_display": false | |
}, | |
"widgets": { | |
"state": {}, | |
"version": "1.1.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment