Professional Documents
Culture Documents
On edX. Due Tue 9/6 at 11:59pm. Instant grading, many submits allowed.
Project 1: Search
Released today! Due Friday 9/16 at 5pm.
Start early and ask ques=ons. Its longer than most!
Contest!
Today
Finish up
Uninformed Search
Informed Search
Heuris=cs
Greedy Search
A* Search
Graph Search
Recap: Search
Recap: Search
Search problem:
Search tree:
Nodes: represent plans for reaching states
Plans have costs (sum of ac=on costs)
Search algorithm:
Systema=cally builds a search tree
Chooses an ordering of the fringe (unexplored nodes)
Op=mal: nds least-cost plans
3
3
4
3
4
3
2
2
4
3
Breadth-First Search
Breadth-First Search
G
Strategy: expand a
shallowest node rst
Implementa6on: Fringe
is a FIFO queue
d
S
h
p
q
S
d
Search
Tiers
e
h
p
q
q
c
a
h
r
q
G
p
q
r
q
f
c
a
1 node
b nodes
b2 nodes
bs nodes
Is it complete?
s must be nite if a solu=on exists, so yes!
Is it op=mal?
Only if costs are all 1 (more on costs later)
bm nodes
Cost-Sensi=ve Search
GOAL
2
c
b
1
8
2
START
15
4
q
2
r
Strategy: expand a
cheapest node first:
S
1
15
1
r
S 0
Cost
contours
b 4
a 6
h 17 r 11
e 5
11
h 13 r 7
f 8
q 11 c
a
G 10
f
c
a
16
Is it complete?
Assuming best solu=on has a nite cost and minimum arc cost
is posi=ve, yes!
Is it op=mal?
Yes! (Proof via A*)
c1
c2
c3
c1
c2
c3
Start
Goal
Video of Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 2)
Informed Search
DFS
BFS
UCS
Heuris=cs
Greedy Search
A* Search
Graph Search
Search Heuris=cs
A heuris=c is:
A func=on that es6mates how close a state is to a goal
Designed for a par=cular search problem
Examples: Manhalan distance, Euclidean distance for
pathing
10
5
11.2
336
0
160
176
193
Greedy Search
Arad
Bucharest
Cralova
Fagaras
Rimnicu V
h(x)
336
0
160
176
193
h(x)
4
3
4
4
3
4
4
3
Greedy Search
Greedy Search
Expand the node that seems closest
Greedy Search
Strategy: expand a node that you think is
closest to a goal state
A common case:
A* Search
A* Search
UCS
Greedy
A*
S
1
S
h=6
c
h=7
a
1
3
h=5
b
h=6
d
h=2
g = 1
h=5 a
h=1
G
h=0
g = 2
h=6
g = 3
h=7
g = 0
h=6
d g = 4
h=2
g = 9
e h=1
g = 6
G h=0
g = 10
h=2
g = 12
G h=0
Example: Teg Grenager
2
S
g h +
h = 3
h = 0
h = 1
0 3 3
S->A
2 2 4
S->B
2 1 3
S->B->G 5 0 5
S->A->G 4 0 4
Is A* Op=mal?
h = 6
3
g h +
h = 7
h = 0
5
What went wrong?
Actual bad goal cost < es=mated good goal cost
We need es=mates to be less than actual costs!
S
S->A
0 7 7
1 6 7
S->G
5 0 5
Admissible Heuris=cs
Idea: Admissibility
Admissible Heuris=cs
A heuris=c h is admissible (op=mis=c) if:
Examples:
15
11.5
0.0
Deni=on of f-cost
Admissibility of h
h = 0 at a goal
B is subop=mal
h = 0 at a goal
Proper=es of A*
Proper=es of A*
Uniform-Cost
A*
UCS vs A* Contours
Uniform-cost expands equally in all
direc=ons
Start
Start
Goal
Goal
Comparison
Greedy
Uniform Cost
A*
A* Applica=ons
A* Applica=ons
Video games
Pathing / rou=ng problems
Resource planning problems
Robot mo=on planning
Language analysis
Machine transla=on
Speech recogni=on
[Demo: UCS / A* pacman =ny maze (L3D6,L3D7)]
[Demo: guess algorithm Empty Shallow/Deep (L3D8)]
Crea=ng Heuris=cs
Example: 8 Puzzle
Start State
Ac=ons
Goal State
8 Puzzle I
Goal State
8 Puzzle II
What if we had an easier 8-puzzle where
any =le could slide any direc=on at any
=me, ignoring other =les?
Total ManhaMan distance
Start State
Goal State
Why is it admissible?
Average nodes expanded
when the op=mal path has
h(start) = 3 + 1 + 2 + = 18
13
12
39
25
227
73
8 Puzzle III
How about using the actual cost as a heuris=c?
Would it be admissible?
Would we save on nodes expanded?
Whats wrong with it?
With A*: a trade-o between quality of es=mate and work per node
As heuris=cs get closer to the true cost, you will expand fewer nodes but usually
do more work per node to compute the heuris=c itself
Semi-Lazce of Heuris=cs
Trivial heuris=cs
Bolom of lazce is the zero heuris=c (what
does this give us?)
Top of lazce is the exact heuris=c
Graph Search
Search Tree
Graph Search
In BFS, for example, we shouldnt bother expanding the circled nodes (why?)
S
d
b
e
h
p
q
q
c
a
h
r
q
G
p
q
r
q
f
c
a
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
Search tree
S (0+2)
A
1
S
h=2
h=4
h=1
B
h=1
A (1+4)
B (1+1)
C (2+1)
C (3+1)
G (5+0)
G (6+0)
G
h=0
Closed Set: S B C A
Consistency of Heuris=cs
Main idea: es=mated heuris=c costs actual costs
A
h=4
h=2
h=1
3
Consequences of consistency:
Op=mality of A* Search
With a admissible heuris=c, Tree A* is op=mal.
With a consistent heuris=c, Graph A* is op=mal.
With h=0, the same proofs shows that UCS is op=mal.
Skipping proof because of =me constraints. Available from:
Lecture notes on edge.edx.org.
Previous years lectures on edge.edx.org, edx.org or YouTube.
Any book on the topic (e.g. page 97 in Russell & Norvig).
f 1
f 2
f 3
Op=mality
Tree search:
Graph search:
A*: Summary
A*: Summary
A* uses both backward costs and (es=mates of) forward costs
A* is op=mal with admissible / consistent heuris=cs
Heuris=c design is key: oyen use relaxed problems
f1
f2
f3