reminder cs 188 artificial intelligence
play

Reminder CS 188: Artificial Intelligence Only a very small fraction - PDF document

Reminder CS 188: Artificial Intelligence Only a very small fraction of AI is about making computers play games intelligently Recall: computer vision, natural language, robotics, machine learning, computational Lectures 2 and 3:


  1. Reminder CS 188: Artificial Intelligence § Only a very small fraction of AI is about making computers play games intelligently § Recall: computer vision, natural language, robotics, machine learning, computational Lectures 2 and 3: Search biology, etc. § That being said: games tend to provide relatively simple example settings which are great to illustrate concepts and learn about algorithms Pieter Abbeel – UC Berkeley which underlie many areas of AI Many slides from Dan Klein A reflex agent for pacman Reflex Agent § Choose action based on 4 actions: move North, East, current percept (and South or West maybe memory) § May have memory or a model of the world ’ s current state § Do not consider the Reflex agent future consequences of § While(food left) their actions § Sort the possible directions to move according § Act on how the world IS to the amount of food in each direction § Go in the direction with the largest amount of § Can a reflex agent be food rational? A reflex agent for pacman (2) A reflex agent for pacman (3) Reflex agent Reflex agent § While(food left) § While(food left) § Sort the possible directions to move according to the § Sort the possible directions to move according amount of food in each direction to the amount of food in each direction § Go in the direction with the largest amount of food § Go in the direction with the largest amount of § But, if other options are available, exclude the direction we food just came from 1

  2. A reflex agent for pacman (4) A reflex agent for pacman (5) Reflex agent Reflex agent § While(food left) § While(food left) § If can keep going in the current direction, do so § If can keep going in the current direction, do so § Otherwise: § Otherwise: § Sort directions according to the amount of food § Sort directions according to the amount of food § Go in the direction with the largest amount of food § Go in the direction with the largest amount of food § But, if other options are available, exclude the direction we just § But, if other options are available, exclude the direction we just came from came from Search Problems Reflex Agent Goal-based Agents § A search problem consists of: § Choose action based on § Plan ahead current percept (and § Ask “ what if ” maybe memory) § A state space § Decisions based on § May have memory or a (hypothesized) model of the world ’ s consequences of current state actions “ N ” , § A successor function 1.0 § Do not consider the future § Must have a model of consequences of their how the world evolves actions in response to actions “ E ” , 1.0 § A start state and a goal test § Act on how the world IS § Act on how the world WOULD BE § A solution is a sequence of actions (a plan) § Can a reflex agent be which transforms the start state to a goal state rational? Example: Romania What ’ s in a State Space? § State space: The world state specifies every § Cities last detail of the § Successor environment function: § Go to adj city with cost = dist A search state keeps only the details needed (abstraction) § Start state: § Problem: Pathing § Problem: Eat-All-Dots § Arad § States: (x,y) location § States: {(x,y), dot booleans} § Goal test: § Actions: NSEW § Actions: NSEW § Is state == § Successor: update location § Successor: update location Bucharest? only and possibly a dot boolean § Goal test: is (x,y)=END § Goal test: dots all false § Solution? 2

  3. State Space Graphs State Space Sizes? § State space graph: A § Search Problem: mathematical G a Eat all of the food representation of a c b § Pacman positions: search problem 10 x 12 = 120 e § For every search problem, d f § Food count: 30 there ’ s a corresponding S h state space graph § Ghost positions: 12 § The successor function is p r q § Pacman facing: represented by arcs up, down, left, right Ridiculously tiny state space § We can rarely build this graph for a tiny search problem graph in memory (so we don ’ t) Search Trees Another Search Tree “ N ” , 1.0 “ E ” , 1.0 § A search tree: § This is a “ what if ” tree of plans and outcomes § Search: § Start state at the root node § Expand out possible plans § Children correspond to successors § Maintain a fringe of unexpanded plans § Nodes contain states, correspond to PLANS to those states § For most problems, we can never actually build the whole tree § Try to expand as few tree nodes as possible Example: Tree Search General Tree Search G a c b e d f S h p r q § Important ideas: § Fringe Detailed pseudocode § Expansion is in the book! § Exploration strategy § Main question: which fringe nodes to explore? 3

  4. State Graphs vs. Search Trees Review: Depth First (Tree) Search G a a Strategy: expand G a Each NODE in in the c c b b deepest node first c search tree is an b e e d d entire PATH in the Implementation: f f e d S f problem graph. h h Fringe is a LIFO S h stack p p r r q q p r q S S e p d e p d q e h r We construct both b c q b c e h r on demand – and we construct as a a h r p q f h r p q f a a little as possible. q c p q f G q c p q f G a q c a G q c G a a Search Algorithm Properties Review: Breadth First (Tree) Search G a § Complete? Guaranteed to find a solution if one exists? Strategy: expand c b shallowest node first § Optimal? Guaranteed to find the least cost path? e d Implementation: f § Time complexity? S Fringe is a FIFO h § Space complexity? queue p r q Variables: S n Number of states in the problem e p d Search b The average branching factor B q b c e h r Tiers (the average number of successors) a a h r p q f C* Cost of least cost solution q c p q f G Depth of the shallowest solution s a q c G m Max depth of the search tree a DFS DFS § With cycle checking, DFS is complete.* Algorithm Complete Optimal Time Space Depth First DFS N N O(B LMAX ) O(LMAX) N N Infinite Infinite 1 node Search b … b nodes b 2 nodes b m tiers START a b m nodes GOAL Algorithm Complete Optimal Time Space § Infinite paths make DFS incomplete … w/ Path DFS Y N O( b m ) O( bm ) Checking § How can we fix this? § When is DFS optimal? * Or graph search – next lecture. 4

  5. BFS Comparisons Algorithm Complete Optimal Time Space DFS w/ Path Y N O( b m ) O( bm ) Checking § When will BFS outperform DFS? BFS Y N* O( b s+1 ) O( b s+1 ) 1 node b b nodes … s tiers § When will DFS outperform BFS? b 2 nodes b s nodes b m nodes § When is BFS optimal? Iterative Deepening Costs on Actions Iterative deepening uses DFS as a subroutine: b GOAL a … 2 1. Do a DFS which only searches for paths of 2 length 1 or less. c b 3 2. If “ 1 ” failed, do a DFS which only searches paths 2 1 8 of length 2 or less. 2 e 3. If “ 2 ” failed, do a DFS which only searches paths 3 d of length 3 or less. f 9 8 2 … .and so on. START h 4 1 1 4 p r Algorithm Complete Optimal Time Space 15 q DFS w/ Path Y N O( b m ) O( bm ) Checking BFS Notice that BFS finds the shortest path in terms of number of Y N* O( b s+1 ) O( b s+1 ) transitions. It does not find the least-cost path. ID Y N* O( b s+1 ) O( bs ) We will quickly cover an algorithm which does find the least-cost path. Uniform Cost (Tree) Search Priority Queue Refresher 2 G a c b 8 Expand cheapest node first: 1 § A priority queue is a data structure in which you can insert and 2 2 e 3 retrieve (key, value) pairs with the following operations: d Fringe is a priority queue f 9 8 1 S h 1 1 p r pq.push(key, value) inserts (key, value) into the queue. q 15 pq.pop() returns the key with the lowest value, and S 0 removes it from the queue. e 9 p 1 d 3 § You can decrease a key ’ s priority by pushing it again 5 17 11 q 16 b 4 c e h r 11 § Unlike a regular queue, insertions aren ’ t constant time, Cost 6 h 13 r 7 p q f a a usually O(log n ) contours 8 q c p q f G § We ’ ll need priority queues for cost-sensitive search methods a q c 11 G 10 a 5

  6. Uniform Cost (Tree) Search Uniform Cost Issues Algorithm Complete Optimal Time (in nodes) Space § Remember: explores c ≤ 1 … DFS w/ Path increasing cost contours Y N O( b m ) O( bm ) Checking c ≤ 2 BFS Y N O( b s+1 ) O( b s+1 ) c ≤ 3 § The good: UCS is UCS Y* Y O( b C*/ ε ) O( b C*/ ε ) complete and optimal! b § The bad: … * UCS can fail if § Explores options in every C*/ ε tiers actions can get “ direction ” arbitrarily cheap § No information about goal location Start Goal Uniform Cost Search Example Search Heuristics § Any estimate of how close a state is to a goal § Designed for a particular search problem § Examples: Manhattan distance, Euclidean distance 10 5 11.2 Example: Heuristic Function Best First / Greedy Search § Expand the node that seems closest … § What can go wrong? h(x) 6

Recommend


More recommend