






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























Optimization-based data analysis Fall 2017
Convex functions are of crucial importance in optimization-based data analysis because they can
be efficiently minimized. In this section we introduce the concept of convexity and then discuss
norms, which are convex functions that are often used to design convex cost functions when fitting
models to data.
A function is convex if and only if its curve lies below any chord joining two of its points.
Definition 1.1 (Convex function). A function f : R
n → R is convex if for any ~x, ~y ∈ R
n and any
θ ∈ (0, 1),
θf (~x) + (1 − θ) f (~y) ≥ f (θ~x + (1 − θ) ~y). (1)
The function is strictly convex if the inequality is always strict, i.e. if ~x 6 = ~y implies that
θf (~x) + (1 − θ) f (~y) > f (θ~x + (1 − θ) ~y). (2)
A concave function is a function f such that −f is convex.
Linear functions are convex, but not strictly convex.
Lemma 1.2. Linear functions are convex but not strictly convex.
Proof. If f is linear, for any ~x, ~y ∈ R
n and any θ ∈ (0, 1),
f (θ~x + (1 − θ) ~y) = θf (~x) + (1 − θ) f (~y). (3)
Condition (1) is illustrated in Figure 1. The following lemma shows that when determining whether
a function is convex we can restrict our attention to its behavior along lines in R
n .
Lemma 1.3 (Proof in Section 4.1). A function f : R
n → R is convex if and only if for any two
points ~x, ~y ∈ R
n the univariate function g~x,~y : [0, 1] → R defined by
g~x,~y (α) := f (α~x + (1 − α) ~y) (4)
is convex. Similarly, f is strictly convex if and only if g~x,~y is strictly convex for any ~x 6 = ~y.
f (θ~x + (1 − θ)~y)
θf (~x) + (1 − θ)f (~y)
f (~x)
f (~y)
Figure 1: Illustration of condition (1) in Definition 1.1. The curve corresponding to the function must
lie below any chord joining two of its points.
Convex functions are easier to optimize than nonconvex functions because once we find a local
minimum of the function we are done: every local minimum is guaranteed to be a global minimum.
Theorem 1.4 (Local minima are global). Any local minimum of a convex function is also a global
minimum.
Proof. We prove the result by contradiction. Let ~xloc be a local minimum and ~xglob a global
minimum such that f (~xglob) < f (~xloc). Since ~xloc is a local minimum, there exists γ > 0 for which
f (~xloc) ≤ f (~x) for all ~x ∈ R
n such that ||~x − ~xloc|| 2 ≤ γ. If we choose θ ∈ (0, 1) small enough,
~xθ := θ~xloc + (1 − θ) ~xglob satisfies ||~xθ − ~xloc|| 2
≤ γ and therefore
f (~xloc) ≤ f (~xθ) (5)
≤ θf (~xloc) + (1 − θ) f (~xglob) by convexity of f (6)
< f (~xloc) because f (~xglob) < f (~xloc). (7)
Many of the cost functions that we consider in data analysis involve norms. Conveniently, all
norms are convex.
Lemma 1.5 (Norms are convex). Any valid norm ||·|| is a convex function.
Proof. By the triangle inequality inequality and homogeneity of the norm, for any ~x, ~y ∈ R
n and
any θ ∈ (0, 1)
||θ~x + (1 − θ) ~y|| ≤ ||θ~x|| + ||(1 − θ) ~y|| = θ ||~x|| + (1 − θ) ||~y||. (8)
t
||t|| 0
||t|| 1
||t|| 2
||t||∞
Figure 2: Graph of the function (16) for different norms and for the nonconvex ` 0 “norm”.
where ||·|| is a valid norm, then we can exploit local information to find the global minimum
(we will discuss how to do this in more detail later on) because the function is convex in t by
Lemma 1.6. This is impossible to do for ||~vt|| 0
because it is constant except at two isolated points.
Figure 2 shows f for different norms.
The ` 1 norm is the best choice for our purposes: it is convex and its global minimum is at the
same location as the minimum 0 “norm” solution. This is not a coincidence: minimizing the 1
norm tends to promote sparsity. When compared to the ` 2 norm, it penalizes small entries much
more (
2 is much smaller than || for small ), as a result it tends to produce solutions that contain
a small number of larger nonzero entries. 4
The rank of a matrix interpreted as a function of its entries is also not convex.
Lemma 1.9 (The rank is not convex). The rank of matrices in R
n×n interpreted as a function
from R
n×n to R is not convex.
Proof. We provide a counterexample that is very similar to the one in the proof of Lemma 1.7.
Let
For any θ ∈ (0, 1)
rank (θX + (1 − θ) Y ) = 2 > 1 = θ rank (X) + (1 − θ) rank (Y ). (18)
1.0 0.5 0.0 0.5 1.0 1. t
Rank
Operator norm
Frobenius norm
Nuclear norm
Figure 3: Values of different norms for the matrix M (t) defined by (19). The rank of the matrix for
each t is marked in green.
Example 1.10 (Promoting low-rank structure). Finding low-rank matrices that are consistent
with data is useful in applications of PCA where data may be corrupted or missing. Let us consider
a toy problem where our goal is to find t so that
M (t) :=
0 .5 + t 1 1
5 0. 5 t
5 1 − t 0. 5
is as low rank as possible. In Figure 3 we compare the rank, the operator norm, the Frobenius
norm and the nuclear norm of M (t) for different values of t. As expected, the rank is highly
nonconvex, whereas the norms are all convex, which follows from Lemma 1.6. The value of t that
minimizes the rank is the same as the one that minimizes the nuclear norm. In contrast, the values
of t that minimize the operator and Frobenius norms are different. Just like the ` 1 norm promotes
sparsity, the nuclear norm, which the ` 1 norm of the singular values, promotes solutions with low
rank, which is the ` 0 “norm” of the singular values. 4
2 Differentiable convex functions
The gradient is the generalization of the concept of derivative, which captures the local rate of
change in the value of a function, in multiple directions.
Figure 4: Contour lines of a function f : R
2 → R. The gradients at different points are represented by
black arrows, which are orthogonal to the contour lines.
The first-order Taylor expansion of a differentiable function is a linear function that approximates
the function around a certain point. Geometrically, in one dimension this linear approximation
is a line that is tangent to the curve (x, f (x)). In multiple dimensions, it is a hyperplane that is
tangent to the hypersurface (~x, f (~x)) at that point.
Definition 2.4 (First-order approximation). The first-order or linear approximation of a differ-
entiable function f : R
n → R at ~x is
f
1 ~x (~y) :=^ f^ (~x) +^ ∇f^ (~x)
T (~y − ~x). (26)
By construction, the first-order approximation of a function at a given point is a linear function
that has exactly the same directional derivatives at that point. The following theorem establishes
that a function f is convex if and only if the linear approximation f
1 ~x is a lower bound of^ f^ for
any ~x ∈ R
n
. Figure 5 illustrates the condition.
Theorem 2.5 (Proof in Section 4.2). A differentiable function f : R
n → R is convex if and only
if for every ~x, ~y ∈ R
n
f (~y) ≥ f (~x) + ∇f (~x)
T (~y − ~x). (27)
It is strictly convex if and only if
f (~y) > f (~x) + ∇f (~x)
T (~y − ~x). (28)
An immediate corollary is that for a convex function, any point at which the gradient is zero is a
global minimum. If the function is strictly convex, the minimum is unique. This is very useful for
minimizing such functions, once we find a point where the gradient is zero we are done!
x
f (~y)
f
1 x (~y)
Figure 5: An example of the first-order condition for convexity. The first-order approximation at any
point is a lower bound of the function.
Figure 6: Epigraph of a function.
Corollary 2.6. If a differentiable function f is convex and ∇f (~x) = 0, then for any ~y ∈ R
f (~y) ≥ f (~x). (29)
If f is strictly convex then for any ~y 6 = ~x
f (~y) > f (~x). (30)
For any differentiable function f and any ~x ∈ R
n let us define the hyperplane Hf,~x ⊂ R
n+ that
corresponds to the first-order approximation of f at ~x,
Hf,~x :=
~y | ~y[n + 1] = f
1 ~x
~y[1]
· · ·
~y[n]
x
f (~y)
f
2 x (~y)
Figure 7: Second-order approximation of a function.
Note that by (33) if f : R → R
n is differentiable everywhere and twice differentiable at ~x ∈ R
n
then the Hessian ∇
2 f (~x) is always a symmetric matrix.
As you might recall from basic calculus, curvature is the rate of change of the slope of the function
and is consequently given by its second derivative. The Hessian matrix encodes the curvature of
the function in every direction, another basic result from multivariable calculus.
Lemma 2.10. If a function f : R
n → R is twice differentiable, the second directional derivative
f
′′ ~u of^ f^ at^ ~x^ equals
f
′′ ~u (~x) =^ ~u
T ∇
2 f (~x) ~u, (34)
for any unit-norm vector ~u ∈ R
n .
The Hessian and the gradient of a twice-differentiable function can be used to build a quadratic
approximation of the function. This approximation is depicted in Figure 7 for a one-dimensional
function.
Definition 2.11 (Second-order approximation). The second-order or quadratic approximation of
f at ~x is
f
2 ~x (~y) :=^ f^ (~x) +^ ∇f^ (~x) (~y^ −^ ~x) +
(~y − ~x)
T ∇
2 f (~x) (~y − ~x) (35)
By construction, the second-order approximation of a function at a given point is a quadratic form
that has exactly the same directional derivatives and curvature at that point. This second-order
approximation is a quadratic form.
Definition 2.12 (Quadratic functions/forms). A quadratic function q : R
n → R is a second-order
polynomial in several dimensions. Such polynomials can be written in terms of a symmetric matrix
A ∈ R
n×n , a vector ~b ∈ R
n and a constant c
q (~x) := ~x
T A~x + ~b
T ~x + c. (36)
A quadratic form is a (pure) quadratic function where ~b = 0 and c = 0.
The quadratic form f
2 ~x
(~y) becomes an arbitrarily good approximation of f as we approach ~x, even
if we divide the error by the squared distance between ~x and ~y. We omit the proof that follows
from multivariable calculus.
Lemma 2.13. The quadratic approximation f
2 ~x :^ R
n → R at ~x ∈ R
n of a twice differentiable
function f : R
n → R satisfies
lim ~y→~x
f (~y) − f
2 ~x (~y)
||~y − ~x||
2 2
To find the maximum curvature of a function at a given point, we can compute an eigendecom-
position of its Hessian.
Theorem 2.14. Let A = U ΛU
T be the eigendecomposition of a symmetric matrix A, where
λ 1 ≥ · · · ≥ λn (which can be negative) are the eigenvalues and ~u 1 ,... , ~un the corresponding
eigenvectors. Then
λ 1 = max
{||~x|| 2 =1^ |^ ~x∈Rn}
~x
T A~x, (38)
~u 1 = arg max
{||~x|| 2 =1^ |^ ~x∈Rn}
~x
T A~x, (39)
λn = min
{||~x|| 2 =1^ |^ ~x∈R
n }
~x
T A~x, (40)
~un = arg min
{||~x|| 2 =1^ |^ ~x∈R
n }
~x
T A~x. (41)
Proof. By Theorem 4.3 in Lecture Notes 2 the eigendecomposition of A is the same as its SVD,
except that some of the eigenvalues may be negative (which flips the direction of the corresponding
eigenvectors with respect to the singular vectors). The result then follows from Theorem 2.7 in
the same lecture notes.
Corollary 2.15. Consider the eigendecomposition of the Hessian matrix of a twice-differentiable
function f at a point ~x. The maximum curvature of f at ~x is given by the largest eigenvalue of
2 f (~x) and is in the direction of the corresponding eigenvector. The smallest curvature, or the
largest negative curvature, of f at ~x is given by the smallest eigenvalue of ∇
2 f (~x) and is in the
direction of the corresponding eigenvector.
If all the eigenvalues of a symmetric matrix A ∈ R
n×n are nonnegative, the matrix is said to be pos-
itive semidefinite. The pure quadratic form corresponding to such matrices is always nonnegative.
Lemma 2.16 (Positive semidefinite matrices). The eigenvalues of a symmetric matrix A ∈ R
n×n
are all nonnegative if and only if
~x
T A~x ≥ 0 (42)
for all ~x ∈ R
n
. Such matrices are called positive semidefinite.
Remark 2.19 (Strict convexity). If the Hessian is positive definite, then the function is strictly
convex (the proof is essentially the same). However, there are functions that are strictly convex
for which the Hessian may equal zero at some points. An example is the univariate function
f (x) = x
4 , for which f
′′ (0) = 0.
We can interpret Corollary 2.18 in terms of the second-order Taylor expansion of f : R
n → R at
~x: f is convex if and only if this quadratic approximation is always convex.
3 Minimizing differentiable convex functions
In this section we describe different techniques for solving the optimization problem
min ~x∈Rn^
f (~x) , (45)
when f is differentiable and convex. By Theorem 1.4 any local minimum of the function is also
a global minimum. This motivates trying to make progress towards a solution by exploiting local
first and second order information.
Gradient descent exploits first-order local information encoded in the gradient to iteratively ap-
proach the point at which f achieves its minimum value. The idea is to take steps in the direction
of steepest descent, which is −∇f (~x) by Corollary 2.3.
Algorithm 3.1 (Gradient descent, aka steepest descent). Set the initial point ~x
(0) to an arbitrary
value in R
n
. Update by setting
~x
(k+1) := ~x
(k) − αk ∇f
~x
(k)
where αk > 0 is a nonnegative real number which we call the step size, until a stopping criterion
is met.
Examples of stopping criteria include checking whether the relative progress
∣ ∣
∣~x (k+1)^ − ~x (k)
2
||~x (k)|| 2
or the norm of the gradient are below a predefined tolerance. Figure 9 shows two examples in
which gradient descent is applied in one and two dimensions. In both cases the method converges
to the minimum.
In the examples of Figure 9 the step size is constant. In practice, determining a constant step
that is adequate for a particular function can be challenging. Figure 10 shows two examples to
illustrate this. In the first, the step size is too small and as a result convergence is extremely slow.
In the second the step size is too large which causes the algorithm to repeatedly overshoot the
minimum and eventually diverge.
f : R → R f : R
2 → R
Figure 9: Iterations of gradient descent applied to a univariate (left) and a bivariate (right) function.
The algorithm converges to the minimum in both cases.
Ideally, we would like to adapt the step size automatically as the iterations progress. A possibility
is to search for the minimum of the function along the direction of the gradient,
αk := arg min α
h (α) (48)
= arg min α∈R
f
~x
(k) − αk∇f
~x
(k)
This is called a line search. Recall that the restriction of an n-dimensional convex function to a
line in its domain is also convex. As a result the line-search problem is a one-dimensional convex
problem. However, it may still be costly to solve. The backtracking line search is an alternative
heuristic that produces very similar results in practice at less cost. The idea is to ensure that we
make some progress in each iteration, without worrying about actually minimizing the univariate
function.
Algorithm 3.2 (Backtracking line search with Armijo rule). Given α
0 ≥ 0 and β, η ∈ (0, 1), set
αk := α
0 β
i for the smallest integer i such that ~x
(k+1) := ~x
(k) − αk∇f
~x
(k)
satisfies
f
~x
(k+1)
≤ f
~x
(k)
αk
∣∇f
~x
(k)
2
2
a condition known as Armijo rule
Figure 11 shows the result of applying gradient descent with a backtracking line search to the
same example as in Figure 10. In this case, the line search manages to adjust the step size so that
the method converges.
Example 3.3 (Gradient descent for least squares). Gradient descent can be used to minimize the
least-squares cost function
minimizeβ~∈Rp
∣~y − X β~
2
2
described in Section 2 of Lecture Notes 6 to fit a linear regression model from n examples of the
form,
( y
(1) , ~x
(1)
y
(2) , ~x
(2)
y
(n) , ~x
(n)
The cost function is convex by Lemma 1.6 (also its Hessian X
T X is positive semidefinite). The
gradient of the quadratic function
f (
β) :=
∣~y − X
β
2
2
β
T X
T X
β − 2
β
T X
T ~y + ~y
T ~y (54)
equals
∇f (~β) = 2X
T X β~ − 2 X
T ~y (55)
so the gradient descent updates are
β^ ~(k+1)^ = β~(k)^ + 2α kX
T
~y − X β~
(k)
= β~
(k)
n ∑
i=
~y
(i) − 〈x
(i) , β~
(k) 〉
x
(i)
. (57)
This has a very intuitive interpretation in terms of the examples: if ~y
(i) is larger than 〈x
(i) , β~
(k) 〉
we add a small multiple of x
(i) in order to reduce the difference, if it is smaller we subtract it.
Gradient descent is not the best first-order iterative optimization method for least-squares min-
imization. The conjugate-gradients method is better suited for this problem. We refer to [5] for
an excellent tutorial on this method. 4
Example 3.4 (Gradient ascent for logistic regression). Since gradient descent minimizes convex
functions, gradient ascent (where we climb in the direction of the gradient) can be used to maximize
concave functions. In particular, let us consider the logistic regression log-likelihood cost function
f (β~) :=
∑^ n
i=
y
(i) log g
〈~x
(i) , β~〉
1 − y
(i)
log
1 − g
〈~x
(i) , β~〉
from Definition 4.2 of Lecture Notes 6, where g (t) = (1 − exp −t)
− 1 the labels y
(i) , 1 ≤ i ≤ n,
are equal to 0 or 1, and the features ~x
(i) are vectors in R
n
. We establish that this cost function is
concave in Corollary 3.23. The gradient of this cost function is given in the following lemma.
Lemma 3.5. The gradient of the function f in equation (58) equals
∇f (β~) =
n ∑
i=
y
(i)
1 − g(〈~x
(i) , β~〉)
~x
(i) −
1 − y
(i)
g(〈~x
(i) , ~β〉)~x
(i)
. (59)
Proof. The result follows from the identities
g
′ (t) = g (t) (1 − g (t)) , (60)
(1 − g (t))
′ = −g (t) (1 − g (t)). (61)
and the chain rule. 4
The gradient ascent updates
β^ ~(k+1)^ := β~(k)^ + α k
n ∑
i=
y
(i)
1 − g(〈~x
(i) , β~
(k) 〉)
~x
(i) −
1 − y
(i)
g(〈~x
(i) , β~
(k) 〉)~x
(i)
. (62)
have an intuitive interpretation. If ~y
(i) equals 1, we add x
(i) scaled by the error 1 − g(〈~x
(i) , β~〉)
to push g(〈~x
(i) ,
β〉) up towards ~y
(i)
. Similarly, if ~y
(i) equals 0, we subtract x
(i) scaled by the error
g(〈~x
(i) , β~〉) to push g(〈~x
(i) , β~〉) down towards ~y
(i)
. 4
In this section we analyze the convergence of gradient descent. We begin by introducing a notion
of continuity for functions from R
n to R
m .
Definition 3.6 (Lipschitz continuity). A function f : R
n → R
m is Lipschitz continuous with
Lipschitz constant L if for any ~x, ~y ∈ R
n
||f (~y) − f (~x)|| 2 ≤ L ||~y − ~x|| 2. (63)
We focus on functions that have Lipschitz-continuous gradients. The following theorem shows
that these functions are upper bounded by a quadratic function.
Theorem 3.7 (Proof in Section 4.5). If the gradient of a function f : R
n → R is Lipschitz
continuous with Lipschitz constant L,
||∇f (~y) − ∇f (~x)|| 2 ≤ L ||~y − ~x|| 2 (64)
then for any ~x, ~y ∈ R
n
f (~y) ≤ f (~x) + ∇f (~x)
T (~y − ~x) +
||~y − ~x||
2 2.^ (65)
The quadratic upper bound immediately implies a bound on the value of the cost function after
k iterations of gradient descent.
Corollary 3.8. Let ~x
(i) be the ith iteration of gradient descent and αi ≥ 0 the ith step size, if ∇f
is L-Lipschitz continuous,
f
~x
(k+1)
≤ f
~x
(k)
− αk
αkL
∣∇f
~x
(k)
2
2
Proof. Applying the quadratic upper bound we obtain
f
~x
(k+1)
≤ f
~x
(k)
~x
(k)
~x
(k+1) − ~x
(k)
∣~x (k+1)^ − ~x (k)
2
2
The result follows because ~x
(k+1) − ~x
(k) = −αk∇f
~x
(k)
Lemma 3.11 (Backtracking line search). If the gradient of a function f : R
n → R is Lipschitz
continuous with Lipschitz constant L the step size obtained by applying a backtracking line search
using the Armijo rule with η = 0. 5 satisfies
αk ≥ αmin := min
α
0 ,
β
Proof. By Corollary 3.8 the Armijo rule with η = 0.5 is satisfied if αk ≤ 1 /L. Since there must
exist an integer i for which β/L ≤ α
0 β
i ≤ 1 /L this establishes the result.
We can now adapt the proof of Theorem 3.10 to establish convergence when we apply a back-
tracking line search.
Theorem 3.12 (Convergence with backtracking line search). If f is convex and ∇f is L-Lipschitz
continuous. Gradient descent with a backtracking line search produces a sequence of points that
satisfy
f
~x
(k)
− f (~x
∗ ) ≤
∣~x (0)^ − ~x ∗
2
2
2 αmin k
where αmin := min
α
0 ,
β L
Proof. Following the reasoning in the proof of Theorem 3.10 up until equation (73) we have
f
~x
(k)
− f (~x
∗ ) ≤
2 αi
∣x(k−1)^ − x∗
2
2
∣x(k)^ − x∗
2
By Lemma 3.11 αi ≥ αmin, so we just mimic the steps at the end of the proof of Theorem 3.10 to
obtain
f
x
(k)
− f (x
∗ ) ≤
k
∑^ k
i=
f
x
(k)
− f (x
∗ ) (80)
2 αmin k
∣x(0)^ − x∗
2
2
∣x(k)^ − x∗
2
2
∣x(0)^ − x∗
2
2
2 αmin k
The results that we have proved imply that we need O (1/) to compute a point at which the cost
function has a value that is close to the minimum. However, in practice gradient descent and
related methods often converge much faster.
The following theorem by Nesterov shows that no algorithm that uses first-order information can
converge faster than O (1/
) for the class of functions with Lipschitz-continuous gradients. The
proof is constructive, see Section 2.1.2 of [4] for the details.
Theorem 3.13 (Lower bound on rate of convergence). There exist convex functions with L-
Lipschitz-continuous gradients such that for any algorithm that selects x
(k) from
x
(0)
∇f
x
(0)
, ∇f
x
(1)
,... , ∇f
x
(k−1)
we have
f
x
(k)
− f (x
∗ ) ≥
∣x(0)^ − x∗
2
2
32 (k + 1)
2
This rate is in fact optimal. The convergence of O (1/
) can be achieved if we modify gradient
descent by adding a momentum term.
Algorithm 3.14 (Nesterov’s accelerated gradient descent). Set the initial point ~x
(0) to an arbi-
trary value in R
n
. Update by setting
y
(k+1) = x
(k) − αk∇f
x
(k)
x
(k+1) = βk y
(k+1)
(k) , (86)
where αk is the step size and βk and γk are nonnegative real parameters, until a stopping criterion
is met.
Intuitively, the momentum term y
(k) prevents the algorithm from overreacting to changes in the
local slope of the function. We refer the interested reader to [3, 4] for more details.
Example 3.15 (Digit classification). In this example we apply both gradient descent and accel-
erated gradient descent to train a logistic-regression model on the MNIST data set
1
. We consider
the task of determining whether a digit is a 5 or not. The feature vector ~xi contains the pixel
values of an image of a 5 (~yi = 1) or another number (~yi = 0). We use different numbers of
training examples to fit a logistic regression model. The cost function is maximized by running
gradient descent and accelerated gradient descent until the gradient is smaller than a certain value.
Figure 12 shows the time taken by both algorithms for different training-set sizes. 4
Cost functions used to fit models from data are often additive, in the sense that we can write them
as a sum of m terms, each of which often depends on just one measurement,
f (~x) =
m
∑^ m
i=
fi (~x). (87)
1 Available at http://yann.lecun.com/exdb/mnist/