Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
CE417: Introduction to Artificial IntelligenceSharif University of TechnologyFall 2019
βArtificial Intelligence: A Modern Approachβ, Chapter 3Most slides have been adopted from Klein and Abdeel, CS188, UC Berkeley.
Informed SearchA* Algorithm
Soleymani
Uniform Cost Search
} Strategy: expand lowest path cost
} The good: UCS is complete and optimal!
} The bad:} Explores options in every βdirectionβ} No information about goal location Start Goal
β¦
c Β£ 3
c Β£ 2
c Β£ 1
4
Search Heuristics§ Aheuristicis:
§ Afunctionthatestimates howcloseastateistoagoal§ Designedforaparticularsearchproblem§ Examples:Manhattandistance,Euclideandistanceforpathing
10
5
11.2
7
Heuristic Function} Incorporating problem-specific knowledge in search
} Information more than problem definition} In order to come to an optimal solution as rapidly as possible
} β π : estimated cost of cheapest path from π to a goal} Depends only on π (not path from root to π)} If π is a goal state then β(π)=0} β(π) β₯ 0
} Examples of heuristic functions include using a rule-of-thumb,an educated guess, or an intuitive judgment
8
Greedy search} Priority queue based on β(π)
} e.g., β'() π =straight-line distance from n to Bucharest
} Greedy search expands the node that appears to beclosest to goal
Greedy
11
Greedy best-first search
} Strategy: expand a node that you think is closest to agoal state} Heuristic: estimate of distance to nearest goal for each state
} A common case:} Best-first takes you straight to the (wrong) goal
} Worst-case: like a badly-guided DFS
β¦b
β¦b
19
Properties of greedy best-first search} Complete? No
} Similar to DFS, only graph search version is complete in finite spaces} Infinite loops, e.g., (Iasi to Fagaras) Iasi Γ Neamt Γ Iasi Γ Neamt
} Time} π(ππ), but a good heuristic can give dramatic improvement
} Space} π(ππ): keeps all nodes in memory
} Optimal? No
20
A* search} Idea: minimizing the total estimated solution cost} Evaluation function for priority π π = π π + β(π)
} π π = cost so far to reach π} β π = estimated cost of the cheapest path from π to goal} So, π π = estimated total cost of path through π to goal
24
start nβ¦ goalβ¦
Actual cost π π Estimated cost β π
π π = π π + β(π)
CombiningUCSandGreedy
} Uniform-cost orders by path cost, or backward cost g(n)} Greedy orders by goal proximity, or forward cost h(n)
} A* Search orders by the sum: f(n) = g(n) + h(n)
S a d
b
Gh=5
h=6
h=2
1
8
11
2
h=6 h=0
c
h=7
3
e h=11
Example:Teg Grenager
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
25
WhenshouldA*terminate?
} Should we stop when we enqueue a goal?
} No: only stop when we dequeue a goal
S
B
A
G
2
3
2
2h=1
h=2
h=0h=3
26
IsA*Optimal?
β’ What went wrong?β’ Actual bad goal cost < estimated good goal costβ’ We need estimates to be less than actual costs!
A
GS
1 3h=6
h=0
5
h =7
27
Idea: Admissibility
Inadmissible(pessimistic)heuristicsbreakoptimalitybytrappinggoodplansonthefrontier
Admissible(optimistic)heuristicsslowdownbadplansbutneveroutweightruecosts
29
Admissible Heuristics
} A heuristic h is admissible (optimistic) if:
where is the true cost to a nearest goal
} Examples:
} Coming up with admissible heuristics is most of whatβsinvolved in using A* in practice.
15
30
OptimalityofA*TreeSearch
Assume:} A is an optimal goal node} B is a suboptimal goal node} h is admissible
Claim:
} A will exit the frontier before B
β¦
32
OptimalityofA*TreeSearch:Blocking
Proof:} Imagine B is on the frontier} Some ancestor n of A is on the
frontier, too (maybe A!)} Claim: n will be expanded before B
1. f(n) is less or equal to f(A)
Definitionoff-costAdmissibilityofh
β¦
h=0atagoal
π π β€ π π + ββ(π)π π΄ = π π + ββ(π)
33
OptimalityofA*TreeSearch:Blocking
Proof:} Imagine B is on the frontier} Some ancestor n of A is on the
frontier, too (maybe A!)} Claim: n will be expanded before B
1. f(n) is less or equal to f(A)2. f(A) is less than f(B)
Bissuboptimalh=0atagoal
β¦
34
OptimalityofA*TreeSearch:Blocking
Proof:} Imagine B is on the frontier} Some ancestor n of A is on the
frontier, too (maybe A!)} Claim: n will be expanded before B
1. f(n) is less or equal to f(A)2. f(A) is less than f(B)3. n expands before B
} All ancestors of A expand before B} A expands before B} A* search is optimal
β¦
35
A* search
36
} Combines advantages of uniform-cost and greedysearches
} A* can be complete and optimal when β(π) has someproperties
} Failure to detect repeated states can cause exponentially more work.
SearchTreeStateGraph
Tree Search: Extra Work!
44
GraphSearch} In BFS, for example, we shouldnβt bother expanding the circled nodes (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
45
Recall: Graph Search} Idea: never expand a state twice
} How to implement:
} Tree search + set of expanded states (βclosed setβ)
} Expand the search tree node-by-node, butβ¦
} Before expanding a node, check to make sure its state has never been expanded before
} If not new, skip it, if new add to closed set
} Important: store the closed set as a set, not a list
} Can graph search wreck completeness? Why/why not?
} How about optimality?
46
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
48
Conditions for optimality of A*
} Admissibility: β(π) be a lower bound on the cost to reach goal} Condition for optimality of TREE-SEARCH version of A*
} Consistency (monotonicity): β π β€ π π, π, π8 + β π8} Condition for optimality of GRAPH-SEARCH version of A*
49
Consistent heuristics
50
} Triangle inequality
π
πβ²
πΊβ(πβ²)
β(π)
π(π, π, πβ²)
π π, π, π8 : cost of generating πβ² by applying action to π
for every node π and every successorπ8 generated by any action π
β π β€ π π, π, π8 + β π8
ConsistencyofHeuristics} Main idea: estimated heuristic costs β€ actual costs
} Admissibility: heuristic cost β€ actual cost to goal
h(A) β€ actual cost from A to G
} Consistency: heuristic βarcβ cost β€ actual cost for each arc
h(A) β h(C) β€ cost(A to C)
} Consequences of consistency:} The f value along a path never decreases
h(A) β€ cost(A to C) + h(C)
} A* graph search is optimal
3
A
C
G
h=4 h=11
h=2
51
Admissible but not consistent: Example
52
} π (for admissible heuristic) may decrease along a path} Is there any way to make β consistent?
π
πβ²
π(π, π, πβ) = 1β(π) = 9β(πβ) = 6βΉ β π β° β πβ + π(π, π, πβ)
1
π π = 5β π = 9π(π) = 14
π πβ² = 6β π8 = 6π(πβ²) = 12G
10
10
βD πβ² = max(β π8 , βD π β π(π, π, πβ²))
Consistency implies admissibility
53
} Consistency βAdmissblity} All consistent heuristic functions are admissible} Nonetheless, most admissible heuristics are also consistent
β πJ β€ π πJ, πJ, πK + β(πK)β€ π πJ, πJ, πK + π πK, πK, πL + β(πL)
β¦β€ β π πN, πN, πNOJP
NQJ + β(G)
πJ πK πL πP πΊβ¦π(πJ, πJ, πK) π(πP, πP, πΊ)π(πK, πK, πL)
0 β β πJ β€ cost of (every) path from πJ to goalβ€ cost of optimal path from πJ to goal
Optimality} Tree search:
} A* is optimal if heuristic is admissible} UCS is a special case (h = 0)
} Graph search:} A* optimal if heuristic is consistent} UCS optimal (h = 0 is consistent)
} Consistency implies admissibility
} In general, most natural admissible heuristics tend to beconsistent, especially if from relaxed problems
54
OptimalityofA*GraphSearch} Sketch: consider what A* does with a consistent heuristic:
} Fact 1: In graph search, A* expands nodes in increasing total f value (f-contours)
} Fact 2: For every state s, nodes that reach s optimally are expanded before nodesthat reach s suboptimally
} Result: A* graph search is optimalβ¦
fΒ£ 3
fΒ£ 2
fΒ£ 1
55
Optimality of A* (consistent heuristics)Theorem: If β(π) is consistent, A* using GRAPH-SEARCH isoptimal
Lemma1: if β(π) is consistent then π(π) values are non-decreasing along any path
Proof: Let πβ² be a successor of π
I. π(πβ²) = π(πβ²) + β(πβ²)II. π(πβ²) = π(π) + π(π, π, πβ²)III. πΌ, πΌπΌ β π π8 = π π + π π, π, π8 + β π8
IV. β π isconsistent β β π β€ π π, π, π8 + β π8 V. πΌπΌπΌ, πΌπ β π(πβ²) β₯ π(π) + β(π) = π(π)
56
Optimality of A* (consistent heuristics)Lemma 2: For every state π, nodes that reach π optimally areexpanded before nodes that reach π sub-optimally
Proof by contradiction:Assume that π has been selected for expansion. Another frontier node π8must exist on the optimal path from initial node to π (using graph separationproperty). Moreover, based on Lemma 1, π π8 β€ π π and thusπ8wouldhave been selected first.
Lemma 1 & 2β The sequence of nodes expanded by A* (using GRAPH-SEARCH) is in non-decreasing order of π(π)
Since β = 0 for goal nodes, the first selected goal node for expansion is anoptimal solution (π is the true cost for goal nodes)
57
Admissible vs. consistent (tree vs. graph search)
58
} Consistent heuristic: When selecting a node for expansion, thepath with the lowest cost to that node has been found
} When an admissible heuristic is not consistent, a node willneed repeated expansion, every time a new best (so-far) costis achieved for it.
Contours in the state space} A* (using GRAPH-SEARCH) expands nodes in order of
increasing π value} Gradually adds "f-contours" of nodes
} Contour π has all nodes with π = πN whereπN < πN+1
A* expands all nodes with f(n) < C*A* expands some nodes with f(n) = C* (nodes on the goal contour)A* expands no nodes with f(n) > C*βΉpruning
59
UCSvs A*Contours
} Uniform-cost (A* using β(π)=0) expandsequally in all βdirectionsβ
} A* expands mainly toward the goal, butdoes hedge its bets to ensure optimality} More accurate heuristics stretched toward the goal
(more narrowly focused around the optimal path)
Start Goal
Start Goal
States are points in 2-D Euclidean space.g(n)=distance from starth(n)=estimate of distance from goal
63
Properties of A*} Complete?
} Yes if nodes with π β€ π πΊ = πΆβ are finite} Step costβ₯ π > 0 and π is finite
} Time?} Exponential
} But, with a smaller branching factor
Β¨ πdβed or when equal step costs πfΓhβihhβ
} Polynomial when |β(π₯) β ββ(π₯)| = π(πππββ(π₯))} However,A* is optimally efficient for any given consistent heuristic
} No optimal algorithm of this type is guaranteed to expand fewer nodes than A* (exceptto node with π = πΆβ)
} Space?} Keeps all leaf and/or explored nodes in memory
} Optimal?} Yes (expanding node in non-decreasing order of π)
65
Robot navigation example
66
} Initial state? Red cell
} States? Cells on rectangular grid (except to obstacle)
} Actions? Move to one of 8 neighbors (if it is not obstacle)
} Goal test? Green cell
} Path cost? Action cost is the Euclidean length of movement
A* vs. UCS: Robot navigation example
67
} Heuristic: Euclidean distance to goal
} Expanded nodes: filled circles in red & green} Color indicating π value (red: lower, green: higher)
} Frontier: empty nodes with blue boundary
} Nodes falling inside the obstacle are discarded
Adopted from: http://en.wikipedia.org/wiki/Talk%3AA*_search_algorithm
Robot navigation: Admissible heuristic
68
} Is Manhattan πo π₯, π¦ = π₯J β π¦J + π₯K β π¦K distancean admissible heuristic for previous example?
A*: inadmissible heuristic
69
β = β_ππΏπ·β = 5 β β_ππΏπ·
Adopted from: http://en.wikipedia.org/wiki/Talk%3AA*_search_algorithm