Partial Derivatives and the Gradient TODO
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
- Verex: use the gradient directly to quote exact slippage. Since the LMSR price is the gradient of the cost function, compute exact slippage for a given order size before showing it in the UI, instead of approximating.
- Verex: document the liquidity parameter b as a tradeoff, not a constant. A larger b flattens the gradient (less slippage, less informative price movement) — write the b-selection rule down explicitly.
- DeFi: run the same gradient-based sensitivity check on any future AMM curve. Catch a curve that's too flat or too steep at the operating point before launch.
Key expressions
| 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/.