1. State-Space Model

Transition Equation

xt=Atxt−1+Wtwt\mathbf{x}_t = \mathbf{A}_t\mathbf{x}_{t-1} + \mathbf{W}_t\mathbf{w}_t

where:

  • xt∈Rnx\mathbf{x}_t\in\mathbb{R}^{n_x} = Hidden (latent) state variable/vector.

  • At∈Rnx×nx\mathbf{A}_t\in\mathbb{R}^{n_x\times n_x} = State transition matrix mapping the previous hidden state xt−1\mathbf{x}_{t-1} into the current hidden state xt\mathbf{x}_t.

  • wt∈Rnw\mathbf{w}_t\in\mathbb{R}^{n_w} = Hidden process noise variable/vector with zero mean, representing random shocks in the evolution of the hidden state.

  • Wt∈Rnx×nw\mathbf{W}_t\in\mathbb{R}^{n_x\times n_w} = Matrix that maps the process noise wt\mathbf{w}_t into the hidden state equation.

  • Qt=E[wtwt′]∈Rnw×nw\mathbf{Q}_t=\mathbb{E}[\mathbf{w}_t\mathbf{w}_t^{\prime}]\in\mathbb{R}^{n_w\times n_w} = Covariance matrix of the process noise wt\mathbf{w}_t.

Measurement Equation

zt=Htxt+Utut\mathbf{z}_t = \mathbf{H}_t\mathbf{x}_t + \mathbf{U}_t\mathbf{u}_t

where:

  • zt∈Rnz\mathbf{z}_t\in\mathbb{R}^{n_z} = Observed measurement variable/vector.

  • Ht∈Rnz×nx\mathbf{H}_t\in\mathbb{R}^{n_z\times n_x} = Measurement matrix mapping the current hidden state xt\mathbf{x}_t into the observed variable zt\mathbf{z}_t.

  • ut∈Rnu\mathbf{u}_t\in\mathbb{R}^{n_u} = Measurement noise variable/vector with zero mean, representing random errors affecting the observed measurement.

  • Ut∈Rnz×nu\mathbf{U}_t\in\mathbb{R}^{n_z\times n_u} = Matrix that maps the measurement noise ut\mathbf{u}_t into the measurement equation.

  • Rt=E[utut′]∈Rnu×nu\mathbf{R}_t=\mathbb{E}[\mathbf{u}_t\mathbf{u}_t^{\prime}]\in\mathbb{R}^{n_u\times n_u} = Covariance matrix of the measurement noise ut\mathbf{u}_t.

2. Algorithm

Kalman Filter proceeds in initialization and two recursive steps as follows:

(0) Initialization

x^0∣0=x0\widehat{\mathbf{x}}_{0\mid 0}=\mathbf{x}_0 P0∣0=P0\mathbf{P}_{0\mid 0}=\mathbf{P}_0

Recursive loop for t=1t=1 to NN:

(1) Prediction (Time Update)

Using all observations up to time t−1t-1, we can predict the distribution of the hidden state at time tt:

p ⁣(xt−1∣z1:t−1)⟶p ⁣(xt∣z1:t−1)p\!\left(\mathbf{x}_{t-1}\mid\mathbf{z}_{1:t-1}\right) \longrightarrow p\!\left(\mathbf{x}_t\mid\mathbf{z}_{1:t-1}\right)

and specifically due to the Markov property and the zero mean of the process noise, we can estimate hidden state a priori by using the previous filtered estimate of the hidden state as:

x^t∣t−1⏞Prior conditionalexpectation of xt=E ⁣[xt∣z1:t−1]=E ⁣[Atxt−1+Wtwt∣z1:t−1]=Atx^t−1∣t−1.\overbrace{\widehat{\mathbf{x}}_{t\mid t-1}}^{\substack{\text{Prior conditional}\\\text{expectation of }\mathbf{x}_t}} = \mathbb{E}\!\left[\mathbf{x}_t\mid\mathbf{z}_{1:t-1}\right] = \mathbb{E}\!\left[ \mathbf{A}_t\mathbf{x}_{t-1} + \mathbf{W}_t\mathbf{w}_t \mid \mathbf{z}_{1:t-1} \right] = \mathbf{A}_t\widehat{\mathbf{x}}_{t-1\mid t-1}.

Then by considering estimation errors:

et∣t−1=xt−x^t∣t−1\mathbf{e}_{t\mid t-1} = \mathbf{x}_t- \widehat{\mathbf{x}}_{t\mid t-1} et−1∣t−1=xt−1−x^t−1∣t−1\mathbf{e}_{t-1\mid t-1} = \mathbf{x}_{t-1}- \widehat{\mathbf{x}}_{t-1\mid t-1}

A priori error covariance, variance in case xt\mathbf{x}_t is scalar, representing uncertainty of estimate x^t∣t−1\widehat{\mathbf{x}}_{t\mid t-1} is:

Pt∣t−1⏞Prior uncertainty ofx^t∣t−1 estimate=E ⁣[(xt−x^t∣t−1)(xt−x^t∣t−1)′]=E ⁣[et∣t−1et∣t−1′]∈Rnx×nx.\overbrace{\mathbf{P}_{t\mid t-1}}^{\substack{\text{Prior uncertainty of}\\\widehat{\mathbf{x}}_{t\mid t-1}\text{ estimate}}} = \mathbb{E}\!\left[ \left(\mathbf{x}_t-\widehat{\mathbf{x}}_{t\mid t-1}\right) \left(\mathbf{x}_t-\widehat{\mathbf{x}}_{t\mid t-1}\right)^{\prime} \right] = \mathbb{E}\!\left[ \mathbf{e}_{t\mid t-1}\mathbf{e}_{t\mid t-1}^{\prime} \right] \in\mathbb{R}^{n_x\times n_x}.

This can be further written down as:

Pt∣t−1=E ⁣[(Atxt−1+Wtwt−Atx^t−1∣t−1)⋅(Atxt−1+Wtwt−Atx^t−1∣t−1)′]=E ⁣[(At(xt−1−x^t−1∣t−1)+Wtwt)⋅(At(xt−1−x^t−1∣t−1)+Wtwt)′]=E ⁣[(Atet−1∣t−1+Wtwt)(Atet−1∣t−1+Wtwt)′]=E ⁣[Atet−1∣t−1et−1∣t−1′At′+Atet−1∣t−1wt′Wt′+Wtwtet−1∣t−1′At′+Wtwtwt′Wt′]=AtE ⁣[et−1∣t−1et−1∣t−1′]At′+AtE ⁣[et−1∣t−1wt′]Wt′+WtE ⁣[wtet−1∣t−1′]At′+WtE ⁣[wtwt′]Wt′.\begin{aligned} \mathbf{P}_{t\mid t-1} &= \mathbb{E}\!\Big[ \big( \mathbf{A}_t\mathbf{x}_{t-1} + \mathbf{W}_t\mathbf{w}_t - \mathbf{A}_t\widehat{\mathbf{x}}_{t-1\mid t-1} \big) \cdot \big( \mathbf{A}_t\mathbf{x}_{t-1} + \mathbf{W}_t\mathbf{w}_t - \mathbf{A}_t\widehat{\mathbf{x}}_{t-1\mid t-1} \big)^{\prime} \Big] \\[0.4em] &= \mathbb{E}\!\Big[ \big( \mathbf{A}_t(\mathbf{x}_{t-1}-\widehat{\mathbf{x}}_{t-1\mid t-1}) + \mathbf{W}_t\mathbf{w}_t \big) \cdot \big( \mathbf{A}_t(\mathbf{x}_{t-1}-\widehat{\mathbf{x}}_{t-1\mid t-1}) + \mathbf{W}_t\mathbf{w}_t \big)^{\prime} \Big] \\[0.4em] &= \mathbb{E}\!\left[ \left( \mathbf{A}_t\mathbf{e}_{t-1\mid t-1} + \mathbf{W}_t\mathbf{w}_t \right) \left( \mathbf{A}_t\mathbf{e}_{t-1\mid t-1} + \mathbf{W}_t\mathbf{w}_t \right)^{\prime} \right] \\[0.4em] &= \mathbb{E}\!\Big[ \mathbf{A}_t\mathbf{e}_{t-1\mid t-1} \mathbf{e}_{t-1\mid t-1}^{\prime}\mathbf{A}_t^{\prime} + \mathbf{A}_t\mathbf{e}_{t-1\mid t-1}\mathbf{w}_t^{\prime}\mathbf{W}_t^{\prime} + \mathbf{W}_t\mathbf{w}_t\mathbf{e}_{t-1\mid t-1}^{\prime}\mathbf{A}_t^{\prime} + \mathbf{W}_t\mathbf{w}_t\mathbf{w}_t^{\prime}\mathbf{W}_t^{\prime} \Big] \\[0.4em] &= \mathbf{A}_t\mathbb{E}\!\left[ \mathbf{e}_{t-1\mid t-1}\mathbf{e}_{t-1\mid t-1}^{\prime} \right]\mathbf{A}_t^{\prime} + \mathbf{A}_t\mathbb{E}\!\left[ \mathbf{e}_{t-1\mid t-1}\mathbf{w}_t^{\prime} \right]\mathbf{W}_t^{\prime} \\ &\quad+ \mathbf{W}_t\mathbb{E}\!\left[ \mathbf{w}_t\mathbf{e}_{t-1\mid t-1}^{\prime} \right]\mathbf{A}_t^{\prime} + \mathbf{W}_t\mathbb{E}\!\left[ \mathbf{w}_t\mathbf{w}_t^{\prime} \right]\mathbf{W}_t^{\prime}. \end{aligned}

where

Pt−1∣t−1=E ⁣[et−1∣t−1et−1∣t−1′],\mathbf{P}_{t-1\mid t-1} = \mathbb{E}\!\left[ \mathbf{e}_{t-1\mid t-1}\mathbf{e}_{t-1\mid t-1}^{\prime} \right], E ⁣[et−1∣t−1wt′]=0,E ⁣[wtet−1∣t−1′]=0,\mathbb{E}\!\left[ \mathbf{e}_{t-1\mid t-1}\mathbf{w}_t^{\prime} \right] = \mathbf{0}, \qquad \mathbb{E}\!\left[ \mathbf{w}_t\mathbf{e}_{t-1\mid t-1}^{\prime} \right] = \mathbf{0},

and

Qt=E ⁣[wtwt′],\mathbf{Q}_t = \mathbb{E}\!\left[ \mathbf{w}_t\mathbf{w}_t^{\prime} \right],

so:

Pt∣t−1⏞Prior uncertainty ofx^t∣t−1 estimate=AtPt−1∣t−1At′⏞Uncertainty of x^t−1∣t−1 estimatepropagated by At into the uncertaintyof the predicted state at time t+WtQtWt′⏞Uncertainty of wt propagatedby Wt into the uncertainty ofthe predicted state at time t.\begin{aligned} \overbrace{\mathbf{P}_{t\mid t-1}}^{\substack{\text{Prior uncertainty of}\\\widehat{\mathbf{x}}_{t\mid t-1}\text{ estimate}}} &= \overbrace{ \mathbf{A}_t\mathbf{P}_{t-1\mid t-1}\mathbf{A}_t^{\prime} }^{\substack{ \text{Uncertainty of }\widehat{\mathbf{x}}_{t-1\mid t-1}\text{ estimate}\\ \text{propagated by }\mathbf{A}_t\text{ into the uncertainty}\\ \text{of the predicted state at time }t }} + \overbrace{ \mathbf{W}_t\mathbf{Q}_t\mathbf{W}_t^{\prime} }^{\substack{ \text{Uncertainty of }\mathbf{w}_t\text{ propagated}\\ \text{by }\mathbf{W}_t\text{ into the uncertainty of}\\ \text{the predicted state at time }t }}. \end{aligned}

(2) Correction (Measurement Update)

After observing the new data point zt\mathbf{z}_t, we can update the predicted distribution of the hidden state at time tt to be more accurate:

p ⁣(xt∣z1:t−1)⟶p ⁣(xt∣z1:t)p\!\left(\mathbf{x}_t\mid\mathbf{z}_{1:t-1}\right) \longrightarrow p\!\left(\mathbf{x}_t\mid\mathbf{z}_{1:t}\right)

By combining the previously predicted state estimate x^t∣t−1\widehat{\mathbf{x}}_{t\mid t-1} with the new observation zt\mathbf{z}_t, we obtain the corrected a posteriori estimate of the hidden state using the following State Update Equation:

x^t∣t⏞Posterior conditionalexpectation of xt=E ⁣[xt∣z1:t]=x^t∣t−1+Ktνt=(I−KtHt)⏞Prior-state estimateweight adjusted by Htx^t∣t−1+Kt⏞Measurement weightzt.\begin{aligned} \overbrace{\widehat{\mathbf{x}}_{t\mid t}}^{\substack{\text{Posterior conditional}\\\text{expectation of }\mathbf{x}_t}} &= \mathbb{E}\!\left[\mathbf{x}_t\mid\mathbf{z}_{1:t}\right] = \widehat{\mathbf{x}}_{t\mid t-1} + \mathbf{K}_t\boldsymbol{\nu}_t \\ &= \overbrace{ \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) }^{\substack{\text{Prior-state estimate}\\ \text{weight adjusted by }\mathbf{H}_t}} \widehat{\mathbf{x}}_{t\mid t-1} + \overbrace{\mathbf{K}_t}^{\text{Measurement weight}} \mathbf{z}_t. \end{aligned}

