Art of Simulation, Latest News
Machine Learning in Simul8: An Illustrative example of Supervised Learning in a Healthcare Simulation for Beginners
Christoph Werner / May 24, 2022
We are so excited to have released Machine Learning last week, that’s why we wanted to share this helpful tutorial with you all! If you want to take your Machine Learning knowledge even further, remember we have our Simul8 bootcamp on ML coming up on the 22nd of June. You can sign up here!
Machine Learning (ML) is becoming an ever more important tool for simulation modelers – at Simul8, we see this often these days through the discussions we have with our users. ML can assist you to better understand how complex decisions are being made in the process you are simulating and implement these directly in your simulation. This is why, here at Simul8, we now provide you with a readily accessible, new feature that integrates any ML algorithm (of your choice) in your simulation for setting up your Routing and Timing logic – all powered by the popular, open-source programming languages of R and Python.
Consider the following: in some situations, it might be difficult and time-consuming to set up complex rules, either through labels or Visual Logic, to decide how long a certain activity takes or which route a work item should go to. Especially, when timing and routing depends on several other factors, such as multiple possible labels, the time of the day or the current state of a simulation object elsewhere in the process. Even further, these complexities and decisions might be unknown to you and anyone in your organization. This is when you can now use ML in Simul8 to support you to better understand how these decisions are being made and implement them.
We want to show you how ML can help you in a Simul8 model by elaborating on an illustrative example from the area of healthcare simulations.
In healthcare, a commonly simulated process is that of an emergency room (ER) department in a hospital. Here, patients often need to receive urgent attendance by qualified staff, such as a nurse or doctor, whereas the number of arrivals together with the exact condition of patients is uncertain. Therefore, a simulation can help you to make evidence-based decisions when it comes to staff planning, pathway modelling and resource optimization, for instance regarding available rooms and beds for treatment. Efficient planning based on a simulation ensures that patients receive the attention they need by the correct staff while considering the fact that you want to run your clinic in a cost-effective manner.
The below example shows a popular ER department simulation that we have used in the past. In fact, you have it as part of your Simul8 installation and can find it at File > Examples (when you open Simul8).
Here, patients arrive at the ER department, either as walk-in arrivals with varying Exponential inter-arrival times depending on the time of the day (the busiest period with most arrivals is between 4 and 8 pm), or through an emergency unit every 1.5 hours.
In this blog post, we want to focus on the walk-in arrivals. These are currently triaged based on a percentage split with 90% of patients being routed to the waiting room and 10% routed to a bed allocation.
The patients that are sent to the waiting room, go to sit down before being directed to an available cubicle. The 10% of patients, who get triaged for a bed, either get a free ER bed or will be admitted to a different ward. Once patients have been seen by a nurse or doctor, they get discharged or admitted to the nearby hospital.
To show you when ML can be helpful in the above simulation, we extend our standard ER example by implementing a common Supervised Learning algorithm for the triage decision. Suppose that the percentage split is only a highly simplified way of routing patients in the simulation. In fact, by now you have obtained data from 100 patients (note: in reality many more data entries are required for a robust ML outcome) together with the corresponding triage decisions. From your dataset you can see that all patients can be classified according to certain attributes that might be important for triaging. However, which attributes are the most relevant ones for the decision is not known to you. Luckily, classification problems are a standard application for ML algorithms. Therefore, we include a Decision Tree in our simulation to make the routing decision for any patient for whom it is unknown. It will learn from the dataset which attributes are important for the routing decision. This will also save us from having to introduce complicated Visual Logic statements with which we would probably try to approximate these rules in an alternative way.
A snapshot of the dataset is given below whereas the triage decision of waiting room (=1) and bed (=2) is shown in the last column.
While our data is fictional for illustrative purposes, some attributes that a patient might have, which are inspired by commonly used triage criteria, are the following:
- Age of the patient
- Consciousness (eye) with a score between 1-4: referring to ocular responses, ranging from 1 if a patient cannot open their eyes or 4 if they can open their eyes spontaneously (rather than solely in response to pain)
- Consciousness (verbal) with a score between 1-5: assessing whether or not patients can converse normally or seem confused or even cannot speak at all
- Consciousness (motor) with a score between 1-6: checking if patient can localize to painful stimuli or cannot move an injured part
- Blood pressure: whereas (for adults) a normal measurement is < 120 and measurements > 140 show signs of hypertension with increasing severity for higher values
- Blood loss: simply as 0 and 1 depending on whether or not blood loss occurs or not
- Respiratory rate: i.e., the rate at which breathing occurs, whereas for healthy adults at rest the rate should be around 12–16 breaths per minute
- Flesh wounds with a score of 0-5: referring to levels of severeness in increasing order while 0 means no flesh wound present
In addition to the above criteria, other possible influencing factors for the triage decision are the time of the day (as in current hour) and the number of nurses currently available.
When printing the Decision Tree, we obtain a visualization of the ML algorithm which for example looks as follows (this can differ depending on your split between training and test data and depending on how your seed numbers are set, so run the corresponding line in R first to see what to expect):
In this case, we can see that for the data in our simulation a patient’s consciousness (eye) is a first criterion for the triage decision. Patients with a score < 3 are likely to be given a bed if their respiratory rate is higher than 18. On the other branch, patients with high blood pressure (despite a consciousness (eye) >= 3) and blood loss are likely to be given a bed. Lastly, even without (fairly) high blood pressure, a flesh wound of score 4 and higher will likely send a patient to go to a bed.
In Simul8, we implement the above Decision Tree using the Routing Out dialog. As shown below, we now have an option to use ML for routing through the By ML option. See here for more information on how this new Routing Out option works.
Most attributes from our spreadsheet are set as a label in Simul8. That way we can easily include and generate new patient data. Additionally, the time of day uses the function HOUR[Simulation Time] and the number of nurses currently available is read from the object property Nurse.Current Available.
Lastly, we point to our R function (stored as .rds file) that contains the Decision Tree results, for which itself we use the “rpart” package. Get the corresponding files here. including a simplified version of the above triage situation that focuses specifically on the routing.
We hope this brief tutorial gave you a better idea of how you can use ML in your simulations and as always, please get in touch with us if you have any questions or an application for ML!