% This is a simple LaTex sample document that gives a submission format
%   for IEEE PAMI-TC conference submissions.  Use at your own risk.
% Make two column format for LaTex 2e.\
\documentclass[12pt,twocolumn]{article} %,twocolumn
\usepackage{times,amsmath,amsfonts}

% Use following instead for LaTex 2.09 (may need some other mods as well).
%\documentstyle[times,twocolumn]{article}
\usepackage[dvips]{graphicx,graphics}
% Set dimensions of columns, gap between columns, and paragraph indent
\setlength{\textheight}{10in} \setlength{\textwidth}{7.5in}
%\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{0in}
\setlength{\headheight}{0in} \setlength{\headsep}{-1in}
\setlength{\parindent}{0.5pc}
\setlength{\oddsidemargin}{-0.6in}  % Centers text.
\setlength{\evensidemargin}{-0.5in}

% Add the period after section numbers.  Adjust spacing.
\newcommand{\Section}[1]{\vspace{-5pt}\section{\hskip -1em.~~#1}\vspace{-3pt}}
\newcommand{\SubSection}[1]{\vspace{-2pt}\subsection{\hskip -1em.~~#1}
        \vspace{-3pt}}
\newcommand{\bqn}{\begin{eqnarray}}
\newcommand{\eqn}{\end{eqnarray}}

\begin{document}

% Make title bold and 14 pt font (Latex default is non-bold, 16pt)
\title{Stat 471: Lecture 23\\
Gibbs Sampler.}
% For single author (just remove % characters)
\author{Moo K. Chung\\
mchung@stat.wisc.edu}
% For two authors (default example)
\maketitle \thispagestyle{empty}
\begin{enumerate}

\item The Gibbs sampler was developed by Geman $\&$ Geman (1984). Let ${\bf Z_i}=(X_i,Y_i)'$ be a Markov chain. The Gibbs sampler can be used to generate specific multivariate distributions. Let $f(x,y)$ be a given joint density and $f(x|y)$ and $f(y|x)$ to be conditional densities. The Gibbs sampling algorithm is given by\\

1. Generate ${\bf Z}_0=(X_0,Y_0)'.$ Set $i=1$.\\
2. Generate $X_{i} \sim f(x_i|Y_{i-1}=y_{i-1})$\\
3. Generate $Y_{i} \sim f(y_{i}|X_{i}=x_{i})$\\
4. Set $i = i+1$ and goto step 2.\\
\item {\bf Theorem.} $X_i, Y_i, (X_i,Y_i)$ generated by the Gibbs
sampler are Markov chains.\\ {\em Proof.} For chain $X_i$, the
transition kernel is
$$K_X(x,x^*) = \int f(y|x)f(x^*|y)\; dy.$$

Since $X_i$ is simulated conditionally only on $x_{i-1}$, $\{ X_i
\}$ is a Markov chain. The invariant distribution of $X_i$ is
marginal distribution $f_X(x) =\int f(x,y) \; dy.$
\begin{figure}
\centering
\renewcommand{\baselinestretch}{1}
\includegraphics[scale=0.5]{lecture23-1.eps}
\end{figure}
\item Let us simulate bivariate normal
$${\bf Z} =(X,Y)' \sim N(0, \Big[\begin{array}{cc}
                                     1 & \rho\\
                                     \rho & 1 \end{array}\Big])$$
The joint density for ${\bf Z} \sim N(\mu,V)$ is given by
$$f({\bf z}) = \frac{1}{2\pi \det V^{1/2}}\exp\Big[-\frac{{\bf z}V^{-1}{\bf z}}{2}\Big].$$
To simulate bivariate normal using the Gibbs sampler, we need to know the conditional distribution (we already know how to simulate multivariate normal based on the Choleskly factorization). Then it can be shown that
$$f(x|y)= \frac{f(x,y)}{f(y)}=\frac{f({\bf z})}{\int f({\bf z}) \;dx}.$$
It can be shown that
$$X|Y=y \sim N(\rho y, 1-\rho^2) \sim \rho y + \sqrt{1-\rho^2}N(0,1),$$
$$Y|X=x \sim N(\rho x, 1-\rho^2) \sim \rho x + \sqrt{1-\rho^2}N(0,1).$$

\begin{verbatim}
x(1)=0;y(1)=0; 
rho=0.9; 
c=sqrt(1-rho^2);
for i=2:6000
   x(i)=rho*y(i-1)+ c*snrnd(1);
   y(i)=rho*x(i)+ c*snrnd(1); 
end;
subplot(1,2,1);
plot(x(1:50),y(1:50));
subplot(1,2,2);
plot(x(4000:6000),y(4000:6000),'.');
\end{verbatim}

\end{enumerate}


\end{document}
