arti cial intelligence · introduction heuristic functions syst.: algorithms syst.: performance...

60
Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References Artificial Intelligence 4. Classical Search, Part II: Informed Search How to Not Play Stupid When Solving a Problem Jana Koehler ´ Alvaro Torralba Summer Term 2019 Thanks to Prof. Hoffmann for slide sources Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 1/61

Upload: others

Post on 17-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Artificial Intelligence4. Classical Search, Part II: Informed Search

How to Not Play Stupid When Solving a Problem

Jana Koehler Alvaro Torralba

Summer Term 2019

Thanks to Prof. Hoffmann for slide sources

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 1/61

Page 2: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Agenda

1 Introduction

2 Heuristic Functions

3 Systematic Search: Algorithms

4 Systematic Search: Performance

5 Local Search

6 Conclusion

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 2/61

Page 3: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

(Not) Playing Stupid

→ Problem: Find a route to Moscow.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 4/61

Page 4: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Informed Search: Basic Idea

Recall: Search strategy=how to choose the next node to expand?

Blind Search: Rigid procedure using the same expansion order nomatter which problem it is applied to.

→ Blind search has 0 knowledge of the problem it is solving.

→ It can’t “focus on roads that go the right direction”, because ithas no idea what “the right direction” is.

Informed Search: Knowledge of the “goodness” of expanding a states is given in the form of a heuristic function h(s), which estimatesthe cost of an optimal (cheapest) path from s to the goal.

→ ”h(s) larger than where I came from =⇒ seems s is not theright direction.”

→ Informed search is a way of giving the computer knowledge about theproblem it is solving, thereby stopping it from doing stupid things.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 5/61

Page 5: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Informed Search: Basic Idea, ctd.

goalinit

cost es

timate

hcost est

imate h

cost estimate h

cost estimate h

→ Heuristic function h estimates the cost of an optimal path from astate s to the goal; search prefers to expand states s with small h(s).

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 6/61

Page 6: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Some Applications

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 7/61

Page 7: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Reminder: Our Agenda for This Topic

→ Our treatment of the topic “Classical Search” consists of Chapters 4and 5.

Chapter 4: Basic definitions and concepts; blind search.

→ Sets up the framework. Blind search is ideal to get our feet wet.It is not wide-spread in practice, but it is among the state of the artin certain applications (e.g., software model checking).

This Chapter: Heuristic functions and informed search.

→ Classical search algorithms exploiting the problem-specificknowledge encoded in a heuristic function. Typically much moreefficient in practice.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 8/61

Page 8: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Our Agenda for This Chapter

Heuristic Functions: How are heuristic functions h defined? What arerelevant properties of such functions? How can we obtain them in practice?

→ Which “problem knowledge” do we wish to give the computer?

Systematic Search: Algorithms: How to use a heuristic function h whilestill guaranteeing completeness/optimality of the search.

→ How to exploit the knowledge in a systematic way?

Systematic Search: Performance: Empirical and theoreticalobservations.

→ What can we say about the performance of heuristic search? Is itactually better than blind search?

Local Search: Overview of methods foresaking completeness/optimality,taking decisions based only on the local surroundings.

→ How to exploit the knowledge in a greedy way?

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 9/61

Page 9: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Functions

Definition (Heuristic Function, h∗). Let Π be a problem with statesS. A heuristic function, short heuristic, for Π is a functionh : S 7→ R+

0 ∪ {∞} so that, for every goal state s, we have h(s) = 0.

The perfect heuristic h∗ is the function assigning every s ∈ S the cost ofa cheapest path from s to a goal state, or ∞ if no such path exists.

Notes:

We also refer to h∗(s) as the goal distance of s.

h(s) = 0 on goal states: If your estimator returns “I think it’s still along way” on a goal state, then its “intelligence” is, um . . .

Return value ∞: To indicate dead ends, from which the goal can’tbe reached anymore.

The value of h depends only on the state s, not on the search node(i.e., the path we took to reach s). I’ll sometimes abuse notationwriting “h(n)” instead of “h(n.State)”.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 11/61

