Contents
(Used to impose infinite penalty if a constraint is violated; circumvented by Lagrange multipliers).
Deep Breakdown
What it tells me (Situation Awareness): The infinite step function is a theoretical device in constrained optimisation. When minimising subject to , one formal encoding is to add to the objective: constraint violation instantly inflates cost to . This device is not directly computable (non-differentiable), but it motivates the Lagrangian: Lagrange multipliers replace the discontinuous step with a smooth linear penalty . The constraint that follows directly from the step function's sign — the penalty for violation must be non-negative. Understanding this concept is essential for reading SVM, QP, and constrained Bayesian optimisation derivations.
Flowchart
Real-world use
Where it is used
Understanding derivations of SVMs, QP duals, constrained neural network training (e.g., fairness constraints), and augmented Lagrangian methods. Encountered whenever reading "the indicator constraint is relaxed via Lagrange multipliers" in a textbook or paper.
Problem it solves
How do you turn a hard constraint into something differentiable that a gradient-based optimiser can handle? The infinite step function shows why the answer (Lagrange multipliers) must be non-negative and yields the KKT conditions.
How it solves the problem
The Lagrangian is a smooth surrogate for the infinite-penalty problem when . Maximising the dual over tightens the lower bound. Under Slater's condition (convex problem with a strictly feasible point), strong duality holds and the dual equals the primal.
Example in a business
A DS derives the SVM hard-margin classifier. Primal: subject to . Rewriting: . The conceptual step-function form makes clear why dual multipliers arise, and complementary slackness ( for non-support-vectors) explains sparsity.
The formula, piece by piece
| Symbol | Meaning |
|---|---|
| Constraint function evaluated at | |
| if | No penalty when constraint is satisfied |
| if | Infinite penalty when constraint is violated |
| Lagrange multiplier replacing | |
| Smooth linear penalty for constraint |
Constrained problem via indicator: Lagrangian: KKT complementary slackness: , ,
The formula in words
"The infinite step function says: if you violate a constraint, cost becomes infinite. Lagrange multipliers replace this with a linear price: the multiplier is the shadow price of constraint . The price must be non-negative because you can only be penalised for violations, not rewarded."
Critical Concepts
- Complementary slackness: (constraint active); (constraint inactive). This is why SVMs are sparse.
- Strong duality under Slater's condition: for convex and convex , if there exists with for all , then primal = dual.
- Barrier methods: interior-point solvers use (log barrier) as a smooth approximation that approaches as .
- Penalty methods: replace with — differentiable but inexact (constraint not exactly satisfied).
- Augmented Lagrangian: combines multiplier update with penalty term for fast, exact constraint satisfaction.
Step-by-step calculation (tiny example)
subject to ().
Step 1: Indicator form . Unconstrained minimum: , which violates .
Step 2: Lagrangian
Step 3: KKT stationarity
Step 4: Complementary slackness If (boundary): . Check: . Constraint is active: . Complementary slackness satisfied. Solution: , .
Code examples
Beginner example (Python)
import numpy as np
from scipy.optimize import minimize
def objective(x):
# min (x - 3)^2
return float((x[0] - 3.0) ** 2)
def gradient(x):
return np.array([2.0 * (x[0] - 3.0)])
# Hard constraint: x <= 2
constraints = [{"type": "ineq", "fun": lambda x: 2.0 - x[0]}]
result = minimize(
objective, x0=[0.0], jac=gradient, method="SLSQP", constraints=constraints,
)
print(f"Optimal x: {result.x[0]:.4f} (expected: 2.0)")
print(f"Optimal f: {result.fun:.4f} (expected: 1.0)")
# Without constraint
result_unc = minimize(objective, x0=[0.0], jac=gradient, method="BFGS")
print(f"Unconstrained x: {result_unc.x[0]:.4f} (expected: 3.0)")Beginner example (R)
# min (x - 3)^2 subject to x <= 2, encoded as -x >= -2
objective <- function(x) (x - 3)^2
gradient <- function(x) 2 * (x - 3)
result <- constrOptim(
theta = 0.0, f = objective, grad = gradient,
ui = matrix(-1, nrow = 1), ci = -2.0, method = "BFGS"
)
cat("Optimal x:", round(result$par, 4), "(expected 2.0)\n")
cat("Optimal f:", round(result$value, 4), "(expected 1.0)\n")Professional example (Python)
import numpy as np
from scipy.optimize import minimize
def penalty_method(
f: object,
g_constraints: list[object],
x0: np.ndarray,
rho_sequence: list[float],
tol: float = 1e-7,
) -> dict[str, object]:
# Penalty method approximating indicator 1(g_i(x)) with rho * max(0, g_i(x))^2.
# As rho increases, constraint satisfaction improves.
x = x0.copy()
history = []
for rho in rho_sequence:
def penalised_obj(x_inner):
return float(f(x_inner)) + rho * sum(
max(0.0, float(g(x_inner))) ** 2 for g in g_constraints
)
result = minimize(penalised_obj, x, method="BFGS", tol=tol)
x = result.x
violations = [max(0.0, float(g(x))) for g in g_constraints]
history.append({
"rho": rho,
"f_value": round(float(f(x)), 6),
"max_violation": round(max(violations, default=0.0), 8),
})
return {"x_opt": x.round(6), "history": history}
if __name__ == "__main__":
# min (x1-2)^2 + (x2-3)^2 s.t. x1 + x2 <= 4, x1 >= 0, x2 >= 0
f_obj = lambda x: (x[0] - 2.0) ** 2 + (x[1] - 3.0) ** 2
g1 = lambda x: x[0] + x[1] - 4.0 # x1+x2 <= 4
g2 = lambda x: -x[0] # x1 >= 0
g3 = lambda x: -x[1] # x2 >= 0
result = penalty_method(
f=f_obj,
g_constraints=[g1, g2, g3],
x0=np.array([1.0, 1.0]),
rho_sequence=[1, 10, 100, 1000],
)
print("Penalty method result:")
print(f" Optimal x: {result['x_opt']}")
print(" Convergence history:")
for row in result["history"]:
print(f" {row}")`` Domain knowledge.
Self-check: mathematical verification
- If is infeasible for , then and , so such points cannot minimize the extended objective when any feasible point exists.
- If is feasible, , so the unconstrained problem matches on the feasible region.
- This is the indicator of the feasible set in convex analysis; smooth penalties (quadratic, log-barrier) approximate it for optimization algorithms.
Common Pitfalls and Edge Cases
- Empty feasible set: every point has cost ; the reformulation hides feasibility diagnosis.
- Numerical optimization cannot literally implement ; barrier or penalty methods use finite smooth surrogates.
- Equality constraints need two inequalities or a separate indicator on an affine subspace.
References and Standard Results
- Constrained-to-unconstrained reformulations; connection to exact penalties and interior-point barrier methods.
- Indicator functions and subdifferential calculus in convex optimization.