CSE573:ArtificialIntelligenceConstraintSatisfactionProblemsFactored(akaStructured)Search
[WithmanyslidesbyDanKleinandPieterAbbeel (UCBerkeley)availableathttp://ai.berkeley.edu.]
FinalPresentations§ 21groups/40people/110min
§ Minustransfers&tournamentreplay
§ Presentations(withquestions)§ Onepersongroups 2.5min§ Twopersongroups 4.5min§ Threepersongroups 6.5min
§ Everyoneshouldspeak(unlessOOT)§ Rehearse§ AddURLforslidestog-doc
§ https://docs.google.com/spreadsheets/d/1Qt5BW0DkSAg6Q4MOM98jSSwjR2wTZpi5i01XdT0X-fs/edit#gid=02
Finalreport
§ Defaultproject~2pages§ Otherprojects~6pages
§ Experiments§ Lessonslearned§ http://courses.cs.washington.edu/courses/cse573/17wi/reports.html
§ Everyone§ Seenoteonappendices– dynamics&externalcode
3
AITopics
§ Search§ Problemspaces§ BFS,DFS,UCS,A*(treeandgraph),localsearch§ CompletenessandOptimality§ Heuristics:admissibilityandconsistency;patternDBs
§ CSPs§ Constraintgraphs,backtrackingsearch§ Forwardchecking,AC3constraintpropagation,ordering
heuristics§ Games
§ Minimax,Alpha-betapruning,§ Expectimax§ EvaluationFunctions
§ MDPs§ Bellmanequations§ Valueiteration,policyiteration
§ Reinforcement Learning§ Exploration vs Exploitation§ Model-based vs. model-free§ Q-learning§ Linear value function approx.
§ Hidden Markov Models§ Markov chains, DBNs§ Forward algorithm§ Particle Filters
§ POMDPs§ Belief space§ Piecewise linear approximation to value fun
§ Beneficial AI§ Bayesian Networks
§ Basic definition, independence (d-sep)§ Variable elimination§ Sampling (rejection, importance)
§ Learning§ BN parameters with complete data§ Search thru space of BN structures§ Expectation maximization
Whatisintelligence?
§ (bounded)Rationality§ Agenthasaperformancemeasuretooptimize§ Givenitsstateofknowledge§ Chooseoptimalaction§ Withlimitedcomputationalresources
§ Human-likeintelligence/behavior
State-SpaceSearch§ Xasasearchproblem
§ states,actions,transitions,cost,goal-test§ Typesofsearch
§ uninformedsystematic:oftenslow§ DFS,BFS,uniform-cost,iterativedeepening
§ Heuristic-guided:better§ Greedybestfirst,A*§ Relaxationleadstoheuristics
§ Local: fast,fewerguarantees;oftenlocaloptimal§ Hillclimbingandvariations§ SimulatedAnnealing:globaloptimal
§ (Local)BeamSearch
WhichAlgorithm?
§ A*, Manhattan Heuristic:
AdversarialSearch
AdversarialSearch
§ AND/ORsearchspace(max,min)§ minimax objectivefunction§ minimax algorithm(~dfs)
§ alpha-betapruning
§ Utilityfunctionforpartialsearch§ Learningutilityfunctionsbyplayingwithitself
§ Openings/Endgamedatabases
PolicyIteration§ Leti =0§ Initializeπi(s)torandomactions§ Repeat
§ Step1:Policyevaluation:§ Initializek=0;Forall s,V0
π (s)=0§ RepeatuntilVπ converges
§ Foreachstates,
§ Letk+=1§ Step2:Policyimprovement:
§ Foreachstate,s,
§ Ifπi ==πi+1 thenit’soptimal;returnit.§ Elseleti +=1
Example
Initializeπ0to “alwaysgoright”
Performpolicyevaluation
PerformpolicyimprovementIteratethroughstates ?
?
?
Haspolicychanged?
Yes!i +=1
Example
π1says“alwaysgoup”
Performpolicyevaluation
PerformpolicyimprovementIteratethroughstates ?
?
?
Haspolicychanged?
No!Wehavetheoptimalpolicy
ReinforcementLearning
§ Forall s,a§ InitializeQ(s,a)=0
§ RepeatForeverWhere are you? s.Choose some action aExecute it in real world: transition =(s, a, r, s’)Do update:
ApproximateQ-Learning
§ Interpretationassearch§ Adjustweightsofactivefeatures§ E.g.,ifsomethingunexpectedlybadhappens,blametheactivefeatures
§ Forall s,a§ Initializewi=0
§ RepeatForeverWhere are you? s.Choose some action aExecute it in real world: transition =(s, a, r, s’)Do updates:
ApproximateQ-Learning
§ Q-learningwithlinearQ-functions:
§ Intuitiveinterpretation:§ Adjustweightsofactivefeatures§ E.g.,ifsomethingunexpectedlybadhappens,blamethefeaturesthatwereactive:
disprefer allstateswiththatstate’sfeatures
Old way: Exact Q’s
Now: Approximate Q’s
WhatisSearchFor?
§ Planning:sequencesofactions§ Thepathtothegoal istheimportantthing§ Pathshavevariouscosts,depths§ Assumelittleaboutproblemstructure
§ Identification:assignmentstovariables§ Thegoalitselfisimportant,notthepath§ Allpathsatthesamedepth(forsomeformulations)
ConstraintSatisfactionProblems
CSPs are structured (factored) identification problems
ConstraintSatisfactionProblems
§ Standardsearchproblems:§ Stateisa“blackbox”:arbitrarydatastructure§ Goaltestcanbeanyfunctionoverstates§ Successorfunctioncanalsobeanything
§ Constraintsatisfactionproblems(CSPs):§ Aspecialsubsetofsearchproblems§ StateisdefinedbyvariablesXi withvaluesfroma
domainD (sometimesD dependsoni)§ Goaltestisasetofconstraintsspecifyingallowable
combinationsofvaluesforsubsetsofvariables
§ MakinguseofCSPformulationallowsforoptimizedalgorithms§ Typicalexampleoftradinggeneralityforutility(inthis
case,speed)
ConstraintSatisfactionProblems
§ Constraintsatisfactionproblems(CSPs):§ Aspecialsubsetofsearchproblems§ StateisdefinedbyvariablesXi withvaluesfroma
domainD (sometimesD dependsoni)§ Goaltestisasetofconstraintsspecifyingallowable
combinationsofvaluesforsubsetsofvariables
§ “Factoring”thestatespace
§ Representingthestatespaceinaknowledgerepresentation
CSPExample:N-Queens
§ Formulation1:§ Variables:§ Domains:§ Constraints
CSPExample:N-Queens
§ Formulation2:§ Variables:
§ Domains:
§ Constraints:
Implicit:
Explicit:
CSPExample:Sudoku
§ Variables:§ Each(open)square
§ Domains:§ {1,2,…,9}
§ Constraints:
9-wayalldiff foreachrow9-wayalldiff foreachcolumn
9-wayalldiffforeachregion(orcanhaveabunchofpairwiseinequalityconstraints)
PropositionalLogic
§ Variables:§ Domains:§ Constraints:
propositionalvariables{T,F}logicalformula
CSPExample:MapColoring
§ Variables:
§ Domains:
§ Constraints:adjacentregionsmusthavedifferentcolors
§ Solutionsareassignmentssatisfyingallconstraints,e.g.:
Implicit:
Explicit:
ConstraintGraphs
ConstraintGraphs
§ BinaryCSP:eachconstraintrelates(atmost)twovariables
§ Binaryconstraintgraph:nodesarevariables,arcsshowconstraints
§ General-purposeCSPalgorithmsusethegraphstructuretospeedupsearch.E.g.,Tasmaniaisanindependentsubproblem!
Example:Cryptarithmetic
§ Variables:
§ Domains:
§ Constraints:
29
ChineseConstraintNetwork
Soup
Total Cost< $40
ChickenDish
Vegetable
RiceSeafood
Pork Dish
Appetizer
Must beHot&Sour
No Peanuts
No Peanuts
NotChow Mein
Not BothSpicy
Real-WorldCSPs
§ Assignmentproblems:e.g.,whoteacheswhatclass§ Timetablingproblems:e.g.,whichclassisofferedwhenandwhere?§ Hardwareconfiguration§ Gateassignmentinairports§ SpaceShuttleRepair§ Transportationscheduling§ Factoryscheduling§ …lotsmore!
Example:TheWaltzAlgorithm
§ TheWaltzalgorithmisforinterpretinglinedrawingsofsolidpolyhedra as3Dobjects
§ AnearlyexampleofanAIcomputationposedasaCSP
?
WaltzonSimpleScenes
§ Assumeallobjects:§ Havenoshadowsorcracks§ Three-facedvertices§ “Generalposition”:nojunctionschangewithsmallmovementsoftheeye.
§ Theneachlineonimageisoneofthefollowing:§ Boundaryline(edgeofanobject)(>)withrighthandofarrowdenoting“solid”andlefthanddenoting“space”
§ Interiorconvexedge(+)§ Interiorconcaveedge(-)
LegalJunctions
§ Onlycertainjunctionsarephysicallypossible§ HowcanweformulateaCSPtolabelanimage?§ Variables:edges§ Domains:>,<,+,-§ Constraints:legaljunctiontypes
SlightProblem:Localvs GlobalConsistency
37
VarietiesofCSPs
VarietiesofCSPVariables
§ DiscreteVariables§ Finitedomains
§ Sized meansO(dn) completeassignments§ E.g.,BooleanCSPs,includingBooleansatisfiability (NP-complete)
§ Infinitedomains(integers,strings,etc.)§ E.g.,jobscheduling,variablesarestart/endtimesforeachjob§ Linearconstraintssolvable,nonlinearundecidable
§ Continuousvariables§ E.g.,start/endtimesforHubbleTelescopeobservations§ Linearconstraintssolvableinpolynomialtimebylinear
programmethods(seeCSE521forabitofLPtheory)
VarietiesofCSPConstraints
§ VarietiesofConstraints§ Unaryconstraintsinvolveasinglevariable(equivalentto
reducingdomains),e.g.:
§ Binaryconstraintsinvolvepairsofvariables,e.g.:
§ Higher-orderconstraintsinvolve3ormorevariables:e.g.,cryptarithmetic columnconstraints
§ Preferences(softconstraints):§ E.g.,redisbetterthangreen§ Oftenrepresentable byacostforeachvariableassignment§ Givesconstrainedoptimizationproblems§ (We’llignoretheseuntilwegettoBayes’nets)
SolvingCSPs
CSPasSearch
§ States§ Operators§ InitialState§ GoalState
StandardDepthFirstSearch
StandardSearchFormulation
§ StandardsearchformulationofCSPs
§ Statesdefinedbythevaluesassignedsofar(partialassignments)§ Initialstate:theemptyassignment,{}§ Successorfunction:assignavaluetoanunassignedvariable
§ Goaltest:thecurrentassignmentiscompleteandsatisfiesallconstraints
§ We’llstartwiththestraightforward,naïveapproach,thenimproveit
BacktrackingSearch
BacktrackingSearch
§ BacktrackingsearchisthebasicuninformedalgorithmforsolvingCSPs
§ Idea1:Onevariableatatime§ Variableassignmentsarecommutative,sofixordering§ I.e.,[WA=redthenNT=green]sameas[NT=greenthenWA=red]§ Onlyneedtoconsiderassignmentstoasinglevariableateachstep
§ Idea2:Checkconstraintsasyougo§ I.e.consideronlyvalueswhichdonotconflictpreviousassignments§ Mighthavetodosomecomputationtochecktheconstraints§ “Incrementalgoaltest”
§ Depth-firstsearchwiththesetwoimprovementsiscalledbacktrackingsearch
§ Cansolven-queensforn» 25
BacktrackingExample
BacktrackingSearch
§ Whatarethechoicepoints?
[Demo:coloring-- backtracking]
BacktrackingSearch
§ Kindofdepthfirstsearch§ Isitcomplete?
ImprovingBacktracking
§ General-purposeideasgivehugegainsinspeed
§ Ordering:§ Whichvariableshouldbeassignednext?§ Inwhatordershoulditsvaluesbetried?
§ Filtering:Canwedetectinevitablefailureearly?
§ Structure:Canweexploittheproblemstructure?
Filtering
§ Filtering:Keeptrackofdomainsforunassignedvariablesandcrossoffbadoptions§ Forwardchecking:Crossoffvaluesthatviolateaconstraintwhenaddedtotheexisting
assignment
Filtering:ForwardChecking
WASANT Q
NSWV
[Demo:coloring-- forwardchecking]
Filtering:ConstraintPropagation
§ Forwardcheckingonlypropagatesinformationfromassignedtounassigned§ Itdoesn'tcatchwhentwounassignedvariableshavenoconsistentassignment:
§ NTandSAcannotbothbeblue!§ Whydidn’twedetectthisyet?§ Constraintpropagation:reasonfromconstrainttoconstraint
WA SA
NT Q
NSW
V
ConsistencyofaSingleArc
§ AnarcX® Yisconsistent iff foreveryxinthetailthereissomeyintheheadwhichcouldbeassignedwithoutviolatingaconstraint
§ Forwardchecking:Enforcingconsistencyofarcspointingtoeachnewassignment
Deletefromthetail!
WA SA
NT Q
NSW
V
ArcConsistencyofanEntireCSP§ Asimpleformofpropagationmakessureallarcsareconsistent:
§ Important:IfXlosesavalue,neighborsofXneedtoberechecked!§ Arcconsistencydetectsfailureearlier thanforwardchecking§ Canberunasapreprocessoror aftereachassignment§ What’sthedownside ofenforcingarcconsistency?
WA SANT Q
NSW
V
AC-3algorithmforArcConsistency
§ Runtime:O(n2d3),canbereducedtoO(n2d2)§ …butdetectingall possiblefutureproblemsisNP-hard– why?
[Demo:CSPapplet(madeavailablebyaispace.org)-- n-queens]
LimitationsofArcConsistency
§ Afterenforcingarcconsistency:§ Canhaveonesolutionleft§ Canhavemultiplesolutionsleft§ Canhavenosolutionsleft
(andnotknowit)
§ EvenwithArcConsistencyyoustillneedbacktrackingsearch!§ Couldrunatevenstepofthatsearch§ Usuallybettertorunitonce,beforesearch
Whatwentwronghere?
VideoofDemoColoring– BacktrackingwithForwardChecking–ComplexGraph
VideoofDemoColoring– BacktrackingwithArcConsistency–ComplexGraph
K-Consistency
K-Consistency§ Increasingdegreesofconsistency
§ 1-Consistency(NodeConsistency):Eachsinglevariable’sdomainhasavaluewhichmeetsthatvariablesunaryconstraints
§ 2-Consistency(ArcConsistency):Foreachpairofvariables,anyconsistentassignmenttoonecanbeextendedtotheother
§ 3-Consistency(PathConsistency):Foreverysetof3vars,anyconsistentassignmentto2ofthevariablescanbeextendedtothethirdvar
§ K-Consistency:Foreachknodes,anyconsistentassignmenttok-1canbeextendedtothekth node.
§ Higherkmoreexpensivetocompute
§ (Youneedtoknowthealgorithmfork=2case:arcconsistency)
StrongK-Consistency
§ Strongk-consistency:alsok-1,k-2,…1consistent
§ Claim:strongn-consistencymeanswecansolvewithoutbacktracking!
§ Why?§ Chooseanyassignmenttoanyvariable§ Chooseanewvariable§ By2-consistency,thereisachoiceconsistentwiththefirst§ Chooseanewvariable§ By3-consistency,thereisachoiceconsistentwiththefirst2§ …
Ordering
BacktrackingSearch
Ordering:MinimumRemainingValues
§ VariableOrdering:Minimumremainingvalues(MRV):§ Choosethevariablewiththefewestlegalleftvaluesinitsdomain
§ Whyminratherthanmax?§ Alsocalled“mostconstrainedvariable”§ “Fail-fast”ordering
§ Tie-breakeramongMRVvariables§ Whatistheveryfirststatetocolor?(Allhave3valuesremaining.)
§ Maximumdegreeheuristic:§ Choosethevariableparticipatinginthemostconstraintsonremainingvariables
§ Whymostratherthanfewestconstraints?
Ordering:MaximumDegree
Ordering:LeastConstrainingValue
§ ValueOrdering:LeastConstrainingValue§ Givenachoiceofvariable,choosetheleastconstrainingvalue
§ I.e.,theonethatrulesoutthefewestvaluesintheremainingvariables
§ Notethatitmaytakesomecomputationtodeterminethis!(E.g.,rerunningfiltering)
§ Whyleastratherthanmost?
§ Combiningtheseorderingideasmakes1000queensfeasible
RationaleforMRV,MD,LCV
§ Wewanttoenterthemostpromisingbranch,butwealsowanttodetectfailurequickly
§ MRV+MD:§ Choosethevariablethatismostlikelytocausefailure§ Itmustbeassignedatsomepoint,soifitisdoomedtofail,bettertofindoutsoon
§ LCV:§ Wehopeourearlyvaluechoicesdonotdoomustofailure§ Choosethevaluethatismostlikelytosucceed
Trapped
§ Pacman istrapped!Heissurroundedbymysteriouscorridors,eachofwhichleadstoeitherapit(P),aghost(G),oranexit(E).Inordertoescape,heneedstofigureoutwhichcorridors,ifany,leadtoanexitandfreedom,ratherthanthecertaindoomofapitoraghost.
§ Theonesignofwhatliesbehindthecorridorsisthewind:apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.Unfortunately,Pacman cannotmeasurethestrengthofthebreezeataspecificcorridor.Instead,hecanstandbetweentwoadjacentcorridorsandfeelthemaxofthetwobreezes.Forexample,ifhestandsbetweenapitandanexithewillsenseastrong(S)breeze,whileifhestandsbetweenanexitandaghost,hewillsenseaweak(W)breeze.Themeasurementsforallintersectionsareshowninthefigurebelow.
§ Also,whilethetotalnumberofexitsmightbezero,one,ormore,Pacmanknowsthattwoneighboringsquareswillnotbothbeexits.
75
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Variables?
Trapped
76
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Variables? X1, … X6Domains {P, G, E}
§ Pacman istrapped!Heissurroundedbymysteriouscorridors,eachofwhichleadstoeitherapit(P),aghost(G),oranexit(E).Inordertoescape,heneedstofigureoutwhichcorridors,ifany,leadtoanexitandfreedom,ratherthanthecertaindoomofapitoraghost.
§ Theonesignofwhatliesbehindthecorridorsisthewind:apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.Unfortunately,Pacman cannotmeasurethestrengthofthebreezeataspecificcorridor.Instead,hecanstandbetweentwoadjacentcorridorsandfeelthemaxofthetwobreezes.Forexample,ifhestandsbetweenapitandanexithewillsenseastrong(S)breeze,whileifhestandsbetweenanexitandaghost,hewillsenseaweak(W)breeze.Themeasurementsforallintersectionsareshowninthefigurebelow.
§ Also,whilethetotalnumberofexitsmightbezero,one,ormore,Pacmanknowsthattwoneighboringsquareswillnotbothbeexits.
Trapped
§ Apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.
§ Pacmanfeelsthemaxofthetwobreezes.§ thetotalnumberofexitsmightbezero,one,ormore,§ twoneighboringsquareswillnotbothbeexits.
77
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Variables? X1, … X6Domains {P, G, E}
Constraints?
Trapped
§ Apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.
§ Pacman feelsthemaxofthetwobreezes.§ thetotalnumberofexitsmightbezero,one,ormore,§ twoneighboringsquareswillnotbothbeexits.
78
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Constraints?
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
X1 = P or X2= P
Xi = E nand Xi+1|7 = E
X3 = E or X4= EX5 = P or X6= PX2 = E or X3= EX4 = P or X5= P
X6 = P or X1= P
Also! X2 =/= PX3 =/= PX4 =/= P
Trapped
§ Apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.
§ Pacman feelsthemaxofthetwobreezes.§ thetotalnumberofexitsmightbezero,one,ormore,§ twoneighboringsquareswillnotbothbeexits.
79
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Arc consistent?
Constraints?
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
X1 = P or X2= P
Xi = E nand Xi+1|7 = E
X3 = E or X4= EX5 = P or X6= PX2 = E or X3= EX4 = P or X5= P
X6 = P or X1= P
Also! X2 =/= PX3 =/= PX4 =/= P
Trapped
§ Apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.
§ Pacman feelsthemaxofthetwobreezes.§ thetotalnumberofexitsmightbezero,one,ormore,§ twoneighboringsquareswillnotbothbeexits.
80
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Arc consistent?
Constraints?
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
MRV heuristic?X1 = P or X2= P
Xi = E nand Xi+1|7 = E
X3 = E or X4= EX5 = P or X6= PX2 = E or X3= EX4 = P or X5= P
X6 = P or X1= P
Also! X2 =/= PX3 =/= PX4 =/= P
Structure
ProblemStructure
§ Extremecase:independentsubproblems§ Example:Tasmaniaandmainlanddonotinteract
§ Independentsubproblems areidentifiableasconnectedcomponentsofconstraintgraph
§ Supposeagraphofnvariablescanbebrokenintosubproblems ofonlycvariables:§ Worst-casesolutioncostisO((n/c)(dc)),linearinn§ E.g.,n=80,d=2,c=20§ 280 =4billionyearsat10millionnodes/sec§ (4)(220)=0.4secondsat10millionnodes/sec
Tree-StructuredCSPs
§ Theorem:iftheconstraintgraphhasnoloops,theCSPcanbesolvedinO(nd2)time§ ComparetogeneralCSPs,whereworst-casetimeisO(dn)
§ Thispropertyalsoappliestoprobabilisticreasoning(later):anexampleoftherelationbetweensyntacticrestrictionsandthecomplexityofreasoning
Tree-StructuredCSPs§ Algorithmfortree-structuredCSPs:
§ Order:Choosearootvariable,ordervariablessothatparentsprecedechildren
§ Removebackward:Fori =n:2,applyRemoveInconsistent(Parent(Xi),Xi)§ Assignforward:Fori =1:n,assignXi consistentlywithParent(Xi)
§ Runtime:O(nd2)(why?)
Tree-StructuredCSPs
§ Claim1:Afterbackwardpass,allroot-to-leafarcsareconsistent§ Proof:EachX®YwasmadeconsistentatonepointandY’sdomaincouldnothave
beenreducedthereafter(becauseY’schildrenwereprocessedbeforeY)
§ Claim2:Ifroot-to-leafarcsareconsistent,forwardassignmentwillnotbacktrack§ Proof:Inductiononposition
§ Whydoesn’tthisalgorithmworkwithcyclesintheconstraintgraph?
§ Note:we’llseethisbasicideaagainwithBayes’nets
ConnectiontoBayesNets
BayesNetExample:AlarmNetwork
Burglary Earthqk
Alarm
Johncalls
Marycalls
B P(B)
+b 0.001
-b 0.999
E P(E)
+e 0.002
-e 0.998
B E A P(A|B,E)
+b +e +a 0.95+b +e -a 0.05+b -e +a 0.94+b -e -a 0.06-b +e +a 0.29-b +e -a 0.71-b -e +a 0.001-b -e -a 0.999
A J P(J|A)
+a +j 0.9+a -j 0.1-a +j 0.05-a -j 0.95
A M P(M|A)
+a +m 0.7+a -m 0.3-a +m 0.01-a -m 0.99
MoreComplexBayes’ Net:AutoDiagnosis
HiddenMarkovModel(TreeStructured)
§ AnHMMisdefinedby:§ Initialdistribution:§ Transitions:§ Emissions:
P(R1 )0.6
Rt-1 tf
P(Rt | Rt-1 )0.70.1
Rttf
P(Ut | Rt )0.90.2
ForwardAlgorithm
Umbr1=T Umbr2=T
Rain0 Rain1 Rain2
B(x0=r)=0.5
P(R1 )0.5
Rt-1 tf
P(Rt | Rt-1 )0.80.6
Rttf
P(Ut | Rt )0.90.3
B
0(Xt+1) =
X
xt
P (X 0|xt
)B(xt
)
B’(x1=r) = 0.7
B(x1=r)=0.875
B’(x2=r) = P(x2=r | x1=r)*0.875 + P(x2=r | x1=s)*0.125= 0.8*0.875 + 0.6*0.125= 0.775
B(x1=r)∝ 0.9*0.775=0.6975B(x1=s)∝ 0.3*0.225=0.0675
Divideby0.765tonormalizeB(x1=r)=0.912
B(Xt+1) /Xt+1 P (et+1|Xt+1)B0(Xt+1)
B(Xt+1) /Xt+1 P (et+1|Xt+1)B0(Xt+1)
MoreComplexHMMInference
§ ForwardBackward§ Computesmarginalprobabilitiesofall hiddenstatesgivensequenceofobservations
P(xt = value)
MoreComplexHMMInference
§ ForwardBackward§ Computesmarginalprobabilities ofallhiddenstatesgivensequenceofobservations
§ Viterbi§ Computesmostlikelysequenceofstates
valuevaluevaluevalue value
ImprovingStructure
NearlyTree-StructuredCSPs
§ Conditioning:instantiateavariable,pruneitsneighbors'domains
§ Cutset conditioning:instantiate(inallways)asetofvariablessuchthattheremainingconstraintgraphisatree
§ Cutset sizecgivesruntimeO((dc)(n-c)d2),veryfastforsmallc
Cutset Conditioning
SA
SA SA SA
Instantiatethecutset(allpossibleways)
ComputeresidualCSPforeachassignment
SolvetheresidualCSPs(treestructured)
Chooseacutset
Cutset Quiz
§ Findthesmallestcutset forthegraphbelow.
LocalSearchforCSPs
IterativeAlgorithmsforCSPs
§ Localsearchmethodstypicallyworkwith“complete”states,i.e.,allvariablesassigned
§ ToapplytoCSPs:§ Takeanassignmentwithunsatisfiedconstraints§ Operatorsreassignvariablevalues§ Nofringe!Liveontheedge.
§ Algorithm:Whilenotsolved,§ Variableselection:randomlyselectanyconflictedvariable§ Valueselection:min-conflictsheuristic:
§ Chooseavaluethatviolatesthefewestconstraints§ I.e.,hillclimbwithh(n)=totalnumberofviolatedconstraints
Example:4-Queens
§ States:4queensin4columns(44 =256states)§ Operators:movequeenincolumn§ Goaltest:noattacks§ Evaluation:c(n)=numberofattacks
[Demo:n-queens– iterativeimprovement(L5D1)][Demo:coloring– iterativeimprovement]
PerformanceofMin-Conflicts
§ Givenrandominitialstate,cansolven-queensinalmostconstanttimeforarbitrarynwithhighprobability(e.g.,n=10,000,000)!
§ Thesameappearstobetrueforanyrandomly-generatedCSPexcept inanarrowrangeoftheratio
Summary:CSPs
§ CSPsareaspecialkindofsearchproblem:§ Statesarepartialassignments§ Goaltestdefinedbyconstraints
§ Basicsolution:backtrackingsearch
§ Speed-ups:§ Ordering§ Filtering§ Structure(cutset conditioning)
§ Iterativemin-conflictsisofteneffectiveinpractice