ai05_04_heursearch notes
DESCRIPTION
notesTRANSCRIPT
-
7/18/2019 AI05_04_HeurSearch notes
1/28
Heuristic search, page 1CSI 4106, Winter 2005
Heuristic searchPointsDefinitionsBest-first searchHill climbingProblems with hill climbing An example: local and globalheuristic functions
Simulated annealing
The A* procedureeans-ends anal!sis
-
7/18/2019 AI05_04_HeurSearch notes
2/28
Heuristic search, page 2CSI 4106, Winter 2005
Definitions
Heuristics "#ree$ heuriskein % find& disco'er(: )the stud!of the methods and rules of disco'er! and in'ention)
+e use our $nowledge of the problem to consider some "not all( successors of the current state "preferabl! ,ustone& as with an oracle( This means pruning the statespace& gaining speed& but perhaps missing the solution.n chess: consider one "apparentl! best( mo'e& ma!be a few -- butnot all possible legal mo'es
.n the tra'elling salesman problem: select one nearest cit!& gi'e upcomplete search "the greed! techni/ue( This gi'es us& in pol!nomialtime& an approximate solution of the inherentl! exponential problem0 itcan be pro'en that the approximation error is bounded
-
7/18/2019 AI05_04_HeurSearch notes
3/28
Heuristic search, page 3CSI 4106, Winter 2005
Definitions "1(
2or heuristic search to wor$& we must be able to ran$the children of a node A heuristic function ta$es a stateand returns a numeric 'alue -- a composite assessmentof this state +e then choose a child with the best score"this could be a maximum or minimum(
A heuristic function can help gain or lose a lot& butfinding the right function is not alwa!s eas!
The 3-pu44le: how man! misplaced tiles5 how man!slots awa! from the correct place5 and so on
+ater ,ugs: 5556hess: no simple counting of pieces is ade/uate
-
7/18/2019 AI05_04_HeurSearch notes
4/28Heuristic search, page 4CSI 4106, Winter 2005
Definitions "7(
The principal gain -- often spectacular -- is thereduction of the state space 2or example& thefull tree for Tic-Tac-Toe has 8 lea'es .f weconsider s!mmetries& the tree becomes sixtimes smaller& but it is still /uite large
+ith a fairl! simple heuristic function we canget the tree down to 9 states " ore on thiswhen we discuss games (
Heuristics can also help speed up exhausti'e &blind search& such as depth-first and breadth-first search
-
7/18/2019 AI05_04_HeurSearch notes
5/28Heuristic search, page 5CSI 4106, Winter 2005
Best-first search
The algorithmselect a heuristic function "e g & distance to the goal(0put the initial node"s( on the open list0repeat
select ;& the best node on the open list0succeed if ; is a goal node0 otherwise put ; on theclosed list and add ;
-
7/18/2019 AI05_04_HeurSearch notes
6/28Heuristic search, page 6CSI 4106, Winter 2005
Hill climbing
This is a greedy algorithm: go as high up as possibleas fast as possible& without loo$ing around too much
The algorithm
select a heuristic function0
set 6& the current node& to the highest-'alued initialnode0
loop
select ;& the highest-'alued child of 60
return 6 if its 'alue is better than the 'alue of ;0otherwise set 6 to ;0
-
7/18/2019 AI05_04_HeurSearch notes
7/28
Heuristic search, page 7CSI 4106, Winter 2005
Problems with hill climbing
= >ocal maximum& or the foothill problem: there is apea$& but it is lower than the highest pea$ in thewhole space
1 The plateau problem: all local mo'es are e/uall!
unpromising& and all pea$s seem far awa!7 The ridge problem: almost e'er! mo'e ta$es us
down
?andom-restart hill climbing is a series of hill-climbing searches with a randoml! selected startnode whene'er the current search gets stuc$
See also simulated annealing -- in a moment
-
7/18/2019 AI05_04_HeurSearch notes
8/28
Heuristic search, page 8CSI 4106, Winter 2005
A hill climbing example
H
G
F
E
D
C
B
A
Goal
state
Initial
state
H
G
F
E
D
C
B
A
H
G
F
E
D
C
B A
Move
1
H
G
F
E
D
C
B A
Move
2a
H
G
F
E
D
C
B A
Move
2b
-
7/18/2019 AI05_04_HeurSearch notes
9/28
Heuristic search, page 9CSI 4106, Winter 2005
A hill climbing example "1(
local heuristic !unction6ount @= for e'er! bloc$ that sits on the correctthing The goal state has the 'alue @3
6ount -= for e'er! bloc$ that sits on an incorrectthing .n the initial state bloc$s 6& D& & 2& #& Hcount @= each Bloc$s A& B count -= each & for thetotal of @9
o'e = gi'es the 'alue @ "A is now on the correctsupport( o'es 1a and 1b both gi'e @9 "B and H
are wrongl! situated( This means we ha'e a localmaximum of @
-
7/18/2019 AI05_04_HeurSearch notes
10/28
Heuristic search, page 10CSI 4106, Winter 2005
A hill climbing example "7(
glo"al heuristic !unction
6ount @; for e'er! bloc$ that sits on a correctstac$ of ; things The goal state has the 'alue@13
6ount -; for e'er! bloc$ that sits on an incorrectstac$ of ; things That is& there is a largepenalt! for bloc$s tied up in a wrong structure
.n the initial state 6& D& & 2& #& H count -=& -1&-7& -9& -C& - A counts - & for the total of -13
continued
-
7/18/2019 AI05_04_HeurSearch notes
11/28
Heuristic search, page 11CSI 4106, Winter 2005
A hill climbing example "9(
o'e = gi'es the 'alue -1= "A is now on thecorrect support(
o'e 1a gi'es -= & because 6& D& & 2& #& Hcount -=& -1& -7& -9& -C& -=
o'e 1b gi'es -=C& because 6& D& & 2& #count -=& -1& -7& -9& -C
There is no local maximum
oral: sometimes changing the heuristicfunction is all we need
-
7/18/2019 AI05_04_HeurSearch notes
12/28
Heuristic search, page 12CSI 4106, Winter 2005
Simulated annealing
The intuition for this search method& animpro'ement on hill-climbing& is theprocess of graduall! cooling a li/uidThere is a schedule of )temperatures)&
changing in time ?eaching the )free4ingpoint) "temperature ( stops the process
.nstead of a random restart& we use amore s!stematic method
-
7/18/2019 AI05_04_HeurSearch notes
13/28
Heuristic search, page 13CSI 4106, Winter 2005
Simulated annealing "1(The algorithm& one of the 'ersions
select a heuristic function f0set 6& the current node& to an! initial node0set t& the current time& to 0let schedule"x( be a table of )temperaturesE0
loopt % t @ =0if schedule"t( % & return 60select at random ;& an! child of 60if f";( F f"6(& set 6 to ;& otherwise
set 6 to ; with probabilit! e "f";(-f"6((Gschedule"t( 0
-
7/18/2019 AI05_04_HeurSearch notes
14/28
Heuristic search, page 14CSI 4106, Winter 2005
A few other search ideas
Stochastic beam search:
select w nodes at random0 nodes with higher'alues ha'e a higher probabilit! of selection
#enetic algorithms:generate nodes li$e in stochastic beam search&but from two parents rather than from one
"This topic is worth! of a separate lecture (
-
7/18/2019 AI05_04_HeurSearch notes
15/28
Heuristic search, page 15CSI 4106, Winter 2005
The A* procedureHill-climbing "and its cle'er 'ersions( ma! miss an optimal solutionHere is a search method that ensures optimalit! of the solution
The algorithm$eep a list of partial paths "initiall! root to root& length (0repeat
succeed if the first path P reaches the goal node0
otherwise remo'e path P from the list0extend P in all possible wa!s& add new paths to the list0sort the list b! the sum of two 'alues: the real cost of P till now&and an estimate of the remaining distance0prune the list b! lea'ing onl! the shortest path for each nodereached so far0
untilsuccess or the list of paths becomes empt!0
-
7/18/2019 AI05_04_HeurSearch notes
16/28
Heuristic search, page 16CSI 4106, Winter 2005
The A* procedure "1(
A* re/uires a lower-bound estimate of thedistance of an! node to the goal node Aheuristic that ne'er o'erestimates is alsocalled optimistic or admissible
+e consider three functions with 'alues :
I g"n( is the actual cost of reaching node n&
I h"n( is the actual unknown remaining cost&
I h
-
7/18/2019 AI05_04_HeurSearch notes
17/28
Heuristic search, page 17CSI 4106, Winter 2005
The A* procedure "7(
Here is a s$etch! proof of the optimalit! of the goal nodefound b! A* >et m be such a non-optimal goal:
g"m( F g"n $(
and let n & n=& & n$ be a path leading to n $
Since m is a goal& h"m( % and thus h
-
7/18/2019 AI05_04_HeurSearch notes
18/28
Heuristic search, page 18CSI 4106, Winter 2005
The A* procedure "9( A simple search problem: S is the start node& # is the
goal node& the real distances are shown
A lower-bound estimate of the distance to # could beas follows "note that we do not need it for 2(:
A B 6
D 2
#S
1
7
9
9 9
9C C
7 C
A B 6
D 2
#S
C 37 9
8 1== C
= =
=7 C
-
7/18/2019 AI05_04_HeurSearch notes
19/28
Heuristic search, page 19CSI 4106, Winter 2005
The A* procedure "C(Hill-climbinghappens to
succeed here: S
A D
A
B 2
#
S
D
= = 9#2
= = == C 7#1
C 3 8 1 3#5
= 0#0
-
7/18/2019 AI05_04_HeurSearch notes
20/28
Heuristic search, page 20CSI 4106, Winter 2005
The A* procedure " (
A*& step =
S
A D
7@= = 9@8 1
-
7/18/2019 AI05_04_HeurSearch notes
21/28
Heuristic search, page 21CSI 4106, Winter 2005
The A* procedure " (
A*& step 1
S
A D
B D
=7 = =7 1
7@9@C 3 7@C@8 1
-
7/18/2019 AI05_04_HeurSearch notes
22/28
Heuristic search, page 22CSI 4106, Winter 2005
The A* procedure "3(
A*& step 7
S
A D
B
6
D
=7 = =7 1
=1 3 = 1
7@9@9@7 9 7@9@C@ =
-
7/18/2019 AI05_04_HeurSearch notes
23/28
Heuristic search, page 23CSI 4106, Winter 2005
The A* procedure "8(
A*& step 9
S
A D
B
6
D A
=7 = =7 1
=1 3 = 1 9@C@= =
=9 9 =8 = 9@1@ =
-
7/18/2019 AI05_04_HeurSearch notes
24/28
Heuristic search, page 24CSI 4106, Winter 2005
The A* procedure "= (
A*& step C
S
A D
B
6
2
D A
B
=7 = =7 1
=1 3 = 1 =8 =
=9 9 =8 = =7 =
9@1@C@C 3 9@1@9@7 C
-
7/18/2019 AI05_04_HeurSearch notes
25/28
Heuristic search, page 25CSI 4106, Winter 2005
The A* procedure "==(
A*& step
S
A D
B
6
2
#
D A
B
=7 = =7 1
=1 3 = 1 =8 =
=9 9 =8 = =7 =
= 3 =7 C
-
7/18/2019 AI05_04_HeurSearch notes
26/28
Heuristic search, page 26CSI 4106, Winter 2005
The A* procedure "=1(
The 3-pu44le withoptimistic heuristics
A& & ;: states0m % misplaced0d % depth0f"x( % m"x( @ d"x(
1
2 3
4
5
6
7
8
1
2 3
4
567
8
1
2 3
4
5
6
7
8
1
2 3
4
5
6
7
8
d(x)
=0
d(x)
=1
d(x)
=2
d(x)
=3
m(B)
=5
m(A)
=4
m(C)
=3
m(D)
=5
1
2 3
4
567
8 1
2 3
4
567
8
1
2 3
4
567
8
m(E)
=3
m(F)
=3
m(G)
=4
1
2 3
4
567
8
m(J)
=2
1
2 3
4
567
8
m(K)
=4
m(H)
=3
m(I)
=4
1
2 3
4
56
7
8
12
3
4
567
8
d(x)
=4
1 2 3
4
567
8
m(L)
=1
d(x)
=5
1 2 3
4
567
8
m(M)
=0
1 2 3
4
56
7 8
m(N)
=2
-
7/18/2019 AI05_04_HeurSearch notes
27/28
Heuristic search, page 27CSI 4106, Winter 2005
eans-ends anal!sis
The idea is due to ;ewell and Simon "=8C (: wor$ b!reducing the difference between states& and soapproaching the goal state There are procedures&indexed b! differences& that change states
The #eneral Problem Sol'er algorithm
set 6& the current node& to an! initial node0loop
succeed if the goal state has been reached& otherwisefind the difference between 6 and the goal state0choose a procedure that reduces this difference & appl!it to 6 to produce the new current state0
-
7/18/2019 AI05_04_HeurSearch notes
28/28
Heuristic search, page 28CSI 4106, Winter 2005
eans-ends anal!sis "1( An example: planning a trip
miles Plane Train 6ar Taxi +al$
F = L
= -= L L
= -= L L
K = L
Prere/uisite At plane At train At car At taxi
D
istance
P r o c e d u r e