\documentclass[11pt]{article}
\usepackage{latexsym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{epsfig}
\usepackage[tight]{subfigure}
\setlength{\subfigcapmargin}{10pt}
\usepackage{tikz}
\usetikzlibrary{snakes,arrows,shapes}

\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}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document header: change the lecture number, date, scribe name, and
% lecture topic.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\lecture{Statistical Techniques in Robotics (16-831, F10)}
{Lecture\#7 (Tuesday September 14)}
{Lecturer: Drew Bagnell}
{Scribe: Chris Dellin \& Bruno Hexsel \footnotemark}
{Gibbs Fields \& Markov Random Fields}

% Be sure to acknowledge all previous scribes.
\footnotetext{Some content adapted from previous scribes: Byron Boots}

\section{Gibbs Fields}

   Like a Bayes' Net, a Gibbs Field is a representation of a set of
   random variables and their relationships.
   An example of a Gibbs Field is given in
   Figure~\ref{fig:gm-gibbs-intro}; edges are undirected, and connote
   some correlation between the connected nodes.
   As with a Bayes' Net, \emph{fewer} connections means \emph{more}
   structure.
   Gibbs Fields are powerful because they imply a way to write the joint
   probability of the random variables as functions over cliques in the
   graph.
   
   \begin{figure}[!ht]
      \centering
      \input{plots/gm-gibbs-intro-dot.tex}
      \caption{A Gibbs Field with nodes $x_1,x_2,x_3,x_4,x_5$.}
      \label{fig:gm-gibbs-intro}
   \end{figure}
   
   \subsection{Cliques and Joint Probability}
   
      A clique is any fully connected subset of the the graph (e.g.
      $\{x_4\}$, $\{ x_1, x_2, x_3 \}$, or $\{ x_3, x_5 \}$).
      We denote the set of all cliques in a graph as $C$, with a clique
      $c_i \in C$ comprising its nodes
      (e.g. $c_3 = \{ x_3, x_5 \}$).
      The joint probability for any set of random variables
      ${\mathbf x} = \{ x_1, \dots x_n \}$ represented by a Gibbs Field
      can be written as the product of clique potentials $\phi_i$:
      \begin{equation}
         \label{eq:dist}
         P(\mathbf{x}) = \frac{1}{Z} \prod_{c_i \in C} \phi_i(c_i),
      \end{equation}
      with $\phi_i(c_i)$ the $i$th clique potential, a function only of
      the values of the clique members in $c_i$.
      Each potential function $\phi_i$ must be positive, but unlike
      probability distribution functions, they need not sum to 1.
      A normalization constant $Z$ is required in to create a valid
      probability distribution
      $Z = \sum_x \prod_{c \in C} \phi_i(c_i)$.
      
      For any Gibbs Field, there is a subset $\hat{C}$ of $C$ consisting
      of only \emph{maximal cliques} which are not proper subsets of any
      other clique.
      For example, the Gibbs Field in Figure~\ref{fig:gm-gibbs-intro} has
      two maximal cliques: $\hat{c}_1 = \{x_0, x_1, x_2\}$ and
      $\hat{c}_2 = \{ x_2, x_3, x_4 \}$.
      We can write a clique potential $\hat{\phi}$ for each maximal
      clique that is the product of all the potentials of its
      sub-cliques.
      In this way, we can write the joint probability as only a product
      over these maximal clique potentials:
      \begin{equation}
         \label{eq:dist-maximal}
         P(\mathbf{x}) = \frac{1}{Z} \prod_{c_i \in \hat{C}}
         \hat{\phi}_i(c_i).
      \end{equation}
      We usually take these potentials to be only functions over the
      maximal cliques, as in ($\ref{eq:dist-maximal}$).
   
   \subsection{Clique Potentials as Energy Functions}
   
      Often, clique potentials of the form $\phi_i(c_i) = \exp(-f(c_i))$
      are used, with $f_i(c_i)$ an energy function over values of $c_i$.
      The energy assigned by the function $f_i(c_i)$ is an indicator of
      the likelihood of the corresponding relationships within the
      clique, with a higher energy configuration having lower
      probability and vice-versa.
      If this is the case, (\ref{eq:dist}) can be written as
      \begin{equation}
         \label{eq:dist-energy}
         P(\mathbf{x}) = \frac{1}{Z} \exp \left[
         - \sum_{c_i \in C} f_i(c_i) \right].
      \end{equation}
      
      For example, we can write energy functions over the cliques in the
      example graph from Figure~\ref{fig:gm-gibbs-intro}.
      Let $f_1(\{x_0,x_1,x_2\}) = x_0^2 + (x_1-5x_2-3)^2$, and
      $f_2(\{x_2,x_3,x_4\}) = (x_2-x_3)^2 + (x_2+x_3+x_4)^2$.
      Then the joint probability can be written as
      \[
         P(\mathbf{x}) = \frac{1}{Z} \exp \left[
            - (x_0^2 + (x_1-5x_2-3)^2) - ((x_2-x_3)^2 + (x_2+x_3+x_4)^2)
         \right].
      \]
      In this form ($f_i$ quadratic in the $x$s), the Gibbs Field is
      known as a Gaussian Gibbs Field.
      
   \subsection{Moralizing: Converting a Bayes' Net to a Gibbs Field}

      Consider the Bayes' Net in Figure~\ref{fig:gm-bayes-ex}.
      Simply removing the arrows (Figure~\ref{fig:gm-gibbs-ex-wrong}) to
      create a Gibbs Field is not sufficient!
      In particular, in the resulting Gibbs Field, observing node $B$
      causes nodes $A$ and $C$ to become independent.
      This is the opposite of what the original Bayes' Net represented!
      
      Instead, we need to \emph{moralize} the graph.
      Whenever there are two parents that are not connected (married),
      we connect them.
      Thus, Figure~\ref{fig:gm-gibbs-ex} shows the correct representation
      of the original Bayes net.
      Note that during this conversion we actually lose information,
      namely that $A$ and $C$ are marginally independent.
      
      \begin{figure}[!ht]
         \centering
         \subfigure[Bayes' Net]{
            \input{plots/gm-bayes-ex-dot.tex}
            \label{fig:gm-bayes-ex}
         }
         \subfigure[Incorrect!]{
            \input{plots/gm-gibbs-ex-wrong-dot.tex}
            \label{fig:gm-gibbs-ex-wrong}
         }
         \subfigure[Correct, with moralizing]{
            \input{plots/gm-gibbs-ex-dot.tex}
            \label{fig:gm-gibbs-ex}
         }
         \caption{Moralizing process.}
      \end{figure}
      
\section{Markov Random Fields (MRFs)}

   A Markov Random Field (MRF) is an undirected graphical model that
   explicitly expresses the conditional independence relationships
   between nodes.
   Two nodes are conditionally independent if all paths between them are
   blocked by given nodes.
   See Figures~\ref{fig:gm-mrf-intro-blocked} and
   \ref{fig:gm-mrf-intro-unblocked} for examples.
   Note that this rule is much simpler than for Bayes' Nets.
   Due to the way that Markov Random Fields express the relationship
   between nodes, they make a lot of sense as a representation of
   physical space.
   
   \begin{figure}[!ht]
      \centering
      \subfigure[Node $x_1$ is conditionally independent to node $x_3$
         given $x_2$, $x_4$ and $x_7$.
         There is no unblocked path between $x_1$ and $x_3$.]
      {
         \input{plots/gm-mrf-intro-blocked-dot.tex}
         \label{fig:gm-mrf-intro-blocked}
      }
      \subfigure[There is at least one path from $x_1$ to $x_3$
         given $x_2$, $x_4$ and $x_6$; $x_1$ and $x_3$ are not
         (necessarily) conditionally independent.]
      {
         \input{plots/gm-mrf-intro-unblocked-dot.tex}
         \label{fig:gm-mrf-intro-unblocked}
      }
      \label{fig:gm-mrf-intro}
      \caption{Markov Random Field example.}
   \end{figure}
   
   \subsection{Markov Random Field Constraints}
   
      The question is, given a Markov Random Field (and its associated
      conditional independence relationships), what is the form of the
      joint probability distribution?
      Indeed, can we even show that such a distribution exists?
      For example, consider the Field from
      Figure~\ref{fig:gm-mrf-intro-blocked}.
      We could write a series of conditional independence relationiships
      that are asserted from the Field.
      For example:
      \begin{center}
      \begin{tabular}{c}
         $x_1 \perp x_3 \;|\; x_2, x_5$ \\
         $x_1 \perp x_7 \;|\; x_3, x_6, x_{10}$ \\
         $x_9 \perp x_{12} \;|\; x_2, x_7, x_{10}$ \\
         $\vdots$ 
      \end{tabular}
      \end{center}         
      What can we say about the form of the joint probability function
      $P(\mathbf{x})$ in this case?
      
      There is a trivial example of a suitable joint probability
      distribution -- when all the nodes are independent:
      \[
         P(\mathbf{x}) = \prod_i P(x_i).
      \]
      This would be a possible solution even for a fully connected
      Markov Random Field -- the weakest possible Field, in which no
      conditional independencies are specified.
      But any given field, such as the one from
      Figure~\ref{fig:gm-mrf-intro-blocked}, has fewer edges (and
      therefore more structure).
      We should hope that there exists a stronger form of $P(\mathbf{x})$
      that follows from a Markov Random Field.
      
      The Hammersley-Clifford theorem proves that a Markov Random Field
      and Gibbs Field are equivalent with regard to the same
      graph.\footnote{Actually, this is true only as long as
      $P(\mathbf{x}) \geq 0 \;\forall \mathbf{x}$; that is, as long as
      all configurations of values are possible.}
      In other words:
      \begin{itemize}      
         \item Given any Markov Random Field, all joint probability
            distributions that satisfy the conditional independencies
            can be written as clique potentials over the maximal cliques
            of the corresponding Gibbs Field.
         \item Given any Gibbs Field, all of its joint probability
            distributions satisfy the conditional independence
            relationships specified by the corresponding Markov Random
            Field.
      \end{itemize}
      
\end{document}
