σμ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.1·~1 hrAdvanced

The forward algorithm

Skill positionModule 2 of 3 · Topic 1 of 4
2.1 The forward algorithm
—Lab score— / 100Total XP—Streak—

How likely is what we saw?

Suppose we saw the moves Small, Large, Large. How likely is that sequence under our model? We could list every hidden path (Calm-Calm-Calm, Calm-Calm-Stormy, and so on), compute each path's probability and add them up. With KKK states and TTT days that is KTK^{T}KT paths, far too many. The forward algorithm does the same sum in T⋅K2T\cdot K^{2}T⋅K2 steps by reusing work. It keeps a number αt(j)\alpha_t(j)αt​(j): the probability of the first ttt observations and of being in state jjj on day ttt.

α1(j)=πjBj(o1),αt(j)=[∑iαt−1(i)Aij]Bj(ot),P(o1,…,oT)=∑jαT(j)\alpha_1(j)=\pi_jB_j(o_1),\qquad \alpha_t(j)=\Big[\sum_i\alpha_{t-1}(i)A_{ij}\Big]B_j(o_t),\qquad P(o_1,\dots,o_T)=\sum_j\alpha_T(j)α1​(j)=πj​Bj​(o1​),αt​(j)=[i∑​αt−1​(i)Aij​]Bj​(ot​),P(o1​,…,oT​)=j∑​αT​(j)(1)

Read the recursion in words: to be in state jjj today, you came from some state iii yesterday (sum over iii with the transition chance), and then today's state produced today's observation. Dividing αt\alpha_tαt​ by its total gives the filtered probabilities, your belief about today's state given the data up to today. One practical problem: multiplying many small numbers gives numbers that shrink toward zero and underflow. So at each step we divide by the total ctc_tct​ and keep it. The log of the data probability is then simply the sum of ln⁡ct\ln c_tlnct​.

Small, Large, LargeDay 1: α1=(0.6⋅0.9, 0.4⋅0.3)=(0.54, 0.12)\alpha_1=(0.6\cdot0.9,\ 0.4\cdot0.3)=(0.54,\ 0.12)α1​=(0.6⋅0.9, 0.4⋅0.3)=(0.54, 0.12), total c1=0.66c_1=0.66c1​=0.66. Day 2 (a large move): Calm gets (0.54⋅0.9+0.12⋅0.2)⋅0.1=0.051(0.54\cdot0.9+0.12\cdot0.2)\cdot0.1=0.051(0.54⋅0.9+0.12⋅0.2)⋅0.1=0.051 and Stormy gets (0.54⋅0.1+0.12⋅0.8)⋅0.7=0.105(0.54\cdot0.1+0.12\cdot0.8)\cdot0.7=0.105(0.54⋅0.1+0.12⋅0.8)⋅0.7=0.105, total 0.1560.1560.156, so the filtered chance of Stormy is 0.105/0.156=0.6730.105/0.156=0.6730.105/0.156=0.673. Day 3 gives α3=(0.00669, 0.06237)\alpha_3=(0.00669,\ 0.06237)α3​=(0.00669, 0.06237). The probability of the whole sequence is 0.00669+0.06237=0.06910.00669+0.06237=0.06910.00669+0.06237=0.0691, and its log is −2.673-2.673−2.673.
  • Forward algorithm: sum over all hidden paths in T⋅K2T\cdot K^{2}T⋅K2 steps instead of KTK^{T}KT.
  • Filtered probabilities: normalise αt\alpha_tαt​ to get your belief about today's state from data up to today.
  • Scaling: divide by ctc_tct​ each step and add up ln⁡ct\ln c_tlnct​ to avoid underflow.

Lab · what's graded

  • The first forward value15 pts
  • The total of day one10 pts
  • Filtered after two days15 pts
  • The probability of the sequence15 pts
  • The log-likelihood10 pts
  • What the forward algorithm saves10 pts
  • Match the vocabulary10 pts
  • Why the values are rescaled15 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

Day 1 shows a small move. What is α1(C)=πC BC(s)\alpha_1(C)=\pi_C\,B_C(s)α1​(C)=πC​BC​(s) with πC=0.6\pi_C=0.6πC​=0.6 and BC(s)=0.9B_C(s)=0.9BC​(s)=0.9?

a=a =a=accepted: ± 0.005
2Numeric answer10 ptsNot answered

With α1=(0.54, 0.12)\alpha_1=(0.54,\ 0.12)α1​=(0.54, 0.12), what is the total c1c_1c1​, the probability of the first observation?

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

After the observations Small and Large, α2=(0.051, 0.105)\alpha_2=(0.051,\ 0.105)α2​=(0.051, 0.105). What is the filtered probability of the stormy state, 0.105/(0.051+0.105)0.105/(0.051+0.105)0.105/(0.051+0.105)? Give three decimals.

p=p =p=accepted: ± 0.003
4Numeric answer15 ptsNot answered

On day 3, α3=(0.00669, 0.06237)\alpha_3=(0.00669,\ 0.06237)α3​=(0.00669, 0.06237). What is the probability of the whole sequence Small, Large, Large, the sum of α3\alpha_3α3​? Give four decimals.

p=p =p=accepted: ± 0.0003
5Numeric answer10 ptsNot answered

What is the natural log of the probability 0.06910.06910.0691 of the sequence? Give two decimals.

l=l =l=accepted: ± 0.02
6Choice10 ptsNot answered

What does the forward algorithm let us avoid?

7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

αt(j)\alpha_t(j)αt​(j)
Filtered probability
ctc_tct​
∑jαT(j)\sum_j\alpha_T(j)∑j​αT​(j)
8Explain in words15 ptsNot answered

In one or two sentences, explain why a real implementation of the forward algorithm divides by ctc_tct​ at every step.

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