CSE 473: Artificial Intelligence Outline
Total Page:16
File Type:pdf, Size:1020Kb
1/8/20 CSE 473: Artificial Intelligence Problem Spaces & Search Dan Weld With slides from Dan Klein, Stuart Russell, Andrew Moore, Luke Zettlemoyer, Dana Nau… 1 Outline § Search Problems § Uninformed Search Methods § Depth-First Search § Breadth-First Search § Iterative Deepening Search § Uniform-Cost Search § Heuristic Search Methods § Heuristic Generation 2 1 1/8/20 Agent vs. Environment § An agent is an entity that Agent perceives and acts. Sensors Percepts § A rational agent selects Environment actions that maximize its ? utility function. § Characteristics of the Actuators percepts, environment, and Actions action space dictate techniques for selecting rational actions. 3 Goal Based Agents § Plan ahead § Ask “What if” § Decisions based on (hypothesized) consequences of actions § Requires a model of hoW the World evolves in response to actions § Act on hoW the World WOULD BE 4 2 1/8/20 Search thru a Problem Space (aka State Space) • Input: Functions: States à States § Set of states Aka “Successor Function” § Operators [and costs] § Start state § Goal state [or test] • Output: • Path: start Þ a state satisfying goal test [May require shortest path] [Sometimes just need a state that passes test] 6 6 Example: Simplified Pac-Man § Input: § A state space § Operators § Go North “Go North” § Go East § Etc “Go East” § A start state § A goal test § Output: 7 3 1/8/20 State Space Defines a Graph State space graph: § Each node is a state a G § Each edge is an operators b c § Edges may be labeled with cost of operator e d f S h p r q In contrast to other areas of CS… We can rarely build this graph in Ridiculously tiny search graph memory (so We don’t try) for a tiny search problem … just a conceptual tool 8 State Space Sizes? § Search Problem: Eat all of the food § Pacman positions: 1010 x 12x 12 = =120 120 § Pacman facing: up, down, left, right § Food configurations: 223030 § Ghost1 positions: 12 § Ghost 2 positions: 1111 120 x 4 x 230 x 12 x 11 = 6.8 x 1013 9 4 1/8/20 Ex: Route Planning: Arad à Bucharest § Input: § Set of states Different operators may be applicable in § Operators [and costs] different states § Start state § Goal state (test) § Output: 10 Ex: Finding optimal repair sequences 11 11 5 1/8/20 Ex: HardWare Verification Prove system Will never make floating point error 12 12 Search Methods § Blind Search • Depth first search • Breadth first search • Iterative deepening search • Uniform cost search § Local Search § Informed Search § Constraint Satisfaction § Adversary Search 19 19 6 1/8/20 Search Trees “Go North” “Go East” § A search tree: § Tree’s root node corresponds to the start state § Children correspond to successors (application of operator) § Edges are labeled With actions/operators and costs § Nodes in the tree contain states, correspond to PATH to those states § For most problems, We can never actually build the Whole tree 20 Example: Tree Search State graph: a G b c e d f S h p r q What is the search tree? 21 7 1/8/20 State Graphs vs. Search Trees a G Each NODE in in the b c search tree denotes e an entire PATH d f through the state S h space graph. p r q S e p We construct both d on demand – and b c e h r q We construct as little as possible. a a h r p q f p q f q c G a q c G Why duplicate nodes? a 22 States vs. Nodes § Vertices in state space graphs are problem states § Represent an abstracted state of the World § Have successors, can be goal / non-goal, have multiple predecessors § Vertices in search trees (“Nodes”) are plans § Contain a problem state and one parent, a path length, a depth & a cost § Represent a plan (sequence of actions) Which results in the node’s state § The same problem state may be achieved by multiple search tree nodes Search Tree Nodes Problem States Parent Depth 5 Action Node Depth 6 23 8 1/8/20 Building Search Trees § Search: § Expand out possible nodes (plans) in the tree § Maintain a fringe of unexpanded nodes § Try to expand as feW nodes as possible 24 General Tree Search Detailed pseudocode is Important ideas: in the book! § Fringe (leaves of partially-expanded tree) § Expansion (adding successors of a leaf node) § Exploration strategy Which fringe node to expand next? 25 9 1/8/20 RevieW: Breadth First Search a G b c e Strategy: expand d f shallowest node first S h Implementation: p r q Fringe is a queue - FIFO 26 RevieW: Breadth First Search a G Expansion order: b c e (S,d,e,p,b,c,e,h,r,q,a,a d f ,h,r,p,q,f,p,q,f,q,c,G) S h p q r S d e p Search b c e h r q Tiers a a h r p q f p q f q c G q c G a a 27 10 1/8/20 RevieW: Depth First Search a G b c e Strategy: expand d f deepest node first S h p r Implementation: q Fringe is a stack - LIFO Wolog: assume We choose children in lexicographic order 28 RevieW: Depth First Search a G Expansion ordering: b c e (d,b,a,c,a,e,h,p,q,q,r,f,c,a,G) d f S h p r q S d e p b c e h r q a a h r p q f p q f q c G q c G a a 29 11 1/8/20 Search Algorithm Properties § Complete? Guaranteed to find a solution if one exists? § Optimal? Guaranteed to find the least cost path? § Time complexity? § Space complexity? Variables: n Number of states in the problem b The maximum branching factor B (the maximum number of successors for a state) C* Cost of least cost solution d Depth of the shalloWest solution m Max depth of the search tree 30 Depth-First Search Algorithm Complete Optimal Time Space DFS Depth First N N AX Search No ) O(LMAX) START § Infinite paths make DFS incomplete… a GOAL § HoW can We fix this? § Check neW nodes against path from S b 31 12 1/8/20 Depth-First Search W/cycle check Algorithm Complete Optimal Time Space DFS Depth First N N AX Search No ) O(LMAX) Yes if finite tree START § Infinite trees still make DFS incomplete… a GOAL § But What if space is finite? b 32 Depth-First Search W/cycle check Assume finite state space Algorithm Complete Optimal Time Space DFS Depth First N N AX m Search Yes if finite No O()b ) O(LMAX)O(b m) tree START a GOAL b = max branching factor d = depth of solution m = max depth of tree b 33 13 1/8/20 BFS Tree Search Algorithm Complete Optimal Time Space w/ Path if finite if finite DFS N unless N O(bm) O(bm) Checking finite else ∞ else ∞ BFS Y* Y* O(bd) alWays O(bd) alWays 1 node b … b nodes d tiers b2 nodes bd nodes bm nodes * Assuming finite branching factor 35 § When is BFS optimal? Memory a Limitation? § Suppose: • 4 GHz CPU • 32 GB main memory • 100 instructions / expansion • 5 bytes / node • 40 M expansions / sec • Memory filled in … 3 min 36 36 14 1/8/20 Iterative Deepening Search § DFS With limit; incrementally groW limit § Evaluation a 37 37 Iterative Deepening Search § DFS Tree Search With limit; incrementally groW limit § Evaluation a b c d 38 38 15 1/8/20 Iterative Deepening Search § DFS Tree Search With limit; incrementally groW limit § Evaluation § Complete? a b e § Time Complexity? c f d i § Space Complexity? g h j k l 39 39 Iterative Deepening Search § DFS With limit; incrementally groW limit § Evaluation § Complete? a b e Yes * § Time Complexity? d c d O(bd) § Space Complexity? O(bd) * Assuming branching factor is finite 40 Important Note: no cycle checking necessary! 40 16 1/8/20 Cost of Iterative Deepening b ratio ID to DFS 2 3 3 2 5 1.5 10 1.2 25 1.08 100 1.02 41 41 Puzzles 15 puzzle 3x3 Rubics cube 42 42 17 1/8/20 Speed Assuming 10M nodes/sec & sufficient memory BFS Iter. Deep. Nodes Time Nodes Time 8 Puzzle 105 .01 sec 105 .01 sec 2x2x2 Rubik’s 106 .2 sec 106 .2 sec 15 Puzzle 1013 6 days 1Mx 1017 20k yrs 3x3x3 Rubik’s 1019 68k yrs 8x 1020 574k yrs 24 Puzzle 1025 12B yrs 1037 1023 yrs Why the difference? Rubik has higher branch factor # of duplicates 15 puzzle has greater depth Slide adapted from Richard Korf presentation 43 43 Tree vs Graph Search In BFS, for example, We shouldn’t bother expanding the circled nodes (Why?) S d e p b c e h r q a a h r p q f p q f q c G q c G a a 44 18 1/8/20 Graph Search § Very simple fix: never expand a state type tWice 45 Some Hints § On small problems § Graph search almost alWays better than tree search § Implement your closed list as a dict or set! § On many real problems § Storage space is a huge concern § Graph search impractical 46 19 1/8/20 Search Methods § Depth first search (DFS) Blind search § Breadth first search (BFS) § Iterative deepening depth-first search (IDS) 47 47 Search Methods § Depth first search (DFS) § Breadth first search (BFS) § Iterative deepening depth-first search (IDS) § Best first search Heuristic search § Uniform cost search (UCS) § Greedy search § A* § Iterative Deepening A* (IDA*) § Beam search § Hill climbing 48 48 20 1/8/20 Blind vs Heuristic Search § Costs on Actions § Heuristic Guidance Separable Issues, but usually linked.