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

Transcript

[AUDIO OUT]

PIETER ABBEEL: Hi. Hi. Welcome everyone. This is the second lecture for 188. Let's start with a couple of announcements. The first one, Project Zero, Python tutorial was due yesterday. OK. If you didn't do it, it's not a disaster because it's zero points on it. But it's our way to check that you're in the class. So if you didn't do it, we might be worried that you're not in the class. So please do it. It's also a good way to get to know our submission system.

There is also a homework zero. It's a math self-diagnostic. Motivation is that the first three to five weeks will be pretty light on math. And then things will change. And when things will change, it will be too late for you to drop the class. And so we want you to be able to know ahead of time what you're getting yourself into and analyze your math skills now while you can still drop, rather than after it's too late. Homework one search will go out this week. There will be two components--

electronic and written. We'll have an announcement about it later tonight. Typically, homeworks are due on Mondays. So kind of get used to that in some sense, but there's an exception next week. Because it's Labor Day on Monday, the homework is going to be due on Tuesday exceptionally. But keep in mind that generally homeworks are going to be due on Mondays. This is just an exception because of Labor Day. Project one is also going out this week and will be due sometime next week, Friday afternoon. It's longer than most projects. And it's the best way for you to test if programming-wise you are prepared for this class. If your programming goes OK for project one, you should be good for all the future projects. Project zero is not a good way to check if you are prepared for this class. It's just a way to check if you have a Python installed and can submit into the system.

Sections start this week. The first one is happening, I think, today at 4:00 PM. There was a bunch of them today, tomorrow, and then Thursday. You can go to a any section you'd like. But you'll have priority in the one that you signed up for on Piazza. So just in case there's too many people in one room that you don't fit, the people who signed up for that time slot have priority, if you're one of the first 35 to sign up. Instructional accounts. There are instructions in a Piazza post, our welcome post, that say you need to go find those accounts online. Also, that you don't need them, but some of you really want them. And if you really want them, there's instructions online. There are some pinned posts on Piazza. Those are the ones you maximally want to pay attention to. Those are our announcements that are currently relevant or relevant throughout the semester. So keep that in mind. And then the most frequently asked question

is can you add me to B courses? But we don't use B courses for 188. So none of you will be added to B courses. Nobody is on it. Nobody will be on it. We do use other things, so make sure you know there is a website. There is Piazza and Gradescope. Any questions about logistics? Yes? STUDENT: [INAUDIBLE] PIETER ABBEEL: Yeah, so homework one will officially release later today. And there will be a post on Piazza that links to all the relevant things for you to work on.

So just a little bit more patience for that. Any the other logistical questions? Another frequently asked question is, how about AI research? Wouldn't it be cool to do AI research? And I agree. I mean, that's half of my job is doing AI research. The other half is AI teaching. So obviously, I'm with you. AI research is good to do, a lot of fun. The way research tends to work is every professor effectively runs their own lab and has their own methodology on how and when to get new students involved. So if you're interested in AI research,

check out the bair.berkeley.edu site. Check out the professors listed there. And then check their pages, see what they work on, see who might be good fits, and then individually contact them. Some of them don't read email, then your email will not be read. But they might still have office hours, or they might be possibly other ways to catch in person. Every professor has their own way of communicating or not communicating. It varies. But that would be your best starting point. And there is no unified entry into this. It's all on a per professor basis. Question here. STUDENT: [INAUDIBLE] PIETER ABBEEL: Oh, the asterisks next to the names refers to professors who are kind of at their core working on AI. That's kind of like the main thing they work on. Whereas, the ones without asterisks often work on very closely related topics, but they might not call themselves necessarily AI faculty. But they work on things that in practice are extremely close.

