σμ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
  • 日本語
  • 中文
Particle filtering and non-stationary time series skill›Module 2 · Particle filters›Topic 2.1·~55 minAdvanced

Importance sampling

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

Estimating with weighted guesses

Often you want an average under a distribution ppp that you cannot draw from. In filtering, ppp is the belief about the hidden state after seeing today's data. The trick of importance sampling is to draw from an easy distribution ggg instead, called the proposal, and to repair the mismatch with weights. A point xix_ixi​ that the proposal produces too often gets a small weight, and one it produces too rarely gets a large weight: wi=p(xi)/g(xi)w_i=p(x_i)/g(x_i)wi​=p(xi​)/g(xi​). Usually ppp is known only up to a constant, so the weights are divided by their sum, which makes them add to 111.

wi=p(xi)g(xi),w~i=wi∑jwj,Ep[f]≈∑iw~i f(xi),ESS=1∑iw~i2w_i=\frac{p(x_i)}{g(x_i)},\quad \tilde w_i=\frac{w_i}{\sum_j w_j},\quad E_p[f]\approx\sum_i\tilde w_i\,f(x_i),\quad \mathrm{ESS}=\frac{1}{\sum_i\tilde w_i^{2}}wi​=g(xi​)p(xi​)​,w~i​=∑j​wj​wi​​,Ep​[f]≈i∑​w~i​f(xi​),ESS=∑i​w~i2​1​(1)

In a filter, the proposal is the prediction (where the state is likely to be before seeing the data) and the target is the belief after the data. Their ratio is just the likelihood of the observation, so the weight of a particle is how well it explains yyy. The effective sample size, ESS, tells how many equally weighted draws the weighted sample is worth. It equals NNN when all weights are equal and 111 when one point carries everything. When ESS is small the estimate rests on a few points and is noisy. This happens when the proposal misses the places where the target has most of its mass, for example when the data is a big surprise.

Four particles and one observationFour draws from the prediction are x=−1,0,1,2x=-1,0,1,2x=−1,0,1,2, and we observe y=1y=1y=1 with noise variance r=1r=1r=1. The unnormalised weights are e−(1−x)2/2=0.135, 0.607, 1, 0.607e^{-(1-x)^2/2}=0.135,\ 0.607,\ 1,\ 0.607e−(1−x)2/2=0.135, 0.607, 1, 0.607, which sum to 2.3482.3482.348. The normalised weights are 0.058, 0.258, 0.426, 0.2580.058,\ 0.258,\ 0.426,\ 0.2580.058, 0.258, 0.426, 0.258. The weighted mean is 0.8850.8850.885 and the weighted second moment is 1.5161.5161.516, so the variance is 1.516−0.8852=0.7341.516-0.885^{2}=0.7341.516−0.8852=0.734. The effective sample size is 1/(0.0582+0.2582+0.4262+0.2582)=3.141/(0.058^2+0.258^2+0.426^2+0.258^2)=3.141/(0.0582+0.2582+0.4262+0.2582)=3.14 out of 444.
  • Weights repair the mismatch: draw from an easy ggg, weight by p/gp/gp/g, divide by the sum.
  • In a filter the weight is the likelihood: the particle that explains the observation best gets the most weight.
  • Watch the ESS: 1/∑w~21/\sum\tilde w^{2}1/∑w~2 falls when a few points dominate, which is the warning sign of a poor proposal.

Lab · what's graded

  • A normalised weight15 pts
  • The weighted mean15 pts
  • The effective sample size15 pts
  • The weighted variance10 pts
  • A dangerous proposal10 pts
  • The steps of importance sampling10 pts
  • Match the vocabulary10 pts
  • Why weights are needed15 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

The unnormalised weights of the four particles are 0.135, 0.607, 1, 0.6070.135,\ 0.607,\ 1,\ 0.6070.135, 0.607, 1, 0.607 and they sum to 2.3482.3482.348. What is the normalised weight of the first particle? Give three decimals.

w=w =w=accepted: ± 0.001
2Numeric answer15 ptsNot answered

The particles x=−1,0,1,2x=-1,0,1,2x=−1,0,1,2 have normalised weights 0.058, 0.258, 0.426, 0.2580.058,\ 0.258,\ 0.426,\ 0.2580.058, 0.258, 0.426, 0.258. What is the weighted mean ∑w~ixi\sum\tilde w_i x_i∑w~i​xi​? Give three decimals.

m=m =m=accepted: ± 0.003
3Numeric answer15 ptsNot answered

With normalised weights 0.058, 0.258, 0.426, 0.2580.058,\ 0.258,\ 0.426,\ 0.2580.058, 0.258, 0.426, 0.258, the sum of squared weights is 0.3180.3180.318. What is the effective sample size 1/∑w~i21/\sum\tilde w_i^{2}1/∑w~i2​? Give two decimals.

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

The weighted second moment ∑w~ixi2\sum\tilde w_i x_i^{2}∑w~i​xi2​ is 1.5161.5161.516 and the weighted mean is 0.8850.8850.885. What is the weighted variance? Give three decimals.

v=v =v=accepted: ± 0.004
5Choice10 ptsNot answered

Which proposal is most likely to give a tiny effective sample size?

6Order the steps10 ptsNot answered

Put the steps of self-normalised importance sampling 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. 1Divide each weight by the sum of the weights
  2. 2Draw points from the easy proposal
  3. 3Average the quantity with the normalised weights
  4. 4Compute a weight for each point: target over proposal
7Match10 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Proposal
Target
Importance weight
Effective sample size
8Explain in words15 ptsNot answered

In one or two sentences, explain why we must weight the draws by p/gp/gp/g when we sample from the proposal ggg instead of the target ppp.

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