8 The Hessian

In Chapter 6 we exploited the second derivative of a one variable real function to analyze convexity along with local minima and maxima.
In this chapter we introduce an analogue of the second derivative for real functions of several variables. This will be a matrix. The important notion of a matrix being positive (semi-) definite introduced in Section 3.7 will now make its appearance.

8.1 Introduction

In Section 6.4 the Taylor expansion for a one variable differentiable function centered at with step size was introduced as
Recall that the second derivative contains a wealth of information about the function. Especially if , then we might glean from if is a local maximum or minimum or none of these (see Theorem 6.50 and review Exercise 6.53 ).
We also saw β€” remember the zigzag path across the narrow valley in Section 7.5.1 β€” that plain gradient descent can be painfully slow. Taking the second derivative into account gives a more detailed picture of the function and, as in Newton's method below, much faster algorithms.

8.2 Several variables

Our main character is a differentiable function in several variables. We already know that
where and are vectors in (as opposed to the good old numbers in (8.1) ). Take a look back at Definition 7.3 for the general definition of differentiability.
We wish to have an analogue of the Taylor expansion in (8.1) for such a function of several variables. To this end we introduce the function given by
Notice that
where is the function given by . In particular we get
by using the chain rule (see Theorem 7.23 ).
Explain how the chain rule is applied to get (8.3) .
The derivative is also composed of several functions and again we may compute by using the chain rule:
where is defined by
and by
The Hessian matrix of at the point is defined by
A very important observation is that above is a symmetric matrix if satisfies the condition in the last part of Theorem 7.11 .
Suppose that is given by
Then the gradient
and the Hessian
of are computed in the python cell below.

Live Python

See the calculus tutorial in the sympy documentation for more.
Verify (just this once) by hand the computations done by sympy in Example 8.3 .
Also, experiment with a few other functions in the python cell and compute their Hessians.
By applying Proposition 7.9 it is not too hard to see that the Hessian matrix fits nicely into the framework above, since
The full application of the chain rule then gives
Give a detailed explanation as to why (8.4) holds.

8.3 Newton's method for finding critical points

We may use Newton's method for computing critical points for a function of several variables. Recall that a critical point is a point with . By (7.8) and (8.4) the computation in Newton's method becomes
In practice the (inverse) Hessian appearing in (8.6) is often a heavy computational burden. This leads to the socalled quasi-Newton methods, where the inverse Hessian in (8.6) is replaced by other matrices.
Let us watch (8.6) in action on the function from Exercise 7.21 ,
with gradient and Hessian
This function offers a rare luxury: the equation can be solved by hand. The first coordinate gives , and substituting this into the second,
so or . The two critical points are
Since we know the answers in advance, we can concentrate on how Newton's method finds them. The cell below starts at v0 and prints the point and the length of the gradient after every step of (8.6) .

Live Python

Two things in the output are worth savoring. First, the speed. Starting from the iteration converges to , and the lengths of the gradients fall like
The exponent roughly doubles in every step, so the number of correct digits doubles too. This quadratic convergence is the trademark of Newton's method β€” compare with the small steps gradient ascent needed in Example 7.33 .
Second, the destination depends on the start. From the very same iteration converges to the other critical point . Newton's method solves and nothing else; it has no opinion on whether the point it finds is a local minimum, a local maximum or neither. So which of the three did we just find? The answer needs the main character of this chapter, the Hessian: see Example 8.14 and Exercise 8.18 .
Run the cell in Example 8.6 with the initial point v0 = [1/6, 1/6]. What goes wrong?
Show that is invertible if and only if , so the failing initial points lie exactly on a hyperbola in the plane. If you nudge the initial point to v0 = [1/6 + 0.001, 1/6], which critical point does Newton's method find?

8.4 The Hessian and critical points

Now we are in a position to state at least the first terms in the Taylor expansion for a differentiable function . The angle of the proof is to reduce to the one-dimensional case through the function defined in (8.2) . Here one may prove that
where with continuous at , much like in the definition of differentiability except that we also include the second derivative.
Now (8.7) translates into
by using (8.3) and (8.5) .
A critical point is called a saddle point for if there exists two vectors , such that
as illustrated in the graphics below.
Now go back and recall the definition of positive definite matrices in Section 3.7 . We call a symmetric matrix negative definite if is positive definite. One more concept (related to the definition of saddle point above):
A symmetric matrix is called indefinite if there exists with
So an indefinite matrix is mixed up in the sense that it is neither positive definite, nor negative definite.
We have the following addition to Proposition 3.43 (with a similar proof).
Let be a symmetric matrix and an invertible matrix. Then is indefinite (positive definite, negative definite) if and only if
is indefinite (positive definite, negative definite).
From (8.8) one can prove the following nice criterion, which may be viewed as a several variable generalization of Theorem 6.50 .
Let be a critical point for . Then
  1. is a local minimum if is positive definite.
  2. is a local maximum if is negative definite.
  3. is a saddle point if is indefinite.
