Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
Lecture03:IntrotoProbabilityLisaYanJune29,2018
Announcements
PS1:dueFriday7/6◦ Coversmaterialuptoandincludingtoday
Pythontutorialonwebsite
Officehourshavestarted!◦ SCPD-supportedhoursaremarkedoncalendar
2
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)!
DNAdistance
ForaDNAtreeweneedtocalculatetheDNAdistancebetweeneachpairofanimals.Howmanycalculationsareneeded?
à Howmanydistinctpairsofn animalsarethere?
4
✓n
2
◆
𝑛2 =
𝑛% − 𝑛2n
Goalsfortoday
Probability◦ Samplespacesandevents◦AxiomsofProbability◦ CorollariesofAxiomsofProbability◦ EquallyLikelyOutcomes
5
”Startedfromthebottomnowwe’rehere”– Drake,2013
TheendofCS109
Countinghere
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
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
Setoperationsonevents
SaythatEandFareeventsinS.
8
E F
S
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}
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=Æ
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}
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
13
Whatisaprobability?
DefinitionofProbability
14
Anumberbetween0and1towhichweascribemeaning.
DefinitionofProbability
15
P (E) = limn!1
n(E)
n
*OurbeliefthataneventEoccurs.
🙆
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
🙆
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,;
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
🤔
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)
🙆
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)
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)}
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
Break!Attendance: tinyurl.com/cs109summer2018
23
🤔
Catsandcarrots
4catsand3carrotsinabag.3drawn.
WhatisP(1catsand2carrotsdrawn)?
24
Problem:
Consider:
Whatisthesamplespacethatwillgiveyouequallylikelyoutcomes?
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
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
🙆
Youoftenmakeindistinguishableitemsdistinguishableinordertogetequallylikely
samplespaceoutcomes.
27
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 ! =
𝑘𝑛
ChipDefectDetection
n chipsaremanufactured,1ofwhichisdefective.k chipsarerandomlyselectedfromn fortesting.
WhatisP(defectivechipisink selectedchips?)
29
1. Choosekchips.
2. Throwadartandmakeonedefective.
P(defectiveoneinkselectedchips)=
Solution:
Problem:
𝑘𝑛
🤔
AnyStraightinPoker
Consider5cardpokerhands.
• “straight”is5consecutiverankcardsofanysuit
• WhatisP(straight)?
30
|S|= ?%?
|E|=10 A.?
P(straight)=÷÷ø
öççè
æ
÷÷ø
öççè
æ
55214
105
Solution:
Problem:
» 0.00394
🤔
“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
🤔
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)
🙆
ItisofteneasiertocalculateP(Ec).
33
𝑃 𝐴 ∪ 𝐵 ∪⋯∪ 𝑍 = 1 − 𝑃 𝐴J𝐵J ⋯𝑍J DeMorgan’s:
🤔
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+
🤔
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%!
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?
Summary
Samplespace,S:Thesetofallpossibleoutcomesofanexperiment.Eventspace,E:AsubsetofS.Ifwehaveequallylikelyoutcomes,thenP(E)=|E|/|S|.
Twokeytacticstocountingprobabilities:• Wecantreatindistinctobjectsasdistinctifithelpscreateequallylikely
outcomes.• DeMorgan’s lawandcalculatingP(Ec)helpsusavoidtrickycounting
situations.
37
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!!!