33
Advanced Artificial Intelligence Lecture 2: Search

Advanced Artificial Intelligence Lecture 2: Search

Embed Size (px)

Citation preview

Page 1: Advanced Artificial Intelligence Lecture 2: Search

Advanced Artificial Intelligence

Lecture 2: Search

Page 2: Advanced Artificial Intelligence Lecture 2: Search

2

Outline

Problem-solving agents (Book: 3.1) Problem types and problem formulation

Search trees and state space graphs (3.3) Uninformed search (3.4)

Depth-first, Breadth-first, Uniform cost Search graphs

Informed search (3.5) Greedy search, A* search Heuristics, admissibility

Page 3: Advanced Artificial Intelligence Lecture 2: Search

Agents

act = AgentFn(percept)

sensors

agent fn

actuators3

Page 4: Advanced Artificial Intelligence Lecture 2: Search

4

Problem types Fully observable, deterministic

single-belief-state problem Non-observable

sensorless (conformant) problem Partially observable/non-deterministic

contingency problem interleave search and execution

Unknown state space exploration problem execution first

Page 5: Advanced Artificial Intelligence Lecture 2: Search

Search Problems

A search problem consists of:

A state space

A transition model

A start state, goal test, and path cost function

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

N, 1

E, 1

Page 6: Advanced Artificial Intelligence Lecture 2: Search

Transition Models

Successor function Successors( ) = {(N, 1, ), (E, 1, )}

Actions and Results Actions( ) = {N, E} Result( , N) = ; Result( , E) =

Cost( , N, ) = 1; Cost( , E, ) = 1

Page 7: Advanced Artificial Intelligence Lecture 2: Search

Example: Romania

State space: Cities

Successor function: Go to adj city

with cost = dist

Start state: Arad

Goal test: Is state ==

Bucharest?

Solution?

Page 8: Advanced Artificial Intelligence Lecture 2: Search

State Space Graphs

State space graph: A mathematical representation of a search problem For every search problem,

there’s a corresponding state space graph

The successor function is represented by arcs

This can be large or infinite, so we won’t create it in memory

S

G

d

b

pq

c

e

h

a

f

r

Ridiculously tiny search graph for a tiny search problem

Page 9: Advanced Artificial Intelligence Lecture 2: Search

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 contain states, correspond to paths to those states For most problems, we can never actually build the whole tree

E, 1N, 1

Page 10: Advanced Artificial Intelligence Lecture 2: Search

Another Search Tree

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

Page 11: Advanced Artificial Intelligence Lecture 2: Search

General Tree Search

Important ideas: Frontier (aka fringe) Expansion Exploration strategy

Main question: which frontier nodes to explore?

Page 12: Advanced Artificial Intelligence Lecture 2: Search

State Space vs. Search Tree

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 Ga

S

G

d

b

p q

c

e

h

a

f

r

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

Each NODE in in the search tree is an entire PATH in the state space.

Page 13: Advanced Artificial Intelligence Lecture 2: Search

States vs. Nodes Nodes in state space graphs are problem states

Represent an abstracted state of the world Have successors, can be goal / non-goal, have multiple predecessors

Nodes in search trees are paths Represent a path (sequence of actions) which results in the node’s state Have a problem state and one parent, a path length, (a depth) & a cost The same problem state may be achieved by multiple search tree nodes

Depth 5

Depth 6

Parent

Node

Search TreeState Space Graph

Action

Page 14: Advanced Artificial Intelligence Lecture 2: Search

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

p q

c

e

h

a

f

rqp

hfd

b

ac

e

r

Strategy: expand deepest node first

Implementation: Frontier is a LIFO stack

Page 15: Advanced Artificial Intelligence Lecture 2: Search

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

c

e

h

a

f

r

Search

Tiers

Strategy: expand shallowest node first

Implementation: Fringe is a FIFO queue

[demo: bfs]

Page 16: Advanced Artificial Intelligence Lecture 2: Search

Santayana’s Warning

“Those who cannot remember the past are condemned to repeat it.” – George Santayana

Failure to detect repeated states can cause exponentially more work (why?)

Page 17: Advanced Artificial Intelligence Lecture 2: Search

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 18: Advanced Artificial Intelligence Lecture 2: Search

Graph Search Very simple fix: never expand a state twice

Can this wreck completeness? Lowest cost?

Page 19: Advanced Artificial Intelligence Lecture 2: Search

Graph Search Hints

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

Implement explored as a dict or set

Implement frontier as priority Q and set

Page 20: Advanced Artificial Intelligence Lecture 2: Search

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 21: Advanced Artificial Intelligence Lecture 2: Search

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:

Frontier is a priority queueS

G

d

b

p q

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 22: Advanced Artificial Intelligence Lecture 2: Search

Uniform Cost Issues

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

Page 23: Advanced Artificial Intelligence Lecture 2: Search

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 24: Advanced Artificial Intelligence Lecture 2: Search

AI Lesson

To do more,

Know more

Page 25: Advanced Artificial Intelligence Lecture 2: Search

Heuristics

Page 26: Advanced Artificial Intelligence Lecture 2: Search

Greedy Best First Search

Expand the node that seems closest to goal…

What can go wrong?

Page 27: Advanced Artificial Intelligence Lecture 2: Search

Greedy goes wrong

SG

Page 28: Advanced Artificial Intelligence Lecture 2: Search

Combining UCS and Greedy Uniform-cost orders by path cost, or backward cost g(n) Best-first orders by distance to goal, or forward cost h(n)

A* Search orders by the sum: f(n) = g(n) + h(n)

S a d

b

Gh=5

h=6

h=2

1

5

11

2

h=6h=0

c

h=7

3

e h=11

Page 29: Advanced Artificial Intelligence Lecture 2: Search

Should we stop when we enqueue a goal?

No: only stop when we dequeue a goal

When should A* terminate?

S

B

A

G

2

3

2

2h = 1

h = 2

h = 0

h = 3

Page 30: Advanced Artificial Intelligence Lecture 2: Search

Is A* Optimal?

A

GS

1

3h = 6

h = 0

5

h = 7

What went wrong? Actual bad path cost (5) < estimate good path cost (1+6) We need estimates (h=6) to be less than

actual (3) costs!

Page 31: Advanced Artificial Intelligence Lecture 2: Search

Admissible Heuristics

A heuristic h is admissible (optimistic) if:

where is the true cost to a nearest goal

Never overestimate!

Page 32: Advanced Artificial Intelligence Lecture 2: Search

Other A* Applications

Path finding / routing problems Resource planning problems Robot motion planning Language analysis Machine translation Speech recognition …

Page 33: Advanced Artificial Intelligence Lecture 2: Search

Summary: A*

A* uses both backward costs, g(n), and (estimates of) forward costs, h(n)

A* is optimal with admissible heuristics

A* is not the final word in search algorithms(but it does get the final word for today)