Welcome back. In our last lesson, we completed our foundational tour of linear algebra by exploring the Singular Value Decomposition (SVD), connecting it directly to the concept of eigendecomposition. With that under our belt, we now pivot from the structure of matrices and transformations to the landscape of functions, a change that brings us to the heart of machine learning: optimisation.
Today's lesson addresses a concept that is arguably the most important dividing line in optimisation theory. We will explore convexity. Our goal is to understand what makes a function convex, why this property is so desirable, and how we can identify convex functions in practice. Understanding convexity is the key to understanding why algorithms like gradient descent can reliably find the "best" model parameters for a vast and important class of machine learning problems.
1. The Optimisation Landscape: Why Convexity?
When we train a machine learning model, we are typically trying to minimise a loss function. This function measures how poorly our model is performing. The parameters of our model are the inputs to this function, and we want to find the set of parameters that results in the lowest possible loss.
Imagine the loss function as a landscape with hills and valleys. Our goal is to find the lowest point in this entire landscape.

As the image suggests, this search is straightforward if the landscape is a simple, single "bowl". Any step we take that goes "downhill" will eventually lead us to the bottom. This is the world of convex optimisation.
However, if the landscape is rugged, with many valleys, we might find the bottom of a small, local valley and get stuck, mistakenly believing we've found the lowest point when a much deeper valley exists elsewhere. This is the challenge of non-convex optimisation, which is typical for complex models like neural networks.
For a significant portion of this course, we will focus on models where the loss function is convex, because it guarantees that simple optimisation strategies will find the one true best solution.
2. Defining Convexity: From Geometry to Algebra
The intuitive idea of a "bowl-shaped" function can be made mathematically precise. There are two common and equivalent ways to define a convex function.
Geometric Definition: The Chord Above the Graph
A function is convex if the line segment connecting any two points on its graph lies on or above the graph itself.

