Download (right-click, save target as ...) this page as a jupyterlab notebook from: Lab14


Laboratory 14: Causality, Simulation, and Probability

LAST NAME, FIRST NAME

R00000000

ENGR 1330 Laboratory 14 - In-Lab


Python for Simulation

What is Russian roulette?

Russian roulette (Russian: русская рулетка, russkaya ruletka) is a lethal game of chance in which a player places a single round in a revolver, spins the cylinder, places the muzzle against their head, and pulls the trigger in hopes that the loaded chamber does not align with the primer percussion mechanism and the barrel, causing the weapon to discharge. Russian refers to the supposed country of origin, and roulette to the element of risk-taking and the spinning of the revolver's cylinder, which is reminiscent of a spinning roulette wheel.

A game of dafts, a game of chance
One where revolver's the one to dance
Rounds and rounds, it goes and spins
Makes you regret all those sins
\ A game of fools, one of lethality
With a one to six probability
There were two guys and a gun
With six chambers but only one...
\ CLICK, one pushed the gun
CLICK, one missed the fun
CLICK, "that awful sound" ...
BANG!, one had his brains all around!


Example: Simulate a game of Russian Roulette:


Example: Simulate the results of throwing a D6 (regular dice) for 10 times.


Example: Assume the following rules:

Define a function to simulate a game with the above rules, assuming a D6, and compute the net gain of the player over any given number of rolls.
Compute the net gain for 5, 50, and 500 rolls

Let's Make A Deal Game Show and Monty Hall Problem

The Monty Hall problem is a brain teaser, in the form of a probability puzzle, loosely based on the American television game show Let's Make a Deal and named after its original host, Monty Hall. The problem was originally posed (and solved) in a letter by Steve Selvin to the American Statistician in 1975 (Selvin 1975a), (Selvin 1975b).

"Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?"

From Wikipedia: https://en.wikipedia.org/wiki/Monty_Hall_problem

/data/img1.png)


Example: Simulate Monty Hall Game for 1000 times. Use a barplot and discuss whether players are better off sticking to their initial choice, or switching doors?

__According to the plot, it is statitically beneficial for the players to switch doors because the initial chance for being correct is only 1/3__

Python for Probability

Important Terminology:

Experiment: An occurrence with an uncertain outcome that we can observe.
For example, rolling a die.
Outcome: The result of an experiment; one particular state of the world. What Laplace calls a "case."
For example: 4.
Sample Space: The set of all possible outcomes for the experiment.
For example, {1, 2, 3, 4, 5, 6}.
Event: A subset of possible outcomes that together have some property we are interested in.
For example, the event "even die roll" is the set of outcomes {2, 4, 6}.
Probability: As Laplace said, the probability of an event with respect to a sample space is the number of favorable cases (outcomes from the sample space that are in the event) divided by the total number of cases in the sample space. (This assumes that all outcomes in the sample space are equally likely.) Since it is a ratio, probability will always be a number between 0 (representing an impossible event) and 1 (representing a certain event).
For example, the probability of an even die roll is 3/6 = 1/2.

From https://people.math.ethz.ch/~jteichma/probability.html


Example: In a game of Russian Roulette, the chance of surviving each round is 5/6 which is almost 83%. Using a for loop, compute probability of surviving


Example: What will be the probability of constantly throwing an even number with a D20 in


Example: What will be the probability of throwing at least one 6 with a D6:


Example: What is the probability of drawing an ace at least once (with replacement):


Example:

This problem is designed based on an example by Daniel Poston from DataCamp, accessible @ https://www.datacamp.com/community/tutorials/statistics-python-tutorial-probability-1


Example: Two unbiased dice are thrown once and the total score is observed. Define an appropriate function and use a simulation to find the estimated probability that :

This problem is designed based on an example by Elliott Saslow from Medium.com, accessible @ https://medium.com/future-vision/simulating-probability-events-in-python-5dd29e34e381


Example: An urn contains 10 white balls, 20 reds and 30 greens. We want to draw 5 balls with replacement. Use a simulation (10000 trials) to find the estimated probability that:

This problem is designed based on an example by Elliott Saslow from Medium.com, accessible @ https://medium.com/future-vision/simulating-probability-events-in-python-5dd29e34e381



Here are some of the resources used for creating this notebook:

Here are some great reads on this topic:

Here are some great videos on these topics:



Exercise: Risk or Probability

Are they the same? Are they different? Discuss your opinion.

Make sure to cite any resources that you may use.