Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Discrete Probability

Huynh Tuong Nguyen,


Nguyen An Khuong,

Chapter 7 Tran Tuan Anh, Le


Hong Trang

Discrete Probability
Discrete Structures for Computing on April 9, 2018
Contents

Introduction
Randomness

Probability

Probability Rules

Random variables

Probability Models
Geometric Model
Binomial Model

Huynh Tuong Nguyen, Nguyen An Khuong, Tran Tuan Anh, Le


Hong Trang
Faculty of Computer Science and Engineering
University of Technology - VNUHCM
htnguyen@hcmut.edu.vn - nakhuong@hcmut.edu.vn
7.1
Discrete Probability
Contents
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

1 Introduction
Randomness

2 Probability Contents

Introduction
Randomness

3 Probability Rules Probability

Probability Rules

Random variables
4 Random variables Probability Models
Geometric Model
Binomial Model

5 Probability Models
Geometric Model
Binomial Model

7.2
Discrete Probability
Course outcomes
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang
Course learning outcomes

L.O.1 Understanding of logic and discrete structures


L.O.1.1 – Describe definition of propositional and predicate logic
L.O.1.2 – Define basic discrete structures: set, mapping, graphs

Contents
L.O.2 Represent and model practical problems with discrete structures
L.O.2.1 – Logically describe some problems arising in Computing Introduction
Randomness
L.O.2.2 – Use proving methods: direct, contrapositive, induction
Probability
L.O.2.3 – Explain problem modeling using discrete structures
Probability Rules

L.O.3 Understanding of basic probability and random variables Random variables

L.O.3.1 – Define basic probability theory Probability Models


L.O.3.2 – Explain discrete random variables Geometric Model
Binomial Model

L.O.4 Compute quantities of discrete structures and probabilities


L.O.4.1 – Operate (compute/ optimize) on discrete structures
L.O.4.2 – Compute probabilities of various events, conditional
ones, Bayes theorem

7.3
Discrete Probability
Motivations
Huynh Tuong Nguyen,
Nguyen An Khuong,
• Gambling Tran Tuan Anh, Le
Hong Trang

Contents

Introduction
Randomness

Probability
• Real life problems
Probability Rules

Random variables

Probability Models
Geometric Model
Binomial Model

• Computer Science: cryptology – deals with encrypting codes


or the design of error correcting codes
7.4
Discrete Probability
Randomness
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Which of these are random phenomena?


• The number you receive when rolling a fair dice
• The sequence for lottery special prize (by law!)
Contents
• Your blood type (No!) Introduction

• You met the red light on the way to school Randomness

Probability
• The traffic light is not random. It has timer.
Probability Rules
• The pattern of your riding is random.
Random variables

Probability Models
So what is special about randomness? Geometric Model
Binomial Model

In the long run, they are predictable and have relative frequency
(fraction of times that the event occurs over and over and over).

7.5
Discrete Probability
Terminology
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Contents

Introduction
Randomness

Probability

Probability Rules

Random variables

Probability Models
• Experiment (thí nghiệm): a procedure that yields one of a Geometric Model
given set of possible outcomes. Binomial Model

• Tossing a coin to see the face


• Sample space (không gian mẫu): set of possible outcomes
• {Head, Tail}
• Event (sự kiện): a subset of sample space.
• You see Head after an experiment. {Head} is an event.

7.6
Discrete Probability
Example
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Example (1)
Experiment: Rolling a die. What is the sample space?
Answer: {1, 2, 3, 4, 5, 6}

Contents

Introduction
Example (2) Randomness

Probability
Experiment: Rolling two dice. What is the sample space?
Probability Rules
Answer: It depends on what we’re going to ask! Random variables

• The total number? Probability Models


Geometric Model
{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} Binomial Model

• The number of each die?


{(1,1), (1,2), (1,3), . . ., (6,6)}

Which is better?
The latter one, because they are equally likely outcomes

7.7
Discrete Probability
The Law of Large Numbers
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Definition
The Law of Large Numbers (Luật số lớn) states that the long-run
relative frequency of repeated independent events gets closer and Contents
closer to the true relative frequency as the number of trials Introduction
increases. Randomness

Probability

Probability Rules
Example
Random variables
Do you believe that the true relative frequency of Head when you Probability Models

toss a coin is 50%? Geometric Model


Binomial Model

Let’s try!

7.8
Discrete Probability
Be Careful!
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Don’t misunderstand the Law of Large Numbers (LLN). It can


lead to money lost and poor business decisions.

Example
Contents
I had 8 children, all of them are girls. Thanks to LLN (!?), there Introduction
are high possibility that the next one will be a boy. Randomness

(Overpopulation!!!) Probability

Probability Rules

Random variables

Example Probability Models


Geometric Model

I’m playing Bầu cua tôm cá, the fish has not appeared in recent 5 Binomial Model

