1. Home
  2. Explore
  3. Computer Science
  4. Informed Search

Study methods

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

Informed Search

Transcript

[SIDE CONVERSATIONS]

PROFESSOR: All right, let's get started. Welcome to the third lecture of 188. Today's topic is Informed Search. Couple of announcements first. Homework One Search has been released. It's due on Tuesday. But keep in mind that typically homework will be due on Mondays. So don't fall into the pattern of thinking it's going to be due on Tuesdays. It's pretty much always going to be Mondays. But because of Labor Day, it's on Tuesday next week. There's two components, electronic and written. You should do both. It's not a choice, one or the other, both are for you to do. Electronic is on Gradescope. You solve things.

And you can try as many times as you like until we get it right and until the deadline hits. The written component is an exam style two-pager. We highly recommend you print it out, try to work it on your own. And then after you've done that for let's say, half an hour, or an hour on your own, feel free to discuss with other students and so forth to try to get a better understanding. But then still, you have to submit your own work not some other students' work of course.

These will be graded on effort/completion, which means that we will check if you-- it looks like you tried as hard as you would try on an exam to solve these problems. That's what it means. And the next week, you'll get to make corrections to anything you got wrong by grading it yourself. And again, grading yourself will be graded on whether you did it precisely, not on whatever grades you would have given yourself. Project One Search has been released. It's due next week, Friday at 4 PM.

You might wonder why 4 PM. It seems pretty arbitrary. We picked PM because a good fraction of students like to work last minute. And if we pick 4 PM, then-- I mean we don't recommend working last minute, but if we pick 4 PM, the students who do work until the last minute still have a Friday evening free for doing something else and weekend. So that's our rationale here to try to help you have Friday evening free.

One important thing is that Project One is representative of the projects we'll have throughout the remainder of the course. Project Zero is not. So if you thought Project Zero is easy, you got it done very quickly, Project One is different, and it's representative of everything that follows. If you're worried about your coding skills, your coding background, Project One will tell you how ready you are. The entire teaching staff is there to help you if you have questions. Post on Piazza, come to office hours. We want you to solve these problems. You can work in a team of two. We recommend that you pair code, or in some other way work together. We don't recommend you just split the work. Because you'll only learn half of the material that way. When you submit into Gradescope, one person submits and has to mark the other student their partner, if you work with a partner to make sure that they get a grade too. So don't forget to mark your partner if you had one

or they will not get that grade. Section started this week, as I mentioned before, you can go to any BF priority and the one you signed up for on Piazza. Any questions about logistics? Yes? There's only-- so there's only one type of discussion per week. There isn't many, many that are meant to be the same. But they're at different times and different GSI's so there will always be a little bit of variation in exactly how each GSI will do things. And also on Fridays, we will try to record a webcast of the material covered in the section that week. So you'll also have a webcast coverage of whatever was that week's section.

Any other questions about logistics? Over there. STUDENT: Can homework be submitted as a picture [? or letter? ?] PROFESSOR: So for homework, we want you to submit something that matches the template that we have. If you want to relay ticket, that's fine. But we want it to match up with a template that we have. Because that's important for our grading. We recommend you print it out and write on it. Because that's most similar to exams. But ultimately if you prefer to type it up, that's fine too.

But follow the template structure that is in our PDF. Other questions about logistics? OK. Today's topic is Informed Search. What that means, we're going to cover something called the heuristics, Greedy Search, A Star Search and then we'll see something called Graph Search, which will be an improvement to the Tree Search we've already seen towards the end of lecture. Let's first recap what is search. Well, in Search, what we're typically interested in is somehow capturing something about the real world inside a computer.

So, and the way we'll do that is by defining a search problem. The search problem is defined by a set of states, which corresponds to the configurations of the world, not necessarily all details of the configurations of the world, but the abstraction of the world that is relevant for the agent's decision making. There are actions that can be taken. And there are typically costs associated with those actions. There is a successor function, which defines for each state and each action that's available in that state, where you would end up, and also the cost associated with it. So that's modeling how the world works, again, at some level of abstraction that you choose as right for your problem. And then there's a start state. That's where the agent starts. And there is a gold test, which allows you to check if a current state that you feed into that test satisfies the goal condition or not. If it does, it's a goal state and you can declare success if you get there.

That's the problem structure. The computation we tend to do is building up a search tree, not fully, but partially hopefully. The nodes in a search area correspond to paths to states. We'll see some examples again soon. And these paths or plans have costs associated with them, which is the sum of all the costs of all the actions you took along that path. A search algorithm is an algorithm that systematically builds out the search tree, hopefully only a fraction of the entire search tree,

but maybe worst case the entire search tree. And it has to choose an ordering of what to currently expand. This is what is-- ready to be expanded is called the fringe. But you have to choose which one to expand first. Then a optimal search algorithm is one that finds least cost plans. So not all search is about pathing. So we'll use a slightly different example here. Pancake flipping. What is the setup here? This is a setup where there is four pancakes. They have different sizes.

And the goal is to get the pancakes stacked with the biggest one at the bottom, second biggest one on top of that, and so forth, smallest one at the top. Your action space is you can put your spatula between two pancakes or underneath the bottom one and then decide to flip everything that's above your spatula. For example, if the spatula goes right there where it's shown, it would flip the top two and the bottom two would stay in place. So for a stack of four pancakes here, you effectively have three actions available to you. You can go between number 2 and number 3, between number 3 and number 4, or below number 4. Going between 1 and 2 doesn't do anything for you. Because you're just keeping the top one on top. So that's the successor states from this particular state.

You might wonder who might care about pancakes? Well, the cost will be the number of pancakes as well. Pancake flipping robots is one type of species that cares a lot about this. But there are actually other people who cared about this. And people you, unless you looked at the slides ahead of time, definitely wouldn't guess. Bill Gates and Christos Papadimitriou wrote a paper this past Tuesday exactly 40 years ago about pancake flipping as an abstraction for sorting things.

So now back to the problem. Here is the state space graph, well, part of the state space graph. There is more states. How many states are there, you think in the state space total if we drew the entire graph? Any thoughts? anyone? Over there. Did you say 24? 24? OK, how do you get to that? STUDENT: Oh, [INAUDIBLE] anywhere and then the [INAUDIBLE].

PROFESSOR: Exactly. So let me say that again just because of the acoustics. It may be hard for people behind you to hear you. The answer was 24 total. So you can see, we're not showing them all on this slide. And how do we get to that? Well, you first have four choices as to what goes at the bottom. Then you have three choices left for what goes on top of that. Two choices left what goes on top of that. And then one choice left before it goes in the top and that multiplication is 24. So part of the state space graph, the costs here correspond to how many pancakes you're flipping. And we can imagine that maybe the robot has some energy costs depending on how many pancakes it has to lift and expends energy. And it prefers to lift us as few as possible and get to a goal. And the goal is to get into this configuration here where they're nicely lined up.

So not all Search is padding. It could be pancake flipping. And there will be other examples in the future. How does Tree Search work. I've illustrated with that pancake flipping problem. Tree Search goes through a loop. It initializes before going into the loop with putting on the fringe the start state, the current situation in the world. Then it checks. Are there any candidates for expansion? That is, is there anything on the fringe? And the answer is yes. This is our fringe. Then it decides to expand that. Well, it'll first check if it's the goal. If it's not the goal, then it will decide to expand it. This will be our new fringe. And then it'll go back around. It'll check is there anything left on the fringe? The answer is yes. Then pick something with some strategy, one of those three. Then it will check, does it achieve the goal condition? The answer will be no. It will then expand and this process repeats.

And then at some point, we might expand this one over here and declare success. This algorithm is underneath all the search arguments we've seen so far, Depth-first, Breadth-first, uniform cost. Today we'll see Greedy and A star. They will still use this. The only difference is the choice of strategy used to expand things from the fringe. And at the end of lecture, we'll see a modification to this called Graph Search where we'll put in one extra check here. But otherwise, it will be the same. And we'll also apply it to all the other-- all the strategies that we've seen.

So in this case, the total cost would be 7 to achieve the goal state if this is how you got there. The way you can implement this, no matter what the strategy is you can implement this with a priority queue. Your fringe is stored as a priority queue. When you pick something from priority queue, your strategy determines what the priorities are. And you pick based on whoever is highest priority. Now if you specifically are interested in Depth-first search, you could also use a stack instead of a priority queue. If you're specifically interested in Breadth-first search, you could also use a regular queue instead of a priority queue, which will make it slightly more efficient but will make your implementation less unified. For project purposes either way is fine. You can choose whether you want to do it in a unified way or have slightly special purpose versions for Depth-first, then Breadth-first.

So last lecture what we covered was Uninformed Search. And what that meant, let's say, it was Uniform Cost Search but the strategy correspondent to expand the lowest path cost from what's currently on the fringe. The good news, it's complete and optimal, which means if a solution exists, it will find it. And it will actually find the optimal solution meaning the way to achieve the goal at lowest cost. The bad news, it searches in every direction equally hard. For example, in this 2D space over here, it would expand in all directions at equal pace, even though the goal is on this side. It doesn't have any information about the goal. All it does with the goal is every now and then check, do I satisfy the goal condition? But nothing else about the goal is used, so it doesn't know that it's going in the right or wrong direction. So pictorially what this corresponds to is, let's say we run uniform cost search on a empty grid. Then it would look--

and so the way we visualize this whenever a state gets expanded for the first time, we show it highlighted here, uniform cost would just equally radiate out in all directions and then finally finds the goal. And then if we have a-- if we have a maze that runs so fast that we didn't see it in action. So what happened here is uniform cost search was run. And it highlighted in red nodes that are expanded during uniform cost search. You are bright red if you're expanded early on. You're darker red if you're expanded later on. So the last one expanded would be around here where-- does that cursor show up over there? Let's see, yeah. So it would be around here. That's the goal state.

That's the last one expanded and declare success. But what you see here in this maze is that it actually expanded every single reachable state, except for just one of them over here. Why did it do that? Well, Uniform Cost Search doesn't know where the goal's going to be since they uniformly explore in all directions. And if you want to know, will it have expanded the state or not, and you want to quickly guess that for a maze like this, you would say, OK, let me eyeball what's the shortest path to the goal. I find the shortest path to the goal from Pac-Man to the go. I measure the length. And I know that Uniform Cost Search will expand every state that is at less than that distance from the start, which in this case means every state except for this loner over here, which is actually further away from the start than the goal. But everything else gets expanded.

So we're hoping to make that more efficient today. The way we're going to make it more efficient is by infusing information about where the goal is while the search algorithm is running. These are called heuristics. Heuristics is a function that estimates how close the state is to a goal. And it will be designed for a particular search problem. Everything we've seen so far, you build a search problem abstraction and you can run your algorithm. If you want a heuristic, we have to take one additional step. We have to come up with a heuristic function for the current problem we're trying to solve. So we'll build the heuristic function. There are some different choices that you can make for these heuristic functions. So we'll dive into that a little bit today. So for example for Pac-Man needing to find the one pallet here in this maze, what could be a reasonable heuristic function? A reasonable way of measuring how close am I to the goal? Any thoughts? Over there. STUDENT: Is it Manhattan distance?

PROFESSOR: So the suggestion was, Manhattan distance. Why would that make sense? Well, you can only move North, East, South, West, so your motion is always along that grid pattern. And so Manhattan distance is, well, in this case, Manhattan distance, of course, measures the distance that to achieve that path to the goal, you'd have to go through walls. But it gives you an estimate. And that's what heuristics are about. It's way of quickly getting an estimate of how far away the goal might be. And Manhattan distance is quick to compute. And it's very much tied into how you move in this space, except that it ignores the walls. You can also use Euclidean distance. So there's Manhattan distance, Euclidean distance would look like this. It's probably not as good a fit for this problem. Because Pac-Man cannot move diagonally. And so it doesn't measure as well how far away you are from the goal.

How about for this pathing problem we saw last time, finding a path in Romania from Iran to Bucharest? Well, again heuristic is something you want to be able to compute easily. And it gives us a guess of how close we are to the goal. So straight line distance could be something. Because all we need for that is the GPS coordinates of each city. From that we can compute the straight line distance to other cities. And that's a good measure of how far we are away. If we want to go to Bucharest, then it would be all straight line distances to Bucharest. And this would be our heuristic function. And this is in a tabular format what it could look like. Like heuristic function, if there's only a finite set of states assigns a number to each state, which is how far you think that state is or how much cost do you think you'll still incur from that state to get to the goal.

How about for pancake flipping ? Any thoughts on heuristics for that? Here. STUDENT: Make a number of pancakes that aren't in correct position. PROFESSOR: So this the suggestion was the number of pancakes not in the correct position. And the reason that could be a good heuristic is because every pancake not in the correct position has to be flipped at some point, at least once. And whenever you do an action, the cost is the number of pancakes flipped. So number of pancakes out of place is definitely an estimate of how much

cost you're going to encounter before you can get everything in place. So that's one choice. Number of pancakes out of place. Any other thoughts on other heuristics? This has to be an art. For many problems there is many, many heuristic you can come up with. STUDENT: Longest chain of correct, like ordered pancakes. PROFESSOR: Say it again. STUDENT: Longest chain of correctly ordered pancakes. PROFESSOR: Longest chain of correctly ordered pancakes. And so can you say a little more about how that measures, how far we are away from achieving the goal? STUDENT: So if you have 1, 2, 3 together, that would be like four 3's. But if you have 1, 3, 5 that gets 0. So your final case would be 1,2, 3, 4. PROFESSOR: Mm-hm. STUDENT: So if you have 1-- like 2, 3, 4 somewhere in there, but not closer to the [INAUDIBLE].. PROFESSOR: So the idea here is that you look at a essentially subset of the pancakes and see how many are already in the right order.

Because that means they are ready for whatever we need to achieve at the end. Now one subtlety here is that usually we measure heuristics measured in a similar unit as cost. So instead of measuring how many are already ordered nicely, which in case of the goal state would be all four. When we're at the goal state, we want the heuristic to be 0. So we want to do maybe something like 4 minus the function that you proposed to make sure that it measures distance from the goal, not higher when closer to the goal. But it's a good suggestion with that small caveat. Any other thoughts?

Here's another one, one that we put on the slides is the number that is the ID number of the largest pancake that is still out of place. How does that work? Well, which is the largest pancake still out of place here, it's the one at the top there. It's pancake number three. So then this heuristic would say 3. Why does that make sense? Well, that pancake is still out of place. That means that everything 3 up still needs to undergo some flipping operation in the stack.

Otherwise there's no way to get this one in place. It measures something about how deep you'll need to go into the stack for some operation before you could ever complete. So this what we're showing here. Later we'll also look at what might make one heuristic better than another heuristic. And, of course, a lot of it has to do with accuracy. And so in this case, let's compare the one that's on the slide with the one that was proposed earlier about how many pancakes still out of place. So we'll look at this one here. How many pancakes still out of place? That is 2.

So what we see is that these are different numbers. And that's going to happen often with different heuristics. One of them may be more precise than the other one. Because actually there is an action here that takes you straight to the goal state. And it has a cost of 3. And so this heuristic here is more precise than this one. Now there are other trade-offs in heuristics at times related to not just precision but also speed of finding your heuristic. But what we see here is that in this case, we might prefer number of the largest pancake that is still out of place over number of pancakes still out of place. So mostly with heuristics we can start doing something called Greedy Search. In Greedy Search what we're going to do is a strategy to pick something from the fringe is to pick the thing that looks like it's already closest to the goal. So it's like you're searching, and you look in your fringe and you say, oh, well this one's already pretty close, closest

of everything on the fringe. Let me pick that one. So what does that look like? On this map of Romania, well, we still start with the start state. Then we expand. At this point we have three nodes on the fringe. And the number shown are the straight line distances to Bucharest, our heuristic function. And Sibiu has the shortest straight line distance to Bucharest. So we started here in Iran. Sibiu is over here, shortest straight line distance. So Greedy will say expand that one.

Then we have now a fringe with 6 members. We again look at which one of these is closest to the goal. It's Fagaras over here with a heuristic of 176. We expand that one. Now we have a fringe of 7. And in that fringe of 7, one of them actually has a heuristic of 0. That's as good as it gets. It's actually the goal. We would pick this one, expand it, and declare a success. And we would have found this path over here.

What can go wrong here? And we might already have gone wrong. Over there. STUDENT: You might choose a path that's a local optimum but not a global optimal. PROFESSOR: So the answer was you might use a path that's a local optimum, not a global optimal, or maybe to rephrase it a little bit into terminology we're using here, you might, and for this specific example, you see Fagaras here. And you expand it. And you end up at the goal. And you found the path. But it turns out that this other path is actually better. The lower path is the better path. And you didn't find that. Why did we not find that? Well, we didn't find it because from Sibiu we compared Fagaras and Ramnicu Valcea and with Fagaras we kind of took a very big action. We covered a lot of ground. It was a bit off to the side. But we covered a lot of ground. And we ended up closer to Bucharest after that action. But it was a costly action.

But Greedy Search ignores that this was a costly action. It doesn't pay attention to how much cost has already been incurred. It just looks at what's left. And so when you take a costly action like this that brings you closer to the goal, you're likely to go for that node again and then maybe again and ignore maybe something that could have been more promising, which is go this route, which was a cheaper option and you could have found a cheaper path to the goal. So what go wrong is that you kind of go down a rabbit hole that looks good and keep going, rather than carefully considering other opportunities that might still exist. So Greedy Search is trying to expand the node that you think is closest to a goal state. The heuristic is the thing that measures the distance to nearest goal for each state. A common case is that this best first approach takes you straight down some path, possibly to the wrong goal, but often to a goal still.

Worst case is that it behaves like a badly guided Depth-first search. And the heuristic sends you the wrong way, wrong way, wrong way and makes you explore everything except for where you need to be. Of course, this depends on your heuristic and so forth. But with a poor heuristic this can absolutely happen. Now let's take a look at how well this works on our two examples. So think for a moment. What do you think Greedy Search will do in this scenario? STUDENT: Straight line. PROFESSOR: Straight line. I think so too. Now there's a slight caveat there. It really depends on the heuristic it's using. All right? So if I don't tell you what heuristic it's using, you can't know for sure what it's going to be doing. But here are the heuristic is measuring straight line distance to the goal. And so what we expect to happen is

that then it'll keep expanding towards the goal. Let's see if it actually happens. It does and finds a solution very quickly, very low compute cost, and actually the optimal path in this case. Now let's take a look at Pac-Man in the small maze. Let's-- actually this is a uniform cost. We need Greedy. So again, this runs so fast we don't see it highlight. But what happened here is that as we run the search, whenever we expand a state for the first time, code successor function,

we color that corresponding square red. The brighter red you are, the earlier that happened. The darker red you are, the later that happened. And black means it never happened. So Greedy did not expend nearly as much as Uniform Cost Search. So it was a faster calculation. But the path it finds is actually suboptimal. It goes off to the left, down, back to the right, it comes down, and then off to the left again. It's a suboptimal path, but it was found quickly.

You might wonder, why does it not try to move to the right? Why is that never being expanded? It's because the heuristic tells us then from that spot one to the right from where Pac-Man started, the heuristic value, which in this case is Manhattan distance, is higher than for any of the nodes we did expand. And so it's still on the fringe waiting to be up next. But it never gets its turn. We expand the goal before we get to it. It's on that fringe. It's waiting but just never got called upon.

So now we're going to see something that hopefully can bring together the best of both worlds. Let's think about this a little bit pictorially. Who knows about the fable of the tortoise and the hare? Most of you, not everybody? Who doesn't know about the fable of the tortoise and the hare? You don't know about it. OK great. Or do you have a question? Or you don't know about it. It's a great fable. Let's see if I can do it justice explaining in here. But the gist is that the tortoise and the hare

are in a race. And they have to get to a destination before the other. And the hare runs off, and it's way ahead of the tortoise early on but then gets off on a side track, takes a nap, does all kinds of things. Because it feels like it's winning anyway. And in the meantime, the tortoise just slow and steady slow and steady, slow and steady keeps moving, keeps moving, keeps moving and actually gets to the destination first. It's meant to be-- the fable is about teaching people a lesson.

But we're going to do some analogies here. Uniform Cost Search is our tortoise. It's slow and steady. It tries out every single thing that might be cheaper than what we've considered, that might be cheap enough, and only will declare success when it's tried everything that's cheaper than the cheapest path to the goal. Greedy is like the hare. It just goes off, tries to find a path to the goal. But it might go down wrong rabbit hole and might not do so well after all. Now, well, wouldn't it be beautiful if we could have something like this?

So we're bringing together slow and steady with greedy and fast. So it's one thing to make a cartoon. Now we need to put an algorithm behind this cartoon. It's called A Star Search, the topic of this lecture, main topic of this lecture. So let's start comparing Uniform Cost, Greedy, and then A Star on a simple example here. And again, keep in mind, these examples are not meant to be representative of problems you would really want to solve, it's just to illustrate the algorithms.

So what does it mean to run Uniform Cost Search? Well, on the left we have the states based graph. On the right here, we have the Search Tree. I have shown the Search Tree here. What will Uniform Cost do? It will go in tiers through that Search Tree, initially S is on the fringe, then a, and s is off. Then a will go off and we'll have b, d, e on the fringe. And then what will happen next, we now have choices to make. There's three options. We will go by lowest cost so far. To get to b cost is 2.

To get to d cost is 4. To get to e cost is 9. So then Uniform Cost will go here, 2 is lowest. Expand b and we'll have found this path to c and so forth. Now what we see here, if we look at the graph, it start state a, b, c. That's kind of going off in the wrong direction. But Uniform Cost Search doesn't know. It does not have access to any information about the goal, except for a Boolean check, am I at the goal or not? So it doesn't know. And so it doesn't do so well.

Now, it's slow and steady and ultimately will explore that search Tree until it finds the shortest path to the goal. But it's going to waste a lot of time on things that are not promising. Greedy, how about Greedy? Well, Greedy orders by forward cost, the heuristic function. So Greedy would also start with the start state, expand that, get just a on the fringe, expand that. Now there are options. And it would check H. H is 1 here, 2 here, 6 here. It would say 1 is best. Let me expand this one.

Now we have this. Now we have 2, 2, and 6. There's some tie-breaking there. It would pick one of them. And then next it finds one of those two goals and declares success. But so what happens with Greedy is that you might end up finding this longer path to the goal that you would find if you were more careful about how you expand. How about A Star Search? A Star Search will consider both G and H. And keep in mind here, g is the cumulative cost so far.

The reason g is 2 here, it's 1 plus 1 to get our 2. So A Star means you do it by g plus h so how will it expand? Well, we'll start with s. No choice there, expand then a, no choice there, expand. Now we have b, d, e. That's our fringe. Which has the lowest g plus h? It would be this one here for 6 total, expand d. Then it would be over here. It would not declare success yet. Remember, we don't declare success just when we put something on the fringe, it's when we pop it off. Now we'll look at what's lowest. G plus h, this one has 8.

This one has 6. This one has 10. This one is lowest, we declare success. Because we popped a state-- a path that ends up in the goal state. So that's A Star Search and we'd expand less nodes than Uniform Cost Search expands, yet still in this case, at least, find the optimal path. So question, when should A Star terminate? Can we stop when we enqueue a goal?

No we can't. And I've tried to emphasize this a few times. This is the most commonly occurring bug in Project One. We have to wait until we dequeue. Now if you want to show something like that, if you want to say, I want to show to you that you have to wait until dequeueing. It's not enough to declare success when you enqueue. The way to prove that is by showing a counterexample, showing that if you do it wrong on this example, things go wrong. You get the wrong solution. That shows that your algorithm then is wrong, and you should change it. So here's a small example showcasing that we can not stop when we enqueue a goal. Because what happens in this example is we start with s on our fringe. Then next we have a and b on our fringe. Then what would be next? Well, t plus h, we have 4 here total. We have 3 here total. So we would expand b first. We then queue g. If we declare success at this point, we'd found the path of length 5.

But there is actually a path of length 4. We need to wait. We have now a and g on the queue. G has a score of g equals 5, h equals 0. So 5 a has 2 plus 2, which is 4. We need to expand a. And now we'll get-- we have on the fringe at this point is s to a to g as well as s to a, s to b to g. This one has 4. This one has 5, both plus 0, because the heuristic of the goal is 0. And then we pop this one, then we can declare success.

So only stop when we dequeue. Is A Star guaranteed to find the optimal solution? Let's do a raise of hands. Who thinks yes? OK. Who thinks no? So it's a bit of a mix. So it's kind of a mixed answer also. But in general, it's not guaranteed to be optimal. Some extra conditions have to be met before that guarantee is satisfied. So we will have that guarantee with extra conditions. Now, why is it not generally true? Well, the way to show it is by, again, showing a counter-example. Come up with a graph where A Star Search finds a suboptimal solution.

And then that's your proof right there that is not guaranteed to be optimal. Here's an example of such graph. If you're run A Star Search on this graph, what do we get? We start with s on the-- with a 0 plus 7. Comes off the fringe. We have s to a with a 1 plus 6. We have s to g with a 5 plus 0. What's next? This one is next. Sorry about those vertical lines, not sure why. This one is next. And that would mean we declare success. And we found this path here, the bottom one. Why did that happen?

STUDENT: Because the heuristic is not on there. PROFESSOR: So the answer is this heuristic here is a very poorly chosen heuristic. It says that it thinks it's still 6 away from the goal, but it's only 3 away. And so because it thinks 6, well, it's on the fringe. And it has to wait its turn much longer than it really should. And it doesn't get its turn soon enough for us to find it before we declare success. So that's also the intuition about what goes wrong when A Star is suboptimal on this specific problem. It's whenever the heuristic is too pessimistic and forces things are actually promising to stay on the fringe for too long and you find something else in the meantime, and you declare success. So the actual cost was smaller than the estimated cost from the heuristic. That's not a good thing. We need to do it the other way around. So this is called an Admissible Heuristic. If you're heuristic satisfies the property, then it's optimistic, meaning than it estimates

how much more cost you're going to get before reaching the goal from the state as a lower number or equal to what it really is. That's an optimistic heuristic, which is admissible, then A Star Search will be optimal. If you're heuristics are too pessimistic and they are inadmissible, A Star Search optimality guarantees will break. Because good plans, good partial plans will be trapped on the fringe and not expanded on. Because the heuristic is holding it back.

So formal definition, h star n is the optimal cost with which you can get from this node m to the goal. Typically we don't have access to that. But mathematically it exists. And a heuristic h is admissible if for every node it estimates something that's lower than or equal to the exact cheapest way to get to the goal from that state.

What are some examples? Manhattan distance. It's lower or equal to the actual cost. If there's no walls, it would be the actual cost. And when there are walls, it might be an optimistic estimate of the actual cost. Pancake flipping. What we had there, number of the ID of the largest one that's still out of place is optimistic. Because at the very least, you need to still go as deep as that one to rearrange things, which means flip at least that many pancakes to get to the goal.

So it's, again, and Admissible Heuristic. Come up with Admissible Heuristics is actually a lot of what's involved in using A Star in practice. Because once you've coded up A Star it's there. You can use it. But when you now want to solve a new problem, you need to think about what's a good heuristic for this new problem. So let's now formally prove that if we have a Admissible Heuristic, again, which means that for every node we estimate the cost to the goal as less than or equal to what it really would be, then A Star Tree Search will be optimal. Assume A is an optimal goal node. So we hope to find this one in the Search Tree. Assume B is a suboptimal goal node. So failure would be if we expand b and then we would declare success before we get to a. And let's assume h is admissible.

