Gradient
The gradient of a scalar function is a vector containing its first-order partial derivatives.
For a function :
Meaning
At a given point:
- points in the direction of steepest increase
- points in the direction of steepest decrease
- tells us how quickly the function changes in that direction
This is why gradient descent updates parameters in the direction of the negative gradient:
where is the learning rate.
Example
Given:
Calculate the two partial derivatives:
Therefore:
Remember
The gradient gives the direction and rate of the greatest local increase.
To minimize a function, move in the opposite direction: .
Hessian Matrix
The Hessian matrix contains all second-order partial derivatives of a scalar function.
For a function :
Meaning
The gradient tells us the local slope.
The Hessian tells us how the slope is changing, so it describes the local curvature of the function.
It helps determine whether a point is locally:
- Curving upward
- Curving downward
- Saddle-shaped
- Relatively flat
Example
Given:
The gradient is:
Now differentiate each gradient component again.
Second derivative with respect to
Mixed partial derivatives
The mixed partial derivatives are equal:
This is known as Clairautβs theorem, assuming the derivatives are continuous.
Second derivative with respect to
Therefore, the Hessian is:
Remember
The gradient gives the direction of steepest change.
The Hessian describes the curvature and how the gradient changes.
For smooth functions, the Hessian is usually symmetric.
Why Derivatives Matter
Derivatives provide local information about a function near a chosen point.
First Derivative
The first derivative tells us:
- The slope and direction of change
- How sensitive the output is to small input changes
- Whether the function is locally increasing or decreasing
In multiple dimensions, this information is captured by the gradient.
Second Derivative
The second derivative tells us:
- The curvature of the function
- Whether the slope itself is increasing or decreasing
- Whether the local shape resembles a bowl, ridge, or saddle
In multiple dimensions, this information is captured by the Hessian matrix.
Why This Is Useful in Machine Learning
Machine-learning objective functions are often highly nonlinear and difficult to analyze directly.
Instead, derivatives let us construct a simpler local approximation around the current point:
- First-order information approximates the function using its slope
- Second-order information improves the approximation by including curvature
This is the main idea behind the Taylor series.
Derivatives allow us to replace a complicated function with a simpler local model that is easier to optimize.