Docsity

Artificial Intelligence Programming - Heuristic Search | CS 662, Study notes of Computer Science

Toggle sidebar
bg1
Artificial Intelligence
Programming
Heuristic Search
Chris Brooks
Department of Computer Science
University of San Francisco
Overview
Heuristic Search - exploiting knowledge about the
problem
Heuristic Search Algorithms
“Best-first” search
Greedy Search
A* Search
Extensions to A*
Constructing Heuristics
Departmentof Computer Science — University of San Francisco – p.1/??
Informing Search
Previous algorithms were able to find solutions, but were
very inefficient.
Exponential number of nodes expanded.
By taking advantage of knowledge about the problem
structure, we can improve performance.
Two caveats:
We have to get knowledge about the problem from
somewhere.
This knowledge has to be correct.
Departmentof Computer Science — University of San Francisco
Best-first Search
Recall Uniform-cost search
Nodes were expanded based on their total path cost
A priority queue was used to implement this.
Path cost is an example of an evaluation function.
We’ll use the notation f(n)to refer to an evaluation
function.
An evaluation function tells us how promising a node is.
Indicates the quality of the solution that node leads to.
Departmentof Computer Science — University of San Francisco – p.3/??
Best-first Search
By ordering and expanding nodes according to their f
value, we search the “best” nodes “first”
If fwas perfect, we would expand a straight path from
the initial state to the goal state.
Arad, Sibiu, Rimnicu Vilcea, Pitesti, Bucharest
Of course, if we had a perfect f, we wouldn’t need to
solve the problem in the first place.
Instead, we’ll try to develop heuristic functions h(n)that
help us estimate f(n).
Departmentof Computer Science — University of San Francisco – p.4/??
Best-first Search
Best-first Pseudocode
enqueue(initialState)
do
node = dequeue()
if goalTest(node)
return node
else
children = successor-fn(node)
for child in children
insert-with(child, f(child))
where insert-with orders our priority queue accordingly.
Departmentof Computer Science — University of San Francisco
pf3
pf4
pf5

Partial preview of the text

Download Artificial Intelligence Programming - Heuristic Search | CS 662 and more Study notes Computer Science in PDF only on Docsity!

Artificial Intelligence

Programming^ Heuristic Search

Chris Brooks Department of Computer ScienceUniversity of San Francisco

Overview Heuristic Search - exploiting knowledge about theproblem Heuristic Search Algorithms^ “Best-first” search^ Greedy Search^ A* Search^ Extensions to A* Constructing Heuristics

Department of Computer Science — University of San Francisco – p.1/

??

Informing Search Previous algorithms were able to find solutions, but werevery inefficient.^ Exponential number of nodes expanded. By taking advantage of knowledge about the problemstructure, we can improve performance. Two caveats:^ We have to get knowledge about the problem fromsomewhere.^ This knowledge has to be correct.

Department of Computer Science — University of San Fra

Best-first Search Recall Uniform-cost search^ Nodes were expanded based on their total path cost^ A priority queue was used to implement this. Path cost is an example of an

evaluation function

We’ll use the notation

f^ (n)^

to refer to an evaluation

function. An evaluation function tells us how promising a node is. Indicates the quality of the solution that node leads to.

Department of Computer Science — University of San Francisco – p.3/

??

Best-first Search By ordering and expanding nodes according to their

f

value, we search the “best” nodes “first” If^ f^ was perfect, we would expand a straight path fromthe initial state to the goal state.^ Arad, Sibiu, Rimnicu Vilcea, Pitesti, Bucharest Of course, if we had a perfect

f^ , we wouldn’t need to

solve the problem in the first place. Instead, we’ll try to develop heuristic functions

h(n)^

that

help us estimate

f^ (n).

Department of Computer Science — University of San Francisco – p.4/

??

Best-first Search Best-first Pseudocode enqueue(initialState)donode^

=^ dequeue()if goalTest(node)return^ nodeelsechildren^

=^ successor-fn(node) for^ child

in^ childreninsert-with(child,

f(child))

where insert-with orders our priority queue accordingly.

Department of Computer Science — University of San Fra

Greedy Search Let’s start with the opposite of uniform-cost search UCS used the solution cost to date as an estimate of

f

Greedy search

uses an estimate of distance to the goal

for^ f^. Rationale: Always pick the node that looks like it will getyou closest to the solution. Let’s start with a simple estimate of

f^ for the Romania

domain.^ h(city

) =Straight-line distance between that city and

Bucharest.

Department of Computer Science — University of San Francisco – p.6/

??

Greedy Search Notice that there wasn’t anything in the problemdescription about straight-line distance or the fact thatthat would be a useful estimate. We used our knowledge about the way roads generallywork. This is sometimes called

common sense

knowledge. Department of Computer Science — University of San Francisco – p.7/

??

Greedy Search Example

MehadiaNeamtOradeaPitestiRimnicu VilceaSibiuTimisoara UrziceniVasluiZerind AradBucharestCraiovaDobretaEforieFagarasGiurgiuHirsovaIasiLugoj

366016024216117677151226244

24123438010019325332980199374

A = 336 (dequeue A) S = 253, T = 329, Z = 374 (dequeue S) F = 176, RV = 193, T =329, A = 336, Z = 374, O = 380 (dequeue F) B = 0, RV = 193, S = 253,T = 329, A = 336, Z = 374, O = 380 dequeue B - solution: A -> S -> F ->B

We found a solution quickly, but it was not optimal. What was the problem with our approach?

Department of Computer Science — University of San Fra

Issues with Greedy Search Sometimes the optimal solution to a problem involvesmoving ‘away’ from the goal. For example, to solve 8-puzzle, you often need to ‘undo’a partial solution. Greedy search has many of the same appeals andweaknesses as DFS.^ Expands a linear number of nodes^ Is not complete or optimal Its ability to cut toward a goal is appealing - can wesalvage this?

Department of Computer Science — University of San Francisco – p.9/

??

A* search A* search is a combination of uniform cost search andgreedy search. A node’s

f^ (n) =

g(n) +

h(n)

g(n)^ = current path cost h(n)^ = heuristic estimate of distance to goal. Favors nodes that have a cheap solution to date andalso look like they’ll get close to the goal. If h(n)^ satisfies certain conditions, A* is both complete(always finds a solution) and optimal (always finds thebest solution).

Department of Computer Science — University of San Francisco – p.10/

??

A* example - Romania h^ = straight-line distance MehadiaArad^366 NeamtBucharest^0 OradeaCraiova^160 PitestiDobreta^242 Rimnicu VilceaEforie^161 SibiuFagaras^176 TimisoaraGiurgiu^77^ UrziceniHirsova^151 VasluiIasi^226 ZerindLugoj^244

24123438010019325332980199374

Arad = 0 + 366 = 366 (dequeue A: g = 0)

S = 140 + 253 = 393

,^ T = 118 + 329 =

447 ,^ Z = 75 + 374 = 449 (dequeue S: g = 140)

RV = 220 + 193 = 413

,^ F = 239 +

, T = 118 + 329 = 447, Z = 374 + 75 = 449,

A =

,^ O = 291 + 380 = 671

(dequeue RV: g = 220) F = 239 + 176 = 415,

P = 317 +

, T = 118 + 329 = 447, Z = 374 + 75 = 449,

C =

,^ S = 300 + 253 = 553

, A = 280 + 336 =

616, O = 291 + 380 = 671 (dequeue F: g = 239) P = 317 + 100 = 417, T = 118 + 329= 447, Z = 374 + 75 = 449, C = 366 + 160 = 526,

B = 550

, S = 300 + 253 = 553,

S = 338 + 253 = 591

,A =

280 + 336 = 616, O = 291 + 380 = 671

Department of Computer Science — University of San Fran

Another A* example ode:^ Queue

[(C^ f^ = 22,

g^ =^ 7,

h^ =^ 15),

(B^ f^

= 28,^

g^ =^ 8,^

h^ =^ 20)] Department of Computer Science — University of San Francisco – p.18/

??

Another A* example Node:^ Queue

C^ [(D

f^ =^ 23,

g^ =^ 15,

h^ = 8),

(B^ f^ =

28,^ g

=^ 8,^

h^ =^ 20)] Department of Computer Science — University of San Francisco – p.19/

??

Another A* example Node:^ Queue

D^ [(I^

f^ =^ 26,

g^ =^ 20,

h^ =^ 6),

(F^ f^

=^ 27,^ g

=^ 21,

h =^ 6),

(B^ f =

28,^ g

= 8,^

h^ = 20),

(E^ f =

28,^ g^

=^ 20,^

h^ =^ 8)] Department of Computer Science — University of San Fran

Another A* example ode:^ Queue

I^ [(F

f^ =^ 27,

g^ =^ 21,

h^ = 6),

(B^ f^

=^ 28,^ g

=^ 8,^

h^ =^ 20),

(E^ f^ =

28,^ g

=^ 20,

h^ = 8),

(G^ f^

=^30 g

=^ 26,

h^ = 4)] Department of Computer Science — University of San Francisco – p.21/

??

Another A* example Node:^ Queue

F^ [(B^

f^ =^ 28,

g^ =^ 8,

h^ =^ 20),

(E^ f^

=^ 28,^

g^ =^ 20,

h =^ 8),

(G^ f =

30 g^

= 26,^

h^ =^ 4),(G

f^ =^30

g^ =^26

h^ =

4)]

Department of Computer Science — University of San Francisco – p.22/

??

Another A* example Node:^ Queue

B [(E^

f^ =^ 28,

g^ =^ 20,

h =^ 8),

(E^ f^

=^ 29,^

g^ =^ 21,

h^ = 8),

(G^ f =

30,^ g

h^ =^ 4),(G

f^ =^ 30,

g^ =^ 26,

h^ = 4)] Department of Computer Science — University of San Fran

Another A* example ode:^ Queue

(E^ f^ =^

29,^ g^

=^ 21,^

h =^ 8),

(G^ f^

=^30

g^ =^ 26,

h^ = 4),

G^ f^ =^30

g =^

26 h

=^ 4),^

(H^ f^ = 31,

g^ =^ 31,

h^ =^ 0)]

ext^ E^ can

be^ discarded)

Department of Computer Science — University of San Francisco – p.24/

??

Another A* example Node:^ Queue

G^ [(G

f^ = 30

g^ =^

26 h

(H^ f^ =

30,^ g

=^ 30,

h^ = 0),

(H^ f^ = 31,

g^ =^ 31,

h^ =^ 0)]

(next^ G

can^ be

discarded)

Department of Computer Science — University of San Francisco – p.25/

??

Another A* example Node:^ Queue

H.^ Solution.

[(H

f^ =^ 31,

g =^ 31,

h^ = 0)]

Solution:

A,C,D,I,G,H

(or^ A,C,D,F,G,H)

Department of Computer Science — University of San Fran

Pruning and Contours OZ LMD

F RP C

U^ B (^) G I V H E N 380400

420 S

Topologically, we can imagineA* creating a set of contourscorresponding to

f^ values over

the search space. A* will search all nodes withina contour before expanding. This allows us to

prune

the

search space.^ We can chop off the portionof the search treecorresponding to Zerindwithout searching it.

Department of Computer Science — University of San Francisco – p.27/

??

Building Effective Heuristics While A* is optimally efficient, actual performancedepends on developing accurate heuristics. Ideally,

h^ is as close to the actual cost to the goal (

∗h)as

possible while remaining admissible. Developing an effective heuristic requires someunderstanding of the problem domain.

Department of Computer Science — University of San Francisco – p.28/

??

Effective Heuristics - 8-puzzle h1 - number of misplaced tiles.^ This is clearly admissible, since each tile will have tobe moved at least once. h2 -^ Manhattan distance

between each tile’s current

position and goal position.^ Also admissible - best case, we’ll move each tiledirectly to where it should go. Which heuristic is better?

Department of Computer Science — University of San Fran