Our claim is that a will exit the fringe before b. If we can prove that claim we're done. Because if for-- this is we have an optimal goal node, any optimal on goal node a, any suboptimal goal node b and if we can show that a will be guaranteed to exit the fringe before b, then that is true for any such optimal and suboptimal goal nodes. And that means we'll always first expand the optimal one before we might consider expansion of the suboptimal one.

So this claim is what we need to prove to as a result get optimality. How do you prove a pops off first from the fringe? Let's see, imagine a's on the fringe. If b's never on the fringe, we have no trouble anyway. But imagine b makes it on the fringe. This might be our fringe. What do we know? We know that when b's on the fringe then also some ancestor n of a is on the fringe. Maybe it's A itself, maybe an ancestor.

How do we know that? If no ancestor of a is on the fringe anymore, then it means we already expanded a. Like, when all your ancestors are gone, you mean you've-- and you're gone, you've been expanded. There's no other way around it. So we know this will-- this condition to be true. Some ancestor or a itself be on the fringe too. Then our claim will be that n will be expanded before b.

So let's see how we can show that. F of N is less or equal then f of a. Why is that? Well, let's expand this. F of n is the backward cost plus the heuristic forward cost. F of n is smaller than t of a. Because that's what it means to be an Admissible Heuristic, it's the heuristics-- to be admissible means that it underestimates how much it will cost to get to the goal, the optimal goal that you can reach from there. So that's using the condition of admissibility. This is where we use it. If it was not admissible, we could not take this step. So we need the admissibility to take this step. t of a equals f of a because a is a goal node. So h is 0.

The only way to be admissible at a goal node is by a heuristic that's 0. Heuristics need to be positive. So this is now true. Then next thing we'll claim is that f of a is less than f of b. Why is that the case? Well, the cost to get to A is less than the cost to get to b. Because that's what we said at the beginning. A is the optimal way of achieving the goal. B is a suboptimal way of achieving the goal. That's exactly what this is. B is suboptimal. That also means f of a smaller than f of b.

Because the heuristic h is 0 at all goal states so including a and b. Now, we have f of n small label to f of a. F of a smaller than f of b which means f of n smaller than f of b, which means n will be expanded before b. Since n expands before b and this was for an arbitrary ancestor n of a, we can repeat this argument for the next ancestor on the fringe, next one, next one. This will keep happening. Ancestors of a will continue to be expanded before f until finally it's a itself on the fringe, which will also be expanded before b. And we've found a before b, hence, we found the optimal path to the goal, not the suboptimal one at b. So a expands before b. A Star Tree Search with Admissible Heuristics, remember we needed that condition somewhere in our proof, is optimal.

I'll leave this up for you to maybe think over during a small break and we'll start again in two minutes. [SIDE CONVERSATIONS] STUDENT: Do you consider A Star to be a Greedy algorithm? PROFESSOR: No. So terminology wise Greedy for us is when you use the heuristic as the only thing to have your-- to determine your strategy of what to expect next. STUDENT: Oh. PROFESSOR: You could think of it may be Greedy in some way and kind of how many people use the terminology greedy in everyday world. But not the terminology, the technical terminology we use here, Greedy means something very, very specific.

It means you just look at the heuristic and expand based on whoever has the lowest heuristic value and repeat. STUDENT: So it's like specific to them, like, AI in the [INAUDIBLE] field? PROFESSOR: Yes. STUDENT: OK. PROFESSOR: Hey. STUDENT: Hi. Just had a question on, I think, one of the previous slides. So you said the-- so f is the total like value received for n, like-- PROFESSOR: F is g plus h. STUDENT: F is g plus h. G is-- PROFESSOR: Backward cost, so the cost of all the actions so far to get you to n. STUDENT: Right. PROFESSOR: Accumulated together, summed together. And then h is the heuristic function that you choose to use. STUDENT: OK. PROFESSOR: It's the estimate of the cost to get to the goal. STUDENT: Right, right, right. So then when you say f of n is less than or equal to g of a, for the cost all the way to get to a, we're saying that-- PROFESSOR: So this step here, from here to here, that's what you're asking about right? STUDENT: Yeah.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent