SlideShare una empresa de Scribd logo
1 de 13
Descargar para leer sin conexión
A* Heuristic
                                                 Search
                                             Andrew W. Moore
                                                 Professor
                                        School of Computer Science
                                         Carnegie Mellon University
                                                      www.cs.cmu.edu/~awm
                                                        awm@cs.cmu.edu
                                                          412-268-7599

Note to other teachers and users of these slides. Andrew would be delighted if you found this source
material useful in giving your own lectures. Feel free to use these slides verbatim, or to modify them to fit
your own needs. PowerPoint originals are available. If you make use of a significant portion of these
slides in your own lecture, please include this message, or the following link to the source repository of      Slide 1
Andrew’s tutorials: http://www.cs.cmu.edu/~awm/tutorials . Comments and corrections gratefully received.




                                                        Overview
    • The inadequacies of “Best First Greedy”
      heuristic search.
    • Good trick: take account of your cost of getting
      to the current state.
    • When should the search stop?
    • Admissible heuristics
    • A* search is complete
    • A* search will always terminate
    • A*’s dark secret
    • Saving masses of memory with IDA* (Iterative
      Deepening A*)
                                                                                                                Slide 2




                                                                                                                          1
Let’s Make “Best first Greedy” Look
             Stupid!
                                                  4

       2              1                 1             2
 S            A               B             C              G

h=4          h=3             h=2            h=1            h=0

• Best –first greedy is clearly not guaranteed
  to find optimal
• Obvious question: What can we do to
  avoid the stupid mistake?
                                                           Slide 3




           A* - The Basic Idea
• Best-first greedy: When you expand a node n, take each
  successor n' and place it on PriQueue with priority h(n')

• A*: When you expand a node n, take each successor n'
  and place it on PriQueue with priority

      (Cost of getting to n') + h(n')                     (1)

      Let g(n) = Cost of getting to n                     (2)

and then define…

             f(n) = g(n) + h(n)                           (3)
                                                           Slide 4




                                                                     2
A* Looking Non-Stupid
                                                         4

       2                1                  1                 2
 S                 A           B                   C                 G

h=4            h=3             h=2                 h=1               h=0




                                                                     Slide 5




      When should A* terminate?
Idea: As soon as it generates a goal state?
Look at this example:
                                   1
           1           S                           h=3
                                               B             1
       h=7             h=8
  A                                                      h=2     C

               7                               D                 1
                                                   h=1

                                       7
                        G    h=0

                                                                     Slide 6




                                                                               3
Correct A* termination rule:
   A* Terminates Only When a Goal State Is Popped
   from the Priority Queue
                                           1
                1              S                       h=3
                                                   B           1
            h=7                h=8
       A                                                     h=2   C

                    7                              D               1
                                                       h=1

                                               7
                                G    h=0

                                                                       Slide 7




                    A* revisiting states
   Another question: What if A* revisits a state that was
   already expanded, and discovers a shorter path?

                                           1
                1              S                       h=3
                                                   B           1
            h=7                h=8
       A                                                           C     h=2


                    1/2                            D               1
                                                       h=1
In this example a state that
had been expanded gets                         7
re-expanded. How and            G
why?
                                                                       Slide 8




                                                                                 4
A* revisiting states
    What if A* visits a state that is already on the queue?

                               h=8
                                                 1
                   1             S                                    h=3
                                                                  B            1
              h=7
        A                                                                            C       h=8


                       1/2                                        D                1
                                                                      h=1
In this example a state that had
been on the queue and was                                                   note that this h
                                           G          7                     value has changed
waiting for expansion had its
                                                                            from previous
priority bumped up. How and                                                 page.
why?
                                                                                         Slide 9




                                                              f
                                                        cost o         Remind
    The A* Algorithm                            g(n) is       n                er:
                                                                      heuristic h(n) is a
                                          inder: wn path to
                                      Rem t kno                                 e
                                            s                         cost to a stimate of
                                      shorte                                   goal fro
                                                                                        mn

