search’ - northeastern university · 2 search as problem solving ! need to search a space of...

64
Search Chapter 3 (acknowledgement goes to Gillian Smith(NEU) and Hwee Tou Ng’s for slides used in this lecture)

Upload: others

Post on 18-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

ì  Search  Chapter  3    (acknowledgement  goes  to  Gillian  Smith(NEU)  and  Hwee  Tou  Ng’s  for  slides  used  in  this  lecture)  

Page 2: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

2

Search as Problem Solving

ì  Need to search a space of possible solutions

ì  There are many sequences of actions, each with their own utility.

ì  We want to find, or search for, the best one.

Page 3: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Framework  for  Search  Problems  

ì  Problem  formula1on  ì  A  set  of  discrete  states  (usually  finite,  usually  huge)  ì  Start  state  ì  Subset  of  states  designated  as  goals  (usually)  ì  A  set  of  ac1ons  the  agent  can  perform  

ì  Objec1ve  ì  Find  a  sequence  of  operators  that  lead  to  the  goal  

state  

Page 4: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

4

Example: Romania

ì  On holiday in Romania; currently in Arad.

ì  Flight leaves tomorrow from Bucharest

ì  Formulate problem: ì  Goal: at a city; e.g., at Bucharest ì  states: at various cities ì  actions: choose next city

Page 5: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

5

Example: Romania

Page 6: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

6

Problem Formulation

A problem is defined as follows:

initial state e.g., “at Arad”

actions set of possible actions in current state x.

transition model Result(x,a) = state that follows from applying action

a in state x. e.g., Result(X2 (Arad), A4 (Arad Zerind)) = X3 (Zerind)

goal test, e.g., x = “at Bucharest”

path cost (additive) ì  e.g., sum of distances, number of actions executed, etc. ì  c(x,a,y) is the step cost, assumed to be ≥ 0

A solution is a sequence of actions leading from the initial state to a goal state

Page 7: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Search  Algorithm  

ì  Start  with  a  specific  state  

ì  State  space  forms  a  tree  structure  ì  Root  =  start  state  ì  Each  node  represents  a  state  ì  Ac1ons  are  branches,  children  are  all  possible  

next-­‐states  

ì  Search  involves  expanding  a  fron%er  of  poten1al  next  states  

Page 8: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

8

Tree search example

Page 9: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

9  

Implementation:  general  tree  search  

fron%er    

Fron%er)    

(fron%er)    

fron%er    

Fron%er)    

Page 10: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Kinds  of  Search  

ì  Uninformed  

ì  Informed    

ì  Op1miza1on  

ì  Adversarial  

Page 11: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Uninformed  Search  Strategies  

ì  Breadth-­‐First  Search  

ì  Depth-­‐First  Search  

ì  Limited  Depth  Search  

ì  Itera1ve  Deepening  

Page 12: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Breadth-­‐First  Search  

ì  Order  of  node  expansion?  ì  Shallowest  unexpanded  node  

A  

B  

D   E  

C  

F   G  

Fron%er  (FIFO  Queue)  

 A                

Page 13: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Breadth-­‐First  Search  

ì  Order  of  node  expansion?  ì  Shallowest  unexpanded  node  

Fron%er  (FIFO  Queue)  

 B  C                

A  

B  

D   E  

C  

F   G  

Page 14: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Breadth-­‐First  Search  ì  Order  of  node  expansion?  

ì  Shallowest  unexpanded  node   Fron%er  (FIFO  Queue)  

 C  D  E              

A  

B  

D   E  

C  

F   G  

Page 15: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Breadth-­‐First  Search  ì  Order  of  node  expansion?  

ì  Shallowest  unexpanded  node   Fron%er  (FIFO  Queue)  

 D  E  F  G              

A  

B  

D   E  

C  

F   G  

Page 16: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

16

Example BFS

Page 17: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Evaluating  a  Search  Strategy  ì  Search  strategy  is  defined  by  picking  the  order  of  node  

expansion  

ì  Evalua1on  criteria  ì  Completeness  ì  Time  complexity  ì  Space  Complexity  ì  Op1mality  

ì  Time  and  space  complexity  measured  in  ì  b  –  maximum  branching  factor  for  the  search  tree  ì  d  –  depth  of  least-­‐cost  solu1on  ì  m  –  maximum  depth  of  the  state  space  

Page 18: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Breadth-­‐First  Search  

ì  Complete?  ì  Yes!  As  long  as  b  is  finite  

ì  Op1mal?  ì  Yes  

ì  Time  cost?  ì  O(bd)  

ì  Space  cost?  ì  O(bd)  

Page 19: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Breadth-­‐First  Search  

ì  Complete?  ì  Yes!  As  long  as  b  is  finite  

ì  Op1mal?  ì  Yes!  Assuming?  

ì  Time  cost?  ì  O(bd)  

ì  Space  cost?  ì  O(bd)  

Suppose  b=10,  a  node  uses  1000  bytes,    1m  nodes/sec  can  be  generated    Depth  10:  ~3  hours,  ~10  terabytes  Depth  12:  ~13  days,  ~1  petabyte  Depth  14:  ~3.5  years,  ~99  petabytes  

Page 20: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Depth-­‐First  Search  

ì  Order  of  node  expansion?  ì  Deepest  unexpanded  node  

A  

B  

D   E  

C  

F   G  

Fron%er  (LIFO  Queue)  

 A                

Page 21: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Depth-­‐First  Search  

A  

B  

D   E  

C  

F   G  

Fron%er  (LIFO  Queue)  

 C  B          

Page 22: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Depth-­‐First  Search  

A  

B  

D   E  

C  

F   G  

Fron%er  (LIFO  Queue)  

 C  E  D        

Page 23: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Depth-­‐First  Search  

A  

B  

D   E  

C  

F   G  

Fron%er  (LIFO  Queue)  

 C  E          

Page 24: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Depth-­‐First  Search  

A  

B  

E  

C  

F   G  

Fron%er  (LIFO  Queue)  

 C            

Page 25: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Depth-­‐First  Search  

A  

C  

F   G  

Fron%er  (LIFO  Queue)  

 G  F          

Page 26: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Depth-­‐First  Search  

A  

C  

F   G  

Fron%er  (LIFO  Queue)  

 G            

Page 27: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Properties of depth-first search

ì  Complete? No: fails in infinite-depth spaces

Can modify to avoid repeated states along path

ì  Time? O(bm) with m=maximum depth

ì  terrible if m is much larger than d ì  but if solutions are dense, may be much faster than breadth-first

ì  Space? O(bm), i.e., linear space! (we only need to

remember a single path + expanded unexplored nodes)

ì  Optimal? No (It may find a non-optimal goal first)

Page 28: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Depth-­‐Limited  Search  

ì  Depth  first  search,  but  don’t  go  past  a  pre-­‐set  limit  (L)  while  searching  

A  

B  

D   E  

C  

F   G  

H   I   J   K   L   M N O

L  

Page 29: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Limited  Depth  Search  

ì  Combines  benefits  of  depth-­‐  and  breadth-­‐first  

ì  Number  of  nodes  generated:  ì  (d+1)b0  +  (d)b1  +  (d-­‐1)b2  +  …  +  (2)bd-­‐1  +  (1)bd  =  O(bd)  

Page 30: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

30

Iterative deepening search L=0

Page 31: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

31

Iterative deepening search L=1

Page 32: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

32

Iterative deepening search L=2

Page 33: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

33

Iterative Deepening Search L=3

Page 34: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

34

Iterative deepening search

ì  Complete? Yes

ì  Time? O(bd)

ì  Space? O(bd)

ì  Optimal? Yes, if step cost = 1 or increasing function of depth.

Page 35: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Iterative  Deepening  Search  

ì  Combines  benefits  of  depth-­‐  and  breadth-­‐first  

ì  Number  of  nodes  generated:  ì  (d+1)b0  +  (d)b1  +  (d-­‐1)b2  +  …  +  (2)bd-­‐1  +  (1)bd  =  O(bd)  

ì  Spa1al  complexity:  O(bd)  

Page 36: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

36

Summary of algorithms

preferred uninformed search strategy

Third edition has O(bd)

Page 37: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

ì  Classwork  

Page 38: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

38

Example: 8-Queens

ì  states? -any arrangement of n<=8 queens -or arrangements of n<=8 queens in leftmost n columns, 1 per column, such that no queen attacks any other. ì  initial state? no queens on the board ì  actions? -add queen to any empty square -or add queen to leftmost empty square such

that it is not attacked by other queens. ì  goal test? 8 queens on the board, none attacked. ì  path cost? 1 per move

Page 39: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Environment types ì  Fully observable (vs. partially observable): An agent's

sensors give it access to the complete state of the environment at each point in time.

ì  Deterministic (vs. stochastic): The next state of the environment is completely determined by the current state and the action executed by the agent. (If the environment is deterministic except for the actions of other agents, then the environment is strategic)

ì  Episodic (vs. sequential): An agent’s action is divided into atomic episodes. Decisions do not depend on previous decisions/actions.

Page 40: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Environment types

ì  Static (vs. dynamic): The environment is unchanged while an agent is deliberating. (The environment is semidynamic if the environment itself does not change with the passage of time but the agent's performance score does)

ì  Discrete (vs. continuous): A limited number of distinct, clearly defined percepts and actions.

ì  Single agent (vs. multi-agent): An agent operating by itself in an environment. Does the other agent interfere with my performance measure?

Page 41: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

BFS,  DFS,  IDFS,  LDFS  

ì  What  type  of  environment/problem  space  would  these  algorithms  be  op1mal  for?    

Page 42: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Quizzes  and  Classwork  

ì  “What  type  of  agent?”  ì  An  intelligent  agent  

ì  “Can  you  formulate  a  poker  agent  in  terms  of  a  search  problem?”  ì  Sorry  I  cannot    

ì  Show  the  state  space  ì  O(bd)  

Page 43: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

ì  informed  Search  

Page 44: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Informed  Search  

ì  Use  problem-­‐specific  knowledge  beyond  the  problem  defini1on  to  find  solu1ons  more  efficiently  

ì  Heuris%c:  which  node  should  be  expanded  next?  

Page 45: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Heuristic  Search  

ì  Use  an  evalua1on  func1on  f(n)  for  each  node  ì  Es1mate  of  “desirability”  ì  Includes  a  heuris1c  func1on,  h(n)  

ì  Expand  the  most  desirable  unexpanded  node  

Page 46: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Greedy  best-­‐first  search  

ì  Evalua1on  func1on  f(n)  =  h(n)  (heuris1c)  =  es1mate  of  cost  from  n  to  goal  

 

ì  e.g.,  hSLD(n)  =  straight-­‐line  distance  from  n  to  Bucharest    

ì  Greedy  best-­‐first  search  expands  the  node  that  appears  to  be  closest  to  goal  

 

Page 47: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Example:  Heuristic  for  Path-­‐Finding  

Page 48: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Greedy  best-­‐first  search  example  

Page 49: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Greedy  best-­‐first  search  example  

Page 50: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Greedy  best-­‐first  search  example  

Page 51: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Greedy  best-­‐first  search  example  

Page 52: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Properties  of  greedy  best-­‐first  search  

ì  Complete?  No  –  can  get  stuck  in  loops,  e.g.,  Iasi  à  Neamt  à  Iasi  à  Neamt  à    

 

ì  Time?  O(bm),  but  a  good  heuris1c  can  give  drama1c  improvement    

ì  Space?  O(bm)  -­‐-­‐  keeps  all  nodes  in  memory    

ì  Op1mal?  No    

Page 53: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  Search  

ì  Avoid  expanding  paths  that  are  already  expensive  

ì  Evalua1on  func1on:  f(n)  =  g(n)  +  h(n)  ì  g(n)  =  cost  of  path  so  far  ì  h(n)  =  es1mated  cost  from  n  to  goal  ì  f(n)  =  es1mated  total  cost  of  path  through  n  to  goal  

Page 54: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  Search  Example:  Arad  to  Bucharest  

Page 55: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  Search  Example:  Arad  to  Bucharest  

Page 56: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  Search  Example:  Arad  to  Bucharest  

Page 57: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  Search  Example:  Arad  to  Bucharest  

Page 58: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  Search  Example:  Arad  to  Bucharest  

Page 59: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  Search  Example:  Arad  to  Bucharest  

Page 60: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  Search  

ì  Complete?  ì  Yes  

ì  Op1mal?  ì  Yes!  

ì  Time?  ì  Exponen1al  

ì  Space?  ì  Keeps  all  nodes  in  memory  

Page 61: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Admissible  Heuristics  

ì  A  heuris1c  is  admissible  if,  for  every  node  n,  h(n)  ≤  h*(n)  ì  h*(n):  true  cost  to  reach  the  goal  from  state  n  

ì  Example:  path-­‐finding  heuris1c  never  overes1mates  actual  road  distance  

ì  Generate  from  a  relaxed  problem    ì  Fewer  restric1ons  than  original  problem  

Page 62: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

ì  Classwork  

Page 63: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

A*  and  Games  Given  A*  algorithm,  define  h(n)  and  f(n),  environment,  trace  the  algorithm  

Resource:  hop://unitygems.com/astar-­‐1-­‐journeys-­‐start-­‐single-­‐step/,  hop://en.wikipedia.org/wiki/A*_search_algorithm  

 

Page 64: Search’ - Northeastern University · 2 Search as Problem Solving ! Need to search a space of possible solutions ! There are many sequences of actions, each with their own utility

Video  –  Summary  and  outlook  

ì  hop://videolectures.net/aaai2010_thayer_bis/