In our last lesson, we transformed constrained optimization problems by creating the Lagrangian and formulating the primal problem: finding the min-max of this new function. This allowed us to derive the KKT conditions, which characterize an optimal solution. Today, we delve deeper into this powerful framework by exploring what happens when we swap the order of minimization and maximization.
This lesson introduces the concept of Lagrangian duality. We will derive the dual problem from the Lagrangian and explore its relationship with the primal problem we've already seen. You will learn about weak duality, a property that always holds, and the more powerful strong duality, which holds under specific conditions. Understanding duality is essential; it provides an alternative, often simpler, way to solve optimization problems and offers profound insights into their structure, which is foundational to understanding algorithms like Support Vector Machines.
From Primal to Dual
Let's recall the standard constrained optimization problem and its primal formulation, which we established in the previous lesson.
Primal Problem:
where the Lagrangian is . The value is the optimal value of our original problem.
The central idea of duality is to consider what happens if we switch the order of the inf and sup. This gives rise to the dual problem.
Dual Problem:
To make sense of this, we first define the inner part, inf_x L(x, u, v), as a new function.
The Lagrange Dual Function
For a fixed set of multipliers , the Lagrange dual function is defined as the infimum of the Lagrangian over the primal variables :
Note that this infimum is taken over all in the domain, without regard for the original constraints.
A fascinating and crucial property of the dual function is that it is always concave, regardless of whether the original problem was convex. This is because it is the pointwise infimum of a family of affine functions of . Since we will be maximizing this function, this means the dual problem is a convex optimization problem, which is often much easier to solve.
The following video provides an excellent intuitive walkthrough of defining the dual function.
Lecture 8 | Convex Optimization I (Stanford)
This lecture from Stephen Boyd's Convex Optimization course at Stanford provides a clear and intuitive introduction to the Lagrange dual function.
Watch the segment from the introduction of the dual function. Pay attention to how it's defined as the minimum of the Lagrangian over x and the proof that it is always a concave function.
With the dual function defined, the dual problem is simply to find the best possible value of , subject to the dual feasibility constraints.
The following reading formally defines the Lagrange dual function and the resulting dual problem.
Lecture 11: October 8 11.1 Primal and dual problems
These lecture notes from CMU's Convex Optimization course give a concise, formal definition of the dual problem.
Please read the first page, from the beginning up to the start of Section 11.2. Focus on the definitions of the Lagrange dual function g(u, v) and the Lagrange dual problem. Notice that the dual problem is always a convex optimization problem (maximizing a concave function).
Weak Duality: A Universal Lower Bound
The dual problem is interesting because its optimal value, , provides a lower bound on the optimal value of the primal problem, . This relationship, known as weak duality, always holds for any optimization problem, convex or not.
Weak Duality Theorem: .
This is a direct consequence of the max-min inequality, which states that for any function , we have:
In our case, is the Lagrangian , is , and is .
The proof is remarkably simple but profound. It establishes that for any choice of dual variables that are dual-feasible, the value is a valid lower bound on the true optimal value . The dual problem, therefore, can be interpreted as a search for the tightest possible lower bound on the primal objective.
9. Lagrangian Duality and Convex Optimization
This video from the Inside Bloomberg channel provides one of the clearest and most general proofs of the max-min inequality, which is the basis for weak duality.
Watch the segment from this section. Follow the simple, step-by-step logic that proves sup inf <= inf sup for any function over any two sets. This elegant proof demonstrates why weak duality is a universal property.
Strong Duality and Slater's Condition
While knowing that is useful, the real power of duality is unlocked when the inequality becomes an equality. This is called strong duality.
Strong Duality: .
When strong duality holds, the duality gap—the difference —is zero. This means we can find the optimal value of the (potentially difficult, non-convex) primal problem by solving the (always convex) dual problem.
Strong duality does not hold for all problems. However, for convex optimization problems, it holds under fairly mild conditions. The most common of these is Slater's condition.
Slater's Condition: For a convex optimization problem, if there exists a point that is strictly feasible—meaning it satisfies all inequality constraints with strict inequality ()—then strong duality holds.
For many problems in machine learning and engineering, this condition is naturally satisfied. If you have a constraint on power being less than or equal to 100mW, it's almost certain that a design using 99.9mW exists. The existence of such a point with a "margin" is enough to guarantee strong duality.
[PDF] Lagrangian Duality Theory - Stanford University
These notes from a Stanford optimization course formally state the strong duality theorem.
Read the section titled "Lagrangian Strong Duality Theorem" (the full theorem statement). Pay attention to the requirements: the problem must be convex, and there must be an interior-point feasible solution. This "interior-point" condition is a formal name for Slater's condition.
The following video discusses the distinction between weak and strong duality and provides a practical perspective on why Slater's condition is often a reasonable assumption.
Lecture 8 | Convex Optimization I (Stanford)
In this part of his lecture, Stephen Boyd discusses weak and strong duality, emphasizing why strong duality is so important and explaining the role of constraint qualifications like Slater's.
Watch the segment from this part of the lecture. His commentary on why you can often assume Slater's condition holds in practical applications, particularly in machine learning, provides valuable context beyond the pure mathematics.
Geometric Interpretation of Duality
A powerful way to visualize duality is to consider the set of achievable values for the constraints and the objective. Let's imagine a simple problem with one inequality constraint . We can define a set in a 2D plane, where each point in the set corresponds to the values for some .

-
The primal optimal value is the minimum objective value we can achieve while being feasible (). Geometrically, this is the lowest point of the set that touches the -axis or is to its left. In the diagram, this is marked as .
-
The dual function for a given can be shown to be the vertical intercept of a supporting hyperplane with slope to the set . The line is one such supporting line.
-
The dual optimal value is the maximum of these intercepts over all valid slopes (). It is the highest point on the -axis that can be touched by a non-vertical supporting hyperplane from below.
The duality gap is the vertical distance between and . From the picture, it's clear that . If the set is convex and doesn't have any strange vertical boundaries at , the supporting hyperplane will be able to "slide up" until it touches the point , making the duality gap zero. This is the geometric essence of strong duality.
Lecture 8 | Convex Optimization I (Stanford)
This final segment from Stephen Boyd's lecture provides a clear walkthrough of this geometric interpretation.
Watch from this final section. This visualization is key to cementing your intuition about what the primal problem, dual problem, and duality gap represent.
Conclusion
In this lesson, we have moved from the primal formulation of a constrained optimization problem to its dual. This "dual perspective" is a cornerstone of modern optimization and machine learning.
The key takeaways are:
- The Lagrange dual problem is formed by swapping the
minandmaxin the primal formulation. It involves maximizing the Lagrange dual function . - The dual problem is always a convex optimization problem, which is a significant advantage.
- Weak duality () always holds, meaning the dual problem provides a lower bound on the true optimal value.
- Strong duality () holds for convex problems that satisfy certain "constraint qualifications," the most common being Slater's condition. When strong duality holds, we can solve the primal by solving the dual.
- The duality gap () can be visualized as the space between the feasible optimum and the best supporting hyperplane from below.
This concludes our module on the mathematical foundations of optimization. We have built a powerful toolkit, starting from simple gradient descent and culminating in the elegant theory of Lagrangian duality. You now have the necessary mathematical machinery to understand how many of the classic machine learning algorithms are trained.
In our next lesson, we will pivot from optimization to the foundations of probability in machine learning. We will begin by deriving the principle of Maximum Likelihood Estimation (MLE), a fundamental framework for fitting probabilistic models to data. This will shift our focus from how we find the minimum of a function to what function we should be minimizing in the first place.