The inequality shown in the image, for , is the algebraic formalisation of this geometric picture. It states that the function value at a point between and is less than or equal to the value on the straight line connecting and .
A slightly more abstract but powerful way to think about this is through the function's epigraph—the set of all points lying on or above its graph. A function is convex if and only if its epigraph is a convex set.
The following video gives a great visual overview of these definitions.
Convexity and The Principle of Duality
This video from the channel Visually Explained provides clear, concise definitions for convex sets and convex functions.
First, watch the segment on convex sets to solidify that prerequisite concept. Then, continue with the definition of a convex function via its epigraph, and note the examples of common convex and non-convex functions.
3. The Power of Convexity: Local Minima are Global Minima
Now we come to the single most important property of convex functions for optimisation. For a convex function, any local minimum is also a global minimum.
This means if we use an algorithm (like gradient descent, which we'll study soon) and it finds a point where no small step can further decrease the function's value (a local minimum), we can be certain that we have found the best possible value (the global minimum). This completely eliminates the problem of getting stuck in a suboptimal valley.
This powerful result stems from the "tangent hyperplane" property of convex functions.
Convexity and The Principle of Duality
Let's return to the "Visually Explained" video to see why this property holds.
Watch the section explaining the dual definition of convexity and its implications for optimisation, starting from this point. Focus on the idea that a convex function's graph always lies above its tangent line (or hyperplane). This directly leads to the conclusion that if the gradient is zero, you must be at a global minimum.
As the video explains, if you find a point where the gradient is zero, the tangent line is horizontal. Since the entire function lies above this tangent, that point must be a global minimum. This is the theoretical guarantee that makes convex optimisation so powerful and reliable.
4. The Practitioner's Toolkit: How to Identify Convex Functions
Knowing that convexity is important is one thing; being able to determine if a given function is convex is another. Here are two primary methods.
4.1. Composition Rules (Building Blocks)
Many complex functions in machine learning are built from simpler pieces. If we know the pieces are convex, we can often deduce that the whole function is convex. Key rules include:
- Non-negative weighted sum: If and are convex, then is convex for any .
- Maximum: If and are convex, then is convex.
- Composition with an affine map: If is convex, then is also convex.
Let's see this in action with the objective function for Support Vector Machines (SVMs), a classic machine learning model.
[PDF] Exercises on Optimization for Machine Learning - Lamsade
This document contains a set of exercises and solutions. We will look at Exercise 1.1, which proves the convexity of the SVM objective function using the building block approach.
First, look at the objective function in Exercise 1.1. Then, read the corresponding solution. Notice how it deconstructs the function into a sum and maximum of simpler linear (and therefore convex) functions to prove the convexity of the whole expression.
This "calculus of convex functions" is a very common way to prove convexity for many machine learning loss functions.
4.2. The Hessian Condition
For twice-differentiable functions of multiple variables, there is a direct test analogous to checking if the second derivative is non-negative in the single-variable case. This test involves the Hessian matrix, which you'll recall from our first lesson is the matrix of second-order partial derivatives.
A twice-differentiable function is convex if and only if its Hessian matrix is positive semidefinite for all in its domain.
A symmetric matrix is positive semidefinite (PSD), denoted , if for all non-zero vectors . Since you're familiar with eigendecomposition, an equivalent condition is that all eigenvalues of a symmetric matrix must be non-negative.
Let's formalize this and see a worked example.
[PDF] Optimization for machine learning Lecture Notes on Convexity ...
This document provides the formal characterization of convex functions using their derivatives.
Please read the section "Convexity in dimension p ≥ 2". Pay close attention to Proposition 4.12, which states the equivalence between convexity and the Hessian being positive semidefinite (point (iv)).
Operations Research 10B: Hessian Matrix, Convex & Concave Functions
This video provides a very practical walkthrough of calculating a Hessian and testing for positive semidefiniteness.
Watch the following segments. I encourage you to pause the video and try the calculations yourself to engage actively with the material. First, understand what the Hessian is and how it's constructed: The Hessian matrix. Follow the example of computing the Hessian for a specific function: A calculation example. Learn the definition of a positive semidefinite matrix: Positive semidefinite. Finally, see how to test if the computed Hessian is positive semidefinite, thus proving the function is convex: An example test.
The Hessian test is a powerful, concrete tool that connects the abstract property of convexity to the calculus and linear algebra we have been studying.
5. A Stronger Guarantee: Strict and Strong Convexity
To conclude, it's worth knowing about two stronger forms of convexity that provide even better guarantees for optimisation.
-
Strictly Convex: The inequality in the definition becomes strict () for distinct points. Geometrically, the chord between any two points is strictly above the function's graph. The main benefit is that if a minimum exists, it is unique. The function is convex but not strictly convex at , while is strictly convex.
-
Strongly Convex: A function is -strongly convex if is convex for some . This is a very strong condition. It implies strict convexity, but also guarantees that the function has a quadratic lower bound around its minimum. This is crucial for proving fast convergence rates for optimisation algorithms. For example, the objective for ridge regression is strongly convex, while ordinary least squares is only convex.
You can read the formal definitions in the lecture notes we used earlier if you're interested.
[PDF] Optimization for machine learning Lecture Notes on Convexity ...
This resource formally defines strict and strong convexity.
You can skim the sections Strictly convex functions and Strongly convex functions to see the mathematical definitions. The key takeaway is that they provide stronger guarantees (uniqueness and faster convergence).
Conclusion
In this lesson, we introduced the fundamental concept of convexity and its central role in optimisation. We've seen that while many machine learning problems are non-convex and hard, a large and important class are convex, which allows us to find guaranteed global solutions.
Here are the key takeaways:
- Convex functions are "bowl-shaped," meaning the line segment between any two points on the graph lies on or above the graph.
- The primary role of convexity in optimisation is that any local minimum is also a global minimum, which makes finding the optimal solution reliable.
- We can identify convex functions using composition rules (building them from convex parts) or by checking if the Hessian matrix is positive semidefinite.
- Strict and strong convexity are stronger conditions that guarantee a unique minimum and can be used to prove faster convergence rates for optimisation algorithms.
We now understand what kind of functions are "easy" to optimise. In our next lesson, we will begin learning how to perform this optimisation under constraints by studying the method of Lagrange multipliers.