1. Home
  2. Explore
  3. Computer Science
  4. AI Course Announcements

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

AI Course Announcements

Speaker 1Speaker 2

AI Course Announcements

16:57
0:00-16:57
  1. Corey

    Welcome back. Before the technical material, a few course logistics: Project Zero, the Python tutorial, was due yesterday. It’s worth zero points, but it checks that you’re participating and gives you a chance to try the submission system, so do it if you haven’t.

  2. Michael

    There’s also Homework Zero, a math self-diagnostic. The first three to five weeks are expected to be relatively light on math, but the course gets more demanding after that. The point is to assess your preparation while you still have the option to make a decision about staying in the class.

  3. Corey

    Homework One on search will be released this week, with electronic and written components. Homeworks are generally due Mondays, except next week, when Labor Day moves the deadline to Tuesday. Project One also comes out this week and is due Friday afternoon next week; it’s longer than most projects and is the best early test of whether your programming is ready for the course.

  4. Michael

    Project Zero is more about having Python installed and knowing how to submit. Sections start this week, and students can attend any section, though the people who signed up for a particular slot have priority if the room fills. For course information, pay attention to pinned Piazza posts and the course website, Piazza, and Gradescope; the class does not use B Courses.

  5. Corey

    And for students interested in AI research, there isn’t one central application process. Professors run their own labs and have their own ways of bringing students in. A good starting point is the Berkeley AI Research site: look at faculty and their research, then contact professors individually. Some may not respond to email, so check whether they have office hours or another way to connect.

  6. Michael

    With the logistics covered, today’s topic is search: how an agent can plan ahead instead of merely reacting. We’ll represent a real-world problem in a formal way, then use algorithms that operate on that representation. The algorithms today include depth-first search, breadth-first search, and uniform-cost search.

  7. Corey

    Let’s start with the contrast between a reflex agent and a planning agent. A reflex agent uses its current percept, and perhaps some memory, to choose an action without considering the consequences of that action. That can be sensible when an immediate response matters more than reasoning through a long chain of outcomes.

  8. Michael

    Like a fly coming toward your face: you close your eyes rather than carefully evaluating every possible result first. Reflexes can also be rational. If your hand is in a fire, pulling it away immediately can be better than spending time reasoning about what will happen if you leave it there.

  9. Corey

    That brings up the course’s definition of rationality: a rational agent optimizes expected utility. Whether it reasons slowly or reacts quickly is separate from whether its behavior is rational. A fast reflex can be the right action in a situation where delay would make the outcome worse.

  10. Michael

    Pac-Man shows how a reflex can work in one setting and fail in another. A simple reflex that moves toward the nearest dot may do fine in an open layout. But if a wall blocks the direction of the nearest dot, Pac-Man can repeatedly try the same move, hit the wall, and get stuck while losing points for wasted time.

  11. Corey

    A planning agent asks, “What if?” It imagines a sequence of actions and considers what would happen if it took them. To do that, it needs a model of how the world works, plus a goal against which it can evaluate possible outcomes.

  12. Michael

    A goal might be a particular destination, or it might be a condition that can be satisfied in many ways. We can also judge planning algorithms by properties such as completeness—whether they find a solution when one exists—and optimality—whether they find a solution with minimum cost.

  13. Corey

    Planning can mean looking all the way ahead, but it can also mean replanning repeatedly. In one Pac-Man approach, the agent plans an entire sequence to clear the board before acting. That can take a long time because there are many possible action sequences to consider.

  14. Michael

    A replanning agent instead finds a route to the nearest dot, follows it, and then solves a new planning problem for the next dot. It can begin acting sooner, but it keeps planning as the world changes. That’s a useful contrast: plan far ahead once, or plan a shorter distance and update repeatedly.

  15. Corey

    To make these ideas precise, we define a search problem using a state space, a successor function, a start state, and a goal test. The state space describes the possible configurations relevant to the problem. The successor function says what actions are available from a state and what state results from each action.

  16. Michael

    The start state is where the problem begins, and the goal test checks whether a state meets the desired condition. A solution is a sequence of actions—a plan—that transforms the start state into a state that passes the goal test.

  17. Corey

    The benefit of that interface is that many different real-world problems can be represented in the same form. Once an algorithm knows how to work with states, successors, a start, and a goal test, it can be used on any problem that has been modeled appropriately.

  18. Michael

    Consider finding a route across Romania, from a starting city to Bucharest. A reasonable state space is the set of cities. The successor function connects a city to its neighboring cities, and the cost of a transition could be the distance along that road.

  19. Corey

    But the model could use a different cost. Perhaps you care about traffic or potholes as well as distance. The important thing is to choose a state representation and successor function that fit together and capture what matters for the problem you want to solve.

  20. Michael

    The same Pac-Man world can also produce different search problems. For pathing to one destination, the state might only need Pac-Man’s location. The actions are directions such as north, east, south, and west, and the successor function accounts for walls—moving into a wall leaves Pac-Man in place.

  21. Corey

    But if the goal is to eat every dot, Pac-Man’s location alone is not enough. The state must also record which dots remain. One way is a Boolean flag for each possible food location: true if food is still there, false if it has been eaten.

  22. Michael

    Then the successor function updates both Pac-Man’s position and the food flags. The goal test checks that all the food flags are false. We don’t need to include where Pac-Man is in the goal condition if the only requirement is that all dots have been eaten.

  23. Corey

    This illustrates a key modeling question: what information must a state contain? It needs enough information to test the goal and enough information for the successor function to predict what happens after an action. If it leaves out something needed for either job, it’s not a sufficient representation.

  24. Michael

    Now consider the size of a state space. In one example, Pac-Man could be in 120 positions, there are 30 possible food locations, two ghosts each have 12 possible positions, and Pac-Man can face four directions. Multiplying the possibilities gives an estimate of the number of world states: 120 times 2 to the 30, times 12 times 12, times 4.

  25. Corey

    The factor 2 to the 30 comes from each of the 30 food locations being either occupied or empty. That number grows very quickly. Some combinations may be impossible—for instance, Pac-Man cannot be on a dot that has not yet been eaten if eating happens automatically—so this calculation is an estimate, not necessarily an exact count.

  26. Michael

    And the search problem’s state space can be smaller than the entire world-state space. For eating all the dots, we may need Pac-Man’s location and the food configuration, but not the ghosts’ positions or Pac-Man’s facing direction if those do not affect the modeled problem. For simple pathing, location alone may be enough.

  27. Corey

    The exact goal matters. Suppose Pac-Man must eat all the dots while keeping ghosts scared at all times. The state would need the regular food locations and Pac-Man’s position, but also the remaining power-pellet locations and a timer for how long the ghosts stay scared.

  28. Michael

    Why include those extra details? The timer lets the successor function detect when the ghosts stop being scared, and the power-pellet locations let it determine when the timer is reset. If the ghosts’ positions affect whether they respawn unscared, then those positions must be represented too. If the model ignores that behavior, they may not be necessary.

  29. Corey

    So the right model depends on how the world works and what you choose to include. A useful check is to ask: can I test the goal from this state, and can I correctly compute the consequences of an action? Then ask whether any information in the state is unnecessary.

  30. Michael

    Once we have a search problem, we can imagine a state-space graph. Each node is a possible state, each arc represents a possible transition from the successor function, and some nodes satisfy the goal test. In that graph, each state appears once.

  31. Corey

    But the state-space graph is usually too large to draw, and an algorithm typically doesn’t construct the entire thing ahead of time. Instead, it builds a search tree as needed, starting at the start state and generating possible continuations by calling the successor function.

  32. Michael

    A search-tree node represents a sequence of states—or, equivalently, a path of actions from the start. That means the same state can appear multiple times in the search tree if different action sequences lead to it. The search tree can therefore be much larger than the state-space graph.

  33. Corey

    In fact, a small state-space graph can have an infinite search tree. If you can move back and forth between states in a loop, there can be paths of arbitrarily great length. So even with only a few distinct states, the tree of all possible action sequences may never end.

  34. Michael

    The basic tree-search procedure grows the tree incrementally. It begins with the start state. It keeps a fringe, meaning the leaf nodes waiting to be considered. It selects a fringe node according to some strategy, checks whether that node reaches a goal, and, if not, expands it by generating its successors.

  35. Corey

    If the fringe has no nodes left, the algorithm has run out of candidates and can report failure. If a selected node passes the goal test, it returns the corresponding plan. Otherwise, expansion replaces that leaf with its successor nodes.

  36. Michael

    The strategy for choosing from the fringe is what distinguishes several search algorithms. In the Romania example, you might expand a path through one city, add its possible continuations to the fringe, and repeat. The search tree records candidate plans; the fringe records which candidates are still waiting.

  37. Corey

    There’s an important detail about when to declare success. The algorithm checks for a goal when it selects a node for expansion—not simply when it first generates a goal as one of the successors. That timing becomes crucial when costs differ, because a goal path that has just been generated may not be the cheapest one.

  38. Michael

    First up is depth-first search, or DFS. It chooses the deepest node on the fringe. If there are ties, a separate rule—such as alphabetical order—can decide which tied node comes first. It follows one branch as far as it can, then backs up and tries another.

  39. Corey

    For complexity, let B be the branching factor—the number of successors per node, in a simplified tree where that number is roughly constant. Let M be the maximum depth. The deepest layer can contain about B to the M nodes, and that exponential growth dominates the size of the tree.

  40. Michael

    In the worst case, DFS may have to explore the whole tree before finding a solution, so its time is on the order of B to the M when the maximum depth is finite. Its space use is much smaller: it mainly retains the unexpanded alternatives along the current path, on the order of B times M.

  41. Corey

    DFS is complete if the search tree is finite: it will eventually examine every branch and find a solution if one exists. But if the tree can be infinite, it may keep following an endless branch and never reach a solution elsewhere. And DFS is not generally optimal; it can find a costly or long solution before a better one.

  42. Michael

    Breadth-first search, or BFS, makes the opposite choice: expand the shallowest fringe node first. It works through the tree level by level, considering paths with fewer actions before paths with more actions.

  43. Corey

    If the shallowest goal is at depth S, BFS’s time is roughly on the order of B to the S, because it may explore the levels leading up to that depth. Its fringe can also grow to about B to the S, so BFS can use a lot of memory.

  44. Michael

    BFS is complete under the usual finite-branching assumption: if a goal is at some finite depth, it will eventually reach that level. It finds a solution with the fewest actions. But that’s only the cheapest solution if every action has the same cost; if actions have different costs, fewest actions and lowest cost are not necessarily the same.

  45. Corey

    The visual difference is easy to remember. BFS spreads outward from the start, expanding nearby states before distant ones. DFS follows a deep route first, even if that route is not the best one. Walls change which paths are available, but those strategies still determine the order of expansion.

  46. Michael

    When might you prefer one? BFS is attractive when a shallow solution is likely or when you need the path with the fewest actions. DFS can be useful when solutions are deep, or when memory is limited, because its fringe is much smaller than BFS’s.

  47. Corey

    Can we combine BFS’s preference for shallow solutions with DFS’s memory advantage? Iterative deepening does that. It runs depth-first search with a depth limit, first one level deep, then two, then three, and keeps increasing the limit until it finds a solution.

  48. Michael

    It does repeat some work, because it searches the earlier levels again each time. But with an exponentially growing tree, the deepest level dominates the work. So redoing the relatively small upper levels is often not much extra compared with exploring the final level anyway.

  49. Corey

    Next, suppose actions have different costs. Then counting actions is not enough. Uniform-cost search, or UCS, always selects the fringe node with the lowest cumulative cost so far, rather than the shallowest or deepest.

  50. Michael

    For example, if one path has cost 3 and another has cost 9, UCS expands the cost-3 path first. When it adds a transition, it adds that transition’s cost to the path’s existing cumulative cost. The priority is the total cost from the start to that fringe node.

  51. Corey

    UCS does not stop just because a goal first appears on the fringe. There might be another route currently costing a little more that leads to the goal with a much cheaper next step. UCS waits until it selects the goal as the lowest-cost fringe node.

  52. Michael

    Assuming positive action costs, that selected goal is optimal: every unexpanded fringe path costs at least as much as the selected path so far, and extending it cannot make its cost smaller. UCS has then found the least-cost route.

  53. Corey

    UCS is complete and optimal under the relevant positive-cost assumptions, but it can still do a lot of work. If the best solution costs C-star and every action costs at least epsilon, then a path with cost no greater than C-star cannot have more than roughly C-star divided by epsilon actions.

  54. Michael

    That quantity is called the effective depth. The search can still be exponential in that depth, with time and memory on the order of B to the effective depth. UCS follows low-cost paths, but it doesn’t know which direction is closer to the goal, so it may explore many promisingly cheap paths that don’t help.

  55. Corey

    A terrain example makes the behavior intuitive. If shallow water is cheaper to cross than deep water, UCS expands paths through shallow water sooner. It may still use deep water if that turns out to be part of the lowest-cost route. BFS would ignore the difference if it only counted actions.

  56. Michael

    These algorithms can share one implementation. Tree search always has the same basic structure; what changes is the priority used to choose a fringe node. DFS prioritizes depth, BFS prioritizes shallowness, and UCS prioritizes cumulative path cost.

  57. Corey

    Finally, a search algorithm can be correct and still produce a bad real-world result if its model is wrong. A driving route that directs a car onto a turn it cannot take may reflect a mismatch between the map and reality, not necessarily a failure of the search algorithm.

  58. Michael

    Likewise, if a map omits a road to the destination, search cannot use a route that isn’t in its state-space graph. It might find an absurd alternative, such as taking a boat, because that’s what the available model permits. Good search depends on building a good model of the world.

  59. Corey

    So the big picture is: define the problem carefully, then let a search strategy explore possible plans. Reflex agents react; planning agents reason about consequences. DFS, BFS, and UCS all use the same search framework, but their fringe-selection rules create different trade-offs in completeness, optimality, time, and memory.

  60. Michael

    And in practice, don’t try to draw or build the entire state space or search tree in advance. Represent the problem well, generate what you need as the algorithm runs, and remember that the quality of the answer is limited by the quality of the model you gave it.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent