Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I Informed = use...

26
Informed Search II CIS 391 Fall 2008

Transcript of Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I Informed = use...

Page 1: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

Informed Search II

CIS 391

Fall 2008

Page 2: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 2

OutlinePART I Informed = use problem-specific knowledge Best-first search and its variants A* - Optimal Search using Knowledge

Proof of Optimality of A*

A* for maneuvering AI agents in games Heuristic functions?

• How to invent them

PART II Local search and optimization

• Hill climbing, local beam search, genetic algorithms,… Local search in continuous spaces Online search agents

Page 3: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 3

Optimality of A* (intuitive) Lemma: A* expands nodes in order of increasing f value

Gradually adds "f-contours" of nodes

Contour i has all nodes with f=fi, where fi < fi+1

Page 4: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 4

Optimality of A* using Tree-Search I (proof) Suppose some suboptimal goal G2 has been generated and is in the fringe.

Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G.

1. g(G2) > g(G) since G2 is suboptimal 2. f(G2) = g(G2) since h(G2) = 0 & f(n) = g(n)+h(n)3. f(G) = g(G) since h(G) = 0 & f(n) = g(n)+h(n)4. f(G2) > f(G) from 1,2,3

Page 5: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 5

Optimality of A* using Tree-Search II (proof)

Suppose some suboptimal goal G2 has been generated and is in thefringe. Let n be an unexpanded node in the fringe such that n is on ashortest path to an optimal goal G.

4. f(G2) > f(G) repeated 5. h*(n) h(n) since h is admissible, and therefore optimistic6. g(n) + h*(n) g(n) + h(n) from 57. g(n) + h*(n) f(n) substituting definition of f8. f(G) f(n) from definitions of f and h* (think about it!)

9. f(G2) >f(n) from 4 & 8

So A* will never select G2 for expansion

Page 6: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 6

Show that n on a optimal path f(G)=g(n)+h*(n)

Page 7: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 7

A* search, evaluation Completeness: YES

• Since bands of increasing f are added• As long as b is finite

— (guaranteeing that there aren’t infinitely many nodes with f<f(G) )

Page 8: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 8

A* search, evaluation Completeness: YES Time complexity:

• Number of nodes expanded is still exponential in the length of the solution.

Page 9: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 9

A* search, evaluation Completeness: YES Time complexity: (exponential with path length) Space complexity:

• It keeps all generated nodes in memory

• Hence space is the major problem not time

Page 10: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 10

A* search, evaluation Completeness: YES Time complexity: (exponential with path length) Space complexity:(all nodes are stored) Optimality: YES

• Cannot expand fi+1 until fi is finished.

• A* expands all nodes with f(n)< f(G)

• A* expands one node with f(n)=f(G)

• A* expands no nodes with f(n)>f(G)

Also optimally efficient (not including ties)

Page 11: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

Search for AI Simulation

Graphics from http://theory.stanford.edu/~amitp/GameProgramming/

(A great site for practical AI & game Programming)

Page 12: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 12

Best-First Search

Yellow: nodes with high h(n) Black: nodes with low h(n)

Page 13: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 13

Dijkstra’s Algorithm

Pink: Starting Point Blue: Goal Teal: Scanned squares

• Darker: Closer to starting point…

Page 14: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 14

A* Algorithm

Yellow: examined nodes with high h(n) Blue: examined nodes with high g(n)

Page 15: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 15

Best-First Search with Obstacle

Page 16: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 16

Dijkstra’s Algorithm

Dijkstra's algorithm works harder but is guaranteed to find a shortest path

Page 17: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 17

A* Algorithm

A* finds a path as good as Dijkstra's algorithm found, but is much more efficient…

Page 18: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

Creating Good Heuristic Functions

Page 19: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 19

Heuristic functions

For the 8-puzzle

• Avg. solution cost is about 22 steps —(branching factor ≤ 3)

• Exhaustive search to depth 22: 3.1 x 1010 states• A good heuristic function can reduce the search

process

Page 20: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 20

Admissible heuristics

E.g., for the 8-puzzle: hoop(n) = number of out of place tiles hmd(n) = total Manhattan distance (i.e., # of moves

from desired location of each tile)

hoop(S) = ? hmd(S) = ?

Page 21: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 21

Admissible heuristics

E.g., for the 8-puzzle: hoop(n) = number of out of place tiles hmd(n) = total Manhattan distance (i.e., # of moves

from desired location of each tile)

hoop(S) = ? 8 hmd(S) = ? 3+1+2+2+2+3+3+2 = 18

Page 22: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 22

Relaxed problems A problem with fewer restrictions on the actions

is called a relaxed problem

The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem

If the rules of the 8-puzzle are relaxed so that a tile can move anywhere, then hoop(n) gives the shortest solution

If the rules are relaxed so that a tile can move to any adjacent square, then hmd(n) gives the shortest solution

Page 23: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 23

Defining Heuristics: h(n)

Cost of an exact solution to a relaxed problem (fewer restrictions on operator)

Constraints on Full Problem:A tile can move from square A to square B if A is adjacent to B

and B is blank.• Constraints on relaxed problems:

—A tile can move from square A to square B if A is adjacent to B. (hmd)

—A tile can move from square A to square B if B is blank.

—A tile can move from square A to square B. (hoop)

Page 24: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 24

Dominance If h2(n) ≥ h1(n) for all n (both admissible)

• then h2 dominates h1 So h2 is optimistic, but more accurate than

h1

• h2 is therefore better for search

Typical search costs (average number of nodes expanded):• d=12 Iterative Deepening Search = 3,644,035 nodes

A*(hoop) = 227 nodes A*(hmd) = 73 nodes

• d=24 IDS = too many nodesA*(hoop) = 39,135 nodes A*(hmd) = 1,641 nodes

Page 25: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 25

Proof of Lemma: Consistency A heuristic is consistent if

If h is consistent, we have

i.e. f(n) is nondecreasing along any path.

Theorem: if h(n) is consistent, A* using Graph-Searchis optimal

h(n) c(n,a,n') h(n')

f (n') g(n') h(n')

g(n) c(n,a,n') h(n')

g(n) h(n)

f (n)

Cost of getting from n to n’ by any action a

Page 26: Informed Search II CIS 391 Fall 2008. CIS 391 - Intro to AI 2 Outline PART I  Informed = use problem-specific knowledge  Best-first search and its variants.

CIS 391 - Intro to AI 26

Iterative Deepening A* and beyond

Beyond our scope:

Iterative Deepening A* Recursive best first search (incorporates A* idea, despite

name) Memory Bounded A* Simplified Memory Bounded A* - R&N say the best

algorithm to use in practice, but not described here at all.

(see pp. 101-104 if you’re interested)