Click the image below to watch a video about how Monte Carlo methods can help save lives in search-and-rescue missions!!
Let's recall:
If you know a set velocity that an object is moving as it goes from one point to another, and you know the time it takes, how do you find the distance traveled?
We can rearrange it to say:
Assumptions help us frame the problems and set bounds and limits to what we are trying to accomplish.
Let's assume:
The velocity of the paddleboarder is 10 km/h (and it remains constant).
The direction of the wave current carrying the paddleboarder is from the South to the North only.
The time that we are interested is 1hr of drifting with the wave currents.
Where will the paddleboarder be after 1 hour?
How far away from the original location?
And will they be found north, south, east, or west of the original location?
We will return back to these questions and answers when it comes time to validate our code!
It would be wonderful if we always knew the velocity at every single second of a given situation, but that isn't always the case, such as in the padddleboarder search and rescue mission. This is where Monte Carlo calculations comes into play to simulate many, many possible estimations. Let's discuss how we will implement these theories.
1) Historical data can be used to set the credible maximum and minimum current velocities; and
2) Random numbers within these ranges can be used to estimate these variables that are unknown or changing (i.e. current speeds and directions in our case).
3) Large data samples can be calculated and examined to help ensure a higher accuracy of the results
KEY POINT: Although Monte Carlo methods involve random sampling (since we are using a random number generator), the results are not arbitrary. The outcomes represent expected possibilities based on random inputs within a reasonable range. We can then calculate the probabilities of each of these outcomes using our simulation! In this way, Monte Carlo methods allow us to quantify uncertainty and make predictions, even in situations with incomplete or uncertain information!
Step 1: Location
Create a value for the initial location.
latitude: 41.3
longitude: -70.8
Step 2: Randomized Current Speeds
Create a randomized number for a current_speed. ranging from0 to 20km/h (depending on weather conditions).
Step 3. Randomized Current Directions Create a randomized number for current_direction ranging from 0 to 360 degrees.
Note: The labels "Code 1" and "Code 2" will come into play in a future example and don't correspond to the steps! Steps 1 and 2 will be done within the "Code 1" block and Step 3 will be done within "Code 2" :)
Step 4. From your previous trinket steps, copy "Code 1" and paste at the appropriate location in this new Trinket Window.
Step 5. Do the same for "Code 2" which should be placed a little lower in the code.
(Be sure to pay attention to the correct indenting needed for Code 2).
You should see the location & drift.
If you zoom in, you should see points for 15 min, 30 min, and 1hr elapsed time.
Note: This trinket (seen below) will be used for Steps 4-9. Therefore, you will need to come back to this window as you progress through the problem.
Coding Assistance: Click this link to get the paddleboarder's route for 15 min, 30 min, and 1hr elapsed times.
Now that we have code that is working, how do we know we can trust it? How do we know the data and information is correct?
We must run some test cases to prove it is correct. This process is called code validation and it is an important part of the engineering process. This is basically setting initial conditions and parameters where you KNOW the exact outcome and checking that the resulting data is matching those values.
Validating Code for Constant Speed of 10 km/hr with a current to the north.
Current to the north.
In order to validate the code, let's set a few items to constant values and check the new location (how far it is displaced from the original location and in what direction).
Step 6a: First, let's set the direction of the wave currents to be only south to north.
What would the bearing angle be for the direction of these waves?
How do you use the min_bearing & max_bearing variables to make this a constant direction?
Where would you expect to find the paddleboarder? (North, South, East, or West of the original location)?
Step 6b. Second, let's set the wave current speed to a constant speed of 10 km/hr.
How far would the paddleboarder have drifted after an hour? Let's test it!
What should the current_speed_min & current_speed_max values to set to in order to keep a constant speed of 10km/hr?
Click on the map you produced to find the starting point coordinates and the final point coordinates.
Enter these values into the calculator to find the total distance traveled. Does it equal 10 km?
Validating Code for Constant Speed of 10 km/hr, current to the east.
Current to the east.
Step 6c: Third, test it for a different wave current direction (i.e. only east to west).
Once you have both cases (North only & East only currents}) working, you can increase the Monte Carlo runs to multiple iterations in the next section to get more estimated locations.
Running Multiple Monte Carlo Iterations
Step 7. Reset the min & max bearing angles and current speeds to variable values (non-constant values).
Step 8. Find the "nums_simulations" variable.
Change this to 5 iterations. Run the code and observe.
Step 9. Set the same variable "nums_simulations" to 100 iterations and re-run the code. Make some notes on your observations.