cs 440 / ece 448 introduction to artificial intelligence...

90
Instructor: Eyal Amir Grad TAs: Wen Pu, Yonatan Bisk Undergrad TAs: Sam Johnson, Nikhil Johri CS 440 / ECE 448 Introduction to Artificial Intelligence Spring 2010 Lecture #4

Upload: lelien

Post on 05-Feb-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Instructor: Eyal AmirGrad TAs: Wen Pu, Yonatan Bisk

Undergrad TAs: Sam Johnson, Nikhil Johri

CS 440 / ECE 448Introduction to Artificial Intelligence

Spring 2010Lecture #4

Page 2: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

When to Use Search Techniques?

The search space is small, andThere is no other available techniques, orIt is not worth the effort to develop a more efficient technique

The search space is large, andThere is no other available techniques, andThere exist “good” heuristics

Page 3: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Models, |=, math proofs

Alpha |= BetaAlpha, Beta – propositional formulasM |= Alpha “M models Alpha” means “Alpha evaluated to TRUE in model M”

Math. Proofs: exampleA � B |= A(another one later in today’s class)

Page 4: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Search AlgorithmsBlind search – BFS, DFS, ID, uniform cost

no notion concept of the “right direction”can only recognize goal once it’s achieved

Heuristic search – we have rough idea of how good various states are, and use this knowledge to guide our search

Page 5: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Types of heuristic search

Best FirstA* is a special caseBFS is a special case

ID A*ID is a special case

Hill climbingSimulated Annealing

Page 6: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

A* Example: 8-Puzzle

0+4

1+5

1+5

1+3

3+3

3+4

3+4

3+2 4+1

5+2

5+0

2+3

2+4

2+3

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 7: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

ID A*: 8-Puzzle Example

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

Page 8: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=4

6

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 9: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=4

6

5

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 10: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=4

6

5

5

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 11: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=4

6

5

56

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 12: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

6

Cutoff=5

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 13: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=5

6

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 14: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=5

6

5

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 15: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=5

6

5

7

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 16: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=5

6

5

7

5

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 17: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=5

6

5

7

5 5

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 18: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

4

6

Cutoff=5

6

5

7

5 5

