Informed Search A* Algorithm CE417: Introduction to Artificial - - PowerPoint PPT Presentation

informed search a algorithm
SMART_READER_LITE
LIVE PREVIEW

Informed Search A* Algorithm CE417: Introduction to Artificial - - PowerPoint PPT Presentation

Informed Search A* Algorithm CE417: Introduction to Artificial Intelligence Sharif University of Technology Fall 2019 Soleymani Artificial Intelligence: A Modern Approach, Chapter 3 Most slides have been adopted from Klein and Abdeel,


slide-1
SLIDE 1

CE417: Introduction to Artificial Intelligence Sharif University of Technology Fall 2019 “Artificial Intelligence: A Modern Approach”, Chapter 3 Most slides have been adopted from Klein and Abdeel, CS188, UC Berkeley.

Informed Search A* Algorithm

Soleymani

slide-2
SLIDE 2

Outline

} Heuristics } Greedy (best-first) search } A* search } Finding heuristics

2

slide-3
SLIDE 3

Uninformed Search

3

slide-4
SLIDE 4

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

slide-5
SLIDE 5

UCS Example

5

slide-6
SLIDE 6

Informed Search

6

slide-7
SLIDE 7

Search Heuristics

§ A heuristic is:

§ A function that estimates how close a state is to a goal § Designed for a particular search problem § Examples: Manhattan distance, Euclidean distance for pathing

10 5 11.2 7

slide-8
SLIDE 8

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

slide-9
SLIDE 9

Example: Heuristic Function

h(x)

9

slide-10
SLIDE 10

Greedy Search

10

slide-11
SLIDE 11

Greedy search

} Priority queue based on ℎ(𝑜)

} e.g., ℎ'() 𝑜 = straight-line distance from n to Bucharest

} Greedy search expands the node that appears to be

closest to goal

Greedy

11

slide-12
SLIDE 12

Example: Heuristic Function

h(x)

12

slide-13
SLIDE 13

Romania with step costs in km

13

slide-14
SLIDE 14

Greedy best-first search example

14

slide-15
SLIDE 15

Greedy best-first search example

15

slide-16
SLIDE 16

Greedy best-first search example

16

slide-17
SLIDE 17

Greedy best-first search example

17

slide-18
SLIDE 18

Greedy best-first search

} Expand the node that seems closest… } What can go wrong? 18

slide-19
SLIDE 19

Greedy best-first search

} Strategy: expand a node that you think is closest to a

goal 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

slide-20
SLIDE 20

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

slide-21
SLIDE 21

Greedy Search

21

slide-22
SLIDE 22

A* Search

22

slide-23
SLIDE 23

A* Search

UCS Greedy A*

23

slide-24
SLIDE 24

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 ℎ 𝑜 𝑔 𝑜 = 𝑕 𝑜 + ℎ(𝑜)

slide-25
SLIDE 25

Combining UCS and Greedy

}

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 G h=5 h=6 h=2 1 8 1 1 2 h=6 h=0 c h=7 3 e h=1 1 Example: Teg Grenager S a b c e d d G G g = 0 h=6 g = 1 h=5 g = 2 h=6 g = 3 h=7 g = 4 h=2 g = 6 h=0 g = 9 h=1 g = 10 h=2 g = 12 h=0

25

slide-26
SLIDE 26

When should A* terminate?

} Should we stop when we enqueue a goal? } No: only stop when we dequeue a goal

S B A G 2 3 2 2

h = 1 h = 2 h = 0 h = 3 26

slide-27
SLIDE 27

Is A* Optimal?

  • What went wrong?
  • Actual bad goal cost < estimated good goal cost
  • We need estimates to be less than actual costs!

A G S 1 3

h = 6 h = 0

5

h = 7

27

slide-28
SLIDE 28

Admissible Heuristics

28

slide-29
SLIDE 29

Idea: Admissibility

Inadmissible (pessimistic) heuristics break

  • ptimality by trapping good plans on the frontier

Admissible (optimistic) heuristics slow down bad plans but never outweigh true costs

29

slide-30
SLIDE 30

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’s

involved in using A* in practice.

15

30

slide-31
SLIDE 31

Optimality of A* Tree Search

31

slide-32
SLIDE 32

Optimality of A* Tree Search

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

slide-33
SLIDE 33

Optimality of A* Tree Search: 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)

Definition of f-cost Admissibility of h

h = 0 at a goal 𝑔 𝑜 ≤ 𝑕 𝑜 + ℎ∗(𝑜)

𝑕 𝐵 = 𝑕 𝑜 + ℎ∗(𝑜)

33

slide-34
SLIDE 34

Optimality of A* Tree Search: 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)

B is suboptimal h = 0 at a goal

… 34

slide-35
SLIDE 35

Optimality of A* Tree Search: 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

slide-36
SLIDE 36

A* search

36

} Combines

advantages

  • f

uniform-cost and greedy searches

} A* can be complete and optimal when ℎ(𝑜) has some

properties

slide-37
SLIDE 37

A* search: example

37

slide-38
SLIDE 38

A* search: example

38

slide-39
SLIDE 39

A* search: example

39

slide-40
SLIDE 40

