Quadratic Programming
Quadratic cost over straight walls bends the bowls into ellipses. The answer is a projection: the closest feasible point to the free minimum.
Why Does This Exist?
Least squares wants the closest fit. Portfolios want the lowest variance. SVMs want the widest margin. All three minimize a quadratic cost over straight walls. Linear programming cannot bend, so it cannot trade smoothly between objectives. Quadratic programming bends exactly once and stays tractable when its matrix is positive semidefinite.
The form is minimize over and , with . KKT becomes a complementarity system solved by active set or interior point methods. It follows linear programming as the curved sibling inside convex optimization.
The one idea you need first
means everywhere: bowls, never saddles. Then any KKT point is global. Indefinite makes the problem NP-hard in general. The PSD assumption is the whole tractability story, so checking it comes before solving.
Think of It Like This
A ball in an elliptical bowl behind a straight fence
Roll a ball in an elliptical bowl parked inside a straight fence. Free, it settles at the bowl bottom. Fenced, it settles at the closest fence point to that bottom, pressed against the active rail. The fence never curves the bowl. It only blocks part of it.
The contact point is the projection under the bowl metric. The rails that touch are the active set. The price of pushing against each rail is its multiplier.
Where it stops: real fences have corners that trap balls ambiguously, which is why active set methods track exactly which rails touch instead of guessing from the final position alone.
How It Actually Works
Unconstrained, the answer solves . Constrained, stationarity says plus primal feasibility, , and complementary slackness. Active set methods guess the touching walls, solve the equality problem, and update the guess. Interior point methods smooth slackness with a barrier and follow the central path. SVM duals, Markowitz portfolios, and MPC controllers are all convex QPs under the hood.
Worked example
Minimize subject to . The unconstrained minimum at violates the wall. By symmetry at the optimum, so the constraint gives with value .
KKT certifies it. Write the wall as with multiplier . Stationarity gives and . At the halves , and slackness holds because . The distance from the origin is . Any feasible pair gives with equality only at the halves. Certified projection.
Code
The point is the check: evaluate the projection and confirm no feasible point beats it.
import numpy as np
x = y = 0.5print(round(x**2 + y**2, 2)) # -> 0.5print(round(float(np.sqrt(x**2 + y**2)), 3)) # -> 0.707
# scan the feasible line x + y = 1best = min(x0**2 + (1 - x0) ** 2 for x0 in [0.0, 0.25, 0.5, 0.75, 1.0])print(round(best, 2)) # -> 0.5Value at distance , and the scan along the wall never goes below .
Watch Out For
Solving with indefinite Q as if convex
Factorization can succeed formally on indefinite and return a saddle or a local maximum certified by nothing. Portfolio optima with negative variance directions are the classic casualty: the solver reports success while the model exploits a direction the math said could not exist.
Symptom: an objective better than any feasible convex bound, or weights that explode along one direction. Fix: check the smallest eigenvalue of before solving. If it is negative, convexify, regularize, or switch to global methods.
Warm starting active set across big changes
Active set methods fly on small sequential QPs like MPC steps and crawl when the active set churns completely. Reusing stale wall guesses across regime changes wastes more pivots than a cold start.
Symptom: iterations tripled after a model change while the problem size stayed fixed. Fix: track active set churn and restart or switch to interior point when it spikes. If the touch pattern changed, the warm start is cold comfort.
The Quick Version
- Convex QP needs . Then KKT points are global projections.
- over lands at with value and distance .
- The multiplier prices the wall, with zero slack at the optimum.
- Active set tracks touching walls. Interior point smooths them.
- SVMs, portfolios, and MPC are convex QPs in disguise.
- Indefinite voids everything. Check eigenvalues first.