Towards Data Science

May 23, 2022

## Probability Simulations: Solve complex probability problems using randomness: Part 1

## A Quick Introduction

Simply defined, probability is the chance that a given event will occur. Or in technical terms, per merriam-webster , it is the ratio of the number of outcomes in an exhaustive set of equally likely outcomes that produce a given event to the total number of possible outcomes.

i.e. P(of an event) = (Number of favorable outcomes) / (Total possible outcomes)

A quick recap of the Bayes’ theorem

And if you want to do a more detailed recap of probability, please refer to this wiki link.

## Simulating Probabilities: Why?

- Gain deeper insights into the problem by actually performing the experiment/s virtually.
- Validate your calculated answer.
- Learning how to simulate simple to complex real life experiments and scenarios using code; e.g. modeling economic stability of a region, or modeling COVID spread in a country, etc.

## Simulating Probabilities: Design steps

- Design the experiment . This comes from the problem statement or a scenario you are trying to figure out the probability for.
- Repeat the experiment N number of times . The larger the N, the better are your estimated probability numbers. (law of large numbers)
- Calculate the ratio of favorable outcomes to the total possible outcomes to calculate the probability.

Please refer to these [ 4 ] and [ 5 ] links for more details.

Let’s see this process in action with an example.

- Let’s say you are trying to answer the question: What is the probability of getting 2 heads (H) when you flip two fair coins or flip a fair coin twice?
- Since getting a coin toss is independent of another coin toss or its own previous tosses, P(2H) = P(H) * P(H) = 0.5 * 0.5 = 0.25 = 1/4. You can also intuitively put it this way → the four possible outcomes of two tosses are {HH, HT, TH, TT}. Out of these 4, only 1 matches our expectations of two heads {HH}. So, the answer is 1/4.
- Let’s simulate this experiment and see what we find..

## The orignal problem

You are in a game show. The host shows you 3 doors and tells you that there is a car behind one door and goats behind the other two. ** The host knows exactly what is behind which door.

- He asks you to pick one door. Say you pick door 1.
- He then opens door 3, with a goat behind it. Note that the host is guaranteed to open a door with a goat behind it, because he knows.
- He then asks you whether you want to go ahead with your previous choice of door 1 or switch to door 2?

What should you do to maximize your chances of winning?

You can also use Bayes theorem to solve this as follows.

Let’s simulate this scenario and see if the outcome matches our calculated value.

You can see that as n_rounds increases, the simulated probability approaches the theoretical probabilities. That is, out of the 10,000 games played, you won almost 2/3rd of those games by switching. You can also increase the number of doors, and play the same game (where the host reveals a goat behind one of the other remaining doors). The probability for switching remains higher, but the difference between switching and not switching decreases and approaches 0 as the number of doors increases. See below. This is because the advantage for the other door(s) gets lower and lower as n_doors increases.( This will change if the host opens more than 1 door….feel free to play with this scenario and see what you get. )

## Variation where the host doesn’t know

The exact same game as above, but this time the host doesn’t know what is behind which door and he randomly chooses a door (excluding the one that you choose) to open. So he may accidentally open a door with a car behind it, in which case, the game either ends or is restarted or you automatically win.

- The host asks you to pick one door. Say you picked door 1.
- He then opens door 3, and finds a goat behind it.

As you can see, the simulation results match the calculations.

Hooray!! By now you must have got a gist of how to design a simulation for a probability problem.

## More from Towards Data Science

Your home for data science. A Medium publication sharing concepts, ideas and codes.

## Get the Medium app

## Pratha Pawar

## Learning Home

## Not Now! Will rate later

- Probability: Concepts & Tricks
- Probability Practice Questions: Level 01
- Probability Practice Questions: Level 02

## Most Popular Articles - PS

## Time and Work Concepts

## Time and Work Formula and Solved Problems

## Time and Work Problems (Easy)

## Time and Work Problems (Difficult)

## Problems on Ages Practice Problems : Level 02

## Chain Rule : Theory & Concepts

## Chain Rule Solved Examples

## Chain Rule Practice Problems: Level 01

## Chain Rule Practice Problems : Level 02

## Problems on Numbers System : Level 02

## Solved Problems of Simple and Compound Probability

What is probability, compound probability.

- Selecting a red ball from a group of colored balls
- Tails up after tossing a coin
- Selecting a queen card from the deck of 52 cards
- Choosing a chocolate-flavored ice cream from a set of eight flavors

