What is constrained optimization?
Constrained optimization finds the minimum or maximum of a function when the inputs must satisfy extra conditions, such as staying on a curve or within a budget. The classic tool is the method of Lagrange multipliers: at a constrained optimum, the gradient of the objective is a multiple of the gradient of the constraint, ∇f = λ∇g. For inequality constraints this generalizes to the Karush–Kuhn–Tucker (KKT) conditions.
In machine learning, constraints show up in support vector machines (maximize the margin subject to classifying every point correctly), in weight-norm limits and L2 regularization, in fairness and safety constraints, and in the KL-divergence trust region used by TRPO and in RLHF. Many penalty terms in loss functions are constraints written in Lagrangian form.
Key ideas
- A constraint limits where the solution can be, and it can only make the best objective value worse or equal.
- At a constrained optimum, ∇f is parallel to the constraint gradient ∇g.
- The Lagrange condition ∇f = λ∇g turns a constrained problem into a system of equations.
- The multiplier λ is the sensitivity of the optimal value to the constraint level.
- Inequality constraints follow the KKT conditions, where λ is zero unless the constraint is active.
- L2 regularization is the penalty form of a constraint on the weight norm.
Common questions
What is the Lagrangian?
The Lagrangian combines the objective and constraints into one function: L(x, λ) = f(x) − λ·(g(x) − c). Setting its gradient to zero with respect to both x and λ recovers ∇f = λ∇g and the constraint itself. Sign conventions vary between textbooks, so λ may appear with a plus sign.
What are the KKT conditions?
They are the optimality conditions for problems with inequality constraints. They require stationarity of the Lagrangian, feasibility, a non-negative multiplier for each inequality, and complementary slackness: each multiplier times its constraint slack equals zero. For convex problems that satisfy a mild regularity condition, the KKT conditions are both necessary and sufficient.
How do support vector machines use constrained optimization?
A hard-margin SVM minimizes |w|²/2 subject to every training point being on the correct side of the margin. Its Lagrange dual depends on the data only through dot products between points, which is what allows the kernel trick. Points with nonzero multipliers are the support vectors.
How are constraints handled in neural network training?
Usually through penalties added to the loss, such as weight decay, or through projection after each step, such as clipping weights or renormalizing them to a maximum norm. Methods like TRPO enforce a trust-region constraint on the policy change directly. Exact constrained solvers are rare at deep learning scale.
Related explainers
- Convexity, Minima & Saddle Points — Why some optimization problems are harder than others
- Partial Derivatives & Gradients — Extend single-variable derivatives to functions of multiple variables and gradient vectors
- Regularization — Dropout, L1, and L2 — keeping models honest
- Support Vector Machines — Maximum margin classifiers and the kernel trick
- Gradient Descent — Optimizing by following the slope downhill
- Norms & Distance Metrics — L1, L2, cosine similarity — measuring closeness in vector spaces
References
- Boyd & Vandenberghe, "Convex Optimization", ch. 5 Duality (free PDF)
- Deisenroth, Faisal & Ong, "Mathematics for Machine Learning", ch. 7 Continuous Optimization
- Cortes & Vapnik (1995), "Support-vector networks", Machine Learning
- Schulman et al. (2015), "Trust Region Policy Optimization"
Last updated