0% found this document useful (0 votes)
5 views61 pages

InformedSearch

The document discusses informed search strategies in artificial intelligence, focusing on search algorithms like A*, Greedy Search, and Uniform Cost Search. It emphasizes the importance of heuristics in guiding searches towards optimal solutions and outlines the properties of admissible heuristics necessary for the optimality of A*. Additionally, it covers the concepts of consistency in heuristics and the implementation of graph search to avoid expanding repeated states.

Uploaded by

kulkarni.k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views61 pages

InformedSearch

The document discusses informed search strategies in artificial intelligence, focusing on search algorithms like A*, Greedy Search, and Uniform Cost Search. It emphasizes the importance of heuristics in guiding searches towards optimal solutions and outlines the properties of admissible heuristics necessary for the optimality of A*. Additionally, it covers the concepts of consistency in heuristics and the implementation of graph search to avoid expanding repeated states.

Uploaded by

kulkarni.k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CSE 473: Artificial Intelligence

Informed Search

slides adapted from


Stuart Russel, Dan Klein, Pieter Abbeel from [Link]
And Hanna Hajishirzi, Jared Moore, Dan Weld
Recap: Search

§ Search problem:
§ States (configurations of the world)
§ Actions and costs
§ Successor function (world dynamics)
§ Start state and goal test

§ Search tree:
§ Nodes: represent plans for reaching states

§ Search algorithm:
§ Systematically builds a search tree
§ Chooses an ordering of the fringe (unexplored nodes)
§ Optimal: finds least-cost plans
Video of Demo Maze with Deep/Shallow Water --- BFS or UCS? (part 2)
What we would like to have happen
Guide search towards the goal instead of all over the place

Start Goal Start Goal

Informed Uninformed
Up next: Informed Search
§ Uninformed Search § Informed Search
§ DFS § Heuristics
§ BFS § Greedy Search
§ UCS § A* Search
§ Graph Search
Search Heuristics
§ A heuristic is:
§ A function that estimates how close a state is to a goal
§ Designed for a particular search problem
§ Pathing?
§ Examples: Manhattan distance, Euclidean distance for pathing

10

5
11.2
Example: route-finding in Romania
Oradea
71
Neamt

Zerind 87
75 151
Iasi
Arad
140
92
Sibiu Fagaras
99
118
Vaslui
80
Rimnicu Vilcea
Timisoara
142
111 Pitesti 211
Lugoj 97
70 98
85 Hirsova
Mehadia 146 101 Urziceni
75 138 86
Bucharest
Drobeta 120
90
Craiova Eforie
Giurgiu
Example: Heuristic Function

h(x)
Greedy Search
Greedy Search
Expand the node that seems closest…

Is it optimal?
No. Resulting path to Bucharest is not the shortest!
Greedy Search
b
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 b

Worst-case: like a badly-guided DFS

python [Link] --layout smallMaze --pacman=GreedyAgent


python [Link] --layout smallMaze --pacman=SearchAgent -a fn=dfs
Video of Demo Contours Greedy (Empty)
Video of Demo Contours Greedy (Pacman Small Maze)
A* Search
A*: the core idea
§ Expand a node n most likely to be on the optimal path
§ Expand a node n s.t. the cost of the best solution through n is optimal
§ Expand a node n with lowest value of g(n) + h*(n)
§ g(n) is the cost from root to n
§ h*(n) is the optimal cost from n to the closest goal
§ We seldom know h*(n) but might have a heuristic approximation h(n)
§ A* = tree search with priority queue ordered by g(n) + h(n)
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)
8 g=0
S h=6
h=1 g=1
e a
1 h=5

1 3 2 g=2 g=9
S a d G
h=6 b d g=4 e h=1
h=6 h=5 h=2
1 h=2 h=0
1 g=3 g=6
c b g = 10
h=7 c G h=0 d
h=2
h=7 h=6
g = 12
G h=0
A* Search orders by the sum: f(n) = g(n) + h(n)
Example: Teg Grenager
When should A* terminate?

§ Should we stop when we enqueue a goal?


h=2
gh+
2 A 2
S 033

S h=3 h=0 G S->A 2 2 4


S->B 2 1 3
2 B 3
S->B->G 5 0 5
h=1
S->A->G 4 0 4
§ No: only stop when we dequeue a goal
Is A* Optimal?
h=6

1 A 3
g, h, f
S 077
S h=7
G h=0 S->A 1 6 7
S->G 5 0 5
5

What went wrong?


§ Actual bad goal cost < estimated good goal cost
§ We need estimates to be less than actual costs!
Admissible Heuristics
Idea: Admissibility

Inadmissible (pessimistic) heuristics Admissible (optimistic) heuristics


break optimality by trapping slow down bad plans but
good plans on the frontier never outweigh true costs
Admissible Heuristics
§ A heuristic h is admissible (optimistic) if:
0 £ h(n) £ h*(n)
where h*(n) is the true cost to a nearest goal

§ Example:
15

§ Finding good, cheap admissible heuristics is the key to success


Properties of A*

Uniform-Cost A*

b b
… …
UCS vs A* Contours

§ Uniform-cost expands equally in all


“directions”
Start Goal

§ A* expands mainly toward the goal,


but does hedge its bets to ensure
optimality Start Goal
Video of Demo Contours (Empty) -- UCS
Video of Demo Contours (Empty) -- Greedy
Video of Demo Contours (Empty) – A*
Which Algorithm?
Summary

Greedy Uniform Cost A*


A*: Summary
A*: Summary
§ A* uses both backward costs and (estimates of) forward costs

§ A* is optimal with admissible (optimistic) heuristics

§ Heuristic design is key: often use relaxed problems


Video of Demo Empty Water Shallow/Deep
– Guess Algorithm
Creating Heuristics
Creating Admissible Heuristics
§ Most of the work in solving hard search problems optimally is in coming up
with admissible heuristics

§ Often, admissible heuristics are solutions to relaxed problems, where new


actions are available

366
15

§ Inadmissible heuristics are often useful too


Example: 8 Puzzle

Start State Actions Goal State

§ What are the states?


§ How many states? Admissible
§ What are the actions? heuristics?
§ What are the step costs?
8 Puzzle I
§ Heuristic: Number of tiles misplaced
§ Why is it admissible?
§ h(start) = 8

Start State Goal State

Average nodes expanded when


the optimal path has…
…4 steps …8 steps …12 steps
UCS 112 6,300 3.6 x 106
A*TILES 13 39 227

Statistics from Andrew Moore


8 Puzzle II

§ What if we had an easier 8-puzzle where


any tile could slide any direction at any
time, ignoring other tiles?

§ Total Manhattan distance


Start State Goal State

§ Why is it admissible?
Average nodes expanded when
§ h(start) = 3 + 1 + 2 + … = 18 the optimal path has…
…4 steps …8 steps …12 steps
A*TILES 13 39 227
A*MANHATTAN 12 25 73
8 Puzzle III
§ How about using the actual cost as a heuristic?
§ Would it be admissible?
§ Would we save on nodes expanded?
§ What’s wrong with it?

§ With A*: a trade-off between quality of estimate and work per node
§ As heuristics get closer to the true cost, you will expand fewer nodes but usually
do more work per node to compute the heuristic itself
Example: Pancake Problem

Cost: Number of pancakes flipped


Example: Pancake Problem
Example: Pancake Problem
State space graph with costs as weights

4
2 3
2
3

4
3
4 2

3 2
2
4

3
Example: Heuristic Function
Heuristic: the number of the largest pancake that is still out of place
3
4
h(x)

3
4
3 0
4
4 3
4
4 2
3
Combining heuristics

§ Dominance: h1 ≥ h2 if
"n h1(n) ³ h2(n)
§ Roughly speaking, larger value is better as long as both are admissible
§ The zero heuristic is pretty bad (what does A* do with h=0?)
§ The exact heuristic is pretty good, but usually too expensive!
§ What if we have two heuristics, neither dominates the other?
§ Form a new heuristic by taking the max of both:
h(n) = max( h1(n), h2(n))
§ Max of admissible heuristics is admissible and dominates both!
§ Example: number of knight’s moves to get from A to B
§ h1 = (Manhattan distance)/3 (rounded up to correct parity)
§ h2 = (Euclidean distance)/√5 (rounded up to correct parity)
§ h3 = (max x or y shift)/2 (rounded up to correct parity)
Optimality of A* Tree Search
Optimality of A* Tree Search
Assume:
§ A is an optimal goal node …
§ B is a suboptimal goal node
§ h is admissible
A
Claim: B
§ A will be chosen for expansion before B
Optimality of A* Tree Search: Blocking
Proof:

§ Imagine B is on the frontier
§ Some ancestor n of A is on the frontier, n
too (maybe A itself!)
§ Claim: n will be expanded before B A
B
1. f(n) is less than or equal to f(A)

f(n) = g(n) + h(n) Definition of f-cost


f(n) £ g(A) Admissibility of h
g(A) = f(A) h = 0 at a goal
Optimality of A* Tree Search: Blocking
Proof:

§ Imagine B is on the frontier
§ Some ancestor n of A is on the frontier, n
too (maybe A itself!)
§ Claim: n will be expanded before B A
B
1. f(n) is less than or equal to f(A)
2. f(A) is less than f(B)

g(A) < g(B) Suboptimality of B


f(A) < f(B) h = 0 at a goal
Optimality of A* Tree Search: Blocking
Proof:

§ Imagine B is on the frontier
§ Some ancestor n of A is on the frontier, n
too (maybe A itself!)
§ Claim: n will be expanded before B A
B
1. f(n) is less than or equal to f(A)
2. f(A) is less than f(B)
3. n is expanded before B
§ All ancestors of A are expanded before B
f(n) £ f(A) < f(B)
§ A is expanded before B
§ A* tree search is optimal
UCS vs A* Contours

§ Uniform-cost expands equally in all


“directions”
Start Goal

§ A* expands mainly toward the goal,


but does hedge its bets to ensure
optimality Start Goal
What do each of these functions measure?
§ h(n)

§ h*(n)

§ g(n)

§ g*(n)

§ f(n) (from A*)


Comparison

Greedy (h) Uniform Cost (g) A* (g+h)


Optimality of A* Graph Search

This part is a bit technical…


Tree Search: Extra Work!
§ Failure to detect repeated states can cause exponentially more work.

State Graph Search Tree


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?
A* Graph Search Gone Wrong?
State space graph Search tree
h=4

A S (0+2)
1 h=1
1
S C
A (1+4) B (1+1)
h=2 1
2
B
3 C (2+1) C (3+1)

h=1
G G (5+0) G (6+0)

h=0
Simple check against expanded set blocks C
Fancy check allows new C if cheaper than old
but requires recalculating C’s descendants
Consistency of Heuristics
§ Main idea: estimated heuristic costs ≤ actual costs

A § Admissibility: heuristic cost ≤ actual cost to goal

1 h(A) ≤ h*(A)
h=4 C h=1
§ Consistency: heuristic “arc” cost ≤ actual cost for each arc
h=3
h(A) – h(C) ≤ c(A,C)
3 or h(A) ≤ c(A,C) + h(C) (triangle inequality)

§ Consequences of consistency:

G § The f value along a path never decreases:

h(A) ≤ c(A,C) + h(C) => g(A) + h(A) ≤ g(A) + c(A,C) + h(C)

§ A* graph search is optimal


Admissibility and Consistency Constraints

h(A)<=4 h(C)<=3 h(A) - c(A,C) <= h(C) <= 3


h(A)<=4
1 1
A C A C

3 3
10^(1/2) 10^(1/2)

G G
Admissible? Consistent?
h(A) - c(A,C) <= h(C) <= 3
3.16 – 1 <= 3 <= 3
h=4 h=1 h=3.16
1 h=3
1
A C A C

3 3
10^(1/2) 10^(1/2)

G G
Admissible? Consistent?
h(A) - c(A,C) <= h(C) <= 3
3 – 1 <= 3 <= 3
h=0 h=0 h=3
1 h=3
1
A C A C

3 3
10^(1/2) 10^(1/2)

G G
Admissible? Consistent?
h(A) - c(A,C) <= h(C) <= 3
3 – 1 <= 1 <= 3
h=4 h=4 h=3
1 h=1
1
A C A C

3 3
10^(1/2) 10^(1/2)

G G
Optimality of A* Graph Search

§ Sketch: consider what A* does with a


consistent heuristic:
… f£1
§ Fact 1: In tree search, A* expands nodes in
f£2
increasing total f value (f-contours)
f£3
§ 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


Optimality
§ Tree search:
§ A* is optimal if heuristic is admissible

§ Graph search:
§ A* optimal if heuristic is consistent

§ Consistency implies admissibility

§ Most natural admissible heuristics tend to be


consistent, especially if from relaxed problems
§ For admissible but inconsistent heuristics see
[Link]

You might also like