games, it will be more likely to be fish next game. Thus, I bet all
my money in fish. (Sorry, you lose!)

7.9
Discrete Probability
Probability
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Definition
The probability (xác suất) of an event E of a finite nonempty
sample space of equally likely outcomes S is:

|E| Contents
p(E) = . Introduction
|S| Randomness

Probability

Probability Rules

• Note that E ⊆ S so 0 ≤ |E| ≤ |S| Random variables

• 0 ≤ p(E) ≤ 1 Probability Models


Geometric Model

• 0 indicates impossibility Binomial Model

• 1 indicates certainty

People often say: “It has a 20% probability”

7.10
Discrete Probability
Examples
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Example (1) Hong Trang

What is the probability of getting a Head when tossing a coin?


Answer:
• There are |S| = 2 possible outcomes
• Getting a Head is |E| = 1 outcome, so Contents
p(E) = 1/2 = 0.5 = 50% Introduction
Randomness

Probability
Example (2) Probability Rules

Random variables
What is the probability of getting a 7 by rolling two dice?
Probability Models

Answer: Geometric Model


Binomial Model

• Product rule: There are a total of 36 equally likely possible


outcomes
• There are six successful outcomes:
(1,6), (2,5), (3,4), (4,3), (5,2), (6,1)
• Thus, |E| = 6, |S| = 36, p(E) = 6/36 = 1/6

7.11
Discrete Probability
Examples
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Example (3)
We toss a coin 6 times. What is probability of H in 6th toss, if all
the previous 5 are T?
Answer:
Contents
Don’t be silly! Still 1/2. Introduction
Randomness

Example (4) Probability

Probability Rules
Which is more likely: Random variables

• Rolling an 8 when 2 dice are rolled? Probability Models


Geometric Model

• Rolling an 8 when 3 dice are rolled? Binomial Model

Answer:
Two dice: 5/36 ≈ 0.139
Three dice: 21/216 ≈ 0.097

7.12
Discrete Probability
Formal Probability
Huynh Tuong Nguyen,
Nguyen An Khuong,
Rule 1 Tran Tuan Anh, Le
Hong Trang

A probability is a number between 0 and 1.

0 ≤ p(E) ≤ 1

Contents
Rule 2: Something has to happen rule Introduction
Randomness
The probability of the set of all possible outcomes of a trial must Probability
be 1. Probability Rules
p(S) = 1 Random variables

Probability Models
Geometric Model
Binomial Model

Rule 3: Compliment Rule


The probability of an event occurring is 1 minus the probability
that it doesn’t occur.

p(E) = 1 − p(E)

7.13
Discrete Probability
Examples
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Example
What is the probability of NOT drawing a heart card from 52 deck
cards? Contents

Introduction
Answer: Randomness

Let E be the event of getting a heart from 52 deck cards. We Probability

have: Probability Rules

p(E) = 13/52 = 1/4 Random variables

By the compliment rule, the probability of NOT getting a heart Probability Models
Geometric Model
card is: Binomial Model

p(E) = 1 − p(E) = 3/4

7.14
Discrete Probability
Formal Probability
Huynh Tuong Nguyen,
Nguyen An Khuong,
General Addition Rule Tran Tuan Anh, Le
Hong Trang

p(E1 ∪ E2 ) = p(E1 ) + p(E2 ) − p(E1 ∩ E2 )

If E1 ∩ E2 = ∅: They are disjoint, which means they can’t occur


together, then, p(E1 ∪ E2 ) = p(E1 ) + p(E2 )
Contents

Introduction
Example (1)
Randomness

If you choose a number between 1 and 100, what is the probability Probability

that it is divisible by either 2 or 5? Probability Rules

Random variables
50 20 10 3
Short Answer: 100 + 100 − 100 = 5 Probability Models
Geometric Model
Binomial Model

Example (2)
There are a survey that about 45% of VN population has Type O
blood, 40% type A, 11% type B and the rest type AB. What is the
probability that a blood donor has Type A or Type B?
Short Answer: 40% + 11% = 51%
7.15
Discrete Probability
Example
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Example (3)
In a hospital unit there are 8 nurses and 5 physicians; 7 nurses and
3 physicians are females. If a staff person is selected, find the
probability that the subject is a nurse or a male.
Contents

The sample space is shown here: Introduction


Randomness

Staff Females Male Total Probability

Probability Rules
Nurses 7 1 8
Random variables
Physicians 3 2 5 Probability Models
Total 10 3 13 Geometric Model
Binomial Model

The probability is:


P(nurse or male) = P(nurse) +P(male) - P(male nurse)
8 3 1 10
= 13 + 13 − 13 = 13

7.16
Discrete Probability
Conditional Probability (Xác suất có điều kiện)
Huynh Tuong Nguyen,
“Knowledge” changes probabilities Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Contents

