σμ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
  • 日本語
  • 中文
Hidden Markov Models skill›Module 2 · The core algorithms›Topic 2.2·~55 minAdvanced

Viterbi decoding

Skill positionModule 2 of 3 · Topic 2 of 4
2.2 Viterbi decoding
—Lab score— / 100Total XP—Streak—

The single most likely story

The forward algorithm adds up all hidden paths to say how likely the data are. Often we want something else: the one best story, the single sequence of states that explains the data with the highest probability. Viterbi decoding finds it. The idea is the forward algorithm with one change: instead of summing over the previous states, take the best one. Keep a score δt(j)\delta_t(j)δt​(j), the probability of the best path that ends in state jjj on day ttt, and remember which previous state gave it, the back-pointer.

δ1(j)=πjBj(o1),δt(j)=[max⁡iδt−1(i)Aij]Bj(ot),ψt(j)=arg⁡max⁡iδt−1(i)Aij\delta_1(j)=\pi_jB_j(o_1),\qquad \delta_t(j)=\Big[\max_i\delta_{t-1}(i)A_{ij}\Big]B_j(o_t),\qquad \psi_t(j)=\arg\max_i\delta_{t-1}(i)A_{ij}δ1​(j)=πj​Bj​(o1​),δt​(j)=[imax​δt−1​(i)Aij​]Bj​(ot​),ψt​(j)=argimax​δt−1​(i)Aij​(1)

After the last day, pick the state with the largest δT\delta_TδT​ and walk back through the pointers ψ\psiψ to read off the whole path. Two practical points. First, work with logs: products of many probabilities shrink to nearly zero, but logs turn them into sums, and since the log is increasing the best path is the same. Second, the best path is not the same as picking the most likely state on each day separately. The path can be forced by what comes later, as the example shows.

Small, Large, Large againDay 1: δ1=(0.54, 0.12)\delta_1=(0.54,\ 0.12)δ1​=(0.54, 0.12). Day 2 (large): Calm comes best from Calm, 0.54⋅0.9⋅0.1=0.04860.54\cdot0.9\cdot0.1=0.04860.54⋅0.9⋅0.1=0.0486. Stormy comes best from Stormy, 0.12⋅0.8⋅0.7=0.06720.12\cdot0.8\cdot0.7=0.06720.12⋅0.8⋅0.7=0.0672, not from Calm (0.54⋅0.1⋅0.7=0.03780.54\cdot0.1\cdot0.7=0.03780.54⋅0.1⋅0.7=0.0378). Day 3: Stormy comes from Stormy, 0.0672⋅0.8⋅0.7=0.03760.0672\cdot0.8\cdot0.7=0.03760.0672⋅0.8⋅0.7=0.0376, and Calm only 0.00440.00440.0044. The best path is Stormy, Stormy, Stormy with probability 0.03760.03760.0376. Yet day one alone looked calm with probability 0.820.820.82. The later large moves pull the whole story toward Stormy. This path is 1.781.781.78 times more likely than Calm, Stormy, Stormy (0.02120.02120.0212).
  • Viterbi replaces the sum of the forward algorithm by a maximum and keeps back-pointers.
  • The best path can differ from the most likely state of each day taken separately.
  • Use logs: sums of logs avoid underflow and keep the same best path.

Lab · what's graded

  • A Viterbi score on day two15 pts
  • The best path's probability15 pts
  • The log of the best path10 pts
  • Against another path10 pts
  • The first state of the best path15 pts
  • The steps of Viterbi10 pts
  • Match the vocabulary10 pts
  • Why use logs15 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

With δ1=(0.54, 0.12)\delta_1=(0.54,\ 0.12)δ1​=(0.54, 0.12) and a large move on day 2, what is δ2(S)=max⁡(0.54⋅0.1, 0.12⋅0.8)⋅0.7\delta_2(S)=\max(0.54\cdot0.1,\ 0.12\cdot0.8)\cdot0.7δ2​(S)=max(0.54⋅0.1, 0.12⋅0.8)⋅0.7? Give four decimals.

d=d =d=accepted: ± 0.0003
2Numeric answer15 ptsNot answered

With δ2=(0.0486, 0.0672)\delta_2=(0.0486,\ 0.0672)δ2​=(0.0486, 0.0672) and a large move on day 3, what is δ3(S)=max⁡(0.0486⋅0.1, 0.0672⋅0.8)⋅0.7\delta_3(S)=\max(0.0486\cdot0.1,\ 0.0672\cdot0.8)\cdot0.7δ3​(S)=max(0.0486⋅0.1, 0.0672⋅0.8)⋅0.7, the probability of the best path? Give four decimals.

d=d =d=accepted: ± 0.0003
3Numeric answer10 ptsNot answered

What is the natural log of the best path's probability 0.03760.03760.0376? Give two decimals.

l=l =l=accepted: ± 0.02
4Numeric answer10 ptsNot answered

How many times more likely is the best path (probability 0.03760.03760.0376) than the path Calm, Stormy, Stormy (probability 0.02120.02120.0212)? Give two decimals.

r=r =r=accepted: ± 0.02
5Choice15 ptsNot answered

Day one shows a small move, which makes Calm 82% likely on its own. What is the first state of the best path for Small, Large, Large?

6Order the steps10 ptsNot answered

Put the steps of Viterbi decoding 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. 1After the last day, pick the state with the largest score
  2. 2Start with delta equal to start probability times the first emission
  3. 3Walk back through the pointers to read the path
  4. 4For each day and state, keep the best predecessor and remember it
7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

δt(j)\delta_t(j)δt​(j)
ψt(j)\psi_t(j)ψt​(j)
Forward algorithm
Viterbi algorithm
8Explain in words15 ptsNot answered

In one or two sentences, explain why Viterbi decoding is usually written with logs of the probabilities and why that does not change the best path.

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