Convex functions
Ideally we want our cost/loss function to be convex(concave).
First we give the definition of a convex set: A set C in
\mathbb{R}^n is said to be convex if, for all x and y in C and
all t \in (0,1) , the point (1 − t)x + ty also belongs to
C. Geometrically this means that every point on the line segment
connecting x and y is in C as discussed below.
The convex subsets of \mathbb{R} are the intervals of
\mathbb{R}. Examples of convex sets of \mathbb{R}^2 are the
regular polygons (triangles, rectangles, pentagons, etc...).
Convex function: Let X \subset \mathbb{R}^n be a convex
set. Assume that the function f: X \rightarrow \mathbb{R} is
continuous, then f is said to be convex if
f(tx_1 + (1-t)x_2) \leq tf(x_1) + (1-t)f(x_2)
for all
x_1, x_2 \in X and for all t \in [0,1].
If \leq is replaced with a strict inequality in the
definition, we demand x_1 \neq x_2 and t\in(0,1) then f is said
to be strictly convex. For a single variable function, convexity means
that if you draw a straight line connecting f(x_1) and f(x_2), the
value of the function on the interval [x_1,x_2] is always below the
line as discussed below.
In the following we state first and second-order conditions which
ensures convexity of a function f. We write D_f to denote the
domain of f, i.e the subset of R^n where f is defined. For more
details and proofs we refer to: [S. Boyd and L. Vandenberghe. Convex Optimization. Cambridge University Press](http://stanford.edu/boyd/cvxbook/, 2004).
First order condition: Suppose f is differentiable (i.e \nabla f(x) is well defined for
all x in the domain of f). Then f is convex if and only if D_f
is a convex set and f(y) \geq f(x) + \nabla f(x)^T (y-x) holds
for all x,y \in D_f. This condition means that for a convex function
the first order Taylor expansion (right hand side above) at any point
is a global under estimator of the function. To convince yourself you can
make a drawing of f(x) = x^2+1 and draw the tangent line to f(x) and
note that it is always below the graph.
Second order condition: Assume that f is twice
differentiable, i.e the Hessian matrix exists at each point in
D_f. Then f is convex if and only if D_f is a convex set and its
Hessian is positive semi-definite for all x\in D_f. For a
single-variable function this reduces to f''(x) \geq 0. Geometrically this means that f has nonnegative curvature
everywhere.
This condition is particularly useful since it gives us an procedure for determining if the function under consideration is convex, apart from using the definition.
The next result is of great importance to us and the reason why we are
going on about convex functions. In machine learning we frequently
have to minimize a loss/cost function in order to find the best
parameters for the model we are considering.
Ideally we want the
global minimum (for high-dimensional models it is hard to know
if we have local or global minimum). However, if the cost/loss function
is convex the following result provides invaluable information:
Any minimum is global for convex functions.
Consider the problem of finding x \in \mathbb{R}^n such that f(x)
is minimal, where f is convex and differentiable. Then, any point
x^* that satisfies \nabla f(x^*) = 0 is a global minimum.
This result means that if we know that the cost/loss function is convex and we are able to find a minimum, we are guaranteed that it is a global minimum.