2

Monte Carlo Simulation

Imagine you’re trying to understand the behaviour of a group of dogs in a park, but there are too many dogs and too many things happening to watch every single dog at every moment! So, instead of trying to observe each dog in every situation, you decide to use Monte Carlo simulation to make sense of it all…

  1. Sampling (Observe Random Dogs)
  2. Estimate (Guess How Often a Dog Runs)
  3. Optimization (Find the Best Spot to Play Fetch)

Let’s imagine you’re wondering how often a dog in the park is running versus sitting. Rather than watching every dog all day long, you pick random dogs from the park and observe what they’re doing at different times. Each observation is like a random sample of the dog’s behaviour. By observing many dogs in different situations (just like random sampling), you can get a good idea of the overall behaviour of all the dogs in the park, despite not seeing every single one.

python 
import random
# Simulate the running times for a dog (in seconds)
def run_time():
    return random.uniform(5, 15)  # Each dog runs for a random time between 5 and 15 seconds
# Want access? Check Yun.Bun I/O

Now, let’s say you want to estimate the average time a dog spends running. You can’t measure this exactly for every dog, so instead, you observe a random sample of dogs, and each time you see one run, you note how long they run. You can then average the times for the dogs you’ve observed to estimate the average running time for all dogs in the park. The more dogs you observe, the more accurate your estimate becomes! This is like how Monte Carlo simulation can estimate things, like calculating integrals – the sums of random behaviours or outcomes.

python
import random
# Define the possible behaviours
behaviours = ['running', 'sitting']
# Function to simulate observing a dog
def observe_dog():
    # Want access? Check Yun.Bun I/O

Now, let’s imagine you’re on the lookout to find the best spot in the park to throw a ball where the dogs are most likely to catch. There are many spots in the park, and you don’t know which one is best. You could throw the ball in random spots multiple times and see which one the dogs tend to run to most often. The more random throws you make (Monte Carlo simulations), the more confident you become in knowing the optimal spot. This is like using Monte Carlo to optimize complex functions, where you’re trying to find the best outcome by exploring different random possibilities.

In short, Monte Carlo simulations help you deal with complex problems by randomly sampling behaviours or data points (like dogs’ actions) and using those samples to make good predictions or estimates about the whole group of dogs (or any complex system)!

Want to try out these examples? Visit https://shorturl.at/4hCor

2 responses to “2”

  1. Antonia O. Avatar
    Antonia O.

    Wow! Thanks for sharing.monte carlo simulations seems a game changer for dogs and their owners! An exciting piece of technology!

    Like

  2. Rose A. Avatar
    Rose A.

    Very smart. It’s important to put your pet in the safest of situations, and you just never know at a park. Best to assess as well as you can, with Monte Carlo, and do your best to put them in the right spot.

    Like

2 responses to “2”

  1. Antonia O. Avatar
    Antonia O.

    Wow! Thanks for sharing.monte carlo simulations seems a game changer for dogs and their owners! An exciting piece of technology!

    Like

  2. Rose A. Avatar
    Rose A.

    Very smart. It’s important to put your pet in the safest of situations, and you just never know at a park. Best to assess as well as you can, with Monte Carlo, and do your best to put them in the right spot.

    Like

Leave a comment