Let be a critical point for . Which of the following statements are true?
If is a local minimum, then is positive definite.
If is indefinite, then is a saddle point.
Every symmetric matrix is positive definite, negative definite or indefinite.
If is positive definite, then is a local minimum.
Consider, with our new technology in Theorem 8.12 , Exercise 7.21 once again. Here we analyzed the point for the function
and showed (by a trick) that is neither a local maximum nor a local minimum for . The Hessian matrix for at is
Now Theorem 8.12 (ⅲ) shows that is a saddle point, since
and

Live Python

Try plotting the graph for different values of a 1 a=4 shows the saddle point clearly. in the python cell in Example 8.14 . What do you observe for the point with respect to the function? Does a have to be a number? Could it be an expression in the variables x and y like a = -10*np.cos(x)*np.sin(y)?
Check the computation of the Hessian matrix in Example 8.14 by showing that the Hessian matrix for at the point is
What about and in Example 8.14 ? How do they relate to the hint given in Exercise 7.21 ?
Newton's method in Example 8.6 also found the critical point for . Compute the Hessian of at this point and use Theorem 8.12 to decide whether it is a local minimum, a local maximum or a saddle point.
Give an example of a function having a local minimum at , where is not positive definite.
  1. The point is a critical point for
    What does Theorem 8.12 say about this point?
  2. The point is a critical point for
    What does Theorem 8.12 say about this point?
  3. The point is a critical point for
    What does Theorem 8.12 say about this point?
Consider the function
Compute its critical points and decide on their types according to Theorem 8.12 . Try to convince yourself that
for every .

Live Python

Look at the minimization problem
subject to
where is a big number.
Give an example of a function that has a local maximum, but where there exists with for any given (large) number .

8.5 Differentiable convex functions of several variables

Below is the generalization of Theorem 6.61 to several variables. You have already seen this in Exercise 6.62 , right?
Let be a differentiable function, where is an open convex subset. Then is convex if and only if
for every .
Proof
Suppose that (8.9) holds and let with , where . To prove that is convex we must verify the inequality
Let . Then
by (8.9) . If you multiply the first inequality by , the second by and then add the two, you get (8.10) .
Suppose on the other hand that is a convex function. Let . Since is an open subset, it follows that for , where is sufficiently small. Now define the function by
Being the composition of two differentiable functions, is differentiable. Suppose that and . Then
showing that is a convex function. By Theorem 6.61 ,
which translates into
by using the chain rule in computing .
Prove that a bounded convex differentiable function is constant.
The following is the generalization of Corollary 6.55 .
Let be a differentiable function with continuous second order partial derivatives, where is a convex open subset. Then is convex if and only if the Hessian is positive semidefinite for every . If is positive definite for every , then is strictly convex.
Proof
We have done all the work for a convenient reduction to the one variable case. Suppose that is convex. Then the same reasoning as in the proof of Theorem 8.23 shows that
is a convex function for every and every from an open interval to for suitable . Therefore by Theorem 6.54 . This proves that the matrix is positive semidefinite for every . Suppose on the other hand that is positive semidefinite for every . Then Theorem 6.54 shows that is a convex function from to for small and , since
for . Therefore is a convex function, since
The same argument (using the last part of Theorem 6.54 on strict convexity), shows that is strictly convex if is positive definite. It follows that is strictly convex if is positive definite for every .
Prove that
is a strictly convex function from to . Also, prove that
is a convex subset of .
Is strictly convex on some non-empty open convex subset of the plane?
Show that given by
is a convex function. Is strictly convex?
Let be given by
where .
  1. Show that is a strictly convex function if and only if and .
    This is a hint for the only if part. If is the Hessian for , then
    where - this is seen by a matrix multiplication computation. We know that is positive semidefinite. If was not positive definite, there would exist with . Now use to complete the proof that is positive definite by looking at .
  2. Suppose now that and . Show that has a unique global minimum and give a formula for this minimum in terms of and .

8.6 How to decide the definiteness of a matrix