Introduction
Randomness

Definition Probability

p(E | F ) = Probability of event E given that event F has Probability Rules

occurred. Random variables

Probability Models
Geometric Model
Binomial Model

General Multiplication Rule

p(E ∩ F ) = p(E) × p(F | E)


= p(F ) × p(E | F )
7.17
Discrete Probability
Example
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Example (1)
What is the probability of drawing a red card and then another red
card without replacement (không hoàn lại)?
Contents

Introduction
Randomness
Solution
Probability
E: the event of drawing the first red card Probability Rules

F : the event of drawing the second red card Random variables

p(E) = 26/52 = 1/2 Probability Models


Geometric Model
p(F | E) = 25/51 Binomial Model

So the event of drawing a red card and then another red card is
p(E ∩ F ) = p(E) × p(F | E) = 1/2 × 25/51 = 25/102

7.18
Discrete Probability
Example
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Example (2)
The probability that Sam parks in a no-parking zone and gets a
parking ticket is 0.06, and the probability that Sam cannot find a
legal parking space and has to park in the no-parking zone is 0.20.
Contents
On Tuesday, Sam arrives at school and has to park in a no-parking Introduction
zone. Find the probability that he will get a parking ticket. Randomness

Probability

Probability Rules
Solution Random variables

N : parking in a no-parking zone Probability Models


