Linearity of Expectation

Mathematics for Computer Science
MIT 6.042J/18.062J
Great
Expectations
Albert R Meyer, May 11, 2009
lec 14M.1
Carnival Dice
choose a number from 1 to 6,
then roll 3 fair dice:
win $1 for each match
lose $1 if no match
Albert R Meyer, May 11, 2009
lec 14M.6
Carnival Dice
Example: choose 5, then
roll 2,3,4: lose $1
roll 5,4,6: win $1
roll 5,4,5: win $2
roll 5,5,5: win $3
Albert R Meyer, May 11, 2009
lec 14M.7
Carnival Dice
Is this a
fair game?
Albert R Meyer, May 11, 2009
lec 14M.8
Carnival Dice
# matches probability
$ won
0
125/216
-1
1
75/216
1
2
15/216
2
3
1/216
3
Albert R Meyer, May 11, 2009
lec 14M.10
Carnival Dice
so every 216 games, expect
0 matches about 125 times
1 match about 75 times
2 matches about 15 times
3 matches about once
Albert R Meyer, May 11, 2009
lec 14M.11
Carnival Dice
So on average expect to win:
NOT fair!
125  ( 1)  75  1  15  2  1  3
216
17

 8 cents
216
Albert R Meyer, May 11, 2009
lec 14M.13
Carnival Dice
You can “expect” to lose 8 cents
per play. But you never actually
lose 8 cents on any single play,
this is just your average loss.
Albert R Meyer, May 11, 2009
lec 14M.14
Expected Value
The expected value of
random variable R is
the average value of R
--with values weighted
by their probabilities
Albert R Meyer, May 11, 2009
lec 14M.15
Expected Value
The expected value of
random variable R is
E[R]::= ∑v Pr{R = v}
17
so E[$win in Carnival] = 
216
Albert R Meyer, May 11, 2009
lec 14M.16
Expected Value
also called
mean value, mean, or
expectation
Albert R Meyer, May 11, 2009
lec 14M.21
Expected #Heads
n independent flips of a
coin with bias p for Heads.
How many Heads expected?
n
E Bn,p    k  Pr k Heads ?
  k 0
n
 n  k n k
::  k   p q
k 0  k 
Albert R Meyer, May 11, 2009
lec 14M.23
Law of Total Expectation
conditional expectation:
E[R | A] ::  v  pr{R  v | A}
E[R]  E[R | A]  pr{A}
 E[R | A]  pr{A}
good for reasoning by cases
Albert R Meyer, May 11, 2009
lec 14M.29
Expected #Heads
Let e(n) ::= expected #H’s in n flips.
= 1 + e(n-1)
if 1st flip H
= e(n-1)
if 1st flip T
by Total Expectation:
e(n) = [1 + e(n-1)] p + e(n1) q
= np  E Bn,p 
e(n) = e(n-1) + p
Albert R Meyer, May 11, 2009
lec 14M.30
Mean Time to “Failure”
E[# flips until first head]?
p
H
q
p
H
q
p
B
q
H
Albert R Meyer, May 11, 2009
lec 14M.33
Mean Time to “Failure”
E[# flips until first head]?
p
H
q
B
B
now use Total Expectation
Albert R Meyer, May 11, 2009
lec 14M.34
Mean Time to “Failure”
E[# flips until first head]?
p
H
E=
E[# |1st is H]
1
q
B
B
p + E[# |1st is T]
Albert R Meyer, May 11, 2009
1+E
q
lec 14M.35
Mean Time to “Failure”
E[# flips until first head]?
p
H
E =1
q
B
B
p + [E+1]
Albert R Meyer, May 11, 2009
(1-p)
lec 14M.36
Mean Time to “Failure”
E[# flips until first head]
1

p
Albert R Meyer, May 11, 2009
lec 14M.37
Linearity of Expectation
A,B random variables, a,b
constants
E[aA + bB] =
aE[A] + bE[B]
Albert R Meyer, May 11, 2009
lec 14M.40
Expectation of indicator I
E[I] = 1⋅pr{I=1} +
0⋅pr{I=0}
= pr{I=1}
Albert R Meyer, May 11, 2009
lec 14M.42
Expected #Heads
E  #H's   E H1 + H2 +
+ Hn 
where Hi is indicator
for Head on ith flip
E[Hi] = p
Albert R Meyer, May 11, 2009
lec 14M.43
Expected #Heads
E  #H's   E H1 + H2 +
so by linearity
 E H1  + E H2  +
 np
Albert R Meyer, May 11, 2009
+ Hn 
+ E Hn 
lec 14M.44
Chinese Banquet
Say n people sit around a
spinner (a “lazy-Susan”) with
n different dishes.
Spin randomly.
How many people do we expect
will get same dish as initially?
Albert R Meyer, May 11, 2009
lec 14M.47
Chinese Banquet
Let Ri be indicator for ith
person getting initial dish.
#people get initial dish =
R1 + R2 + … + Rn
Pr{Ri=1} = 1/n
Albert R Meyer, May 11, 2009
lec 14M.48
Chinese Banquet
Ri’s are totally dependent...
all = 1 or all = 0
Albert R Meyer, May 11, 2009
lec 14M.49
Chinese Banquet
E[# initial dishes] = E[∑
Ri]
so by linearity = ∑ E[Ri]
= ∑ Pr{Ri=1} = ∑ 1/n
= n(1/n) = 1
Albert R Meyer, May 11, 2009
lec 14M.50
Expectation & Independence
for independent R,S
E[R⋅S] = E[R]⋅E[S]
Albert R Meyer, May 11, 2009
lec 14M.51
Team Problems
Problems
1-4
Albert R Meyer, May 11, 2009
lec 14M.53