Lensa ML
Lensa ML

How Constrained Optimization Works

Step 1 of 6

Unconstrained vs Constrained

What happens when you can't reach the true minimum

Constraint radius r1.50
-3-2-11234-3-2-11234xymin (2,2)(1.1,1.1)f(x,y) = (x−2)² + (y−2)²
UNCONSTRAINED MIN
0.0
CONSTRAINED MIN
1.76
GAP
1.76

With a small radius, the feasible region is far from the unconstrained minimum. The constraint forces a much worse solution.

Step 1 of 6: Unconstrained vs Constrained

What happens when you can't reach the true minimum

Constraint radius r1.50
-3-2-11234-3-2-11234xymin (2,2)(1.1,1.1)f(x,y) = (x−2)² + (y−2)²
UNCONSTRAINED MIN
0.0
CONSTRAINED MIN
1.76
GAP
1.76

With a small radius, the feasible region is far from the unconstrained minimum. The constraint forces a much worse solution.

Step 2 of 6: The Constraint Curve

Exploring the feasible region for better solutions

Constraint radius r1.50
Position t along constraint0.79
-3-2-11234-3-2-11234xyf=1.76Drag t to explore the constraint circle
x
1.06
y
1.07
f(x,y)
1.76
OPTIMAL f
1.76

You're very close to the constrained optimum! This is the best you can do while staying on the circle.

Step 3 of 6: Gradient Alignment

At the optimum, objective and constraint gradients align

Position t along constraint0.79
-3-2-11234-3-2-11234xy∇f∇g∇f = objective gradient   ∇g = constraint gradient
|∇f|
2.66
|∇g|
3.00
ANGLE
179.4°
f(x,y)
1.76

The gradients are nearly parallel — this is the optimality condition! At the constrained minimum, ∇f and ∇g point in the same (or opposite) direction.

Step 4 of 6: The Lagrange Multiplier λ

The scalar that makes ∇f = λ∇g

Position t along constraint0.79
Lagrange multiplier λ1.00
-3-2-11234-3-2-11234xy∇fλ∇gcondition: ∇f = λ∇g
λ
1.0
|∇f − λ∇g|
5.66
OPTIMAL λ
-0.89

Large mismatch — the current λ doesn't satisfy ∇f = λ∇g. Try moving λ toward the optimal value shown in the green card.

Step 5 of 6: Finding the Optimum

Iteratively converging to the constrained solution

Iteration step0
-3-2-11234-3-2-11234xytargetProjected gradient descent on constraint
STEP
0
x
-1.50
y
0.00
f(x,y)
16.25

Starting from the opposite side of the constraint circle. The solver will move along the constraint toward the optimum using projected gradient descent.

Step 6 of 6: Regularization as a Constraint

Constraining weights to prevent overfitting

Constraint budget c = ||w||² ≤ c2.00
-3-2-11234-3-2-11234xy||w||² ≤ 2.0unreg. minw*Loss contours (blue) + weight constraint (fuchsia)
||w||²
2.00
LOSS
3.06
BUDGET c
2.0
REG. LOSS
5.06

A balanced constraint — the weights are pulled toward the origin but can still fit the data reasonably. This sweet spot trades off loss and model complexity.