Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
CS343:ArtificialIntelligenceInformedSearch
Prof.ScottNiekum
UniversityofTexasatAustin[TheseslidesbasedononescreatedbyDanKleinandPieterAbbeelforCS188IntrotoAIatUCBerkeley.AllCS188materialsareavailableathttp://ai.berkeley.edu.]
Today
▪ InformedSearch▪Heuristics▪GreedySearch▪ A*Search
▪ GraphSearch
Recap:Search
▪ Searchproblem:▪ States(configurationsoftheworld)▪ Actionsandcosts▪ Successorfunction(worlddynamics)▪ Startstateandgoaltest
▪ Searchtree:▪ Nodes:representplansforreachingstates▪ Planshavecosts(sumofactioncosts)
▪ Searchalgorithm:▪ Systematicallybuildsasearchtree▪ Choosesanorderingofthefringe(unexplorednodes)▪ Optimal:findsleast-costplans
Example:PancakeProblem
Cost:Numberofpancakesflipped
Example:PancakeProblem
3
2
4
3
3
2
2
2
4
Statespacegraphwithcostsasweights
34
3
4
2
GeneralTreeSearch
Action:fliptoptwo Cost:2
Action:flipallfourCost:4Pathtoreachgoal:Flipfour,flipthree
Totalcost:7
TheOneQueue
▪ Allthesesearchalgorithmsarethesameexceptforfringestrategies
▪ Conceptually,allfringesarepriorityqueues(i.e.collectionsofnodeswithattachedpriorities)
▪ Practically,forDFSandBFS,youcanavoidthelog(n)overheadfromanactualpriorityqueue,byusingstacksandqueues
▪ Canevencodeoneimplementationthattakesavariablequeuingobject
UninformedSearch
UniformCostSearch
▪ Strategy:expandlowestpathcost
▪ Thegood:UCSiscompleteandoptimal!
▪ Thebad:▪ Exploresoptionsinevery“direction”▪ Noinformationaboutgoallocation
Start Goal
…
c ≤ 3
c ≤ 2
c ≤ 1
VideoofDemoContoursUCSEmpty
VideoofDemoContoursUCSPacmanSmallMaze
InformedSearch
SearchHeuristics
▪ Aheuristicis:▪ Afunctionthatestimateshowcloseastateistoagoal
▪ Designedforaparticularsearchproblem
▪ Examples:Manhattandistance,Euclideandistanceforpathing
10
5
11.2
Example:HeuristicFunction
h(x)
Example:HeuristicFunction
Heuristic:thenumberofthelargestpancakethatisstilloutofplace
43
0
2
3
3
3
4
4
3
4
4
4
h(x)
GreedySearch
Example:HeuristicFunction
h(x)
GreedySearch
▪ Expandthenodethatseemsclosest…
▪ Whatcangowrong?
GreedySearch
▪ Strategy:expandanodethatyouthinkisclosesttoagoalstate▪ Heuristic:estimateofdistancetonearestgoalforeachstate
▪ Bestcase:▪ Best-firsttakesyoustraighttothenearestgoal
▪ Acommoncase:▪ Suboptimalroutetogoalduetoimperfectheuristic▪ Doesnotleadtonearestgoal
▪ Worst-case:likeabadly-guidedDFS
…b
…b
VideoofDemoContoursGreedy(Empty)
VideoofDemoContoursGreedy(PacmanSmallMaze)
A*Search
A*Search
UCS Greedy
A*
▪ Uniform-costordersbypathcost,orbackwardcostg(n)▪ Greedyordersbygoalproximity,orforwardcosth(n)
▪ A*Searchordersbythesum:f(n)=g(n)+h(n)
CombiningUCSandGreedy
S a d
b
Gh=5
h=6
h=2
1
8
11
2
h=6h=0
c
h=7
3
e h=11
S
a
b
c
ed
dG
G
g=0h=6
g=1h=5
g=2h=6
g=3h=7
g=4h=2
g=6h=0
g=9h=1
g=10h=2
g=12h=0
WhenshouldA*terminate?
▪ Shouldwestopwhenweenqueueagoal?
S
B
A
G
2
3
2
2h=1
h=2
h=0h=3
▪ No:onlystopwhenweexpandagoal
IsA*Optimal?
▪ WhatwillA*dohere?
▪ Whatwentwrong?
▪ Actualbadgoalcost<estimatedgoodgoalcost
▪ Weneedestimatestobelessthanactualcosts!
A
GS
1 3
h=6
h=0
5h=7
Idea:Admissibility
Inadmissible(pessimistic)heuristicsbreakoptimalitybytrappinggoodplansonthefringe
Admissible(optimistic)heuristicscanstillhelptodelaytheevaluationofbadplans,butnever
overestimatethetruecosts
AdmissibleHeuristics
▪ Aheuristichisadmissible(optimistic)if:
whereisthetruecosttoanearestgoal
▪ Examples:
▪ Comingupwithadmissibleheuristicsismostofwhat’sinvolvedinusingA*inpractice.
415
OptimalityofA*TreeSearch
OptimalityofA*TreeSearch
Assume:
▪ Aisanoptimalgoalnode
▪ Bisasuboptimalgoalnode
▪ hisadmissible
Claim:
▪ AwillexitthefringebeforeB
…
OptimalityofA*TreeSearch:Blocking
Proof:
▪ ImagineBisonthefringe
▪ SomeancestornofAisonthefringe,too(maybeA!)
▪ Claim:nwillbeexpandedbeforeB
1. f(n)islessorequaltof(A)
Definitionoff-costAdmissibilityofh
…
h=0atagoal
OptimalityofA*TreeSearch:Blocking
Proof:
▪ ImagineBisonthefringe
▪ SomeancestornofAisonthefringe,too(maybeA!)
▪ Claim:nwillbeexpandedbeforeB
1. f(n)islessorequaltof(A)2. f(A)islessthanf(B)
Bissuboptimalh=0atagoal
…
OptimalityofA*TreeSearch:Blocking
Proof:
▪ ImagineBisonthefringe
▪ SomeancestornofAisonthefringe,too(maybeA!)
▪ Claim:nwillbeexpandedbeforeB
1. f(n)islessorequaltof(A)2. f(A)islessthanf(B)3. nexpandsbeforeB
▪ AllancestorsofAexpandbeforeB
▪ AexpandsbeforeB
▪ A*searchisoptimal
…
PropertiesofA*
PropertiesofA*
…b
…b
Uniform-Cost A*
UCSvsA*Contours
▪ Uniform-costexpandsequallyinall“directions”
▪ A*expandsmainlytowardthegoal,butdoeshedgeitsbetstoensureoptimality
Start Goal
Start Goal
VideoofDemoContours(Empty)--UCS
VideoofDemoContours(Empty)--Greedy
VideoofDemoContours(Empty)–A*
Pacman-A*
Pacman-Greedy
Pacman-UCS
Comparison
Greedy UniformCost A*
Guessalgorithm(DFS/BFS/UCS/Greedy/A*)
Guessalgorithm(DFS/BFS/UCS/Greedy/A*)
Guessalgorithm(DFS/BFS/UCS/Greedy/A*)
Guessalgorithm(DFS/BFS/UCS/Greedy/A*)
Guessalgorithm(DFS/BFS/UCS/Greedy/A*)
A*Applications
▪ Videogames
▪ Pathing/routingproblems
▪ Resourceplanningproblems
▪ Robotmotionplanning
▪ Languageanalysis▪ Machinetranslation
▪ Speechrecognition▪ …
CreatingAdmissibleHeuristics
▪ Mostoftheworkinsolvinghardsearchproblemsoptimallyisincomingupwithadmissibleheuristics
▪ Often,admissibleheuristicsaresolutionstorelaxedproblems,wherenewactionsareavailable
▪ Inadmissibleheuristicsareoftenusefultoo
15366
Example:8Puzzle
▪ Whatarethestates?▪ Howmanystates?▪ Whataretheactions?▪ Howmanysuccessorsfromthestartstate?▪ Whatshouldthecostsbe?
StartState GoalStateActions
8PuzzleI
▪ Heuristic:Numberoftilesmisplaced
▪ Whyisitadmissible?
▪ h(start)=
▪ Thisisarelaxed-problemheuristic
8
Averagenodesexpandedwhentheoptimalpathhas…
…4steps …8steps …12steps
UCS 112 6,300 3.6x106
TILES 13 39 227
StartState GoalState
8PuzzleII
▪ Whatifwehadaneasier8-puzzlewhereanytilecouldslideanydirectionatanytime,ignoringothertiles?
▪ TotalManhattandistance
▪ Whyisitadmissible?
▪ h(start)= 3+1+2+…=18
Averagenodesexpandedwhentheoptimalpathhas…
…4steps …8steps …12steps
TILES 13 39 227
MANHATTAN 12 25 73
StartState GoalState
8PuzzleIII
▪ Howaboutusingtheactualcostasaheuristic?▪ Woulditbeadmissible?▪ Wouldwesaveonnodesexpanded?▪ What’swrongwithit?
▪ WithA*:atrade-offbetweenqualityofestimateandworkpernode▪ Asheuristicsgetclosertothetruecost,youwillexpandfewernodesbutusuallydomoreworkpernodetocomputetheheuristicitself
TrivialHeuristics,Dominance
▪ Dominance:ha≥hcif
▪ Heuristicsformasemi-lattice:▪ Maxofadmissibleheuristicsisadmissible
▪ Trivialheuristics▪ Bottomoflatticeisthezeroheuristic(what
doesthisgiveus?)▪ Topoflatticeistheexactheuristic
GraphSearch
▪ Failuretodetectrepeatedstatescancauseexponentiallymorework.
SearchTreeStateGraph
TreeSearch:ExtraWork!
GraphSearch
▪ InBFS,forexample,weshouldn’tbotherexpandingthecirclednodes(why?)
S
a
b
d p
a
c
e
p
h
f
r
q
q c G
a
qe
p
h
f
r
q
q c G
a
GraphSearch
▪ Idea:neverexpandastatetwice
▪ Howtoimplement:
▪ Treesearch+setofexpandedstates(“closedset”)▪ Expandthesearchtreenode-by-node,but…▪ Beforeexpandinganode,checktomakesureitsstatehasneverbeen
expandedbefore▪ Ifnotnew,skipit,ifnewaddtoclosedset
▪ Important:storetheclosedsetasaset,notalist
▪ Cangraphsearchwreckcompleteness?Why/whynot?
▪ Howaboutoptimality?
A*GraphSearchGoneWrong?
S
A
B
C
G
1
1
1
23
h=2
h=1
h=4
h=1
h=0
S(0+2)
A(1+4) B(1+1)
C(2+1)
G(5+0)
C(3+1)
G(6+0)
Statespacegraph Searchtree
ConsistencyofHeuristics
▪ Mainidea:estimatedheuristiccosts≤actualcosts
▪ Admissibility:heuristiccost≤actualcosttogoal
h(A)≤actualcostfromAtoG
▪ Consistency:heuristic“arc”cost≤actualcostforeacharc
h(A)–h(C)≤cost(AtoC)
i.e.ifthetruecostofanedgefromAtoCisX,thentheh-valueshouldnot
decreasebymorethanXbetweenAandC.
▪ Consequencesofconsistency:
▪ Thefvaluealongapathneverdecreases
h(A)≤cost(AtoC)+h(C)
▪ A*graphsearchisoptimal
3
A
C
G
h=4 h=11
h=2
OptimalityofA*GraphSearch
▪ Sketch:considerwhatA*doeswithaconsistentheuristic:
▪ Fact1:Intreesearch,A*expandsnodesinincreasingtotalfvalue(f-contours)
▪ Fact2:Foreverystates,nodesthatreachsoptimallyareexpandedbeforenodesthatreachssuboptimally
▪ Result:A*graphsearchisoptimal
…
f≤ 3
f≤ 2
f≤ 1
Optimality
▪ Treesearch:▪ A*isoptimalifheuristicisadmissible▪ UCSisaspecialcase(h=0)
▪ Graphsearch:▪ A*optimalifheuristicisconsistent▪ UCSoptimal(h=0isconsistent)
▪ Consistencyimpliesadmissibility
▪ Ingeneral,mostnaturaladmissibleheuristicstendtobeconsistent,especiallyiffromrelaxedproblems
A*:Summary
A*:Summary
▪ A*usesbothbackwardcostsand(estimatesof)forwardcosts
▪ A*isoptimalwithadmissible/consistentheuristics
▪ Heuristicdesigniskey:oftenuserelaxedproblems
TreeSearchPseudo-Code
GraphSearchPseudo-Code