Code › codeit-ai-sprint
Partial Derivatives and Gradient Vectors
A learning note on partial derivatives and gradients from a machine learning fundamentals course
I finished the last practice problem in the machine learning fundamentals course today. The lesson moved from the steepest direction in two dimensions, through local minima and maxima, into higher-dimensional derivatives and why derivatives matter in machine learning. I got stuck for a bit around partial derivatives and gradient vectors. The idea was not impossibly complicated, but the picture in my head became blurry once slope moved from one variable to several variables.
With a single-variable function, slope is fairly easy to imagine. I can look at how much changes when moves a little. If the instantaneous rate of change is positive, the function value goes up as increases; if it is negative, the function value goes down as increases.
The point where the slope is zero needed a bit more care. A zero slope only means the graph is flat at that instant, not that the point is automatically a minimum or maximum. If the graph goes down, touches the bottom, and comes back up, that point is a local minimum. If it goes up, touches the top, and comes back down, that point is a local maximum. The smallest point across the whole range is the global minimum, and the largest one is the global maximum.
A saddle point is the case that still feels a little strange. The slope can look like zero there, but the point is neither a bottom nor a top. In one direction it can look like the surface is going down, while in another direction it can look like it is going up. The name makes sense once I imagine an actual saddle shape.
Then the input variables increase to two.
Now the function value is no longer decided by alone. Both and go into the function, and together they determine the height. If I think of it like a map, one axis is east-west, the other is north-south, and the function value is close to the altitude at that location.
A partial derivative is a way to move only one variable at a time. When differentiating with respect to , I temporarily hold fixed; when differentiating with respect to , I hold fixed. If both move at the same time, it becomes hard to separate which variable changed the function value by how much.
So when I partially differentiate with respect to , the result is . The part only contains , so from the point of view of , it is treated like a constant. Since a constant has no rate of change, it disappears.
When differentiating with respect to , I treat like a constant and only differentiate .
A new symbol showed up here. Or maybe I had seen it before and forgot. Instead of the usual , partial derivatives use the curled symbol . With a single-variable function, means differentiating with respect to , and the in the denominator marks as the reference variable for the rate of change. Partial derivatives are similar, but because the function has several inputs, the notation has to make clear which one variable I am using as the reference at that moment.
So means I keep the other variables fixed and change only a tiny amount, then look at how much changes. does the same thing with while keeping fixed. For a single-variable function, the usual phrasing is “differentiate with respect to .” For a function with several inputs, it becomes “take the partial derivative with respect to ” or “take the partial derivative with respect to .”
If I collect the partial derivatives for each variable, I get a gradient vector.
I also looked up the upside-down triangle symbol and found that it is called nabla. For now, I am reading it as a way to collect the rate of change in each direction. It puts the steepness in the direction and the steepness in the direction into one vector.
For example, if I plug in , I get this.
At first, the 2 and 4 did not really land. After unpacking it, 2 means how much the function value changes when I keep fixed and move slightly. The 4 means how much the function value changes when I keep fixed and move slightly.
Using the map analogy, if my current location is , moving one step east raises the altitude by roughly 2. Moving one step north raises it by roughly 4. In that sense, it is easier to see which direction is steeper. At this point, the change in the direction is larger than the change in the direction.
But the gradient vector does not stop at saying “east is 2, north is 4.” It combines those two pieces and points to the steepest upward direction from the current location. The vector moves in both the and directions, but more strongly toward , so that seems to be why the gradient vector is described as the direction where the function increases the fastest.
If I want to go down as fast as possible, I can put a minus sign in front of it.
I understood this as saying that if I want to reduce the function value from the current position, I should move in the opposite direction of the gradient vector. The last quiz said that a slope can point toward either an increasing direction or a decreasing direction. My current understanding is that the gradient itself tells me the increasing direction, and the opposite direction becomes the decreasing one.
I also connected this to why derivatives are needed in machine learning. To evaluate a model’s performance, I need some number that tells me whether things are getting better or worse, and I also need to know which direction makes that number go down.