Last Updated on August 19, 2021
Hessian matrices belong to a class of mathematical structures that involve second order derivatives. They are often used in machine learning and data science algorithms for optimizing a function of interest.
In this tutorial, you will discover Hessian matrices, their corresponding discriminants, and their significance. All concepts are illustrated via an example.
After completing this tutorial, you will know:
- Hessian matrices
- Discriminants computed via Hessian matrices
- What information is contained in the discriminant
Let’s get started.
This tutorial is divided into three parts; they are:
- Definition of a function’s Hessian matrix and the corresponding discriminant
- Example of computing the Hessian matrix, and the discriminant
- What the Hessian and discriminant tell us about the function of interest
For this tutorial, we assume that you already know:
- Derivative of functions
- Function of several variables, partial derivatives and gradient vectors
- Higher order derivatives
You can review these concepts by clicking on the links given above.
What Is A Hessian Matrix?
The Hessian matrix is a matrix of second order partial derivatives. Suppose we have a function f of n variables, i.e.,
$$f: R^n \rightarrow R$$
The Hessian of f is given by the following matrix on the left. The Hessian for a function of two variables is also shown below on the right.
We already know from our tutorial on gradient vectors that the gradient is a vector of first order partial derivatives. The Hessian is similarly, a matrix of second order partial derivatives formed from all pairs of variables in the domain of f.
What Is The Discriminant?
The determinant of the Hessian is also called the discriminant of f. For a two variable function f(x, y), it is given by:
Examples of Hessian Matrices And Discriminants
Suppose we have the following function:
g(x, y) = x^3 + 2y^2 + 3xy^2
Then the Hessian H_g and the discriminant D_g are given by:
Let’s evaluate the discriminant at different points:
D_g(0, 0) = 0
D_g(1, 0) = 36 + 24 = 60
D_g(0, 1) = -36
D_g(-1, 0) = 12
What Do The Hessian And Discriminant Signify?
The Hessian and the corresponding discriminant are used to determine the local extreme points of a function. Evaluating them helps in the understanding of a function of several variables. Here are some important rules for a point (a,b) where the discriminant is D(a, b):
- The function f has a local minimum if f_xx(a, b) > 0 and the discriminant D(a,b) > 0
- The function f has a local maximum if f_xx(a, b) < 0 and the discriminant D(a,b) > 0
- The function f has a saddle point if D(a, b) < 0
- We cannot draw any conclusions if D(a, b) = 0 and need more tests
Example: g(x, y)
For the function g(x,y):
- We cannot draw any conclusions for the point (0, 0)
- f_xx(1, 0) = 6 > 0 and D_g(1, 0) = 60 > 0, hence (1, 0) is a local minimum
- The point (0,1) is a saddle point as D_g(0, 1) < 0
- f_xx(-1,0) = -6 < 0 and D_g(-1, 0) = 12 > 0, hence (-1, 0) is a local maximum
The figure below shows a graph of the function g(x, y) and its corresponding contours.
Why Is The Hessian Matrix Important In Machine Learning?
The Hessian matrix plays an important role in many machine learning algorithms, which involve optimizing a given function. While it may be expensive to compute, it holds some key information about the function being optimized. It can help determine the saddle points, and the local extremum of a function. It is used extensively in training neural networks and deep learning architectures.
This section lists some ideas for extending the tutorial that you may wish to explore.
- Eigen values of the Hessian matrix
- Inverse of Hessian matrix and neural network training
If you explore any of these extensions, I’d love to know. Post your findings in the comments below.
This section provides more resources on the topic if you are looking to go deeper.
- Gradient descent for machine learning
- What is gradient in machine learning
- Partial derivatives and gradient vectors
- Higher order derivatives
- How to choose an optimization algorithm
- Additional resources on Calculus Books for Machine Learning
- Thomas’ Calculus, 14th edition, 2017. (based on the original works of George B. Thomas, revised by Joel Hass, Christopher Heil, Maurice Weir)
- Calculus, 3rd Edition, 2017. (Gilbert Strang)
- Calculus, 8th edition, 2015. (James Stewart)
In this tutorial, you discovered what are Hessian matrices. Specifically, you learned:
- Hessian matrix
- Discriminant of a function
Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.