Download presentation
1
Introduction to Artificial Intelligence (G51IAI)
Dr Rong Qu Heuristic Searches
2
Blind Search vs. Heuristic Searches
Randomly choose where to search in the search tree When problems get large, not practical any more Heuristic search Explore the node which is more likely to lead to the goal state Quite often, using knowledge Both based on tree search blind, systematic, random choose which child node to go Heuristic, use knowledge, go to the promising child node / branches G51IAI - Heuristic
3
Heuristic Searches - Characteristics
Heuristic searches work by deciding which is the next best node to expand Has some domain knowledge Use a function to tell us how close the node is to the goal state Usually more efficient than blind searches Sometimes called an informed search There is no guarantee that it is the best node G51IAI - Heuristic
4
Heuristic Searches - Characteristics
Heuristic searches estimate the cost to the goal from its current position. It is usual to denote the heuristic evaluation function by h(n) Compare this with something like Uniform Cost Search which chooses the lowest code node thus far ( g(n) ) UCS: only guarantee the lowest cost route from the root to the current Heuristic: estimate the cost from the current node to the goal node – how? G51IAI - Heuristic
5
Heuristic Searches - Characteristics
Heuristic searches vs. Uniform Cost Search Uniform cost search expand the path with the lowest path cost chooses the lowest cost node thus far Heuristic search estimate how close the solution is to the goal not how cheap the solution is thus far Heuristic: better and precise evaluation of the current solution being built G51IAI - Heuristic
6
Heuristic Searches - Characteristics
Heuristic searches vs. Uniform Cost Search Heuristic searches evaluation function h(n): how close is the current node to the solution Uniform Cost Search path cost function g(n): the cost of the path thus far Draw tree example G51IAI - Heuristic
7
Heuristic Searches - Definition
Heuristics are "rules of thumb", educated guesses, intuitive judgments or simply common sense. A heuristic method is particularly used to rapidly come to a solution that is hoped to be close to the best possible answer, or 'optimal solution'. - Wikipedia G51IAI - Heuristic
8
Heuristic Searches - methods
Tree searches (G51IAI) A way to reduce the search effort by pushing search in good directions Not losing completeness Search algorithms Not complete Find good solutions quickly Genetic Algorithms, Tabu Search, Ant Algorithms G51IAI - Heuristic
9
Heuristic Searches - Implementation 1
Implementation is achieved by sorting the nodes based on the evaluation function: h(n) Search is based on the order of the nodes G51IAI - Heuristic
10
Heuristic Searches - Implementation 2
Function BEST-FIRST-SEARCH(problem, EVAL- FN) returns a solution sequence Inputs: a problem Eval-Fn: an evaluation function Queuing-Fn: a function that orders nodes by EVAL-FN Return GENERAL-SEARCH (problem, Queuing-Fn) Based on general search, now define the best first search, rather than picking the child randomly What’s important is the evaluation function, other operations are the same, i.e. remove front node, insert child nodes G51IAI - Heuristic
11
Heuristic Searches – Example
Go to the city which is nearest to the goal city Available infor: SLD to goal from each city on the map Evaluation function (heuristic): SLD, a good estimation of how good the solution is Hsld(n) = straight line distance between n and the goal location
12
Heuristic Searches - Greedy Search
So named as it takes the biggest “bite” it can out of the problem. That is, it seeks to minimise the estimated cost to the goal by expanding the node estimated to be closest to the goal state Function GREEDY-SEARCH(problem) returns a solution of failure Return BEST-FIRST-SEARCH(problem,h) Important: easy to define Simple, quick – still being used most of the time as initialisation approach G51IAI - Heuristic
13
Heuristic Searches - Greedy Search
It is only concerned with short term aims It is possible to get stuck in an infinite loop Fsg: two child nodes (Siblu and Buchrest); Fsg Bucharest (nearest to Iasi) Buchsrest: four child nodes; Buchsrest Fsg (nearest to Iasi) Iasi - Buchsrest: 226 Even bigger problem: get stuck to local optimal G51IAI - Heuristic
14
Heuristic Searches - Greedy Search
It is not optimal It is not complete Time and space complexity is O(bm); where m is the depth of the search tree Big O: to learn in ADS G51IAI - Heuristic
15
Performed well, but not optimal
Greedy Search Luckily not get in a loop, but Sibiu Bucharest is not optimal Performed well, but not optimal
16
UCS Arad Nodes Expanded 1.Sibiu 2.Rimnicu 3.Faragas 4.Arad 5.Pitesti
6.Zerind 7.Craiova 8.Timisoara 9.Bucharest 278 GOAL!! Neamt 286 215 Oradea 71 Zerind 87 Iasi Fringe in RED with g Visited in BLUE 75 140 92 Arad Optimal route is ( ) = 278 miles 140 140 Vaslui 118 99 99 Sibiu Faragas Timisoara 142 258 80 111 80 211 Lugoj Rimnicu 98 Urziceni 369 Hirsova 177 70 86 97 Exam the sub-problem now: Sibiu Bucharest UCS: optimal and complete Pitesti Mehadia 146 101 Bucharest 86 75 138 310 (F) Dobreta 90 278 (R,P) 226 (R) 120 Craiova 336 Eforie Giurgui [315 (R,P)]
17
Heuristic Searches vs. UCS
goal outline of graph increasing cost start goal outline of graph increasing cost start This region is basically wasted effort UCS: give all search directions the same priority as long as the current cost is the least Heuristic: use estimation (function) to guide search towards more promising direction to the goal Estimation from the current to the goal! Make sue of knowledge, not blind search G51IAI - Heuristic
18
Heuristic Searches vs. UCS
goal outline of graph increasing cost start Want to achieve this but stay complete optimal If bias the search “too much” then could miss goals or miss shorter paths However, heuristic search, guided by evaluation function not designed properly, not complete, nor optimal Greedy search: bias the search too much All background knowledge – now think how! G51IAI - Heuristic
19
Heuristic Searches - A* Algorithm
Combines the cost so far and the estimated cost to the goal That is fn = g(n) + h(n) This gives us an estimated cost of the cheapest solution through n g: cost so far (not losing the best from root to node so far) h: estimate to the goal (good guidance to goal from what’s the best so far) G51IAI - Heuristic
20
Heuristic Searches - A* Algorithm
We need to have a proper way to estimate h goal outline of graph start A B gA gB hA hB Best so far, corrected by good estimate gB < gA, but (gB + hB) > (gA + hA) G51IAI - Heuristic
21
Heuristic Searches - A* Algorithm
A search algorithm to find the shortest path through a search space to a goal state using a heuristic. f = g + h f - function that gives an evaluation of the state g - the cost of getting from the initial state to the current state h - the cost of getting from the current state to a goal state G51IAI - Heuristic
22
Heuristic Searches - A* Algorithm
A search algorithm to find the shortest path through a search space to a goal state using a heuristic h=0 A* becomes UCS complete & optimal* but search pattern undirected h too large if h is large enough to dominate g then becomes like Greedy, lose optimality *when cost along path never decrease G51IAI - Heuristic
23
Heuristic Searches - A* Algorithm
It can be proved to be optimal and complete providing that the heuristic is admissible. That is the heuristic must never over estimate the cost to reach the goal h(n) must provide a valid lower bound on cost to the goal But, the number of nodes that have to be searched still grows exponentially Minimisation problem here Intelligent: still exponentially G51IAI - Heuristic
24
Heuristic Searches - A* Algorithm
Function A*-SEARCH(problem) returns a solution of failure Return BEST-FIRST-SEARCH(problem, g + h) G51IAI - Heuristic
25
Straight Line Distances to Bucharest
Town SLD Arad 366 Bucharest Craiova 160 Dobreta 242 Eforie 161 Fagaras 178 Giurgiu 77 Hirsova 151 Iasi 226 Lugoj 244 Town SLD Mehadai 241 Neamt 234 Oradea 380 Pitesti 98 Rimnicu 193 Sibiu 253 Timisoara 329 Urziceni 80 Vaslui 199 Zerind 374 We can use straight line distances as an admissible heuristic as they will never overestimate the cost to the goal. This is because there is no shorter distance between two cities than the straight line distance. G51IAI - Heuristic
26
ANIMATION OF A*. Arad Nodes Expanded 1.Sibiu 2.Rimnicu 3.Pitesti
4.Fagaras 5.Bucharest GOAL!! Neamt Oradea 71 Zerind 87 Iasi Annotations: “g+h=f” Fringe in RED Visited in BLUE 75 =506 92 Arad Optimal route is ( ) = 278 miles 140 140 Vaslui 118 0+253=253 99+178=277 99 Sibiu Fagaras Timisoara Why not 211? 142 80 111 80+193=273 211 Lugoj Rimnicu 98 Urziceni Hirsova 177+98=275 70 86 97 Give chance to other direction if it’s good enough, while the overall direction is towards the goal. Pitesti Mehadia 146 101 Bucharest 86 75 138 310+0=310 (F) Dobreta 90 278+0=278 (R,P) =386(R) 120 Craiova Eforie Giurgui =475(P)
27
Arad Oradea Zerind Faragas Neamt Iasi Vaslui Hirsova Eforie Urziceni Giurgui Pitesti Sibiu Dobreta Craiova Rimnicu Mehadia Timisoara Lugoj 87 92 142 86 98 211 101 90 99 71 75 140 118 111 70 120 138 146 97 80 Bucharest Optimal route is ( ) = 278 miles Arad Oradea Zerind Fagaras Neamt Iasi Vaslui Hirsova Eforie Urziceni Giurgui Pitesti Sibiu Dobreta Craiova Rimnicu Mehadia Timisoara Lugoj 87 92 142 86 98 211 101 90 99 71 75 140 118 111 70 120 138 146 97 80 Bucharest Optimal route is ( ) = 278 miles UCS A* A*: give chance to other direction if it’s good enough, while the overall direction is towards the goal. UCS: give all directions the same chance. Difference: heuristic in A*: admissible Nodes expanded: 1.Sibiu; 2.Rimnicu; 3.Faragas; 4.Arad; 5.Pitesti; 6.Zerind; 7.Craiova; 8.Timisoara; 9.Bucharest 278 Nodes Expanded: 1.Sibiu; 2.Rimnicu; 3.Pitesti; 4.Fagaras; 5.Bucharest 278
28
In terms of a search tree we could represent this as follows ....
101 Bu 278+0 =278 5 97 Pi =275 Ri =273 3 2 80 138 Cr =475 146 99 Cr =386 Si. 0+253 =253 1 Fa =277 4 Maths: “g + h = f” 211 Bu 310+0 =310 140 Ar =506 The only problem in working through the algorithm was that when we found our goal state the first time we ignored it as we had to expand an even lower cost node to see if it led to an even better solution. This has shown to be a problem in previous examinations The goal state is achieved. In relation to path cost, A* has found the optimal route with 5 expansions. Press space to end. Press space to begin the search A* SEARCH TREE
29
Heuristic Searches - A* Algorithm
Clearly the expansion of the fringe is much more directed towards the goal The number of expansions is significantly reduced G51IAI - Heuristic
30
Heuristic Searches - A* Algorithm
A* is optimal and complete, but it is not all good news It can be shown that the number of nodes that are searched is still exponential to the size of most problems This has implications not only for the time taken to perform the search but also the space required Of these two problems the space complexity is more serious A*: more like a BFS, space is bigger problem G51IAI - Heuristic
31
Heuristic Searches - A* Algorithm
If you examine the animation on the previous slide you will notice an interesting phenomenon Along any path from the root, the f-cost never decreases This is no accident It holds true for all admissible heuristics Admissible: never over estimate G51IAI - Heuristic
32
Heuristic Searches - A* Example
Initial State Goal State Map search: good example 8-puzzle: another widely studied example in AI G51IAI - Heuristic
33
Heuristic Searches - A* Example
Typical solution is about twenty steps Branching factor is approximately three. Therefore a complete search would need to search 320 states. But by keeping track of repeated states we would only need to search 9! (362,880) states But even this is a lot (imagine having all these in memory) Our aim is to develop a heuristic that does not over estimate (it is admissible) so that we can use A* to find the optimal solution G51IAI - Heuristic
34
Heuristic Searches - A* Example
8 puzzle and 15 puzzle Online demo of A* algorithm for 8 puzzle Noyes Chapman’s 15 puzzle A lot online game: mainly based on A*? Key issue: how to design admissible heuristic! 15 puzzle: with only 15 and 14 reverse - not solvable! a solvable 15 puzzle: take the shortcut of solving the squares 1,2,3,4,5,9 and 13 - only have a 3x3 grid to solve. This speeds the process up quite considerably. G51IAI - Heuristic
35
Heuristic Searches - Possible Heuristics in A* Algorithm
= the number of tiles that are in the wrong position H2 = the sum of the distances of the tiles from their goal positions using the Manhattan Distance We need admissible heuristics (never over estimate) Both are admissible but which one is better? Lot of research attention: design efficient heuristic so better solutions can be found in shorter time Question: do we need to consider the path cost so far? G51IAI - Heuristic
36
Heuristic Searches - Possible Heuristics in A* Algorithm
= the number of tiles that are in the wrong position (=4) H2 = the sum of the distances of the tiles from their goal positions using the Manhattan Distance (=5) What’s the effect of higher and lower h? Why we don’t need to cost so far? G51IAI - Heuristic
37
Heuristic Searches - Possible Heuristics in A* Algorithm
1 3 4 8 6 2 7 5 1 3 4 8 6 2 7 5 5 4 1 3 4 8 2 7 6 5 1 3 4 8 6 2 7 5 6 1 3 4 8 6 2 7 5 1 3 4 8 6 2 7 5 1 3 4 8 6 2 7 5 4 6 5 1 3 4 8 2 7 6 5 6 3 H1 = the number of tiles that are in the wrong position (=4) H2 = the sum of the distances of the tiles from their goal positions using the Manhattan Distance (=5) G51IAI - Heuristic
38
Possible Heuristics in A* Algorithm
1 3 4 8 6 2 7 5 5 1 3 4 8 2 7 6 5 1 3 4 8 6 2 7 5 6 1 3 4 8 6 2 7 5 4 6 1 4 8 3 2 7 6 5 1 3 4 8 2 7 6 5 5 1 3 4 8 2 7 6 5 5 3 1 3 8 2 4 7 6 5 1 3 4 8 2 5 7 6 2 4 1 3 8 2 4 7 6 5 1 What’s wrong with this search? is it A*? H2 = the sum of the distances of the tiles from their goal positions using the Manhattan Distance (=5)
39
Possible Heuristics in A* Algorithm
1 3 4 8 6 2 7 5 4 1 3 4 8 2 7 6 5 1 3 4 8 6 2 7 5 5 1 3 4 8 6 2 7 5 3 5 1 4 8 3 2 7 6 5 1 3 4 8 2 7 6 5 4 1 3 4 8 2 7 6 5 3 3 1 4 8 3 2 7 6 5 1 4 8 3 2 7 6 5 4 3 1 4 2 8 3 7 6 5 3 What’s wrong with this search? is it A*? H1 = the number of tiles that are in the wrong position (=4)
40
Test from 100 runs with varying solution depths using h1 and h2
Solutions at different depths the average number of nodes that were expanded H2 looks better as fewer nodes are expanded. But why? G51IAI - Heuristic
41
Effective Branching Factor
h2 is better estimation compared with h1, closer to real cost of solution, more precise. Admissible, but as closer to the optimal solution as possible Effective branching factor: average number of branches expanded H2 has a lower branching factor and so fewer nodes are expanded Therefore, one way to measure the quality of a heuristic is to find its average branching factor H2 has a lower EBF and is therefore the better heuristic G51IAI - Heuristic
42
Domination For any node: h2(n) <= h1(n) h2 dominates h1
G51IAI - Heuristic
43
G51IAI - Heuristic Previous final year project
G51IAI - Heuristic
44
Show at each step what fringe nodes are in the queue (5 marks).
Use Uniform Cost Search to find the shortest path from A to F in the map below (not drawn to scale). You should not re-visit a node that you have just come from. Show at each step what fringe nodes are in the queue (5 marks). Show the list of nodes that are expanded (3 marks). State the shortest route you take and its cost (2 marks). Can Uniform Cost Search guarantee to find the optimal solution for this problem? Explain the reason. (3 marks) A 15 25 B 20 C 15 12 25 D E 16 8 F
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.