\documentclass[11pt]{article}
\usepackage{latexsym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{epsfig}
\usepackage{hyperref}
\usepackage[tight]{subfigure}

\newcommand{\handout}[5]{
  \noindent
  \begin{center}
  \framebox{
    \vbox{
      \hbox to 5.78in { {#1} \hfill #2 }
      \vspace{4mm}
      \hbox to 5.78in { {\Large \hfill #5  \hfill} }
      \vspace{2mm}
      \hbox to 5.78in { {\em #3 \hfill #4} }
    }
  }
  \end{center}
  \vspace*{4mm}
}

\newcommand{\lecture}[5]{\handout{#1}{#2}{#3}{#4}{#5}}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{observation}[theorem]{Observation}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{assumption}[theorem]{Assumption}

% 1-inch margins, from fullpage.sty by H.Partl, Version 2, Dec. 15, 1988.
\topmargin 0pt
\advance \topmargin by -\headheight
\advance \topmargin by -\headsep
\textheight 8.9in
\oddsidemargin 0pt
\evensidemargin \oddsidemargin
\marginparwidth 0.5in
\textwidth 6.5in

\parindent 0in
\parskip 1.5ex

%\renewcommand{\baselinestretch}{1.25}

\begin{document}

\lecture{Statistical Techniques in Robotics (16-831, F12)}
{Lecture\#17 (Wednesday October 31)}
{Lecturer: Drew Bagnell}
{Scribe:Greydon Foil \footnotemark}
{Kalman Filters}

\footnotetext{Some content adapted from previous scribes: Ammar Husain, Heather Justice, Kiho Kwak, Siddharth Mehrotra}

\section{Gauss Markov Model}
Consider $X_1,X_2,....X_t,X_{t+1}$ to be the state variables and $Y_1,Y_2,...Y_t,Y_{t+1}$ be the sequence of corresponding observations. As in Hidden Markov models, conditional independencies (see Figure 1) dictate that past and future states are uncorrelated given the current state, $X_t$ at time $t$. For example, if we know what $X_2$ is, then no information about $X_1$ can possibly help us to reason about what $X_3$ should be. 
\begin{figure}[h]
\centering
   \includegraphics[width=12cm, angle=0, trim=0.25in 2.5in 0.25in 2.5in]{GaussMarkovModel.pdf}
\caption{The Independence Diagram of a Gauss-Markov model}
\end{figure}


The update for state variable $X_{t+1}$ is given by:
\[X_{t+1} = AX_t + \epsilon\]
where
\[X_0 \sim N(\mu_0, \Sigma_0)\]
\[\epsilon \sim N(0,Q)\]
\[X_{t+1}|X_t \sim N(AX_t, Q)\]

The corresponding observation $Y_{t+1}$ is given by equation:
\[Y_{t+1} = CX_{t+1} + \delta\]
where
\[Y_0 \sim N(\mu_0,\epsilon_0)\]
\[\delta \sim N(0,R)\]

Each component is defined as follow:
\begin{itemize}
	\item $A_{t}$: Matrix ($n \times n$) that describes how the state evolves from t to t-1 without controls or noise.
	\item $C_t$: Matrix ($k \times n$) that describes how to map the state $X_{t}$ to an observation $Y_{t}$, where $k$ is the number of observations.
	\item $\epsilon_{t}$, $\delta_{t}$: Random variables representing the process and measurement noise that are assumed to be independent and normally distributed with $n \times n$ noise covariances $R_{t}$ and $Q_{t}$ respectively.
\end{itemize}

We want to find $x_t | y_{1...t}$, so we need to calculate $\mu_{x+t}$ and $\Sigma_{x_t}$. Because a Gaussian will try to fit itself to all of the data, in a real situation we would first try to remove all outliers to achieve a more stable result.

Note that this parameterization is directly related to Bayes Linear Regression if it meets the following conditions:
\begin{itemize}
    \item $X$ here is equivalent to $\theta$ in BLR and $Y$ here is equivalent to $Y$ in BLR.
    \item The motion model is just the identity matrix.
    \item $Q$ is going to 0 as $t \rightarrow \infty$. It is nonzero if the noise might be changing as a function of time.
    \item $C$ is the vector $x_t$ from BLR, different here at every timestep. 
    \item $\delta \sim N(0, \sigma^2)$.
\end{itemize}

\section{What can you do with Gaussians?}

There are two common parameterizations for Gaussians, the moment parameterization and the natural parameterization. It is often most practical to switch back and forth between representations, depending on which calculations are needed. The moment parameterization is more convenient for visualization (simply draw a Gaussian centered around the mean with width determined by the variance), calculating expected value, and computing marginals. The natural parameterization is more convenient for multiplying Gaussians and for conditioning on known variables. While it is often convenient to switch between the two parameterizations, it is not always efficient, as we will discuss later.

\subsection{Moment Parameterization}

Recall that the moment parameterization of a Gaussian is:
\begin{eqnarray*}
\mathcal{N}(\mu,\Sigma) = p(\theta) = \frac{1}{z}\exp\left( -\frac{1}{2}\left(\theta -\mu\right)^T\Sigma^{-1}\left(\theta -\mu\right)\right)
\end{eqnarray*}

Given:
\begin{eqnarray*}
\left[\begin{array}{c}x_1\\x_2\end{array}\right] \sim \mathcal{N}\left(\left[\begin{array}{c}\mu_1\\\mu_2\end{array}\right],\left[\begin{array}{cc}\Sigma_{11}&\Sigma_{12}\\\Sigma_{21}&\Sigma_{22}\end{array}\right]\right)
\end{eqnarray*}
\textbf{Marginal:} computing $p(x_2)$
\begin{eqnarray*}
\mu_2^{\mathrm{marg}} &=& \mu_2\\
\Sigma_2^{\mathrm{marg}} &=& \Sigma_{22}
\end{eqnarray*}
We find both of these by the definition of moments, specifically the fact that the moments of $x_2$ don't change if $x_1$ is removed.

\textbf{Conditional:} computing $p(x_1|x_2)$
\begin{eqnarray*}
\mu_{1|2} &=& \mu_1 + \Sigma_{12}\Sigma_{22}^{-1}\left(x_2 -\mu_2\right)
\end{eqnarray*}
$(x_2 - \mu_2)$ is the distance $x_2$ is from its mean. We then multiply it by its uncertainty ($\Sigma_{22}$), and convert that value into the frame of $x_1$ using $\Sigma_{12}$, adding it to our best guess for $x_1$, $\mu_1$. 

\begin{eqnarray*}
\Sigma_{1|2} &=& \Sigma_{11} - \Sigma_{12}\Sigma_{22}^{-1} \Sigma_{21}
\end{eqnarray*}
Here we start with the uncertainty in $x_1$, $\Sigma_{11}$, and subtract out the uncertainty in $x_2$ and between $x_1$ and $x_2$, again mapping it to the frame of $x_1$ using $\Sigma_{12}$.

\subsection{Natural Parameterization}

Recall that the natural parameterization of a Gaussian is:
\begin{eqnarray*}
\tilde{\mathcal{N}}(J,P) = \tilde{p}(\theta) &=& \frac{1}{z}\exp\left( J^T\theta-\frac{1}{2}\theta^{T}P\theta\right)
\end{eqnarray*}
where
\begin{eqnarray*}
P_0 &=& \Sigma^{-1}_0\\
J_0 &=& P_0 \mu_0
\end{eqnarray*}

Given:
\begin{eqnarray*}
\left[\begin{array}{c}x_1\\x_2\end{array}\right] \sim \mathcal{N}\left(\left[\begin{array}{c}J_1\\J_2\end{array}\right],\left[\begin{array}{cc}P_{11}&P_{12}\\P_{21}&P_{22}\end{array}\right]\right)
\end{eqnarray*}
\textbf{Marginal:} computing $p(x_2)$
\begin{eqnarray*}
J_2^{\mathrm{marg}} &=& J_2 - P_{21}P_{11}^{-1}J_1\\
P_2^{\mathrm{marg}} &=& P_{22} - P_{21}P_{11}^{-1}P_{12}
\end{eqnarray*}
These are most easily calculated by deriving the marignals in moment parameterization and converting to natural parameterization.

\textbf{Conditional:} computing $p(x_1|x_2)$
\begin{eqnarray*}
J_{1|2} &=& J_1 - P_{12}x_2\\
P_{1|2} &=& P_{11}
\end{eqnarray*}
Derivation of these conditionals is a straightforward expansion of the full moment parameterization, and was said to be a possible test question. I encourage you to read page 7 of \cite{moment_marginals} for the full derivation. Also note that the moment parameterization is often called the \textit{canonical parameterization}.


\section{Lazy Gauss Markov Filter}
\subsection* {Motion Model (Prediction step):} 
Before the observation is taken:
\[X_{t+1} \sim \mu_{t+1}^- = A\mu_t\]
\subsection* {Proof:}
Mean:
\begin{eqnarray*}
E[X_{t+1}] &=& E[AX_t + \epsilon]\\
&=& E[AX_t] + E[\epsilon]\\
&=& AE[X_t] \text{(since the mean of $\epsilon$ is 0)}\\
&=& A\mu_t
\end{eqnarray*}
Variance:
\begin{eqnarray*}
\Sigma_{t+1}^- &=& E[X_{t+1}*X_{t+1}{}^T]\\
&=& E[(AX_t + \epsilon)(AX_t + \epsilon)^T]\\
&=& E[(AX_t)(AX_t)^T] + Var(\epsilon)\\ 
&=& AE[(X_t)(X_t)^T]A^T + Q\\
&=& A\Sigma_tA^T + Q
\end{eqnarray*}
Therefore the motion update becomes:

\[\mu_{t+1}^- = A\mu_t\]
\[\Sigma_{t+1}^- = A\Sigma_tA^T + Q\]

\subsection{Observation Model (Correction step):}
For the observation model the natural parameterization is more suitable as it involves multiplication of terms. The model equation in terms of Natural Parameters $J$ and $P$ is given by:
\begin{eqnarray*}
P(y_{t+1}|x_{t+1})P(x_{t+1}) &\propto& e^{(J^{-T}x_{t+1} - \frac{1}{2}x_{t+1}^TPx_{t+1})}*e^{-\frac{1}{2}(y_{t+1} - Cx_{t+1})^TR^{-1}(y_{t+1}-Cx_{t+1})}\\
&=&e^{-\frac{1}{2}[-2y_{t+1}^TR^{-1}Cx_{t+1} + x_{t+1}^TC^TR^{-1}Cx_{t+1} + y_{t+1}^TR^{-1}y_{t+1}]}\\
&=&e^{-\frac{1}{2}[-2y_{t+1}^TR^{-1}Cx_{t+1} + x_{t+1}^TC^TR^{-1}Cx_{t+1}]}
\end{eqnarray*}
  
The last term in the second line is constant with respect to $x_{t+1}$, so it can be added to the the marginalization term. Therefore the observation update is:

\begin{eqnarray*}
J^+_{t+1} &=& J^-_{t+1} + (y_{t+1}^TR^{-1}C)^T\\
P^+_{t+1} &=& P^-_{t+1} + C^{-1}R^{-1}C
\end{eqnarray*}

\subsection{Performance}
Lazy Gauss Markov can be expressed in two forms:
\begin{itemize}
    \item When expressed in terms of moment parameters, $\mu$ and $\Sigma$, it acts as {\textbf{Kalman Filter}}.
    \item When expressed in terms of natural parameters, $J$ and $P$, it acts as {\textbf{Information Filter}}.
\end{itemize}
Kalman filters, as we will see, require matrix multiplications, approximately $O(n^2)$ time, to do a prediction step, yet require matrix inversions, approximately $O(n^{2.8})$ time, to perform the observation update. Information filters are the exact opposite, requiring matrix inversions for the prediction step and matrix multiplications for the observation update. As mentioned above, the conversion between moment and natural parameterization requires an inversion of the covariance matrix, so switching between the two can be costly. Depending on the ratio of motion model updates to observation model updates one filter may be faster than the other. 


\begin{thebibliography}{1}
\bibitem{moment_marginals}
Michael I. Jordan and Christopher M. Bishop, ``An Introduction to Graphical Models.'' July 10, 2001. \url{http://people.csail.mit.edu/yks/documents/classes/mlbook/pdf/chapter12.pdf}. 
\end{thebibliography}
\end{document}
