14 conditional expectation - stanford university

Post on 16-Feb-2022

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

14: Conditional ExpectationJerry CainApril 28, 2021

1

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Quick slide reference

2

3 Conditional distributions 14a_conditional_distributions

11 Conditional expectation 14b_cond_expectation

17 Law of Total Expectation and Exercises LIVE

Discrete conditional distributions

3

14a_conditional_distributions

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Discrete conditional distributionsRecall the definition of the conditional probability of event 𝐸 given event 𝐹:

𝑃 𝐸 𝐹 =𝑃 𝐸𝐹𝑃 𝐹

For discrete random variables 𝑋 and π‘Œ, the conditional PMF of 𝑋 given π‘Œ is

𝑃 𝑋 = π‘₯ π‘Œ = 𝑦 =𝑃 𝑋 = π‘₯, π‘Œ = 𝑦

𝑃 π‘Œ = 𝑦

𝑝!|# π‘₯|𝑦 =𝑝!,# π‘₯, 𝑦𝑝# 𝑦

4

Different notation,same idea:

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Discrete probabilities of CS109Each student responds with:Year π‘Œβ€’ 1: Frosh/Sophβ€’ 2: Jr/Srβ€’ 3: Co-term/grad/NDO

Timezone 𝑇 (12pm California time in my timezone is):β€’ βˆ’1: AMβ€’ 0: noonβ€’ 1: PM

5

𝑃 π‘Œ = 3, 𝑇 = 1

Joint PMFs sum to 1.

π‘Œ = 1 π‘Œ = 2 π‘Œ = 3𝑇 = βˆ’1 .06 .01 .01𝑇 = 0 .29 .14 .09𝑇 = 1 .30 .08 .02

Joint PMF

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Discrete probabilities of CS109The below are conditional probability tablesfor conditional PMFs(A) 𝑃 π‘Œ = 𝑦|𝑇 = 𝑑 and (B) 𝑃 𝑇 = 𝑑|π‘Œ = 𝑦 .1. Which is which?2. What’s the missing probability?

6

π‘Œ = 1 π‘Œ = 2 π‘Œ = 3𝑇 = βˆ’1 .06 .01 .01𝑇 = 0 .29 .14 .09𝑇 = 1 .30 .08 .02

Joint PMF

πŸ€”

π‘Œ = 1 π‘Œ = 2 π‘Œ = 3𝑇 = βˆ’1 .09 .04 .08𝑇 = 0 .45 .61 .75𝑇 = 1 .46 .35 .17

π‘Œ = 1 π‘Œ = 2 π‘Œ = 3𝑇 = βˆ’1 .75 .125 ?𝑇 = 0 .56 .27 .17𝑇 = 1 .75 .2 .05

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Discrete probabilities of CS109The below are conditional probability tablesfor conditional PMFs(A) 𝑃 π‘Œ = 𝑦|𝑇 = 𝑑 and (B) 𝑃 𝑇 = 𝑑|π‘Œ = 𝑦 .1. Which is which?2. What’s the missing probability?

7

π‘Œ = 1 π‘Œ = 2 π‘Œ = 3𝑇 = βˆ’1 .06 .01 .01𝑇 = 0 .29 .14 .09𝑇 = 1 .30 .08 .02

π‘Œ = 1 π‘Œ = 2 π‘Œ = 3𝑇 = βˆ’1 .09 .04 .08𝑇 = 0 .45 .61 .75𝑇 = 1 .46 .35 .17

Joint PMF

π‘Œ = 1 π‘Œ = 2 π‘Œ = 3𝑇 = βˆ’1 .75 .125 ?𝑇 = 0 .56 .27 .17𝑇 = 1 .75 .2 .05

(B) 𝑃 𝑇 = 𝑑|π‘Œ = 𝑦 (A) 𝑃 π‘Œ = 𝑦|𝑇 = 𝑑

.30/(.06+.29+.30)

1-.75-.125.125

Conditional PMFs also sum to 1 conditioned on different events!

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Extended to Amazon

8

P(bought item 𝑋 | bought item π‘Œ)

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Quick checkNumber or function?

1. 𝑃 𝑋 = 2 π‘Œ = 5

2. 𝑃 𝑋 = π‘₯ π‘Œ = 5

3. 𝑃 𝑋 = 2 π‘Œ = 𝑦

4. 𝑃 𝑋 = π‘₯ π‘Œ = 𝑦

9

𝑃 𝑋 = π‘₯ π‘Œ = 𝑦 =𝑃 𝑋 = π‘₯, π‘Œ = 𝑦

𝑃 π‘Œ = 𝑦

πŸ€”

True or false?

5.

6.

7.

8.

)!

)"

𝑃 𝑋 = π‘₯|π‘Œ = 𝑦 = 1

)"

𝑃 𝑋 = 2|π‘Œ = 𝑦 = 1

)!

𝑃 𝑋 = π‘₯|π‘Œ = 5 = 1

)!

)"

𝑃 𝑋 = π‘₯|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦 = 1

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Quick checkNumber or function?

1. 𝑃 𝑋 = 2 π‘Œ = 5

2. 𝑃 𝑋 = π‘₯ π‘Œ = 5

3. 𝑃 𝑋 = 2 π‘Œ = 𝑦

4. 𝑃 𝑋 = π‘₯ π‘Œ = 𝑦

10

2-D function

1-D function

1-D function

numbertrue

false

false

𝑃 𝑋 = π‘₯ π‘Œ = 𝑦 =𝑃 𝑋 = π‘₯, π‘Œ = 𝑦

𝑃 π‘Œ = 𝑦

True or false?

5.

6.

7.

8.

)!

)"

𝑃 𝑋 = π‘₯|π‘Œ = 𝑦 = 1

)"

𝑃 𝑋 = 2|π‘Œ = 𝑦 = 1

)!

𝑃 𝑋 = π‘₯|π‘Œ = 5 = 1

)!

)"

𝑃 𝑋 = π‘₯|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦 = 1 true

Conditional Expectation

11

14b_cond_expectation

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Conditional expectationRecall the the conditional PMF of 𝑋 given π‘Œ = 𝑦:

𝑝0|1 π‘₯|𝑦 = 𝑃 𝑋 = π‘₯|π‘Œ = 𝑦 =𝑝0,1 π‘₯, 𝑦𝑝1 𝑦

The conditional expectation of 𝑋 given π‘Œ = 𝑦 is

𝐸 𝑋|π‘Œ = 𝑦 =5%

π‘₯𝑃 𝑋 = π‘₯|π‘Œ = 𝑦 =5%

π‘₯𝑝!|# π‘₯|𝑦

12

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

It’s been so long, our dice friendsβ€’ Roll two 6-sided dice.β€’ Let roll 1 be 𝐷&, roll 2 be 𝐷'. β€’ Let 𝑆 = value of 𝐷& + 𝐷'.

1. What is 𝐸 𝑆|𝐷' = 6 ?

13

𝐸 𝑋|π‘Œ = 𝑦 = )!

π‘₯𝑝"|$ π‘₯|𝑦

𝐸 𝑆|𝐷, = 6 =)!

π‘₯𝑃 𝑆 = π‘₯|𝐷, = 6

=16

7 + 8 + 9 + 10 + 11 + 12

Intuitively: 6 + 𝐸 𝐷- = 6 + 3.5 = 9.5

=576= 9.5

Let’s prove this!

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Properties of conditional expectation

14

1. LOTUS:

𝐸 𝑔 𝑋 |π‘Œ = 𝑦 =)!

𝑔 π‘₯ 𝑝.|/(π‘₯|𝑦)

2. Linearity of conditional expectation:

𝐸 )01-

2

𝑋0 | π‘Œ = 𝑦 =)01-

2

𝐸 𝑋0|π‘Œ = 𝑦

3. Law of total expectation (next time)

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

It’s been so long, our dice friendsβ€’ Roll two 6-sided dice.β€’ Let roll 1 be 𝐷&, roll 2 be 𝐷'. β€’ Let 𝑆 = value of 𝐷& + 𝐷'.

1. What is 𝐸 𝑆|𝐷' = 6 ?2. What is 𝐸 𝑆|𝐷' ?

A. A function of 𝑆B. A function of 𝐷'C. A number

3. Give an expressionfor 𝐸 𝑆|𝐷' .

15

𝐸 𝑋|π‘Œ = 𝑦 = )!

π‘₯𝑝"|$ π‘₯|𝑦

576= 9.5

πŸ€”

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

It’s been so long, our dice friendsβ€’ Roll two 6-sided dice.β€’ Let roll 1 be 𝐷&, roll 2 be 𝐷'. β€’ Let 𝑆 = value of 𝐷& + 𝐷'.

1. What is 𝐸 𝑆|𝐷' = 6 ?2. What is 𝐸 𝑆|𝐷' ?

A. A function of 𝑆B. A function of 𝐷'C. A number

3. Give an expressionfor 𝐸 𝑆|𝐷' .

16

𝐸 𝑋|π‘Œ = 𝑦 = )!

π‘₯𝑝"|$ π‘₯|𝑦

576= 9.5

𝐸 𝑆|𝐷, = 𝑑, = 𝐸 𝐷- + 𝑑,|𝐷, = 𝑑,

=)3!

𝑑- + 𝑑, 𝑃 𝐷- = 𝑑-|𝐷, = 𝑑,

=)3!

𝑑-𝑃 𝐷- = 𝑑- + 𝑑,)3!

𝑃 𝐷- = 𝑑-

= 𝐸 𝐷- + 𝑑, = 3.5 + 𝑑, 𝐸 𝑆|𝐷' = 3.5 + 𝐷'

(𝐷% = 𝑑%, 𝐷& = 𝑑&independent

events)

(live)14: Conditional ExpectationJerry CainApril 28, 2021

17

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Where are we now? A roadmap of CS109

Last week: Joint distributions𝑝!,# π‘₯, 𝑦

18

Monday: Statistics of multiple RVs!Var 𝑋 + π‘ŒπΈ 𝑋 + π‘ŒCov 𝑋, π‘ŒπœŒ 𝑋, π‘Œ

Today:Conditional distributions

𝑝!|# π‘₯|𝑦𝐸 𝑋|π‘Œ

Time to kick it up a notch!

Friday: Modeling with Bayesian Networks

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Conditional Expectation

19

Conditional Distributions Expectation

Law of Total Expectation

20

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Properties of conditional expectation

21

1. LOTUS:

𝐸 𝑔 𝑋 |π‘Œ = 𝑦 =)!

𝑔 π‘₯ 𝑝.|/(π‘₯|𝑦)

2. Linearity of conditional expectation:

𝐸 )01-

2

𝑋0 | π‘Œ = 𝑦 =)01-

2

𝐸 𝑋0|π‘Œ = 𝑦

3. Law of total expectation:

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ what?!

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Proof of Law of Total Expectation

22

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ

𝐸 𝐸 𝑋|π‘Œ = 𝐸 𝑔 π‘Œ =)"

𝑃 π‘Œ = 𝑦 𝐸 𝑋|π‘Œ = 𝑦 (LOTUS, 𝑔 π‘Œ = 𝐸 𝑋|π‘Œ )

=)"

𝑃 π‘Œ = 𝑦 )!

π‘₯𝑃 𝑋 = π‘₯|π‘Œ = 𝑦(def of

conditional expectation)

=)"

)!

π‘₯𝑃 𝑋 = π‘₯|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦 =)"

)!

π‘₯𝑃 𝑋 = π‘₯, π‘Œ = 𝑦 (chain rule)

=)!

)"

π‘₯𝑃 𝑋 = π‘₯, π‘Œ = 𝑦 =)!

π‘₯)"

𝑃 𝑋 = π‘₯, π‘Œ = 𝑦 (switch order of summations)

=)!

π‘₯𝑃 𝑋 = π‘₯ (marginalization)

= 𝐸 𝑋 …what?

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Another way to compute 𝐸 𝑋

If we only have a conditional PMF of 𝑋 on some discrete variable π‘Œ,we can compute 𝐸 𝑋 as follows:1. Compute expectation of 𝑋 given some value of π‘Œ = 𝑦2. Repeat step 1 for all values of π‘Œ3. Compute a weighted sum (where weights are 𝑃 π‘Œ = 𝑦 )

23

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ

𝐸 𝐸 𝑋|π‘Œ =)"

𝑃 π‘Œ = 𝑦 𝐸 𝑋|π‘Œ = 𝑦 = 𝐸 𝑋

Useful for analyzing recursive code!!

def recurse():if (random.random() < 0.5):

return 3else: return (2 + recurse())

Breakout Rooms

Check out the question on the next slide (Slide 25). Post any clarifications here!https://edstem.org/us/courses/5090/discussion/392856

Breakout rooms: 4 min. Introduce yourself!

24

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Quick check1. 𝐸 𝑋

2. 𝐸 𝑋, π‘Œ

3. 𝐸 𝑋 + π‘Œ

4. 𝐸 𝑋|π‘Œ

5. 𝐸 𝑋|π‘Œ = 6

6. 𝐸 𝑋 = 1

7. 𝐸 π‘Œ|𝑋 = π‘₯

25

A. valueB. one RV, function on π‘ŒC. one RV, function on 𝑋D. two RVs, function on 𝑋 and π‘ŒE. doesn’t make sense

*

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Analyzing recursive code

26

def recurse():# equally likely values 1,2,3x = np.random.choice([1,2,3])if (x == 1): return 3elif (x == 2): return (5 + recurse())else: return (7 + recurse())

Let π‘Œ = return value of recurse().What is 𝐸 π‘Œ ?

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ = )'

𝐸 𝑋|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Analyzing recursive code

27

def recurse():# equally likely values 1,2,3x = np.random.choice([1,2,3])if (x == 1): return 3elif (x == 2): return (5 + recurse())else: return (7 + recurse())

Let π‘Œ = return value of recurse().What is 𝐸 π‘Œ ?

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ = )'

𝐸 𝑋|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦

When 𝑋 = 1, return 3.𝐸 π‘Œ|𝑋 = 1 = 3

𝐸 π‘Œ = 𝐸 π‘Œ|𝑋 = 1 𝑃 𝑋 = 1 + 𝐸 π‘Œ|𝑋 = 2 𝑃 𝑋 = 2 + 𝐸 π‘Œ|𝑋 = 3 𝑃 𝑋 = 3

ThinkSlide 29 has a question to go over by yourself.

Post any clarifications here!https://edstem.org/us/courses/5090/discussion/392856

Think by yourself: 2 min

28

(by yourself)

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

πŸ€”29

Analyzing recursive code

def recurse():# equally likely values 1,2,3x = np.random.choice([1,2,3])if (x == 1): return 3elif (x == 2): return (5 + recurse())else: return (7 + recurse())

Let π‘Œ = return value of recurse().What is 𝐸 π‘Œ ?

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ = )'

𝐸 𝑋|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦If π‘Œ discrete

What is 𝐸 π‘Œ|𝑋 = 2 ?A. 𝐸 5 + π‘ŒB. 𝐸 5 + π‘Œ = 5 + 𝐸 π‘ŒC. 5 + 𝐸 π‘Œ|𝑋 = 2

𝐸 π‘Œ|𝑋 = 1 = 3

𝐸 π‘Œ = 𝐸 π‘Œ|𝑋 = 1 𝑃 𝑋 = 1 + 𝐸 π‘Œ|𝑋 = 2 𝑃 𝑋 = 2 + 𝐸 π‘Œ|𝑋 = 3 𝑃 𝑋 = 3

(by yourself)

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Analyzing recursive code

30

def recurse():# equally likely values 1,2,3x = np.random.choice([1,2,3])if (x == 1): return 3elif (x == 2): return (5 + recurse())else: return (7 + recurse())

Let π‘Œ = return value of recurse().What is 𝐸 π‘Œ ?

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ = )'

𝐸 𝑋|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦If π‘Œ discrete

When 𝑋 = 2, return 5 +a future return value of recurse().

What is 𝐸 π‘Œ|𝑋 = 2 ?A. 𝐸 5 + π‘ŒB. 𝐸 5 + π‘Œ = 5 + 𝐸 π‘ŒC. 5 + 𝐸 π‘Œ|𝑋 = 2

𝐸 π‘Œ|𝑋 = 1 = 3

𝐸 π‘Œ = 𝐸 π‘Œ|𝑋 = 1 𝑃 𝑋 = 1 + 𝐸 π‘Œ|𝑋 = 2 𝑃 𝑋 = 2 + 𝐸 π‘Œ|𝑋 = 3 𝑃 𝑋 = 3

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Analyzing recursive code

31

def recurse():# equally likely values 1,2,3x = np.random.choice([1,2,3])if (x == 1): return 3elif (x == 2): return (5 + recurse())else: return (7 + recurse())

Let π‘Œ = return value of recurse().What is 𝐸 π‘Œ ?

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ = )'

𝐸 𝑋|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦If π‘Œ discrete

𝐸 π‘Œ|𝑋 = 1 = 3 𝐸 π‘Œ|𝑋 = 2 = 𝐸 5 + π‘Œ When 𝑋 = 3, return 7 + a future return value of recurse().

𝐸 π‘Œ|𝑋 = 3 = 𝐸 7 + π‘Œ

𝐸 π‘Œ = 𝐸 π‘Œ|𝑋 = 1 𝑃 𝑋 = 1 + 𝐸 π‘Œ|𝑋 = 2 𝑃 𝑋 = 2 + 𝐸 π‘Œ|𝑋 = 3 𝑃 𝑋 = 3

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Analyzing recursive code

32

def recurse():# equally likely values 1,2,3x = np.random.choice([1,2,3])if (x == 1): return 3elif (x == 2): return (5 + recurse())else: return (7 + recurse())

Let π‘Œ = return value of recurse().What is 𝐸 π‘Œ ?

𝐸 𝑋 = 𝐸 𝐸 𝑋|π‘Œ = )'

𝐸 𝑋|π‘Œ = 𝑦 𝑃 π‘Œ = 𝑦If π‘Œ discrete

𝐸 π‘Œ = 𝐸 π‘Œ|𝑋 = 1 𝑃 𝑋 = 1 + 𝐸 π‘Œ|𝑋 = 2 𝑃 𝑋 = 2 + 𝐸 π‘Œ|𝑋 = 3 𝑃 𝑋 = 3

𝐸 π‘Œ = 3 1/3 + 5 + 𝐸 π‘Œ 1/3 + 7 + 𝐸 π‘Œ 1/3

𝐸 π‘Œ = 1/3 15 + 2𝐸 π‘Œ = 5 + 2/3 𝐸 π‘Œ

𝐸 π‘Œ = 15

𝐸 π‘Œ|𝑋 = 1 = 3 𝐸 π‘Œ|𝑋 = 2 = 𝐸 5 + π‘Œ 𝐸 π‘Œ|𝑋 = 3 = 𝐸 7 + π‘Œ

On your own: What is Var π‘Œ ?

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Independent RVs, defined another wayIf 𝑋 and π‘Œ are independent discrete random variables, then βˆ€π‘₯, 𝑦:

𝑃 𝑋 = π‘₯|π‘Œ = 𝑦 =𝑃 𝑋 = π‘₯, π‘Œ = 𝑦

𝑃 π‘Œ = 𝑦=𝑃 𝑋 = π‘₯ 𝑃 π‘Œ = 𝑦

𝑃 π‘Œ = 𝑦= 𝑃 𝑋 = π‘₯

𝑝!|# π‘₯|𝑦 =𝑝!,# π‘₯, 𝑦𝑝# 𝑦

=𝑝! π‘₯ 𝑝# 𝑦𝑝# 𝑦

= 𝑝! π‘₯

Note for conditional expectation, independent 𝑋 and π‘Œ implies

𝐸 𝑋|π‘Œ = 𝑦 =5%

π‘₯𝑝!|# π‘₯|𝑦 = 5%

π‘₯𝑝! π‘₯ = 𝐸 𝑋

33

Breakout Rooms

Check out the question on the next slide (Slide 35). Post any clarifications here!https://edstem.org/us/courses/5090/discussion/392856

Breakout rooms: 4 min.

34

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Random number of random variablesSay you have a website: BestJokesEver.com. Let:β€’ 𝑋 = # of people per day who visit your site. 𝑋~Bin 100,0.5β€’ π‘Œ0 = # of minutes spent per day by visitor 𝑖 π‘Œ0~Poi 8β€’ 𝑋 and all π‘Œ0 are independent.

The time spent by all visitors per day is . What is 𝐸 π‘Š ?

35

π‘Š =)01-

.

π‘Œ0

𝐸 𝑋|π‘Œ = 𝑦 = 𝐸 𝑋indep 𝑋, π‘Œ

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Random number of random variablesSay you have a website: BestJokesEver.com. Let:β€’ 𝑋 = # of people per day who visit your site. 𝑋~Bin 100,0.5β€’ π‘Œ0 = # of minutes spent by visitor 𝑖. π‘Œ0~Poi 8β€’ 𝑋 and all π‘Œ0 are independent.

The time spent by all visitors per day is . What is 𝐸 π‘Š ?

36

π‘Š =)01-

.

π‘Œ0

𝐸 π‘Š = 𝐸 )01-

.

π‘Œ0 = 𝐸 𝐸 )01-

.

π‘Œ0 |𝑋 Suppose 𝑋 = π‘₯.

𝐸 /!

"

π‘Œ! |𝑋 = π‘₯ =/!#$

"

𝐸 π‘Œ!|𝑋 = π‘₯

=)01-

!

𝐸 π‘Œ0

= π‘₯𝐸 π‘Œ0

(independence)

(linearity)

= 𝐸 𝑋𝐸 π‘Œ0= 𝐸 π‘Œ0 𝐸 𝑋

= 8 β‹… 50

(scalar 𝐸 π‘Œ! )

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

See you next time!

Have a super Wednesday!

37

Extra

38

(no video)

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Hiring software engineersYour company has only one job opening for a software engineer.β€’ n candidates interview, in order (n! orderings equally likely)β€’ Must decide hire/no hire immediately after each interviewStrategy:

What is your target k that maximizes P(get best candidate)?

39

1. Interview k (of n) candidates and reject all k2. Accept the next candidate better than all of first k candidates.

Fun fact:β€’ There is an Ξ±-to-1 factor difference in productivity b/t

the β€œbest” and β€œaverage” software engineer.β€’ Steve jobs said Ξ±=25, Mark Zuckerberg claims Ξ±=100,

some even claim Ξ±=300

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Hiring software engineersYour company has only one job opening for a software engineer.β€’ n candidates interview, in order (n! orderings equally likely)β€’ Must decide hire/no hire immediately after each interviewStrategy:

What is your target k that maximizes P(get best candidate)?

40

Define: X = position of best engineer candidate (1, 2, …, n)B = event that you hire the best engineer

Want to maximize for k: Pk(B) = probability of B when using strategy for a given k

𝑃8 𝐡 = βˆ‘01-2 𝑃8 𝐡|𝑋 = 𝑖 𝑃 𝑋 = 𝑖 = -2βˆ‘01-2 𝑃8 𝐡|𝑋 = 𝑖 (law of total probability)

1. Interview k (of n) candidates and reject all k2. Accept the next candidate better than all of first k candidates.

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Hiring software engineersYour company has only one job opening for a software engineer.Strategy:

What is your target k that maximizes P(get best candidate)?

41

Define: X = position of best engineer candidateB = event that you hire the best engineer

If 𝑖 ≀ π‘˜ : 𝑃8 𝐡|𝑋 = 𝑖 = 0 (we fired best candidate already)Else:

𝑃8 𝐡 = -2βˆ‘01-2 𝑃8 𝐡|𝑋 = 𝑖

=1𝑛 /!#%&$

'π‘˜

𝑖 βˆ’ 1 ß Want to maximize over k

We must not hire prior to the i-th candidate.Γ We must have fired the best of the i–1 first candidates.Γ  The best of the i–1 needs to be our comparison point for positions k+1, …, i–1.Γ  The best of the i–1 needs to be one of our first k comparison/auto-fire

𝑃8 𝐡|𝑋 = 𝑖 =π‘˜

𝑖 βˆ’ 1

1. Interview k (of n) candidates and reject all k2. Accept the next candidate better than all of first k candidates.

Lisa Yan, Chris Piech, Mehran Sahami, and Jerry Cain, CS109, Spring 2021

Hiring software engineers

42

Want to maximize over k:

𝑃8 𝐡 =1𝑛)0189-

2π‘˜

𝑖 βˆ’ 1 =π‘˜π‘›

Jln 𝑖 βˆ’ 10189-

2=π‘˜π‘›ln𝑛 βˆ’ 1π‘˜

β‰ˆπ‘˜π‘›lnπ‘›π‘˜

π‘‘π‘‘π‘˜

π‘˜π‘›lnπ‘›π‘˜

=1𝑛lnπ‘›π‘˜+π‘˜π‘›β‹…π‘˜π‘›β‹…βˆ’π‘›π‘˜,

= 0

Maximize by differentiating w.r.t k , set to 0, solve for k:

lnπ‘›π‘˜= 1 π‘˜ =

𝑛𝑒

1. Interview 2:

candidates2. Pick best based on strategy3. 𝑃8 𝐡 β‰ˆ 1/𝑒 β‰ˆ 0.368

Sum of converging series

β‰ˆπ‘˜π‘›P0189-

2 1𝑖 βˆ’ 1

𝑑𝑖

Your company has only one job opening for a software engineer.Strategy:

What is your target k that maximizes P(get best candidate)?

1. Interview k (of n) candidates and reject all k2. Accept the next candidate better than all of first k candidates.

top related