Transcript lecture11

Today’s Topics
• Exam Thursday Oct 22. 5:30-7:3-pm, same room as lecture
• Makeup Thursday Oct 29? Or that Monday or Wednesday?
• Exam Covers Material through End of Lecture 14
• Part of Oct 20 class will be Exam Review
– Bring (worked!) copy of my Fall 2014 cs540 midterm
• I will Arrange for TA to come to Epic Oct 21, 5:30-7:30pm
• What if Arcs have Costs?
– Finding Least-Cost Solutions (eg, GPS, Google Maps)
– Uniform-cost search, A* search
– Heuristic functions
• Search Wrapup (except genetic and games)
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
1
What if Arcs Have Costs?
• Might want CHEAPEST solutions
– and be willing to spend more cpu cycles
• We’ll put (non-negative) costs on arcs
– If costs negative, infinite loops would be great!
2
B
S
10
5
10/6/15
G
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
2
Uniform Cost
Search (UC)
• Sort OPEN by g(node), which is the cost
from a/the startNode to node by the path
taken to reach node
• Need to store ‘parent pointers’ in nodes
(so can ‘back trace’ to startNode)
• Sometimes we will need to change these
pointers if a CHEAPER path to node found
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
3
Addition to Our Generic
Search Code
• If a child of X is ALREADY IN
OPEN OR CLOSED, see if current path
is better
• If so, remove old item from OPEN/CLOSED
and insert new item in OPEN
• Otherwise discard child
– In some cases non-optimal paths will never
reach CLOSED, but safer to always check
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
4
New and Improved,
Now with Arc Costs
- assume LOWER scores are better
1
B
score = 11
5
Start
score = 9
6
7
8
D
score = 4
C
score = 8
9
2
E
score = 3
Step# OPEN
4
Goal
score = 0
CLOSED X CHILDREN RemainingCHILDREN
(this part done on doc camera for UNIFORM and, later, A*)
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
5
UC - not shown, but you should use a SUPERSCRIPT to show parent
Step# OPEN
1
{ S0 }
2
{ B1, C6 }
3
{ C 6, D 8 }
4
{ D8, G15 }
5
{ E10, G15 }
6
{ G14 }
CLOSED
X CHILDREN RemCHILDREN
{ }
S { S5, B1, C6 }
{ B1, C6 }
{ S0 }
B { D8 }
{ D8 }
{ S0, B1 }
C { G15 }
{ G15 }
{ S0, B1, C6}
D { E10, C16 }
{ E10 }
{ S0, B1, C6, D8}
E { G14 }
{ G14 }
{ S0, B1, C6, D8, E10} G DONE
A* - subscript is g+h
Step# OPEN
1
2
3
4
5
6
9/29/15
{ S0+9 }
{ B1+11, C6+8}
{ D8+4, C6+8 }
{ E10+3, C6+8 }
{ C6+8 , G14+0 }
{ G14+0 }
CLOSED
{ }
{ S0+9 }
{ S0+9, B1+11 }
{S0+9, B1+11 , D8+4 }
{… E10+3}
{… E10+3, C6+8 }
X
S0+9
B1+11
D8+4
E10+3
C6+8
G14+0
CHILDREN
RemCHILDREN
{ S5+9, B1+11, C6+8}
{ D8+4 }
{ E10+3, C16+8 }
{ G14+0 }
{ G15+0 }
DONE
CS 540 - Fall 2015 (Shavlik©), Lecture 9, Week 4
{ B1+11, C6+8 }
{ D8+4 }
{ E10+3 }
{ G14 }
{ }
Lecture 1, Slide 6
Theorem
Uniform-cost search will
produce a lowest-cost solution
PROOF
Assume we have found solution path S that costs C
If cheaper soln exists, the beginning of it would be
in OPEN (we keep ALL partial solns)
Since all arc costs are non-negative, this partial soln
would cost less than C (total costs never get smaller)
But by construction, we POP OPEN and lowest-cost
always at front
Hence cannot have something something still in OPEN
that costs less than C
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
7
UC Doesn’t Use
Domain K (K = knowledge)
Under certain conditions (later),
sorting by this will get a shortest path
f(node) = g(node) + h(node)
while possible ‘expanding’ many fewer nodes
h(node) is our heuristic estimate of ‘distance’ to goal
S
n
G
g(n)
10/6/15
h(n)
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
8
Practice with f(n)
• Go back to Slide 5 and use f(n)
• An example where using h(n) greatly helps
1
S
h=94
A 1
C
1
1
E
1
F
D
4
1
Z
B
h=89
70
90
G
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
9
Graph Where One Needs to
Remove Item from CLOSED
(also shows why we check for GOAL when
REMOVING from OPEN, rather than when ADDING)
2
B
h=20
S
h=3
5
2
C
h=1
99
G
h=0
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
10
Admissibility
Defn: if a search algo always produces shortest paths
(assuming one exists), then the algo is called admissible
• If h(n) never over estimates the actual distance to a
goal, then using f(n)=g(n)+h(n) will lead to best-first
search being admissible (and we also call h(n) admissible)
• BEST with an admissible h(n) is called A*
(pronounced “A star” – some AI humor!)
• Note that A* can have large OPEN and CLOSED since
all promising partial paths kept
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
11
What Happens if h(n) Overestimates?
Best solution might get pushed deep
into OPEN and never checked
2
B
h=999
S
h=3
5
2
C
h=1
99
G
h=0
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
12
What Happens if h(n) Underestimates?
Might waste time on a non-optimal path
2
B
h=1
S
h=3
5
C
h=1
1
...
10/6/15
D
h=1
99
G
h=0
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
13
Creating Good h Functions
• Mainly a task-specific ‘art’
• h(n) should be a fast algorithm
(would not be good if h(n) implemented DFS!)
• Often ‘simplifying assumptions’ or
‘relaxations’ of the task create good h’s
• Note that user focuses on creating h using
domain K and A* ‘works out the details’
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
14
Some Properties of A*
1. “Informedness” If h1(n) and h2(n) are both
admissible, and n h1(n)  h2(n) then the
nodes A* expands using h1(n) are a subset
of those it expands using h2(n)
Visually
error
h
So the better h(n) is,
the faster A* runs
10/6/15
True
distance
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
h1
h2
15
Some Properties of A*
2. “Robustness”
If h ‘rarely’ overestimates by more than ,
then A* will rarely find a sol’n whose cost
is  more than optimal
2. “Completeness”
A* will terminate with a optimal soln even
in infinite space, provided a soln exists
and all arc costs are greater than some
positive number 
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
16
THINK Before
You Search!
• Naïve Algo
ACTIONS: Fill ‘top-left most’ empty cell
with legal moves in {1, 2, …, 9 }
LARGE search tree!
• Smarter Algo
(usually NEVER need to search!)
1)
Mark each empty cell with candidates that do not violate game’s rules,
eg, top cell in this image can be filled with {3, 5, 8, or 9}
2)
IF NO cells with only one possible filler
Only 2 legal here
Let k be the smaller set of fillers, pick ‘top-left most’ cell with k fillers
and put the k next board states in OPEN
3)
ELSE For all those cells with only ONE possible filler, choose that filer
If game solved EXIT else update “possible fillers’” for all empty cells and go to 2
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
17
Search Wrap Up
• Lots of Variations and Tradeoffs
• We’ve Explored a Wide Range but not All
• Powerful, General-Purpose, Problem-Solving Method
– Watch for Places it can be Employed
– Especially when cpu cycles abundant
• OPEN a Key Data Structure
– CLOSED Prevents Repeated Work
• Our General Search Algo Inefficient for Some Methods,
but Provides a Unifying View
– Needs Modification for Some Methods to Work Correctly
• Heuristic Functions a Good Way to Use Domain K in Intuitive Way
• Next: Search with an Adversary (game playing)
• Then: Genetic Search (based on evolution)
10/6/15
CS 540 - Fall 2015 (Shavlik©), Lecture 11, Week 5
18