In my particular case, the way I tend to recruit students is through email. So just email me your transcript, your resume, and I'll look at that and see from there. I got to warn you, I get like more than 100 per semester. And I can only get three or four or five involved in a semester. But you should try. And the same with other faculty, you should try if you're interested in research, and then see where you might be able to get involved. Any questions about that? OK. Let's get started on the technical topics then. Today's topic is search. What does that mean? We're going to discuss agents that plan ahead, rather than just react to a current situation. We'll formalize this into search problems. And this is going to be a recurring theme throughout the course, is that we will look at some high level intuition, some notion of the type of problem we're interested in. We'll then show a formalization. For example, search problem is a formalization

of real world settings into something mathematically workable. And then we'll have algorithms that can work with that mathematical interface to solve the problem. And the algorithms we'll see today are depth first, breadth first, a uniform cost search, and we'll expand on that in the next lecture. So agents that plan. Before we dive into agents that plan, let's maybe contrast it by a more naive type of agent, the reflex agent because that might be the simplest way to just write up some AI agent.

So what are reflex agents? Reflex agents are agents that have a current precept, maybe some memory. And based on that, make a decision, but without consideration of the consequences of their actions. So let's see. Who here is maybe like sometimes a reflex agent? Who thinks they're sometimes a reflex agent? OK. Why? STUDENT: [INAUDIBLE] PIETER ABBEEL: So the answer was because sometimes just instinctively you feel what to do, and you just do it. You don't reason through all the consequences.

Sometimes good consequences result, sometimes bad, I guess. But a good example would be something where maybe an insect, a fly is flying to your face. And you don't want to go, OK, well, if I keep my eyes open, what will happen? If I close them, what will happen? You just want to close your eyes and be done with it. That would be a reflex compared to planning, which is thinking through all the consequences. So reflexes make a lot of sense, especially when you need to react quickly. Can reflex agents be rational? Meaning, a rational agent is an agent that optimizes expected utility.

I hear a yes. Why yes? Anybody? STUDENT: [INAUDIBLE] PIETER ABBEEL: So the answer is by reacting quickly you might be doing the right thing. And if you're doing the right thing, indeed like your hand's in the fire, you pull it back right away instead of thinking through the consequences of will this become burned? Will it become charcoal? What will the result be? You just pull back is much more optimal then to maybe reason through everything and might be too late.

So our definition of rational means optimal behavior. And how you reach those conclusions is decoupled from whether the agent is rational or not. And so that's a good example. Let's look at a Pac-Man example. So we'll run a demo here of Pac-Man in a very simple world. And the goal is to eat all the dots as efficiently as possible. And we're going to run a reflex agent, which just moves to the nearest by dot. So it looks at the nearest by dot, tries to move in that direction.

Here's what happens. There's nothing better available for you to do. So doing something as simple as move in the direction of the closest dot does succeed. Now, let's look at another case. Same piece of code. Look at the nearest by dot and try to move in that direction. So initially, it's going to go north, a lot of west, some more north. And it's east, east, east, east, east, east, east, east, east, and nothing happens. Because by moving east, it bumps into the wall, encounters the same situation, has the same reflex, repeats over and over and over. And actually, it loses points here. So in the one idiot Pac-Man world, when you waste time or every step that passes you lose a point to encourage you to be more efficient at completing the game. So this is a reflex agent that's clearly not optimal.

We'd really would want it to go around that wall and get the dot, but it's not going to do that. So we've seen a reflex agent that is rational, one that's not rational. Oh, quick note here. In the slides that you'll find online, the PowerPoint version has the videos of the demos embedded. So if at home, you're kind of reworking through the slides, and you're like, oh, what happened again in lecture one, this demo was run, you can click Play. And then you can watch the same demo at home as a video rather than a live demo. OK. So we've seen reflex agents. How about planning agents?

Planning agents ask themselves the question, what if? So they hypothesize if they were to take a sequence of actions, what would the result be? A requirement for this is that the agent has a model of how the world works. If you don't have a model of how the world works, you cannot reason through the possible consequences of your actions. You also have to have some kind of goal. Because the planning agent would have a sequence of actions its hypothesizing about, and then evaluating them based on whether they achieved the goal or not. The goal could sometimes be a single thing that needs to be achieved, or it could be a test, a condition that needs to be met that can be met in many ways. And you just need to meet the condition in some way. There are questions you will be able to ask and hopefully answer about planning algorithms when we see them. An algorithm could be optimal or suboptimal. Optimal means that you achieve goals in minimum cost.

Complete means that when there exists a solution, you find it. And then we'll look at some planning versus re-planning in the next demo here. So we'll start with a showcase of a mastermind agent that is planning through everything. So same maze again as we just saw. Now, it's going to be a planning agent. When I hit Start, we're going to see some planning happening down here. Let's see. It's actually pre-calculating to be ready for planning. It's done that.

It's done 1,000 expansions, 2,000 expansions. This is reasoning through many possible consequences of actions. It's then found what it knows is the optimal sequence of actions to clear this board. And then executes that sequence of actions. Now, the reason it took a while for this vision to get going is because a lot of sequence of actions to consider. And before you can ensure that you've found the optimal one, you have to consider quite a few in this scenario. Sometimes it's not practical to wait this long. And you might want to do something slightly different, which you'll do in some of your project ones also, which is re-planning. So what we're going to watch here is an agent that doesn't plan an entire sequence ahead of time,

but it just plans to the nearest dot. So it checks where is the nearest dot? What's my path to get there? Executes that plan. After it's executed that plan, formulates a new planning problem where it will plan path to the next nearest dot and repeats over and over and over. So this one can start acting almost right away and is continuously re-planning throughout execution to find the shortest path to the next dot.

OK. So we've seen a few examples here. And it's now started formalizing what it means to be a search problem. What are the key components? A state space. So whenever you are formulating a problem in the real world that you try to solve, a state space will be something you have to formulate for it. For example, for Pac-Man, the state space is a set of possible configurations of where Pac-Man is and where the dots are. Then a successor function. The successor function says for any given state what the actions are that are available, and what the consequence states will be. For example, from this particular state, the agent can take either the north action or the east action. And then the results are shown on the right. So the successor function encodes how the world works.

They need a start state and a goal test. Start state could be wherever you are currently in. And the goal test would be the condition that you want your agent to meet. The solution to your problem would be a sequence of actions, which we'll call a plan, which transformed the start state into a state that satisfies the goal condition. Now, the beauty of having this kind of interface up here is that once we agree to an interface like this, any real world problem we can cast this way, if we then have an algorithm that can work with this interface, that algorithm can solve that real world problem. And so the unifying theme in this lecture and the next lecture for casting real world problems as things we'll solve with our AI algorithms is by casting them as search problems. OK. Search problems are always just models.

And so a lot of the art will be in thinking through what it means to be a good model of the problem that you're trying to solve in the real world. So let's look at an example. Let's say you want to find a path. And this is a map-- well, a simplified map-- of Romania. And maybe you want to start in [INAUDIBLE],, which would be your start state, and end up in Bucharest, where you have the airport. To model this as a search problem, we need to ask the question, well, what are the states?

What's the state space? Any thoughts? Yeah. STUDENT: [INAUDIBLE] PIETER ABBEEL: So suggestion is, all locations. And that's indeed also the choice we made here. Since we're interested in finding paths, that seems reasonable. But you might go back and say, hey, the way I'm going to model this is actually different. I don't just care about the cities. I care about more details of the path along the way. And then break it down more and so forth. But at some point, you have to make a decision. And this is one reasonable decision.

How about successor function? Any thoughts? For any city, whichever cities are neighboring it, is the possible successors. So it is defined by the graph here. And the cost associated with the transition would be the distance on that edge. Again, you could make other decisions in practice. You might say I don't just care about how many kilometers it is between two cities. I care about how much traffic there is. Or I care about the number of potholes in the road. And you can adjust your cost and increase it

if there's more potholes and so forth. But one choice would be distance. Yeah. STUDENT: [INAUDIBLE] PIETER ABBEEL: So the question is, if you choose a different state space, might your successor function be different? And the answer is yes. You need to choose them in a compatible way. And we'll see more examples soon where you'll see that. Indeed, once you start picking a different state space for the same type of problem, you have different successor functions. Start state. Well, if we need to go from [INAUDIBLE] to Bucharest, that's [INAUDIBLE]. Goal test, we need to end up in Bucharest. So is our state equal to Bucharest is our goal test. What's the solution? Well, the solution would be some kind of path, maybe this path over here, or maybe you like this path. We'd have to calculate maybe which one is shorter to find the optimal path. There are even longer ones. But those are possible solutions to the problem. OK. Let's do a few more of these.

Here's a Pac-Man environment. And keep in mind the world state encodes everything about the environment. So the world state would have everything about this board situation. But now, the problem we're trying to solve would determine, well, we want to put in our state space for our search problem. So let's say we want to solve pathing. What would we put into our state space? Any thoughts? Location. So location makes sense because if we have location we can track where we are. And we need to go from some start to some destinations. That makes sense. Successor function. Well, it'd be something about north, east, south, west, take [INAUDIBLE] certain direction. And it would have something about where the walls are. Because if you run into a wall, you don't move. You stay put. So that would be encoded into the successor function.

And the actions are part of your successor function. And then goal test would be am I at the end state I want to be at? Now, let's change it. What if our goal was to eat all the dots? What would our state space be now? STUDENT: [INAUDIBLE] PIETER ABBEEL: So the suggestion was food locations and the location of Pac-Man. Then we need to think about what does it mean to encode food locations? For Pac-Man, we have xy coordinates for food, different options. One possibility could be, because the map is fixed, we could say for every possible location, there was a 01 Boolean flag saying whether there is still food there or not. So we'd have a long list of 01s, depending on whether there was

food or not, together with the coordinates of Pac-Man. How about actions? Action stay the same. Right? Same game-- north, south, east, west. How about successor function? STUDENT: [INAUDIBLE] PIETER ABBEEL: So if we now need to update both the location and the binary state of the food. So that's where we have now a different successor function than before. Before we are able to ignore that. Even though it might change in the real world, we just ignored it because for pathing it didn't matter. But here, we have to keep track of it. And then the goal test would be whether dots have all taken on the value false. And we don't need to worry about where

Pac-Man is because that's not part of what we need to achieve. It's just about eating all the dots. OK. So once we understand state spaces, the first question we can ask is, how big is our state space? So here is another maze. There's Pac-Man. There are some ghosts. There's 120 possible agent positions. There's a food count, 30 positions. Then 12 possible ghost positions for each ghost. And there's an agent. And the agent could be facing north, east, south, west. OK.

So what's the size of the state space? Well, somehow we need to count this. The way you do this, you look at all the variables involved and see how many are there. So let's first look at the world state. So world state wise, how many do we have? Well, agent positions we have-- not sure about this vertical bar--

we have agent positions, 120 possibilities. Then to know how many total states there are we need to check everything that varies and effectively multiply the count together. So food count, 30 locations that could be food or no food. So that's 2 to the 30 possibilities multiplied by 120. Each ghost could be in 12 locations. So that times 12 times 12 for both ghosts. And then the agent could be facing north, east, south, west. So the total number of world states is this product.

And the thing that should make you worried here is this one over here. We're going to have something very large in the exponent. Usually the number becomes very large. And so you have something very big to deal with. OK. That's world state. How about search problem state? That depends on the type of problem we're trying to solve. Imagine we're trying to solve eat all dots. OK. Well, what do we need for eating all the dots? We went through that on the previous slide. We need the agent position. We need to know where the food is. Since the ghosts are blocked off, we don't need to know about where the ghosts are. And we also don't need to know about which way the agent is facing. So I end up with 120 times to 230. What if it was just pathing?

Then all we need to know is the agent position. It would be 120. And so you can start seeing here why mastermind Pac-Man who was trying to figure out the shortest path to eat all the dots had to think for a long time because actually eating all the dots means that you have a state space where you need to keep track of which dots are still present or not. And this is going to be very large, especially for a bigger maze. Whereas, just pathing problem can be solved a lot more quickly. Any questions about the counts and how this works?

Yes. STUDENT: Do you have to account for instructions or impossible [INAUDIBLE]? PIETER ABBEEL: OK. That's a really good question. So should we account for instructions about impossible world states? For example, should we count maybe for whether ghosts can tunnel through the wall or not? Or do you have something else in mind? STUDENT: Actually, if Pac-Man [INAUDIBLE]..

PIETER ABBEEL: So I think what you're asking is, what's the exact definition of how this world works? And the way it works is that once Pac-Man arrives on a position where there's a food dot, it instantly gets eaten. So there is no such notion as being on that food dot, but not yet having eaten it. The eating is automatic. STUDENT: [INAUDIBLE] PIETER ABBEEL: Oh, I see. You're saying in the count. So that's a very good point. When we do this count here, it's a slight overestimate

of what actually could happen. The state where Pac-Man is in a particular location and there is food there is a state that doesn't happen. And in principle, we could take it out. And so we can actually start subtracting, in this case, a relatively small number of states from that count because they can not occur. And so what we're doing here, you're absolutely right, is essentially getting a ballpark estimate of how big this problem space is when we estimate it this way. And we try to get it roughly right, but not up to the exact number. Yes? STUDENT: What's 2 to the 30 [INAUDIBLE]?? PIETER ABBEEL: So 2 to the 30 corresponds to the fact that for each of the 30 food locations, the dot could be present or could be absent. And so every possible combination of presence/absence is 2 to the 30.

OK. Now, let's do a little quiz. Well, let's first define the problem. The problem is defined as we want Pac-Man to eat all the dots while keeping the ghosts scared at all times. So the way Pac-Man works is that if you eat one of those bigger dots, a power pellet, ghosts become scared for a while. And so what we want here is we want to find a sequence of actions and a search problem formulation corresponding that'll allow us to find that such that we'll keep the ghosts scared at all times and eat all the dots. OK.

Why don't you talk to each other for a couple of minutes. And then we'll see what you come up with as the state space, successor function, and so forth. [CHATTER]

OK. So let's see. Let's do this by just committing in some sense grow what goes into state space. OK. Who wants to put something in the state space? Raise your hand. Any thoughts? STUDENT: [INAUDIBLE] PIETER ABBEEL: OK. So let's say I'll write it here. Power pellet. STUDENT: And you can also add just the amount of time left [INAUDIBLE]. PIETER ABBEEL: Remaining locations.

A timer for the ghosts. OK. Anybody else wants to add something else? Over there. STUDENT: [INAUDIBLE] PIETER ABBEEL: So the regular food pellets, essentially dot Booleans, as we had before. Anything else?

Pac-Man location. So Pac-Man xy. Anything else? Over there. STUDENT: [INAUDIBLE] PIETER ABBEEL: So that's a good question. So it depends on how this world works what we might have to put into the state space. So and I didn't really specify much about that. Anything else?

What's a good way to check if this is enough? And then we can also later check if it's maybe too much. Good way to check is what do we need from our state space? We need to be able to do a goal check. Like, did we satisfy the goal? OK. Goal is to eat all food pellets. Well, we can definitely check for that. Then, what else is kind of part of our goal in some sense is to keep the ghosts scared at all times. The way we think of that is that the successor function will essentially say there's nothing left in the game here if the ghosts are not scared. That game is over. So it's like a game over successor state. OK? And so to able to have that game over successor state, we need the timer on the ghosts. Otherwise, we don't know when that's going to happen. To be able to know when we reset that timer,

we need to know the remaining power pellet locations. Of course, we need to know where Pac-Man is relative to them. Otherwise, we can't encode whether or not these things get eaten or not. So it seems like we need all of these. The food palettes we need for the goal test. And the other three we need for the successor function in coding what's going to happen next when we take an action. And then ghosts locations, well, it's a good one. It kind of depends on how we specify the problem.

In Pac-Man, if you run into a scared ghost, what often happens is that it responds alive unscared. In which case, you want that never to happen because you're supposed to be always keeping the ghosts scared. And so then you need to keep track of the ghost locations. If you ignore them, if you say, OK, we're just going to ignore that ghosts respawn unscared, we'll just use the timer as our reference, if we say that's how the world works, then we don't need to keep track of it. And that will often be a question you have to ask yourself about the problem you're trying to solve. Exactly how does this work? And what's the right model? On the slides, we kind of assume that the ghosts don't respawn alive. But if you thought they were responding alive, then the right model would be to also keep track of the ghost locations because you'll need to simulate that process in your successor function.

Now, one thing that might be worth highlighting here. When we think about-- let's say food pellets-- why don't we just keep track of the number of food pellets left rather than going into all the details of the locations? STUDENT: If you only kept track of the number, you wouldn't really be able to do planning. PIETER ABBEEL: Exactly. So it's important that we don't just pay attention to what the goal check asks us for, but also we need to do the planning, which is a successor function that reasons about the world. And so whenever you do any of those, think about, can I check for the goal that's needed in this state? And then, can I encode my successor function using this representation? And then, check if there's anything that you didn't need. Anything here that we don't need? Not really. We needed everything that was listed, so we can't discard anything from here.

OK so at this point, what we looked at is how the formulate real world problems into search problems. And what results from those formulations is essentially a state space graph, which is a mathematical representation of a search problem where the nodes are abstracted world configurations might look something like this. And the arcs represent the successor function. And the goal test would correspond to some of the nodes in this graph meeting the goal condition, and other ones wouldn't meet the goal condition. Now in the state space graph, every state will occur only once. Keep that in mind. We'll soon see things where that's not the case. And we can barely build this thing in practice, so remember that we had something like to 2 to the thirtieth possible food pellet configurations for even this small world. Well, it's very difficult to draw 2 to the thirtieth different states on a slide or even a bigger piece of paper.

And so this is really just an abstract idea for us to think about. We know it mathematically exists. We're never actually going to lay this thing out unless on a slide to explain the principles behind some algorithms. Here's another one, and here's the running example we'll use. This is a really, really, really small state space graph research problem, and we'll use it as our running example. But keep in mind when we use this that this is just to illustrative purposes. In practice, you would never first draw a state space graph and then solve the problem. You would only implicitly ever deal with this state space graph. What we're actually going to build up when an algorithm runs is called a search tree. Search tree is something that starts with wherever the start state is and then calls a successor function to see what's possible from there. And it might call the successor function again, and so forth. So the entire search tree has all possible plans in it,

all possible sequences of actions, and their possible consequences. In a search tree, when we think about a node in the search tree, we actually think of it as a sequence of states that have happened. So this node here in the search tree corresponds to starting in the start state, taking the action east, ending up in the state shown there. For most problems we'll look at, we can't build the search tree either. In fact, the search tree will typically be much larger even than the state space graph because there might be multiple ways to get to the same state. And in that case, the search tree will have multiple occurrences of that same state. And so, often, it's much, much bigger than the state space graph, but it is the underlying abstraction we're going to work with.

So here for our very small example, on the left is the state space graph. On the right is a search tree. Assuming start state is S, search tree is rooted in the start state, and then from there, looks at all possible consequences of actions. Again, we're never going to construct any one of those when we actually write code and solve real problems, but on the slides for illustrative purposes, we will have them. Key will be in our algorithms that will construct these on-demand as needed, rather then ahead of time. OK, let's do a quick quiz. Here is a four state space graph. What would the search tree look like for this state space graph and how big would it be? I'll give you 30 seconds to talk to your neighbor and we'll see where you come up with. [SIDE CONVERSATIONS]

What do we think? Any thoughts on how big the search tree is for this state space graph? Over there. STUDENT: Infinite. PIETER ABBEEL: Answer-- infinite. Anybody wants to throw something else out than infinite? We're all going with infinite? Infinite is a good choice. Why is this infinite? Well, think about how do you build a search tree. You started at S. You can go to A or B. From A, you could go to B or G. From B, you could go to A or G, or you can go to B or G. And even just this first path in the search tree is already infinitely long, not to mention that there is even more of them here.

So what we see here is that we end up with an infinite search tree, even though the state space graph is actually quite small. So let's look at an algorithm on how to build up this search tree in a very incremental way, just enough to find a solution and then stop and return the solution. Let's do an example. We'll do pathing for Romania. What does a search tree look like? Well, as you run search, you start with the start states. You then expand out to potential next states. These are potential plans. These are one action plans. Then there is two action plans living here, and so forth. And the hope is that somehow we want to explore as little as possible of this giant search tree, yet find the solution. So it would go tier by tier, and we

hope that we find a solution relatively quickly before we've traversed everything in the search tree. Here's an algorithm to do this. It's called tree search. It will be the foundation of what we'll be doing this and next lecture. How does it work? Initialize your search tree with just the initial state of the problem. That's the only thing you put in it, and then you loop. You check. If there are no candidates for expansion-- what's a candidate for expansion? You look at all the leaves of your search tree. Those are all candidates for expansion. If there are a non-zero number of leaves, that means you have candidates for expansion. If there are none of them, that means you only have dead ends left in your search tree, and you're done, and you didn't find a solution. But if there are candidates, leaf nodes, then we pick one according to some strategy. We still have to determine that strategy, but will have many options, and somehow we'll pick one.

Then we'll check. If that node is a plan that ends up in one of the goals states, then you return the corresponding solution, and you're done. If not, then you call the successor function on the last state on that node, and expand from there, and go back around. What are the key ideas? There is the fringe, which is a set of leaf nodes that are waiting to be expanded. There is the process of expansion, where you pick one out of the fringe and expand it, but before you do, of course, you

check if it might already achieved the goal. And then there is the strategy. Which one of the elements in the fringe are you going to pick first to expand? And there's a lot of different strategies we'll look at. Let's run through an example. So how do we do this? We start with the start state and I will have two things going on. On the left, I will expand the search tree, and on the right, this is what will be in code happening for your projects.

So how does this start? There is just S, and you'll just have S on your fringe. So this is the fringe, S, stored in your code, and this is the search tree. Well, what can we do? We only have one option, so we pick S. What happens after S? We can end up in D, E, or P. The way we'll denote that here is that S got expanded, got taken out of the fringe, and instead we have S to D, S to E, S to P. Now, we again look at our fringe. Pick one. Which one do you want to pick?

I'm hearing E. Let's go with E. We pick E from our fringe-- first step. So pick this one here, which corresponds to this one here. We say, OK, does this achieve the goal condition? No. Then we expand. What does it expand to? From E we can go to H or R. So we expand to H or R. In your code, this one would have disappeared, and you'd have S to E to H, and S to E to R. Now, our fringe in it has four members. Which one do you want to pick?

Any preference? People choosing H. Interesting choice, because the goal is here. But that's a strategy. That's a thing, and we hope that in the future our computer programs will have good strategies. So H. From H we can end up in P or Q. And here, the way it would look is that this would disappear from the fringe, and instead we'd have S to E to H to P. S to E to H to Q. What do we pick next? Q. We're really going down a rabbit hole here. We're picking Q next. It is a strategy.

