Workspace IndexMath › Day 29

Gradient Descent and Convex Intuition TODO

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

Concept

Gradient descent is an optimization method that exploits the fact that the gradient of the objective function points in the direction of steepest ascent, and repeatedly moves a step of size equal to the learning rate in the opposite direction. A function is convex if the line segment joining any two points in its domain always lies on or above the function's graph; this property guarantees that a local minimum is also the global minimum, and that a point where the gradient is zero is optimal. For a smooth convex function whose gradient is L-Lipschitz continuous, choosing a learning rate at or below 1/L guarantees convergence, and adding strong convexity yields a faster, exponentially decaying error rate. A learning rate that's too large causes divergence, one that's too small is slow, and poor conditioning causes zig-zagging in narrow, elongated valleys — which is why techniques like momentum, adaptive learning rates, and preconditioning are used to mitigate it.

In numerical optimization beyond machine learning — market-making parameter tuning, calibration — you need to tell whether a failure to converge comes from the problem's non-convexity or from a learning-rate/conditioning issue.

Code & Formula

# Day 29 — Gradient Descent / Convex 직관
# 볼록함수 f(x) = (x - 3)^2 위에서 경사하강법을 돌려 최소점 x=3 으로 수렴하는 과정을 본다.

def f(x):
    return (x - 3) ** 2


def f_prime(x):
    return 2 * (x - 3)


x = 10.0  # 시작점
learning_rate = 0.1
history = [x]

for step in range(30):
    grad = f_prime(x)
    x = x - learning_rate * grad
    history.append(x)

print("경사하강 진행 (x, f(x)):")
for i in [0, 1, 2, 5, 10, 20, len(history) - 1]:
    xi = history[i]
    print(f"  step {i:2d}: x = {xi:.6f}, f(x) = {f(xi):.8f}")

print(f"\n최종 x = {history[-1]:.6f} (참값 x* = 3)")
print(f"최종 f(x) = {f(history[-1]):.10f} (참값 f(x*) = 0)")

Exercise

Construct a 2D quadratic function with a deliberately poor condition number, run both plain and momentum-based gradient descent on it across several learning rates, and compare the iteration counts and trajectories visually.

Practical Connection

The LMSR cost function is convex, so properties like well-defined prices and a bounded loss follow directly from convexity, and this same optimization toolkit is exactly what you use when calibrating parameters against real data.

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/.


한국어

Gradient Descent / Convex 직관 TODO

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

개념

경사하강법은 목적함수의 기울기가 가장 가파른 상승 방향임을 이용해, 그 반대 방향으로 학습률만큼 이동하기를 반복하는 최적화 방법이다. 볼록함수는 정의역의 두 점을 잇는 선분이 항상 함수 그래프 위에 있는 함수이며, 이 성질 덕분에 국소 최소점이 곧 전역 최소점이고 기울기가 0인 점이 최적해가 된다. 기울기가 L-립시츠 연속인 매끄러운 볼록함수에서는 학습률을 1/L 이하로 잡으면 수렴이 보장되고, 강볼록성까지 있으면 오차가 기하급수적으로 줄어드는 더 빠른 속도를 얻는다. 학습률이 너무 크면 발산하고 너무 작으면 느리며, 조건수가 나쁘면 좁고 긴 골짜기에서 지그재그로 진동한다. 이를 완화하려고 모멘텀, 적응적 학습률, 전처리 같은 기법을 쓴다.

머신러닝뿐 아니라 시장조성 파라미터 튜닝이나 캘리브레이션 같은 수치 최적화에서, 수렴하지 않는 원인이 문제의 비볼록성인지 학습률·조건수 문제인지 구분해야 한다.

코드 · 수식

# Day 29 — Gradient Descent / Convex 직관
# 볼록함수 f(x) = (x - 3)^2 위에서 경사하강법을 돌려 최소점 x=3 으로 수렴하는 과정을 본다.

def f(x):
    return (x - 3) ** 2


def f_prime(x):
    return 2 * (x - 3)


x = 10.0  # 시작점
learning_rate = 0.1
history = [x]

for step in range(30):
    grad = f_prime(x)
    x = x - learning_rate * grad
    history.append(x)

print("경사하강 진행 (x, f(x)):")
for i in [0, 1, 2, 5, 10, 20, len(history) - 1]:
    xi = history[i]
    print(f"  step {i:2d}: x = {xi:.6f}, f(x) = {f(xi):.8f}")

print(f"\n최종 x = {history[-1]:.6f} (참값 x* = 3)")
print(f"최종 f(x) = {f(history[-1]):.10f} (참값 f(x*) = 0)")

연습

2차원 이차함수의 조건수를 크게 만들어 놓고 경사하강법을 순수 버전과 모멘텀 버전으로 돌려, 학습률을 바꿔가며 반복 횟수와 궤적을 그림으로 비교하라.

실무 · Verex 연결

LMSR의 비용함수는 볼록이라 가격과 손실 상한 같은 성질이 볼록성에서 곧바로 따라오고, 파라미터를 데이터에 맞춰 캘리브레이션할 때 이 최적화 도구가 그대로 쓰인다.

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

← 28. 편미분/그래디언트30. 라그랑주/KKT(개념) →