search (complementary slides) · search (complementary slides) tomas svoboda, be5b33kui 2017-03-13...
TRANSCRIPT
Search(complementary slides)
Tomas Svoboda, BE5B33KUI2017-03-13
Slide material from CS 188: Artificial Intelligence at UCBby Dan Klein, and Pieter Abbeel, used with permision
BE5B33KUI - admin
• Deadline for the 02_search postponed to March 20 (night after the next computer lab)
• The lecture program will change slightly - due to the delayed start
2
Graphs and Trees
3
State Space Graphs
• State space graphs - mathematical representation of a search problem
• Every state only once
• Do we need the whole graph? (in a memory)
4
State#Space#Graphs#
! State#space#graph:#A#mathema)cal#representa)on#of#a#search#problem#! Nodes#are#(abstracted)#world#configura)ons#! Arcs#represent#successors#(ac)on#results)#! The#goal#test#is#a#set#of#goal#nodes#(maybe#only#one)#
! In#a#search#graph,#each#state#occurs#only#once!#
! We#can#rarely#build#this#full#graph#in#memory#(it’s#too#big),#but#it’s#a#useful#idea#
#
S
G
d
b
p q
c
e
h
a
f
r
Tiny%search%graph%for%a%0ny%search%problem%
Search Trees
• A “what-if” tree of plans and outcomes
• Parents, children
• Nodes of the tree contain states, but much more
5
Search#Trees#
! A#search#tree:#! A#“what#if”#tree#of#plans#and#their#outcomes#! The#start#state#is#the#root#node#! Children#correspond#to#successors#! Nodes#show#states,#but#correspond#to#PLANS#that#achieve#those#states#! For#most#problems,#we#can#never#actually#build#the#whole#tree#
“E”,#1.0#“N”,#1.0#
This#is#now#/#start#
Possible#futures#
State Space Graphs vs. Search Trees
6
State#Space#Graphs#vs.#Search#Trees#
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
S
G
d
b
p q
c
e
h
a
f
r
We%construct%both%on%demand%–%and%we%construct%as%li:le%as%possible.%
Each%NODE%in%in%the%search%tree%is%an%en0re%PATH%in%the%problem%graph.%
Search#Tree#State#Space#Graph#
State Graphs vs. Search Trees
7
Quiz:#State#Graphs#vs.#Search#Trees#
S G
b
a
Consider#this#4Jstate#graph:##
Important:#Lots#of#repeated#structure#in#the#search#tree!#
How#big#is#its#search#tree#(from#S)?#How big is the search tree?A 4-state graph
Quiz:#State#Graphs#vs.#Search#Trees#
S G
b
a
Consider#this#4Jstate#graph:##
Important:#Lots#of#repeated#structure#in#the#search#tree!#
How#big#is#its#search#tree#(from#S)?#
Breadth-First Search (BFS)
8
State#Space#Graphs#
! State#space#graph:#A#mathema)cal#representa)on#of#a#search#problem#! Nodes#are#(abstracted)#world#configura)ons#! Arcs#represent#successors#(ac)on#results)#! The#goal#test#is#a#set#of#goal#nodes#(maybe#only#one)#
! In#a#search#graph,#each#state#occurs#only#once!#
! We#can#rarely#build#this#full#graph#in#memory#(it’s#too#big),#but#it’s#a#useful#idea#
#
S
G
d
b
p q
c
e
h
a
f
r
Tiny%search%graph%for%a%0ny%search%problem%
BreadthJFirst#Search#
Now, build the Search Tree
Breadth-First Search
9
BreadthJFirst#Search#
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
S
G
d
b
p q
c e
h
a
f
r
Search
Tiers
Strategy:%expand%a%shallowest%node%first%
Implementa0on:%Fringe%is%a%FIFO%queue%
BFS properties
• Time?
• Space?
• Complete?
• Optimal?
10
Search#Algorithm#Proper)es#
! Complete:#Guaranteed#to#find#a#solu)on#if#one#exists?#
! Op)mal:#Guaranteed#to#find#the#least#cost#path?#
! Time#complexity?#
! Space#complexity?#
! Cartoon#of#search#tree:#! b#is#the#branching#factor#! m#is#the#maximum#depth#
! solu)ons#at#various#depths#
! Number#of#nodes#in#en)re#tree?#! 1#+#b#+#b2#+#….#bm#=#O(bm)#
…b
1 node b nodes
b2 nodes
bm nodes
m tiers d - depth of a solution
Depth-First Search (DFS)
11
State#Space#Graphs#
! State#space#graph:#A#mathema)cal#representa)on#of#a#search#problem#! Nodes#are#(abstracted)#world#configura)ons#! Arcs#represent#successors#(ac)on#results)#! The#goal#test#is#a#set#of#goal#nodes#(maybe#only#one)#
! In#a#search#graph,#each#state#occurs#only#once!#
! We#can#rarely#build#this#full#graph#in#memory#(it’s#too#big),#but#it’s#a#useful#idea#
#
S
G
d
b
p q
c
e
h
a
f
r
Tiny%search%graph%for%a%0ny%search%problem%Now, build the Search Tree
DepthJFirst#Search#
Depth-First Search
12
DepthJFirst#Search#
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
S
G
d
b
p q
c
e
h
a
f
r q p h
f d
b a
c
e
r
Strategy:%expand%a%deepest%node%first%
Implementa0on:%Fringe%is%a%LIFO%stack%
DFS properties
• Time?
• Space?
• Complete?
• Optimal?
13
DepthJFirst#Search#(DFS)#Proper)es#
…b
1 node b nodes
b2 nodes
bm nodes
m tiers
! What#nodes#DFS#expand?#! Some#lem#prefix#of#the#tree.#! Could#process#the#whole#tree!#! If#m#is#finite,#takes#)me#O(bm)#
! How#much#space#does#the#fringe#take?#! Only#has#siblings#on#path#to#root,#so#O(bm)#
! Is#it#complete?#! m#could#be#infinite,#so#only#if#we#prevent#
cycles#(more#later)#
! Is#it#op)mal?#! No,#it#finds#the#“lemmost”#solu)on,#
regardless#of#depth#or#cost#
d - depth of a solution
BFS vs DFS
14
Iterative Deepening Search
• Run a DFS with depth limit 1
• If no solution
• Run a DFS with depth limit 2
• …
15
Itera)ve#Deepening#
…b
! Idea:#get#DFS’s#space#advantage#with#BFS’s#)me#/#shallowJsolu)on#advantages#! Run#a#DFS#with#depth#limit#1.##If#no#solu)on…#! Run#a#DFS#with#depth#limit#2.##If#no#solu)on…#! Run#a#DFS#with#depth#limit#3.##…..#
! Isn’t#that#wastefully#redundant?#! Generally#most#work#happens#in#the#lowest#level#searched,#so#not#so#bad!#
Is it not too wasteful? Even compared to the BFS?
Cost-sensitive search
16
CostJSensi)ve#Search#
BFS#finds#the#shortest#path#in#terms#of#number#of#ac)ons.#It#does#not#find#the#leastJcost#path.##We#will#now#cover#a#similar#algorithm#which#does#find#the#leastJcost#path.###
START
GOAL
d
b
p q
c
e
h
a
f
r
2
9 2
8 1
8
2
3
2
4
4
15
1
3 2
2
What about using the BFS?
Uniform Cost Search (UCS)
17
Uniform#Cost#Search#
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
Strategy: expand a cheapest node first:
Fringe is a priority queue (priority: cumulative cost) S
G
d
b
p q
c
e
h
a
f
r
3 9 1
16 4 11
5
7 13
8
10 11
17 11
0
6
3 9
1
1
2
8
8 2
15
1
2
Cost contours
2
UCS properties
• Time
• Space
• Complete?
• Optimal?
18
…
Uniform#Cost#Search#(UCS)#Proper)es#
! What#nodes#does#UFS#expand?#! Processes#all#nodes#with#cost#less#than#cheapest#solu)on!#! If#that#solu)on#costs#C* and#arcs#cost#at#least#ε , then#the#
“effec)ve#depth”#is#roughly#C*/ε#! Takes#)me#O(bC*/ε)#(exponen)al#in#effec)ve#depth)#
! How#much#space#does#the#fringe#take?#! Has#roughly#the#last#)er,#so#O(bC*/ε)#
! Is#it#complete?#! Assuming#best#solu)on#has#a#finite#cost#and#minimum#arc#cost#
is#posi)ve,#yes!#
! Is#it#op)mal?#! Yes!##(Proof#next#lecture#via#A*)#
b
C*/ε “tiers” c ≤ 3
c ≤ 2 c ≤ 1
• C⇤- solution cost
• ✏ - arc minimum cost
The One Queue
• All algorithms the same …
• except the fringe strategies
19