Created
May 9, 2016 17:03
-
-
Save mariusae/457d395597c77b4b68dc77bf39c3924f to your computer and use it in GitHub Desktop.
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": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import math" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"class boston:\n", | |
" K = 0.22\n", | |
" a1 = 0.02\n", | |
" a2 = 0.022\n", | |
" U0 = 1.\n", | |
" \n", | |
" @classmethod\n", | |
" def activity(cls, t):\n", | |
" #p(t) = K U0 (e−α1t − e−α2t).\n", | |
" # where U0 is the subcutaneous-drug impulse dose in units (U), K is a constant, in dl−1, associated with the amplitude\n", | |
" # of the impulse response of p(t), and α1 and α2 are positive constants in min−1 (or s−1, depending on t). The latter\n", | |
" # three constants can all be identified from values of the peak absorption time, the peak absorption concentration, and\n", | |
" # the overall time of action associated with the pharmacokinetics of insulin, which depends on the the type of insulin\n", | |
" # used.\n", | |
" return cls.K*cls.U0*(math.exp(-cls.a1*t) - math.exp(-cls.a2*t))\n", | |
"\n", | |
" \n", | |
" @classmethod\n", | |
" def activityRolling(cls, ts):\n", | |
" now = len(ts)\n", | |
" s = 0\n", | |
" for t in range(0, len(ts)):\n", | |
" s += ts[t]*cls.activity(now-t)\n", | |
" return s\n", | |
" \n", | |
" \n", | |
" @classmethod\n", | |
" def iob(cls, t):\n", | |
" return ((cls.K*cls.U0)/(cls.a1*cls.a2))*(cls.a2*math.exp(-cls.a1*t) - cls.a1*math.exp(-cls.a2*t))\n", | |
"\n", | |
"def printc(arr):\n", | |
" for a in arr:\n", | |
" print '\\t%s,' % a" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"r = range(0,240, 5)\n", | |
"\n", | |
"act = [boston.activity(t) for t in r]\n", | |
"iob = [boston.iob(t) for t in r]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\t0.0,\n", | |
"\t0.00198072220267,\n", | |
"\t0.00356663012541,\n", | |
"\t0.00481678719495,\n", | |
"\t0.00578239748955,\n", | |
"\t0.00650778685307,\n", | |
"\t0.00703126635251,\n", | |
"\t0.00738589180564,\n", | |
"\t0.00760013153584,\n", | |
"\t0.00769845311808,\n", | |
"\t0.00770183864414,\n", | |
"\t0.007628236939,\n", | |
"\t0.0074929601882,\n", | |
"\t0.00730903157386,\n", | |
"\t0.00708748975322,\n", | |
"\t0.00683765533609,\n", | |
"\t0.00656736391775,\n", | |
"\t0.00628316969227,\n", | |
"\t0.00599052320035,\n", | |
"\t0.00569392634914,\n", | |
"\t0.00539706747234,\n", | |
"\t0.00510293887253,\n", | |
"\t0.00481393899865,\n", | |
"\t0.00453196115612,\n", | |
"\t0.00425847042127,\n", | |
"\t0.00399457023178,\n", | |
"\t0.00374105994875,\n", | |
"\t0.00349848452972,\n", | |
"\t0.00326717731476,\n", | |
"\t0.00304729680581,\n", | |
"\t0.00283885821266,\n", | |
"\t0.00264176044389,\n", | |
"\t0.0024558091383,\n", | |
"\t0.00228073625832,\n", | |
"\t0.00211621670238,\n", | |
"\t0.00196188233647,\n", | |
"\t0.00181733379425,\n", | |
"\t0.00168215035183,\n", | |
"\t0.00155589814368,\n", | |
"\t0.00143813695266,\n", | |
"\t0.00132842577685,\n", | |
"\t0.00122632734971,\n", | |
"\t0.00113141176704,\n", | |
"\t0.00104325935394,\n", | |
"\t0.000961462887324,\n", | |
"\t0.000885629274022,\n", | |
"\t0.000815380770979,\n", | |
"\t0.000750355822145,\n" | |
] | |
} | |
], | |
"source": [ | |
"printc(act)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"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.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment