σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Optimization skill›Module 2 · Gradient methods›Topic 2.1·~50 minIntermediate

Gradient descent

Skill positionModule 2 of 5 · Topic 1 of 3
2.1 Gradient descent
—Lab score— / 100Total XP—Streak—

Walking downhill

Gradient descent repeats one move: step against the gradient, wk+1=wk−η ∇f(wk)\mathbf w_{k+1}=\mathbf w_k-\eta\,\nabla f(\mathbf w_k)wk+1​=wk​−η∇f(wk​). The number η>0\eta>0η>0 is the step size, often called the learning rate. A small η\etaη is safe but slow. A large η\etaη overshoots the valley and the iterates can bounce further away each time.

f(w)=12a w2 ⇒ wk+1=(1−ηa) wk,∣1−ηa∣<1  ⟺  0<η<2af(w)=\tfrac12 a\,w^{2}\ \Rightarrow\ w_{k+1}=(1-\eta a)\,w_k,\qquad |1-\eta a|<1\iff 0<\eta<\frac{2}{a}f(w)=21​aw2 ⇒ wk+1​=(1−ηa)wk​,∣1−ηa∣<1⟺0<η<a2​(1)

On the simplest bowl the update multiplies www by 1−ηa1-\eta a1−ηa each time, so the iterates shrink to zero exactly when ∣1−ηa∣<1|1-\eta a|<1∣1−ηa∣<1, that is when η<2/a\eta<2/aη<2/a. The choice η=1/a\eta=1/aη=1/a lands on the minimum in one step, and any η\etaη between 1/a1/a1/a and 2/a2/a2/a still converges but alternates sign on the way. Beyond 2/a2/a2/a the factor has size above one and the iterates explode.

Three steps on f = 3x²Here f′(x)=6xf'(x)=6xf′(x)=6x, so a=6a=6a=6. Start at x0=4x_0=4x0​=4 with η=0.1\eta=0.1η=0.1: the factor is 1−0.6=0.41-0.6=0.41−0.6=0.4, giving x1=1.6x_1=1.6x1​=1.6, x2=0.64x_2=0.64x2​=0.64, x3=0.256x_3=0.256x3​=0.256. The stability limit is 2/6=0.3332/6=0.3332/6=0.333. With η=0.5\eta=0.5η=0.5 the factor is 1−3=−21-3=-21−3=−2, so the iterates run 4,−4,8,…4,-4,8,\dots4,−4,8,… and double in size each step.

In several variables the curvature differs by direction. The largest Hessian eigenvalue LLL caps the usable step (η<2/L\eta<2/Lη<2/L) and the smallest μ\muμ sets how slowly the flattest direction is crossed. Their ratio κ=L/μ\kappa=L/\muκ=L/μ is the condition number. With the best fixed step η=2/(L+μ)\eta=2/(L+\mu)η=2/(L+μ) the error shrinks by about the factor (κ−1)/(κ+1)(\kappa-1)/(\kappa+1)(κ−1)/(κ+1) per step, so a large κ\kappaκ means a factor close to one and a slow zig-zag down a long narrow valley. For the covariance matrix of twelve large US stocks since 2010, κ\kappaκ is about 333333: the factor is 0.9410.9410.941 and cutting the error 100-fold takes about 76 steps.

η∗=2L+μ,∥wk−w∗∥ ≲ (κ−1κ+1)k∥w0−w∗∥,κ=Lμ\eta^{*}=\frac{2}{L+\mu},\qquad \lVert\mathbf w_k-\mathbf w^{*}\rVert\ \lesssim\ \Big(\frac{\kappa-1}{\kappa+1}\Big)^{k}\lVert\mathbf w_0-\mathbf w^{*}\rVert,\qquad \kappa=\frac{L}{\mu}η∗=L+μ2​,∥wk​−w∗∥ ≲ (κ+1κ−1​)k∥w0​−w∗∥,κ=μL​(2)
  • Safe step: η<2/L\eta<2/Lη<2/L, where LLL is the largest Hessian eigenvalue; otherwise the iterates diverge.
  • Speed: set by the condition number κ=L/μ\kappa=L/\muκ=L/μ; the larger it is, the slower the descent.
  • Stopping: stop when ∥∇f∥\lVert\nabla f\rVert∥∇f∥ is below a tolerance, with a cap on the number of iterations.
Scale the variablesA large condition number often comes from variables on very different scales, for example a weight between 0 and 1 beside a volatility in basis points. Rescaling each variable to a similar size lowers κ\kappaκ and can turn thousands of iterations into dozens. Preconditioning is the general form of the same idea.

Lab · what's graded

  • The first step15 pts
  • The second step10 pts
  • The largest stable step15 pts
  • A step that is too big15 pts
  • A condition number15 pts
  • The best contraction factor15 pts
  • Why ill-conditioning is slow15 pts
0/ 7 answered
Tasks
1Numeric answer15 ptsNot answered

Run gradient descent on f(x)=3x2f(x)=3x^2f(x)=3x2 from x0=4x_0=4x0​=4 with η=0.1\eta=0.1η=0.1. What is x1x_1x1​?

x1=x1 =x1=accepted: ± 0.01
2Numeric answer10 ptsNot answered

Continue one more step with the same η\etaη. What is x2x_2x2​?

x2=x2 =x2=accepted: ± 0.005
3Numeric answer15 ptsNot answered

For f(x)=3x2f(x)=3x^2f(x)=3x2, gradient descent converges only if η\etaη is below a limit. What is that limit? Give it to three decimals.

limit=limit =limit=accepted: ± 0.003
4Choice15 ptsNot answered

On f(x)=3x2f(x)=3x^2f(x)=3x2 you use η=0.5\eta=0.5η=0.5. What happens to the iterates?

5Numeric answer15 ptsNot answered

The function f(x,y)=x2+10y2f(x,y)=x^2+10y^2f(x,y)=x2+10y2 has Hessian diag(2,20)\mathrm{diag}(2,20)diag(2,20). What is its condition number κ=L/μ\kappa=L/\muκ=L/μ?

kappa=kappa =kappa=accepted: ± 0.05
6Numeric answer15 ptsNot answered

For that fff, gradient descent with the best fixed step shrinks the error per step by about (κ−1)/(κ+1)(\kappa-1)/(\kappa+1)(κ−1)/(κ+1). What is this factor? Give it to three decimals.

rate=rate =rate=accepted: ± 0.003
7Explain in words15 ptsNot answered

In one or two sentences, say why gradient descent is slow when the condition number is large.

Math modeKeyboard or LaTeX inputTask 1 of 7 · Ctrl ⏎ to check

Log in to run your code.

Every lecture is free to read. Create an account or log in to run code, run tests and submit this lab.

  • In-browser IDE with a bash terminal — nothing to install
  • Instant grading, XP and your place on the skill
Create an accountLog in
OR
Continue with GitHub