ID A*: 8-Puzzle Examplef(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 19: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Hill climbing example 2 8 31 6 47 5

2 8 31 47 6 5

2 31 8 47 6 5

1 38 4

7 6 5

2

31 8 47 6 5

2

1 38 47 6 5

2start

goal

-5

h = -3

h = -3

h = -2

h = -1

h = 0

h = -4

-5

-4

-4

-3

-2

f(n) = -(number of tiles out of place)

Page 20: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Best-first search

Idea: use an evaluation function f(n) for each node nExpand unexpanded node n with min f(n)Implementation: FRINGE is queue sorted by decreasing order of desirability

Greedy searchA* search

Page 21: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Greedy Search

h(n) – a ‘heuristic’ function estimating the distance to the goal

Greedy Best First: expand argmin_n h(n)thus, f(v) = h(v)

Page 22: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Informed Search

Add domain-specific information to select the best path along which to continue searchingh(n) = estimated cost (or distance) of minimal cost path from n to a goal state. The heuristic function is an estimate, based on domain-specific information that is computable from the current state description, of how close we are to a goal

Page 23: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Robot Navigation

Page 24: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Robot Navigation

0 211

58 7

7

3

4

7

6

7

6 3 2

8

6

45

23 3

36 5 24 43 5

54 6

5

6

4

5

f(N) = h(N), with h(N) = Manhattan distance to the goal

Page 25: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Robot Navigation

0 211

58 7

7

3

4

7

6

7

6 3 2

8

6

45

23 3

36 5 24 43 5

54 6

5

6

4

5

f(N) = h(N), with h(N) = Manhattan distance to the goal

7

0What happened???

Page 26: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Greedy Search

f(N) = h(N) � greedy best-firstIs it complete?

If we eliminate endless loops, yesIs it optimal?

Page 27: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

More informed search

Our goal is not to minimize the distance from the current head of our path to the goal, we want to minimize the overall length of the path to the goal!Let g(N) be the cost of the bestpath found so far between the initial node and Nf(N) = g(N) + h(N)

Page 28: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Robot Navigation

f(N) = g(N)+h(N), with h(N) = Manhattan distance to goal

0 211

58 7

7

3

4

7

6

7

6 3 2

8

6

45

23 3

36 5 24 43 5

54 6

5

6

4

57+0

6+1

6+1

8+1

7+0

7+2

6+1

7+2

6+1

8+1

7+2

8+3

7+2

6+3

6+3

5+4

5+4

4+5

4+5

3+6

3+6

2+7

8+3

7+4

7+4

6+5

5+6

6+3

5+6

2+7

3+8

4+7

5+6

4+7

3+8

4+7

3+8

3+8

2+9

2+9

3+10

2+9

3+8

2+9

1+10

1+10

0+11

Page 29: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Can we Prove Anything?

If the state space is finite and we avoid repeated states, the search is complete, but in general is not optimalProof: ?If the state space is finite and we do not avoid repeated states, the search is in general not complete

Page 30: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Admissible heuristic

Let h*(N) be the true cost of the optimal path from N to a goal nodeHeuristic h(N) is admissible if: 0 � h(N) � h*(N)

An admissible heuristic is always optimistic

Page 31: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

A* Search

Evaluation function:f(N) = g(N) + h(N)where:

g(N) is the cost of the best path found so far to Nh(N) is an admissible heuristic

Then, best-first search with this evaluation function is called A* search

Important AI algorithm developed by Fikes and Nilsson in early 70s. Originally used in Shakey robot.

Page 32: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Completeness & Optimality of A*

Claim 1: If there is a path from the initial to a goal node, A* (with no removal of repeated states) terminates by finding the best path, hence is:

completeoptimal

requirements:0 < � � c(N,N’) - c(N,N’) – cost of going from N to N’

Page 33: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Completeness of A*

Theorem: If there is a finite path from the initial state to a goal node, A* will find it.

Page 34: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Proof of Completeness

Intuition (not math. Proof):

Let g be the cost of a best path to a goal nodeNo path in search tree can get longer than g/�, before the goal node is expanded

Page 35: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Optimality of A*

Theorem: If h(n) is admissable, then A* is optimal (finds an optimal path).

Page 36: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Proof of Optimality

G1

N

G2

f(G1) = g(G1)

f(N) = g(N) + h(N) � g(N) + h*(N)

f(G1) � g(N) + h(N) � g(N) + h*(N)

Cost of best path to a goal thru N

Page 37: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Example of Evaluation Function

f(N) = (sum of distances of each tile to its goal)+ 3 x (sum of score functions for each tile)

where score function for a non-central tile is 2 if it is not followed by the correct tile in clockwise order and 0 otherwise

1 2 34 5 67 8

123

45

67

8

N goal

f(N) = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 13x(2 + 2 + 2 + 2 + 2 + 0 + 2)= 49

Page 38: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Heuristic Function

Function h(N) that estimates the cost of the cheapest path from node N to goal node.Example: 8-puzzle

1 2 34 5 67 8

123

45

67

8

N goal

h(N) = number of misplaced tiles= 6

Page 39: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Heuristic Function

Function h(N) that estimate the cost of the cheapest path from node N to goal node.Example: 8-puzzle

1 2 34 5 67 8

123

45

67

8

N goal

h(N) = sum of the distances of every tile to its goal position= 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1= 13

Page 40: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

5

5

3

3

4

3 4

4

2 1

2

0

3

4

3

f(N) = h(N) = number of misplaced tiles

Page 41: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

0+4

1+5

1+5

1+3

3+3

3+4

3+4

3+2 4+1

5+2

5+0

2+3

2+4

2+3

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 42: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

5

6

6

4

4

2 1

2

0

5

5

3

f(N) = h(N) = � distances of tiles to goal

Page 43: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

1 2 3

4 5 6

7 8

12

3

4

5

67

8

N goalh1(N) = number of misplaced tiles = 6 is

admissibleh2(N) = sum of distances of each tile to goal = 13is admissibleh3(N) = (sum of distances of each tile to goal)+ 3 x (sum of score functions for each tile) = 49is not admissible

Page 44: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

0+4

1+5

1+5

1+3

3+3

3+4

3+4

3+2 4+1

5+2

5+0

2+3

2+4

2+3

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Page 45: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Robot navigation

Cost of one horizontal/vertical step = 1Cost of one diagonal step = �2

f(N) = g(N) + h(N), with h(N) = straight-line distance from N to goal

Page 46: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

About Repeated States

N N1S S

1f(N)=g(N)+h(N)

f(N1)=g(N1)+h(N1)

g(N1) < g(N)h(N) < h(N1)f(N) < f(N1)

N2f(N2)=g(N2)+h(N)

g(N2) < g(N)

Page 47: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Consistent Heuristic

The admissible heuristic h is consistent (or satisfies the monotone restriction) if for every node N and every successor N’ of N:

h(N) � c(N,N’) + h(N’)

(triangle inequality)

N

N’

h(N)

h(N’)

c(N,N’)

Page 48: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

1 2 3

4 5 6

7 8

12

3

4

5

67

8

N goal

h1(N) = number of misplaced tilesh2(N) = sum of distances of each tile to goal

are both consistent

Page 49: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Robot navigation

Cost of one horizontal/vertical step = 1Cost of one diagonal step = �2

h(N) = straight-line distance to the goal is consistent

Page 50: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Claims

If h is consistent, then the function f alongany path is non-decreasing:

f(N) = g(N) + h(N)f(N’) = g(N) +c(N,N’) + h(N’)

N

N’

h(N)

h(N’)

c(N,N’)

Page 51: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Claims

If h is consistent, then the function f alongany path is non-decreasing:

f(N) = g(N) + h(N)f(N’) = g(N) +c(N,N’) + h(N’)h(N) � c(N,N’) + h(N’)f(N) � f(N’)

N

N’

h(N)

h(N’)

c(N,N’)

Page 52: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Claims

If h is consistent, then the function f alongany path is non-decreasing:

f(N) = g(N) + h(N)f(N’) = g(N) +c(N,N’) + h(N’)h(N) � c(N,N’) + h(N’)f(N) � f(N’) If h is consistent, then whenever A* expands a node it has already found an optimal path to the state associated with this node

N

N’

h(N)

h(N’)

c(N,N’)

Page 53: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Avoiding Repeated States in A*

If the heuristic h is consistent, then:Let CLOSED be the list of states associated with expanded nodesWhen a new node N is generated:

If its state is in CLOSED, then discard NIf it has the same state as another node in the fringe, then discard the node with the largest f

Page 54: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Complexity of Consistent A*

Let s be the size of the state space Let r be the maximal number of states that can be attained in one step from any stateAssume that the time needed to test if a state is in CLOSED is O(1)The time complexity of A* is O(s r log s)

Page 55: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Heuristic Accuracy

h(N) = 0 for all nodes is admissible and consistent. Hence, breadth-first is a special case of A* !!!Let h1 and h2 be two admissible and consistent heuristics such that for all nodes N: h1(N) � h2(N). Then, every node expanded by A* using h2 is also expanded by A* using h1.h2 is more informed than h1

Page 56: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Iterative Deepening A* (IDA*)

Use f(N) = g(N) + h(N) with admissible and consistent hEach iteration is depth-first with cutoff on the value of f of expanded nodes

Page 57: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

Page 58: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

6

Page 59: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

6

5

Page 60: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

6

5

5

Page 61: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

4

8-Puzzle

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=4

6

5

56

Page 62: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

Page 63: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

Page 64: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

Page 65: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

7

Page 66: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

7

5

Page 67: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

7

5 5

Page 68: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

8-Puzzle

4

4

6

f(N) = g(N) + h(N) with h(N) = number of misplaced tiles

Cutoff=5

6

5

7

5 5

Page 69: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

About Heuristics

Heuristics are intended to orient the search along promising pathsThe time spent computing heuristics must be recovered by a better searchAfter all, a heuristic function could consist of solving the problem; then it would perfectly guide the searchDeciding which node to expand is sometimes called meta-reasoningHeuristics may not always look like numbers and may involve large amount of knowledge

Page 70: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

What’s the Issue?

Search is an iterative local procedureGood heuristics should provide some global look-ahead (at low computational cost)

Page 71: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Another approach…

for optimization problemsrather than constructing an optimal solution from scratch, start with a suboptimal solution and iteratively improve it

Local Search AlgorithmsHill-climbing or Gradient descentPotential FieldsSimulated AnnealingGenetic Algorithms, others…

Page 72: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Hill-climbing searchIf there exists a successor s for the current state n such that

h(s) < h(n)h(s) <= h(t) for all the successors t of n,

then move from n to s. Otherwise, halt at n. Looks one step ahead to determine if any successor is better than the current state; if there is, move to the best successor. Similar to Greedy search in that it uses h, but does not allow backtracking or jumping to an alternative path since it doesn’t “remember” where it has been.Not complete since the search will terminate at "local minima," "plateaus," and "ridges."

Page 73: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Hill climbing on a surface of states

Height Defined by Evaluation Function

Page 74: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Hill climbing

Steepest descent (~ greedy best-first with no search) � may get stuck into local minimum

Page 75: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Robot Navigation

f(N) = h(N) = straight distance to the goal

Local-minimum problem

Page 77: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Drawbacks of hill climbing

Problems:Local Maxima: peaks that aren’t the highest point in the spacePlateaus: the space has a broad flat region that gives the search algorithm no direction (random walk)Ridges: flat like a plateau, but with dropoffs to the sides; steps to the North, East, South and West may go down, but a step to the NW may go up.

Remedy: Introduce randomness

Random restart.

Some problem spaces are great for hill climbing and others are terrible.

Page 78: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

What’s the Issue?

Search is an iterative local procedureGood heuristics should provide some global look-ahead (at low computational cost)

Page 79: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Hill climbing example 2 8 31 6 47 5

2 8 31 47 6 5

2 31 8 47 6 5

1 38 4

7 6 5

2

31 8 47 6 5

2

1 38 47 6 5

2start

goal

-5

h = -3

h = -3

h = -2

h = -1

h = 0

h = -4

-5

-4

-4

-3

-2

f(n) = -(number of tiles out of place)

Page 80: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Example of a local maximum

1 2 57 4

8 6 3

1 2 57 4

8 6 3

1 2 57 4

8 6 3

1 2 57 4

8 6 3

1 2 57 4

8 6 3

-3

-4

-4

-4

0

start

goal

Page 81: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Potential FieldsIdea: modify the heuristic functionGoal is gravity well, drawing the robot toward itObstacles have repelling fields, pushing the robot away from themThis causes robot to “slide” around obstaclesPotential field defined as sum of attractor field which get higher as you get closer to the goal and the indivual obstacle repelling field (often fixed radius that increases exponentially closer to the obstacle)

Page 82: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Does it always work?

No.But, it often works very well in practiceAdvantage #1: can search a very large search space without maintaining fringe of possiblitiesScales well to high dimensions, where no other methods workExample: motion planningAdvantage #2: local method. Can be done online

Page 83: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Example: RoboSoccerAll robots have same field: attracted to the ball

Repulsive potential to other playersKicking field: attractive potential to the ball and local repulsive potential if clase to the ball, but not facing the direction of the opponent’s goal. Result is tangent, player goes around the ball.Single team: kicking field + repulsive field to avoid hitting other players + player position fields (paraboilic if outside your area of the field, 0 inside). Player nearest to the ball has the largest attractive coefficient, avoids all players crowding the ball.Two teams: identical potential fields.

Page 84: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Simulated annealingSimulated annealing (SA) exploits an analogy between the way in which a metal cools and freezes into a minimum-energy crystalline structure (the annealing process) and the search for a minimum [or maximum] in a more general system. SA can avoid becoming trapped at local minima.SA uses a random search that accepts changes that increase objective function f, as well as some that decrease it.SA uses a control parameter T, which by analogy with the original application is known as the system “temperature.”T starts out high and gradually decreases toward 0.

Page 85: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Simulated annealing (cont.)

A “bad” move from A to B is accepted with a probability

(f(B)-f(A)/T)

eThe higher the temperature, the more likely it is that a bad move can be made.As T tends to zero, this probability tends to zero, and SA becomes more like hill climbingIf T is lowered slowly enough, SA is complete and admissible.

Page 86: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

The simulated annealing algorithm

Page 87: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Summary: Local Search Algorithms

Steepest descent (~ greedy best-first with no search) � may get stuck into local minimumBetter Heuristics: Potential FieldsSimulated annealingGenetic algorithms

Page 88: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

When to Use Search Techniques?

The search space is small, andThere is no other available techniques, orIt is not worth the effort to develop a more efficient technique

The search space is large, andThere is no other available techniques, andThere exist “good” heuristics

Page 89: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Summary

Heuristic functionBest-first searchAdmissible heuristic and A*A* is complete and optimalConsistent heuristic and repeated statesHeuristic accuracyIDA*

Page 90: CS 440 / ECE 448 Introduction to Artificial Intelligence ...reason.cs.uiuc.edu/cs440/slides/cs440-lec4-heuristic-search.pdf · Introduction to Artificial Intelligence Spring 2010

Modified Search Algorithm

1. INSERT(initial-node,FRINGE)2. Repeat:

If FRINGE is empty then return failuren � REMOVE(FRINGE)s � STATE(n)If GOAL?(s) then return path or goal stateFor every state s’ in SUCCESSORS(s)

Create a node n’INSERT(n’,FRINGE)