search’ - northeastern university · 2 search as problem solving ! need to search a space of...
TRANSCRIPT
ì Search Chapter 3 (acknowledgement goes to Gillian Smith(NEU) and Hwee Tou Ng’s for slides used in this lecture)
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.
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
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
5
Example: Romania
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
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
8
Tree search example
9
Implementation: general tree search
fron%er
Fron%er)
(fron%er)
fron%er
Fron%er)
Kinds of Search
ì Uninformed
ì Informed
ì Op1miza1on
ì Adversarial
Uninformed Search Strategies
ì Breadth-‐First Search
ì Depth-‐First Search
ì Limited Depth Search
ì Itera1ve Deepening
Breadth-‐First Search
ì Order of node expansion? ì Shallowest unexpanded node
A
B
D E
C
F G
Fron%er (FIFO Queue)
A
Breadth-‐First Search
ì Order of node expansion? ì Shallowest unexpanded node
Fron%er (FIFO Queue)
B C
A
B
D E
C
F G
Breadth-‐First Search ì Order of node expansion?
ì Shallowest unexpanded node Fron%er (FIFO Queue)
C D E
A
B
D E
C
F G
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
16
Example BFS
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
Breadth-‐First Search
ì Complete? ì Yes! As long as b is finite
ì Op1mal? ì Yes
ì Time cost? ì O(bd)
ì Space cost? ì O(bd)
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
Depth-‐First Search
ì Order of node expansion? ì Deepest unexpanded node
A
B
D E
C
F G
Fron%er (LIFO Queue)
A
Depth-‐First Search
A
B
D E
C
F G
Fron%er (LIFO Queue)
C B
Depth-‐First Search
A
B
D E
C
F G
Fron%er (LIFO Queue)
C E D
Depth-‐First Search
A
B
D E
C
F G
Fron%er (LIFO Queue)
C E
Depth-‐First Search
A
B
E
C
F G
Fron%er (LIFO Queue)
C
Depth-‐First Search
A
C
F G
Fron%er (LIFO Queue)
G F
Depth-‐First Search
A
C
F G
Fron%er (LIFO Queue)
G
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)
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
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)
30
Iterative deepening search L=0
31
Iterative deepening search L=1
32
Iterative deepening search L=2
33
Iterative Deepening Search L=3
34
Iterative deepening search
ì Complete? Yes
ì Time? O(bd)
ì Space? O(bd)
ì Optimal? Yes, if step cost = 1 or increasing function of depth.
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)
36
Summary of algorithms
preferred uninformed search strategy
Third edition has O(bd)
ì Classwork
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
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.
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?
BFS, DFS, IDFS, LDFS
ì What type of environment/problem space would these algorithms be op1mal for?
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)
ì informed Search
Informed Search
ì Use problem-‐specific knowledge beyond the problem defini1on to find solu1ons more efficiently
ì Heuris%c: which node should be expanded next?
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
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
Example: Heuristic for Path-‐Finding
Greedy best-‐first search example
Greedy best-‐first search example
Greedy best-‐first search example
Greedy best-‐first search example
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
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
A* Search Example: Arad to Bucharest
A* Search Example: Arad to Bucharest
A* Search Example: Arad to Bucharest
A* Search Example: Arad to Bucharest
A* Search Example: Arad to Bucharest
A* Search Example: Arad to Bucharest
A* Search
ì Complete? ì Yes
ì Op1mal? ì Yes!
ì Time? ì Exponen1al
ì Space? ì Keeps all nodes in memory
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
ì Classwork
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
Video – Summary and outlook
ì hop://videolectures.net/aaai2010_thayer_bis/