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
6 changes: 3 additions & 3 deletions content/04_111_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@
" Simulates the service process for a call operator\n",
"\n",
" 1. request and wait for a call operator\n",
" 2. phone triage (triangular)\n",
" 2. phone triage (triangular distribution)\n",
" 3. exit system\n",
" \n",
" Params:\n",
" ------\n",
" \n",
" identifier: int \n",
" A unique identifer for this caller\n",
" A unique identifier for this caller\n",
" \n",
" operators: simpy.Resource\n",
" The pool of call operators that answer calls\n",
" These are shared across resources.\n",
" \n",
" env: simpy.Environment\n",
" The current environent the simulation is running in\n",
" The current environment the simulation is running in\n",
" We use this to pause and restart the process after a delay.\n",
"\n",
" service_rng: numpy.random.Generator\n",
Expand Down
6 changes: 3 additions & 3 deletions content/05_basic_results.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@
" Simulates the service process for a call operator\n",
"\n",
" 1. request and wait for a call operator\n",
" 2. phone triage (triangular)\n",
" 2. phone triage (triangular distribution)\n",
" 3. exit system\n",
" \n",
" Params:\n",
" ------\n",
" \n",
" identifier: int \n",
" A unique identifer for this caller\n",
" A unique identifier for this caller\n",
" \n",
" operators: simpy.Resource\n",
" The pool of call operators that answer calls\n",
" These are shared across resources.\n",
" \n",
" env: simpy.Environment\n",
" The current environent the simulation is running in\n",
" The current environment the simulation is running in\n",
" We use this to pause and restart the process after a delay.\n",
"\n",
" service_rng: numpy.random.Generator\n",
Expand Down
4 changes: 2 additions & 2 deletions content/06a_basic_results_exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@
" ------\n",
" \n",
" identifier: int \n",
" A unique identifer for this caller\n",
" A unique identifier for this caller\n",
" \n",
" operators: simpy.Resource\n",
" The pool of call operators that answer calls\n",
" These are shared across resources.\n",
" \n",
" env: simpy.Environment\n",
" The current environent the simulation is running in\n",
" The current environment the simulation is running in\n",
" We use this to pause and restart the process after a delay.\n",
" \n",
" '''\n",
Expand Down
4 changes: 2 additions & 2 deletions content/06b_basic_results_solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@
" ------\n",
" \n",
" identifier: int \n",
" A unique identifer for this caller\n",
" A unique identifier for this caller\n",
" \n",
" operators: simpy.Resource\n",
" The pool of call operators that answer calls\n",
" These are shared across resources.\n",
" \n",
" env: simpy.Environment\n",
" The current environent the simulation is running in\n",
" The current environment the simulation is running in\n",
" We use this to pause and restart the process after a delay.\n",
" \n",
" '''\n",
Expand Down
10 changes: 5 additions & 5 deletions content/07_experiments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"\n",
"All of these approaches work well and it really is a matter of judgement on what you prefer. One downside of a python `dict` and a custom class is that they are both mutable (although a class can have custom properties where users can only access 'viewable' attributes). A dataclass can easily be made immutable and requires less code than a custom class, but has the downside that its syntax is a little less pythonic. Here we will build a parameter class called `Experiment`. \n",
"\n",
"> ☺️ We will also use this re-organisation of code to elimiate our global variables!"
"> ☺️ We will also use this re-organisation of code to eliminate our global variables!"
]
},
{
Expand Down Expand Up @@ -75,7 +75,7 @@
"N_STREAMS = 2\n",
"DEFAULT_RND_SET = 0\n",
"\n",
"# Boolean switch to simulation results as the model runs\n",
"# Boolean switch to display simulation results as the model runs\n",
"TRACE = False\n",
"\n",
"# run variables\n",
Expand Down Expand Up @@ -217,7 +217,7 @@
" An Experiment:\n",
" 1. Contains a list of parameters that can be left as defaults or varied\n",
" 2. Provides a place for the experimentor to record results of a run \n",
" 3. Controls the set & streams of psuedo random numbers used in a run.\n",
" 3. Controls the set & streams of pseudo random numbers used in a run.\n",
" \n",
" \"\"\"\n",
"\n",
Expand Down Expand Up @@ -442,10 +442,10 @@
" ------\n",
"\n",
" identifier: int\n",
" A unique identifer for this caller\n",
" A unique identifier for this caller\n",
"\n",
" env: simpy.Environment\n",
" The current environent the simulation is running in\n",
" The current environment the simulation is running in\n",
" We use this to pause and restart the process after a delay.\n",
"\n",
" args: Experiment\n",
Expand Down
8 changes: 4 additions & 4 deletions content/08_full_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"DEFAULT_RND_SET = 0\n",
"# ##############################################################################\n",
"\n",
"# Boolean switch to simulation results as the model runs\n",
"# Boolean switch to display simulation results as the model runs\n",
"TRACE = False\n",
"\n",
"# run variables\n",
Expand Down Expand Up @@ -349,7 +349,7 @@
" An Experiment:\n",
" 1. Contains a list of parameters that can be left as defaults or varied\n",
" 2. Provides a place for the experimentor to record results of a run\n",
" 3. Controls the set & streams of psuedo random numbers used in a run.\n",
" 3. Controls the set & streams of pseudo random numbers used in a run.\n",
"\n",
" \"\"\"\n",
"\n",
Expand Down Expand Up @@ -566,10 +566,10 @@
" Params:\n",
" ------\n",
" identifier: int\n",
" A unique identifer for this caller\n",
" A unique identifier for this caller\n",
"\n",
" env: simpy.Environment\n",
" The current environent the simulation is running in\n",
" The current environment the simulation is running in\n",
" We use this to pause and restart the process after a delay.\n",
"\n",
" args: Experiment\n",
Expand Down
8 changes: 4 additions & 4 deletions content/09_time_weighted_calcs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"DEFAULT_RND_SET = 0\n",
"# ##############################################################################\n",
"\n",
"# Boolean switch to simulation results as the model runs\n",
"# Boolean switch to display simulation results as the model runs\n",
"TRACE = False\n",
"\n",
"# run variables\n",
Expand Down Expand Up @@ -423,7 +423,7 @@
" An Experiment:\n",
" 1. Contains a list of parameters that can be left as defaults or varied\n",
" 2. Provides a place for the experimentor to record results of a run\n",
" 3. Controls the set & streams of psuedo random numbers used in a run.\n",
" 3. Controls the set & streams of pseudo random numbers used in a run.\n",
"\n",
" \"\"\"\n",
"\n",
Expand Down Expand Up @@ -648,10 +648,10 @@
" Params:\n",
" ------\n",
" identifier: int\n",
" A unique identifer for this caller\n",
" A unique identifier for this caller\n",
"\n",
" env: simpy.Environment\n",
" The current environent the simulation is running in\n",
" The current environment the simulation is running in\n",
" We use this to pause and restart the process after a delay.\n",
"\n",
" args: Experiment\n",
Expand Down
10 changes: 5 additions & 5 deletions content/10_multiple_arrival_processes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"N_STREAMS = 4\n",
"DEFAULT_RND_SET = 0\n",
"\n",
"# Boolean switch to simulation results as the model runs\n",
"# Boolean switch to display simulation results as the model runs\n",
"TRACE = False\n",
"\n",
"# run variables (units = hours)\n",
Expand All @@ -79,7 +79,7 @@
"id": "5f2a4ad9-6d5e-480d-850f-84d4882a738b",
"metadata": {},
"source": [
"## 2. Helper classes and functions"
"## 3. Helper classes and functions"
]
},
{
Expand Down Expand Up @@ -153,7 +153,7 @@
"id": "5a8c050c-4bb6-408f-a805-3a4aaab56916",
"metadata": {},
"source": [
"## 3. Experiment class"
"## 4. Experiment class"
]
},
{
Expand Down Expand Up @@ -257,7 +257,7 @@
"id": "de8990c2-a330-4c02-ac77-26c30d3e0a41",
"metadata": {},
"source": [
"## 4. A function per arrival source\n",
"## 5. A function per arrival source\n",
"\n",
"The first approach we will use is creating an arrival generator per source. There will be some code redundancy, but it will a clear design for others to understand."
]
Expand Down Expand Up @@ -392,7 +392,7 @@
"id": "6058571e-9fdb-4961-be27-8a3b8c2fe26e",
"metadata": {},
"source": [
"## 5. Single run function"
"## 6. Single run function"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions content/11_blocking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"N_STREAMS = 3\n",
"DEFAULT_RND_SET = 0\n",
"\n",
"# Boolean switch to simulation results as the model runs\n",
"# Boolean switch to display simulation results as the model runs\n",
"TRACE = False\n",
"\n",
"# run variables (units = days)\n",
Expand All @@ -94,7 +94,7 @@
"id": "5f2a4ad9-6d5e-480d-850f-84d4882a738b",
"metadata": {},
"source": [
"## 2. Helper classes and functions"
"## 3. Helper classes and functions"
]
},
{
Expand Down Expand Up @@ -122,7 +122,7 @@
"id": "5a8c050c-4bb6-408f-a805-3a4aaab56916",
"metadata": {},
"source": [
"## 3. Experiment class"
"## 4. Experiment class"
]
},
{
Expand Down Expand Up @@ -229,7 +229,7 @@
"id": "94f0f9c5-22cb-493a-9f1f-4e2a8325beaa",
"metadata": {},
"source": [
"## 4. Pathway process logic\n",
"## 5. Pathway process logic\n",
"\n",
"The key things to recognise are \n",
"\n",
Expand Down Expand Up @@ -317,7 +317,7 @@
"id": "de8990c2-a330-4c02-ac77-26c30d3e0a41",
"metadata": {},
"source": [
"## 4. Arrivals generator\n",
"## 6. Arrivals generator\n",
"\n",
"This is a standard arrivals generator. We create stroke arrivals according to their distribution."
]
Expand Down Expand Up @@ -362,7 +362,7 @@
"id": "6058571e-9fdb-4961-be27-8a3b8c2fe26e",
"metadata": {},
"source": [
"## 5. Single run function"
"## 7. Single run function"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion content/12_arrival_classes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"N_STREAMS = 4\n",
"DEFAULT_RND_SET = 0\n",
"\n",
"# Boolean switch to simulation results as the model runs\n",
"# Boolean switch to display simulation results as the model runs\n",
"TRACE = False\n",
"\n",
"# run variables (units = minutes)\n",
Expand Down
2 changes: 1 addition & 1 deletion content/13_warm_up.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"N_STREAMS = 2\n",
"DEFAULT_RND_SET = 0\n",
"\n",
"# Boolean switch to simulation results as the model runs\n",
"# Boolean switch to display simulation results as the model runs\n",
"TRACE = False\n",
"\n",
"# run variables (units = days)\n",
Expand Down
2 changes: 1 addition & 1 deletion content/14_initial_conditions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"N_STREAMS = 3\n",
"DEFAULT_RND_SET = 0\n",
"\n",
"# Boolean switch to simulation results as the model runs\n",
"# Boolean switch to display simulation results as the model runs\n",
"TRACE = False\n",
"\n",
"# run variables (units = days)\n",
Expand Down
6 changes: 3 additions & 3 deletions content/basic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Experiment:
An Experiment:
1. Contains a list of parameters that can be left as defaults or varied
2. Provides a place for the experimentor to record results of a run
3. Controls the set & streams of psuedo random numbers used in a run.
3. Controls the set & streams of pseudo random numbers used in a run.
"""

def __init__(
Expand Down Expand Up @@ -261,10 +261,10 @@ def service(identifier, env, args):
Params:
------
identifier: int
A unique identifer for this caller
A unique identifier for this caller

env: simpy.Environment
The current environent the simulation is running in
The current environment the simulation is running in
We use this to pause and restart the process after a delay.

args: Experiment
Expand Down
46 changes: 1 addition & 45 deletions content/distributions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Distribution and utility classes avilable to these examples.
Distribution and utility classes available to these examples.
"""

import numpy as np
Expand Down Expand Up @@ -142,50 +142,6 @@ def sample(self, size=None):
"""
return self.rand.exponential(self.mean, size=size)


class Bernoulli:
"""
Convenience class for the Bernoulli distribution.
packages up distribution parameters, seed and random generator.

The Bernoulli distribution is a special case of the binomial distribution
where a single trial is conducted

Use the Bernoulli distribution to sample success or failure.
"""

def __init__(self, p, random_seed=None):
"""
Constructor

Params:
------
p: float
probability of drawing a 1

random_seed: int | SeedSequence, optional (default=None)
A random seed to reproduce samples. If set to none then a unique
sample is created.
"""
self.rand = np.random.default_rng(seed=random_seed)
self.p = p

def sample(self, size=None):
"""
Generate a sample from the exponential distribution

Params:
-------
size: int, optional (default=None)
the number of samples to return. If size=None then a single
sample is returned.

Returns:
-------
float or np.ndarray (if size >=1)
"""
return self.rand.binomial(n=1, p=self.p, size=size)

class DiscreteEmpirical:
"""
DiscreteEmpirical distribution implementation.
Expand Down