1 / 54

CS 343H: Artificial Intelligence

CS 343H: Artificial Intelligence. Week2a: Uninformed Search. Today. Agents that Plan Ahead Search Problems Uninformed Search Methods Depth-First Search Breadth-First Search Uniform-Cost Search. Agent. Sensors. Percepts. ?. Environment. Actuators. Actions. Recall: Rational Agents.

ddevore
Download Presentation

CS 343H: Artificial Intelligence

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 343H: Artificial Intelligence Week2a: Uninformed Search

  2. Today • Agents that Plan Ahead • Search Problems • Uninformed Search Methods • Depth-First Search • Breadth-First Search • Uniform-Cost Search

  3. Agent Sensors Percepts ? Environment Actuators Actions Recall: Rational Agents • An agent is an entity that perceives and acts. • A rational agentselects actions that maximize its utility function. • Characteristics of the percepts, environment, and action space dictate techniques for selecting rational actions.

  4. Reflex Agents • Reflex agents: • Choose action based on current percept (and maybe memory) • May have memory or a model of the world’s current state • Do not consider the future consequences of their actions • Consider how the world IS • Can a reflex agent be rational?

  5. Planning Agents • Plan ahead • Ask “what if” • Decisions based on (hypothesized) consequences of actions • Must have a model of how the world evolves in response to actions • Consider how the world WOULD BE

  6. Quiz: Reflex or Planning? Select which type of agent is described: • Pacman, where Pacman is programmed to move in the direction of the closest food pellet • Pacman, where Pacman is programmed to move in the direction of the closest food pellet, unless there is a ghost in that direction that is less than 3 steps away. • A navigation system that first considers all possible routes to the destination, then selects the shortest route.

  7. Search Problems • A searchproblem consists of: • A state space • A successor function (with actions, costs) • A start state and a goal test • A solution is a sequence of actions (a plan) which transforms the start state to a goal state “N”, 1.0 “E”, 1.0

  8. Example: Romania • State space: • Cities • Successor function: • Roads: Go to adj city with cost = dist • Start state: • Arad • Goal test: • Is state == Bucharest? • Solution?

  9. What’s in a State Space? • Problem 1: Pathing • States: (x,y) location • Actions: NSEW • Successor: update location only • Goal test: is (x,y)=END • Problem 2: Eat-All-Dots • States: {(x,y), dot booleans} • Actions: NSEW • Successor: update location and possibly a dot boolean • Goal test: dots all false The world state specifies every last detail of the environment A search state keeps only the details needed (abstraction)

  10. State Space Sizes? • World state: • Agent positions: 120 • Food count: 30 • Ghost positions: 12 • Agent facing: NSEW • How many • World states? 120x(230)x(122)x4 • States for pathing? 120 • States for eat-all-dots? 120x(230)

  11. G a c b e d f S h p r q State Space Graphs • State space graph: A mathematical representation of a search problem • Nodes: abstracted world configurations • Arcs: successors (action results) • Goal test is set of goal nodes (maybe only one) • In a search graph, each state occurs only once! • We can rarely build this graph in memory (so we don’t) Ridiculously tiny search graph for a tiny search problem

  12. Search Trees This is now / start • A search tree: • This is a “what if” tree of plans and outcomes • Start state at the root node • Children correspond to successors • Nodes contain states, correspond to PLANS to those states • For most problems, we can never actually build the whole tree “N”, 1.0 “E”, 1.0 Possible futures

  13. Quiz • Consider this 4-state graph: • How big is its search tree (from S)? A S G B

  14. Recall: Romania example

  15. Searching with a search tree • Search: • Expand out possible plans • Maintain a fringe of unexpanded plans • Try to expand as few tree nodes as possible

  16. General Tree Search • Important ideas: • Fringe • Expansion • Exploration strategy • Main question: which fringe nodes to explore? Detailed pseudocode is in the book!

  17. G a c b e d f S h p r q Example: Tree Search Tree Fringe (potential plans)

  18. G a c b e d f S h S e e p d p r q q h h r r b c p p q q f f a a q q c c G G a a State Graphs vs. Search Trees Each NODE in the search tree is an entire PATH in the problem graph. We construct both on demand – and we construct as little as possible.

  19. G a c b a c b e d f e d f S h S h e e p d p r p q q q h h r r b c p p q q f f a a q q c c G G a a Depth First Search Strategy: expand deepest node first Implementation: Fringe is a LIFO stack State graph r Search tree

  20. Quiz • Which solution would depth-first search find if run on the graph below? Assume ties are broken alphabetically. For example, a partial plan S->X->A would be expanded before S->X->B; similarly, S->A->Z would be expanded before S->B->A

  21. Search Algorithm Properties Complete? Guaranteed to find a solution if one exists? Optimal? Guaranteed to find the least cost path? Time complexity? ~How many nodes get expanded? Space complexity? ~How big can the fringe get?

  22. DFS • Infinite paths make DFS incomplete… • How can we fix this? N N Infinite Infinite b START a GOAL

  23. DFS • With cycle checking, DFS is complete.* • When is DFS optimal? 1 node b b nodes … b2 nodes m tiers bm nodes Y N O(bm) O(bm) * Or graph search – next lecture.

  24. G a c b e d f S S e e p h d Search Tiers q h h r r b c p r q p p q q f f a a q q c c G G a a Breadth First Search Strategy: expand shallowest node first Implementation: Fringe is a FIFO queue

  25. Quiz • Which solution would BFS find if run on this graph?

  26. BFS • When is BFS optimal? Y N O(bm) O(bm) Y N* O(bs) O(bs) 1 node b b nodes … s tiers b2 nodes bs nodes bm nodes

  27. BFS complexity: concretely s • Russell & Norvig

  28. Quiz • Which are true about BFS? (b is the branching factor, s is the depth of the shallowest solution) • At any given time during the search, the number of nodes on the fringe can be no larger than bs. • At any given time during the search, the number of nodes on the fringe can be as large as b^s. • The number of nodes considered throughout the entire search can be no larger than bs. • The number of nodes considered throughout the entire search can be as large as b^s.

  29. Comparisons • When will BFS outperform DFS? • When will DFS outperform BFS?

  30. Iterative Deepening b Iterative deepening: BFS using DFS as a subroutine: • Do a DFS which only searches for paths of length 1 or less. • If “1” failed, do a DFS which only searches paths of length 2 or less. • If “2” failed, do a DFS which only searches paths of length 3 or less. ….and so on. … Y N O(bm) O(bm) Y N* O(bs) O(bs) Y N* O(bs) O(bs)

  31. GOAL a 2 2 c b 3 2 1 8 e 2 d 3 f 9 8 2 START h 4 2 1 4 15 p r q Costs on Actions Notice that BFS finds the shortest path in terms of number of transitions. It does not find the least-cost path.

  32. G a c b e d f S h S e e p d p r q q h h r r b c p p q q f f a a q q c c G G a a Uniform Cost Search 2 8 1 Expand cheapest node first: Fringe is a priority queue (priority: cumulative cost) 2 2 3 2 9 8 1 1 15 0 1 9 3 16 11 5 17 4 11 Cost contours 7 6 13 8 11 10

  33. Priority Queue Refresher • A priority queue is a data structure in which you can insert and retrieve (key, value) pairs with the following operations: • You can decrease a key’s priority by pushing it again • Unlike a regular queue, insertions aren’t constant time, usually O(log n) • We’ll need priority queues for cost-sensitive search methods

  34. Quiz • Which solution would uniform cost search find if run on the graph below?

  35. Uniform Cost Search • Remember: explores increasing cost contours c  1 … c  2 c  3

  36. C*/ tiers Uniform Cost Search Y N O(bm) O(bm) Y N O(bs) O(bs) Y Y O(bC*/) O(bC*/) b …

  37. Uniform Cost Issues • Remember: explores increasing cost contours • The good: UCS is complete and optimal! • The bad: • Explores options in every “direction” • No information about goal location c  1 … c  2 c  3 Start Goal

  38. Search Gone Wrong?

  39. Summary • Agents that Plan Ahead • Search Problems • Uninformed Search Methods • Depth-First Search • Breadth-First Search • Uniform-Cost Search • Next time: informed search, A*

  40. If we had arbitrarily large negative costs, we would have to explore the entire state space to get an optimal solution. • Any path, no matter how bad it appears, might lead to an arbitrarily large reward (negative cost). Therefore, one would need to exhaust all possible paths to be sure of finding the best one.

  41. 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

  42. Heuristics

  43. Best First / Greedy Search • Expand the node that seems closest… • What can go wrong? [demo: greedy]

  44. Best First / Greedy Search b • A common case: • Best-first takes you straight to the (wrong) goal • Worst-case: like a badly-guided DFS in the worst case • Can explore everything • Can get stuck in loops if no cycle checking • Like DFS in completeness (finite states w/ cycle checking) … b …

  45. Some hints • Graph search is almost always better than tree search (when not?) • Implement your closed list as a dict or set! • Nodes are conceptually paths, but better to represent with a state, cost, last action, and reference to the parent node

  46. Extra Work? • Failure to detect repeated states can cause exponentially more work (why?)

  47. S e e p d q h h r r b c p p q q f f a a q q c c G G a a Graph Search • In BFS, for example, we shouldn’t bother expanding the circled nodes (why?)

  48. Graph Search • Very simple fix: never expand a state type twice • Can this wreck completeness? Why or why not? • How about optimality? Why or why not?

  49. Some Hints • Graph search is almost always better than tree search (when not?) • Implement your closed list as a dict or set! • Nodes are conceptually paths, but better to represent with a state, cost, last action, and reference to the parent node

More Related