Foundations to Frontier
Tests
A. Mathematical Foundations › A6 Optimization › Convex optimization

Optimality Conditions

How do you know you've found the optimum? Without constraints, a convex function is minimized exactly where its gradient vanishes. With constraints, the gradient usually doesn't vanish; instead, no feasible direction can go downhill, which means the negative gradient must point straight out of the feasible set (into the normal cone). You will learn the variational inequality, normal cones, the projection fixed-point characterization, conditions for boxes, balls and simplices, projected gradient descent, and verify optimality in a non-negative spectral unmixing problem.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Pressed against the fence

A ball rolling in an open bowl stops at the bottom, where the ground is flat. Put a fence across the bowl so the bottom is out of reach, and the ball rolls until it presses against the fence and stops there. The ground isn’t flat at that point; it still slopes downhill, but downhill points straight through the fence.

That’s the optimality condition with constraints: you’re at the best allowed point when every direction you’re allowed to move goes uphill (or stays level).

At a constrained optimum, the downhill direction points out of the set
feasible set:
x* = (1.000, -0.400) · ∇f(x*) = (-1.00, 0.00) · −∇f lies in the normal cone (on an edge: a single normal direction)
Grey dot: the unconstrained minimum c. Orange: the constrained minimum x* and −∇f(x*). Green rays: the normal cone, directions that point "straight out" of the set at x*. If c is feasible, x* = c and ∇f = 0. Otherwise x* is on the boundary and −∇f is a non-negative combination of the outward normals of the active constraints: exactly what the KKT multipliers (A6.2-5) encode. At a corner the cone is a whole wedge.
Why engineers care

Solvers stop when an optimality test passes. Engineers use the same conditions to verify a solution, read off which constraints are binding (which actuator is saturated, which safety limit is active), and design fast special-purpose solvers.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Without constraints, a smooth convex function is minimized where its slope is…
  2. 2. With a fence, the ball stops where downhill points…
  3. 3. At a constrained optimum on the boundary, is ∇f zero?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Unconstrained

For differentiable convex ff: x⋆x^\star is a global minimizer iff ∇f(x⋆)=0\nabla f(x^\star) = 0. Convexity makes the first-order condition sufficient as well as necessary.

Constrained to a convex set C

x⋆∈Cx^\star\in C minimizes a differentiable convex ff over CC iff

∇f(x⋆)⊤(z−x⋆)≥0for all z∈C\nabla f(x^\star)^\top(z - x^\star)\ge0\qquad\text{for all } z\in C

No feasible direction z−x⋆z - x^\star is a descent direction. This is the variational inequality.

1-D example

min⁡(x−3)2\min(x - 3)^2 over [0,2][0, 2]. The unconstrained minimum 3 is infeasible, so x⋆=2x^\star = 2 and f′(2)=−2≠0f'(2) = -2\ne0. The only feasible direction from 2 is to the left (z−2≤0z - 2\le0), and f′(2)(z−2)=−2(z−2)≥0f'(2)(z - 2) = -2(z - 2)\ge0. ✓

📝 Quick check (Level 1)
0/3 answered
  1. 1. min (x − 3)² over [0, 2] is attained at…
  2. 2. The variational inequality says ∇f(x*)ᵀ(z − x*) is … for feasible z
  3. 3. For convex f, ∇f(x*) = 0 is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

Normal cones

The normal cone of CC at xx is NC(x)={v:v⊤(z−x)≤0 ∀z∈C}N_C(x) = \{v : v^\top(z - x)\le0\ \forall z\in C\}. The optimality condition becomes

−∇f(x⋆)∈NC(x⋆)-\nabla f(x^\star)\in N_C(x^\star)
  • Interior point: NC={0}N_C = \{0\}, so ∇f=0\nabla f = 0.
  • Smooth boundary (ball): NCN_C is the outward normal ray.
  • Corner (box, polytope): NCN_C is the cone spanned by the outward normals of the active constraints. Their coefficients are the KKT multipliers (A6.2-5).

Concrete sets

  • Box l≤x≤ul\le x\le u: gi=0g_i = 0 if li<xi<uil_i < x_i < u_i; gi≥0g_i\ge0 if xi=lix_i = l_i; gi≤0g_i\le0 if xi=uix_i = u_i.
  • Non-negativity x≥0x\ge0: g≥0g\ge0, x≥0x\ge0 and xigi=0x_ig_i = 0 (complementarity).
  • Ball: x⋆=cx^\star = c if ∥c∥≤r\|c\|\le r, else rc/∥c∥rc/\|c\| for f=∥x−c∥2f = \|x - c\|^2.

Fixed-point form and projected gradient

x⋆x^\star is optimal iff x⋆=PC(x⋆−η∇f(x⋆))x^\star = P_C(x^\star - \eta\nabla f(x^\star)) for any η>0\eta > 0. This suggests projected gradient descent, x←PC(x−η∇f(x))x\leftarrow P_C(x - \eta\nabla f(x)), which converges at the same rates as GD when η=1/L\eta = 1/L. The gradient mapping Gη(x)=(x−PC(x−η∇f))/ηG_\eta(x) = (x - P_C(x - \eta\nabla f))/\eta replaces ∇f\nabla f as the stopping measure.

🐍 Exercise 1: projected gradient on a box
Implement projected gradient descent and the gradient mapping. Solve a box-constrained quadratic, compare with brute force, and verify that ∇f(x*) ≠ 0 but −∇f points out through the active bounds.
📝 Quick check (Level 2)
0/3 answered
  1. 1. At an interior point, the normal cone is…
  2. 2. For x ≥ 0, optimality requires gᵢxᵢ = …
  3. 3. x* is optimal iff x* = P_C(x* − η∇f(x*)). This is the…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Proof of the variational inequality

Necessity: if ∇f(x⋆)⊤(z−x⋆)<0\nabla f(x^\star)^\top(z - x^\star) < 0 for some z∈Cz\in C, then x⋆+t(z−x⋆)∈Cx^\star + t(z - x^\star)\in C (by convexity) and ff decreases along it for small tt. That’s a contradiction.

Sufficiency: by the first-order convexity inequality, f(z)≥f(x⋆)+∇f(x⋆)⊤(z−x⋆)≥f(x⋆)f(z)\ge f(x^\star) + \nabla f(x^\star)^\top(z - x^\star)\ge f(x^\star). ∎

Proof of the fixed-point form

p=PC(y)p = P_C(y) iff (y−p)⊤(z−p)≤0(y - p)^\top(z - p)\le0 for all z∈Cz\in C. With y=x⋆−η∇f(x⋆)y = x^\star - \eta\nabla f(x^\star) and p=x⋆p = x^\star, this reads −η∇f(x⋆)⊤(z−x⋆)≤0-\eta\nabla f(x^\star)^\top(z - x^\star)\le0, which is the variational inequality. ∎

Box conditions from the variational inequality

Take z=x⋆±teiz = x^\star\pm te_i when it’s feasible. If xix_i is interior, both signs are allowed, so gi=0g_i = 0. At a lower bound only +ei+e_i is allowed, giving gi≥0g_i\ge0. At an upper bound only −ei-e_i is allowed, giving gi≤0g_i\le0. ∎

Exercise 3.1: Project (0.5, 1.2, −0.3) onto the probability simplex

Sort: 1.2, 0.5, −0.3. Find τ\tau with ∑max⁡(vi−τ,0)=1\sum\max(v_i - \tau, 0) = 1: τ=0.35\tau = 0.35 gives 0.85+0.15=10.85 + 0.15 = 1. The result is (0.15,0.85,0)(0.15, 0.85, 0).

📝 Quick check (Level 3)
0/3 answered
  1. 1. Sufficiency of the variational inequality uses…
  2. 2. At a lower bound xᵢ = lᵢ, optimality requires gᵢ…
  3. 3. Projected GD with η = 1/L converges at…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Unmixing a planetary spectrum

A reflectance spectrum from an orbiter is modelled as a mixture of endmember spectra (regolith, water ice, frost, basalt). Abundances must be non-negative. Unconstrained least squares often reports small negative abundances for materials that aren’t there, which is physically meaningless. Non-negative least squares by projected gradient returns zero instead. Then the optimality conditions certify the answer: the gradient is ≥ 0 everywhere, and it’s exactly 0 on every material that’s present (complementary slackness).

🐍 Exercise 2 (research): non-negative spectral unmixing
Solve non-negative least squares by projected gradient. Compare with unconstrained LS across noisy spectra, and verify the optimality conditions g ≥ 0 and aᵢgᵢ = 0.

Optimality conditions in AI, robotics and aerospace

  • Spectral unmixing for planetary and Earth remote sensing uses non-negativity and sum-to-one constraints (Keshava and Mustard, 2002; Bioucas-Dias et al., 2012).
  • Actuator saturation and control allocation: the active set at the optimum tells you which actuators are saturated (Bodson, 2002).
  • Projected-gradient training: constrained network weights (non-negative, norm-bounded) and adversarial training with projected attacks (PGD; Madry et al., 2018).
  • Stopping criteria in solvers such as OSQP and IPOPT are scaled measures of how far the optimality conditions are from holding.

References

  1. S. Boyd, L. Vandenberghe (2004). Convex Optimization. Cambridge University Press. §4.2.3.
  2. D. Bertsekas (2016). Nonlinear Programming, 3rd ed. Athena Scientific. Ch. 2.
  3. R. T. Rockafellar, R. Wets (1998). Variational Analysis. Springer.
  4. A. Beck (2017). First-Order Methods in Optimization. SIAM. Ch. 9–10.
  5. C. Lawson, R. Hanson (1974). Solving Least Squares Problems. Prentice-Hall (NNLS).
  6. N. Keshava, J. Mustard (2002). “Spectral unmixing.” IEEE Signal Processing Magazine, 19(1).
  7. J. Bioucas-Dias et al. (2012). “Hyperspectral unmixing overview.” IEEE JSTARS, 5(2).
  8. J. Duchi, S. Shalev-Shwartz, Y. Singer, T. Chandra (2008). “Efficient projections onto the ℓ1-ball for learning in high dimensions.” ICML.
  9. A. Madry et al. (2018). “Towards deep learning models resistant to adversarial attacks.” ICLR.
  10. M. Bodson (2002). “Evaluation of optimization methods for control allocation.” Journal of Guidance, Control, and Dynamics, 25(4).