- If it is certain that an event will occur, then its probability will be 1 .
- If the probability of an event is 0 , then we assume that there is no possibility of occurrence of an event.
- The probabilities of all possible events lie between 0 to 1 .

This list of possible outcomes is known as sample space .

P(A or B) = P(A) + P(B) - P(A and B)

- A and B are any two events.
- P(A) means the likelihood of the occurrence of event A.
- P(B) means the likelihood of the occurrence of an event B.
- P(A and B) is the probability that both the events A and B will occur at the same time.

There are three parts of this problem. We will find the probability of each event separately:

Number of girls in the class = 30

Total number of students in the class = 45

We will write the fraction in its most simplified form like this:

Number of boys who like football = 10

Simplifying the above probability will give us the following fraction:

John rolls a dice. What is the probability of getting 3 or 6?

According to this formula, first, we need to get the probability of each event separately like this:

Since only one dice is rolled, hence the probability of getting 3 and 6 both is 0.

Find the probability of selecting a red card or 2 from a deck of 52 cards.

- There are four suits
- Two suit have black cards and two of them are red
- In each suit, there are 13 cards. These 13 cards include a queen, a king a jack, ace, 2, 3, 4, 5, 6, 7, 8, 9, and 10.

Total number of cards in a deck = 52

Number of cards having 2 in a deck = 4

Number of red cards and 2 from a deck = 2

Solving and simplifying the above expression algebraically will give us the following answer:

Number of balls in the pool = 20

Total number of items in the pool = 60

The probability that a random item picked will be a ball:

Number of balls of red color= 10

Number of blue balls in the pool = 10

Number of blue blocks in the pool = 20

Total number of objects in the pool = 60

Alice rolls a dice on the floor. What is the probability that the number will be a multiple of 2?

Number of multiples of 2 on the dice = 3

The platform that connects tutors and students

Did you like this article? Rate it!

## Solved Problem of Probabilty 8

Solved probability problems and solutions are given here for a concept with clear understanding.

Solved probability problems with solutions :

Match the following events with the corresponding probabilities:

Number of blue triangles in a container = 4

Total number of objects = 4 + 5 + 7 = 16

(i) The objects is not a circle:

= Number of circles/Total number of objects

= 1 - P(the object is a circle)

(ii) The objects is a triangle:

= Number of triangle/Total number of objects

(iii) The objects is not a triangle:

= Number of triangles/Total number of objects

P(the object is not a triangle)

= 1 - P(the object is a triangle)

(iv) The objects is not a square:

= Number of squares/Total number of objects

= 1 - P(the object is a square)

Match the following events with the corresponding probabilities are shown below:

2. A single card is drawn at random from a standard deck of 52 playing cards.

Match each event with its probability.

Total number of playing cards = 52

Number of diamonds in a deck of 52 cards = 13

= Number of diamonds/Total number of playing cards

Number of red king in a deck of 52 cards = 2

= Number of red kings/Total number of playing cards

(iii) The card is a king or queen:

Number of kings in a deck of 52 cards = 4

Number of queens in a deck of 52 cards = 4

Total number of king or queen in a deck of 52 cards = 4 + 4 = 8

P(the card is a king or queen)

= Number of king or queen/Total number of playing cards

(iv) The card is either a red card or an ace:

Total number of red card or an ace in a deck of 52 cards = 28

P(the card is either a red card or an ace)

= Number of cards which is either a red card or an ace/Total number of playing cards

= Number of kings/Total number of playing cards

(vi) The card is a five or lower:

Number of cards is a five or lower = 16

P(the card is a five or lower)

= Number of card is a five or lower/Total number of playing cards

Number of black cards in a deck of 52 cards = 26

= Number of black cards/Total number of playing cards

(i) Total number of possible outcomes = 3 + 4 = 7.

Number of favourable outcomes for the event E.

(ii) The event of the ball being not black = \(\bar{E}\).

Hence, required probability = P(\(\bar{E}\))

Let E = the event of Serena Williams winning.

From the question, P(E) = 0.86.

Clearly, \(\bar{E}\) = the event of Serena Williams losing.

5. Find the probability of getting 53 Sunday in a leap year.

A leap year has 366 days. So, it has 52 weeks and 2 days.

So, 52 Sundays are assured. For 53 Sundays, one of the two remaining days must be a Sunday.

For the remaining 2 days we can have

So, total number of possible outcomes = 7.

Number of favourable outcomes for the event E = 2, [namely, (Sunday, Monday), (Saturday, Sunday)].

So, by definition: P(E) = \(\frac{2}{7}\).

25% of 24 = \(\frac{25}{100}\) × 24 = 6.

So, there are 6 defective bulbs and 18 bulbs are not defective.

After the first draw, the lot is left with 6 defective bulbs and 17 non-defective bulbs.

So, when the second bulb is drwn, the total number of possible outcomes = 23 (= 6+ 17).

Number of favourable outcomes for the event E = number of non-defective bulbs = 17.

So, the required probability = P(E) = (\frac{17}{23}\).

## You might like these

## Theoretical Probability |Classical or A Priori Probability |Definition

## 10th Grade Worksheet on Probability |Probability Questions and Answers

## Probability |Terms Related to Probability|Tossing a Coin|Coin Probabil

## Worksheet on Playing Cards | Playing Cards Probability | With Answers

## Rolling Dice Probability Worksheet |Dice Probability Worksheet|Answers

Probability of Tossing Two Coins

Probability of Tossing Three Coins

Probability for Rolling Two Dice

Probability for Rolling Three Dice

From Solved Probability Problems to HOME PAGE

## New! Comments

- Preschool Activities
- Kindergarten Math
- 1st Grade Math
- 2nd Grade Math
- 3rd Grade Math
- 4th Grade Math
- 5th Grade Math
- 6th Grade Math
- 7th Grade Math
- 8th Grade Math
- 10th Grade Math
- 11 & 12 Grade Math
- Concepts of Sets
- Boolean Algebra
- Math Coloring Pages
- Multiplication Table
- Cool Maths Games
- Math Flash Cards
- Online Math Quiz
- Math Puzzles
- Binary System
- Math Dictionary
- Conversion Chart
- Homework Sheets
- Math Problem Ans
- Free Math Answers
- Printable Math Sheet
- Funny Math Answers
- Employment Test
- Math Patterns
- Link Partners

© and ™ math-only-math.com. All Rights Reserved. 2010 - 2022.

Forgot password? New user? Sign up

## Probability - Problem Solving

Already have an account? Log in here.

To solve problems on this page, you should be familiar with

- Uniform Probability
- Probability - By Outcomes
- Probability - Rule of Sum
- Probability - Rule of Product
- Probability - By Complement
- Probability - Independent Events
- Conditional Probability

## Problem Solving - Basic

Problem solving - intermediate, problem solving - difficult.

If I throw 2 standard 5-sided dice, what is the probability that the sum of their top faces equals to 10? Assume both throws are independent to each other. Solution : The only way to obtain a sum of 10 from two 5-sided dice is that both die shows 5 face up. Therefore, the probability is simply \( \frac15 \times \frac15 = \frac1{25} = .04\)

2 fair 6-sided dice are rolled. What is the probability that the sum of these dice is \(10\)? Solution : The event for which I obtain a sum of 10 is \(\{(4,6),(6,4),(5,5) \}\). And there is a total of \(6^2 = 36\) possible outcomes. Thus the probability is simply \( \frac3{36} = \frac1{12} \approx 0.0833\)

You can try my other Probability problems by clicking here

Suppose a jar contains 15 red marbles, 20 blue marbles, 5 green marbles, and 16 yellow marbles. If you randomly select one marble from the jar, what is the probability that you will have a red or green marble? First, we can solve this by thinking in terms of outcomes. You could draw a red, blue, green, or yellow marble. The probability that you will draw a green or a red marble is \(\frac{5 + 15}{5+15+16+20}\). We can also solve this problem by thinking in terms of probability by complement. We know that the marble we draw must be blue, red, green, or yellow. In other words, there is a probability of 1 that we will draw a blue, red, green, or yellow marble. We want to know the probability that we will draw a green or red marble. The probability that the marble is blue or yellow is \(\frac{16 + 20}{5+15+16+20}\). , Using the following formula \(P(\text{red or green}) = 1 - P(\text{blue or yellow})\), we can determine that \(P(\text{red or green}) = 1 - \frac{16 + 20}{5+15+16+20} = \frac{5 + 15}{5+15+16+20}\).

If I throw 3 fair 5-sided dice, what is the probability that the sum of their top faces equals 10? Solution : We want to find the total integer solution for which \(a +b+c=10 \) with integers \(1\leq a,b,c \leq5 \). Without loss of generality, let \(a\leq b \leq c\). We list out the integer solutions: \[ (1,4,5),(2,3,5), (2,4,4), (3,3,4) \] When relaxing the constraint of \(a\leq b \leq c\), we have a total of \(3! + 3! + \frac{3!}{2!} + \frac{3!}{2!} = 18 \) solutions. Because there's a total of \(5^3 = 125\) possible combinations, the probability is \( \frac{18}{125} = 14.4\%. \ \square\)

How many ways are there to choose exactly two pets from a store with 8 dogs and 12 cats? Since we haven't specified what kind of pets we pick, we can choose any animal for our first pick, which gives us \( 8+12=20\) options. For our second choice, we have 19 animals left to choose from. Thus, by the rule of product, there are \( 20 \times 19 = 380 \) possible ways to choose exactly two pets. However, we have counted every pet combination twice. For example, (A,B) and (B,A) are counted as two different choices even when we have selected the same two pets. Therefore, the correct number of possible ways are \( {380 \over 2} = 190 \)

Out of 10001 tickets numbered consecutively, 3 are drawn at random .

Find the chance that the numbers on them are in Arithmetic Progression .

The answer is of the form \( \frac{l}{k} \) .

Find \( k - l \) where \(k\) and \(l\) are co-prime integers.

HINT : You might consider solving for \(2n + 1\) tickets .

You can try more of my Questions here .

## Photo credit: www.figurerealm.com

Her first shot has a 50% chance of going in.

Photo credit: http://polymathprogrammer.com/

## 1.4.5 Solved Problems: Conditional Probability

- What is the probability of three heads, $HHH$?
- What is the probability that you observe exactly one heads?
- Given that you have observed at least one heads, what is the probability that you observe at least two heads?
- $P(HHH)=P(H)\cdot P(H) \cdot P(H)=0.5^3=\frac{1}{8}$.
- $A$ and $C$ are independent,
- $B$ and $C$ are independent,
- $A$ and $B$ are disjoint,
- $P(A \cup C)=\frac{2}{3}, P(B \cup C)=\frac{3}{4}, P(A \cup B\cup C)=\frac{11}{12}$

- $A$ and $B$ are conditionally independent given $C_i$, for all $i \in \{1,2,\cdots,M\}$;
- $B$ is independent of all $C_i$'s.
- What is the probability that it's not raining and there is heavy traffic and I am not late?
- What is the probability that I am late?
- Given that I arrived late at work, what is the probability that it rained that day?

- You pick a coin at random and toss it. What is the probability that it lands heads up?
- You pick a coin at random and toss it, and get heads. What is the probability that it is the two-headed coin?

The print version of the book is available through Amazon here .

## IMAGES

## VIDEO

## COMMENTS

The six steps of problem solving involve problem definition, problem analysis, developing possible solutions, selecting a solution, implementing the solution and evaluating the outcome. Problem solving models are used to address issues that...

Complex problems are questions or issues that cannot be answered through simple logical procedures. They generally require abstract reasoning to be applied through multiple frames of reference.

When multiplying or dividing different bases with the same exponent, combine the bases, and keep the exponent the same. For example, X raised to the third power times Y raised to the third power becomes the product of X times Y raised to th...

Probability Explained! · An Introduction to Conditional Probability · How to solve a clever sum of sums problem · Solving some advanced probability

probability in this context is a difficult problem for a large number of people.).

Use Python to solve simple to complex probability problems. Design experiments, repeat them and calculate the probability of your favorable

Generally speaking, you count the possible results, and you count the possible results that fit your requirements, then you divide the fits by the possibles.

it more and more difficult to tell when I was working and when playing,.

Probability: Solved Examples · Example 7: Three dice are rolled together. What is the probability as getting at least one '4'? · Sol: Total number of ways = 6 × 6

This is an example of a compound probability because we are asked to tell the probability of two events. The formula for computing the compound probability is

Solved Probability Problems · 1. Probability Problems with Solutions · 2. A single card is drawn at random from a standard deck of 52 playing cards. · 3. A bag

To solve problems on this page, you should be familiar with Uniform Probability Probability - By Outcomes Probability - Rule of Sum Probability - Rule of

Finding the probability of a simple event happening is fairly straightforward: add the probabilities together. For example

I toss a coin repeatedly. The coin is unfair and P(H)=p. The game ends the first time that two consecutive heads (HH) or two consecutive tails (TT) are observed