lecture 03: intro to probability - stanford university · intro to probability lisa yan june 29,...

38
Lecture 03: Intro to Probability Lisa Yan June 29, 2018

Upload: others

Post on 06-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Lecture03:IntrotoProbabilityLisaYanJune29,2018

Page 2: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Announcements

PS1:dueFriday7/6◦ Coversmaterialuptoandincludingtoday

Pythontutorialonwebsite

Officehourshavestarted!◦ SCPD-supportedhoursaremarkedoncalendar

2

Page 3: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

SummaryofCombinatorics

3

Countingoperationsonn objects

Orderedpermutations

Choosekcombinations Putinr buckets

Distinguishable

Someindistinguishable

n!

n1!n2! . . .n!

Distinguish-able

Indis-tinguishable

rn(n+ r � 1)!

n!(r � 1)!

Distinguishable

1group r groups✓n

k

◆=

n!

k!(n� k)!

Page 4: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

DNAdistance

ForaDNAtreeweneedtocalculatetheDNAdistancebetweeneachpairofanimals.Howmanycalculationsareneeded?

à Howmanydistinctpairsofn animalsarethere?

4

✓n

2

𝑛2 =

𝑛% − 𝑛2n

Page 5: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Goalsfortoday

Probability◦ Samplespacesandevents◦AxiomsofProbability◦ CorollariesofAxiomsofProbability◦ EquallyLikelyOutcomes

5

”Startedfromthebottomnowwe’rehere”– Drake,2013

TheendofCS109

Countinghere

Page 6: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Samplespaces

Thesamplespace,S,isthesetofallpossibleoutcomesofanexperiment.

Examples:• Coinflip: S={Head,Tails}• Flippingtwocoins: S={(H,H),(H,T),(T,H),(T,T)}• Rollof6-sideddie: S={1,2,3,4,5,6}• #emailsinaday: S={x|xÎ ℤ,x≥0}(non-negativeintegers)• YouTubehrs.inday: S={x|xÎ ℝ,0≤x≤24}

6

Page 7: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Events

Anevent,E,issomesubsetofS (EÍ S).

Examples:• Coinflipisheads: E={Head}• ≥1headon2coinflips: E={(H,H),(H,T),(T,H)}• Rollofdieis3orless: E={1,2,3}• #emailsinaday£ 20: E={x |x Î ℤ,0£ x £ 20}• Wastedday(≥5YThrs.): E={x |x Îℝ,5£ x £ 24}

7

Page 8: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Setoperationsonevents

SaythatEandFareeventsinS.

8

E F

S

Page 9: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Unionofevents

DefinetheneweventEÈ FastheunionofeventsEandF,whichcontainsalloutcomesthatareinEor F.

9

E F

S

E È F

• S={1,2,3,4,5,6} dierolloutcome• E={1,2} F={2,3}• EÈ F={1,2,3}

Page 10: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Intersectionofevents

DefinetheneweventEÇ FastheintersectionofeventsEandF,whichcontainsalloutcomesthatareinbothEand F.

10

E F

S

E Ç F aka EF• S={1,2,3,4,5,6} dierolloutcome• E={1,2} F={2,3}• EF={2}

Note: mutuallyexclusiveeventsmeansthatEÇ F =EF=Æ

Page 11: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Complementofanevent

DefinetheneweventEc thecomplementoftheeventE,whichcontainsalloutcomesthatarenot inE.

11

E F

S

Ec or ~E• S={1,2,3,4,5,6} dierolloutcome• E={1,2}• Ec ={3,4,5,6}

Page 12: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

DeMorgan’s Laws

12

(E È F)c = Ec Ç Fc E F

S

!"n

i

ci

cn

ii EE

11 ==

=÷÷ø

öççè

æ

E F

S

(E Ç F)c = Ec È Fc !"n

i

ci

cn

ii EE

11 ==

=÷÷ø

öççè

æ

Generalform

Page 13: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

13

Whatisaprobability?

Page 14: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

DefinitionofProbability

14

Anumberbetween0and1towhichweascribemeaning.

Page 15: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

DefinitionofProbability

15

P (E) = limn!1

n(E)

n

*OurbeliefthataneventEoccurs.

Page 16: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🙆

AxiomsofProbability

Axiom1: 0£ P(E) £ 1

Axiom2: P(S) =1

Axiom3: IfE andFmutuallyexclusive (EÇ F=Æ),then P(E)+ P(F)= P(EÈ F)

Foranysequenceofmutuallyexclusiveevents E1,E2,...

16

å¥

=

¥

=

=÷÷ø

öççè

æ

11

)(i

ii

i EPEP !(liketheSumRuleofCounting,butforprobabilities)

P (E) = limn!1

n(E)

n

Page 17: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🙆

CorollariesofAxioms

17

1. P(Ec)=1– P(E) (=P(S)– P(E) )

2. IfE Í F,thenP(E) £ P(F)

3. P(EÈ F)=P(E)+P(F)– P(EF)

GeneralformofInclusion-ExclusionIdentity:

Inclusion-ExclusionPrincipleforProbability

𝑃 ∪+

,-.𝐸, = ∑ −1 23.+

2-. ∑ 𝑃 ∩2

5-.𝐸,6

�,89⋯9,;

Page 18: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

GeneralformofInclusion-Exclusion

P(EÈ FÈ G)

=P(E) +P(F) +P(G)

– P(EÇ F)– P(EÇ G)– P(FÇ G)

+P(EÇ FÇ G)

18

Includeeachspaceexactlyonce.

𝑃 ∪+

,-.𝐸, = ∑ −1 23.+

2-. ∑ 𝑃 ∩2

5-.𝐸,6

�,89⋯9,;

E

F G

r =1

r =2

r =3

Page 19: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🤔

SelectingProgrammers• P(studentprogramsinJava)=0.28• P(studentprogramsinPython)=0.07• P(studentprogramsinJavaandPython)=0.05.

WhatisP(studentdoesnotprogramin(JavaorPython))?

19

Define: A=eventthatstudentprogramsinJavaB =eventthatstudentprogramsinPython

Wanttofind(WTF): P((A È B)c) =1– P(A È B)=1– [P(A)+P(B)– P(A Ç B)]=1– (0.28+0.07– 0.05)=0.7à 70%

P(studentprogramsinPython,butnotJava)?P(AcÇ B)=P(B)– P(A Ç B)=0.07– 0.05=0.02à 2%

Solution:

=P(A)=P(B)=P(AÇ B)

Page 20: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🙆

EquallyLikelyOutcomes

Somesamplespaceshaveequallylikelyoutcomes• Coinflip: S={Head,Tails}• Flippingtwocoins: S={(H,H),(H,T),(T,H),(T,T)}• Rollof6-sideddie: S={1,2,3,4,5,6}

P(Eachoutcome)=

Inthatcase,P(E)= =

20

||1SnumberofoutcomesinEnumberofoutcomesinS ||

||SE (byAxiom3of

probability)

Page 21: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Rollingtwodice

Rolltwo6-sideddice. WhatisP(sum=7)?

21

6/36=1/6

Solution:

Problem:

S={(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(2,1),(2,2),(2,3),(2,4),(2,5),(2,6),(3,1),(3,2),(3,3),(3,4),(3,5),(3,6),(4,1),(4,2),(4,3),(4,4),(4,5),(4,6),(5,1),(5,2),(5,3),(5,4),(5,5),(5,6),(6,1),(6,2),(6,3),(6,4),(6,5),(6,6)}

E={(1,6),(2,5),(3,4),(4,3),(5,2),(6,1)}

Page 22: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

11outcomesforrollingasum:{2,3,4,5,6,7,8,9,10,11,12}

7isonlyoneoftheseoutcomes,so

Rollingtwodicethewrongway

Rolltwo6-sideddice. WhatisP(sum=7)?

22

...

(wrong)

WrongSolution:

Problem:

LesslikelyMorelikely

Page 23: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Break!Attendance: tinyurl.com/cs109summer2018

23

Page 24: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🤔

Catsandcarrots

4catsand3carrotsinabag.3drawn.

WhatisP(1catsand2carrotsdrawn)?

24

Problem:

Consider:

Whatisthesamplespacethatwillgiveyouequallylikelyoutcomes?

Page 25: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Catsandcarrots

4catsand3carrotsinabag.3drawn.

WhatisP(1catand2carrotsdrawn)?

25

Definesamplespace:|S|=7x6x5=210

Validevents:|E|= (4 x3x2) + (3x4 x2) + (3x2x4) =72

(cat as#1) (cat as#2) (cat as#3)

P(1cat,2carrots)=|E|/|S|=72/210=12/35

Problem:

Solution1:Orderedlistof3distinguishableobjects

Page 26: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Catsandcarrots

4catsand3carrotsinabag.3drawn.

WhatisP(1catsand2carrotsdrawn)?

26

Definesamplespace:

|S|==35

Validevents:

|E|= =12

Problem:

Solution2:

÷÷ø

öççè

æ37

÷÷ø

öççè

æ÷÷ø

öççè

æ23

14

P(1cats,2carrots)=|E|/|S|=12/35

(choosethecat)

(choosethe2carrots)

Unorderedsetof3distinguishableobjects

Page 27: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🙆

Youoftenmakeindistinguishableitemsdistinguishableinordertogetequallylikely

samplespaceoutcomes.

27

Page 28: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

ChipDefectDetectionn chipsaremanufactured,1ofwhichisdefective.k chipsarerandomlyselectedfromn fortesting.

WhatisP(defectivechipisink selectedchips?)

28

|S|= +<|E|= ..

+=.<=.

P(defectivechipink selectedchips)=P(E)

Solution:

=𝑛 − 1𝑘 − 1𝑛𝑘

=

𝑛 − 1 !𝑘 − 1 ! 𝑛 − 𝑘 !

𝑛!𝑘! 𝑛 − 𝑘 !

=𝑛 − 1 !𝑘!𝑛! 𝑘 − 1 ! =

𝑘𝑛 =

𝑛 − 1 !𝑘 − 1 ! 𝑛 − 𝑘 !

𝑛!𝑘! 𝑛 − 𝑘 !

=𝑛 − 1 !𝑘!𝑛! 𝑘 − 1 ! =

𝑘𝑛

Page 29: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

ChipDefectDetection

n chipsaremanufactured,1ofwhichisdefective.k chipsarerandomlyselectedfromn fortesting.

WhatisP(defectivechipisink selectedchips?)

29

1. Choosekchips.

2. Throwadartandmakeonedefective.

P(defectiveoneinkselectedchips)=

Solution:

Problem:

𝑘𝑛

Page 30: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🤔

AnyStraightinPoker

Consider5cardpokerhands.

• “straight”is5consecutiverankcardsofanysuit

• WhatisP(straight)?

30

|S|= ?%?

|E|=10 A.?

P(straight)=÷÷ø

öççè

æ

÷÷ø

öççè

æ

55214

105

Solution:

Problem:

» 0.00394

Page 31: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🤔

“Official”StraightinPoker

Consider5cardpokerhands.• “straight”is5consecutiverankcardsofanysuit• “straightflush”is5consecutiverankcardsofsame suit• WhatisP(straightbutnotstraightflush)?

31

|S|= ?%?

|E|=10 A.?− 10 A

.

P(straightbutnotstraightflush)=

Solution:

Problem:

» 0.0039210 A.?− 10 A

.525

Page 32: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🤔

Ina52carddeck,cardsareflippedoneatatime.Afterthefirstace(ofanysuit)appears,considerthenextcard.

IsP(nextcard=AceSpades)<P(nextcard=2Clubs)?

CardFlipping

Youmightthinksoinitially,but…|S|=52!(shufflingcards)

Case1: EAS =nextcardisAceSpades1. TakeoutAceofSpades.2. Shuffleleftover51cards.3. AddAceSpadesafterfirstace.|EAS|=51!1

Solution:

Case2: E2C =nextcardisTwoClubs1. Takeout2Clubs.2. DothesamethingasCase13. Butwith2Clubsinstead.

|E2C|=51!1P(EAS)= P(EAS)

Page 33: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🙆

ItisofteneasiertocalculateP(Ec).

33

𝑃 𝐴 ∪ 𝐵 ∪⋯∪ 𝑍 = 1 − 𝑃 𝐴J𝐵J ⋯𝑍J DeMorgan’s:

Page 34: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🤔

TheBirthdayParadox ProblemWhatistheprobabilitythatinasetofn people,atleastone pairofthemwillsharethesamebirthday?

34

P(atleastonepairsharesbirthday)=P(E)=1– P(noonesharesabirthday)=1– P(Ec)

P(noonesharesabirthday)=P(Ec):|Ec|={allwaysthatn peoplecanhavedifferentbirthdays}

= (365)(364)...(365– n+1)= KL?n n!|S|={allwaysn peoplecanhaveanybirthdays}=365n

P(nomatchingbirthdays)=|Ec|/|S|=

Solution:

Shoutouttoyou,NPR…

365𝑛 ⋅ 𝑛!365+

Page 35: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

🤔

TheBirthdayParadox Problem

Whatistheprobabilitythatinasetofn people,atleastone pairofthemwillsharethesamebirthday?

35

P(nomatchingbirthdays)=P(Ec)=|Ec|/|S|=P(atleastonepairsharesabirthday)=1– P(noonesharesabirthday)

P(E)=1– P(Ec)=1–n =23: P(E)>½n =75: P(E)>1– 1/3,000=0.9997n =100: P(E)>1– 1/3,000,000=0.9999997n=150: P(E)>1– 1/3,000,000,000,000,000

Solution: 365𝑛 ⋅ 𝑛!365+

365𝑛 ⋅ 𝑛!365+

ByPigeonholeprinciple,wewouldneed366peopletoreach100%!

Page 36: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

TheHarderBirthdayProblem

Whatistheprobabilitythatofn otherpeople,someonehasthesamebirthdayasyou?

36

P(someonehasyourbirthday)=P(E)=1– P(Ec)|Ec|={allwaysthatnoonehasyourbirthday}=364n|S|=365n

n =23: P(E)» 0.0612n =150: P(E)» 0.3374n =253: P(E) » 0.5005

Solution:

Problem:

P(E)=1– 364n/365n

Whyaretheseprobabilitiesmuchhigherthanbefore?• AnyonebornonJune22nd?• Istodayanyone’sbirthday?

Page 37: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Summary

Samplespace,S:Thesetofallpossibleoutcomesofanexperiment.Eventspace,E:AsubsetofS.Ifwehaveequallylikelyoutcomes,thenP(E)=|E|/|S|.

Twokeytacticstocountingprobabilities:• Wecantreatindistinctobjectsasdistinctifithelpscreateequallylikely

outcomes.• DeMorgan’s lawandcalculatingP(Ec)helpsusavoidtrickycounting

situations.

37

Page 38: Lecture 03: Intro to Probability - Stanford University · Intro to Probability Lisa Yan June 29, 2018. Announcements PS1: due Friday 7/6 Covers material up to and including today

Summary

IndividualProblemswithChance: P1,P2,… PnAnyproblemswithChance: P1È P2È … È PnEventE:noproblems

E =(P1È P2È … È Pn)c

Don’twantnoproblems:Ec =((P1È P2È … È Pn)c)c

=P1È P2È … È Pn

38

”Youdon’twantnoproblems,wantnoproblemswithme”– ChancetheRapper,2016

Wewantproblemswithyou,Chance!!!