Jarrar.lecture notes.aai.2011s.ch4.informedsearch

473 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
473
On SlideShare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Jarrar.lecture notes.aai.2011s.ch4.informedsearch

  1. 1. Chapter 4 Informed Searching Dr. Mustafa Jarrar University of Birzeit [email_address] www.jarrar.info Lecture Notes, Advanced Artificial Intelligence (SCOM7341) University of Birzeit 2 nd Semester, 2011 Advanced Artificial Intelligence (SCOM7341)
  2. 2. Discussion and Motivation How to determine the minimum number of coins to give while making change?  The coin of the highest value first ?
  3. 3. Discussion and Motivation <ul><li>Travel Salesperson Problem </li></ul><ul><li>Any idea how to improve this type of search? </li></ul><ul><li>What type of information we may use to improve our search? </li></ul><ul><li>Do you think this idea is useful: (At each stage visit the unvisited city nearest to the current city)? </li></ul>Given a list of cities and their pair wise distances, the task is to find a shortest possible tour that visits each city exactly once.
  4. 4. Best-first search <ul><li>Idea: use an evaluation function f(n) for each node </li></ul><ul><ul><li>family of search methods with various evaluation functions (estimate of &quot;desirability“) </li></ul></ul><ul><ul><li>usually gives an estimate of the distance to the goal </li></ul></ul><ul><ul><li>often referred to as heuristics in this context </li></ul></ul><ul><ul><li>Expand most desirable unexpanded node. </li></ul></ul><ul><li>Implementation : </li></ul><ul><li>Order the nodes in fringe in decreasing order of desirability. </li></ul><ul><li>Special cases: </li></ul><ul><ul><li>greedy best-first search </li></ul></ul><ul><ul><li>A * search </li></ul></ul>
  5. 5. Romania with step costs in km Suppose we can have this info (SLD)  How can we use it to improve our search?
  6. 6. Greedy best-first search <ul><ul><li>Greedy best-first search expands the node that appears to be closest to goal. </li></ul></ul><ul><ul><li>Estimate of cost from n to goal , e.g., h SLD (n) = straight-line distance from n to Bucharest. </li></ul></ul><ul><li>Utilizes a h euristic function as evaluation function </li></ul><ul><ul><li>f(n) = h (n) = estimated cost from the current node to a goal. </li></ul></ul><ul><ul><li>Heuristic functions are problem-specific. </li></ul></ul><ul><ul><li>Often straight-line distance for route-finding and similar problems. </li></ul></ul><ul><ul><li>Often better than depth-first, although worst-time complexities are equal or worse (space). </li></ul></ul>
  7. 7. Greedy best-first search example
  8. 8. Greedy best-first search example
  9. 9. Greedy best-first search example
  10. 10. Greedy best-first search example
  11. 11. Properties of greedy best-first search <ul><li>Complete: No – can get stuck in loops (e.g., Iasi  Neamt  Iasi  Neamt  ….) </li></ul><ul><li>Time: O(b m ) , but a good heuristic can give significant improvement </li></ul><ul><li>Space: O(b m ) -- keeps all nodes in memory </li></ul><ul><li>Optimal: No </li></ul>b branching factor m maximum depth of the search tree
  12. 12. Discussion <ul><li>Do you think h SLD (n) is admissible? </li></ul><ul><li>Would you use h SLD (n) in Palestine? How? Why? </li></ul><ul><li>Did you find the Greedy idea useful? </li></ul><ul><li> Ideas to improve it? </li></ul>
  13. 13. A * search <ul><li>Idea: avoid expanding paths that are already expensive. </li></ul><ul><li>Evaluation function = path cost + estimated cost to the goal </li></ul><ul><li>f(n) = g(n) + h(n) </li></ul><ul><ul><li>- g(n) = cost so far to reach n </li></ul></ul><ul><ul><li>-h(n) = estimated cost from n to goal </li></ul></ul><ul><ul><li>-f(n) = estimated total cost of path through n to goal </li></ul></ul><ul><li>Combines greedy and uniform-cost search to find the (estimated) cheapest path through the current node </li></ul><ul><ul><li>Heuristics must be admissible </li></ul></ul><ul><ul><ul><li>Never overestimate the cost to reach the goal </li></ul></ul></ul><ul><ul><li>Very good search method, but with complexity problems </li></ul></ul>
  14. 14. A * search example
  15. 15. A * search example
  16. 16. A * search example
  17. 17. A * search example
  18. 18. A * search example
  19. 19. A * search example
  20. 20. A* Exercise How will A* get from Iasi to Fagaras?
  21. 21. A* Exercise Node Coordinates SL Distance A (5,9) 8.0 B (3,8) 7.3 C (8,8) 7.6 D (5,7) 6.0 E (7,6) 5.4 F (4,5) 4.1 G (6,5) 4.1 H (3,3) 2.8 I (5,3) 2.0 J (7,2) 2.2 K (5,1) 0.0
  22. 22. Solution to A* Exercise
  23. 23. Greedy Best-First Exercise Node Coordinates Distance A (5,9) 8.0 B (3,8) 7.3 C (8,8) 7.6 D (5,7) 6.0 E (7,6) 5.4 F (4,5) 4.1 G (6,5) 4.1 H (3,3) 2.8 I (5,3) 2.0 J (7,2) 2.2 K (5,1) 0.0
  24. 24. Solution to Greedy Best-First Exercise
  25. 25. Another Exercise Node C g(n) h(n) A (5,10) 0.0 8.0 B (3,8) 2.8 6.3 C (7,8) 2.8 6.3 D (2,6) 5.0 5.0 E (5,6) 5.6 4.0 F (6,7) 4.2 5.1 G (8,6) 5.0 5.0 H (1,4) 7.2 4.5 I (3,4) 7.2 2.8 J (7,3) 8.1 2.2 K (8,4) 7.0 3.6 L (5,2) 9.6 0.0 Do 1) A* Search and 2) Greedy Best-Fit Search
  26. 26. Admissible Heuristics <ul><li>A heuristic h(n) is admissible if for every node n , h(n) ≤ h * (n), where h * (n) is the true cost to reach the goal state from n . </li></ul><ul><li>An admissible heuristic never overestimates the cost to reach the goal, i.e., it is optimistic </li></ul><ul><li>Example: h SLD (n) (never overestimates the actual road distance) </li></ul><ul><li>Theorem-1 : If h(n) is admissible, A * using TREE-SEARCH is optimal. </li></ul><ul><li>(Ideas to prove this theorem?) </li></ul>
  27. 27. Optimality of A * (proof) <ul><li>Suppose some suboptimal goal G 2 has been generated and is in the fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G . </li></ul><ul><li>f(G 2 ) = g(G 2 ) since h (G 2 ) = 0 </li></ul><ul><li>g(G 2 ) > g(G) since G 2 is suboptimal </li></ul><ul><li>f(G) = g(G) since h (G) = 0 </li></ul><ul><li>f(G 2 ) > f(G) from above </li></ul>We want to prove: f(n) < f(G2) (then A* will prefer n over G2)
  28. 28. Optimality of A * (proof) <ul><li>Suppose some suboptimal goal G2 has been generated and is in the fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G. </li></ul><ul><li>f(G 2 ) > f(G) from above </li></ul><ul><li>h(n) ≤ h^*(n) since h is admissible </li></ul><ul><li>g(n) + h(n) ≤ g(n) + h * (n) </li></ul><ul><li>f(n) ≤ f(G) </li></ul><ul><li>Hence f(G 2 ) > f(n) , and n is expanded  contradiction ! </li></ul><ul><li>thus, A * will never select G 2 for expansion </li></ul>
  29. 29. Optimality of A * (proof) <ul><li>Suppose some suboptimal goal G2 has been generated and is in the fringe. Let n be an unexpanded node in the fringe such that n is on a shortest path to an optimal goal G. </li></ul><ul><li>In other words: </li></ul><ul><li>f(G 2 ) = g(G 2 ) + h(G 2 ) = g(G 2 ) > C*, since G 2 is a goal on a non-optimal path (C* is the optimal cost) </li></ul><ul><li>f(n) = g(n) + h(n) <= C*, since h is admissible </li></ul><ul><li>f(n) <= C* < f(G 2 ), so G 2 will never be expanded  A* will not expand goals on sub-optimal paths </li></ul>
  30. 30. Consistent Heuristics <ul><li>A heuristic is consistent if for every node n , every successor n' of n generated by any action a , </li></ul><ul><li>h(n) ≤ c(n,a,n') + h(n') </li></ul><ul><li>If h is consistent, we have </li></ul><ul><li>f(n') = g(n') + h(n') </li></ul><ul><li> = g(n) + c(n,a,n') + h(n') </li></ul><ul><li> ≥ g(n) + h(n) </li></ul><ul><li> = f(n) </li></ul><ul><li>i.e., f(n) is non-decreasing along any path. </li></ul><ul><li>Theorem-2 : If h(n) is consistent, A * using GRAPH-SEARCH is optimal. </li></ul><ul><li>consistency is also called monotonicity </li></ul>
  31. 31. Optimality of A * <ul><li>A * expands nodes in order of increasing f value </li></ul><ul><li>Gradually adds &quot; f -contours&quot; of nodes </li></ul><ul><li>Contour i has all nodes with f=f i , where f i < f i+1 </li></ul>
  32. 32. Complexity of A* <ul><li>The number of nodes within the goal contour search space is still exponential </li></ul><ul><ul><li>with respect to the length of the solution </li></ul></ul><ul><ul><li>better than other algorithms, but still problematic </li></ul></ul><ul><li>Frequently, space complexity is more important than time complexity </li></ul><ul><ul><li>A* keeps all generated nodes in memory </li></ul></ul>
  33. 33. Properties of A* <ul><li>Complete: Yes </li></ul><ul><li>(unless there are infinitely many nodes with f ≤ f(G) ) </li></ul><ul><ul><li>Time: Exponential </li></ul></ul><ul><ul><ul><li>Because all nodes such that f(n) <= C* are expanded! </li></ul></ul></ul><ul><ul><li>Space: Keeps all nodes in memory, </li></ul></ul><ul><ul><ul><li>Fringe is exponentially large </li></ul></ul></ul><ul><li>Optimal: Yes </li></ul><ul><li> who can propose an idea to improve the time/space complexity </li></ul>
  34. 34. Memory Bounded Heuristic Search <ul><li>How can we solve the memory problem for A* search? </li></ul><ul><li>Idea: Try something like iterative deeping search, but the cutoff is f-cost (g+h) at each iteration, rather than depth first. </li></ul><ul><li>Two types of memory bounded heuristic searches: </li></ul><ul><li>Recursive BFS </li></ul><ul><li>MA* </li></ul>
  35. 35. Recursive Best First Search (RBFS) RBFS changes its mind very often in practice. This is because the f=g+h become more accurate (less optimistic) as we approach the goal. Hence, higher level nodes have smaller f-values and will be explored first. Problem? If we have more memory we cannot make use of it. Ay idea to improve this? best alternative over fringe nodes, which are not children: do I want to back up?
  36. 36. Simple Memory Bounded A* (MA*) <ul><li>This is like A*, but when memory is full we delete the worst node (largest f-value). </li></ul><ul><li>Like RBFS, we remember the best descendent in the branch we delete. </li></ul><ul><li>If there is a tie (equal f-values) we first delete the oldest nodes first. </li></ul><ul><li>Simple-MBA* finds the optimal reachable solution given the memory constraint. </li></ul><ul><li>But time can still be exponential. </li></ul>
  37. 37. SMA* pseudocode function SMA*( problem ) returns a solution sequence inputs : problem , a problem static : Queue , a queue of nodes ordered by f -cost Queue  MAKE-QUEUE({MAKE-NODE(INITIAL-STATE[ problem ])}) loop do if Queue is empty then return failure n  deepest least-f-cost node in Queue if GOAL-TEST( n ) then return success s  NEXT-SUCCESSOR( n ) if s is not a goal and is at maximum depth then f( s )   else f( s )  MAX(f( n ),g( s )+h( s )) if all of n ’s successors have been generated then update n ’s f -cost and those of its ancestors if necessary if SUCCESSORS( n ) all in memory then remove n from Queue if memory is full then delete shallowest, highest-f-cost node in Queue remove it from its parent’s successor list insert its parent on Queue if necessary insert s in Queue end
  38. 38. Simple Memory-bounded A* (MA*) 24+0=24 A B 12 15 H 13  A G 18 13[15]  f = g+h (Example with 3-node memory) Progress of MA*. Each node is labeled with its current f -cost. Values in parentheses show the value of the best forgotten descendant. Can tell you when best solution found within memory constraint is optimal or not.  = goal Search space A B G C D E F H J I K 0+12=12 10+5=15 20+5=25 30+5=35 20+0=20 30+0=30 8+5=13 16+2=18 24+0=24 24+5=29 10 8 10 10 10 10 8 16 8 8 A 12 A B G 13 15 13 A G 24[  ] I 15[15] 24 A B G 15 15 24 A B C 15[24] 15 25 A B D 8 20 20[24] 20[  ]
  39. 39. Admissible Heuristics <ul><li>How can you invent a good admissible heuristic function? </li></ul><ul><li>E.g., for the 8-puzzle </li></ul>
  40. 40. Admissible heuristics <ul><li>E.g., for the 8-puzzle: </li></ul><ul><li>h 1 (n) = number of misplaced tiles </li></ul><ul><li>h 2 (n) = total Manhattan distance </li></ul><ul><li>(i.e., no. of squares from desired location of each tile) </li></ul><ul><li>h 1 (S) = ? </li></ul><ul><li>h 2 (S) = ? </li></ul>
  41. 41. Admissible Heuristics <ul><li>E.g., for the 8-puzzle: </li></ul><ul><li>h 1 (n) = number of misplaced tiles </li></ul><ul><li>h 2 (n) = total Manhattan distance </li></ul><ul><li>(i.e., no. of squares from desired location of each tile) </li></ul><ul><li>h 1 (S) = ? 8 </li></ul><ul><li>h 2 (S) = ? 3+1+2+2+2+3+3+2 = 18 </li></ul>
  42. 42. Dominance <ul><li>If h 2 (n) ≥ h 1 (n) for all n (both admissible) </li></ul><ul><li>then h 2 dominates h 1 </li></ul><ul><li>h 2 is better for search: it is guaranteed to expand less nodes. </li></ul><ul><li>Typical search costs (average number of nodes expanded): </li></ul><ul><li>d=12 IDS = 3,644,035 nodes A * (h 1 ) = 227 nodes A * (h 2 ) = 73 nodes </li></ul><ul><li>d=24 IDS = too many nodes A * (h 1 ) = 39,135 nodes A * (h 2 ) = 1,641 nodes </li></ul><ul><li>What to do If we have h 1 …h m , but none dominates the other? </li></ul><ul><li> h(n) = max{h 1 (n), . . .h m (n)} </li></ul>
  43. 43. Relaxed Problems <ul><li>A problem with fewer restrictions on the actions is called a relaxed problem </li></ul><ul><li>The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem </li></ul><ul><li>If the rules of the 8-puzzle are relaxed so that a tile can move anywhere , then h 1 (n) gives the shortest solution </li></ul><ul><li>If the rules are relaxed so that a tile can move to any near square, then h 2 (n) gives the shortest solution </li></ul>
  44. 44. Admissible Heuristics <ul><li>How can you invent a good admissible heuristic function? </li></ul><ul><li>Try to relax the problem, from which an optimal solution can be found easily. </li></ul><ul><li>Learn from experience. </li></ul><ul><li>Can machines invite an admissible heuristic automaticlly? </li></ul>
  45. 45. Local Search Algorithms <ul><li>In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution. </li></ul><ul><li>State space = set of &quot;complete&quot; configurations. </li></ul><ul><li>Find configuration satisfying constraints, e.g., n-queens. </li></ul><ul><li>In such cases, we can use local search algorithms. </li></ul><ul><ul><li>keep a single &quot;current&quot; state, try to improve it according to an objective function </li></ul></ul><ul><ul><li>Advantages: </li></ul></ul><ul><ul><ul><li>Uses little memory </li></ul></ul></ul><ul><ul><ul><li>Finds reasonable solutions in large infinite spaces </li></ul></ul></ul>
  46. 46. Local Search Algorithms <ul><li>Local search can be used on problems that can be formulated as finding a solution maximizing a criterion among a number of candidate solutions. </li></ul><ul><li>Local search algorithms move from solution to solution in the space of candidate solutions (the search space ) until a solution deemed optimal is found or a time bound is elapsed. </li></ul><ul><li>For example, the travelling salesman problem, in which a solution is a cycle containing all nodes of the graph and the target is to minimize the total length of the cycle. i.e. a solution can be a cycle and the criterion to maximize is a combination of the number of nodes and the length of the cycle. </li></ul><ul><li>A local search algorithm starts from a candidate solution and then iteratively moves to a neighbor solution. </li></ul>
  47. 47. Local Search Algorithms <ul><li>If every candidate solution has more than one neighbor solution; the choice of which one to move to is taken using only information about the solutions in the neighborhood of the current one. </li></ul><ul><li>hence the name local search. </li></ul><ul><li>Terminate on a time bound or if the situation is not improved after number of steps. </li></ul><ul><li>Local search algorithms are typically incomplete algorithms , as the search may stop even if the best solution found by the algorithm is not optimal. </li></ul>
  48. 48. Example: n -queens <ul><li>Put n queens on an n × n board with no two queens on the same row, column, or diagonal. </li></ul><ul><li>Move a queen to reduce number of conflicts. </li></ul>
  49. 49. Hill-Climbing Search <ul><li>Technique which belongs to the family of local search. </li></ul><ul><li>starts with a random (potentially poor) solution, and iteratively makes small changes to the solution, each time improving it a little. When the algorithm cannot see any improvement anymore, it terminates. </li></ul><ul><li>Problem: depending on initial state, can get stuck in local maxima. </li></ul><ul><li>Hill climbing can be used to solve problems that have many solutions, some of which are better than others. (e.g. Bisimilarity ) </li></ul>
  50. 50. Hill-climbing search: 8-queens problem <ul><li>h = number of pairs of queens that are attacking each other, either directly or indirectly ( h = 17 for the above state) </li></ul>Each number indicates h if we move a queen in its corresponding column
  51. 51. Hill-climbing search: 8-queens problem A local minimum with h = 1
  52. 52. Simulated Annealing Search <ul><li>Find an acceptably good solution in a fixed amount of time, rather than the best possible solution. </li></ul><ul><li>Locating a good approximation to the global minimum of a given function in a large search space. </li></ul><ul><li>At each step, the SA heuristic considers some neighbour s' of the current state s , and probabilistically decides between moving the system to state s' or staying in state s . </li></ul><ul><li>Widely used in VLSI layout, airline scheduling, etc. </li></ul>
  53. 53. Properties of Simulated Annealing Search <ul><li>One can prove: If T decreases slowly enough, then simulated annealing search will find a global optimum with probability approaching 1 (however, this may take VERY long) </li></ul><ul><li>Widely used in VLSI layout, airline scheduling, etc. </li></ul>
  54. 54. Genetic Algorithms <ul><li>Inspired by evolutionary biology such as inheritance. </li></ul><ul><li>Evolves toward better solutions. </li></ul><ul><li>A successor state is generated by combining two parent states. </li></ul><ul><li>Start with k randomly generated states ( population ). </li></ul>
  55. 55. Genetic Algorithms <ul><li>A state is represented as a string over a finite alphabet (often a string of 0s and 1s) </li></ul><ul><li>Evaluation function ( fitness function ). Higher values for better states. </li></ul><ul><li>Produce the next generation of states by selection, crossover, and mutation. </li></ul><ul><li>Commonly, the algorithm terminates when either a maximum number of generations has been produced, or a satisfactory fitness level has been reached for the population. </li></ul>
  56. 56. <ul><li>Fitness function: number of non-attacking pairs of queens (min = 0, max = 8 × 7/2 = 28) </li></ul><ul><li>24/(24+23+20+11) = 31% </li></ul><ul><li>23/(24+23+20+11) = 29% etc </li></ul>Genetic Algorithms fitness: #non-attacking queens probability of being regenerated in next generation
  57. 57. Genetic Algorithms [2,6,9,3,5 0,4,1,7,8] [3,6,9,7,3 8,0,4,7,1] [2,6,9,3,5,8,0,4,7,1] [3,6,9,7,3,0,4,1,7,8]
  58. 58. Homework-1 <ul><li>Draw the map of about 20 towns (including Jerusalem), Illustrate the greedy, A*, and RBSF algorithms to go between a town and Bethlehem. </li></ul><ul><li>Estimate the straight line distance between these towns (use Google earth). Prove (theoretically, and by example) that your estimation is consistent and admissible; and that the obtained path is optimal. </li></ul><ul><li>Overestimate the distances, and proof (theoretically, and by example) that the obtained path to Bethlehem is not optimal. </li></ul><ul><li>Upload this homework to Ritaj, and don’t send it to me directly. </li></ul><ul><li>Your solution should be clear, and with animation (use ppt). </li></ul><ul><li>Each student should select different towns (whole Palestine!). </li></ul><ul><li>Don’t send me email (Only to Ritaj). </li></ul><ul><li>File name: AAI10.Search.RamiHodrob.v52.ppt </li></ul><ul><li>Spilling of Town should correct (as found on the map or Wikipedia) </li></ul><ul><li>Deadline (11/2/2011) </li></ul>

×