Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young...

34
Informed Search UCS and Greedy A CS540 Introduction to Artificial Intelligence Lecture 18 Young Wu Based on lecture slides by Jerry Zhu, Yingyu Liang, and Charles Dyer July 26, 2021

Transcript of Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young...

Page 1: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

CS540 Introduction to Artificial IntelligenceLecture 18

Young WuBased on lecture slides by Jerry Zhu, Yingyu Liang, and Charles

Dyer

July 26, 2021

Page 2: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Uniformed vs. Informed SearchMotivation

Uninformed search means only the goal G and the successorfunctions s 1 are given.

Informed search means which non-goal states are better is alsoknown.

Page 3: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

HeuristicMotivation

The additional information is usually given as a heuristic costfrom a state s to the goal.

The cost of the path from the start to a vertex s in thefrontier is g psq.

The cost from s to the goal, h� psq, is estimated by h psq.This estimate may not be accurate.

h psq � h� psq

Page 4: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Heuristic DiagramMotivation

Page 5: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Uniform Cost SearchDescription

Expand the vertices with the lowest current path cost g psqfirst.

It is BFS with a priority queue based on g psq.

It is equivalent to BFS if c � 1 is constant on all edges.

It is also called Dijkstra’s Algorithm.

Page 6: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Uniform Cost Search Maze ExampleDefinition

Page 7: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Uniform Cost Search Simple ExampleDefinition

Page 8: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Uniform Cost SearchAlgorithm

Input: a weighted digraph pV ,E , cq, initial states I and goalstates G .

Output: a path from I to G .

EnQueue initial states into a priority queue Q. Here, Q isordered by g psq for s P Q.

Q � I

While Q is not empty and goal is not deQueued, deQueue Qand enQueue its successors.

s � Qp0q � arg minsPQ

g psq

Q � Q � s 1 psq

Page 9: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Uniform Cost Search PerformanceDiscussion

UCS is complete.

UCS is optimal with any c .

Page 10: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Best First Greedy SearchDescription

Expand the vertices with the lowest heuristic cost h psq first.

Use a priority queue based on h psq.

Page 11: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Greedy Search Maze ExampleDefinition

Page 12: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Greedy Search Simple ExampleDefinition

Page 13: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Best First Greedy SearchAlgorithm

Input: a weighted digraph pV ,E , cq, initial states I and goalstates G , and the heuristic function h psq , s P V .

Output: a path from I to G .

EnQueue initial states into a priority queue Q. Here, Q isordered by h psq for s P Q.

Q � I

While Q is not empty and goal is not deQueued, deQueue Qand enQueue its successors.

s � Qp0q � arg minsPQ

h psq

Q � Q � s 1 psq

Page 14: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Best First Greedy Search PerformanceDiscussion

Greedy is incomplete.

Greedy is not optimal.

Page 15: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A SearchDescription

Expand the vertices with the lowest total cost g psq � h psqfirst.

Use a priority queue based on g psq � h psq.

A stands for Always be optimistic?

Page 16: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Search Maze ExampleDefinition

Page 17: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Search Simple Example 1Definition

Page 18: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Search Simple Example 2Definition

Page 19: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Search Simple Example 3Definition

Page 20: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A SearchAlgorithm

Input: a weighted digraph pV ,E , cq, initial states I and goalstates G , and the heuristic function h psq , s P V .

Output: a path from I to G .

EnQueue initial states into a priority queue Q. Here, Q isordered by g psq � h psq for s P Q.

Q � I

While Q is not empty and goal is not deQueued, deQueue Qand enQueue its successors.

s � Qp0q � arg minsPQ

g psq � h psq

Q � Q � s 1 psq

Page 21: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Search PerformanceDiscussion

A is complete.

A is not optimal.

Page 22: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Star SearchDescription

A� search is A search with an admissible heuristic.

Page 23: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Admissible HeuristicDefinition

A heuristic is admissible if it never over estimates the truecost.

0 ¤ h psq ¤ h� psq

Page 24: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Admissible Heuristic 8 Puzzle ExampleDefinition

Page 25: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Dominated HeuristicDefinition

One heuristic, h1, is dominated by another, h2, if:

h1 psq ¤ h2 psq ¤ h� psq , @ s P S

If h2 dominates h1, then h2 is better than h1 since A� using h1expands at least as many states (or more) than A� using h2.

If h2 dominated h1,A� with h2 is better informed than A�

with h1.

Page 26: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Non-Optimal HeuristicDefinition

If optimality is not required and a satisfying solution isacceptable, then the heuristic should be as close as possible,either under or over, to the actual cost.

This results in fewer states being expanded compared to usingpoor but admissible heuristics.

Page 27: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Admissible Heuristic 8 Puzzle ExampleQuiz

Which ones (select multiple) of the following are admissibleheuristic function for the 8 Puzzle?

A: h psq � number of tiles in the wrong position.

B: h psq � 0.

C: h psq � 1.

D: h psq � sum of Manhattan distance between each tile andits goal location.

E: h psq � sum of Euclidean distance between each tile and itsgoal location.

Page 28: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Star Search with Revisit, Part IAlgorithm

Input: a weighted digraph pV ,E , cq, initial states I and goalstates G , and the heuristic function h psq , s P V .

Output: a path with minimum cost from I to G .

EnQueue initial states into a priority queue Q. Here, Q isordered by g psq � h psq for s P Q.

Q � I

g pI q � 0

g psq � 8, for s R I

Initialize the list of visited vertices, P.

P � H

Page 29: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Star Search with Revisit, Part IIAlgorithm

While Q is not empty and goal is not deQueued, deQueue Q,put it on P and enQueue its successors to Q, and update thecost functions.

s � Qp0q � arg minsPQ

g psq � h psq

P � P � s

Q � Q � s 1 psq , update g�s 1�� min

g�s 1�, g psq � c

�s, s 1

�(

Page 30: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

A Search PerformanceDiscussion

A� is complete.

A� is optimal.

Page 31: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Iterative Deepening A Star SearchDiscussion

A� can use a lot of memory.

Do path checking without expanding any vertex withg psq � h psq ¡ 1.

Do path checking without expanding any vertex withg psq � h psq ¡ 2.

...

Do path checking without expanding any vertex withg psq � h psq ¡ d .

Page 32: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Iterative Deepening A Star Search PerformanceDiscussion

IDA� is complete.

IDA� is optimal.

IDA� is more costly than A�.

Page 33: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Beam SearchDiscussion

Version 1: Keep a priority queue with fixed size k . Only keepthe top k vertices and discard the rest.

Version 2: Only keep the vertices that are at most ε worsethan the best vertex in the queue. ε is called the beam width.

Page 34: Young Wu July 25, 2019pages.cs.wisc.edu/~yw/CS540/CS540_Lecture_18_P.pdf · 2019. 7. 25. · Young Wu Based on lecture slides by Jerry Zhu and Yingyu Liang July 25, 2019. ... The

Informed Search UCS and Greedy A

Beam Search PerformanceDiscussion

Beam is incomplete.

Beam is not optimal.