Mathematics for Computer Science
MIT 6.042J/18.062J
Introduction to
Random Variables
Albert R Meyer
December 5, 2011
lec 14M.1
Guess the Bigger Number
Team 1:
• Write different integers between 0 and
7 on two pieces of paper
• Show to Team 2 face down
Team 2:
• Expose one paper and look at number
• Either stick or switch to other number
Team 2 wins if gets larger number
Albert R Meyer
December 5, 2011
lec 14M.2
Strategy for Team 2
• pick a paper to expose, giving each
paper equal probability.
• if exposed number is “small” then
switch, otherwise stick. That is
switch if threshold Z where
Z is a random integer, 0 Z 6.
Albert R Meyer
December 5, 2011
lec 14M.4
Analysis of Team 2 Strategy
Case M: low Z < high
Team 2 wins in this case, so
Pr{Team 2 wins | M} = 1
1
and Pr{M}
7
Albert R Meyer
December 5, 2011
lec 14M.5
Analysis of Team 2 Strategy
Case H: high Z
Team 2 will switch, so wins iff
low card gets exposed
1
Pr{Team 2 wins | H} =
2
Albert R Meyer
December 5, 2011
lec 14M.6
Analysis of Team 2 Strategy
Case L: Z < low
Team 2 will stick, so wins iff
high card gets exposed
1
Pr{Team 2 wins | L} =
2
Albert R Meyer
December 5, 2011
lec 14M.7
Analysis of Team 2 Strategy
So 1/7 of time, sure win.
Rest of time, win 1/2.
by Law of Total Probability
Albert R Meyer
December 5, 2011
lec 14M.8
Analysis of Team 2 Strategy
So 1/7 of time, sure win.
Rest of time, win 1/2.
Pr{Team 2 wins} =
Pr{win|Z good}⋅Pr{Z good} +
Pr{win|Z no good}⋅Pr{Z no good}
Albert R Meyer
December 5, 2011
lec 14M.9
Analysis of Team 2 Strategy
So 1/7 of time, sure win.
Rest of time, win 1/2.
Pr{Team 2 wins}
1
1 1
1 1
7
7 2
Albert R Meyer
December 5, 2011
4
7
lec 14M.10
Analysis of Team 2 Strategy
Does not matter
what Team 1 does!
Albert R Meyer
December 5, 2011
lec 14M.11
Team 1 Strategy
…& Team 1 can play so
4
Pr{Team 2 wins}
7
whatever Team 2 does
Albert R Meyer
December 5, 2011
lec 14M.12
Random Variables
Informally: an RV is a number
produced by a random process:
• threshold variable Z
• number of larger card
• number of smaller card
• number of exposed card
Albert R Meyer
December 5, 2011
lec 14M.13
Random Variables
Informally: an RV is a number
produced by a random process:
• #hours to next system crash
• #faulty chips in production run
• avg # faulty chips in many runs
• #heads in n coin flips
Albert R Meyer
December 5, 2011
lec 14M.14
Intro to Random Variables
Example: Flip three fair coins
C ::= # heads (Count)
1 if all Match,
M ::
0 otherwise.
Albert R Meyer
December 5, 2011
lec 14M.15
Intro to Random Variables
Specify events using values of variables
• [C = 1] is event “exactly 1 head”
Pr{C = 1} = 3/8
• Pr{C 1} = 7/8
• Pr{C·M > 0} = Pr{M>0 and C>0}
= Pr{all heads} = 1/8
Albert R Meyer
December 5, 2011
lec 14M.16
What is a Random Variable?
Formally,
R:
Sample space
Albert R Meyer
December 5, 2011
(usually)
lec 14M.17
Independent Variables
random variables R,S
are independent iff
[R = a], [S = b]
are independent
events for all a, b
Albert R Meyer
December 5, 2011
lec 14M.18
Independent Variables
alternate version:
Pr{R = a AND S = b} =
Pr{R = a} · Pr{S = b}
Albert R Meyer
December 5, 2011
lec 14M.20
Independent Variables
Are C and M
independent? NO:
Pr{M=1}⋅Pr{C=1} > 0
Pr{M=1 and C=1} = 0
Albert R Meyer
December 5, 2011
lec 14M.21
Indicator Variables
The indicator variable for
event A:
ì
ì 1 if A occurs,
I A ::= ì
ì0 if A does not occur.
(Sanity check:
IA and IB are independent iff
A and B are independent.)
Albert R Meyer
December 5, 2011
lec 14M.22
Mutally Independent Variables
Def:
R1, R2, … , Rn
are mutually indep RV’s iff
[R1=a1],[R2=a2],…,[Rn=an]
are mutually indep events
for all a1, a2, … , an
Albert R Meyer
December 5, 2011
lec 14M.24
Mutally Independent Variables
Pr{R1=a1 AND R2=a2 AND
··· AND Rn=an}
= Pr{R1=a1}·Pr{R2=a2}·
··· Pr{Rn=an}
Albert R Meyer
December 5, 2011
lec 14M.25
Binomial Random Variable
Bn,p::= # heads in n mutually indep flips.
Coin may be biased. So 2 parameters
n ::= # flips, p ::= Pr{head}
C is binomial for 3 flips: C is B3,1/2
for n=5, p=2/3
Pr{HHTTH} =
Pr{H}⋅Pr{H}⋅Pr{T}⋅Pr{T}⋅Pr{H}
(by independence)
Albert R Meyer
December 5, 2011
lec 14M.29
Binomial Random Variable
Bn,p::= # heads in n mutually indep flips.
Coin may be biased. So 2 parameters
n ::= # flips, p ::= Pr{head}
C is binomial for 3 flips: C is B3,1/2
for n=5, p=2/3
Pr{HHTTH} =
Albert R Meyer
December 5, 2011
lec 14M.30
Binomial Random Variable
Bn,p::= # heads in n mutually indep flips.
Coin may be biased. So 2 parameters
n ::= # flips, p ::= Pr{head}
C is binomial for 3 flips: C is B3,1/2
for n=5, p=2/3
Pr{HHTTH} =
Albert R Meyer
December 5, 2011
lec 14M.31
Binomial Random Variable
Bn,p::= # heads in n mutually indep flips.
Coin may be biased. So 2 parameters
n ::= # flips, p ::= Pr{head}
Pr{each sequence w/i H’s, n-i T’s} =
Albert R Meyer
December 5, 2011
lec 14M.33
Binomial Random Variable
Bn,p::= # heads in n mutually indep flips.
Coin may be biased. So 2 parameters
n ::= # flips, p ::= Pr{head}
Pr{get i H’s, n-i T’s} = #seq’s⋅pr[seq]
Albert R Meyer
December 5, 2011
lec 14M.34
Binomial Random Variable
Bn,p::= # heads in n mutually indep flips.
Coin may be biased. So 2 parameters
n ::= # flips, p ::= Pr{head}
Pr{
} = #seq’s⋅pr{seq}
Albert R Meyer
December 5, 2011
lec 14M.35
Density & Distribution
Probability Density Function
of random variable R,
so
PDFR(a) ::= Pr{R = a}
Albert R Meyer
December 5, 2011
lec 14M.36
Uniform Distribution
…all values equally likely.
“threshold” variable was uniform:
1
PDFZ(i) ::= Pr{Z = i} =
7
for i = 0,1,…,6.
Albert R Meyer
December 5, 2011
lec 14M.38
Uniform Distribution
R is uniform iff PDFR is constant
D ::= outcome of fair die roll
Pr{D=1} = Pr{D=2} =···= Pr{D=6} = 1/6
S ::= 4-digit lottery number
Pr{S = 0000} = Pr{S = 0001} = ···
= Pr{S = 9999} = 1/10000
Albert R Meyer
December 5, 2011
lec 14M.39
Mutual Independence
Given mutually indep RV’s R1,R2,…
[R1=R2] indep of [R3=R4] ?
obviously!
Albert R Meyer
December 5, 2011
lec 14M.40
Mutual Independence
Given mutually indep RV’s R1,R2,…
[R1=R2] indep of [R3=R2] ?
YES as long as one of
the Ri’s is uniform
Albert R Meyer
December 5, 2011
lec 14M.41
Mutual Independence
Given mutually indep RV’s R1,R2,…
[Ri=Rj] indep of [Rk=Rl]
for (i,j) (k,l) if one of
the R’s is uniform
they are pairwise indep
Albert R Meyer
December 5, 2011
lec 14M.42
Mutual Independence
Given mutually indep RV’s R1,R2,…
not 3-way independent
R1=R2 and R3=R2
implies R1=R3
Albert R Meyer
December 5, 2011
lec 14M.43
Team Problems
Problems
1―3
Albert R Meyer
December 5, 2011
lec 14M.44
© Copyright 2026 Paperzz