A* search: example

40

slide-41
SLIDE 41

A* search: example

41

slide-42
SLIDE 42

A* search: example

42

slide-43
SLIDE 43

Graph Search

43

slide-44
SLIDE 44

} Failure to detect repeated states can cause exponentially more work.

Search Tree State Graph

Tree Search: Extra Work!

44

slide-45
SLIDE 45

Graph Search

} 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 q e p h f r q q c

G

a 45

slide-46
SLIDE 46

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

slide-47
SLIDE 47

Optimality of A* Graph Search

47

slide-48
SLIDE 48

A* Graph Search Gone Wrong?

S A B C G

1 1 1 2 3 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)

State space graph Search tree

48

slide-49
SLIDE 49

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

slide-50
SLIDE 50

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

slide-51
SLIDE 51

Consistency of Heuristics

} 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=1 1 h=2

51

slide-52
SLIDE 52

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 𝑔(𝑜′) = 12 G 10 10

ℎ D 𝑜′ = max (ℎ 𝑜8 , ℎ D 𝑜 − 𝑑(𝑜, 𝑏, 𝑜′))

slide-53
SLIDE 53

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, 𝑜NOJ

P NQJ

+ ℎ(G) 𝑜J 𝑜K 𝑜L 𝑜P 𝐻 … 𝑑(𝑜J, 𝑏J, 𝑜K) 𝑑(𝑜P, 𝑏P, 𝐻) 𝑑(𝑜K, 𝑏K, 𝑜L) ⇒ ℎ 𝑜J ≤ cost of (every) path from 𝑜J to goal ≤ cost of optimal path from 𝑜J to goal

slide-54
SLIDE 54

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 be

consistent, especially if from relaxed problems

54

slide-55
SLIDE 55

Optimality of A* Graph Search

} 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 nodes

that reach s suboptimally

} Result: A* graph search is optimal … f £ 3 f £ 2 f £ 1 55

slide-56
SLIDE 56

Optimality of A* (consistent heuristics)

Theorem: If ℎ(𝑜) is consistent, A* using GRAPH-SEARCH is

  • ptimal

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.

ℎ 𝑜 is consistent ⇒ ℎ 𝑜 ≤ 𝑑 𝑜, 𝑏, 𝑜8 + ℎ 𝑜8

V.

𝐽𝐽𝐽, 𝐽𝑊 ⇒ 𝑔(𝑜′) ≥ 𝑕(𝑜) + ℎ(𝑜) = 𝑔(𝑜)

56

slide-57
SLIDE 57

Optimality of A* (consistent heuristics)

Lemma 2: For every state 𝑜, nodes that reach 𝑜 optimally are expanded before nodes that reach 𝑜 sub-optimally

Proof by contradiction: Assume that 𝑜 has been selected for expansion. Another frontier node 𝑜8 must exist on the optimal path from initial node to 𝑜 (using graph separation property). Moreover, based on Lemma 1, 𝑔 𝑜8 ≤ 𝑔 𝑜 and thus 𝑜8 would have 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 an

  • ptimal solution (𝑔 is the true cost for goal nodes)

57

slide-58
SLIDE 58

Admissible vs. consistent (tree vs. graph search)

58

} Consistent heuristic: When selecting a node for expansion, the

path with the lowest cost to that node has been found

} When an admissible heuristic is not consistent, a node will

need repeated expansion, every time a new best (so-far) cost is achieved for it.

slide-59
SLIDE 59

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

slide-60
SLIDE 60

Properties of A*

… b … b

Uniform-Cost A*

60

slide-61
SLIDE 61

A* Example

61

slide-62
SLIDE 62

Example

62

UCS Greedy A*

slide-63
SLIDE 63

UCS vs A* Contours

} Uniform-cost (A*

using ℎ(𝑜)=0) expands equally in all “directions”

} A* expands mainly toward the goal, but

does 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 start h(n)=estimate of distance from goal

63

slide-64
SLIDE 64

Comparison

Greedy Uniform Cost A*

64

slide-65
SLIDE 65

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∗ih

h∗

} 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* (except

to node with 𝑔 = 𝐷∗)

} Space?

} Keeps all leaf and/or explored nodes in memory

} Optimal?

} Yes (expanding node in non-decreasing order of 𝑔) 65

slide-66
SLIDE 66

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

slide-67
SLIDE 67

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

slide-68
SLIDE 68

Robot navigation: Admissible heuristic

68

} Is Manhattan 𝑒o 𝑦, 𝑧 = 𝑦J − 𝑧J + 𝑦K − 𝑧K

distance an admissible heuristic for previous example?

slide-69
SLIDE 69

A*: inadmissible heuristic

69

ℎ = ℎ_𝑇𝑀𝐸 ℎ = 5 ∗ ℎ_𝑇𝑀𝐸

Adopted from: http://en.wikipedia.org/wiki/Talk%3AA*_search_algorithm

slide-70
SLIDE 70

A*: Summary

70

slide-71
SLIDE 71

A*: Summary

} A* uses both backward costs and (estimates of) forward

costs

} A* is optimal with admissible / consistent heuristics } Heuristic design is key: often use relaxed problems

71