Workspace IndexMath › Day 28

Partial Derivatives and the Gradient TODO

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

Concept

A partial derivative is the derivative of a multivariable function taken with respect to one variable while holding the others fixed. The gradient collects these partial derivatives into a vector that points in the direction of steepest increase at that point, with its magnitude giving the rate of increase in that direction. At a differentiable point, the gradient is perpendicular to the level set passing through that point. The basic optimization move is gradient descent — taking small steps opposite the gradient — and at an unconstrained local optimum of a smooth function, the gradient is zero. If the function is convex, a point where the gradient vanishes is the global minimum.

Parameter calibration, cost minimization, and model training are all gradient-based, so if you can't read sensitivity off the equations you can't diagnose why something is diverging or why convergence has stalled.

Code & Formula

# Day 28 — 편미분/그래디언트
# 다변수 함수의 편미분을 수치로 구해 그래디언트 벡터를 만들고, 최급상승 방향임을 확인한다.

import numpy as np


def f(v):
    x, y = v
    return x ** 2 + 3 * y ** 2 - 2 * x * y


def gradient(f, v, h=1e-6):
    grad = np.zeros_like(v)
    for i in range(len(v)):
        v_plus = v.copy()
        v_minus = v.copy()
        v_plus[i] += h
        v_minus[i] -= h
        grad[i] = (f(v_plus) - f(v_minus)) / (2 * h)
    return grad


v0 = np.array([1.0, 2.0])
grad = gradient(f, v0)
print(f"f({v0}) = {f(v0):.4f}")
print(f"gradient = {grad}")

# 그래디언트 방향으로 조금 이동하면 함수값이 증가, 반대 방향이면 감소해야 한다.
step = 0.01
unit = grad / np.linalg.norm(grad)
f_plus = f(v0 + step * unit)
f_minus = f(v0 - step * unit)
print(f"\ngradient 방향으로 이동: f = {f_plus:.6f} (증가해야 함)")
print(f"반대 방향으로 이동:   f = {f_minus:.6f} (감소해야 함)")
print(f"원래 값:              f = {f(v0):.6f}")

Exercise

Take the partial derivatives of the LMSR cost function C(q) = b·ln(Σ exp(q_i/b)) by hand and confirm that these values are exactly the prices of each outcome, and that they sum to 1.

Practical Connection

Verex's LMSR price is literally the gradient of the cost function, so this calculation isn't abstract — it directly explains price, slippage, and sensitivity to the liquidity parameter b.

Where it lands in Jayverse

Key expressions

Words and phrases from this page worth keeping, with the Korean meaning and the sentence they come from.

Expression뜻 · 쓰이는 자리
steepest increase가장 가파르게 증가하는 방향 · 그레디언트가 가리키는 방향을 설명할 때. "points in the direction of steepest increase at that point"
perpendicular to~에 수직인 · 그레디언트와 등고선(레벨셋)의 기하학적 관계를 말할 때. "the gradient is perpendicular to the level set"
vanishes(값이) 0이 되다, 사라지다 · 그레디언트가 0이 되는 지점을 가리킬 때. "a point where the gradient vanishes is the global minimum"
unconstrained제약이 없는 · 별도 조건 없이 자유롭게 최적화하는 상황을 말할 때. "at an unconstrained local optimum of a smooth function"
diverging발산하는, 값이 계속 커지는 · 수렴하지 않고 오히려 커지는 상황을 가리킬 때. "you can't diagnose why something is diverging"
convergence has stalled수렴이 멈췄다, 더 이상 나아지지 않는다 · 학습·최적화가 정체됐을 때. "or why convergence has stalled"
read sensitivity off수식에서 민감도를 읽어내다 · 방정식만 보고 변화에 얼마나 민감한지 파악할 때. "if you can't read sensitivity off the equations"
LMSR로그마켓 스코어링 규칙(Logarithmic Market Scoring Rule) · 예측시장의 비용함수 기반 자동시장조성 방식, Verex 가격이 이 비용함수의 그레디언트. "the LMSR cost function C(q) = b·ln(Σ exp(q_i/b))"

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


한국어

편미분/그래디언트 TODO

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

개념

편미분은 다변수 함수에서 한 변수만 변화시키고 나머지를 고정한 채 구한 미분이다. 그래디언트는 편미분들을 모은 벡터로, 그 점에서 함수가 가장 가파르게 증가하는 방향을 가리키고 크기는 그 방향의 증가율이다. 미분 가능한 점에서 그래디언트는 그 점을 지나는 등위면에 수직이다. 최적화의 기본은 그래디언트 반대 방향으로 조금씩 이동하는 경사하강이며, 제약 없는 매끄러운 함수의 국소 최적점에서는 그래디언트가 0이 된다. 함수가 볼록하면 그래디언트가 0인 점이 곧 전역 최소점이다.

파라미터 캘리브레이션·비용 최소화·모델 학습이 전부 그래디언트 기반이라, 수식에서 민감도를 읽지 못하면 왜 발산하거나 수렴이 멈추는지 진단할 수 없다.

코드 · 수식

# Day 28 — 편미분/그래디언트
# 다변수 함수의 편미분을 수치로 구해 그래디언트 벡터를 만들고, 최급상승 방향임을 확인한다.

import numpy as np


def f(v):
    x, y = v
    return x ** 2 + 3 * y ** 2 - 2 * x * y


def gradient(f, v, h=1e-6):
    grad = np.zeros_like(v)
    for i in range(len(v)):
        v_plus = v.copy()
        v_minus = v.copy()
        v_plus[i] += h
        v_minus[i] -= h
        grad[i] = (f(v_plus) - f(v_minus)) / (2 * h)
    return grad


v0 = np.array([1.0, 2.0])
grad = gradient(f, v0)
print(f"f({v0}) = {f(v0):.4f}")
print(f"gradient = {grad}")

# 그래디언트 방향으로 조금 이동하면 함수값이 증가, 반대 방향이면 감소해야 한다.
step = 0.01
unit = grad / np.linalg.norm(grad)
f_plus = f(v0 + step * unit)
f_minus = f(v0 - step * unit)
print(f"\ngradient 방향으로 이동: f = {f_plus:.6f} (증가해야 함)")
print(f"반대 방향으로 이동:   f = {f_minus:.6f} (감소해야 함)")
print(f"원래 값:              f = {f(v0):.6f}")

연습

LMSR 비용함수 C(q) = b·ln(Σ exp(q_i/b))의 편미분을 손으로 구해 그 값이 각 결과의 가격이 되고 합이 1이 됨을 확인하라.

실무 · Verex 연결

Verex의 LMSR 가격이 정확히 비용함수의 그래디언트이므로 이 계산은 추상 개념이 아니라 가격, 슬리피지, 유동성 파라미터 b에 대한 민감도를 그대로 설명해준다.

Jayverse에서의 위치

핵심 표현

이 페이지의 영어 본문에서 배울 만한 단어와 표현, 뜻과 나온 자리.

Expression뜻 · 쓰이는 자리
steepest increase가장 가파르게 증가하는 방향 · 그레디언트가 가리키는 방향을 설명할 때. "points in the direction of steepest increase at that point"
perpendicular to~에 수직인 · 그레디언트와 등고선(레벨셋)의 기하학적 관계를 말할 때. "the gradient is perpendicular to the level set"
vanishes(값이) 0이 되다, 사라지다 · 그레디언트가 0이 되는 지점을 가리킬 때. "a point where the gradient vanishes is the global minimum"
unconstrained제약이 없는 · 별도 조건 없이 자유롭게 최적화하는 상황을 말할 때. "at an unconstrained local optimum of a smooth function"
diverging발산하는, 값이 계속 커지는 · 수렴하지 않고 오히려 커지는 상황을 가리킬 때. "you can't diagnose why something is diverging"
convergence has stalled수렴이 멈췄다, 더 이상 나아지지 않는다 · 학습·최적화가 정체됐을 때. "or why convergence has stalled"
read sensitivity off수식에서 민감도를 읽어내다 · 방정식만 보고 변화에 얼마나 민감한지 파악할 때. "if you can't read sensitivity off the equations"
LMSR로그마켓 스코어링 규칙(Logarithmic Market Scoring Rule) · 예측시장의 비용함수 기반 자동시장조성 방식, Verex 가격이 이 비용함수의 그레디언트. "the LMSR cost function C(q) = b·ln(Σ exp(q_i/b))"

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

← 1031. 미분·기울기·연쇄법칙1033. Gradient Descent / Convex 직관 →