SlideShare a Scribd company logo
1 of 37
CS 767: Advanced Topics in AI
Search
Instructor: Dr. Muhammad Aqib
University Institute of Information Technology
PMAS-Arid Agriculture University Rawalpindi
(slides courtesy Dan Klein, Pieter Abbeel, University of California, Berkeley)
Informed Search
o Uninformed Search
o DFS
o BFS
o UCS
▪ Informed Search
▪ Heuristics
▪ Greedy Search
▪ A* Search
▪ Graph Search
2
Search Heuristics
▪ A heuristic is:
▪ A function that estimates how close a state is to a goal
▪ Designed for a particular search problem
▪ Pathing?
▪ Examples: Manhattan distance, Euclidean distance for
pathing
10
5
11.
2
3
Example: Heuristic Function
h(x)
4
Greedy Search
5
Greedy Search
o Expand the node that seems closest…
o Is it optimal?
o No. Resulting path to Bucharest is not the shortest!
6
Greedy Search
o Strategy: expand a node that you think is
closest to a goal state
o Heuristic: estimate of distance to nearest
goal for each state
o A common case:
o Best-first takes you straight to the (wrong)
goal
o Worst-case: like a badly-guided DFS
…
b
…
b
[Demo: contours greedy empty (L3D1)]
[Demo: contours greedy pacman small maze (L3D4)]
7
A* Search
8
A* Search
UCS Greedy
A*
9
Combining UCS and Greedy
o Uniform-cost orders by path cost, or backward cost g(n)
o Greedy orders by goal proximity, or forward cost h(n)
o A* Search orders by the sum: f(n) = g(n) + h(n)
S a d
b
G
h=5
h=6
h=2
1
8
1
1
2
h=6
h=0
c
h=7
3
e h=1
1
Example: Teg
S
a
b
c
e
d
d
G
G
g = 0
h=6
g = 1
h=5
g = 2
h=6
g = 3
h=7
g = 4
h=2
g = 6
h=0
g = 9
h=1
g = 10
h=2
g = 12
h=0
10
When should A* terminate?
o Should we stop when we enqueue a goal?
o No: only stop when we dequeue a goal
S
B
A
G
2
3
2
2
h = 1
h = 2
h = 0
h = 3
S 0 3 3
g h +
S->A 2 2 4
S->B 2 1 3
S->B->G 5 0 5
S->A->G 4 0 4
11
Is A* Optimal?
o What went wrong?
o Actual bad goal cost < estimated good goal cost
o We need estimates to be less than actual costs!
A
G
S
1 3
h = 6
h = 0
5
h = 7
g h +
S 0 7 7
S->A 1 6 7
S->G 5 0 5
12
Admissible Heuristics
Idea: Admissibility
Inadmissible (pessimistic) heuristics
break optimality by trapping
good plans on the fringe
Admissible (optimistic) heuristics
slow down bad plans but
never outweigh true costs
Admissible Heuristics
o A heuristic h is admissible (optimistic) if:
where is the true cost to a nearest goal
o Examples:
o Coming up with admissible heuristics is most of what’s
involved in using A* in practice.
15 11.5
0.0
Optimality of A* Tree Search
Optimality of A* Tree Search
Assume:
o A is an optimal goal node
o B is a suboptimal goal node
o h is admissible
Claim:
o A will exit the fringe before B
…
Optimality of A* Tree Search: Blocking
Proof:
o Imagine B is on the fringe
o Some ancestor n of A is on the
fringe, too (maybe A!)
o Claim: n will be expanded before B
1. f(n) is less or equal to f(A)
Definition of f-cost
Admissibility of h
…
h = 0 at a goal
Optimality of A* Tree Search: Blocking
Proof:
o Imagine B is on the fringe
o Some ancestor n of A is on the
fringe, too (maybe A!)
o Claim: n will be expanded before B
1. f(n) is less or equal to f(A)
2. f(A) is less than f(B)
B is suboptimal
h = 0 at a goal
…
Optimality of A* Tree Search: Blocking
Proof:
o Imagine B is on the fringe
o Some ancestor n of A is on the
fringe, too (maybe A!)
o Claim: n will be expanded before B
1. f(n) is less or equal to f(A)
2. f(A) is less than f(B)
3. n expands before B
o All ancestors of A expand before B
o A expands before B
o A* search is optimal
…
Properties of A*
…
b
…
b
Uniform-Cost A*
UCS vs A* Contours
o Uniform-cost expands equally in
all “directions”
o A* expands mainly toward the
goal, but does hedge its bets to
ensure optimality
Start Goal
Start Goal
[Demo: contours UCS / greedy / A* empty (L3D1)]
[Demo: contours A* pacman small maze (L3D5)]
Graph Search
Tree Search: Extra Work!
o Failure to detect repeated states can cause exponentially more
work.
Search Tree
State Graph
Graph Search
o In BFS, for example, we shouldn’t bother expanding the circled nodes
(why?)
S
a
b
d p
a
c
e
p
h
f
r
q
q c G
a
q
e
p
h
f
r
q
q c G
a
Graph Search
o Idea: never expand a state twice
o How to implement:
o Tree search + set of expanded states (“closed set”)
o Expand the search tree node-by-node, but…
o Before expanding a node, check to make sure its state has
never been expanded before
o If not new, skip it, if new add to closed set
o Important: store the closed set as a set, not a list
o Can graph search wreck completeness? Why/why not?
o How about optimality?
A* Graph Search Gone Wrong?
S
A
B
C
G
1
1
1
2
3
h=2
h=1
h=4
h=1
h=0
S
(0+2)
A
(1+4)
B
(1+1)
C
(2+1)
G
(5+0)
C
(3+1)
G
(6+0)
State space
graph
Search
tree
Closed
Set:
S B C A
Consistency of Heuristics
o Main idea: estimated heuristic costs ≤ actual costs
o Admissibility: heuristic cost ≤ actual cost to goal
h(A) ≤ actual cost from A to G
o Consistency: heuristic “arc” cost ≤ actual cost for each
arc
h(A) – h(C) ≤ cost(A to C)
o Consequences of consistency:
o The f value along a path never decreases
h(A) ≤ cost(A to C) + h(C)
o A* graph search is optimal
3
A
C
G
h=4 h=1
1
h=2
Optimality of A* Search
o With a admissible heuristic, Tree A* is optimal.
o With a consistent heuristic, Graph A* is optimal.
o See slides, also video lecture from past years for details.
o With h=0, the same proof shows that UCS is optimal.
A*: Summary
A*: Summary
o A* uses both backward costs and (estimates of) forward
costs
o A* is optimal with admissible / consistent heuristics
o Heuristic design is key: often use relaxed problems
Tree Search Pseudo-Code
Graph Search Pseudo-Code
The One Queue
o All these search algorithms are
the same except for fringe
strategies
o Conceptually, all fringes are priority
queues (i.e. collections of nodes
with attached priorities)
o Practically, for DFS and BFS, you
can avoid the log(n) overhead from
an actual priority queue, by using
stacks and queues
o Can even code one implementation
that takes a variable queuing object
Search and Models
o Search operates over
models of the world
o The agent doesn’t
actually try all the plans
out in the real world!
o Planning is all “in
simulation”
o Your search is only as
good as your models…
Search Gone Wrong?
41
CS767_Lecture_03.pptx

More Related Content

Similar to CS767_Lecture_03.pptx

Artificial intelligence(06)
Artificial intelligence(06)Artificial intelligence(06)
Artificial intelligence(06)Nazir Ahmed
 
Artificial intelligence(06)
Artificial intelligence(06)Artificial intelligence(06)
Artificial intelligence(06)Nazir Ahmed
 
Jarrar: Informed Search
Jarrar: Informed Search  Jarrar: Informed Search
Jarrar: Informed Search Mustafa Jarrar
 
Informed search algorithms.pptx
Informed search algorithms.pptxInformed search algorithms.pptx
Informed search algorithms.pptxDr.Shweta
 
informed_search.pdf
informed_search.pdfinformed_search.pdf
informed_search.pdfSankarTerli
 
Lec 2 1 informed search
Lec 2 1  informed searchLec 2 1  informed search
Lec 2 1 informed searchEyob Sisay
 
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.pptmmpnair0
 
uniformed (also called blind search algo)
uniformed (also called blind search algo)uniformed (also called blind search algo)
uniformed (also called blind search algo)ssuser2a76b5
 
Outrageous Ideas for Graph Databases
Outrageous Ideas for Graph DatabasesOutrageous Ideas for Graph Databases
Outrageous Ideas for Graph DatabasesMax De Marzi
 
Pathfinding - Part 1: Α* heuristic search
Pathfinding - Part 1: Α* heuristic searchPathfinding - Part 1: Α* heuristic search
Pathfinding - Part 1: Α* heuristic searchStavros Vassos
 
Astar.ppt hjguyjgukyjgoyjgugukgulgoyulgyilglyi
Astar.ppt hjguyjgukyjgoyjgugukgulgoyulgyilglyiAstar.ppt hjguyjgukyjgoyjgugukgulgoyulgyilglyi
Astar.ppt hjguyjgukyjgoyjgugukgulgoyulgyilglyikamaleshs183
 
AI Greedy and A-STAR Search
AI Greedy and A-STAR SearchAI Greedy and A-STAR Search
AI Greedy and A-STAR SearchAndrew Ferlitsch
 

Similar to CS767_Lecture_03.pptx (20)

Artificial intelligence(06)
Artificial intelligence(06)Artificial intelligence(06)
Artificial intelligence(06)
 
Artificial intelligence(06)
Artificial intelligence(06)Artificial intelligence(06)
Artificial intelligence(06)
 
Search 2
Search 2Search 2
Search 2
 
Jarrar: Informed Search
Jarrar: Informed Search  Jarrar: Informed Search
Jarrar: Informed Search
 
Informed search algorithms.pptx
Informed search algorithms.pptxInformed search algorithms.pptx
Informed search algorithms.pptx
 
M4 heuristics
M4 heuristicsM4 heuristics
M4 heuristics
 
informed_search.pdf
informed_search.pdfinformed_search.pdf
informed_search.pdf
 
m4-heuristics.ppt
m4-heuristics.pptm4-heuristics.ppt
m4-heuristics.ppt
 
Lec 2 1 informed search
Lec 2 1  informed searchLec 2 1  informed search
Lec 2 1 informed search
 
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
2012wq171-03-UninformedSeknlk ;lm,l;mk;arch.ppt
 
uniformed (also called blind search algo)
uniformed (also called blind search algo)uniformed (also called blind search algo)
uniformed (also called blind search algo)
 
A Star Search
A Star SearchA Star Search
A Star Search
 
A Star Search
A Star SearchA Star Search
A Star Search
 
Outrageous Ideas for Graph Databases
Outrageous Ideas for Graph DatabasesOutrageous Ideas for Graph Databases
Outrageous Ideas for Graph Databases
 
Final slide4 (bsc csit) chapter 4
Final slide4 (bsc csit) chapter 4Final slide4 (bsc csit) chapter 4
Final slide4 (bsc csit) chapter 4
 
Pathfinding - Part 1: Α* heuristic search
Pathfinding - Part 1: Α* heuristic searchPathfinding - Part 1: Α* heuristic search
Pathfinding - Part 1: Α* heuristic search
 
M4 Heuristics
M4 HeuristicsM4 Heuristics
M4 Heuristics
 
Astar.ppt hjguyjgukyjgoyjgugukgulgoyulgyilglyi
Astar.ppt hjguyjgukyjgoyjgugukgulgoyulgyilglyiAstar.ppt hjguyjgukyjgoyjgugukgulgoyulgyilglyi
Astar.ppt hjguyjgukyjgoyjgugukgulgoyulgyilglyi
 
And or graph problem reduction using predicate logic
And or graph problem reduction using predicate logicAnd or graph problem reduction using predicate logic
And or graph problem reduction using predicate logic
 
AI Greedy and A-STAR Search
AI Greedy and A-STAR SearchAI Greedy and A-STAR Search
AI Greedy and A-STAR Search
 

More from ShujatHussainGadi

More from ShujatHussainGadi (7)

Decision Tree Assignment.pdf
Decision  Tree Assignment.pdfDecision  Tree Assignment.pdf
Decision Tree Assignment.pdf
 
Marakas-Ch04-Saif Week 04.ppt
Marakas-Ch04-Saif Week 04.pptMarakas-Ch04-Saif Week 04.ppt
Marakas-Ch04-Saif Week 04.ppt
 
Lec-01.ppt
Lec-01.pptLec-01.ppt
Lec-01.ppt
 
GA.pptx
GA.pptxGA.pptx
GA.pptx
 
CS767_Lecture_02.pptx
CS767_Lecture_02.pptxCS767_Lecture_02.pptx
CS767_Lecture_02.pptx
 
CS767_Lecture_04.pptx
CS767_Lecture_04.pptxCS767_Lecture_04.pptx
CS767_Lecture_04.pptx
 
CS767_Lecture_05.pptx
CS767_Lecture_05.pptxCS767_Lecture_05.pptx
CS767_Lecture_05.pptx
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
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
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
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
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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 ...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

CS767_Lecture_03.pptx

  • 1. CS 767: Advanced Topics in AI Search Instructor: Dr. Muhammad Aqib University Institute of Information Technology PMAS-Arid Agriculture University Rawalpindi (slides courtesy Dan Klein, Pieter Abbeel, University of California, Berkeley)
  • 2. Informed Search o Uninformed Search o DFS o BFS o UCS ▪ Informed Search ▪ Heuristics ▪ Greedy Search ▪ A* Search ▪ Graph Search 2
  • 3. Search Heuristics ▪ A heuristic is: ▪ A function that estimates how close a state is to a goal ▪ Designed for a particular search problem ▪ Pathing? ▪ Examples: Manhattan distance, Euclidean distance for pathing 10 5 11. 2 3
  • 6. Greedy Search o Expand the node that seems closest… o Is it optimal? o No. Resulting path to Bucharest is not the shortest! 6
  • 7. Greedy Search o Strategy: expand a node that you think is closest to a goal state o Heuristic: estimate of distance to nearest goal for each state o A common case: o Best-first takes you straight to the (wrong) goal o Worst-case: like a badly-guided DFS … b … b [Demo: contours greedy empty (L3D1)] [Demo: contours greedy pacman small maze (L3D4)] 7
  • 10. Combining UCS and Greedy o Uniform-cost orders by path cost, or backward cost g(n) o Greedy orders by goal proximity, or forward cost h(n) o A* Search orders by the sum: f(n) = g(n) + h(n) S a d b G h=5 h=6 h=2 1 8 1 1 2 h=6 h=0 c h=7 3 e h=1 1 Example: Teg S a b c e d d G G g = 0 h=6 g = 1 h=5 g = 2 h=6 g = 3 h=7 g = 4 h=2 g = 6 h=0 g = 9 h=1 g = 10 h=2 g = 12 h=0 10
  • 11. When should A* terminate? o Should we stop when we enqueue a goal? o No: only stop when we dequeue a goal S B A G 2 3 2 2 h = 1 h = 2 h = 0 h = 3 S 0 3 3 g h + S->A 2 2 4 S->B 2 1 3 S->B->G 5 0 5 S->A->G 4 0 4 11
  • 12. Is A* Optimal? o What went wrong? o Actual bad goal cost < estimated good goal cost o We need estimates to be less than actual costs! A G S 1 3 h = 6 h = 0 5 h = 7 g h + S 0 7 7 S->A 1 6 7 S->G 5 0 5 12
  • 14. Idea: Admissibility Inadmissible (pessimistic) heuristics break optimality by trapping good plans on the fringe Admissible (optimistic) heuristics slow down bad plans but never outweigh true costs
  • 15. Admissible Heuristics o A heuristic h is admissible (optimistic) if: where is the true cost to a nearest goal o Examples: o Coming up with admissible heuristics is most of what’s involved in using A* in practice. 15 11.5 0.0
  • 16. Optimality of A* Tree Search
  • 17. Optimality of A* Tree Search Assume: o A is an optimal goal node o B is a suboptimal goal node o h is admissible Claim: o A will exit the fringe before B …
  • 18. Optimality of A* Tree Search: Blocking Proof: o Imagine B is on the fringe o Some ancestor n of A is on the fringe, too (maybe A!) o Claim: n will be expanded before B 1. f(n) is less or equal to f(A) Definition of f-cost Admissibility of h … h = 0 at a goal
  • 19. Optimality of A* Tree Search: Blocking Proof: o Imagine B is on the fringe o Some ancestor n of A is on the fringe, too (maybe A!) o Claim: n will be expanded before B 1. f(n) is less or equal to f(A) 2. f(A) is less than f(B) B is suboptimal h = 0 at a goal …
  • 20. Optimality of A* Tree Search: Blocking Proof: o Imagine B is on the fringe o Some ancestor n of A is on the fringe, too (maybe A!) o Claim: n will be expanded before B 1. f(n) is less or equal to f(A) 2. f(A) is less than f(B) 3. n expands before B o All ancestors of A expand before B o A expands before B o A* search is optimal …
  • 22. UCS vs A* Contours o Uniform-cost expands equally in all “directions” o A* expands mainly toward the goal, but does hedge its bets to ensure optimality Start Goal Start Goal [Demo: contours UCS / greedy / A* empty (L3D1)] [Demo: contours A* pacman small maze (L3D5)]
  • 24. Tree Search: Extra Work! o Failure to detect repeated states can cause exponentially more work. Search Tree State Graph
  • 25. Graph Search o In BFS, for example, we shouldn’t bother expanding the circled nodes (why?) S a b d p a c e p h f r q q c G a q e p h f r q q c G a
  • 26. Graph Search o Idea: never expand a state twice o How to implement: o Tree search + set of expanded states (“closed set”) o Expand the search tree node-by-node, but… o Before expanding a node, check to make sure its state has never been expanded before o If not new, skip it, if new add to closed set o Important: store the closed set as a set, not a list o Can graph search wreck completeness? Why/why not? o How about optimality?
  • 27. A* Graph Search Gone Wrong? S A B C G 1 1 1 2 3 h=2 h=1 h=4 h=1 h=0 S (0+2) A (1+4) B (1+1) C (2+1) G (5+0) C (3+1) G (6+0) State space graph Search tree Closed Set: S B C A
  • 28. Consistency of Heuristics o Main idea: estimated heuristic costs ≤ actual costs o Admissibility: heuristic cost ≤ actual cost to goal h(A) ≤ actual cost from A to G o Consistency: heuristic “arc” cost ≤ actual cost for each arc h(A) – h(C) ≤ cost(A to C) o Consequences of consistency: o The f value along a path never decreases h(A) ≤ cost(A to C) + h(C) o A* graph search is optimal 3 A C G h=4 h=1 1 h=2
  • 29. Optimality of A* Search o With a admissible heuristic, Tree A* is optimal. o With a consistent heuristic, Graph A* is optimal. o See slides, also video lecture from past years for details. o With h=0, the same proof shows that UCS is optimal.
  • 31. A*: Summary o A* uses both backward costs and (estimates of) forward costs o A* is optimal with admissible / consistent heuristics o Heuristic design is key: often use relaxed problems
  • 34. The One Queue o All these search algorithms are the same except for fringe strategies o Conceptually, all fringes are priority queues (i.e. collections of nodes with attached priorities) o Practically, for DFS and BFS, you can avoid the log(n) overhead from an actual priority queue, by using stacks and queues o Can even code one implementation that takes a variable queuing object
  • 35. Search and Models o Search operates over models of the world o The agent doesn’t actually try all the plans out in the real world! o Planning is all “in simulation” o Your search is only as good as your models…