where:

  • νt\boldsymbol{\nu}_t = Innovation process representing the surprise in the new observation, i.e. how badly the observed variable was predicted. For a given Kalman Gain, a larger innovation produces a greater correction to the predicted hidden-state estimate, and vice versa.
νt=zt−z^t∣t−1=Htxt+Utut−Htx^t∣t−1∈Rnz\boldsymbol{\nu}_t = \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} = \mathbf{H}_t\mathbf{x}_t+\mathbf{U}_t\mathbf{u}_t -\mathbf{H}_t\widehat{\mathbf{x}}_{t\mid t-1} \in\mathbb{R}^{n_z}
  • Kt\mathbf{K}_t = Kalman Gain representing the sensitivity of the corrected hidden-state estimate to the innovation process νt\boldsymbol{\nu}_t, i.e., it determines how strongly the predicted estimate is corrected. Greater sensitivity associated with Kt\mathbf{K}_t means that the same innovation produces a larger correction, and vice versa. The Kalman Gain is chosen to minimize the posterior estimation uncertainty represented by Pt∣t\mathbf{P}_{t\mid t}.
Kt=(Incomplete) uncertainty of predicted observationUncertainty of predicted observation+Uncertainty of measurement noise=Pt∣t−1Ht′Ct∣t−1−1=Pt∣t−1Ht′(HtPt∣t−1Ht′+UtRtUt′)−1∈Rnx×nz\begin{aligned} \mathbf{K}_t &= \frac{ \textit{\small (Incomplete) uncertainty of predicted observation} }{ \textit{\small Uncertainty of predicted observation} + \textit{\small Uncertainty of measurement noise} } \\[0.5em] &= \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime}\mathbf{C}_{t\mid t-1}^{-1} = \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime} \left( \mathbf{H}_t\mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime} + \mathbf{U}_t\mathbf{R}_t\mathbf{U}_t^{\prime} \right)^{-1} \in\mathbb{R}^{n_x\times n_z} \end{aligned}
  • Ct∣t−1\mathbf{C}_{t\mid t-1} = Covariance matrix of the innovation process, representing the total uncertainty of the observed measurement variable. It combines the uncertainty of the predicted observation arising from uncertainty in the predicted hidden state with the uncertainty caused by measurement noise.
Ct∣t−1=E ⁣[νtνt′]=HtPt∣t−1Ht′⏟Predicted-state uncertainty projectedinto observation space by Ht+UtRtUt′⏟Measurement-noise uncertainty projectedinto observation space by Ut∈Rnz×nz.\mathbf{C}_{t\mid t-1} = \mathbb{E}\!\left[ \boldsymbol{\nu}_t\boldsymbol{\nu}_t^{\prime} \right] = \underbrace{ \mathbf{H}_t\mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime} }_{\substack{ \text{Predicted-state uncertainty projected}\\ \text{into observation space by }\mathbf{H}_t }} + \underbrace{ \mathbf{U}_t\mathbf{R}_t\mathbf{U}_t^{\prime} }_{\substack{ \text{Measurement-noise uncertainty projected}\\ \text{into observation space by }\mathbf{U}_t }} \in\mathbb{R}^{n_z\times n_z}.
  • Pt∣t−1Ht′\mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime} = Cross-covariance matrix obtained by propagating the predicted-state uncertainty toward the observation space through the right-side transformation Ht′\mathbf{H}_t^{\prime}. The missing left transformation by Ht\mathbf{H}_t appears explicitly later in the weight I−KtHt\mathbf{I}-\mathbf{K}_t\mathbf{H}_t applied to the prior state estimate, while on the observation side it is implicitly reflected in Ktzt\mathbf{K}_t\mathbf{z}_t through the measurement equation zt=Htxt+Utut\mathbf{z}_t=\mathbf{H}_t\mathbf{x}_t+\mathbf{U}_t\mathbf{u}_t.

Finally, the a posteriori error covariance, representing the uncertainty of the corrected hidden-state estimate x^t∣t\widehat{\mathbf{x}}_{t\mid t}, can be expressed as follows:

Pt∣t=(I−KtHt)Pt∣t−1.\mathbf{P}_{t\mid t} = \left( \mathbf{I}-\mathbf{K}_t\mathbf{H}_t \right) \mathbf{P}_{t\mid t-1}.

Intuitively, we are correcting the predicted distribution using the information contained in the new observation zt\mathbf{z}_t.

This formula can be derived as follows:

Pt∣t=E ⁣[et∣tet∣t′]=E ⁣[(xt−x^t∣t)(xt−x^t∣t)′]=E ⁣[(xt−x^t∣t−1−Kt(zt−z^t∣t−1)) ⁣⋅ ⁣(xt−x^t∣t−1−Kt(zt−z^t∣t−1))′]=E ⁣[(xt−x^t∣t−1−Kt(Htxt+Utut−Htx^t∣t−1)) ⁣⋅ ⁣(xt−x^t∣t−1−Kt(Htxt+Utut−Htx^t∣t−1))′]=E ⁣[((I−KtHt)(xt−x^t∣t−1)−KtUtut) ⁣⋅ ⁣((I−KtHt)(xt−x^t∣t−1)−KtUtut)′]=E ⁣[((I−KtHt)et∣t−1−KtUtut)((I−KtHt)et∣t−1−KtUtut)′]=(I−KtHt)E ⁣[et∣t−1et∣t−1′](I−KtHt)′−(I−KtHt)E ⁣[et∣t−1ut′]Ut′Kt′−KtUtE ⁣[utet∣t−1′](I−KtHt)′+KtUtE ⁣[utut′]Ut′Kt′.\begin{aligned} \mathbf{P}_{t\mid t} &= \mathbb{E}\!\left[ \mathbf{e}_{t\mid t}\mathbf{e}_{t\mid t}^{\prime} \right] \\[4pt] &= \mathbb{E}\!\left[ \left( \mathbf{x}_t-\widehat{\mathbf{x}}_{t\mid t} \right) \left( \mathbf{x}_t-\widehat{\mathbf{x}}_{t\mid t} \right)^{\prime} \right] \\[4pt] &= \mathbb{E}\!\left[ \left( \mathbf{x}_t - \widehat{\mathbf{x}}_{t\mid t-1} - \mathbf{K}_t \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right) \right)\!\cdot\! \left( \mathbf{x}_t - \widehat{\mathbf{x}}_{t\mid t-1} - \mathbf{K}_t \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right) \right)^{\prime} \right] \\[4pt] &= \mathbb{E}\!\left[ \left( \mathbf{x}_t - \widehat{\mathbf{x}}_{t\mid t-1} - \mathbf{K}_t \left( \mathbf{H}_t\mathbf{x}_t + \mathbf{U}_t\mathbf{u}_t - \mathbf{H}_t\widehat{\mathbf{x}}_{t\mid t-1} \right) \right)\!\cdot\! \left( \mathbf{x}_t - \widehat{\mathbf{x}}_{t\mid t-1} - \mathbf{K}_t \left( \mathbf{H}_t\mathbf{x}_t + \mathbf{U}_t\mathbf{u}_t - \mathbf{H}_t\widehat{\mathbf{x}}_{t\mid t-1} \right) \right)^{\prime} \right] \\[4pt] &= \mathbb{E}\!\left[ \left( \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) \left( \mathbf{x}_t-\widehat{\mathbf{x}}_{t\mid t-1} \right) - \mathbf{K}_t\mathbf{U}_t\mathbf{u}_t \right) \!\cdot\! \left( \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) \left( \mathbf{x}_t-\widehat{\mathbf{x}}_{t\mid t-1} \right) - \mathbf{K}_t\mathbf{U}_t\mathbf{u}_t \right)^{\prime} \right] \\[4pt] &= \mathbb{E}\!\left[ \left( \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) \mathbf{e}_{t\mid t-1} - \mathbf{K}_t\mathbf{U}_t\mathbf{u}_t \right) \left( \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) \mathbf{e}_{t\mid t-1} - \mathbf{K}_t\mathbf{U}_t\mathbf{u}_t \right)^{\prime} \right] \\[4pt] &= \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) \mathbb{E}\!\left[ \mathbf{e}_{t\mid t-1}\mathbf{e}_{t\mid t-1}^{\prime} \right] \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right)^{\prime} \\[-2pt] &\quad - \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) \mathbb{E}\!\left[ \mathbf{e}_{t\mid t-1}\mathbf{u}_t^{\prime} \right] \mathbf{U}_t^{\prime}\mathbf{K}_t^{\prime} \\[-2pt] &\quad - \mathbf{K}_t\mathbf{U}_t \mathbb{E}\!\left[ \mathbf{u}_t\mathbf{e}_{t\mid t-1}^{\prime} \right] \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right)^{\prime} \\[-2pt] &\quad + \mathbf{K}_t\mathbf{U}_t \mathbb{E}\!\left[ \mathbf{u}_t\mathbf{u}_t^{\prime} \right] \mathbf{U}_t^{\prime}\mathbf{K}_t^{\prime}. \end{aligned}