•   Priority queue PQ begins empty.
•   V (= set of previously visited (state,f,backpointer)-triples) begins empty.
•   Put S into PQ and V with priority f(s) = g(s) + h(s)
•   Is PQ empty?
                                                                = h(s) because
       Yes? Sadly admit there’s no solution                       g(start) = 0
       No? Remove node with lowest f(n) from queue. Call it n.
       If n is a goal, stop and report success.
       “expand” n : For each n' in successors(n)….                        use sneaky trick
                                                                          to compute g(n)
         • Let f’ = g(n') + h(n') = g(n) + cost(n,n') + h(n')
         • If n' not seen before, or n' previously expanded with
           f(n')>f’, or n' currently in PQ with f(n')>f’
         • Then Place/promote n' on priority queue with priority f’
           and update V to include (state=n', f ’, BackPtr=n).
         • Else Ignore n'
                                                                                        Slide 10




                                                                                                   5
Is A* Guaranteed to Find the
             Optimal Path?
            1           A
                               1
                    h=6

                                          h=0
  S   h=7
                                          G

                    3


  Nope. And this example shows why not.

                                          Slide 11




        Admissible Heuristics
• Write h*(n) = the true minimal cost to goal
  from n.
• A heuristic h is admissible if
     h(n) <= h*(n) for all states n.
• An admissible heuristic is guaranteed
  never to overestimate cost to goal.
• An admissible heuristic is optimistic.

                                          Slide 12




                                                     6
8-Puzzle Example

 Example   1   5                    Goal    1 2 3
 State                              State
           2 6 3                            4 5 6
           7 4 8                            7 8
 Which of the following are admissible heuristics?
• h(n) = Number of tiles in wrong
  position in state n
• h(n) = 0                                  • h(n) = min (2, h*[n])
• h(n) = Sum of Manhattan                   • h(n) = h*(n)
  distances between each tile and           • h(n) = max (2, h*[n])
  its goal location
• h(n) = 1                                                  Slide 13




       A* with Admissible Heuristic
        Guarantees Optimal Path
 • Simple proof
 • Your lecturer will attempt to give it from
   memory.
 • He might even get it right. But don’t hold
   your breath.




                                                            Slide 14




                                                                       7
Is A* Guaranteed to                            i.e. is it
        Terminate?                                complete?
• There are finitely many acyclic paths in the search
  tree.
• A* only ever considers acyclic paths.
• On each iteration of A* a new acyclic path is
  generated because:
   – When a node is added the first time, a new path
     exists.
   – When a node is “promoted”, a new path to that
     node exists. It must be new because it’s shorter.
• So the very most work it could do is to look at every
  acyclic path in the graph.
• So, it terminates.                               Slide 15




   Comparing Iterative Deepening with A*
           From Russell and Norvig, Page 107, Fig 4.8

                                     For 8-puzzle, average number of
                                     states expanded over 100
                                     randomly chosen problems in
                                     which optimal path is length…
                                     …4 steps …8 steps …12 steps

 Iterative Deepening (see            112       6,300      3.6 x 106
 previous slides)
 A* search using “number of          13        39         227
 misplaced tiles” as the heuristic
 A* using “Sum of Manhattan          12        25         73
                                                                Slide 16
 distances” as the heuristic




                                                                           8
Indeed there are
                                                                 only a couple
    Comparing Iterative Deepening with A*
Andrew’s editorial co
                        mments
                                    even “number of misp
                                                            lacedhundred thousand
                                                                 states for the entire
1. At first sight might look like                 state)=0 would eight puzzle
                          istic. But and ly h(
                From Russell probabNorvig, Page 107, Fig 4.8
   tiles” is a great heur                       the difference is
                           better than ID, so
    also do much much                 blem of expanding th
                                                             e same
    mainly   to do with ID’s big pro                 c.
                             t the use of a heuristi
    state many times, no                         panded” does notof states
                                                 Average number
                         “number of states ex
 2. Judging solely by                            expanded and 100 randomly
                                                      tables over
                               of maintaining hash
     account for overhead                        clear here that this
                                                 chosen problem in which optimal
                            , though it’s pretty
     priority queue for A*
                              ange the results. path is length…
     won’t dramatically ch
                                                 …4 steps …8 steps …12 steps

  Iterative Deepening (see                  112         6,300        3.6 x 106
  previous slides)
  A* search using “number of                13          39           227
  misplaced tiles” as the heuristic
  A* using “Sum of Manhattan                12          25           73
                                                                          Slide 17
  distances” as the heuristic




        A* : The Dark Side
   • A* can use lots of memory.
     In principle:
         O(number of states)
   • For really big search
     spaces, A* will run out of
     memory.



                                                                          Slide 18




                                                                                         9
IDA* : Memory Bounded Search
•     Iterative deepening A*. Actually, pretty different from A*. Assume
      costs integer.
       1.   Do loop-avoiding DFS, not expanding any node with
                 f(n) > 0. Did we find a goal? If so, stop.
       2.   Do loop-avoiding DFS, not expanding any node with
                 f(n) > 1. Did we find a goal? If so, stop.
       3.   Do loop-avoiding DFS, not expanding any node with
                 f(n) > 2. Did we find a goal? If so, stop.
       4.   Do loop-avoiding DFS, not expanding any node with
                 f(n) > 3. Did we find a goal? If so, stop.
            …keep doing this, increasing the f(n) threshold by 1 each
            time, until we stop.
•     This is
            Complete
            Guaranteed to find optimal
            More costly than A* in general.

                                                                   Slide 19




            What You Should Know
• Thoroughly understand A*.
• Be able to trace simple examples of A* execution.
• Understand “admissibility” of heuristics. Proof of
  completeness, guaranteed optimality of path.
• Be able to criticize best first search.

References:
    Nils Nilsson. Problem Solving Methods in Artificial Intelligence.
    McGraw Hill (1971) E&S-BK 501-5353 N71p.
    Judea Pearl. Heuristics: Intelligent Search Strategies for Computer
    Problem Solving. Addison Wesley (1984) E&S-BK 501-535 P35h.
    Chapters 3 & 4 of Stuart Russell and Peter Norvig. Artificial
    Intelligence: A Modern Approach.
                                                                   Slide 20




                                                                              10
Proof: A* with Admissible Heuristic Guarantees Optimal Path
• Suppose it finds a suboptimal path, ending in goal state G1
  where f(G1) > f* where f* = h* (start) = cost of optimal path.
• There must exist a node n which is
    Unexpanded
    The path from start to n (stored in the BackPointers(n)
    values) is the start of a true optimal path
                                                             Why must such a node
• f(n) >= f(G1) (else search wouldn’t have ended)            exist? Consider any
                                                             optimal path
• Also f(n) = g(n) + h(n)         because it’s on
                                  optimal path               s,n1,n2…goal. If all along
       = g*(n) + h(n)                                        it were expanded, the goal
       <= g*(n) + h*(n)                 By the               would’ve been reached
                                        admissibility        along the shortest path.
       = f*         Because n is on     assumption
                      the optimal path

So f* >= f(n) >= f(G1)                   contradicting
                                         top of slide
                                                                               Slide 21




                         Exercise Part 1
    In the following maze the successors of a cell include any cell directly to the
    east, south, west or north of the current cell except that no transition may pass
    through the central barrier. for example successors(m) = { d , n , g }.

                                                a        b
                                                c        d   e
                             f     s      h     k        m   n
                            p      q      r     t        g

    The search problem is to find a path from s to g. We are going to examine the
    order in which cells are expanded by various search algorithms. for example,
    one possible expansion order that breadth first search might use is:
                                 shfkpcqarbtdg
    There are other possible orders depending on which of two equal-distance-
    from-start states happen to be expanded first. For example s f h p k c q r a t b
    g is another possible answer.                                  continued->
                                                                               Slide 22




                                                                                          11
Exercise Part 1 continued

                                           a        b
                                           c        d   e
                         f       s   h     k        m   n
                         p       q   r      t       g

Assume you run depth-first-search until it expands the goal node. Assume
that you always try to expand East first, then South, then West, then North.
Assume your version of depth first search avoids loops: it never expands a
state on the current path. What is the order of state expansion?




                                                                           Slide 23




                     Exercise Part 2
                                            a       b
                                            c       d   e
                             f   s    h     k       m   n
                         p       q    r         t   g

Next, you decide to use a Manhattan Distance Metric heuristic function
h(state) = shortest number of steps from state to g if there were no barriers
So, for example, h(k) = 2, h(s) = 4, h(g) = 0
Assume you now use best-first greedy search using heuristic h (a version that
never re-explores the same state twice). Again, give all the states expanded, in
the order they are expanded, until the algorithm expands the goal node.
Finally, assume you use A* search with heuristic h, and run it until it terminates
using the conventional A* termination rule. Again, give all the states expanded,
in the order they are expanded. (Note that depending on the method that A*
uses to break ties, more than one correct answer is possible).
                                                                           Slide 24




                                                                                      12
Another Example Question
Consider the use of the A* algorithm on a search graph with cycles,
and assume that this graph does not have negative-length edges.
Suppose you are explaining this algorithm to Pat, who is not familiar
with AI. After your elaborated explanation of how A* handles cycles,
Pat is convinced that A* does a lot of unnecessary work to guarantee
that it works properly (i.e. finds the optimal solution) in graphs
containing cycles. Pat suggests the following modification to improve
the efficiency of the algorithm:
    Since the graph has cycles, you may detect new cycles from time to time
    when expanding a node. For example, if you expand nodes A, B, and C
    shown on figure (a) on the next slide, then after expanding C and noticing
    that A is also a successor of C, you will detect the cycle A-B-C-A. Every
    time you notice a cycle, you may remove the last edge of this cycle from
    the search graph. For example, after expanding C, you can remove the
    edge C-A (see figure (b) on next slide). Then, if A* visits node C again in
    the process of further search, it will not need to traverse this useless edge
    the second time.                                      continued next slide


                                                                           Slide 25




  more Another Example Question
Does this modified version of A* always find the optimal path to a
solution? Why or why not?

                 Start                                     Start


           A                 …                        A                …


           B                                          B
                         …                                         …

           C                                          C


           …                                         …
  (a) Detecting a Cycle                  (b) Removing the detected cycle

                                                                           Slide 26




                                                                                      13

Más contenido relacionado

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Último (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destacado (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Astar08

  • 1. A* Heuristic Search Andrew W. Moore Professor School of Computer Science Carnegie Mellon University www.cs.cmu.edu/~awm awm@cs.cmu.edu 412-268-7599 Note to other teachers and users of these slides. Andrew would be delighted if you found this source material useful in giving your own lectures. Feel free to use these slides verbatim, or to modify them to fit your own needs. PowerPoint originals are available. If you make use of a significant portion of these slides in your own lecture, please include this message, or the following link to the source repository of Slide 1 Andrew’s tutorials: http://www.cs.cmu.edu/~awm/tutorials . Comments and corrections gratefully received. Overview • The inadequacies of “Best First Greedy” heuristic search. • Good trick: take account of your cost of getting to the current state. • When should the search stop? • Admissible heuristics • A* search is complete • A* search will always terminate • A*’s dark secret • Saving masses of memory with IDA* (Iterative Deepening A*) Slide 2 1
  • 2. Let’s Make “Best first Greedy” Look Stupid! 4 2 1 1 2 S A B C G h=4 h=3 h=2 h=1 h=0 • Best –first greedy is clearly not guaranteed to find optimal • Obvious question: What can we do to avoid the stupid mistake? Slide 3 A* - The Basic Idea • Best-first greedy: When you expand a node n, take each successor n' and place it on PriQueue with priority h(n') • A*: When you expand a node n, take each successor n' and place it on PriQueue with priority (Cost of getting to n') + h(n') (1) Let g(n) = Cost of getting to n (2) and then define… f(n) = g(n) + h(n) (3) Slide 4 2
  • 3. A* Looking Non-Stupid 4 2 1 1 2 S A B C G h=4 h=3 h=2 h=1 h=0 Slide 5 When should A* terminate? Idea: As soon as it generates a goal state? Look at this example: 1 1 S h=3 B 1 h=7 h=8 A h=2 C 7 D 1 h=1 7 G h=0 Slide 6 3
  • 4. Correct A* termination rule: A* Terminates Only When a Goal State Is Popped from the Priority Queue 1 1 S h=3 B 1 h=7 h=8 A h=2 C 7 D 1 h=1 7 G h=0 Slide 7 A* revisiting states Another question: What if A* revisits a state that was already expanded, and discovers a shorter path? 1 1 S h=3 B 1 h=7 h=8 A C h=2 1/2 D 1 h=1 In this example a state that had been expanded gets 7 re-expanded. How and G why? Slide 8 4
  • 5. A* revisiting states What if A* visits a state that is already on the queue? h=8 1 1 S h=3 B 1 h=7 A C h=8 1/2 D 1 h=1 In this example a state that had been on the queue and was note that this h G 7 value has changed waiting for expansion had its from previous priority bumped up. How and page. why? Slide 9 f cost o Remind The A* Algorithm g(n) is n er: heuristic h(n) is a inder: wn path to Rem t kno e s cost to a stimate of shorte goal fro mn • Priority queue PQ begins empty. • V (= set of previously visited (state,f,backpointer)-triples) begins empty. • Put S into PQ and V with priority f(s) = g(s) + h(s) • Is PQ empty? = h(s) because Yes? Sadly admit there’s no solution g(start) = 0 No? Remove node with lowest f(n) from queue. Call it n. If n is a goal, stop and report success. “expand” n : For each n' in successors(n)…. use sneaky trick to compute g(n) • Let f’ = g(n') + h(n') = g(n) + cost(n,n') + h(n') • If n' not seen before, or n' previously expanded with f(n')>f’, or n' currently in PQ with f(n')>f’ • Then Place/promote n' on priority queue with priority f’ and update V to include (state=n', f ’, BackPtr=n). • Else Ignore n' Slide 10 5
  • 6. Is A* Guaranteed to Find the Optimal Path? 1 A 1 h=6 h=0 S h=7 G 3 Nope. And this example shows why not. Slide 11 Admissible Heuristics • Write h*(n) = the true minimal cost to goal from n. • A heuristic h is admissible if h(n) <= h*(n) for all states n. • An admissible heuristic is guaranteed never to overestimate cost to goal. • An admissible heuristic is optimistic. Slide 12 6
  • 7. 8-Puzzle Example Example 1 5 Goal 1 2 3 State State 2 6 3 4 5 6 7 4 8 7 8 Which of the following are admissible heuristics? • h(n) = Number of tiles in wrong position in state n • h(n) = 0 • h(n) = min (2, h*[n]) • h(n) = Sum of Manhattan • h(n) = h*(n) distances between each tile and • h(n) = max (2, h*[n]) its goal location • h(n) = 1 Slide 13 A* with Admissible Heuristic Guarantees Optimal Path • Simple proof • Your lecturer will attempt to give it from memory. • He might even get it right. But don’t hold your breath. Slide 14 7
  • 8. Is A* Guaranteed to i.e. is it Terminate? complete? • There are finitely many acyclic paths in the search tree. • A* only ever considers acyclic paths. • On each iteration of A* a new acyclic path is generated because: – When a node is added the first time, a new path exists. – When a node is “promoted”, a new path to that node exists. It must be new because it’s shorter. • So the very most work it could do is to look at every acyclic path in the graph. • So, it terminates. Slide 15 Comparing Iterative Deepening with A* From Russell and Norvig, Page 107, Fig 4.8 For 8-puzzle, average number of states expanded over 100 randomly chosen problems in which optimal path is length… …4 steps …8 steps …12 steps Iterative Deepening (see 112 6,300 3.6 x 106 previous slides) A* search using “number of 13 39 227 misplaced tiles” as the heuristic A* using “Sum of Manhattan 12 25 73 Slide 16 distances” as the heuristic 8
  • 9. Indeed there are only a couple Comparing Iterative Deepening with A* Andrew’s editorial co mments even “number of misp lacedhundred thousand states for the entire 1. At first sight might look like state)=0 would eight puzzle istic. But and ly h( From Russell probabNorvig, Page 107, Fig 4.8 tiles” is a great heur the difference is better than ID, so also do much much blem of expanding th e same mainly to do with ID’s big pro c. t the use of a heuristi state many times, no panded” does notof states Average number “number of states ex 2. Judging solely by expanded and 100 randomly tables over of maintaining hash account for overhead clear here that this chosen problem in which optimal , though it’s pretty priority queue for A* ange the results. path is length… won’t dramatically ch …4 steps …8 steps …12 steps Iterative Deepening (see 112 6,300 3.6 x 106 previous slides) A* search using “number of 13 39 227 misplaced tiles” as the heuristic A* using “Sum of Manhattan 12 25 73 Slide 17 distances” as the heuristic A* : The Dark Side • A* can use lots of memory. In principle: O(number of states) • For really big search spaces, A* will run out of memory. Slide 18 9
  • 10. IDA* : Memory Bounded Search • Iterative deepening A*. Actually, pretty different from A*. Assume costs integer. 1. Do loop-avoiding DFS, not expanding any node with f(n) > 0. Did we find a goal? If so, stop. 2. Do loop-avoiding DFS, not expanding any node with f(n) > 1. Did we find a goal? If so, stop. 3. Do loop-avoiding DFS, not expanding any node with f(n) > 2. Did we find a goal? If so, stop. 4. Do loop-avoiding DFS, not expanding any node with f(n) > 3. Did we find a goal? If so, stop. …keep doing this, increasing the f(n) threshold by 1 each time, until we stop. • This is Complete Guaranteed to find optimal More costly than A* in general. Slide 19 What You Should Know • Thoroughly understand A*. • Be able to trace simple examples of A* execution. • Understand “admissibility” of heuristics. Proof of completeness, guaranteed optimality of path. • Be able to criticize best first search. References: Nils Nilsson. Problem Solving Methods in Artificial Intelligence. McGraw Hill (1971) E&S-BK 501-5353 N71p. Judea Pearl. Heuristics: Intelligent Search Strategies for Computer Problem Solving. Addison Wesley (1984) E&S-BK 501-535 P35h. Chapters 3 & 4 of Stuart Russell and Peter Norvig. Artificial Intelligence: A Modern Approach. Slide 20 10
  • 11. Proof: A* with Admissible Heuristic Guarantees Optimal Path • Suppose it finds a suboptimal path, ending in goal state G1 where f(G1) > f* where f* = h* (start) = cost of optimal path. • There must exist a node n which is Unexpanded The path from start to n (stored in the BackPointers(n) values) is the start of a true optimal path Why must such a node • f(n) >= f(G1) (else search wouldn’t have ended) exist? Consider any optimal path • Also f(n) = g(n) + h(n) because it’s on optimal path s,n1,n2…goal. If all along = g*(n) + h(n) it were expanded, the goal <= g*(n) + h*(n) By the would’ve been reached admissibility along the shortest path. = f* Because n is on assumption the optimal path So f* >= f(n) >= f(G1) contradicting top of slide Slide 21 Exercise Part 1 In the following maze the successors of a cell include any cell directly to the east, south, west or north of the current cell except that no transition may pass through the central barrier. for example successors(m) = { d , n , g }. a b c d e f s h k m n p q r t g The search problem is to find a path from s to g. We are going to examine the order in which cells are expanded by various search algorithms. for example, one possible expansion order that breadth first search might use is: shfkpcqarbtdg There are other possible orders depending on which of two equal-distance- from-start states happen to be expanded first. For example s f h p k c q r a t b g is another possible answer. continued-> Slide 22 11
  • 12. Exercise Part 1 continued a b c d e f s h k m n p q r t g Assume you run depth-first-search until it expands the goal node. Assume that you always try to expand East first, then South, then West, then North. Assume your version of depth first search avoids loops: it never expands a state on the current path. What is the order of state expansion? Slide 23 Exercise Part 2 a b c d e f s h k m n p q r t g Next, you decide to use a Manhattan Distance Metric heuristic function h(state) = shortest number of steps from state to g if there were no barriers So, for example, h(k) = 2, h(s) = 4, h(g) = 0 Assume you now use best-first greedy search using heuristic h (a version that never re-explores the same state twice). Again, give all the states expanded, in the order they are expanded, until the algorithm expands the goal node. Finally, assume you use A* search with heuristic h, and run it until it terminates using the conventional A* termination rule. Again, give all the states expanded, in the order they are expanded. (Note that depending on the method that A* uses to break ties, more than one correct answer is possible). Slide 24 12
  • 13. Another Example Question Consider the use of the A* algorithm on a search graph with cycles, and assume that this graph does not have negative-length edges. Suppose you are explaining this algorithm to Pat, who is not familiar with AI. After your elaborated explanation of how A* handles cycles, Pat is convinced that A* does a lot of unnecessary work to guarantee that it works properly (i.e. finds the optimal solution) in graphs containing cycles. Pat suggests the following modification to improve the efficiency of the algorithm: Since the graph has cycles, you may detect new cycles from time to time when expanding a node. For example, if you expand nodes A, B, and C shown on figure (a) on the next slide, then after expanding C and noticing that A is also a successor of C, you will detect the cycle A-B-C-A. Every time you notice a cycle, you may remove the last edge of this cycle from the search graph. For example, after expanding C, you can remove the edge C-A (see figure (b) on next slide). Then, if A* visits node C again in the process of further search, it will not need to traverse this useless edge the second time. continued next slide Slide 25 more Another Example Question Does this modified version of A* always find the optimal path to a solution? Why or why not? Start Start A … A … B B … … C C … … (a) Detecting a Cycle (b) Removing the detected cycle Slide 26 13