Page 10: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Why “Heuristic”?

What’s the meaning of “heuristic”?

Heuristik: Ancient Greek ευρισκειν (= “I find”); aka: ευρηκα!

Popularized in modern science by George Polya: “How to Solve It”(published 1945).

Same word often used for: “rule of thumb”, “imprecise solutionmethod”.

In classical search (and many other problems studied in AI), it’s themathematical term just explained.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 12/61

Page 11: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Functions: The Eternal Trade-Off

Distance “estimate”? (h is an arbitrary function in principle!)

We want h to be accurate (aka: informative), i.e., “close to” theactual goal distance.

We also want it to be fast, i.e., a small overhead for computing h.

These two wishes are in contradiction!

→ Extreme cases?

→ We need to trade off the accuracy of h against the overhead forcomputing h(s) on every search state s.

So, how to? → Given a problem Π, a heuristic function h for Π can beobtained as goal distance within a simplified (relaxed) problem Π′.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 13/61

Page 12: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Functions from Relaxed Problems: Example 1

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 14/61

Page 13: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Functions from Relaxed Problems: Example 2

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 15/61

Page 14: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Functions from Relaxed Problems: Example 3

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 16/61

Page 15: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Functions from Relaxed Problems: Example 4

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 17/61

Page 16: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Function Pitfalls: Example Path Planning

h∗:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1

2

3

4

5

I

G

9

89 7

8

6 5

4 3 2 1

01

1011

11

12

12

12

12

13

13

13

13

14 14

14

14

15 15

15

15

15

16

16

16

16

1617

17 17

17

18

18

18

19

20

21

2122

22

22

23

23

2324

24

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 18/61

Page 17: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Function Pitfalls: Example Path Planning

Manhattan Distance, “accurate h”:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1

2

3

4

5

I

G

14 13 12

131415

16

17

18

15 14

15

16 15

14 13

14 13 12

11 10

1012

11

10

10

9

9

9 8

9

8 7 6 5 4

345678

7

67 5

6

4 3

4 3 2 1

01

910

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 18/61

Page 18: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Heuristic Function Pitfalls: Example Path Planning

Manhattan Distance, “inaccurate h”:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1

2

3

4

5

I

G

14 13 12

131415

16

17

18

15 14

15

16 15

14 13

14 13 12

10

1012

11

10

10

9

9

9 8

9

8 7 6 5 4

345678

7

67 5

6

4 3

4 3 2 1

01

91017

16

13

12

12

11

11

11

8

8

7 6 5

5

4 3

2

2

11

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 18/61

Page 19: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Questionnaire

n blocks, 1 hand.

A single action either takes a block with the hand or puts ablock we’re holding onto some other block/the table.

The goal is a set of statements “on(x,y)”.

Question!

Consider h := number of goal statements that are not currentlytrue. Is the error relative to h∗ bounded by a constant?

(A): Yes. (B): No.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 19/61

Page 20: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Properties of Heuristic Functions

Definition (Admissibility, Consistency). Let Π be a problem withstate space Θ and states S, and let h be a heuristic function for Π. Wesay that h is admissible if, for all s ∈ S, we have h(s) ≤ h∗(s). We saythat h is consistent if, for all transitions s

a−→ s′ in Θ, we haveh(s)− h(s′) ≤ c(a).

In other words . . .

Admissibility: lower bound on goal distance.

Consistency: when applying an action a, the heuristic value cannotdecrease by more than the cost of a.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 20/61

Page 21: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Properties of Heuristic Functions, ctd.

Proposition (Consistency =⇒ Admissibility). Let Π be a problem,and let h be a heuristic function for Π. If h is consistent, then h isadmissible.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 21/61

Page 22: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Properties of Heuristic Functions: Examples

Admissibility and consistency:

Is straight line distance admissible/consistent? Yes. Consistency: If youdrive 100km, then the straight line distance to Moscow can’t decrease bymore than 100km.

Is goal distance of the “reduced puzzle” (slide 15) admissible/consistent?

Can somebody come up with an admissible but inconsistent heuristic?

→ In practice, admissible heuristics are typically consistent.

Inadmissible heuristics:

Inadmissible heuristics typically arise as approximations of admissibleheuristics that are too costly to compute. (We’ll meet some examples ofthis in Chapter 15.)

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 22/61

Page 23: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Questionnaire

3 missionaries, 3 cannibals.

Boat that holds ≤ 2.

Never leave k missionaries alone with > k cannibals.

Question!

Is h := number of persons at right bank consistent/admissible?

(A): Only consistent.

(C): None.

(B): Only admissible.

(D): Both.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 23/61

Page 24: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Before We Begin

Systematic search vs. local search:

Systematic search strategies: No limit on the number of searchnodes kept in memory at any point in time.

→ Guarantee to consider all options at some point, thus complete.

Local search strategies: Keep only one (or a few) search nodes at atime.

→ No systematic exploration of all options, thus incomplete.

Tree search vs. graph search:

For the systematic search strategies, we consider graph searchalgorithms exclusively, i.e., we use duplicate pruning.

There also are tree search versions of these algorithms. These areeasier to understand, but aren’t used in practice. (Maintaining acomplete open list, the search is memory-intensive anyway.)

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 25/61

Page 25: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Greedy Best-First Search

function Greedy Best-First Search(problem) returns a solution, or failurenode ← a node n with n.state=problem.InitialStatefrontier ← a priority queue ordered by ascending h, only element nexplored ← empty set of statesloop do

if Empty?(frontier) then return failuren ← Pop(frontier)if problem.GoalTest(n.State) then return Solution(n)explored ← explored ∪n.Statefor each action a in problem.Actions(n.State) do

n′ ← ChildNode(problem,n,a)if n′.State 6∈explored ∪ States(frontier) then Insert(n′, h(n′), frontier)

Frontier ordered by ascending h.

Duplicates checked at successor generation, against both thefrontier and the explored set.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 26/61

Page 26: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Greedy Best-First Search: Route to Bucharest

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 27/61

Page 27: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Greedy Best-First Search: Guarantees

Completeness: Yes, thanks to duplicate elimination and ourassumption that the state space is finite.

Optimality?

Can we do better than this?

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 28/61

Page 28: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

A∗

function A∗(problem) returns a solution, or failurenode ← a node n with n.State=problem.InitialStatefrontier ← a priority queue ordered by ascending g + h, only element nexplored ← empty set of statesloop do

if Empty?(frontier) then return failuren ← Pop(frontier)if problem.GoalTest(n.State) then return Solution(n)explored ← explored∪n.Statefor each action a in problem.Actions(n.State) do

n′ ← ChildNode(problem,n,a)if n′.State 6∈explored ∪ States(frontier) then

Insert(n′, g(n′) + h(n′), frontier)else if ex. n′′ ∈frontier s.t. n′′.State= n′.State and g(n′) < g(n′′) then

replace n′′ in frontier with n′

Frontier ordered by ascending g + h.

Duplicates handled exactly as in uniform-cost search.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 29/61

Page 29: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

A∗: Route to Bucharest

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 30/61

Page 30: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Questionnaire

Question!

If we set h(s) := 0 for all states s, what does greedy best-firstsearch become?(A): Breadth-first search

(C): Uniform-cost search

(B): Depth-first search

(D): Depth-limited search

Question!

If we set h(s) := 0 for all states s, what does A∗ become?

(A): Breadth-first search

(C): Uniform-cost search

(B): Depth-first search

(D): Depth-limited search

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 31/61

Page 31: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Optimality of A∗: Proof, Step 1

Idea: The proof is via a correspondence to uniform-cost search.

→ Step 1: Capture the heuristic function in terms of action costs.

Definition. Let Π be a problem with state space Θ = (S,A, c, T, I, SG),and let h be a consistent heuristic function for Π. We define theh-weighted state space as Θh = (S,Ah, ch, T h, I, SG) where:

Ah := {a[s, s′] | a ∈ A, s ∈ S, s′ ∈ S, (s, a, s′) ∈ T}.ch : Ah 7→ R+

0 is defined by ch(a[s, s′]) := c(a)− [h(s)− h(s′)].

T h = {(s, a[s, s′], s′) | (s, a, s′) ∈ T}.

→ Subtract, from each action cost, the “gain in heuristic value”.

Lemma. Θh is well-defined, i.e., c(a)− [h(s)− h(s′)] ≥ 0.

Proof.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 32/61

Page 32: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Optimality of A∗: Proof – Illustration

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 33/61

Page 33: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Optimality of A∗: Proof, Step 2

→ Step 2: Identify the correspondence.

Lemma (A). Θ and Θh have the same optimal solutions.

Lemma (B). The search space of A∗ on Θ is isomorphic to that ofuniform-cost search on Θh.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 34/61

Page 34: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Optimality of A∗: Proof – Illustration

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 35/61

Page 35: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Optimality of A∗: Proof, Step 3

→ Step 3: Put the pieces together.

Theorem (Optimality of A∗). Let Π be a problem, and let h be aheuristic function for Π. If h is consistent, then the solution returned byA∗ (if any) is optimal.

Proof. Denote by Θ the state space of Π. Let ~s(A∗,Θ) be the solutionreturned by A∗ run on Θ. Denote by ~S(UCS,Θh) the set of solutionsthat could in principle be returned by uniform-cost search run on Θh.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 36/61

Page 36: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Optimality of A∗: Different Variants

Our variant of A∗ does duplicate elimination but not re-opening.

Re-opening: check, when generating a node n containing state s that isalready in the explored set, whether (*) the new path to s is cheaper. Ifso, remove s from the explored set and insert n into the frontier.

With a consistent heuristic, (*) can’t happen so we don’t need re-openingfor optimality.

Given admissible but inconsistent h, if we either don’t use duplicateelimination at all, or use duplicate elimination with re-opening, then A∗ isoptimal as well. Hence the well-known statement “A∗ is optimal if h isadmissible”.

→ But for our variant (as per slide 29), being admissible is NOT enoughfor optimality! Frequent implementation bug!

→ Recall: In practice, admissible heuristics are typically consistent. That’s whyI chose to present this variant.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 37/61

Page 37: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

And now, let’s relax a bit . . .

http://movingai.com/flrta.html

More videos: http://movingai.com/

→ Illustrations of various issues in heuristic search/A∗ that go deeperthan our introductory material here.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 38/61

Page 38: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Provable Performance Bounds: Extreme Case

Let’s consider an extreme case: What happens if h = h∗?

Greedy Best-First Search:

A∗:

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 40/61

Page 39: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Provable Performance Bounds: More Interesting Cases?

“Almost perfect” heuristics:

|h∗(n)− h(n)| ≤ c for a constant c

Basically the only thing that lead to some interesting results.

If the state space is a tree (only one path to every state), and thereis only one goal state: linear in the length of the solution [Gaschnig(1977)].

But if these additional restrictions do not hold: exponential even forvery simple problems and for c = 1 [Helmert and Roger (2008)]!

→ Systematically analyzing the practical behavior of heuristic searchremains one of the biggest research challenges.

→ There is little hope to prove practical sub-exponential-search bounds.(But there are some interesting insights one can gain → FAI.)

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 41/61

Page 40: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Empirical Performance: A∗ in the 8-Puzzle

Without Duplicate Elimination; d = length of solution:

Number of search nodes generatedIterative A∗ with

d Deepening Search misplaced tiles h Manhattan distance h

2 10 6 64 112 13 126 680 20 188 6384 39 25

10 47127 93 3912 3644035 227 7314 - 539 11316 - 1301 21118 - 3056 36320 - 7276 67622 - 18094 121924 - 39135 1641

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 42/61

Page 41: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Empirical Performance: A∗ in Path Planning

Live Demo vs. Breadth-First Search:

http://qiao.github.io/PathFinding.js/visual/

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 43/61

Page 42: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Greedy Best-First vs. A∗: Illustration Path Planning

A∗(g + h), “accurate h”:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1

2

3

4

5

I

G

18

18

18

18

18 18 18

18 18

18 18

20 20 20

20

20

20 20

20 20

22 22 22 22 22

22

22 22 22

22 22 22 22 22 22 22 22

22

22

22

22 22 22

24

24

24 24 24

2424

24 24 24 24 24 24 24

→ In A∗ with a consistent heuristic, g + h always increasesmonotonically (h cannot decrease by more than g increases).

→ We need more search, in the “right upper half”. This is typical:Greedy best-first search tends to be faster than A∗.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 44/61

Page 43: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Greedy Best-First vs. A∗: Illustration Path Planning

Greedy best-first search, “inaccurate h”:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1

2

3

4

5

I

G

14 13 12

131415

16

17

18

15 14

15

16 15

14 13

14 13 12

10

1012

11

10

10

9

9

9 8

9

8 7 6 5 4

345678

7

67 5

6

4 3

4 3 2 1

01

91017

16

13

12

12

11

11

11

8

8

7 6 5

5

4 3

2

2

11

→ Search will be mis-guided into the “dead-end street”.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 44/61

Page 44: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Greedy Best-First vs. A∗: Illustration Path Planning

A∗(g + h), “inaccurate h”:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1

2

3

4

5

I

G

18 18 18

181818

18

18

18

15 20

22

24 24

14 13

24 24 24

10

2222

20

18

10

9

9

9 45678

5

6 4 2

1

2417

16

13

12

12

24

22

18

8

5 3

11

22

22 22 22

24

26 26 26

26

26 26 26

28

30

24

24

24

24

242424242424

→ We will search less of the “dead-end street”. For very “badheuristics”, g + h gives better search guidance than h, and A∗ is faster.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 44/61

Page 45: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Greedy Best-First vs. A∗: Illustration Path Planning

A∗(g + h) using h∗:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1

2

3

4

5

I

G

15

14 13 10

10

9

9

9 45678

5

6 4 2

1

17

16

13

12

12

8

5 3

11

24

24

24

24

24242424242424242424242424

24

24

242424

24

24

24

26 26 26 28 30

32

34 36 38

40

42 44 46

48

50 52 54

56

58 60 62

64

66

→ With h = h∗, g + h remains constant on optimal paths.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 44/61

Page 46: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Questionnaire

Question!

1. Is A∗ always at least as fast as uniform-cost search? 2. Does italways expand at most as many states?

(A): No and no.

(C): No and Yes.

(B): Yes and no.

(D): Yes and yes.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 45/61

Page 47: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Local Search

Do you “think through all possible options” beforechoosing your path to the Mensa?

→ Sometimes, “going where your nose leads you” works quite well.

What is the computer’s “nose”?

→ Local search takes decisions based on the h values of immediateneighbor states.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 47/61

Page 48: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Hill Climbing

function Hill-Climbing(problem)n ← a node n with n.state=problem.InitialStateloop do

n′ ← among child nodes n′ of n with minimal h(n′),randomly pick one

if h(n′) ≥ h(n) then return the path to nn ← n′

→ Hill-Climbing keeps choosing actions leading to a direct successorstate with best heuristic value. It stops when no more immediateimprovements can be made.

Alternative name (more fitting, here): Gradient-Descent.

Often used in optimization problems where all “states” are feasiblesolutions, and we can choose the search neighborhood (“childnodes”) freely. (Return just n.State, rather than the path to n)

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 48/61

Page 49: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Local Search: Guarantees and Complexity

Guarantees:

Completeness: No. Search ends when no more immediateimprovements can be made (= local minimum, up next). This is notguaranteed to be a solution.

Optimality: No, for the same reason.

Complexity:

Time: We stop once the value doesn’t strictly increase, so the statespace size is a bound.→ Note: This bound is (a) huge, and (b) applies to a single run ofHill-Climbing, which typically does not find a solution.

Memory: Basically no consumption: O(b) states at any moment intime.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 49/61

Page 50: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Hill Climbing: Example 8-Queens Problem

14

18

17

15

14

18

14

14

14

14

14

12

16

12

13

16

17

14

18

13

14

17

15

18

15

13

15

13

12

15

15

13

15

12

13

14

14

14

16

12

14

12

12

15

16

13

14

12

14

18

16

16

16

14

16

14

Problem: Place the queens so that theydon’t attack each other.

Heuristic: Number of pairs attackingeach other.

Neighborhood: Move any queen withinits column.

→ Starting from random initialization, solves only 14% of cases.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 50/61

Page 51: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

A Local Minimum in the 8-Queens Problem

→ Current h value is?

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 51/61

Page 52: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Local Search: Difficulties

Difficulties:

Local minima: All neighbors look worse (have a worse h value) than thecurrent state (e.g.: previous slide).

→ If we stop, the solution may be sub-optimal (or not even feasible). If wedon’t stop, where to go next?

Plateaus: All neighbors have the same h value as the current state.

→ Moves will be chosen completely at random.

Strategies addressing these:

Re-start when reaching a local minimum, or when we have spent a certainamount of time without “making progress”.

Do random walks in the hope that these will lead out of the localminimum/plateau.

→ Configuring these strategies requires lots of algorithm parameters. Selectinggood values is a big issue in practice. (Cross your fingers . . . )

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 52/61

Page 53: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Hill Climbing With Sideways Moves: Example 8-Queens

14

18

17

15

14

18

14

14

14

14

14

12

16

12

13

16

17

14

18

13

14

17

15

18

15

13

15

13

12

15

15

13

15

12

13

14

14

14

16

12

14

12

12

15

16

13

14

12

14

18

16

16

16

14

16

14 Heuristic: Number of pairs attackingeach other.

Neighborhood: Move any queen withinits column.

Sideways Moves: In contrast toslide 50, allow up to 100 consecutivemoves in which the h value does not getbetter.

→ Starting from random initialization, solves 94% of cases!

→ Successful local search procedures often combine randomness(exploration) with following the heuristic (exploitation).

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 53/61

Page 54: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

One (Out of Many) Other Local Search Strategies:Simulated Annealing

Idea: Taking inspiration from processes in physics (objects coolingdown), inject “noise” systematically: first a lot, then gradually less.

4 BEYOND CLASSICALSEARCH

function HILL -CLIMBING(problem) returns a state that is a local maximum

current←MAKE-NODE(problem .INITIAL -STATE)loop do

neighbor←a highest-valued successor ofcurrentif neighbor.VALUE ≤ current.VALUE then return current .STATE

current←neighbor

Figure 4.2 The hill-climbing search algorithm, which is the most basiclocal search technique. Ateach step the current node is replaced by the best neighbor; in this version, that means the neighborwith the highest VALUE, but if a heuristic cost estimateh is used, we would find the neighbor with thelowesth.

function SIMULATED -ANNEALING(problem ,schedule) returns a solution stateinputs: problem , a problem

schedule , a mapping from time to “temperature”

current←MAKE-NODE(problem .INITIAL -STATE)for t = 1 to∞ do

T← schedule(t)if T = 0 then return currentnext←a randomly selected successor ofcurrent∆E← next .VALUE – current .VALUE

if ∆E > 0 then current←nextelse current←next only with probabilitye∆E/T

Figure 4.5 The simulated annealing algorithm, a version of stochastichill climbing where somedownhill moves are allowed. Downhill moves are accepted readily early in the annealing schedule andthen less often as time goes on. Theschedule input determines the value of the temperatureT as afunction of time.

8

→ Used since early 80s for VSLI Layout and other optimization problems.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 54/61

Page 55: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Questionnaire

Question!

Can local minima occur in route planning with h :=straight linedistance?(A): Yes. (B): No.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 55/61

Page 56: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Questionnaire, ctd.

Question!

What is the maximum size of plateaus in the 15-puzzle withh :=Manhattan distance?(A): 0

(C): 2

(B): 1

(D): ∞

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 56/61

Page 57: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Summary

Heuristic functions h map each state to an estimate of its goaldistance. This provides the search with knowledge about theproblem at hand, thus making it more focussed.

h is admissible if it lower-bounds goal distance. h is consistent ifapplying an action cannot reduce its value by more than the action’scost. Consistency implies admissibility. In practice, admissibleheuristics are typically consistent.

Greedy best-first search explores states by increasing h. It iscomplete but not optimal.

A∗ explores states by increasing g + h. It is complete. If h isconsistent, then A∗ is optimal. (If h is admissible but notconsistent, then we need to use re-opening to guarantee optimality.)

Local search takes decisions based on its direct neighborhood. It isneither complete nor optimal, and suffers from local minima andplateaus. Nevertheless, it is often successful in practice.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 58/61

Page 58: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Topics We Didn’t Cover Here

Bounded Sub-optimal Search: Giving a guarantee weaker than “optimal”on the solution, e.g., within a constant factor W of optimal.

Limited-Memory Heuristic Search: Hybrids of A∗ with depth-first search(using linear memory), algorithms allowing to make best use of a givenamount M of memory, . . .

External Memory Search: Store the open/closed list on the hard drive,group states to minimize the number of drive accesses.

Search on the GPU: How to use the GPU for part of the search work?

Real-Time Search: What if there is a fixed deadline by which we mustreturn a solution? (Often: fractions of seconds . . . )

Lifelong Search: When our problem changes, how can we re-useinformation from previous searches?

Non-Deterministic Actions: What if there are several possible outcomes?

Partial Observability: What if parts of the world state are unknown?

Reinforcement Learning Problems: What if, a priori, the solver does notknow anything about the world it is acting in?

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 59/61

Page 59: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

Reading

Chapter 3: Solving Problems by Searching, Sections 3.5 and 3.6 [Russelland Norvig (2010)].

Content: Section 3.5: A less formal account of what I cover in “SystematicSearch Strategies”. My main changes pertain to making precise howGreedy Best-First Search and A∗ handle duplcate checking: Imho, withrespect to this aspect RN is much too vague. For A∗, not getting thisright is the primary source of bugs leading to non-optimal solutions.

Section 3.6 (and parts of Section 3.5): A less formal account of what Icover in “Heuristic Functions”. Gives many complementary explanations,nice as additional background reading.

Chapter 4: Beyond Classical Search, Section 4.1 [Russell and Norvig(2010)].

Content: Similar to what I cover in “Local Search Strategies”, except itmistakenly acts as if local search could not be used to solve classical searchproblems. Discusses also Genetic Algorithms, and is nice as additionalbackground reading.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 60/61

Page 60: Arti cial Intelligence · Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search ConclusionReferences Properties of Heuristic Functions: Examples Admissibility

Introduction Heuristic Functions Syst.: Algorithms Syst.: Performance Local Search Conclusion References

References I

John Gaschnig. Exactly how good are heuristics?: Toward a realistic predictive theoryof best-first search. In Proceedings of the 5th International Joint Conference onArtificial Intelligence (IJCAI’77), pages 434–441, Cambridge, MA, August 1977.William Kaufmann.

Malte Helmert and Gabriele Roger. How good is almost perfect? In Dieter Fox andCarla Gomes, editors, Proceedings of the 23rd National Conference of the AmericanAssociation for Artificial Intelligence (AAAI’08), pages 944–949, Chicago, Illinois,USA, July 2008. AAAI Press.

Stuart Russell and Peter Norvig. Artificial Intelligence: A Modern Approach (ThirdEdition). Prentice-Hall, Englewood Cliffs, NJ, 2010.

Koehler and Torralba Artificial Intelligence Chapter 4: Classical Search, Part II 61/61