And because we know that:

E ⁣[et∣t−1ut′]=0,E ⁣[utet∣t−1′]=0,\mathbb{E}\!\left[ \mathbf{e}_{t\mid t-1}\mathbf{u}_t^{\prime} \right] = \mathbf{0}, \qquad \mathbb{E}\!\left[ \mathbf{u}_t\mathbf{e}_{t\mid t-1}^{\prime} \right] = \mathbf{0},

we can continue as follows:

Pt∣t=(I−KtHt)Pt∣t−1(I−KtHt)′+KtUtRtUt′Kt′=(I−KtHt)Pt∣t−1(I−Ht′Kt′)+KtUtRtUt′Kt′=Pt∣t−1(I−Ht′Kt′)−KtHtPt∣t−1(I−Ht′Kt′)+KtUtRtUt′Kt′=Pt∣t−1−Pt∣t−1Ht′Kt′−KtHtPt∣t−1+KtHtPt∣t−1Ht′Kt′+KtUtRtUt′Kt′=Pt∣t−1−KtHtPt∣t−1−Pt∣t−1Ht′Kt′+Kt(HtPt∣t−1Ht′+UtRtUt′)Kt′=Pt∣t−1−KtHtPt∣t−1−Pt∣t−1Ht′Kt′+KtCt∣t−1Kt′=Pt∣t−1−KtHtPt∣t−1−Pt∣t−1Ht′Kt′+(Pt∣t−1Ht′Ct∣t−1−1)Ct∣t−1Kt′=Pt∣t−1−KtHtPt∣t−1−Pt∣t−1Ht′Kt′+Pt∣t−1Ht′Kt′=Pt∣t−1−KtHtPt∣t−1=(I−KtHt)Pt∣t−1.\begin{aligned} \mathbf{P}_{t\mid t} &= \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) \mathbf{P}_{t\mid t-1} \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right)^{\prime} + \mathbf{K}_t\mathbf{U}_t\mathbf{R}_t\mathbf{U}_t^{\prime}\mathbf{K}_t^{\prime} \\[4pt] &= \left(\mathbf{I}-\mathbf{K}_t\mathbf{H}_t\right) \mathbf{P}_{t\mid t-1} \left(\mathbf{I}-\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime}\right) + \mathbf{K}_t\mathbf{U}_t\mathbf{R}_t\mathbf{U}_t^{\prime}\mathbf{K}_t^{\prime} \\[4pt] &= \mathbf{P}_{t\mid t-1} \left(\mathbf{I}-\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime}\right) - \mathbf{K}_t\mathbf{H}_t\mathbf{P}_{t\mid t-1} \left(\mathbf{I}-\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime}\right) + \mathbf{K}_t\mathbf{U}_t\mathbf{R}_t\mathbf{U}_t^{\prime}\mathbf{K}_t^{\prime} \\[4pt] &= \mathbf{P}_{t\mid t-1} - \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime} - \mathbf{K}_t\mathbf{H}_t\mathbf{P}_{t\mid t-1} + \mathbf{K}_t\mathbf{H}_t \mathbf{P}_{t\mid t-1} \mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime} + \mathbf{K}_t\mathbf{U}_t\mathbf{R}_t\mathbf{U}_t^{\prime}\mathbf{K}_t^{\prime} \\[4pt] &= \mathbf{P}_{t\mid t-1} - \mathbf{K}_t\mathbf{H}_t\mathbf{P}_{t\mid t-1} - \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime} + \mathbf{K}_t \left( \mathbf{H}_t\mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime} + \mathbf{U}_t\mathbf{R}_t\mathbf{U}_t^{\prime} \right) \mathbf{K}_t^{\prime} \\[4pt] &= \mathbf{P}_{t\mid t-1} - \mathbf{K}_t\mathbf{H}_t\mathbf{P}_{t\mid t-1} - \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime} + \mathbf{K}_t\mathbf{C}_{t\mid t-1}\mathbf{K}_t^{\prime} \\[4pt] &= \mathbf{P}_{t\mid t-1} - \mathbf{K}_t\mathbf{H}_t\mathbf{P}_{t\mid t-1} - \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime} + \left( \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime}\mathbf{C}_{t\mid t-1}^{-1} \right) \mathbf{C}_{t\mid t-1}\mathbf{K}_t^{\prime} \\[4pt] &= \mathbf{P}_{t\mid t-1} - \mathbf{K}_t\mathbf{H}_t\mathbf{P}_{t\mid t-1} - \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime} + \mathbf{P}_{t\mid t-1}\mathbf{H}_t^{\prime}\mathbf{K}_t^{\prime} \\[4pt] &= \mathbf{P}_{t\mid t-1} - \mathbf{K}_t\mathbf{H}_t\mathbf{P}_{t\mid t-1} \\[4pt] &= \left( \mathbf{I}-\mathbf{K}_t\mathbf{H}_t \right) \mathbf{P}_{t\mid t-1}. \end{aligned}

