THE SCORE KALMAN FILTER · EQUATION LAB

From moments to a score

Change a non-Gaussian prior, inspect the linear solve, then add one observation.

Fit four coefficients from seven moments

Eqs. (8)–(9) ↗
Density · reference and fitted family
Score · derivative of log density

Teaching example, not a reproduction of the paper’s experiments. Quadrature supplies reference data and density plots only.

What this lab computes

1. An ordinary linear system

For p(x) ∝ exp(−Σⱼ λⱼxʲ), the score is s(x) = −Σⱼ jλⱼxʲ⁻¹. The normalizing constant disappears after differentiation. With j,k ∈ {1,2,3,4}, the score-matching system is Aⱼₖ = jkmⱼ₊ₖ₋₂ and dⱼ = j(j−1)mⱼ₋₂. We write the right-hand side as d to distinguish it from the prior’s shape parameter b. A stable, scaled pivoted solve returns λ. Paper Eqs. (8)–(9).

2. Higher moments from Stein’s identity

For an integer β ≥ 1, λ₁mᵦ + 2λ₂mᵦ₊₁ + 3λ₃mᵦ₊₂ + 4λ₄mᵦ₊₃ = βmᵦ₋₁. With m₀ … m₆ known, β = 4 gives m₇. Then β = 5 gives m₈ using the newly computed m₇. These moments are compared with withheld reference values. This is a scalar illustration of the closure relation, without a dynamical prediction step. Paper Eq. (12).

3. Add the likelihood score once

For one observation y = x + v, with v ∼ N(0,R), the likelihood score is (y−x)/R. Thus λ₁⁺ = λ₁⁻ − y/R and λ₂⁺ = λ₂⁻ + 1/(2R). The cubic and quartic coefficients stay unchanged. Moving an observation slider recomputes this single update from the prior. Paper Eqs. (13)–(14).

Reference calculations are separate

Deterministic composite Simpson quadrature with 4,096 intervals creates synthetic input moments and normalizes the plotted prior, fitted family, and posterior. Integration bounds expand until the tails are negligible. Neither score fitting nor Stein closure uses quadrature internally. The displayed posterior mean and variance are reference values from quadrature. The paper’s truncated posterior moment recovery, Eq. (15), and full filter are not implemented here.