σμ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.4·~1 hr 10 minAdvanced

Baum-Welch and EM

Skill positionModule 2 of 3 · Topic 4 of 4
2.4 Baum-Welch and EM
—Lab score— / 100Total XP—Streak—

Letting the model learn its own numbers

So far we assumed that we knew π\piπ, AAA and BBB. In real data we do not: we only have the observations. The Baum-Welch algorithm learns the numbers from the data. It is an example of expectation-maximisation (EM), and it works by repeating two steps. In the E-step, use the current numbers and the forward-backward algorithm to work out how likely each hidden state and each state switch was on each day. In the M-step, re-estimate the numbers by counting, but with these probabilities instead of whole counts.

πi←γ1(i),Aij←∑t=1T−1ξt(i,j)∑t=1T−1γt(i),Bj(k)←∑tγt(j) [ot=k]∑tγt(j)\pi_i\leftarrow\gamma_1(i),\qquad A_{ij}\leftarrow\frac{\sum_{t=1}^{T-1}\xi_t(i,j)}{\sum_{t=1}^{T-1}\gamma_t(i)},\qquad B_j(k)\leftarrow\frac{\sum_t\gamma_t(j)\,[o_t=k]}{\sum_t\gamma_t(j)}πi​←γ1​(i),Aij​←∑t=1T−1​γt​(i)∑t=1T−1​ξt​(i,j)​,Bj​(k)←∑t​γt​(j)∑t​γt​(j)[ot​=k]​(1)

Here γt(i)\gamma_t(i)γt​(i) is the smoothed probability of state iii on day ttt and ξt(i,j)\xi_t(i,j)ξt​(i,j) is the smoothed probability of moving from iii to jjj between day ttt and t+1t+1t+1. So the new AijA_{ij}Aij​ is the expected number of i→ji\to ji→j moves divided by the expected number of days spent in iii. Two facts are worth knowing. The log-likelihood of the data never decreases from one EM round to the next, so you can stop when it stops improving. But EM only climbs to the nearest peak, so it can end on a local maximum, and different starting values can give different answers. In practice one tries several starts and keeps the best.

One round on Small, Large, LargeFrom the last topic, the smoothed chance of Calm on the three days is (0.430, 0.118, 0.097)(0.430,\ 0.118,\ 0.097)(0.430, 0.118, 0.097). The expected number of calm days is 0.6450.6450.645. The new start probability of Calm is 0.4300.4300.430. Day one was the only small move, so the new chance of a small move in Calm is 0.430/0.645=0.6670.430/0.645=0.6670.430/0.645=0.667. The expected number of Calm-to-Calm moves is 0.1790.1790.179 and the expected number of days spent in Calm before a move is 0.430+0.118=0.5480.430+0.118=0.5480.430+0.118=0.548, so the new ACC=0.179/0.548=0.327A_{CC}=0.179/0.548=0.327ACC​=0.179/0.548=0.327. With three days of data this is only an illustration, but real runs repeat it on thousands of days until the log-likelihood stops improving.
  • E-step: with the current numbers, compute γ\gammaγ and ξ\xiξ by forward-backward.
  • M-step: re-estimate π\piπ, AAA and BBB as expected counts divided by expected totals.
  • The log-likelihood never falls, but EM can stop at a local maximum: try several starts.

Lab · what's graded

  • Expected calm days10 pts
  • A new emission probability15 pts
  • A new start probability10 pts
  • A new transition probability15 pts
  • What EM guarantees15 pts
  • One EM round10 pts
  • Match the vocabulary10 pts
  • Why starts matter15 pts
0/ 8 answered
Tasks
1Numeric answer10 ptsNot answered

The smoothed chances of Calm on the three days are 0.430, 0.118, 0.0970.430,\ 0.118,\ 0.0970.430, 0.118, 0.097. What is the expected number of calm days, their sum? Give three decimals.

c=c =c=accepted: ± 0.002
2Numeric answer15 ptsNot answered

Only day one was a small move. What is the new BC(s)B_C(s)BC​(s), the smoothed Calm weight of the small-move days divided by the expected number of calm days, 0.430/0.6450.430/0.6450.430/0.645? Give three decimals.

b=b =b=accepted: ± 0.003
3Numeric answer10 ptsNot answered

What is the new start probability of Calm, πC←γ1(C)\pi_C\leftarrow\gamma_1(C)πC​←γ1​(C), from the numbers above?

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

The expected number of Calm-to-Calm moves is 0.1790.1790.179 and the expected number of days in Calm before a move is 0.5480.5480.548. What is the new ACC=0.179/0.548A_{CC}=0.179/0.548ACC​=0.179/0.548? Give three decimals.

a=a =a=accepted: ± 0.003
5Choice15 ptsNot answered

What is guaranteed about the log-likelihood of the data from one EM round to the next?

6Order the steps10 ptsNot answered

Put the steps of Baum-Welch 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. 1M-step: re-estimate pi, A and B from the expected counts
  2. 2Start from a guess for pi, A and B
  3. 3Check the log-likelihood and repeat until it stops improving
  4. 4E-step: compute gamma and xi with forward-backward
7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

γt(i)\gamma_t(i)γt​(i)
ξt(i,j)\xi_t(i,j)ξt​(i,j)
E-step
M-step
8Explain in words15 ptsNot answered

In one or two sentences, explain why running Baum-Welch from different starting values can give different answers.

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