In this section we will outline a straightforward method for deciding if a matrix is positive definite, positive semidefinite, negative definite or indefinite.
Before proceeding it is a must that you do the following exercise.
Show that a diagonal matrix
is positive definite if and only if , positive semidefinite if and only if and indefinite if and only if there exists with and .
The crucial ingredient is the following result.
Let be a real symmetric matrix. Then there exists an invertible matrix , such that is a diagonal matrix.
The proof contains an algorithm for building by different steps. We will supply examples afterwards illustrating these. An operational procedure implementing the steps is outlined in section 8.7 .
Proof
Suppose that . If has a non-zero entry in the upper left hand corner i.e., , then
where is a real symmetric matrix and is the invertible matrix
By induction on we may find an invertible matrix matrix such that
Putting
it follows that
We now treat the case of a zero entry in the upper left hand corner i.e., . Suppose first that for some . Let denote the identity matrix with the first and -th rows interchanged. The operation amounts to interchanging the first and -th columns in . Similarly is interchanging that first and -th rows in . The matrix is invertible and is a symmetric matrix with and we have reduced to the case of a non-zero entry in the upper left hand corner.
If for every we may assume that for some . Let denote the identity matrix where the entry in the first column and -th row is . The operation amounts to adding the -th column to the first column in . Similarly is adding the -th row to the first row in . All in all we get , where we have used that for . Again we have reduced to the case of a non-zero entry in the upper left hand corner.
Consider the real symmetric matrix.
Here . Therefore the fundamental step in the proof of Theorem 8.31 applies and
and again
Summing up we get
You are invited to check that
Let
Here , but the diagonal element . So we are in the second step of the proof of Theorem 8.31 . Using the matrix
we get
As argued in the proof, this corresponds to interchanging the first and third columns and then interchanging the first and third rows. In total you move the non-zero to the upper left corner in the matrix.
Consider the symmetric matrix
We have zero entries in the diagonal. As in the third step in the proof of Theorem 8.31 we must find an invertible matrix , such that the upper left corner in is non-zero. In the proof it is used that every diagonal element is zero: if we locate a non-zero element in the -th column in the first row, we can add the -th column to the first column and then the -th row to the first row obtaining a non-zero element in the upper left corner. For above we choose and the matrix becomes
so that
Let be any matrix. Show that
is positive semidefinite.
Which of the following statements about symmetric matrices are true?
A symmetric matrix with a diagonal entry equal to cannot be positive definite.
is positive semidefinite for every matrix .
Every symmetric matrix is either positive semidefinite or negative semidefinite.
A symmetric matrix with all diagonal entries positive is positive definite.
Find inequalities defining the set
Same question with positive semidefinite. Sketch and compare the two subsets of the plane .
Let denote the function given by
where . Let denote the Hessian of in a point .
  1. Compute .
  2. Show that for and .
  3. Compute a non-zero vector , such that in the case, where . Is invertible in this case?
  4. Show that is strictly convex if .
  5. Is strictly convex if ?
    Hint
    Consider the line segment between and a suitable vector , where .
Why is the subset given by the inequalities
a convex subset of ?

8.7 A schematic procedure for transforming symmetric matrices

Suppose that is a symmetric matrix. We wish to find an invertible matrix and a diagonal matrix so that
Every step in the algorithm in the proof of Theorem 8.31 involve an operation on the columns of followed by a similar operation on the rows. These steps can be carried out systematically by transforming the extended matrix
The recipe is: every column operation (on ) is carried out on the full matrix, whereas every row operation is only carried out on the lower matrix in (8.11) .
Here is how this plays out for the examples above.
Here is the schematic procedure applied to Example 8.32 :
Here is the schematic procedure applied to Example 8.33 :
Here is the schematic procedure applied to Example 8.34 :
The schematic procedure is exactly the kind of mechanical recipe a computer is made for. In the cell below the computer does the exact arithmetic β€” you step through the algorithm with the Next button. Run the cell, then press Next~: every press performs one arrow from the chains above β€” a column operation on the whole extended matrix, or the matching row operation on the lower half β€” and highlights the entries that changed. Watch being built in the upper half while is hammered into the diagonal matrix in the lower half. Step back and forth until every move makes sense, then replace A with the matrices from Examples 8.33 and 8.34 β€” the stepper knows the swap and the zero-diagonal trick from the proof of Theorem 8.31 β€” or with a symmetric matrix of your own.

Live Python

In the button below is a complete implementation. The function diagonalize carries out the steps from the proof of Theorem 8.31 , returning the matrices and , and definiteness reads the answer off the diagonal of . Try it on the examples above and check it against the steps in the widget.
Complete implementation

Live Python

The algorithm you have just seen is old. In 1759, the 23-year-old Joseph-Louis Lagrange published Recherches sur la mΓ©thode de maximis et minimis, asking precisely the question of this chapter: when is a critical point of a function of several variables a minimum? His answer amounted to repeatedly completing the square in the second order term β€” in modern language, the diagonal entry is used to eliminate the mixed terms, which is exactly step one of our procedure. For this reason the method is still known as Lagrange reduction of a quadratic form. The bookkeeping with matrices came much later. The systematic treatment, including the tricks for a vanishing diagonal, was collected in Felix Gantmacher's The Theory of Matrices (1953, English translation 1959), for decades the standard reference on the subject and still in print. It is a pleasant thought that when you press Run in the cells above, your browser is carrying out, step by step, a computation Lagrange did by hand more than 250 years ago.