Introduction
In our last lesson, we learned to interpret the gradient vector as a diagnostic tool. We saw that when the gradient's magnitude approaches zero, our optimization algorithm stops. While this could mean we've found the best possible solution (a global minimum), it could also mean we're stuck in a suboptimal "valley" known as a local minimum. This problem is especially relevant in fields like computational biology, where the energy landscape for protein folding is fraught with such local minima.
This lesson introduces a fundamental concept that determines whether this problem of getting "stuck" can even occur: convexity. You will learn to distinguish between convex and non-convex functions, which visually correspond to simple "bowls" versus complex "mountain ranges." Most importantly, you will understand the powerful guarantee that convexity provides: for a convex function, any local minimum is automatically the global minimum. This property separates many classical machine learning algorithms from modern deep learning, and understanding it is key to diagnosing why some models are easy to optimize while others are not.
What is a Convex Function?
At its heart, convexity is a geometric property of a function's shape. A function is convex if it is "bowl-shaped," curving upwards everywhere. A function that has multiple valleys and peaks, like a mountain range, is non-convex.

The formal geometric definition is simple but powerful: a function is convex if the straight line segment connecting any two points on its graph lies on or above the graph itself. If this line segment ever dips below the function's curve, the function is non-convex.

The following article introduces this concept clearly.
Convexity, Curvature, and Why Your Optimizer Gets Lost
This article provides an excellent visual and mathematical introduction to convexity.
Read the first section, "What is Convexity?". Focus on the geometric definition involving the line segment between two points. The mathematical formula presented is the formal expression of this geometric idea.
The Guarantee: Any Local Minimum is a Global Minimum
The reason we care so much about convexity in optimization is the incredible guarantee it provides. For a convex function, the problem of getting stuck in a suboptimal local minimum completely vanishes.
If a function is convex, any local minimum is also a global minimum.
This means that if our gradient descent algorithm finds a flat spot (a point with a zero gradient), we can be certain we have found the best possible solution. The following video offers a fantastic and intuitive proof-by-contradiction for why this is true, using only the geometric definition of convexity.
Convex: Local vs Global Minimum
The channel "Mohamed Omar" provides a clear, step-by-step argument for this crucial property of convex functions.
Watch the full video (it's about 11 minutes). First, pay attention to how he defines convexity using the line segment idea, without needing calculus. Then, follow his proof by contradiction, which shows that if you assume a local minimum exists that is not a global minimum, you violate the definition of convexity.
For a more formal, written version of the same proof, you can refer to this document from Stanford. The logic is identical to what you saw in the video.
These notes from Stanford's AI Lab formalize the concepts we are discussing.
In the subsection "Consequences of convexity," read the statement and proof of Proposition 1. Notice how the argument hinges on choosing a point on the line segment between the supposed local and global minima to create a contradiction.
From Abstract Geometry to ML Loss Landscapes
Now, let's connect this back to our goal of training models. The "functions" we are optimizing are the loss functions, and their inputs are the model's parameters (weights and biases).
A convex loss landscape is a paradise for optimization. It's a single, smooth hyper-dimensional bowl. No matter where you initialize your model's parameters, gradient descent will guide you steadily downhill to the one and only global minimum.
A non-convex loss landscape, on the other hand, is a treacherous mountain range. It's filled with countless local minima, plateaus, and saddle points. Where you start your descent (your random parameter initialization) dramatically affects which valley you end up in. Two models trained with the exact same data and architecture but different random seeds can converge to different solutions with different performance.
This article beautifully visualizes these two scenarios.
Convexity, Curvature, and Why Your Optimizer Gets Lost
We return to the same article to see these concepts applied directly to ML loss surfaces.
Read the sections titled "Convex landscape" and "Non-convex landscape". Study the 3D surfaces, contour plots, and the paths of gradient descent. The visuals clearly show why initialization doesn't matter for the convex case but is critical for the non-convex one. Finally, read the crucial section "Why Convexity Matters in Machine Learning". This part explains which common ML models have which type of loss surface.
As the article highlights:
- Convex Loss Functions are the hallmark of many classical machine learning algorithms. Linear regression with Mean Squared Error (MSE) loss and Logistic Regression are prime examples. Their loss surfaces are convex, which means we are guaranteed to find the single best set of parameters.
- Non-Convex Loss Functions are characteristic of almost all deep neural networks. The combination of many layers and non-linear activation functions (like ReLU) creates an incredibly complex and rugged loss landscape. This is why training deep learning models is often described as a "black art," heavily reliant on smart initialization, sophisticated optimizers (like Adam), and careful hyperparameter tuning.
Your interest in AlphaFold is highly relevant here. The protein folding problem involves finding the lowest energy state of a protein chain on an extremely non-convex energy landscape. The revolutionary success of AlphaFold comes from using a deep learning model that is exceptionally good at navigating this treacherous, high-dimensional space to find the global minimum corresponding to the protein's native structure.
Conclusion
In this lesson, you've grasped one of the most important dichotomies in machine learning optimization. The distinction between convex and non-convex loss surfaces underpins why some models are "easy" to train and others are notoriously difficult.
Key Takeaways:
- Convex functions are "bowl-shaped." The line segment connecting any two points on their graph lies on or above the graph.
- Non-convex functions can have multiple peaks and valleys, like a mountain range.
- The crucial guarantee of convexity is that any local minimum is also a global minimum. This makes optimization reliable and predictable.
- Classical models like linear and logistic regression have convex loss functions.
- Neural networks have highly non-convex loss functions, making their training sensitive to initialization and requiring advanced optimization techniques.
In our last few lessons, we've visualized the loss surface and understood the gradient that guides us on it. In the next lesson, we will finally put it all together and implement the gradient descent algorithm itself. You will trace its steps on a 2D loss surface and see firsthand how the choices we make, like the step size or "learning rate," determine whether our algorithm successfully navigates these landscapes to find a minimum.