Lagrangian duality

Also known as: Lagrange duality · dual problem

On this page 7

Lagrangian duality is the principle that every constrained optimization problem, called the primal problem, has an associated dual problem built from its Lagrangian, and that the optimal value of the dual always provides a lower bound on the primal optimum for minimization. In optimization for artificial intelligence, Lagrange duality underpins support vector machines, constrained reinforcement learning, fairness-constrained training and many distributed solvers.

The idea converts hard constraints into weighted penalties. Each constraint receives a Lagrange multiplier, and the dual problem searches for the multipliers that make the penalized problem as informative as possible. When the gap between the two optimal values closes, solving the dual is equivalent to solving the original task.

How the Lagrangian dual problem is constructed

The dual problem is constructed in three steps: form the Lagrangian, minimize it over the primal variables, then maximize the result over the multipliers. For a problem that minimizes f(x) subject to inequality constraints g_i(x) ≤ 0 and equality constraints h_j(x) = 0, the Lagrangian is L(x, λ, ν) = f(x) + Σ λ_i g_i(x) + Σ ν_j h_j(x), with λ_i ≥ 0 for every inequality.

Minimizing the Lagrangian over x for fixed multipliers yields the dual function g(λ, ν). This function is always concave, even when the primal problem is non-convex, because it is a pointwise infimum of affine functions in the multipliers. The dual problem maximizes this concave function, so it is a convex optimization problem regardless of the structure of the original task.

The following table summarizes the components of the construction and their roles.

ComponentDefinitionRole
Primal problemMinimize f(x) under constraintsThe task that must actually be solved
LagrangianObjective plus weighted constraintsRelaxes constraints into penalties
Dual functionInfimum of the Lagrangian over xProduces a lower bound for each multiplier choice
Dual problemMaximize the dual function, λ ≥ 0Finds the tightest available bound
Duality gapPrimal optimum minus dual optimumMeasures how much the bound loses
Building blocks of the Lagrangian dual

Weak duality, strong duality and the duality gap

Weak duality states that the dual optimum d* never exceeds the primal optimum p*, so d* ≤ p* holds for every problem. The proof is short: for any feasible x and any λ ≥ 0, the penalty terms are non-positive, so the Lagrangian cannot exceed f(x), and its infimum cannot either.

Strong duality means that the gap is exactly zero, d* = p*. It does not hold in general, but it does hold for convex problems that satisfy a constraint qualification. The best-known one is Slater’s condition: the problem is convex and some point strictly satisfies every non-affine inequality constraint. Linear programs enjoy strong duality whenever either problem has a finite optimum.

The table below contrasts the three situations a practitioner encounters.

Problem classTypical gapPractical consequence
Linear programmingZero when an optimum existsDual solves the primal exactly
Convex with Slater pointZeroDual solution recovers primal solution
Convex without qualificationPossibly positiveDual bound may be loose
Non-convex problemsOften positiveDual gives a relaxation bound only
Integer programsUsually positiveUsed for bounds in branch and bound
Duality outcomes by problem class

When strong duality holds and both optima are attained, the primal and dual solutions satisfy the Karush-Kuhn-Tucker conditions. The most informative of these is complementary slackness: λ_i g_i(x) = 0, so a multiplier can be positive only when its constraint is active at the optimum.

Why multipliers act as shadow prices

An optimal Lagrange multiplier measures the sensitivity of the optimal value to its constraint. If constraint i is relaxed from g_i(x) ≤ 0 to g_i(x) ≤ u, the optimal value changes at a rate of roughly minus λ_i per unit of u under standard regularity. Economists call this a shadow price: the marginal value of one more unit of a scarce resource.

This interpretation is useful in machine learning. In a fairness-constrained classifier, a large multiplier on a demographic parity constraint signals that the constraint is costing substantial accuracy. In a constrained Markov decision process, the multiplier on a safety budget tells the engineer how much reward is sacrificed to keep expected violations under the limit.

Where Lagrange duality appears in machine learning

Duality changes which variables an algorithm works with, and that change is often the source of a computational advantage. The dual of the soft-margin support vector machine depends on the data only through inner products, which is exactly what allows the kernel trick. The dual also has one variable per training example, which favors problems with many features and moderate sample counts.

The next table lists common applications and what duality contributes to each.

ApplicationWhat the dual providesTypical method
Support vector machinesKernelized quadratic programSequential minimal optimization
Constrained reinforcement learningAdaptive penalty on cost budgetsPrimal-dual policy gradient
Fair and robust trainingLearned constraint weightsGradient descent-ascent
Distributed optimizationSeparable subproblems per nodeDual decomposition, ADMM
Optimal transportPotential functions instead of a planSinkhorn iterations on the entropic dual
Combinatorial relaxationBounds for pruning a search treeSubgradient method on the dual
Applications of Lagrangian duality in AI

Dual decomposition deserves special mention. When the objective is a sum of terms coupled only through linear constraints, the Lagrangian separates into independent pieces, so each machine or agent can solve its own piece while a coordinator updates the shared multipliers. ADMM refines this scheme with an augmented penalty that improves convergence.

Limitations and common mistakes

Duality is powerful but easy to misapply. The most frequent error is to assume strong duality without checking convexity or a constraint qualification, which can produce a dual solution that does not correspond to any feasible primal point.

PitfallCauseRemedy
Unrecoverable primal solutionGap is positive or minimizer is not uniqueAdd a proximal or augmented term
Oscillating multipliersNon-smooth dual functionUse averaging or diminishing step sizes
Unbounded dual functionLagrangian has no finite minimum in xAdd bounds or regularization to x
Sign errors on multipliersInequalities written in the wrong directionStandardize constraints as g(x) ≤ 0
Frequent pitfalls with dual methods

Another misconception is that a zero duality gap guarantees a fast algorithm. The dual function is frequently non-differentiable, so plain subgradient ascent converges slowly, at a rate of about O(1/√k) after k iterations. Smoothing, augmented Lagrangian methods and interior-point approaches are usually preferred when precision matters.

In plain words

Many problems ask for the best answer while obeying rules. Lagrangian duality turns each rule into a price for breaking it. You then look for the best answer when breaking rules costs money.

Next, you adjust the prices. A rule that is broken too often gets a higher price. A rule that is never close to breaking gets a price of zero. The best prices give a guaranteed floor under the true answer. For well-behaved problems, that floor is exactly the true answer.

So duality gives two views of the same problem. One view searches for the answer. The other view searches for the fair prices of the rules.

A real-world example

A logistics team trains a delivery-routing policy with reinforcement learning. The goal is to maximize on-time deliveries, but the expected number of late-night driving hours must stay below 40 hours per week across the fleet. Writing this as a constrained Markov decision process, the team introduces one Lagrange multiplier for the driving-hours budget.

Training alternates two updates. The policy improves its reward minus the multiplier times the excess driving hours, and the multiplier rises whenever the measured hours exceed 40 and falls when they stay under. After several thousand episodes, the multiplier settles near a stable value and the policy meets the 40-hour budget while losing only a few percent of on-time deliveries.

The settled multiplier also serves the planning managers. Its value states how many on-time deliveries each additional permitted hour would buy, which gives them a quantitative basis for negotiating the budget with drivers.