CS 4700:
Foundations of
Artificial Intelligence
Spring 2020
Prof. Haym Hirsh
Lecture 4
Reminder: Technology Policy
Reminder: Due Feb 4
• Special accommodations letter:
Scan documentation letter and email to
[email protected]
First Karma Lecture
The Principal-Agent Value Alignment Problem in Artificial Intelligence
Textbook
So far:
“Uninformed” Search: Sections 3.1-3.5 Upcoming:
“Informed” Search: Sections 3.6.1, 4.1
1 10 6 2 3 4 5 7 8 9 11 12 13
Depth-First Search
1 4 3 2 5 6 7 8 9 11 12 13
Breadth-First Search
10DFS vs BFS
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
Space O(bm) O(bd)
Complete: If there’s a solution you will find it
Optimal: You will find the
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
Space O(bm) O(bd)
DFS can miss optimal solutions BFS won’t
Complete: If there’s a solution you will find it
Optimal: You will find the
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
Space O(bm) O(bd)
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
Space O(bm) O(bd)
Loosely, number of nodes expanded Worst-case exponential DFS: in depth of search space
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
Space O(bm) O(bd)
Loosely, number of nodes expanded Worst-case exponential DFS: in depth of search space
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
Space O(bm) O(bd)
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
Space O(bm) O(bd)
Loosely, number of nodes in Open
DFS vs BFS: more detail
DFS vs BFS: more detail
• b: branching factor (finite) • d: depth of solution (finite) • Assume a tree of depth m
DFS vs BFS: more detail
DFS vs BFS: more detail
• b: branching factor (finite) • d: depth of solution (finite) • Assume a tree of depth m
DFS vs BFS: more detail
• b: branching factor (finite) • d: depth of solution (finite) • Assume a tree of depth m
But search space is a graph not a tree!
DFS vs BFS: more detail
• b: branching factor (finite) • d: depth of solution (finite) • Assume a tree of depth m
Space = # of nodes in Open – what about Closed? Because we check if a state has already been visited,
DFS vs BFS: more detail
• b: branching factor (finite) • d: depth of solution (finite) • Assume a tree of depth m
DFS vs BFS: more detail
• b: branching factor (finite) • d: depth of solution (finite) • Assume a tree of depth m
Space = # of nodes in Open – what about Closed? (Handwavy response, see book for more handwaving)
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
DFS vs BFS:
Handwavy Analysis
Method DFS BFS
Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd)
Space O(bm) O(bd)
DFS vs BFS
DFS vs BFS
Search Algorithm Template
Initial call: Search(initialstate,ops,{},{})
Search(s,ops,open,closed) =
If goal(s) Then return(s); Else If not(s closed)
Then
successors {}; add(s,closed); For each o ops that applies to s
add apply(o,s) to successors open add successors to open;
If not(empty(open))
s’ select(open);
open remove(s’,open);
DFS
Initial call: DFS(initialstate,ops,{},{})
DFS(s,ops,open,closed) =
If goal(s) Then return(s); Else If not(s closed)
Then
successors {}; add(s,closed); For each o ops that applies to s
add apply(o,s) to successors open add successors to open;
If not(empty(open))
s’ newest(open);
open remove(s’,open);
Depth-Bounded Depth-First Search
Initial call: DBDFS(initialstate,ops,{},{},bound)
DBDFS(s,ops,open,closed,bound) = If goal(s) Then return(s);
Else If not(s closed) and bound>0
Then
successors {}; add(s,closed); For each o ops that applies to s
add apply(o,s) to successors open add successors to open;
If not(empty(open))
s’ newest(open);
open remove(s’,open);
Iterative Deepening Search
IDS(s,ops) i=0
loop {result = DBDFS(s,ops,{},{},i) if result = fail then i=i+1 else return(result)}
Depth-Bounded Depth-First Search
Initial call: DBDFS(initialstate,ops,{},{},bound)
DBDFS(s,ops,open,closed,bound) = If goal(s) Then return(s);
Else If not(s closed) and bound>0
Then
successors {}; add(s,closed); For each o ops that applies to s
add apply(o,s) to successors open add successors to open;
If not(empty(open))
s’ newest(open);
open remove(s’,open);
Iterative Deepening Search
1,2Iterative Deepening Search
1,2Iterative Deepening Search
1,2Iterative Deepening Search
1,2,6Iterative Deepening Search
1,2,6Iterative Deepening Search
8
1,2,6
Iterative Deepening Search
8 9
1,2,6
Iterative Deepening Search
8 9 10
1,2,6
Iterative Deepening Search
8 9 10
1,2,6
Iterative Deepening Search
8 9 10 12
1,2,6
Iterative Deepening Search
8 9 10 12 13
1,2,6
Iterative Deepening Search
8 9 10 12 13 14
1,2,6
Iterative Deepening Search
8 9 10 12 13 14
1,2,6
Iterative Deepening Search
8 9 10 12 13 14 16
1,2,6
Iterative Deepening Search
8 9 10 12 13 14 16 17
1,2,6
Iterative Deepening Search
8 9 10 12 13 14 16 17 18
1,2,6
Iterative Deepening Search
What???
b=2 # States Visited
Level Depth-First Iterative Deepening Ratio
b=2 # States Visited
Level Depth-First Iterative Deepening Ratio
b=10 # States Visited
Level Depth-First Iterative Deepening Ratio
DFS vs BFS vs IDS
Method DFS BFS IDS Complete? Yes Yes
Optimal? No Yes
Time O(bm) O(bd) O()
DFS vs BFS vs IDS
Method DFS BFS IDS Complete? Yes Yes Yes
Optimal? No Yes Yes
Time O(bm) O(bd) O(bd)
Space O(bm) O(bd) O(bd)
Time Complexity of IDS
• Time for depth-bounded depth-first search to level i: O(bi)
Time Complexity of IDS
• Time for depth-bounded depth-first search to level i: O(bi)
• Time for IDS is the sum of this time for i = 0, …, d
Time Complexity of IDS
• Time for depth-bounded depth-first search to level i: O(bi)
• Time for IDS is the sum of this time for i = 0, …, d
Time Complexity of IDS
• Time for depth-bounded depth-first search to level i: O(bi)
• Time for IDS is the sum of this time for i = 0, …, d
𝑖=0 𝑑
𝑏𝑖 = 𝑏
𝑑+1 − 1
Time Complexity of IDS
• Time for depth-bounded depth-first search to level i: O(bi)
• Time for IDS is the sum of this time for i = 0, …, d
Time Complexity of IDS
• Time for depth-bounded depth-first search to level i: O(bi)
• Time for IDS is the sum of this time for i = 0, …, d
𝑖=0 𝑑 𝑏𝑖 = 𝑏 𝑑+1 − 1 𝑏 − 1 This is O(bd)
Iterative Deepening Search
• The amount of wasted effort is a fraction of the time for the final stage of the search
• That fraction gets smaller as the branching factor gets bigger
• In exchange for that, you get linear space! (In d, not m!) Looks like BFS in the right ways