Skip to content
Merged
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
159 changes: 122 additions & 37 deletions content/02_model_code/04_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -492,22 +492,110 @@
" \n",
" Passed to a model and its process classes\n",
" '''\n",
" def __init__(self, random_number_set=DEFAULT_RNG_SET):\n",
" def __init__(self, random_number_set=DEFAULT_RNG_SET,\n",
" n_triage=DEFAULT_N_TRIAGE,\n",
" n_reg=DEFAULT_N_REG,\n",
" n_exam=DEFAULT_N_EXAM,\n",
" n_trauma=DEFAULT_N_TRAUMA,\n",
" n_cubicles_1=DEFAULT_N_CUBICLES_1,\n",
" n_cubicles_2=DEFAULT_N_CUBICLES_2,\n",
" triage_mean=DEFAULT_TRIAGE_MEAN,\n",
" reg_mean=DEFAULT_REG_MEAN,\n",
" reg_var=DEFAULT_REG_VAR,\n",
" exam_mean=DEFAULT_EXAM_MEAN,\n",
" exam_var=DEFAULT_EXAM_VAR,\n",
" trauma_mean=DEFAULT_TRAUMA_MEAN,\n",
" trauma_treat_mean=DEFAULT_TRAUMA_TREAT_MEAN,\n",
" trauma_treat_var=DEFAULT_TRAUMA_TREAT_VAR,\n",
" non_trauma_treat_mean=DEFAULT_NON_TRAUMA_TREAT_MEAN,\n",
" non_trauma_treat_var=DEFAULT_NON_TRAUMA_TREAT_VAR,\n",
" non_trauma_treat_p=DEFAULT_NON_TRAUMA_TREAT_P,\n",
" prob_trauma=DEFAULT_PROB_TRAUMA):\n",
" '''\n",
" The init method sets up our defaults.\n",
" Create a scenario to parameterise the simulation model\n",
" \n",
" Parameters:\n",
" -----------\n",
" random_number_set: int, optional (default=DEFAULT_RNG_SET)\n",
" Set to control the initial seeds of each stream of pseudo\n",
" random numbers used in the model.\n",
" \n",
" n_triage: int\n",
" The number of triage cubicles\n",
" \n",
" n_reg: int\n",
" The number of registration clerks\n",
" \n",
" n_exam: int\n",
" The number of examination rooms\n",
" \n",
" n_trauma: int\n",
" The number of trauma bays for stablisation\n",
" \n",
" n_cubicles_1: int\n",
" The number of non-trauma treatment cubicles\n",
" \n",
" n_cubicles_2: int\n",
" The number of trauma treatment cubicles\n",
" \n",
" triage_mean: float\n",
" Mean duration of the triage distribution (Exponential)\n",
" \n",
" reg_mean: float\n",
" Mean duration of the registration distribution (Lognormal)\n",
" \n",
" reg_var: float\n",
" Variance of the registration distribution (Lognormal)\n",
" \n",
" exam_mean: float\n",
" Mean of the examination distribution (Normal)\n",
" \n",
" exam_var: float\n",
" Variance of the examination distribution (Normal)\n",
" \n",
" trauma_mean: float\n",
" Mean of the trauma stabilisation distribution (Exponential)\n",
" \n",
" trauma_treat_mean: float\n",
" Mean of the trauma cubicle treatment distribution (Lognormal)\n",
" \n",
" trauma_treat_var: float\n",
" Variance of the trauma cubicle treatment distribution (Lognormal)\n",
" \n",
" non_trauma_treat_mean: float\n",
" Mean of the non trauma treatment distribution\n",
" \n",
" non_trauma_treat_var: float\n",
" Variance of the non trauma treatment distribution\n",
" \n",
" non_trauma_treat_p: float\n",
" Probability non trauma patient requires treatment\n",
" \n",
" prob_trauma: float\n",
" probability that a new arrival is a trauma patient.\n",
" '''\n",
" # sampling\n",
" self.random_number_set = random_number_set\n",
" \n",
" # store parameters for sampling\n",
" self.triage_mean = triage_mean\n",
" self.reg_mean = reg_mean\n",
" self.reg_var = reg_var\n",
" self.exam_mean= exam_mean\n",
" self.exam_var = exam_var\n",
" self.trauma_mean = trauma_mean\n",
" self.trauma_treat_mean = trauma_treat_mean\n",
" self.trauma_treat_var = trauma_treat_var\n",
" self.non_trauma_treat_mean = non_trauma_treat_mean\n",
" self.non_trauma_treat_var = non_trauma_treat_var\n",
" self.non_trauma_treat_p = non_trauma_treat_p\n",
" self.prob_trauma = prob_trauma\n",
" \n",
" self.init_sampling()\n",
" \n",
" # count of each type of resource\n",
" self.init_resourse_counts()\n",
" self.init_resourse_counts(n_triage, n_reg, n_exam, n_trauma,\n",
" n_cubicles_1, n_cubicles_2)\n",
" \n",
" def set_random_no_set(self, random_number_set):\n",
" '''\n",
Expand All @@ -521,18 +609,19 @@
" self.random_number_set = random_number_set\n",
" self.init_sampling()\n",
"\n",
" def init_resourse_counts(self):\n",
" def init_resourse_counts(self, n_triage, n_reg, n_exam, n_trauma,\n",
" n_cubicles_1, n_cubicles_2):\n",
" '''\n",
" Init the counts of resources to default values...\n",
" '''\n",
" self.n_triage = DEFAULT_N_TRIAGE\n",
" self.n_reg = DEFAULT_N_REG\n",
" self.n_exam = DEFAULT_N_EXAM\n",
" self.n_trauma = DEFAULT_N_TRAUMA\n",
" self.n_triage = n_triage\n",
" self.n_reg = n_reg\n",
" self.n_exam = n_exam\n",
" self.n_trauma = n_trauma\n",
" \n",
" # non-trauma (1), trauma (2) treatment cubicles\n",
" self.n_cubicles_1 = DEFAULT_N_CUBICLES_1\n",
" self.n_cubicles_2 = DEFAULT_N_CUBICLES_2\n",
" self.n_cubicles_1 = n_cubicles_1\n",
" self.n_cubicles_2 = n_cubicles_2\n",
"\n",
" def init_sampling(self):\n",
" '''\n",
Expand All @@ -546,40 +635,40 @@
" # create distributions\n",
" \n",
" # Triage duration\n",
" self.triage_dist = Exponential(DEFAULT_TRIAGE_MEAN, \n",
" self.triage_dist = Exponential(self.triage_mean, \n",
" random_seed=self.seeds[0])\n",
" \n",
" # Registration duration (non-trauma only)\n",
" self.reg_dist = Lognormal(DEFAULT_REG_MEAN, \n",
" np.sqrt(DEFAULT_REG_VAR),\n",
" self.reg_dist = Lognormal(self.reg_mean, \n",
" np.sqrt(self.reg_var),\n",
" random_seed=self.seeds[1])\n",
" \n",
" # Evaluation (non-trauma only)\n",
" self.exam_dist = Normal(DEFAULT_EXAM_MEAN,\n",
" np.sqrt(DEFAULT_EXAM_VAR),\n",
" self.exam_dist = Normal(self.exam_mean,\n",
" np.sqrt(self.exam_var),\n",
" random_seed=self.seeds[2])\n",
" \n",
" # Trauma/stablisation duration (trauma only)\n",
" self.trauma_dist = Exponential(DEFAULT_TRAUMA_MEAN, \n",
" self.trauma_dist = Exponential(self.trauma_mean, \n",
" random_seed=self.seeds[3])\n",
" \n",
" # Non-trauma treatment\n",
" self.nt_treat_dist = Lognormal(DEFAULT_NON_TRAUMA_TREAT_MEAN, \n",
" np.sqrt(DEFAULT_NON_TRAUMA_TREAT_VAR),\n",
" self.nt_treat_dist = Lognormal(self.non_trauma_treat_mean, \n",
" np.sqrt(self.non_trauma_treat_var),\n",
" random_seed=self.seeds[4])\n",
" \n",
" # treatment of trauma patients\n",
" self.treat_dist = Lognormal(DEFAULT_TRAUMA_TREAT_MEAN, \n",
" np.sqrt(DEFAULT_TRAUMA_TREAT_VAR),\n",
" self.treat_dist = Lognormal(self.trauma_treat_mean, \n",
" np.sqrt(self.non_trauma_treat_var),\n",
" random_seed=self.seeds[5])\n",
" \n",
" # probability of non-trauma patient requiring treatment\n",
" self.nt_p_treat_dist = Bernoulli(DEFAULT_NON_TRAUMA_TREAT_P, \n",
" self.nt_p_treat_dist = Bernoulli(self.non_trauma_treat_p, \n",
" random_seed=self.seeds[6])\n",
" \n",
" \n",
" # probability of non-trauma versus trauma patient\n",
" self.p_trauma_dist = Bernoulli(DEFAULT_PROB_TRAUMA, \n",
" self.p_trauma_dist = Bernoulli(self.prob_trauma, \n",
" random_seed=self.seeds[7])\n",
" \n",
" # init sampling for non-stationary poisson process\n",
Expand Down Expand Up @@ -752,7 +841,7 @@
"metadata": {},
"outputs": [],
"source": [
"class NonTraumaPathway(object):\n",
"class NonTraumaPathway:\n",
" '''\n",
" Encapsulates the process a patient with minor injuries and illness.\n",
" \n",
Expand Down Expand Up @@ -1536,8 +1625,8 @@
"text": [
"Running multiple replications => done.\n",
"\n",
"CPU times: user 2.52 s, sys: 42.7 ms, total: 2.56 s\n",
"Wall time: 3.88 s\n"
"CPU times: user 2.09 s, sys: 12.9 ms, total: 2.11 s\n",
"Wall time: 3.46 s\n"
]
},
{
Expand Down Expand Up @@ -1821,20 +1910,16 @@
" scenarios['base'] = Scenario()\n",
" \n",
" # extra triage capacity\n",
" scenarios['triage+1'] = Scenario()\n",
" scenarios['triage+1'].n_triage += 1\n",
" scenarios['triage+1'] = Scenario(n_triage=DEFAULT_N_TRIAGE+1)\n",
" \n",
" # extra examination capacity\n",
" scenarios['exam+1'] = Scenario()\n",
" scenarios['exam+1'].n_exam += 1\n",
" scenarios['exam+1'] = Scenario(n_exam=DEFAULT_N_EXAM+1)\n",
" \n",
" # extra non-trauma treatment capacity\n",
" scenarios['treat+1'] = Scenario()\n",
" scenarios['treat+1'].n_cubicles_1 += 1\n",
" scenarios['treat+1'] = Scenario(n_cubicles_1=DEFAULT_N_CUBICLES_1+1)\n",
" \n",
" scenarios['triage+exam'] = Scenario()\n",
" scenarios['triage+exam'].n_triage += 1\n",
" scenarios['triage+exam'].n_exam += 1\n",
" scenarios['triage+exam'] = Scenario(n_triage=DEFAULT_N_TRIAGE+1,\n",
" n_exam=DEFAULT_N_EXAM+1)\n",
" \n",
" return scenarios"
]
Expand Down Expand Up @@ -2170,7 +2255,7 @@
},
{
"cell_type": "code",
"execution_count": 91,
"execution_count": 26,
"id": "4d2d0e59",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -2272,7 +2357,7 @@
"5 Trauma treatment 168.27 209.12 195.16 150.37 193.69"
]
},
"execution_count": 91,
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -2298,7 +2383,7 @@
},
{
"cell_type": "code",
"execution_count": 123,
"execution_count": 27,
"id": "e6453c53",
"metadata": {},
"outputs": [
Expand Down
10 changes: 5 additions & 5 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
matplotlib==3.3.4
numpy==1.19.2
pandas==1.2.3
scipy==1.6.1
simpy==4.0.1
matplotlib>=3.3.4
numpy>=1.19.2
pandas>=1.2.3
scipy>=1.6.1
simpy>=4.0.1
Empty file removed src/test_pacakge.ipynb
Empty file.
Loading