cs 430 lecture 7 - university of...

33
Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 1 Lecture 7 Homework 2 posted, due next Thursday Questions?

Upload: others

Post on 31-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 1

Lecture 7

Homework 2 posted, due next Thursday Questions?

Page 2: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 2

Outline

Chapter 3 - Solving Problems by Searching Informed (Heuristic) Search Strategies

Greedy Best-First Search A* Search Recursive Best-First Search (RBFS)

Heuristic Functions

Page 3: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 3

Informed Search Strategies

Previous search algorithms generated new states from problem definition data only.

If search uses problem-specific data beyond the problem definition can do an informed search much more efficiently.

General approach is a best-first strategy that bases selection on an evaluation function, traditionally called f(n), that is construed as a cost estimate.

Page 4: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 4

Informed Search Strategies

Choice of f(n) determines the search strategy, and most best-first algorithms include a heuristic function, denoted h(n), where h(n) = estimated cost of cheapest path from the

state at node n to the goal state

For now, h(n) is an arbitrary, non-negative, problem specific function with constraint that h(n) = 0 when n is a goal node.

Page 5: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 5

Greedy Best-First Search

Greedy best-first search expands the node that is believed to be the closest to the goal node by using f(n) = h(n).

E.g., for the Romanian map problem, can use the straight-line distance heuristic, denoted h

SLD.

Straight-line distanceto Bucharest

Page 6: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 6

Example: Romanian Map

Choose Sibiu (253), then Faragas (176), then Bucharest (0), a goal node.

Start with Arad and expand to Sibiu (253), Timisoara (329), and Zerind (374).

Page 7: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 7

Greedy Best-First Search

Note that the value of hSLD

cannot be computed

from the problem description.

Also, it takes experience to know that hSLD

is

correlated to actual road distances, and therefore a useful heuristic function.

Evaluation: Complete? Optimal? Time? Space?

Page 8: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Thursday, January 26 CS 430 Artificial Intelligence - Lecture 6 8

Map of Romania

Page 9: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 9

A* Search

Mostly widely known form of best-first search is called A* (pronounced "A-star") search. It uses

f(n) = g(n) + h(n)

where g(n) is the (actual) path cost to reach node n and h(n) is the estimated cost from node n to the goal, making f(n) the estimated cost of the cheapest solution through n.

Expand the node with the lowest f(n). Note if h(n) = 0 for all nodes, this is the same as uniform-cost search.

Page 10: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 10

Example: Romanian Map

Choose Sibiu, then Rimnicu Vilcea (413=220+ 193), then Faragas (415 =239+176).

Start with Arad and expand to Sibiu (393=140+253), Timisoara (447=118+329), and Zerind (449=75+374).

Page 11: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 11

Example: Romanian Map

Choose Pitesti, then Bucharest (418=418+0), a goal node.

Faragas expands to Sibiu and Bucharest, but next lowest node is Pitesti (417=317+100).

Page 12: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 12

Optimality of A* Search

For certain heuristic functions, A* search is both complete and optimal using Graph-Search.

First, h(n) must be an admissible heuristic, meaning that it never overestimates the cost to reach the goal.

E.g., hSLD

is admissible, since the straight-line

distance is the minimum distance between two points, it can never be shorter than the actual road distance between two cities.

Page 13: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 13

Optimality of A* Search

Second, h(n) must be consistent, meaning that for every node n and every successor n' of n generated by any action a, the estimated cost of reaching the goal from n is no greater than the step cost of getting to n' plus the estimated cost of reaching the goal from n'. I.e.,

h(n) <= c(n, a, n') + h(n')

This a form of the triangle inequality: a side of a triangle cannot be longer than the sum of the other two sides.

Page 14: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 14

Optimality of A* Search

Proof of A* optimality with consistent h(n): If h(n) is consistent, then the values of f(n)

along any path are non-decreasing. This follows directly from the definition of

