3.5.22Guidance, Navigation & Control (GNC)

Kalman gain — minimizes trace of covariance

1,812 words8 min readdifficulty · medium

WHAT are we minimizing?


Set-up: the update step

At the measurement step we have:

  • Prior (predicted) estimate x^\hat{x}^- with covariance PP^-.
  • Measurement z=Hx+vz = Hx + v, where vv is sensor noise, E[vv]=R\mathbb{E}[vv^\top]=R, uncorrelated with the state error.
  • HH maps state → measurement space.

We form a linear corrected estimate: x^+=x^+K(zHx^).\hat{x}^+ = \hat{x}^- + K(z - H\hat{x}^-).


Derivation from first principles

Step 1 — Propagate the error. Define priors error e=xx^e^- = x-\hat{x}^-. Then e+=xx^+=xx^K(zHx^).e^+ = x-\hat{x}^+ = x-\hat{x}^- - K(z-H\hat{x}^-). Why this step? Just substitute the update rule — we track how the error transforms.

Substitute z=Hx+vz = Hx+v: e+=eK(Hx+vHx^)=eKHeKv=(IKH)eKv.e^+ = e^- - K(Hx + v - H\hat{x}^-) = e^- - KH e^- - Kv = (I-KH)e^- - Kv. Why this step? Grouping HxHx^=HeHx - H\hat{x}^- = He^- exposes the error explicitly; vv is the injected sensor noise.

Step 2 — Compute the posterior covariance. P+=E[e+e+].P^+ = \mathbb{E}[e^+ e^{+\top}]. Because ee^- and vv are uncorrelated (E[ev]=0\mathbb{E}[e^-v^\top]=0), cross terms vanish: P+=(IKH)P(IKH)+KRK.\boxed{P^+ = (I-KH)P^-(I-KH)^\top + K R K^\top.} Why this step? This is the Joseph form — valid for any gain KK, not just the optimal one. It's guaranteed symmetric and positive-semidefinite. It cleanly separates the "prediction contribution" from the "noise contribution."

Step 3 — Minimize the trace. We minimize J(K)=tr(P+)J(K)=\operatorname{tr}(P^+). Expand: P+=PKHPPHK+K(HPH+R)K.P^+ = P^- - KHP^- - P^-H^\top K^\top + K(HP^-H^\top + R)K^\top. Let S=HPH+RS = HP^-H^\top + R (the innovation covariance). Take the trace and use two matrix-calculus identities:

\frac{\partial}{\partial K}\operatorname{tr}(KBK^\top)=2KB\ (B\text{ symmetric}).$$ Then $$\frac{\partial J}{\partial K} = -2(HP^-)^\top + 2KS = -2P^-H^\top + 2KS.$$ *Why this step?* The two mixed terms $\operatorname{tr}(KHP^-)$ and $\operatorname{tr}(P^-H^\top K^\top)$ are equal (trace of a matrix = trace of its transpose), giving the factor 2. Set the derivative to zero: $$KS = P^-H^\top \implies$$ > [!formula] Optimal Kalman gain > $$\boxed{K = P^-H^\top\,(HP^-H^\top + R)^{-1} = P^-H^\top S^{-1}}$$ > This $K$ minimizes $\operatorname{tr}(P^+)$. The second derivative $2S$ is positive-definite, so it's a genuine **minimum**. **Step 4 — Simplified posterior at the optimum.** Plug optimal $K$ into $P^+$. Since $KS=P^-H^\top$, the $K R K^\top$ term collapses and: $$\boxed{P^+ = (I-KH)P^-.}$$ *Why this step?* Nice, but only true at the *optimal* $K$. For numerical safety implementers keep the Joseph form. ![[3.5.22-Kalman-gain-—-minimizes-trace-of-covariance.png]] --- ## Limiting cases (Forecast-then-Verify) > [!example] Perfect sensor, $R\to 0$ > **Forecast:** we should trust the sensor completely. > **Verify:** $K = P^-H^\top(HP^-H^\top)^{-1}$. In scalar $H=1$: $K = P^-/P^- = 1$. Then $\hat{x}^+ = z$ — exactly the measurement. ✅ > [!example] Useless sensor, $R\to\infty$ > **Forecast:** ignore the measurement. > **Verify:** $S\to\infty$ so $K = P^-H^\top S^{-1}\to 0$. Then $\hat{x}^+=\hat{x}^-$. ✅ > [!example] Scalar numeric > $P^-=4,\ H=1,\ R=1$. > $S = 4+1=5$, $K = 4/5 = 0.8$. > New covariance $P^+ = (1-0.8)\cdot 4 = 0.8$. > *Why this step?* Since $P^+=0.8 < 4 = P^-$ and $<1=R$, the fused estimate is **more certain than either source alone** — the whole point of fusion. --- ## Common mistakes > [!mistake] "Bigger gain always = better estimate." > **Why it feels right:** larger $K$ uses the measurement more, and measurements feel like "real data." > **The fix:** the trace $\operatorname{tr}(P^+)$ is a *parabola* in $K$ (the $KRK^\top$ term is quadratic and positive). Beyond the optimum, extra $K$ injects more sensor noise than it removes prediction error. There's a unique sweet spot. > [!mistake] Forgetting the noise term when deriving $P^+$. > **Why it feels right:** people write $P^+=(I-KH)P^-$ and use it for *any* $K$. > **The fix:** that shortcut is **only valid at the optimal $K$**. For arbitrary $K$ you must use the Joseph form $(I-KH)P^-(I-KH)^\top + KRK^\top$. > [!mistake] Treating $S^{-1}$ as $1/R$. > **Why it feels right:** $R$ is the sensor noise, so it looks like "the thing to divide by." > **The fix:** $S = HP^-H^\top + R$ includes the propagated prior uncertainty. Both sources' confidence matter. --- > [!recall]- Feynman: explain to a 12-year-old > You're guessing where a ball will land. Your friend (the model) predicts a spot; a slightly blurry photo (the sensor) shows another spot. Neither is exact. The Kalman gain is a **slider from 0 to 1** telling you how far to move your guess from the model's spot toward the photo's spot. If the model is usually wrong, slide toward the photo; if the photo is blurry, stay near the model. We pick the slider position that makes our final guess as tight as possible — smallest "how-wrong-am-I" number, which is the **trace** of the uncertainty. > [!mnemonic] > **"PH over S"** — $K = \dfrac{PH}{S}$. Think *"Push toward measurement by Prior-times-H, held back by innovation Spread S."* And the trace is a **U-shaped valley**: too little $K$ = trust bad model; too much $K$ = trust noisy sensor; bottom of the U = optimal. --- ## #flashcards/physics What quantity does the optimal Kalman gain minimize? ::: The trace of the posterior error covariance $\operatorname{tr}(P^+)$, i.e. total mean-squared estimation error. Why is trace the right thing to minimize? ::: $\operatorname{tr}(P)=\mathbb{E}[\|x-\hat x\|^2]$, the total mean-squared error over all state components. State the Joseph-form posterior covariance (valid for any $K$). ::: $P^+=(I-KH)P^-(I-KH)^\top+KRK^\top$. Give the optimal Kalman gain formula. ::: $K=P^-H^\top(HP^-H^\top+R)^{-1}=P^-H^\top S^{-1}$. What is the innovation covariance $S$? ::: $S=HP^-H^\top+R$: predicted uncertainty mapped to measurement space plus sensor noise. Simplified $P^+$ at optimal gain? ::: $P^+=(I-KH)P^-$ — only valid at the optimum. What happens to $K$ as $R\to0$ (perfect sensor)? ::: $K\to H^{-1}$ (scalar: 1); estimate equals measurement. What happens to $K$ as $R\to\infty$ (useless sensor)? ::: $K\to0$; estimate equals prediction. Why does the trace have a unique minimum in $K$? ::: The $KRK^\top$ term makes it a positive-definite quadratic in $K$; second derivative $2S\succ0$. Derivative identity used to minimize the trace? ::: $\partial_K\operatorname{tr}(KBK^\top)=2KB$ and $\partial_K\operatorname{tr}(KA)=A^\top$. --- ## Connections - [[Kalman Filter — Predict Step]] - [[Kalman Filter — Update Step]] - [[Covariance Matrices and Uncertainty]] - [[Least Squares Estimation]] (Kalman = recursive weighted least squares) - [[Innovation and Residuals]] - [[Joseph Form Covariance Update]] - [[Extended Kalman Filter (EKF) in GNC]] - [[Sensor Fusion in Navigation]] ## 🖼️ Concept Map ```mermaid flowchart TD PRED[Prediction x-hat-minus, P-minus] -->|blended by K| EST[Corrected estimate x-hat-plus] MEAS[Measurement z = Hx + v] -->|forms innovation| INNOV[Innovation z - H x-hat-minus] INNOV -->|scaled by K| EST K[Kalman gain K] -->|controls trust| EST EST -->|error e = x - x-hat| ERR[Estimation error] ERR -->|expected outer product| P[Error covariance P] P -->|sum of diagonal| TR[Trace tr of P] TR -->|equals total mean-squared error| MSE[Total MSE] P -->|Joseph form| JOS[P-plus = I-KH P-minus I-KH transpose + K R K transpose] JOS -->|larger K shrinks prediction term| TRADE[Trade-off] JOS -->|larger K grows K R K transpose| TRADE TRADE -->|minimize trace| K ``` ## 🔊 Hinglish (regional understanding) > [!intuition]- Hinglish mein samjho > Dekho, Kalman filter ka kaam hai do "guesses" ko smartly mix karna: ek model se prediction aati hai, dusri sensor se measurement. Dono thodi noisy hoti hain — koi bhi 100% sahi nahi. Kalman gain $K$ ek slider ki tarah hai jo decide karta hai ki hum measurement ko kitna trust karein aur prediction ko kitna. Agar sensor bahut accha hai (chhota $R$), $K$ bada ho jaata hai aur hum measurement ke paas chale jaate hain; agar sensor bekaar hai (bada $R$), $K$ chhota ho jaata hai aur hum apni prediction pe tike rehte hain. > > Ab "best" $K$ kaunsa hai? Iske liye hum error covariance matrix $P$ ka **trace** minimize karte hain. Trace matlab saare state components ki variance ka sum — yani total mean-squared error. Jitna chhota trace, utna certain hamara estimate. Derivation simple hai: error propagate karo, Joseph form $P^+=(I-KH)P^-(I-KH)^\top+KRK^\top$ likho, phir trace ko $K$ ke respect me differentiate karke zero set karo. Result nikalta hai $K=P^-H^\top S^{-1}$ jahan $S=HP^-H^\top+R$ innovation covariance hai. > > Key intuition: trace, $K$ ka ek **U-shaped (parabola)** function hai. Bahut kam $K$ = kharab model pe bharosa, bahut zyada $K$ = sensor noise andar aane lagti hai. U ke bottom par optimal $K$ milta hai — jahan dono errors balance ho jaate hain. Isiliye fused estimate ki uncertainty dono individual sources se bhi kam ho sakti hai (jaise numeric example me $P^+=0.8$ jabki $P^-=4$ aur $R=1$). > > GNC me yeh core hai — spacecraft, rockets, drones sab isi se apni position/velocity accurately estimate karte hain, jahan GPS, IMU, star-trackers sab noisy data dete hain. Yaad rakho mnemonic "PH over S", aur ek galti se bachna: $P^+=(I-KH)P^-$ sirf optimal $K$ par valid hai, general $K$ ke liye Joseph form use karo. ![[audio/3.5.22-Kalman-gain-—-minimizes-trace-of-covariance.mp3]]

Go deeper — visual, from zero

Test yourself — Guidance, Navigation & Control (GNC)

Connections