3. Parameter Estimation with MLE

The parameter set

θ={At,Wt,Ht,Ut}\boldsymbol{\theta} = \left\{ \mathbf{A}_t, \mathbf{W}_t, \mathbf{H}_t, \mathbf{U}_t \right\}

can be estimated using Maximum Likelihood Estimation by finding the parameter values under which the observed sequence z1,…,zN\mathbf{z}_1,\ldots,\mathbf{z}_N is as unsurprising as possible. This means that the one-step-ahead conditional probabilities assigned by the model to the actually observed values zt\mathbf{z}_t should be jointly as large as possible:

θ^=arg⁡max⁡θ  p ⁣(z1:N∣θ)=arg⁡max⁡θ  ∏t=1Np ⁣(zt∣z1:t−1,θ).\widehat{\boldsymbol{\theta}} = \underset{\boldsymbol{\theta}}{\arg\max} \; p\!\left( \mathbf{z}_{1:N} \mid \boldsymbol{\theta} \right) = \underset{\boldsymbol{\theta}}{\arg\max} \; \prod_{t=1}^{N} p\!\left( \mathbf{z}_t \mid \mathbf{z}_{1:t-1}, \boldsymbol{\theta} \right).

As established in the previous section, the Kalman Filter provides the following one-step-ahead conditional mean and covariance matrix for the measurement variable zt\mathbf{z}_t:

z^t∣t−1=E ⁣[zt∣z1:t−1]=E ⁣[Htxt+Utut∣z1:t−1]=Htx^t∣t−1,\widehat{\mathbf{z}}_{t\mid t-1} = \mathbb{E}\!\left[ \mathbf{z}_t \mid \mathbf{z}_{1:t-1} \right] = \mathbb{E}\!\left[ \mathbf{H}_t\mathbf{x}_t + \mathbf{U}_t\mathbf{u}_t \mid \mathbf{z}_{1:t-1} \right] = \mathbf{H}_t \widehat{\mathbf{x}}_{t\mid t-1}, Ct∣t−1=E ⁣[(zt−z^t∣t−1)(zt−z^t∣t−1)′∣z1:t−1]=HtPt∣t−1Ht′+UtRtUt′,\mathbf{C}_{t\mid t-1} = \mathbb{E}\!\left[ \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right) \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right)^{\prime} \mid \mathbf{z}_{1:t-1} \right] = \mathbf{H}_t \mathbf{P}_{t\mid t-1} \mathbf{H}_t^{\prime} + \mathbf{U}_t \mathbf{R}_t \mathbf{U}_t^{\prime},

which fully characterize the one-step-ahead Gaussian predictive distribution of zt\mathbf{z}_t, conditional on the previous observations z1:t−1\mathbf{z}_{1:t-1} and the parameter set θ\boldsymbol{\theta}:

zt∣z1:t−1,θ∼N ⁣(z^t∣t−1,Ct∣t−1).\mathbf{z}_t \mid \mathbf{z}_{1:t-1}, \boldsymbol{\theta} \sim \mathcal{N}\!\left( \widehat{\mathbf{z}}_{t\mid t-1}, \mathbf{C}_{t\mid t-1} \right).

Then, the corresponding conditional probability density function evaluated at the observed value zt\mathbf{z}_t is:

p ⁣(zt∣z1:t−1,θ)=1(2π)nzdet⁡ ⁣(Ct∣t−1)exp⁡ ⁣[−12(zt−z^t∣t−1)′Ct∣t−1−1(zt−z^t∣t−1)].p\!\left( \mathbf{z}_t \mid \mathbf{z}_{1:t-1}, \boldsymbol{\theta} \right) = \frac{1}{ \sqrt{ (2\pi)^{n_z} \det\!\left(\mathbf{C}_{t\mid t-1}\right) } } \exp\!\left[ -\frac{1}{2} \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right)^{\prime} \mathbf{C}_{t\mid t-1}^{-1} \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right) \right].

where nzn_z is the dimension of each observation vector zt\mathbf{z}_t, whereas NN is the number of time steps in the complete observed sequence.

Substituting this conditional Normal density into the likelihood of the complete observed sequence gives:

L1:N ⁣(θ)=∏t=1Np ⁣(zt∣z1:t−1,θ)=∏t=1N[1(2π)nzdet⁡ ⁣(Ct∣t−1)exp⁡ ⁣[−12(zt−z^t∣t−1)′Ct∣t−1−1(zt−z^t∣t−1)]].\begin{aligned} \mathcal{L}_{1:N}\!\left(\boldsymbol{\theta}\right) &= \prod_{t=1}^{N} p\!\left( \mathbf{z}_t \mid \mathbf{z}_{1:t-1}, \boldsymbol{\theta} \right) \\[4pt] &= \prod_{t=1}^{N} \left[ \frac{1}{ \sqrt{ (2\pi)^{n_z} \det\!\left(\mathbf{C}_{t\mid t-1}\right) } } \exp\!\left[ -\frac{1}{2} \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right)^{\prime} \mathbf{C}_{t\mid t-1}^{-1} \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right) \right] \right]. \end{aligned}

For optimization, the likelihood can be simplified by taking its logarithm, which transforms the product over time into a sum:

ln⁡L1:N ⁣(θ)=∑t=1Nln⁡ ⁣[1(2π)nzdet⁡ ⁣(Ct∣t−1)exp⁡ ⁣[−12(zt−z^t∣t−1)′Ct∣t−1−1(zt−z^t∣t−1)]]=−12∑t=1N[nzln⁡(2π)+ln⁡det⁡ ⁣(Ct∣t−1)+(zt−z^t∣t−1)′Ct∣t−1−1(zt−z^t∣t−1)].\begin{aligned} \ln\mathcal{L}_{1:N}\!\left(\boldsymbol{\theta}\right) &= \sum_{t=1}^{N} \ln\!\left[ \frac{1}{ \sqrt{ (2\pi)^{n_z} \det\!\left(\mathbf{C}_{t\mid t-1}\right) } } \exp\!\left[ -\frac{1}{2} \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right)^{\prime} \mathbf{C}_{t\mid t-1}^{-1} \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right) \right] \right] \\[4pt] &= -\frac{1}{2} \sum_{t=1}^{N} \left[ n_z\ln(2\pi) + \ln\det\!\left(\mathbf{C}_{t\mid t-1}\right) + \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right)^{\prime} \mathbf{C}_{t\mid t-1}^{-1} \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right) \right]. \end{aligned}

This expression can be simplified further. Since the term nzln⁡(2π)n_z\ln(2\pi) is constant with respect to θ\boldsymbol{\theta}, and the common factor −1/2-1/2 does not affect which parameter values maximize the function, we can omit the constant term and change the sign. Then, maximizing the log-likelihood is equivalent to minimizing:

θ^=arg⁡min⁡θ  L1:N ⁣(θ)=arg⁡min⁡θ  ∑t=1N[ln⁡det⁡ ⁣(Ct∣t−1)⏟Prevention from makingevery observation unsurprising+(zt−z^t∣t−1)′Ct∣t−1−1(zt−z^t∣t−1)⏟Penalization ofprediction error].\begin{aligned} \widehat{\boldsymbol{\theta}} &= \underset{\boldsymbol{\theta}}{\arg\min} \; L_{1:N}\!\left(\boldsymbol{\theta}\right) \\[4pt] &= \underset{\boldsymbol{\theta}}{\arg\min} \; \sum_{t=1}^{N} \left[ \underbrace{ \ln\det\!\left(\mathbf{C}_{t\mid t-1}\right) }_{\substack{ \text{Prevention from making}\\ \text{every observation unsurprising} }} + \underbrace{ \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right)^{\prime} \mathbf{C}_{t\mid t-1}^{-1} \left( \mathbf{z}_t-\widehat{\mathbf{z}}_{t\mid t-1} \right) }_{\substack{ \text{Penalization of}\\ \text{prediction error} }} \right]. \end{aligned}

When ztz_t is a scalar variable, the determinant reduces to the scalar conditional variance Ct∣t−1C_{t\mid t-1}, while the inverse covariance matrix reduces to 1/Ct∣t−11/C_{t\mid t-1}. Therefore, the objective simplifies to:

L1:N(θ)=∑t=1N[ln⁡ ⁣(Ct∣t−1)+(zt−z^t∣t−1)2Ct∣t−1].L_{1:N}(\theta) = \sum_{t=1}^{N} \left[ \ln\!\left(C_{t\mid t-1}\right) + \frac{ \left( z_t-\widehat{z}_{t\mid t-1} \right)^2 }{ C_{t\mid t-1} } \right].