yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Gradient and graphs


5m read
·Nov 11, 2024

So here I'd like to talk about what the gradient means in the context of the graph of a function.

In the last video, I defined the gradient, um, but let me just take a function here. The one that I have graphed is (x^2 + y^2) (f of xy = (x^2 + y^2)). So, two-dimensional input, which we think about as being kind of the XY plane, and then a one-dimensional output that's just the height of the graph above that plane.

I defined in the last video the gradient to be a certain operator. An operator just means you take in a function and you output another function, and we use this upside down triangle, so it gives you another function that's also of X and Y, but this time it has a vector valued output. The two components of its output are the partial derivatives: partial of f with respect to X and the partial of f with respect to Y.

For a function like this, we actually evaluate it. Let's take a look. Um, the very first one is taking the derivative with respect to X, so it looks at X and says, "You look like a variable to me. I'm going to take your derivative: your 2x."

But the Y component just looks like a constant as far as the partial X is concerned, and the derivative of a constant is zero. But when you take the partial derivative with respect to Y, things reverse. It looks at the X component and says, "You look like a constant, your derivative is zero," but it looks at the Y component and says, "Ah, you look like a variable, your derivative is 2y."

So this ultimate function that we get—the gradient—which takes in a two variable input (xy) (some point on this plane), but outputs a vector can nicely be visualized with a vector field. I have another video on vector fields if you're feeling unsure, but I want you to just take a moment, pause if you need to, and guess or try to think about what vector field this will look like.

I'm going to show you in a moment, but what's it going to look like—the one that takes in (xy) and outputs (2x, 2y)? All right, have you done it? Have you thought about what it's going to look like?

Here's what we get: it's a bunch of vectors pointing away from the origin. The basic reason for that is that if you have any given input point, and say it’s got coordinates (xy), then the vector that that input point represents would, you know, if it went from the origin here, that's what that vector looks like.

But the output is two times that vector. So when we attach that output to the original point, you get something that's two times that original vector but pointing in the same direction, which is away from the origin. I kind of drew it poorly here, um, and of course, when we draw vector fields, we don't usually draw them to scale.

We scale them down just so that things don't look as cluttered. That's why everything here looks the same length, but color indicates length. So you should think of these red guys as being really long, the blue ones as being really short.

So what does this have to do with the graph of the function? There's actually a really cool interpretation. Imagine that you are just walking along this graph; you know, you're a hiker, and this is a mountain.

You picture yourself at any point on this graph. Let's say—what color should I use?—let's say you’re sitting at a point like this, and you say, "What direction should I walk to increase my altitude the fastest?" You want to get uphill as quickly as possible.

From that point, you might walk, you know, what looks like straight up there. You certainly wouldn't go around in this way; you wouldn't go down. So you might go straight up there. If you project your point down onto the input space—so this is the point above which you are—that vector, the one that's going to get you going uphill the fastest, the direction you should walk for this graph, it should kind of make sense, is directly away from the origin.

Because here, I’ll erase this because once I start moving things, that won’t stick. Um, if you were to look at things from the very bottom, any point that you are on the mountain, on the graph here, and you want to increase the fastest, you should just go directly away from the origin. Because that’s when it’s the steepest, and all of these vectors are also pointing directly away from the origin.

So, people will say, "The gradient points in the direction of steepest ascent." That might even be worth writing down: direction of steepest descent.

And let’s just see what that looks like in the context of another example. So I’ll pull up another graph here, pull up another graph, and it’s a vector field. So this graph, it’s all negative values; it’s all below the XY plane, and it’s got these two different peaks.

I’ve also drawn the gradient field, which is the word for the vector field representing the gradient on top. You’ll notice near the peak, all of the vectors are pointing kind of in the uphill direction, sort of telling you to go towards that peak in some way.

And, you know, as you get a feel around, you can see here this very top one, like the point that it’s stemming from corresponds with something just a little bit shy of the peak there. Everybody's telling you to go uphill; each vector is telling you which way to walk to increase the altitude on the graph the fastest.

It’s the direction of steepest descent, and that’s what the direction means. But what does the length mean? Well, if you take a look at these red vectors here, so red means that they should be considered very, very long, and the graph itself—the point they correspond to on the graph is just way off-screen for us because this graph gets really steep and really negative very fast.

So the points these correspond to have really, really steep slopes, whereas these blue ones over here—you know, it’s kind of a relatively shallow slope. By the time you’re getting to the peak, things start leveling off.

So the length of the gradient vector actually tells you the steepness of that direction of steepest ascent.

Uh, but one thing I want to point out here: it doesn't really make sense immediately looking at it why just throwing the partial derivatives into a vector is going to give you this direction of steepest descent.

Uh, ultimately it will, we’re going to talk through that, and I hope to make that connection pretty clear. But unless you're some kind of intuitive genius, I don't think that connection is at all obvious at first.

But you will see it in due time; it’s going to require something called the directional derivative.

See you next video.

More Articles

View All
These are the questions you should be asking at a late-stage startup.
When a company goes public or when a company is acquired for a lot of money, the market is looking at how much revenue that company is making and is that revenue growing. I would say that, you know, for example, if I’m at a company right now that’s making…
Dealing cards with functions | Intro to CS - Python | Khan Academy
Let’s design a program with functions and nested function calls. We want to build a program that lets the user play several different car games. That means every game is going to need to share functionality for dealing a deck of playing cards. The first …
How can I review the security of my account?
So Guemmy, you’ve given us a lot of tips and things to think about. Is there a way to just see where we are in terms of our account security? Yeah. One thing I love that’s evolved in the industry over the last few years is a lot of the tech providers hav…
Warren Buffett's SECRET to Making Millions from IRRATIONAL BEHAVIOUR!
There’s a certain irony in that we will, we would do the best over decades if we operated in a market where people operated very foolishly. The more people respond to short-term events and exaggerated things, or anything that causes people to get wildly e…
HOT SPIDER COSPLAY .... AND MORE! IMG! #25
In Taiwan, the Subways don’t require pants, and a boy in love—wait, it’s episode 25 of IMG. There is nothing better than sniffing hippo butt, except a jar full of kitty. Put things in front of your face to get a kiss, or a fish face, or just dress up in S…
Unraveling a Mapmaker’s Dangerous Decision | Podcast | Overheard at National Geographic
So I told them that they didn’t have a chance, and for the sake of their wives and children, they should vacate the area and go back. Both of them sunk, and at that time I heard the cocking of weapons. Once both of them cocked their weapons, I knew they m…