uninformed search - · pdf fileuninformed search hal daumé iii computer science...

38
CS421: Intro to AI 1 Hal Daumé III ([email protected]) Uninformed Search Hal Daumé III Computer Science University of Maryland [email protected] CS 421: Introduction to Artificial Intelligence 31 Jan 2012 Many slides courtesy of Dan Klein, Stuart Russell, or Andrew Moore

Upload: hoangdang

Post on 06-Mar-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI1 Hal Daumé III ([email protected])

Uninformed Search

Hal Daumé IIIComputer ScienceUniversity of Maryland

[email protected]

CS 421: Introduction to Artificial Intelligence

31 Jan 2012

Many slides courtesy ofDan Klein, Stuart Russell,

or Andrew Moore

Page 2: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI2 Hal Daumé III ([email protected])

Announcements➢ Forgot to tell you login information for web page:

➢ User name = “cs421” (but no quotes)➢ Password = “________” (still no quotes)➢ (this will be used for posting solutions)

➢ Junkfood machines:➢ You may develop at home, but must run on Junkfood

➢ Homework 1 has been posted➢ Project 1 will be posted soon

Page 3: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI3 Hal Daumé III ([email protected])

Today➢ Agents that Plan Ahead

➢ Search Problems

➢ Uniformed Search Methods➢ Depth-First Search➢ Breadth-First Search➢ Uniform-Cost Search

Page 4: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI4 Hal Daumé III ([email protected])

Search Problems

➢ A search problem consists of:

➢ A state space

➢ A successor function

➢ A start state and a goal test

➢ A solution is a sequence of actions (a plan) which transforms the start state to a goal state

“N”, 1.0

“E”, 1.0

Page 5: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI5 Hal Daumé III ([email protected])

Reflex Agents➢ Reflex agents:

➢ Choose action based on current percept and memory

➢ May have memory or a model of the world’s current state

➢ Do not consider the future consequences of their actions

➢ Can a reflex agent be rational?

[demo: reflex ]

Page 6: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI6 Hal Daumé III ([email protected])

Goal Based Agents➢ Goal-based agents:

➢ Plan ahead

➢ Decisions based on (hypothesized) consequences of actions

➢ Must have a model of how the world evolves in response to actions

[demo: plan fast / slow ]

Page 7: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI7 Hal Daumé III ([email protected])

Search Trees

➢ A search tree:➢ This is a “what if” tree of plans and outcomes➢ Start state at the root node➢ Children correspond to successors➢ Nodes labeled with states, correspond to PLANS to those

states➢ For most problems, can never build the whole tree

➢ So, have to find ways to use only the important parts!

“E”, 1.0“N”, 1.0

Page 8: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI8 Hal Daumé III ([email protected])

State Space Graphs

➢ There’s some big graph in which

➢ Each state is a node

➢ Each successor is an outgoing arc

➢ Important: For most problems we could never actually build this graph

➢ How many states in Pacman?

S

G

d

b

p q

c

e

h

a

f

r

Laughably tiny search graph for a tiny search

problem

u.hal3.name/ic.pl?q=q

Page 9: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI9 Hal Daumé III ([email protected])

Example: Romania

Page 10: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI10 Hal Daumé III ([email protected])

Another Search Tree

➢ Search:➢ Expand out possible plans➢ Maintain a fringe of unexpanded plans➢ Try to expand as few tree nodes as possible

Page 11: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI11 Hal Daumé III ([email protected])

States vs. Nodes

➢ Problem graphs have problem states➢ Represent an abstracted state of the world➢ Have successors, predecessors, can be goal / non-goal

➢ Search trees have search nodes➢ Represent a plan (path) which results in the node’s state➢ Have 1 parent, a length and cost, point to a problem state➢ Expand uses successor function to create new tree nodes➢ The same problem state in multiple search tree nodes

Page 12: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI12 Hal Daumé III ([email protected])

General Tree Search

➢ Important ideas:➢ Fringe➢ Expansion➢ Exploration strategy

➢ Main question: which fringe nodes to explore?

Detailed pseudocode is in the book!

Page 13: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI13 Hal Daumé III ([email protected])

Example: Tree Search

S

G

d

b

pq

c

e

h

a

f

r

Page 14: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI14 Hal Daumé III ([email protected])

State Graphs vs Search Trees

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c G

a

S

G

d

b

pq

c

e

h

a

f

r

We almost always construct both on demand – and we construct as little as possible.

Each NODE in in the search tree is an entire PATH in the problem graph.

Page 15: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI15 Hal Daumé III ([email protected])

Review: Depth First Search

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c G

a

S

G

d

b

pq

c

e

h

a

f

rq

p

h

fd

b

a

c

e

r

Strategy: expand deepest node first

Implementation: Fringe is a LIFO stack

Page 16: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI16 Hal Daumé III ([email protected])

Review: Breadth First Search

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c G

a

S

G

d

b

p q

ce

h

a

f

r

Search

Tiers

Strategy: expand shallowest node first

Implementation: Fringe is a FIFO queue

Page 17: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI17 Hal Daumé III ([email protected])

Search Algorithm Properties

Complete? Guaranteed to find a solution if one exists? Optimal? Guaranteed to find the least cost path? Time complexity? Space complexity?

Variables:

n Number of states in the problem

b The average branching factor B(the average number of successors)

C* Cost of least cost solution

s Depth of the shallowest solution

m Max depth of the search tree

Page 18: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI18 Hal Daumé III ([email protected])

DFS

➢ Infinite paths make DFS incomplete…➢ How can we fix this?

Algorithm Complete Optimal Time Space

DFS Depth First Search

N N O(BLMAX) O(LMAX)

START

GOAL

a

b

N N Infinite Infinite

n # states b avg branch C* least cost s shallow goal m max depth

Page 19: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI19 Hal Daumé III ([email protected])

DFS

➢ With cycle checking, DFS is complete.

b 1 node

b nodes

b2 nodes

bm nodes

m tiers

n # states b avg branch C* least cost s shallow goal m max depth

Algorithm Complete Optimal Time Space

DFS w/ Path Checking

N N O(BLMAX) O(LMAX)Y

u.hal3.name/ic.pl?q=dfs

Page 20: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI20 Hal Daumé III ([email protected])

BFS

…b

1 node

b nodes

b2 nodes

bm nodes

s tiers

bs nodes

n # states b avg branch C* least cost s shallow goal m max depth

Page 21: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI21 Hal Daumé III ([email protected])

Iterative Deepening

Iterative deepening uses DFS as a subroutine:

1. Do a DFS which only searches for paths of length <=1 (DFS gives up on path of length 2)

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 Complete Optimal Time Space

DFS w/ Path Checking

BFS

ID

Y

Y

Y

…b

n # states b avg branch C* least cost s shallow goal m max depth

Page 22: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI22 Hal Daumé III ([email protected])

Comparisons

➢ When will BFS outperform DFS?

➢ When will DFS outperform BFS?

n # states b avg branch C* least cost s shallow goal m max depth

Page 23: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI23 Hal Daumé III ([email protected])

Costs on Actions

Notice that BFS finds the shortest path in terms of number of transitions. It does not find the least-cost path.We will quickly cover an algorithm which does find the least-cost path.

START

GOAL

d

b

pq

c

e

h

a

f

r

2

9 2

81

8

2

3

1

4

4

15

1

32

2

Page 24: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI24 Hal Daumé III ([email protected])

Uniform Cost Search

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c G

a

Expand cheapest node first:

Fringe is a priority queue S

G

d

b

pq

c

e

h

a

f

r

3 9 1

16411

5

713

8

1011

17 11

0

6

39

1

1

2

8

8 1

15

1

2

Cost contours

2

Page 25: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI25 Hal Daumé III ([email protected])

Priority Queue Refresher

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.

➢ A priority queue is a data structure in which you can insert and retrieve (key, value) pairs with the following operations:

➢ You can promote or demote keys by resetting their priorities

➢ Unlike a regular queue, insertions into a priority queue are not constant time, usually O(log n)

➢ We’ll need priority queues for most cost-sensitive search methods.

Page 26: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI26 Hal Daumé III ([email protected])

Uniform Cost Search

➢ What will UCS do for this graph?

➢ What does this mean for completeness?

START

GOAL

a

b

1

1

0

0

Page 27: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI27 Hal Daumé III ([email protected])

Uniform Cost Search

Algorithm Complete Optimal Time Space

DFS w/ Path Checking

BFS

UCS

…b

C*/ε tiers

Y* Y O(C* bC*/ε) O(bC*/ε)

We’ll talk more about uniform cost search’s failure cases later…

n # states b avg branch C* least cost s shallow goal m max depth

Page 28: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI28 Hal Daumé III ([email protected])

Uniform Cost Problems

➢ Remember: explores increasing cost contours

➢ The good: UCS is complete and optimal!

➢ The bad:➢ Explores options in every

“direction”➢ No information about goal

location

Start Goal

c ≤ 3

c ≤ 2

c ≤ 1

[demo: ucs contours ]

Page 29: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI29 Hal Daumé III ([email protected])

Heuristics

Page 30: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI30 Hal Daumé III ([email protected])

Best First / Greedy Search

➢ Expand the node that seems closest…

➢ What can go wrong?

Page 31: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI31 Hal Daumé III ([email protected])

Best First / Greedy Search

START

GOAL

d

b

pq

c

e

h

a

f

r

2

9 9

81

1

2

3

5

34

4

15

1

25

2

h=12

h=11

h=8

h=8

h=5 h=4

h=6

h=9

h=0

h=4

h=6h=11

Page 32: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI32 Hal Daumé III ([email protected])

Best First / Greedy Search

➢ A common case:➢ Best-first takes you

straight to the (wrong) goal

➢ Worst-case: like a badly-guided DFS in the worst case

➢ Can explore everything➢ Can get stuck in loops

if no cycle checking

➢ Like DFS in completeness (finite states w/ cycle checking)

…b

…b

Page 33: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI33 Hal Daumé III ([email protected])

Search Gone Wrong?

Page 34: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI34 Hal Daumé III ([email protected])

Extra Work?

➢ Failure to detect repeated states can cause exponentially more work. Why?

Page 35: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI35 Hal Daumé III ([email protected])

Graph Search

➢ In BFS, for example, we shouldn’t bother expanding the circled nodes (why?)

S

a

b

d p

a

c

e

p

h

f

r

q

q c G

a

qe

p

h

f

r

q

q c G

a

Page 36: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI36 Hal Daumé III ([email protected])

Graph Search

➢ Very simple fix: never expand a state type twice

➢ Can this wreck completeness? Why or why not?➢ How about optimality? Why or why not?

Page 37: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI37 Hal Daumé III ([email protected])

Some Hints

➢ Graph search is almost always better than tree search (when not?)

➢ Fringes are sometimes called “closed lists” – but don’t implement them with lists (use sets)!

➢ Nodes are conceptually paths, but better to represent with a state, cost, and reference to parent node

Page 38: Uninformed Search - · PDF fileUninformed Search Hal Daumé III Computer Science University of Maryland me@hal3.name CS 421: Introduction to Artificial Intelligence ... Exploration

CS421: Intro to AI38 Hal Daumé III ([email protected])

Best First Greedy Search

Algorithm Complete Optimal Time Space

Greedy Best-First Search

➢ What do we need to do to make it complete?➢ Can we make it optimal? Next class!

Y* N O(bm) O(bm)

…b

m

n # states b avg branch C* least cost s shallow goal m max depth