Hessian matrix is useful for determining whether a function is convex or not. Specifically, a twice differentiable function f:Rn→R is convex if and only if its Hessian matrix ∇2f(x) is positive semi-definite for all x∈Rn. Conversely, if we could find an x∈Rn such that ∇2f(x) is not positive semi-definite, f is not convex.
In this blog post, I would like show a self-contained discussion and proof for this property.
Convex Function Definitions
Here are the definitions of function being convex, strictly convex, and strongly convex. Strongly convex implies strictly convex, and strictly convex implies convex.
Convex Function
A function f:Rn→R is convex if its domain X is a convex set and for any x1,x2∈X, for all λ∈[0,1], we have
f(λx1+(1−λ)x2)≤λf(x1)+(1−λ)f(x2)
The local minimum of f is the global minimum of f.
Strictly Convex Function
A function f:Rn→R is strictly convex if its domain X is a convex set and for any x1,x2∈X and x1=x2, for all λ∈(0,1), we have
f(λx1+(1−λ)x2)<λf(x1)+(1−λ)f(x2)
The local minimum of f is the global minimum of f and there is only one local minimum.
Strongly Convex Function
A function f:Rn→R is strongly convex if there exists α>0 such that f(x)−α∥x∥2 is convex.
Prerequisites
Directional Derivative
Given the function f:Rn→R, the directional derivative at point x in direction h is defined as
∇hf(x)=t→0limtf(x+th)−f(x)
In addition, if the function is differentiable at x, we will also define the gradient at x, ∇f(x), such that
∇hf(x)=∇f(x)⊤h
There are multiple different definitions for directional derivative. For example, some people defined the directional derivative to be with respect to an arbitrary nonzero vector v after normalization, thus being independent of its magnitude and depending only on its direction.
∇hf(x)=t→0limt∣h∣f(x+th)−f(x)
In this case, the gradient at x is different for this directional derivative definition and is defined as follows.
∇hf(x)=∇f(x)⊤∣h∣h
The value of the directional derivatives at the same point using the two directional derivative definitions are, obviously, different and they are off by a scale of the norm of h. But we could also see that, even though the value of the directional derivatives at the same point using the two directional derivative definitions are different, the value of gradients at the same point using the two gradient definitions are the same.
In this article, we will use the first set of definitions for directional derivative and gradient.
Convex Function Additions
If functions f,g:Rn→R are both convex, then f+g is also convex.
This could be easily proved using the definition of convex functions.
Proof
Because f and g are both convex functions, we have
Because w and v are arbitrary, therefore, by definition, f is a convex function.
This concludes the proof.
Similarly, for strictly convex function, the inequality becomes
f(y)>f(x)+∇f(x)⊤(y−x)
and we could prove it using the similar fashion as we did for convex function.
Taylor Theorem
The univariate and multivariate Taylor theorem has been discussed and proved in detail in my previous blog post “Taylor Theorem”.
For quadratic multivariate Taylor theorem, let f:Rn→R be a $2$-times differentiable function at the point a∈Rn. Using the Lagrange form of the remainder, there exists t∈(0,1) such that
where ∇f⊤ is a row vector and s is a column vector. Specifically,
∇f⊤=[∂u1∂f,∂u2∂f,⋯,∂un∂f]
Therefore,
g′(0)=∇f(x∗)⊤s=0
Because s is arbitrary, therefore,
∇f(x∗)=0
This concludes the proof.
Global Minimizer
If function f:Rn→R is convex and differentiable, then x∗ is a global minimizer of f if and only if ∇f(x∗)=0.
Proof
Assume x∗ is a global minimizer, then x∗ is also a local minimizer. According to the first-order necessary conditions for local minimizer, ∇f(x∗)=0.
Now assume ∇f(x∗)=0, according to the sufficient and necessary condition for convex functions, we must have
f(y)≥f(x∗)+∇f(x∗)⊤(y−x∗)≥f(x∗)
Because y is arbitrary, therefore x∗ is a global minimizer.
This concludes the proof.
Second-Order Necessary Conditions for Local Minimizer
If function f:Rn→R is $2$ times continuously differentiable, suppose x∗ is a local minimizer of f, then the Hessian matrix H(x∗), i.e., ∇2f(x∗), must be positive semi-definite.
Proof
Given an arbitrary constant s∈Rn, we construct a new univariate function g:R→R
Because x∗ is a local minimizer of f, it is easy to see that $0$ is a local minimizer of g. By the first-order necessary condition for local minimum, we must have
g′(0)=0
We further claim that
g′′(0)≥0
and we will prove it by contradiction.
Because
α→0limh(α)=0
there must exists an ε>0 such that for all $0 < \lvert \alpha \rvert < \varepsilon$
g(α)>g(0)
h(α)<21g′′(0)
We further multiply the non-negative α2 on both sides of the inequality.
h(α)α2<21g′′(0)α2
Because for all $0 < \lvert \alpha \rvert < \varepsilon$
Because s is arbitrary, therefore, ∇2f(x∗) is positive semi-definite.
This concludes the proof.
Hessian Matrix
A twice differentiable function f:Rn→R is convex if and only if its Hessian matrix ∇2f(x) is positive semi-definite for all x∈Rn.
Proof
Assume f is convex and we have an arbitrary value a∈Rn. We define a new function g:Rn→R.
g(y)=f(y)−∇f(a)⊤(y−a)
Because −∇f(a)⊤(y−a) is a linear function, thus it is convex. Because g(y) is the summation of two convex functions, f(y) and −∇f(a)⊤(y−a), thus it is convex.
The first-order and second-order partial derivatives of g are
∇g(y)=∇f(y)−∇f(a)
∇2g(y)=∇2f(y)
for all y∈Rn.
We also note that
∇g(a)=∇f(a)−∇f(a)=0
From the property of the global minimizer of a convex and differentiable function, we know that a is a global minimizer of g. Based on the second-order necessary condition for a local minimizer (global minimizer is also a local minimizer), ∇2g(a) is positive semi-definite. Because ∇2g(a)=∇2f(a), ∇2f(a) is also positive semi-definite. Because a∈Rn is arbitrary, the Hessian matrix ∇2f(x) is positive semi-definite for all x∈Rn.
Assume the Hessian matrix ∇2f(x) is positive semi-definite for all x∈Rn, according to Taylor’s theorem,
f(y)=f(x)+∇f(x)⊤(y−x)+21(y−x)⊤∇2f(x+t(y−x))(y−x)
for some $0 \leq t \leq 1$.
Because ∇2f(x) is positive semi-definite for all x∈Rn, (y−x)⊤∇2f(x+t(y−x))(y−x)≥0. Therefore,