2PP

CS 188: Artificial Intelligence
Fall 2006
Lecture 4: A* Search
9/5/2006
Dan Klein – UC Berkeley
Many slides over the course adapted from either Stuart
Russell or Andrew Moore
Announcements
ƒ New / changed office hours this week
ƒ In particular Dan’s Wednesday office hours
moved to Friday 1-3
ƒ Extra lab time, see web page
1
Today
ƒ A* Search
ƒ Heuristic Design
ƒ Local Search
Recap: Search
ƒ Search problems:
ƒ States, successors, costs, start and goal tests
ƒ Search trees:
ƒ Nodes: represent paths, have costs
ƒ Strategies differing fringe management
ƒ Tree vs. graph search
2
Uniform Cost: Problems
ƒ Remember: explores
increasing cost contours
…
c≤1
c≤2
c≤3
ƒ The good: UCS is
complete and optimal!
ƒ The bad:
ƒ Explores options in every
“direction”
ƒ No information about goal
location
Start
Goal
Best-First Search
GOAL
a
2
2
h=8
b
1
h=11
h=0
c
2
2
e
d
3
9
h=8
1
START
h=12
5
h=4
h=5
8
p
h=11
1
5
h=4
h
4
1
f
9
5
h=6
4
q
h=9
3
r
h=6
3
Best-First Search
ƒ A common case:
b
…
ƒ Best-first takes you straight
to the (wrong) goal
ƒ Worst-case: like a badlyguided DFS in the worst
case
ƒ Can explore everything
ƒ Can get stuck in loops if no
cycle checking
b
…
ƒ Like DFS in completeness
(finite states w/ cycle
checking)
Combining UCS and Greedy
ƒ Uniform-cost orders by path cost, or backward cost g(n)
ƒ Best-first orders by goal proximity, or forward cost h(n)
5
e
h=1
1
S
h=6
1
3
a
1
b
h=5
1
h=5
2
d
2
h=2
G
h=0
c
h=4
ƒ A* Search orders by the sum: f(n) = g(n) + h(n)
Example: Teg Grenager
4
When should A* terminate?
ƒ Should we stop when we enqueue a goal?
A
2
1
h=2
S
G
h=3
B
2
h=0
2
h=1
ƒ No: only stop when we dequeue a goal
Is A* Optimal?
1
A
h=6
3
h=0
S
h=7
G
5
ƒ What went wrong?
ƒ Actual bad goal cost > estimated good goal cost
ƒ We need estimates to be less than actual costs!
5
Admissible Heuristics
ƒ A heuristic is admissible (optimistic) if:
where
is the true cost to a nearest goal
ƒ E.g. Euclidean distance on a map problem
ƒ Coming up with admissible heuristics is most of
what’s involved in using A* in practice.
Optimality of A*: Blocking
This proof assumed
ƒ Proof: tree search! Where?
…
ƒ What could go wrong?
ƒ We’d have to have to pop
a suboptimal goal off the
fringe queue
ƒ This can’t happen:
ƒ Imagine a suboptimal goal
G’ is on the queue
ƒ Consider any unexpanded
(fringe) node n on a
shortest path to optimal G
ƒ n will be popped before G
6
Optimality of A*: Contours
ƒ Consider what A* does:
ƒ Expands nodes in increasing total f value (f-contours)
ƒ Proof idea: optimal goals have lower f value, so get
expanded first
Holds for graph search as
well, but we made a different
assumption. What?
Consistency
ƒ Wait, how do we know we expand in increasing f value?
ƒ Couldn’t we pop some node n, and find its child n’ to
have lower f value?
ƒ YES:
h=0 h=8
3
g = 10
B
G
A
h = 10
ƒ What do we need to do to fix this?
ƒ Consistency:
ƒ Real cost always exceeds reduction in heuristic
7
UCS vs A* Contours
ƒ Uniform-cost expanded
in all directions
ƒ A* expands mainly
toward the goal, but
does hedge its bets to
ensure optimality
Start
Goal
Start
Goal
Properties of A*
Uniform-Cost
A*
b
b
…
…
8
Admissible Heuristics
ƒ Most of the work is in coming up with admissible
heuristics
ƒ Good news: usually admissible heuristics are also
consistent
ƒ More good news: inadmissible heuristics are often quite
effective (especially when you have no choice)
ƒ Very common hack: use α x h(n) for admissible h, α > 1
to generate a faster but less optimal inadmissible h’
Example: 8-Puzzle
ƒ
ƒ
ƒ
ƒ
What are the states?
What are the actions?
What states can I reach from the start state?
What should the costs be?
9
8-Puzzle I
ƒ Number of tiles
misplaced?
ƒ Why is it admissible?
Average nodes expanded when
optimal path has length…
ƒ h(start) = 8
…4 steps …8 steps …12 steps
ƒ This is a relaxedproblem heuristic
ID
112
TILES 13
6,300
39
3.6 x 106
227
8-Puzzle II
ƒ What if we had an
easier 8-puzzle where
any tile could slide any
one direction at any
time?
ƒ Total Manhattan
distance
ƒ Why admissible?
Average nodes expanded when
optimal path has length…
…4 steps …8 steps …12 steps
ƒ h(start) =
3+1+2+…
= 18
TILES
MANHATTAN
13
12
39
25
227
73
10
8-Puzzle III
ƒ How about using the actual cost as a
heuristic?
ƒ Would it be admissible?
ƒ Would we save on nodes?
ƒ What’s wrong with it?
ƒ With A*, trade-off between quality of
estimate and work per node!
Trivial Heuristics, Dominance
ƒ Dominance:
ƒ Heuristics form a semi-lattice:
ƒ Max of admissible heuristics is admissible
ƒ Trivial heuristics
ƒ Bottom of lattice is the zero heuristic (what
does this give us?)
ƒ Top of lattice is the exact heuristic
11
Course Scheduling
ƒ From the university’s perspective:
ƒ
ƒ
ƒ
ƒ
Set of courses {c1, c2, … cn}
Set of room / times {r1, r2, … rn}
Each pairing (ck, rm) has a cost wkm
What’s the best assignment of courses to rooms?
ƒ States: list of pairings
ƒ Actions: add a legal pairing
ƒ Costs: cost of the new pairing
ƒ Admissible heuristics?
ƒ (Who can think of a cs170 answer to this problem?)
Other A* Applications
ƒ
ƒ
ƒ
ƒ
ƒ
ƒ
ƒ
Pathing / routing problems
Resource planning problems
Robot motion planning
Language analysis
Machine translation
Speech recognition
…
12
Summary: A*
ƒ A* uses both backward costs and
(estimates of) forward costs
ƒ A* is optimal with admissible heuristics
ƒ Heuristic design is key: often use relaxed
problems
Local Search Methods
ƒ Queue-based algorithms keep fallback
options (backtracking)
ƒ Local search: improve what you have until
you can’t make it better
ƒ Generally much more efficient (but
incomplete)
13
Example: N-Queens
ƒ
ƒ
ƒ
ƒ
ƒ
What are the states?
What is the start?
What is the goal?
What are the actions?
What should the costs be?
Types of Problems
ƒ Planning problems:
ƒ We want a path to a solution
(examples?)
ƒ Usually want an optimal path
ƒ Incremental formulations
ƒ Identification problems:
ƒ We actually just want to know what
the goal is (examples?)
ƒ Usually want an optimal goal
ƒ Complete-state formulations
ƒ Iterative improvement algorithms
14
Example: N-Queens
ƒ Start wherever, move queens to reduce conflicts
ƒ Almost always solves large n-queens nearly instantly
ƒ How is this different from best-first search?
Hill Climbing
ƒ Simple, general idea:
ƒ Start wherever
ƒ Always choose the best neighbor
ƒ If no neighbors have better scores than
current, quit
ƒ Why can this be a terrible idea?
ƒ Complete?
ƒ Optimal?
ƒ What’s good about it?
15
Hill Climbing Diagram
ƒ Random restarts?
ƒ Random sideways steps?
Simulated Annealing
ƒ Idea: Escape local maxima by allowing downhill moves
ƒ But make them rarer as time goes on
16
Simulated Annealing
ƒ Theoretical guarantee:
ƒ Stationary distribution:
ƒ If T decreased slowly enough,
will converge to optimal state!
ƒ Is this an interesting guarantee?
ƒ Sounds like magic, but reality is reality:
ƒ The more downhill steps you need to escape, the less
likely you are to every make them all in a row
ƒ People think hard about ridge operators which let you
jump around the space in better ways
Beam Search
ƒ Like greedy search, but keep K states at all
times:
Greedy Search
ƒ
ƒ
ƒ
ƒ
Beam Search
Variables: beam size, encourage diversity?
The best choice in MANY practical settings
Complete? Optimal?
Why do we still need optimal methods?
17
Genetic Algorithms
ƒ Genetic algorithms use a natural selection metaphor
ƒ Like beam search (selection), but also have pairwise
crossover operators, with optional mutation
ƒ Probably the most misunderstood, misapplied (and even
maligned) technique around!
Example: N-Queens
ƒ
ƒ
ƒ
ƒ
Why does crossover make sense here?
When wouldn’t it make sense?
What would mutation be?
What would a good fitness function be?
18
Continuous Problems
ƒ Placing airports in Romania
ƒ States: (x1,y1,x2,y2,x3,y3)
ƒ Cost: sum of squared distances to closest city
Gradient Methods
ƒ How to deal with continous (therefore infinite)
state spaces?
ƒ Discretization: bucket ranges of values
ƒ E.g. force integral coordinates
ƒ Continuous optimization
ƒ E.g. gradient ascent
ƒ More on this next class…
Image from vias.org
19