It's this year's 188 strategy. So we pick Q. Is it at the goal? No. So then we expand. Does it have successors? Actually, it doesn't have any successors. So this kind of just dies off here. Nothing can happen from here. With pick this off, and fringe had one less in it. We need to pick again. What do we pick next? STUDENT: R. STUDENT: R. PIETER ABBEEL: Let's pick R, because search trees are very big. If we build the entire search tree, even for this problem, it's going to take a long time.

So let's try to be effective. R seems a pretty good choice. From R we can end up in F. Over here, it means that this guy disappears, and instead we have S to E to R to F. What do we pick next? I hear many. Let's do F, among the many choices. F allows us to get to G and to C. This one goes off. We have S to E to R to F to G. S to E to R to F to C. At this point in our algorithm, we do not declare success. You might say, why not? We found a path. It'll matter in the future that we don't, and it's

one of the most frequently occurring bugs in your project one that you declare success at this point. It's too soon. That's not how the algorithm works. We wait. We go to our fringe again and look for candidates for expansion. What might we pick? Well, let's pick the one that ends in G. We pick it for expansion. We check, does it achieve the goal? The answer is, yes. Now, we declare success. It's not going to be obvious if you haven't seen search before why this is important, the sequencing, but it will start mattering and you will see soon why.

So at this point we expanded this one, which is this one here. We declare success, and we found S to E to R to F to G as our path. Great, we did it. Here is a-- on the slides, type set version-- the same thing. A slightly faster version than what we chose. It also highlights the actual search tree. So the actual search tree is a lot bigger than the part that needs to be explored to find a solution.

Let's take a two minute break here. And after the break, let's explore different strategies to choose nodes for expansion. [SIDE CONVERSATIONS]

Let's restart. Any questions about the first half? Let's look at our first choice of strategy, depth-first search. Who here has seen depth-first? Many of you. So it should be a good review that will ground everything else we're going to see in something you already know. If you haven't seen it, we're not going to leave anything out. This will be a full coverage of depth-first search. What would depth-first search mean for this pathing problem here?

Well, what makes depth-first depth-first? It's the choice of which node to expand first from the fringe. Initially there's only one node, S. So no choice has to be made. Every search algorithm will do the same thing. Every strategy expands S. Now we have three choices. Which one to pick? Depth-first says, pick the deepest one first. They're all equally deep. So we need to break some ties, maybe break ties alphabetically and pick D first. Now on the fringe we have five candidates.

The depth-first search says, pick the deepest one first. There's three deepest ones. We'll break ties, alphabetically again, expand out one. Now, there is, again, five on the fringe. Depth-first search, we'll pick the deepest one first. There's only one deepest one. The only choice is to pick this node over here, which encodes going from S to D to B to A. As always in tree search, you check, did it achieve the goal? It did not. Then call the successor function.

It has no successors, and this has been explored, and nothing left there. Four left on the fringe. Pick the deepest one. Again, there is ties. We pick one of them, we break ties alphabetically here, and this process kind of repeats. Streaking left to right, if we do alphabetical tie-breaking, through this search tree until it decides to expand the goal state, at which point it's done. One possible strategy-- depth-first. Now let's think about the properties of this algorithm, and let's first take a step back. What are properties we might want to quantify about any algorithm, not just depth-first search? Well, one is completeness. Is an algorithm guaranteed to find the solution, if one exists? Another one is optimality. Is it guaranteed to find an optimal path, the least cost path, if one exists?

Time complexity-- how long does the compute take to find a solution? And space complexity-- how much memory do you need in the process of that compute to get the computation done? So to do this, we'll use a cartoon of a search tree. Here's our search tree cartoon. We have a start state at the top, and from there we might expand through the successor function. And we're going to have a few variables here to quantify things. So B is the branching factor. It says-- essentially saying, how many successors are there from any given node? And for simplicity in this cartoon, we'll assume every node has as many successors as any other node, which is B. So then after one choice of action, there is B possible next states, after which we have B options in each one of them, which gives us B squared possible states after two actions, and so forth. Actually, I should be more precise. These are not states that we're counting, but nodes in the search tree.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent