CS 294-5: Statistical Natural Language Processing

Download Report

Transcript CS 294-5: Statistical Natural Language Processing

CS 5368: Artificial Intelligence
Fall 2010
Lecture 2: Search Part1
8/31/2010
Mohan Sridharan
Slides adapted from Dan Klein
General Questions
 Access to textbook and course material?
 Python tutorial or online link?
 Read chapters 1, 2?
 Any questions?
This Lecture
 Agents that plan, i.e., look ahead.
 Search problems.
 Un-informed Search Methods:
 Depth-First Search.
 Breadth-First Search.
 Uniform-Cost Search.
 Heuristic Search Methods:
 Greedy Search.
Review: Reflex Agents
 Reflex agents:
 Choose action based on
current percept (and
maybe memory).
 May have memory or a
model of the current
state.
 Do not consider the
future consequences of
their actions.
 Act on how the world IS.
 Can a reflex agent be
rational?
Review: Goal Based Agents
 Goal-based agents:
 Ask “what if”.
 Decisions based on
(hypothesized) action
consequences.
 Need a model of how
the world evolves in
response to actions.
 Act on how the world
WOULD BE.
Search Problems
 A search problem consists of:
 State space:
 Actions and
successor function:
“N”, 1.0
“E”, 1.0
 Start state, goal test, path cost.
 A solution is a sequence of actions (a plan) that
transforms the start state to a goal state.
Example: Romania
 State space:
 Cities.
 Successor
function:
 Go to adj city
cost = dist.
 Start state:
 Arad.
 Goal test:
 Is state ==
Bucharest?
 Solution?
State Space Graphs
 State space graph: A
mathematical model of a
search problem:
 For every search problem,
there’s a corresponding
state space graph.
 The successor function is
represented by arcs.
 We can rarely build this
graph in memory (so we
do not!).
G
a
c
b
e
d
f
S
h
p
q
r
Ridiculously tiny search graph
for a tiny search problem
State Space Sizes?
 Search Problem:
Eat all of the food 
 Pacman positions: 30
 Food count: 30
 Ghost positions: 12
 Pacman facing:
up, down, left, right.
Search Trees
“N”, 1.0
“E”, 1.0
 A search tree:





This is a “what if” tree of plans and outcomes.
Start state at the root node.
Children correspond to successors.
Nodes contain states, correspond to plans to those states.
For most problems, we can never actually build the whole tree!
Search Tree Example
 Search:
 Expand out possible plans.
 Maintain a fringe of unexpanded plans.
 Try to expand as few tree nodes as possible.
General Tree Search
 Important ideas:
 Fringe; frontier; open list.
 Expansion.
 Exploration strategy.
Pseudo-code is in
Figure 3.7.
 Main question: which fringe nodes to explore?
State Graphs vs. Search Trees
G
a
Each NODE in in the
search tree is an
entire PATH in the
problem graph.
c
b
e
d
f
S
h
p
r
q
S
e
d
We construct both
on demand – and
we construct as
little as possible.
b
c
a
a
e
h
p
q
q
c
a
h
r
p
f
q
G
p
q
r
q
f
c
a
G
Review: Breadth First Search
G
a
Strategy: expand
shallowest node first
c
b
e
d
Implementation:
Fringe is a FIFO
queue
S
f
h
p
r
q
S
e
d
Search
Tiers
b
c
a
a
e
h
p
q
q
c
a
h
r
p
f
q
G
p
q
r
q
f
c
a
G
Review: Depth First Search
G
a
Strategy: expand
deepest node first
c
b
e
d
Implementation:
Fringe is a LIFO
stack
f
S
h
p
r
q
S
e
d
b
c
a
a
e
h
p
q
q
c
a
h
r
p
f
q
G
p
q
r
q
f
c
a
G
Search Algorithm Properties




Complete: guaranteed to find a solution if one exists?
Optimal: guaranteed to find the least cost path?
Time complexity: how long to find a solution?
Space complexity: how much memory for search?
Variables:
n
Number of states in the problem.
b
The average branching factor B
(the average number of successors).
Cost of least costly solution.
C*
s
Depth of the shallowest solution.
m
Max depth of the search tree.
BFS Again…
 Optimal only if path cost is a non-decreasing function of node depth.
 Solution at (shallowest) depth s: time complexity O(bs+1).
 Every generated node remains in memory: space complexity O(bs).
 Exponential complexity is scary! See Figure 3.13 
 Memory requirements bigger problem than execution time!
Uniform-cost Search
 Expand nodes in the order of optimal path cost.
 Shallowest goal state is optimal solution.
 Optimal for any step-cost function!
 Pseudo-code in Figure 3.14.
 Will come back to this in a few slides.
DFS Again…
Algorithm
DFS
Depth First
Search
Complete Optimal
Time
Space
N
LMAX)
O(B
Infinite
O(LMAX)
Infinite
No
N No
b
START
a
GOAL
 Infinite paths make DFS incomplete, LIFO queue.
 How can we fix this? Solution: cycle/path checking.
DFS
 With cycle checking, DFS is complete.*
…
b
1 node
b nodes
b2 nodes
m tiers
bm nodes
 Time complexity: O(bm+1)
 Why not just do BFS then?
 When is DFS optimal?
* Or graph search – next lecture.
DFS
 Pseudo-code in Figure 3.16.
 Once a node has been expanded and its descendants explored, it
can be removed from memory!
 Space complexity is O(bm), much smaller than BFS.
 The main benefit is the space complexity.
 More sophistication:
 Backtracking search (Chapter 6).
 Depth-limited search (Figure 3.17 in Section 3.4.4).
Algorithm
DFS
w/ Path
Checking
Complete
Yes
Optimal
No
Time
O(bm+1)
Space
O(bm)
* Or graph search – next lecture.
BFS vs. DFS
Algorithm
DFS
Complete
w/ Path
Checking
BFS
s tiers
Optimal
Time
Space
Yes
No
O(bm+1)
O(bm)
Yes
No*
O(bs+1)
O(bs)
…
b
1 node
b nodes
b2 nodes
bs nodes
bm nodes
Comparisons
 When will BFS outperform DFS?
 When will DFS outperform BFS?
Iterative Deepening
Iterative deepening uses depth-limited search as
a subroutine (Figure 3.18):
…
b
1. Do a DFS which only searches for paths of
length 1 or less.
2. If “1” failed, do a DFS which only searches paths
of length 2 or less.
3. If “2” failed, do a DFS which only searches paths
of length 3 or less.
….and so on.
Algorithm
DFS
w/ Path
Checking
Complete Optimal
Time
Space
Y
N
O(bm+1)
O(bm)
BFS
Y
N*
O(bs+1)
O(bs)
ID
Y
N*
O(bs+1)
O(bs)
Iterative Deepening
 Time complexity for depth d: O(bd).
 Asymptotically similar to BFS.
 N(IDS) = (d)b + (d-1)b2 + … + (1) bd
 Can be combined with BFS as well.
 Best choice among uninformed search methods!
Costs on Actions
GOAL
a
2
2
c
b
1
3
2
8
2
e
d
3
9
8
START
p
15
2
h
4
1
f
4
q
1
r
BFS finds the shortest path in terms of number of transitions. It does
not find the least-cost path.
Uniform Cost Search
2
b
Expand cheapest node first:
d
S
1
p
15
Cost
contours
c
a 6
a
h 17 r 11
e 5
11
p
9
e
3
b 4
h 13 r 7
p
f 8
q
q
q 11 c
a
G 10
2
9
2
e
h
8
q
f
c
a
G
f
1
1
r
q
0
S
d
c
8
1
3
Fringe is a priority queue
G
a
p
1
q
16
Priority Queue Refresher
 A priority queue is a data structure in which you can insert
and retrieve (key, value) pairs with the following operations:
pq.push(key, value)
inserts (key, value) into the queue.
pq.pop()
returns the key with the lowest value, and
removes it from the queue.
 You can decrease a key’s priority by pushing it again
 Unlike a regular queue, insertions aren’t constant time,
usually O(log n)
 We’ll need priority queues for cost-sensitive search methods
DFS, BFS and UCS
Algorithm
DFS
Complete Optimal
w/ Path
Checking
Time
Space
Y
N
O(bm+1)
O(bm)
BFS
Y
N
O(bs+1)
O(bs)
UCS
Y*
Y
O(bC*/)
O(bC*/)
…
C*/ tiers

b
* UCS can fail if
actions can get
arbitrarily cheap
See Figure 3.21 for comparison of all uninformed search strategies.
Uniform Cost Issues
 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
Search Heuristics
 Any estimate of how close a state is to a goal.
 Designed for a particular search problem.
 Examples: Manhattan distance, Euclidean distance.
10
5
11.2
Heuristics
Best First / Greedy Search
 Expand the node that seems closest…
 What can go wrong?
Best First / Greedy Search
 A common case:
 Best-first takes you straight
to the (wrong) goal.
…
b
 Worst-case: like a badlyguided DFS in the worst
case.
 Can explore everything.
 Can get stuck in loops
without cycle checking.
 Like DFS in completeness
(finite states w/ cycle
checking).
…
b