consistency. Suppose n' is a successor to n, then g(n') = g(n) + c(n, a, n') for some action a, giving

f(n') = g(n') + h(n') = g(n) + c(n, a, n') + h(n') >= g(n) + h(n) = f(n)

Page 15: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 15

Optimality of A* Search

Whenever A* selects a node n for expansion, the optimal path to that node has been found.

Prove this by contradiction: If this was not the case, there would have to be another frontier node n' on the optimal path from the start node to n by the graph separation property of Graph-Search. Because f is non-decreasing along any path, n' would have a lower f-cost than n and would have been selected first.

Page 16: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 16

Optimality of A* Search

Thus the sequence of nodes expanded by A* is in non-decreasing order of f(n).

Hence the first goal node selected for expansion must be an optimal solution, because f(n) is the true cost (h(n) = 0) and all later nodes will be at least as expensive.

Page 17: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 17

Optimality of A* Search

Then A* expands some nodes on the goal contour (f(n) = C*) before selecting a goal node.

Can draw this as contours in the search space. For example, in the Romanian map, the contour labeled 400 encloses all nodes that have f(n) <= 400.

A* expands all nodes with f(n) < C*

Page 18: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 18

Optimality of A* Search

Note: A* expands no nodes with f(n) > C*, effectively pruning away parts of the search space without having to examine them.

Among algorithms that extend search paths from the root and use the same heuristic function, A* is optimally efficient, meaning that no other optimal algorithm is guaranteed to expand fewer nodes than A*.

Page 19: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 19

Memory-Bounded Heuristic Search

Main problem with A* is space requirements. Still need to keep all generated nodes in memory.

Could using iterative deepening technique (IDA*) using f-cost (g+h) rather than depth. Works well for unit step costs, but not so well on real-valued steps costs.

Page 20: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 20

Recursive Best-First Search (RBFS)

Recursive Best-First Search (RBFS) uses linear space in a manner similar to DFS. As it goes down the tree, it keeps track of an f-limit, the f-value of the best alternative path.

When the current node exceeds the f-limit, RBFS backtracks back to the best alternative path, replacing each node's f-value with the best f-value of its children. This allows RBFS to decide to re-expand the subtree if needed.

Page 21: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 21

Example: Romanian Map

RBFS chooses Sibiu (393), but keeps track of Timisoara (447). Likewise it chooses Rimnicu Vilcea (413), but keeps track of Faragas (415).

Lowest child Pitesti (417) is less than f-limit (415), so must back track.

Page 22: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 22

Example: Romanian Map

Unwind back to Sibiu, keeping track of 417 in Rimnicu Vilcea. RFBS then chooses Faragas (415) keeping track of Rimnicu Vilcea (417).

Both children are larger than 417, so go back to Sibiu and re-expand Rimnicu Vilcea.

Page 23: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 23

Example: Romanian Map

Keep track of the new best alternative Timisoara (447). Re-expand Rimnicu Vilcea, then choose Pitesti (417).

Bucharest (418) is lowest and is a goal node.

Page 24: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 24

Memory-Bounded Heuristic Search

IDA* and RBFS both suffer from re-expanding many nodes that have already been visited while not being able to take advantage of any available extra memory.

MA* (memory-bounded A*) and SMA* (simple MA*) expand nodes until memory is full, then deletes frontier nodes starting with the worst one, backing up the value of the forgotten node.

Page 25: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 25

Heuristic Functions

Average solution is 22 steps. b is about 3 Uninformed tree search is 322 ~= 3.1 x 1010

Uninformed graph search is ~170,000 For 15-puzzle, graph search is ~1013

Page 26: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 26

Heuristic Functions

To use A* search, need an admissible h(n), two common ones:

h1 = number of misplaced tiles. Clearly admissible

since every misplaced tile must be moved at least once.

h2 = sum of the distances of tiles from their goal

positions. Use Manhattan distance, the sum of the vertical and horizontal distances, since tiles cannot move diagonally. Admissible, since any move can only move a tile one step closer to its goal position.

Page 27: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 27

Heuristic Functions

For a problem with solution at d = 22 IDS generates more nodes than will fit in memory

A*(h1) generates ~18,000 nodes

A*(h2) generates ~1200 nodes

Even for a problem with solution at d = 6 IDS generates ~680 nodes

A*(h1) generates ~20 nodes

A*(h2) generates ~18 nodes

Page 28: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 28

Heuristic Functions

To compare heuristic functions, look at the effective branching factor, b*. For a solution with N total nodes and solution at depth d, b* is the branching factor that a uniform tree of depth d would have in order to contain N+1 nodes. I.e., N+1 = 1 + b* + (b*)2 + … + (b*)d

Better heuristics generate b* values close to 1. If h

2(n) >= h

1(n) for any node n, then can say h

2

dominates h1. Means that h

2 will never expand

more nodes than h1.

Page 29: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 29

Generating Admissible Heuristics

One way to generate an admissible heuristic is to look at solutions to relaxed problems, problems with fewer restrictions on the actions.

The state space of a relaxed problem adds edges to the original state space. The optimal solution to the original problem will be a solution to the relaxed problem, but their may be better solutions, thus the cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem.

Page 30: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 30

Example: 8-puzzle

Original problem: A tile can move from square A to square B if A is horizontally or vertically adjacent to B and B is blank.

Remove one or both restrictions to get relaxed problems:

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

(b) A tile can move from square A to square B if B is blank.

(c) A tile can move from square A to square B.

Page 31: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 31

Example: 8-puzzle

From (a), can derive h2 (Manhattan distance)

From (c), can derive h1 (misplaced tiles)

Heuristic derived from (b) is a homework problem...

Page 32: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 32

Generating Admissible Heuristics

Admissible heuristics can be generated from pattern databases storing exact solutions to subproblems of the original problem. E.g., all solutions to configurations of the 8-puzzle involving 1-2-3-4-blank.

Page 33: CS 430 Lecture 7 - University of Evansvilleuenics.evansville.edu/~hwang/s12-courses/cs430/lecture07... · 2012-01-31 · Tuesday, January 31 CS 430 Artificial Intelligence - Lecture

Tuesday, January 31 CS 430 Artificial Intelligence - Lecture 7 33

Learning Heuristics from Experience

An agent could construct a function h(n) by solving many instances and comparing the value of a feature relevant to predicting the state's value and the actual cost.

E.g., a feature might be "number of misplaced tiles", called x(n), and after 100 randomly generated puzzles, could determine that when x(n) = 5 that average solution cost is ~14. Then can use x(n) to predict h(n).