Workspace IndexMath › Day 30

Lagrange Multipliers and KKT Conditions (Concept) TODO

Math · Day 30 / 52 · October — Calculus & Optimization (Day 27-34)

Concept

For constrained optimization, the method of Lagrange multipliers builds a Lagrangian by adding the equality constraints to the objective function, each scaled by a multiplier, and then looks for its stationary points. Geometrically, this expresses the condition that at the optimum, the gradient of the objective function must lie within the space spanned by the gradients of the constraints — meaning there's no direction along the constraint that still improves the objective. The KKT conditions extend this to include inequality constraints, and consist of stationarity of the Lagrangian, primal feasibility, non-negativity of the inequality multipliers, and complementary slackness. Complementary slackness requires that a multiplier be zero whenever its constraint isn't active — formalizing the intuition that a slack constraint doesn't affect the optimum. KKT conditions are generally necessary conditions, but for convex problems satisfying an appropriate constraint qualification, they are also sufficient for optimality.

Real-world optimization — allocation under risk limits, position optimization under collateral constraints, scheduling under resource constraints — is almost always constrained, and the multipliers give you a bonus: they're the value of relaxing a constraint by one unit.

Code & Formula

# Day 30 — 라그랑주/KKT(개념)
# 등식 제약 x + y = 1 아래에서 f(x,y) = x^2 + y^2 최소화를 라그랑주 승수법으로 푼다.
# L(x,y,lam) = x^2 + y^2 - lam*(x + y - 1); 정상점 조건: 2x=lam, 2y=lam, x+y=1

import numpy as np

# 정상점 조건을 선형연립방정식으로 세운다: [2, 0, -1; 0, 2, -1; 1, 1, 0] [x,y,lam]^T = [0,0,1]^T
A = np.array([
    [2.0, 0.0, -1.0],
    [0.0, 2.0, -1.0],
    [1.0, 1.0, 0.0],
])
b = np.array([0.0, 0.0, 1.0])

x, y, lam = np.linalg.solve(A, b)
print(f"라그랑주 해: x = {x:.4f}, y = {y:.4f}, lambda = {lam:.4f}")
print(f"제약 확인 x + y = {x + y:.4f} (목표: 1)")
print(f"목적함수 f(x,y) = {x**2 + y**2:.6f}")


def f(x, y):
    return x ** 2 + y ** 2


# 대칭성으로 예상되는 답 (0.5, 0.5)과 비교, 제약을 만족하는 다른 점들과 비교해 최소임을 확인
print("\n제약선 위 다른 점들과 비교 (모두 x+y=1을 만족):")
for t in [0.0, 0.3, 0.5, 0.7, 1.0]:
    xt, yt = t, 1 - t
    print(f"  (x,y)=({xt:.2f},{yt:.2f}) -> f = {f(xt, yt):.6f}")

Exercise

Set up and solve by hand the KKT conditions for maximizing a simple convex objective under a budget constraint, then solve the same problem with a numerical optimization library and check that the multiplier values match.

Practical Connection

Setting a market maker's liquidity parameter under a maximum-loss cap, or adjusting a fee structure under constraints, is exactly a constrained optimization problem, and the multiplier reads as the marginal benefit of relaxing that cap.

If you study this on a given day, add a note link and a ✅ to this line in the source curriculum (docs/knowledge/math-50-curriculum.md) and this spot will lead straight to the note body. You can also write directly on this page — but regenerating overwrites it, so it's safer to keep anything you want to save as markdown under docs/algorithms/.


한국어

라그랑주/KKT(개념) TODO

Math · Day 30 / 52 · 10월 — 미적분·최적화 (Day 27–34)

개념

제약이 있는 최적화에서 라그랑주 승수법은 등식 제약을 목적함수에 승수를 곱해 더한 라그랑지안을 만들고, 그 정상점을 찾는 방법이다. 기하적으로는 최적점에서 목적함수의 기울기가 제약면의 기울기들이 만드는 공간 안에 놓여야 한다는 조건, 즉 제약을 따라 움직여서는 더 이상 개선할 방향이 없다는 조건을 표현한다. 부등식 제약까지 포함하도록 확장한 것이 KKT 조건이며, 라그랑지안의 정상성, 원 문제의 실현가능성, 부등식 승수의 비음수성, 그리고 상보 여유성으로 구성된다. 상보 여유성은 제약이 활성이 아니면 그 승수가 0이어야 한다는 조건으로, 느슨한 제약은 최적해에 영향을 주지 않는다는 직관을 형식화한 것이다. KKT는 일반적으로 필요조건이지만, 볼록 문제이고 적절한 제약 자격이 성립하면 최적성의 충분조건이 되기도 한다.

리스크 한도 하의 배분, 담보 제약 하의 포지션 최적화, 자원 제약이 있는 스케줄링처럼 실무의 최적화는 거의 항상 제약이 붙은 형태이고, 승수는 제약을 한 단위 완화했을 때의 가치라는 해석까지 준다.

코드 · 수식

# Day 30 — 라그랑주/KKT(개념)
# 등식 제약 x + y = 1 아래에서 f(x,y) = x^2 + y^2 최소화를 라그랑주 승수법으로 푼다.
# L(x,y,lam) = x^2 + y^2 - lam*(x + y - 1); 정상점 조건: 2x=lam, 2y=lam, x+y=1

import numpy as np

# 정상점 조건을 선형연립방정식으로 세운다: [2, 0, -1; 0, 2, -1; 1, 1, 0] [x,y,lam]^T = [0,0,1]^T
A = np.array([
    [2.0, 0.0, -1.0],
    [0.0, 2.0, -1.0],
    [1.0, 1.0, 0.0],
])
b = np.array([0.0, 0.0, 1.0])

x, y, lam = np.linalg.solve(A, b)
print(f"라그랑주 해: x = {x:.4f}, y = {y:.4f}, lambda = {lam:.4f}")
print(f"제약 확인 x + y = {x + y:.4f} (목표: 1)")
print(f"목적함수 f(x,y) = {x**2 + y**2:.6f}")


def f(x, y):
    return x ** 2 + y ** 2


# 대칭성으로 예상되는 답 (0.5, 0.5)과 비교, 제약을 만족하는 다른 점들과 비교해 최소임을 확인
print("\n제약선 위 다른 점들과 비교 (모두 x+y=1을 만족):")
for t in [0.0, 0.3, 0.5, 0.7, 1.0]:
    xt, yt = t, 1 - t
    print(f"  (x,y)=({xt:.2f},{yt:.2f}) -> f = {f(xt, yt):.6f}")

연습

예산 제약 하에서 간단한 볼록 목적함수를 최대화하는 문제를 손으로 KKT 조건을 세워 풀고, 같은 문제를 수치 최적화 라이브러리로 풀어 승수 값이 일치하는지 비교하라.

실무 · Verex 연결

마켓 메이커의 유동성 파라미터를 최대 손실 한도 아래에서 정하거나 수수료 구조를 제약 하에 조정하는 문제가 정확히 제약 최적화 형태이고, 승수는 그 한도를 완화했을 때의 한계 이익으로 읽힌다.

공부한 날 원본 커리큘럼(docs/knowledge/math-50-curriculum.md)의 이 줄에 노트 링크와 ✅ 를 붙이면, 이 자리는 노트 본문으로 바로 이어집니다. 노트 없이 이 페이지에 바로 적어도 됩니다 — 다만 다시 생성하면 덮어쓰이므로, 남길 글은 docs/algorithms/ 의 마크다운으로 쓰는 편이 안전합니다.

← 29. Gradient Descent / Convex 직관31. 뉴턴법/고정점 반복(StableSwap 필수) →