CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation...

52
CS 109 Lecture 11 April 20th, 2016

Transcript of CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation...

Page 1: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

CS  109Lecture  11

April  20th,  2016

Page 2: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

Review

Page 3: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• X is  a  Normal  Random  Variable:  X ~  N(µ,  σ 2)§ Probability  Density  Function  (PDF):

§

§

§ Also  called  “Gaussian”§ Note:  f(x) is  symmetric  about  µ

∞<<∞−= −− xexf x where2

1)(22 2/)( σµ

πσµ=][XE

2)( σ=XVar)(xf

x

µ

The Normal Distribution

Page 4: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

value

prob

abilit

y

µ

σ2

Simplicity is Humble

*  A  Gaussian  maximizes  entropy  for  a  given  mean  and  variance

Page 5: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Anatomy of a beautiful equation

probability density at x

the distance to the mean

f(x) =1

p2⇡

e

�(x�µ)2

2�2

a constant

“exponential”

sigma shows up twice

N (µ,�2)

Page 6: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

And here we are

Table of Φ(z) values in textbook, p. 201 and handout

F (x) = �

✓x� µ

CDF of Standard Normal: A function that has been solved

for numerically

The cumulative density function

(CDF) of any normal

N (µ,�2)

Page 7: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Symmetry of Phi

a-a

ɸ(-a)

1 – ɸ(a)

ɸ(-a) = 1 – ɸ(a)

µ = 0

Page 8: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Interval of Phi

dc

ɸ(c)ɸ(d)

µ = 0

Page 9: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Interval of Phi

dc

ɸ(c)ɸ(d)

ɸ(d) - ɸ(c)

µ = 0

Page 10: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

Great  in  class  questions

Page 11: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

68%  rule  only  for  Gaussians?

Page 12: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

68% Rule?

Only applies to normal

P (µ� � < X < µ+ �) = P

✓µ� � � µ

�<

X � µ

�<

µ+ � � µ

= P (�1 < Z < 1)

= �(1)� �(�1)

= �(1)� [1� �(1)]

= 2�(1)� 1

= 2[0.8413]� 1 = 0.683

What  is  the  probability   that  a  normal  variable  has  a  value  within  one  standard  deviation  of  its  mean?  

X ⇠ N(µ,�2)

P (µ� � < X < µ+ �) = P

✓µ� � � µ

�<

X � µ

�<

µ+ � � µ

= P (�1 < Z < 1)

= �(1)� �(�1)

= �(1)� [1� �(1)]

= 2�(1)� 1

= 2[0.8413]� 1 = 0.683

P (µ� � < X < µ+ �) = P

✓µ� � � µ

�<

X � µ

�<

µ+ � � µ

= P (�1 < Z < 1)

= �(1)� �(�1)

= �(1)� [1� �(1)]

= 2�(1)� 1

= 2[0.8413]� 1 = 0.683

P (µ� � < X < µ+ �) = P

✓µ� � � µ

�<

X � µ

�<

µ+ � � µ

= P (�1 < Z < 1)

= �(1)� �(�1)

= �(1)� [1� �(1)]

= 2�(1)� 1

= 2[0.8413]� 1 = 0.683

P (µ� � < X < µ+ �) = P

✓µ� � � µ

�<

X � µ

�<

µ+ � � µ

= P (�1 < Z < 1)

= �(1)� �(�1)

= �(1)� [1� �(1)]

= 2�(1)� 1

= 2[0.8413]� 1 = 0.683

P (µ� � < X < µ+ �) = P

✓µ� � � µ

�<

X � µ

�<

µ+ � � µ

= P (�1 < Z < 1)

= �(1)� �(�1)

= �(1)� [1� �(1)]

= 2�(1)� 1

= 2[0.8413]� 1 = 0.683

Page 13: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

68% Rule?Counter  example:  Uniform   X ⇠ Uni(↵,�)

V ar(X) =(� � ↵)2

12

� =pV ar(X)

=� � ↵p

12

2�

1

� � ↵

↵�

=1

� � ↵

2(� � ↵)p

12

= 0.58

P (µ� � < X < µ+ �)

=2p12

=1

� � ↵

2(� � ↵)p

12

= 0.58

Page 14: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

How  do  you  sample  from  a  Gaussian?

Page 15: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

How Does a Computer Sample Normal?

Further reading: Box–Muller transform

Inverse Transform Sampling

50-5

1

CDF of the Standard Normal

�(x)

pick

a u

nifo

rm n

umbe

r ybe

twee

n 0,

1

Find the x such that �(x) = y

Page 16: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

Where  we  left  off…

Page 17: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Normal Approximates Binomial

There  is  a  deep  reason  for  the  Binomial/Normal   approximation…

Page 18: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Stanford  accepts  2480  students§ Each  accepted  student  has  68%  chance  of  attending§ X  =  #  students  who  will  attend.      X  ~  Bin(2480,  0.68)§ What  is  P(X  >  1745)?

§ Use  Normal  approximation:  Y  ~  N(1686.4,  539.65)

§ Using  Binomial:

)5.1745()1745( >≈> YPXP

23.23165.53914.1686 – p)np( – p) np( np ≈≈=

( ) 0055.0)54.2(1)5.1745( 23.234.16865.1745

23.234.1686 ≈Φ−=>=> −−YPYP

0053.0)1745( ≈>XP

Stanford Admissions

Page 19: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Stanford  Daily,  March  28,  2014“Class  of  2018  Admit  Rates  Lowest  in  University  History”  by  Alex  Zivkovic

“Fewer  students  were  admitted  to  the  Class  of  2018  than  the  Class  of  2017,  due  to  the  increase  in  Stanford’s  yield  rate  which  has  increased  over  5  percent  in  the  past  four  years,  according  to  Colleen  Lim  M.A.  ’80,  Director  of  Undergraduate  Admission.”

Changes in Stanford Admissions

68% 10 years ago 80% last year

Page 20: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

Next  distribution:  Exponential

Page 21: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• X is  an  Exponential  RV:  X ~  Exp(λ)      Rate:  λ >  0§ Probability  Density  Function  (PDF):

§

§

§ Cumulative  distribution  function  (CDF),  F(X)  =  P(X ≤ x):

§ Represents   time  until  some  evento Earthquake,  request  to  web  server,  end  cell  phone  contract,  etc.

∞<<∞−⎩⎨⎧

<

≥=

xxxe

xfx

where0 if00 if

)(λλ

λ1][ =XE

2

1)(λ

=XVar

)(xf

x

0 where1)( ≥−= − xexF xλ

Exponential Random Variable

Page 22: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• X  =  time  until  some  event  occurs§ X  ~  Exp(λ)§ What  is  P(X  >  s  +  t  |  X  >  s)?

§ After  initial  period  of  time s,  P(X  >  t  |  •)  for  waiting  another  t units  of  time  until  event  is  same  as  at  start

§ “Memoryless”  =  no  impact  from  preceding  period  s

)()(

)() and ()|(

sXPtsXP

sXPsXtsXPsXtsXP

>

+>=

>

>+>=>+>

)()(1)(1)(1

)()( )(

tXPtFeee

sFtsF

sXPtsXP t

s

ts

>=−===−

+−=

>

+> −−

+−λ

λ

λ

)()|( So, tXPsXtsXP >=>+>

Exponential is Memoryless

Page 23: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

E[X]  and  Var(X)  for  exponential

Page 24: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Product  rule  for  derivatives:

• Derivative  and  integral  of  exponential:

• Integration  by  parts:

dvuvduvud ⋅+⋅=⋅ )(

dxdue

dxed uu

=)(

∫∫∫ ⋅+⋅=⋅=⋅ dvuduvvuvud )(

∫∫ ⋅−⋅=⋅ duvvudvu

uu edue =∫

A Little Calculus Review

Page 25: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Compute  n-­th  moment  of  Exponential  distribution

§ Step  1:  don’t  panic,  think  happy  thoughts,  recall...§ Step  2:  find  u and  v (and  du and  dv):

§ Step  3:  substitute  (a.k.a.  “plug  and  chug”)

∫∞

−=0

][ dxexXE xnn λλ

xn evxu λ−−== dxedvdxnxdu xn λλ −− == 1

∫∫∫∫ −−−− +−=⋅−⋅=⋅=⋅ dxenxexduvvudxexdvu xnxnxn λλλλ 1

][0][ 111

0−−−−−− =+=+−= ∫∫

∞ nxnxnxnn XEdxexdxenxexXE nnλλ

λλλ λ

,... ][ ][ so ,1]1[][ :case Base 220 212,1

λλλλ ===== XEXEEXE

And Now, Calculus Practice

Page 26: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Say  visitor  to  your  web  site  leaves  after  X  minutes§ On  average,  visitors  leave  site  after  5  minutes§ Assume  length  of  stay  is  Exponentially  distributed§ X  ~  Exp(λ =  1/5),      since  E[X]  =  1/λ =  5§ What  is  P(X  >  10)?

§ What  is  P(10  <  X  <  20)?

1353.0)1(1)10(1)10( 210 ≈=−−=−=> −− eeFXP λ

1170.0)1()1()10()20()2010( 24 ≈−−−=−=<< −− eeFFXP

Visits to a Website

Page 27: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• X  =  #  hours  of  use  until  your  laptop  dies§ On  average,  laptops  die  after  5000  hours  of  use§ X  ~  Exp(λ =  1/5000),      since  E[X]  =  1/λ =  5000§ You  use  your  laptop  5  hours/day.    § What  is  P(your  laptop  lasts  4  years)?§ That  is:  P(X  >  (5)(365)(4)  =  7300)

§ Better  plan  ahead...    especially   if  you  are  coterming:

2322.0)1(1)7300(1)7300( 46.15000/7300 ≈=−−=−=> −− eeFXP

plan)year (5 1612.0)9125(1)9125( 825.1 ≈=−=> −eFXPplan)year (6 1119.0)10950(1)10950( 19.2 ≈=−=> −eFXP

Replacing Your Laptop

Page 28: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Continuous Random Variables

Uniform  Random  VariableAll  values  of  x between  alpha  and  beta  are  equally  likely.

Normal  Random  VariableAka  Gaussian.  Defined  by  mean  and  variance.  Goldilocks  distribution.

Exponential  Random  VariableTime  until  an  event  happens.  Parameterized  by  lambda  (same  as  Poisson).

Alpha  Beta  Random  VariableHow  mysterious  and  curious.  You  must  wait  a  few  classes  J.

X ⇠ Uni(↵,�)

X ⇠ N (µ,�2)

X ⇠ Exp(�)

Page 29: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

Joint  Distributions

Page 30: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

Events  occur  with  other  events

Page 31: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• For  two  discrete  random  variables  X and  Y,  the                        Joint  Probability  Mass  Function is:

• Marginal  distributions:

• Example:  X  =  value  of  die  D1,  Y  =  value  of  die  D2

),(),(, bYaXPbap YX ===

∑===y

YXX yapaXPap ),()()( ,

∑===x

YXY bxpbYPbp ),()()( ,

61

3616

1

6

1, ),1()1( ==== ∑∑

== yyYX ypXP

Discrete Joint Mass Function

Page 32: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Probability Table• States  all  possible  outcomes  with  several  discrete  variables• Often  is  not  “parametric”• If  #variables   is  >  2,  you  can  have  a  probability   table,  but  you  can’t  draw  it  on  a  slide

All  values  of  A

All  values  of  B

a

b P(A = a, B = b)

Remember “,” means “and”

Every outcome falls into a bucket

Page 33: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

It’s Complicated Demo

Go  to  this  URL:  https://goo.gl/ZNRsqD

Page 34: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Consider  households  in  Silicon  Valley§ A  household  has  C  computers:  C  =  X  Macs  +  Y  PCs§ Assume  each  computer  equally   likely  to  be  Mac  or  PC

⎪⎪⎩

⎪⎪⎨

=

=

=

=

==

332.0228.0124.0016.0

)(

cccc

cCP

XY 0 1 2 3 pY(y)

0 0.16 0.12 ? 0.04

1 0.12 0.14 0.12 0

2 0.07 0.12 0 0

3 0.04 0 0 0

pX(x)

A Computer (or Three) In Every House

Page 35: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Consider  households  in  Silicon  Valley§ A  household  has  C  computers:  C  =  X  Macs  +  Y  PCs§ Assume  each  computer  equally   likely  to  be  Mac  or  PC

⎪⎪⎩

⎪⎪⎨

=

=

=

=

==

332.0228.0124.0016.0

)(

cccc

cCP

XY 0 1 2 3 pY(y)

0 0.16 0.12 0.07 0.04

1 0.12 0.14 0.12 0

2 0.07 0.12 0 0

3 0.04 0 0 0

pX(x)

A Computer (or Three) In Every House

Page 36: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Consider  households  in  Silicon  Valley§ A  household  has  C  computers:  C  =  X  Macs  +  Y  PCs§ Assume  each  computer  equally   likely  to  be  Mac  or  PC

⎪⎪⎩

⎪⎪⎨

=

=

=

=

==

332.0228.0124.0016.0

)(

cccc

cCP

XY 0 1 2 3 pY(y)

0 0.16 0.12 0.07 0.04 0.39

1 0.12 0.14 0.12 0 0.38

2 0.07 0.12 0 0 0.19

3 0.04 0 0 0 0.04

pX(x) 0.39 0.38 0.19 0.04 1.00

Marginal  distributions

A Computer (or Three) In Every House

Page 37: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• This  is  a  joint

• A  joint  is  not  a  mathematician§ It  did  not  start  doing  mathematics  at  an  early  age§ It  is  not  the  reason  we  have  “joint  distributions”§ And,  no,  Charlie  Sheen  does  not  look  like  a  joint

o But  he  does  have  them…o He  also  has  joint custody  of  his  children  with  Denise  Richards

Joint

Page 38: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

What  about  the  continuous  world?

Page 39: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Random  variables  X and  Y,  are  Jointly  Continuous if  there  exists  PDF  fX,Y(x, y) defined  over  –∞ < x, y < ∞ such  that:

∫ ∫=≤<≤<2

1

2

1

),( ) ,(P ,2121

a

a

b

bYX dxdyyxfbYbaXa

Jointly Continuous

Let’s  look  at  one:

Page 40: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Jointly Continuous

∫ ∫=≤<≤<2

1

2

1

),( ) ,(P ,2121

a

a

b

bYX dxdyyxfbYbaXa

a1

a2b2

b1

fX,Y (x, y)

x

y

Page 41: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Cumulative  Density  Function  (CDF):

• Marginal  density  functions:

∫ ∫∞− ∞−

=a b

YXYX dxdyyxfbaF ),( ),( ,, ),(),( ,

2

, baFbaf YXYX ba ∂∂∂=

∫∞

∞−

= dyyafaf YXX ),()( , ∫∞

∞−

= dxbxfbf YXY ),()( ,

Jointly Continuous

Page 42: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• For  two  continuous  random  variables  X and  Y,  the                        Joint  Cumulative  Probability  Distribution is:

• Marginal  distributions:

∞<<∞−≤≤== babYaXPbaFbaF YX , where),(),(),(,

),(),P( )()( , ∞=∞<≤=≤= aFYaXaXPaF YXX

),(),P( )()( , bFbYXbYPbF YXY ∞=≤∞<=≤=

Continuous Joint Distribution Functions

Page 43: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Joint Dart Distribution

0

y

x900

900

Page 44: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Darts!

X-Pixel Marginal

y

xY-Pixel Marginal

X ⇠ N✓900

2,900

2

◆Y ⇠ N

✓900

3,900

5

Page 45: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Let  X and  Y be  two  continuous  random  variables§ where  0  ≤  X ≤  1  and  0  ≤  Y ≤  2

• We  want  to  integrate  g(x,y)  =  xy w.r.t.  X and  Y:§ First,  do  “innermost”  integral  (treat  y as  a  constant):

§ Then,  evaluate  remaining  (single)  integral:

∫∫∫ ∫∫ ∫=== == =

=⎥⎦

⎤⎢⎣

⎡=⎟

⎟⎠

⎞⎜⎜⎝

⎛=

2

0

2

0

22

0

1

0

2

0

1

0 21

2

0

1

yyy xy x

dyydyxydydxxydydxxy

101 42

10

222

0

=−=⎥⎦

⎤⎢⎣

⎡=∫

=

ydyyy

Multiple Integrals Without Tears

Page 46: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Let  FX,Y (x, y) be  joint  CDF  for  X and  Y

)),((1) ,P( cbYaXPbYaX >>−=>>

),()()(1 , baFbFaF YXYX +−−=

))()((1 cc bYaXP >∪>−=))()((1 bYaXP ≤∪≤−=

)),()()((1 bYaXPbYPaXP ≤≤−≤+≤−=

Computing Joint Probabilities

Page 47: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

),(),(),(),( ) ,(P

12112122

2121

baFbaFbaFbaFbYbaXa

−+−=

≤<≤<

1a 2a

2b1b

The General Rule Given Joint CDFLet  FX,Y (x, y) be  joint  CDF  for  X and  Y

Page 48: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Y is  a  non-­negative continuous  random  variable§ Probability  Density  Function:    fY(y)§ Already  knew  that:

§ But,  did  you  know  that:

?!?

§ Analogously,   in  the  discrete  case,  where  X =  1,  2,  …,  n

dyyfyYE Y∫∞

∞−

= )( ][

dy yYPYE ∫∞

>=0

)(][

∑=

≥=n

iiXPXE

1

)(][

Lovely Lemma

Page 49: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

In  the  discrete  case,  where  X =  1,  2,  …,  n

∑=

≥=n

iiXPXE

1

)(][

How this lemma was made

P (X = 1) + P (X = 2) + P (X = 3) + · · ·+ P (X = n)

P (X = 2) + P (X = 3) + · · ·+ P (X = n)P (X = 3) + · · ·+ P (X = n)

P (X = n)

...

+

+

+

nX

i=1

P (X � i) =

= 1P (X = 1) + 2P (X = 2) + · · ·+ n(PX = n)

= E[X]

Each row is an expansion of

Page 50: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

Four Prototypical Trajectories

Life  gives  you  lemmas,make  lemmanade!

Page 51: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Disk  surface  is  a  circle  of  radius  R§ A  single  point  imperfection  uniformly  distributed  on  disk

∞<<∞−⎪⎩

⎪⎨⎧

>+

≤+= x,y

Ryx

Ryxyxf RYX where

if 0

if),(

222

2222

,

Imperfections on a Disk

f

X

(x) =

Z 1

�1f

X,Y

(x, y)dy =1

R

2

Z

x

2+y

2R

2

dy

=1

R

2

Z pR

2�x

2

�pR

2�x

2

dy

=2pR

2 � x

2

⇡R

2

f

X

(x) =

Z 1

�1f

X,Y

(x, y)dy =1

R

2

Z

x

2+y

2R

2

dy

=1

R

2

Z pR

2�x

2

�pR

2�x

2

dy

=2pR

2 � x

2

⇡R

2

f

X

(x) =

Z 1

�1f

X,Y

(x, y)dy =1

R

2

Z

x

2+y

2R

2

dy

=1

R

2

Z pR

2�x

2

�pR

2�x

2

dy

=2pR

2 � x

2

⇡R

2

Only integrate over the support range

Marginal of Y is the same by symmetry

Page 52: CS#109 Lecture#11 April#20th,2016 - Stanford University · Anatomy of a beautiful equation probability density at x the distance to the mean f (x)= 1 p 2⇡ e (xµ)2 22 a constant

• Disk  surface  is  a  circle  of  radius  R§ A  single  point  imperfection  uniformly  distributed  on  disk§ Distance  to  origin:§ What  is  E[D]?                                              

22 YXD +=

2

2

2

2

)( Ra

RaaDP ==≤

ππ

Imperfections on a Disk

Ra Because of

equally likely outcomes

E[D] =

Z R

0P (D > a)da =

Z R

01� P (D a)da

=

Z R

01� a2

R2da

=

a� a3

3R2

�R

0

=2R

3

E[D] =

Z R

0P (D > a)da =

Z R

01� P (D a)da

=

Z R

01� a2

R2da

=

a� a3

3R2

�R

0

=2R

3

E[D] =

Z R

0P (D > a)da =

Z R

01� P (D a)da

=

Z R

01� a2

R2da

=

a� a3

3R2

�R

0

=2R

3

E[D] =

Z R

0P (D > a)da =

Z R

01� P (D a)da

=

Z R

01� a2

R2da

=

a� a3

3R2

�R

0

=2R

3

E[D] =

Z R

0P (D > a)da =

Z R

01� P (D a)da

=

Z R

01� a2

R2da

=

a� a3

3R2

�R

0

=2R

3