σμ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
  • 日本語
  • 中文
Bayesian Inference skill›Module 2 · Sampling the posterior›Topic 2.2·~55 minAdvanced

Gibbs sampling

Skill positionModule 2 of 3 · Topic 2 of 2
2.2 Gibbs sampling
—Lab score— / 100Total XP—Streak—

Updating one piece at a time

Some posteriors are hard as a whole but easy one piece at a time. Gibbs sampling uses this. With two unknowns, say a mean μ\muμ and a precision τ\tauτ (one over the variance), you do not need their joint distribution. Draw μ\muμ from its distribution given the current τ\tauτ. Then draw τ\tauτ from its distribution given the new μ\muμ. Repeat. Each draw is a conditional draw, and it is always accepted: unlike Metropolis-Hastings there is no accept-or-reject step. The pairs you collect form a chain that explores the joint posterior.

μ∣τ,x∼N ⁣(P0m0+nτxˉP0+nτ, 1P0+nτ),τ∣μ,x∼Gamma ⁣(a+n2, b+∑(xi−μ)22)\mu\mid\tau,x\sim N\!\left(\frac{P_0m_0+n\tau\bar x}{P_0+n\tau},\ \frac{1}{P_0+n\tau}\right),\qquad \tau\mid\mu,x\sim\mathrm{Gamma}\!\left(a+\frac n2,\ b+\frac{\sum(x_i-\mu)^{2}}{2}\right)μ∣τ,x∼N(P0​+nτP0​m0​+nτxˉ​, P0​+nτ1​),τ∣μ,x∼Gamma(a+2n​, b+2∑(xi​−μ)2​)(1)

Gibbs works best when the pieces are not tied tightly together. If two unknowns are strongly correlated, each conditional draw can only take a tiny step along the narrow ridge, so the chain zigzags and moves slowly. A two-variable example: if xxx and yyy are bivariate normal with correlation ρ\rhoρ, then xxx given yyy is normal with mean ρy\rho yρy and standard deviation 1−ρ2\sqrt{1-\rho^{2}}1−ρ2​. With ρ=0.8\rho=0.8ρ=0.8 and y=2y=2y=2 the draw of xxx has mean 1.61.61.6 and standard deviation 0.60.60.6. With ρ=0.99\rho=0.99ρ=0.99 the standard deviation drops to 0.140.140.14 and the steps become tiny.

Both conditional steps with numbersSay n=25n=25n=25 returns have mean xˉ=0.5\bar x=0.5xˉ=0.5, and the current σ2=4\sigma^{2}=4σ2=4, so τ=0.25\tau=0.25τ=0.25. With the prior N(0,102)N(0,10^{2})N(0,102) the prior precision is P0=0.01P_0=0.01P0​=0.01. The data precision is nτ=6.25n\tau=6.25nτ=6.25. So μ\muμ is drawn from a normal with mean 6.25×0.5/6.26=0.4996.25\times0.5/6.26=0.4996.25×0.5/6.26=0.499 and standard deviation 1/6.26=0.4001/\sqrt{6.26}=0.4001/6.26​=0.400. Next, with a=b=1a=b=1a=b=1 and ∑(xi−μ)2=100\sum(x_i-\mu)^{2}=100∑(xi​−μ)2=100, the precision is drawn from Gamma(13.5, 51)\mathrm{Gamma}(13.5,\ 51)Gamma(13.5, 51), whose mean is 13.5/51=0.26513.5/51=0.26513.5/51=0.265, a variance of about 3.83.83.8.
  • Gibbs sampling: draw each unknown in turn from its conditional distribution given the others.
  • No rejection: every conditional draw is kept, but you need each conditional to be easy to draw from.
  • Strong correlation between unknowns makes the chain zigzag and mix slowly.

Lab · what's graded

  • A conditional mean15 pts
  • A conditional spread10 pts
  • Drawing the mean15 pts
  • Drawing the precision15 pts
  • No rejection step10 pts
  • One sweep10 pts
  • Match the vocabulary10 pts
  • Strong correlation slows Gibbs15 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

xxx and yyy are bivariate normal with correlation ρ=0.8\rho=0.8ρ=0.8. Given y=2y=2y=2, what is the mean ρy\rho yρy of the conditional distribution of xxx?

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

What is the standard deviation 1−ρ2\sqrt{1-\rho^{2}}1−ρ2​ of that conditional distribution? Give two decimals.

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

With n=25n=25n=25, xˉ=0.5\bar x=0.5xˉ=0.5, τ=0.25\tau=0.25τ=0.25 and prior N(0,102)N(0,10^{2})N(0,102), the conditional of μ\muμ has precision 0.01+25×0.25=6.260.01+25\times0.25=6.260.01+25×0.25=6.26. What is its mean 6.25×0.5 / 6.266.25\times0.5\,/\,6.266.25×0.5/6.26? Give three decimals.

m=m =m=accepted: ± 0.002
4Numeric answer15 ptsNot answered

With a=b=1a=b=1a=b=1, n=25n=25n=25 and ∑(xi−μ)2=100\sum(x_i-\mu)^{2}=100∑(xi​−μ)2=100, the conditional of τ\tauτ is Gamma(a+n/2, b+100/2)\mathrm{Gamma}(a+n/2,\ b+100/2)Gamma(a+n/2, b+100/2). What is its mean, shape divided by rate? Give three decimals.

t=t =t=accepted: ± 0.002
5Choice10 ptsNot answered

Why does Gibbs sampling need no accept-or-reject step?

6Order the steps10 ptsNot answered

Put the steps of a Gibbs sampler in order.

Drag to reorder, or focus an item, press Space to lift it, the arrow keys to move it and Space to drop it.

  1. 1Record the pair
  2. 2Draw the mean given the precision
  3. 3Choose starting values
  4. 4Draw the precision given the new mean
  5. 5Repeat many times and drop the burn-in
7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Gibbs sampling
Conditional distribution
Sweep
Slow mixing
8Explain in words15 ptsNot answered

In one or two sentences, explain why a Gibbs sampler is slow when two unknowns are strongly correlated.

Math modeKeyboard or LaTeX inputTask 1 of 8 · 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