CSE473:Ar+ficialIntelligence
Probability
Instructors:LukeZe?lemoyer---UniversityofWashington[TheseslideswerecreatedbyDanKleinandPieterAbbeelforCS188IntrotoAIatUCBerkeley.AllCS188materialsareavailableath?p://ai.berkeley.edu.]
Today
§ Probability§ RandomVariables§ JointandMarginalDistribu+ons§ Condi+onalDistribu+on§ ProductRule,ChainRule,Bayes’Rule§ Inference§ Independence
§ You’llneedallthisstuffALOTforthenextfewweeks,somakesureyougooveritnow!
InferenceinGhostbusters
§ Aghostisinthegridsomewhere
§ Sensorreadingstellhowcloseasquareistotheghost§ Ontheghost:red§ 1or2away:orange§ 3or4away:yellow§ 5+away:green
P(red|3) P(orange|3) P(yellow|3) P(green|3)0.05 0.15 0.5 0.3
§ Sensorsarenoisy,butweknowP(Color|Distance)
[Demo:Ghostbuster–noprobability(L12D1)]
Uncertainty
§ Generalsitua+on:
§ Observedvariables(evidence):Agentknowscertainthingsaboutthestateoftheworld(e.g.,sensorreadingsorsymptoms)
§ Unobservedvariables:Agentneedstoreasonaboutotheraspects(e.g.whereanobjectisorwhatdiseaseispresent)
§ Model:Agentknowssomethingabouthowtheknownvariablesrelatetotheunknownvariables
§ Probabilis+creasoninggivesusaframeworkformanagingourbeliefsandknowledge
RandomVariables
§ Arandomvariableissomeaspectoftheworldaboutwhichwe(may)haveuncertainty
§ R=Isitraining?§ T=Isithotorcold?§ D=Howlongwillittaketodrivetowork?§ L=Whereistheghost?
§ Wedenoterandomvariableswithcapitalle?ers
§ Randomvariableshavedomains§ Rin{true,false}(ooenwriteas{+r,-r})§ Tin{hot,cold}§ Din[0,∞)§ Linpossibleloca+ons,maybe{(0,0),(0,1),…}
ProbabilityDistribu+ons
§ Associateaprobabilitywitheachvalue
§ Temperature:
T P
hot 0.5
cold 0.5
W P
sun 0.6
rain 0.1
fog 0.3
meteor 0.0
§ Weather:
Shorthandnota+on:
OKifalldomainentriesareunique
ProbabilityDistribu+ons
§ Unobservedrandomvariableshavedistribu+ons
§ Adistribu+onisaTABLEofprobabili+esofvalues
§ Aprobability(lowercasevalue)isasinglenumber
§ Musthave:and
T P
hot 0.5
cold 0.5
W P
sun 0.6
rain 0.1
fog 0.3
meteor 0.0
JointDistribu+ons§ Ajointdistribu-onoverasetofrandomvariables:specifiesarealnumberforeachassignment(oroutcome):
§ Mustobey:
§ Sizeofdistribu+onifnvariableswithdomainsizesd?
§ Forallbutthesmallestdistribu+ons,imprac+caltowriteout!
T W Phot sun 0.4hot rain 0.1cold sun 0.2cold rain 0.3
Probabilis+cModels
§ Aprobabilis+cmodelisajointdistribu+onoverasetofrandomvariables
§ Probabilis+cmodels:§ (Random)variableswithdomains§ Assignmentsarecalledoutcomes§ Jointdistribu+ons:saywhetherassignments(outcomes)arelikely
§ Normalized:sumto1.0§ Ideally:onlycertainvariablesdirectlyinteract
T W Phot sun 0.4hot rain 0.1cold sun 0.2cold rain 0.3
Distribu+onoverT,W
Events§ AneventisasetEofoutcomes
§ Fromajointdistribu+on,wecancalculatetheprobabilityofanyevent
§ Probabilitythatit’shotANDsunny?
§ Probabilitythatit’shot?
§ Probabilitythatit’shotORsunny?
§ Typically,theeventswecareaboutarepar-alassignments,likeP(T=hot)
T W Phot sun 0.4hot rain 0.1cold sun 0.2cold rain 0.3
Quiz:Events
§ P(+x,+y)?
§ P(+x)?
§ P(-yOR+x)?
X Y P+x +y 0.2+x -y 0.3-x +y 0.4-x -y 0.1
=0.2
0.2+0.3 = 0.5
0.2+0.3+0.1 = 0.6
MarginalDistribu+ons
§ Marginaldistribu+onsaresub-tableswhicheliminatevariables§ Marginaliza+on(summingout):Combinecollapsedrowsbyadding
T W Phot sun 0.4hot rain 0.1cold sun 0.2cold rain 0.3
T Phot 0.5cold 0.5
W Psun 0.6rain 0.4
Condi+onalProbabili+es§ Asimplerela+onbetweenjointandcondi+onalprobabili+es
§ Infact,thisistakenasthedefini-onofacondi+onalprobability
T W Phot sun 0.4hot rain 0.1cold sun 0.2cold rain 0.3
P(b)P(a)
P(a,b)
Quiz:Condi+onalProbabili+es
X Y P+x +y 0.2+x -y 0.3-x +y 0.4-x -y 0.1
§ P(+x|+y)?
§ P(-x|+y)?
§ P(-y|+x)?
0.2 / (0.2+0.4) = 1/3
0.4 / (0.2+0.4) = 2/3
0.3 / (0.2+0.3) = 3/5
Condi+onalDistribu+ons
§ Condi+onaldistribu+onsareprobabilitydistribu+onsoversomevariablesgivenfixedvaluesofothers
T W Phot sun 0.4hot rain 0.1cold sun 0.2cold rain 0.3
W Psun 0.8rain 0.2
W Psun 0.4rain 0.6
Condi+onalDistribu+ons JointDistribu+on
Probabilis+cInference
§ Probabilis+cinference:computeadesiredprobabilityfromotherknownprobabili+es(e.g.condi+onalfromjoint)
§ Wegenerallycomputecondi+onalprobabili+es§ P(on+me|noreportedaccidents)=0.90§ Theserepresenttheagent’sbeliefsgiventheevidence
§ Probabili+eschangewithnewevidence:§ P(on+me|noaccidents,5a.m.)=0.95§ P(on+me|noaccidents,5a.m.,raining)=0.80§ Observingnewevidencecausesbeliefstobeupdated
InferencebyEnumera+on§ Generalcase:
§ Evidencevariables:§ Query*variable:§ Hiddenvariables: Allvariables
*Worksfinewithmul-plequeryvariables,too
§ Wewant:
§ Step1:Selecttheentriesconsistentwiththeevidence
§ Step2:SumoutHtogetjointofQueryandevidence
§ Step3:Normalize
⇥ 1
Z
InferencebyEnumera+on
§ P(W)?
§ P(W|winter)?
§ P(W|winter,hot)?
S T W Psummer hot sun 0.30summer hot rain 0.05summer cold sun 0.10summer cold rain 0.05winter hot sun 0.10winter hot rain 0.05winter cold sun 0.15winter cold rain 0.20
W Psun 0.65rain 0.35
W Psun 0.25rain 0.25 Z = 0.5
Normalize W Psun 0.5rain 0.5
W Psun 0.1rain 0.05 Z = 0.15
Normalize W Psun 0.66rain 0.33
§ Obviousproblems:
§ Worst-case+mecomplexityO(dn)
§ SpacecomplexityO(dn)tostorethejointdistribu+on
InferencebyEnumera+on
TheProductRule
§ Example:
R P
sun 0.8
rain 0.2
D W P
wet sun 0.1
dry sun 0.9
wet rain 0.7
dry rain 0.3
D W P
wet sun 0.08
dry sun 0.72
wet rain 0.14
dry rain 0.06
TheChainRule
§ Moregenerally,canalwayswriteanyjointdistribu+onasanincrementalproductofcondi+onaldistribu+ons
§ Whyisthisalwaystrue?
Bayes’Rule
§ Twowaystofactorajointdistribu+onovertwovariables:
§ Dividing,weget:
§ Whyisthisatallhelpful?
§ Letsusbuildonecondi+onalfromitsreverse§ Ooenonecondi+onalistrickybuttheotheroneissimple§ Founda+onofmanysystemswe’llseelater(e.g.ASR,MT)
§ IntherunningformostimportantAIequa+on!
That’smyrule!
InferencewithBayes’Rule
§ Example:Diagnos+cprobabilityfromcausalprobability:
§ Example:§ M:meningi+s,S:s+ffneck
§ Note:posteriorprobabilityofmeningi+ss+llverysmall§ Note:youshoulds+llgets+ffneckscheckedout!Why?
Examplegivens
P (+s|�m) = 0.01
P (+m|+ s) =P (+s|+m)P (+m)
P (+s)=
P (+s|+m)P (+m)
P (+s|+m)P (+m) + P (+s|�m)P (�m)=
0.8⇥ 0.0001
0.8⇥ 0.0001 + 0.01⇥ 0.9999= 0.007937
P (+m) = 0.0001P (+s|+m) = 0.8
P (cause|e↵ect) = P (e↵ect|cause)P (cause)
P (e↵ect)
Quiz:Bayes’Rule
§ Given:
§ WhatisP(W|dry)?
R P
sun 0.8
rain 0.2
D W P
wet sun 0.1
dry sun 0.9
wet rain 0.7
dry rain 0.3
Ghostbusters,Revisited
§ Let’ssaywehavetwodistribu+ons:§ Priordistribu+onoverghostloca+on:P(G)
§ Let’ssaythisisuniform§ Sensorreadingmodel:P(R|G)
§ Given:weknowwhatoursensorsdo§ R=readingcolormeasuredat(1,1)§ E.g.P(R=yellow|G=(1,1))=0.1
§ Wecancalculatetheposteriordistribu+onP(G|r)overghostloca+onsgivenareadingusingBayes’rule:
[Demo:Ghostbuster–withprobability(L12D2)]
Independence
§ Twovariablesareindependentinajointdistribu+onif:
§ Saysthejointdistribu+onfactorsintoaproductoftwosimpleones§ Usuallyvariablesaren’tindependent!
§ Canuseindependenceasamodelingassump-on§ Independencecanbeasimplifyingassump+on§ Empiricaljointdistribu+ons:atbest“close”toindependent§ Whatcouldweassumefor{Weather,Traffic,Cavity}?
Example:Independence?
T W P
hot sun 0.4
hot rain 0.1
cold sun 0.2
cold rain 0.3
T W P
hot sun 0.3
hot rain 0.2
cold sun 0.3
cold rain 0.2
T P
hot 0.5
cold 0.5
W P
sun 0.6
rain 0.4
P2(T,W ) = P (T )P (W )
Condi+onalIndependence§ P(Toothache,Cavity,Catch)
§ IfIhaveacavity,theprobabilitythattheprobecatchesinitdoesn'tdependonwhetherIhaveatoothache:§ P(+catch|+toothache,+cavity)=P(+catch|+cavity)
§ ThesameindependenceholdsifIdon�thaveacavity:§ P(+catch|+toothache,-cavity)=P(+catch|-cavity)
§ Catchiscondi-onallyindependentofToothachegivenCavity:§ P(Catch|Toothache,Cavity)=P(Catch|Cavity)
§ Equivalentstatements:§ P(Toothache|Catch,Cavity)=P(Toothache|Cavity)§ P(Toothache,Catch|Cavity)=P(Toothache|Cavity)P(Catch|Cavity)§ Onecanbederivedfromtheothereasily
Condi+onalIndependence
§ Uncondi+onal(absolute)independenceveryrare(why?)
§ Condi-onalindependenceisourmostbasicandrobustformofknowledgeaboutuncertainenvironments.
§ Xiscondi+onallyindependentofYgivenZ
ifandonlyif:or,equivalently,ifandonlyif
ProbabilityRecap
§ Condi+onalprobability
§ Productrule
§ Chainrule
§ X,Yindependentifandonlyif:
§ XandYarecondi+onallyindependentgivenZifandonlyif: