Heuristic Search Methods that use a heuristic function

  • Slides: 20
Download presentation
Heuristic Search Methods that use a heuristic function to provide specific knowledge about the

Heuristic Search Methods that use a heuristic function to provide specific knowledge about the problem: Heuristic Functions Hill climbing Beam search Hill climbing (2) Greedy search

Heuristic Functions ¥ To further improve the quality of the previous methods, we need

Heuristic Functions ¥ To further improve the quality of the previous methods, we need to include problem-specific knowledge on the problem. è How to do this in such a way that the algorithms remain generally applicable ? ? ? èHEURISTIC FUNCTIONS: u f: States --> Numbers u f(T) : expresses the quality of the state T – allow to express problem-specific knowledge, BUT: can be imported in a generic way in the algorithms. 2

Examples (1): ¥ Imagine the problem of finding a route on a road map

Examples (1): ¥ Imagine the problem of finding a route on a road map and that the NET below is the road map: 4 4 A B C 3 5 5 S G 4 3 D E F 2 4 ¥ Define f(T) = the straight-line distance from T to G A 10. 4 11 S D 8. 9 B 6. 7 E 6. 9 C 4 The estimate G can be wrong! F 3 3

Examples (2): 8 -puzzle ¥ f 1(T) = the number correctly placed tiles on

Examples (2): 8 -puzzle ¥ f 1(T) = the number correctly placed tiles on the board: 1 3 2 f 1 8 4 5 6 7 =4 ¥ f 2(T) = number or incorrectly placed tiles on board: ègives (rough!) estimate of how far we are from goal f 2 1 3 2 8 4 5 6 7 =4 Most often, ‘distance to goal’ heuristics are more useful ! 4

Examples (3): Manhattan distance ¥ f 3(T) = the sum of ( the horizontal

Examples (3): Manhattan distance ¥ f 3(T) = the sum of ( the horizontal + vertical distance that each tile is away from its final destination): ègives a better estimate of distance from the goal node f 3 1 5 2 8 4 3 6 7 = 1 + 4 + 2 + 3 = 10 5

Examples (4): Chess: ¥ F(T) = (Value count of black pieces) - (Value count

Examples (4): Chess: ¥ F(T) = (Value count of black pieces) - (Value count of white pieces) f = v( + v( - v( ) ) ) 6

Hill climbing A basic heuristic search method: depth-first + heuristic

Hill climbing A basic heuristic search method: depth-first + heuristic

Hill climbing_1 ¥ Example: using the straight-line distance: S A 10. 4 D 8.

Hill climbing_1 ¥ Example: using the straight-line distance: S A 10. 4 D 8. 9 A 10. 4 6. 7 B E 6. 9 F 3. 0 ¥ Perform depth-first, BUT: ¥ instead of left-toright selection, ¥ FIRST select the child with the best heuristic value G 8

Hill climbing_1 algorithm: 1. QUEUE <-- path only containing the root; 2. WHILE DO

Hill climbing_1 algorithm: 1. QUEUE <-- path only containing the root; 2. WHILE DO QUEUE is not empty AND goal is not reached remove the first path from the QUEUE; create new paths (to all children); reject the new paths with loops; sort new paths (HEURISTIC) ; add the new paths to front of QUEUE; 3. IF goal reached THEN success; ELSE failure; 9

Beam search Narrowing the width of the breadth-first search

Beam search Narrowing the width of the breadth-first search

Beam search (1): Depth 1) 8. 9 10. 4 D A Depth 2) B

Beam search (1): Depth 1) 8. 9 10. 4 D A Depth 2) B 8. 9 ¥ Perform breadthfirst, BUT: ¥ Only keep the WIDTH best new nodes S A 6. 7 ¥ Assume a prefixed WIDTH (example : 2 ) S D D A 10. 4 X X ignore E 6. 9 depending on heuristic at each new level. 11

Beam search (2): Depth 3) S 4. 0 B _C E 6. 9 X

Beam search (2): Depth 3) S 4. 0 B _C E 6. 9 X end ignore A D X Depth 4) X _C D D E X 6. 7 B S A B ¥ Optimization: E ignore 3. 0 F leafs that are not goal nodes (see C) D A X E B 10. 4 A _C F G 0. 0 12

Beam search algorithm: ¥ See exercises! Properties: ¥ Completeness: è Hill climbing: YES (backtracking),

Beam search algorithm: ¥ See exercises! Properties: ¥ Completeness: è Hill climbing: YES (backtracking), Beam search: NO ¥ Speed/Memory: è Hill climbing: u same as Depth-first (in worst case) è Beam search: u QUEUE always has length WIDTH, so memory usage is constant = WIDTH, time is of the order of WIDTH*m*b or WIDTH*d*b if no solution is found 13

Hill climbing_2 ¥ == Beam search with a width of 1. ¥ Inspiring Example:

Hill climbing_2 ¥ == Beam search with a width of 1. ¥ Inspiring Example: climbing a hill in the fog. èHeuristic function: check the change in altitude in 4 directions: the strongest increase is the direction in which to move next. ¥ Is identical to Hill climbing_1, except for dropping the backtracking. ¥ Produces a number of classical problems: 14

Problems with Hill climbing_2: Plateaus Foothills: Local maximum Ridges 15

Problems with Hill climbing_2: Plateaus Foothills: Local maximum Ridges 15

Comments: ¥ Foothills are local minima: hill climbing_2 can’t detect the difference. ¥ Plateaus

Comments: ¥ Foothills are local minima: hill climbing_2 can’t detect the difference. ¥ Plateaus don’t allow you to progress in any direction. èFoothills and plateaus require random jumps to be combined with the hill climbing algorithm. ¥ Ridges neither: the directions you have fixed in advance all move downwards for this surface. èRidges require new rules, more directly targeted to the goal, to be introduced (new directions to move). 16

Local search S ¥ Hill climbing_2 is an example of local search. ¥ In

Local search S ¥ Hill climbing_2 is an example of local search. ¥ In local search, we only keep track of 1 path and use it to compute a new path in the next step. A B C è QUEUE is always of the form: u ( p) D ¥ Another example: è MINIMAL COST search: ¥ If p is the current path: è the next path extends p by adding the node with the smallest cost from the endpoint of p A 3 2 D 4 B 3 C E 5 F 17

Greedy search Always expand the heuristically best nodes first.

Greedy search Always expand the heuristically best nodes first.

Greedy search, or Heuristic best-first search: S 1 10 3 15 35 2 25

Greedy search, or Heuristic best-first search: S 1 10 3 15 35 2 25 30 20 27 45 40 18 ¥ At each step, select the node with the best (in this case: lowest) heuristic value. The ‘open’ nodes 19

Greedy search algorithm: 1. QUEUE <-- path only containing the root; 2. WHILE DO

Greedy search algorithm: 1. QUEUE <-- path only containing the root; 2. WHILE DO QUEUE is not empty AND goal is not reached remove the first path from the QUEUE; create new paths (to all children); reject the new paths with loops; add the new paths and sort the entire QUEUE; 3. IF goal reached THEN success; ELSE failure; (HEURISTIC) 20