Geometric Model
T : get a ticket Binomial Model
∩T )
p(T |N ) = p(N 0.06
p(N ) = 0.2 = 0.3
Hence, Sam has a 0.3 probability of getting a parking ticket, given
that he parked in a no-parking zone.

7.19
Discrete Probability
Independence
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Definition Hong Trang

Events E and F are independent (độc lập) whenever

p(E | F ) = p(E)

Contents
• The outcome of one event does not influence the probability Introduction

of the other. Randomness

Probability
• Example: p(“Head”|“It’s raining outside”) = p(“Head”) Probability Rules

• If E and F are independent Random variables

Probability Models
Geometric Model
p(E ∩ F ) = p(E) × p(F ) Binomial Model

Disjoint 6= Independence
Disjoint events cannot be independent. They have no outcomes in
common, so knowing that one occurred means the other did not.

7.20
Discrete Probability
Bayes’s Theorem
Huynh Tuong Nguyen,
Nguyen An Khuong,
Theorem (Bayes’s Theorem) Tran Tuan Anh, Le
Hong Trang

p(E | F )p(F )
p(F | E) =
p(E | F )p(F ) + p(E | F )p(F )

Example Contents

Introduction
If we know that the probability that a person has tuberculosis Randomness

(TB) is p(TB) = 0.0005. Probability

We also know p(+|TB) = 0.999 and p(−|TB) = 0.99. Probability Rules

What is p(TB|+) and p(TB|−)? Random variables

Probability Models
Geometric Model
p(+|T B)p(T B) Binomial Model
p(T B|+) =
p(+|T B)p(T B) + p(+|T B)p(T B)
0.999 × 0.0005
= = 0.0476
0.999 × 0.0005 + (1 − 0.99) × (1 − 0.0005)

p(T B|−) = 0.99

7.21
Discrete Probability
Expected Value: Center
Huynh Tuong Nguyen,
Nguyen An Khuong,
Expected value (giá trị kỳ vọng) Tran Tuan Anh, Le
Hong Trang

P
E(X) = x · p(X = x)

Example
An insurance company charges $50 a year. Can company make a Contents

Introduction
profit? Assuming that it made a research on 1000 people and have Randomness

following table: Probability

Probability Rules

Outcome Payroll (x) Probability p(X = x) Random variables

Probability Models
1
Death 10,000 1000 Geometric Model
Binomial Model
2
Disability 5000 1000
997
Neither 0 1000

X is a discrete random variable (biến ngẫu nhiên rời rạc)


The company expects that they have to pay each customer:
E(X) = $10, 000(1/1000) + $5000(2/1000) + $0(997/1000) = $20
7.22
Discrete Probability
Variance: The Spread
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
• Of course, the expected value $20 will not happen in reality Hong Trang

• There will be variability. Let’s calculate!

• Variance P
(phương sai)
V (X) = (x − E(X))2 · p(X = x) Contents

• V (X) = 99802 ( 1000


1
) + 49802 ( 1000
2
) + (−20)2 ( 1000
997
)= Introduction
Randomness
149, 600
Probability
• Standard deviation (độ lệch chuẩn) Probability Rules
p
SD(X) = V (X) Random variables

• SD(X) = 149, 600 ≈ $386.78 Probability Models
Geometric Model
Binomial Model

Comment
The company expects to pay out $20, and make $30. However,
the standard deviation of $386.78 indicates that it’s no sure thing.
That’s pretty big spread (and risk) for an average profit of $20.

7.23
Discrete Probability
Example
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Example
One thousand tickets are sold at 1 each for a color television
valued at 350. What is the expected value of the gain if you
purchase one ticket?
The problem can be set up as follows: Contents

Introduction
Randomness
Win Lose Probability

Gain 349 −1 Probability Rules

Random variables
1 999
probability 1000 1000
Probability Models
Geometric Model
Binomial Model
The solution, then, is
1 999
E(X) = $349( ) + (−1)( ) = −0.65
1000 1000

7.24
Discrete Probability
Example
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Example Hong Trang

A person pays $2 to play a certain game by rolling a single die


once. If a 1 or a 2 comes up, the person wins nothing. If, however,
the player rolls a 3, 4, 5, or 6, he or she wins the difference
between the number rolled and 2. Is the game fair?
Contents

Example Introduction
Randomness

The roulette wheel: Probability

Probability Rules

Random variables

Probability Models
Geometric Model
Binomial Model

7.25
Discrete Probability
Bernoulli Trials
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Example
Some people madly drink Coca-Cola, hoping to find a ticket to see
Big Bang. Let’s call tearing a bottle’s label trial (phép thử ):
• There are only possible outcomes (congrats or good luck)
Contents

• The probability of success, p, is the same on every trial, say Introduction

0.06 Randomness

Probability
• The trials are independent. Finding a ticket in the first bottle Probability Rules
does not change what might happen in the second one. Random variables

Probability Models
Geometric Model
Binomial Model

• Bernoulli Trials
• Another examples: tossing a coin many times, results of
testing TB on many patients, . . .

7.26
Discrete Probability
Geometric Model (Mô hình hình học)
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang

Question: How long it will take us to achieve a success, given p,


the probability of success?

Definition (Geometric probability model: Geom(p)) Contents

Introduction
p = probability of success (q = 1 − p = probability of failure) Randomness

X = number of trials until the first success occurs Probability

Probability Rules
x−1
p(X = x) = q p Random variables

Probability Models
Geometric Model
1
Expected value: µ = p Binomial Model
q
q
Standard deviation: σ = p2

7.27
Discrete Probability
Geometric Model: Example
Huynh Tuong Nguyen,
Example Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang
If the probability of finding a Sound Fest ticket is p = 0.06, how
many bottles do you expect to open before you find a ticket?
What is the probability that the first ticket is in one of the first
four bottles?

Contents
Solution
Introduction
Let X = number of trials until a ticket is found Randomness

We can model X with Geom(0.06). Probability

1 Probability Rules
E(X) = 0.06 ≈ 16.7
Random variables

Probability Models
Geometric Model

P (X ≤ 4) = P (X = 1) + P (X = 2) + P (X = 3) + P (X = 4) Binomial Model

= (0.06) + (0.94)(0.06) + (0.94)2 (0.06)


+(0.94)3 (0.06)
≈ 0.2193

Conclusion: We expect to open 16.7 bottles to find a ticket.


About 22% of time we’ll find one within the first 4 bottles. 7.28
Discrete Probability
Binomial Model (Mô hình nhị thức)
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang
Previous Question: How long it will take us to achieve a success,
given p, the probability of success?
New Question: You buy 5 Coca-Cola. What’s the probability you
get exactly 2 Sound Fest tickets?
Contents

Introduction
Definition (Binomial probability model: Binom(n, p)) Randomness

n = number of trials Probability

Probability Rules
p = probability of success (q = 1 − p = probability of failure)
Random variables
X = number of successes in n trials
Probability Models
  Geometric Model
n x n−x Binomial Model
p(X = x) = p q
x

Expected value: µ = np

Standard deviation: σ = npq

7.29
Discrete Probability
Binomial Model: Example
Huynh Tuong Nguyen,
Nguyen An Khuong,
Example Tran Tuan Anh, Le
Hong Trang
Suppose you buy 20 Coca-Cola bottles. What are the mean and
standard deviation of the number of winning bottles among them?
What is the probability that there are 2 or 3 tickets?

Solution
Contents
Let X = number of tickets among n = 20 bottles Introduction

We can model X with Binom(20, 0.06). Randomness

Probability
E(X) = np = 20(0.06)
p = 1.2
√ Probability Rules
SD(X) = npq = 20(0.06)(0.94) ≈ 1.96
Random variables

Probability Models
P (X = 2 or 3) = P (X = 2) + P (X = 3) Geometric Model
    Binomial Model
20 20
= (0.06)2 (0.94)18 + (0.06)3 (0.94)17
2 3
≈ 0.2246 + 0.0860 = 0.3106

Conclusion: In 20 bottles, we expect to find an average of 1.2


tickets, with a sd of 1.06. About 31% of the time we’ll find 2 or 3
tickets among 20 bottles.
7.30

You might also like