% 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}{11in} \setlength{\textwidth}{7.5in}
%\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{0in}
\setlength{\headheight}{-.3in} \setlength{\headsep}{-1in}
\setlength{\parindent}{1pc}
\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 22\\
MCMC II.}
% 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 {\em Random-walk Metropolis.} The Metropolis sampler refers to the original version of Metropolis {\em et al.} (1953). For proposal distribution, we assume $q(y|x)=q(|y-x|)$. See example $Y \sim N(x,1)$ in lecture 20. In this case,
$$\alpha(X_i,Y)= \min \Big( \frac{\pi(Y)}{\pi(X_i)}, 1\Big).$$ 
Given $X_i=x_i$,\\
1. Generate $Y \sim g(|y-x_i|)$.\\
2. $X_{i+1} = Y$ with probability $\alpha(X_i,Y)$ and $X_{i+1}=X_i$ otherwise.\\
Generating $Y \sim g(y-x_i)$ is equivalent to $Y = X_i + \epsilon_i$, where $\epsilon_i \sim g(y)$. So we have random walk $X_{i+1} = X_i + B_i\epsilon_i$ where $B_i$ is Bernoulli with $P(B=1)=\alpha$.\\ 

Let's generate $N(0,1)$ from $Unif(-2,2)$.  
\begin{verbatim}
n=10000;
x(1)=0;
snrpdf=inline('exp(-x^2/2)');
for i=2:n
  y=x(i-1) + 2*(1-2*rand);
  alpha=min([1,snrpdf(y)
       /snrpdf(x(i-1))]);
  u=rand;
  if u <= alpha
    x(i)=y;
  else
    x(i)=x(i-1);
  end 
end  
\end{verbatim}
\begin{figure}
\centering
\renewcommand{\baselinestretch}{1}
\includegraphics[scale=0.4]{lecture22-1.eps}
\end{figure}

\item {\em Independent sampler} is the special case of H-M algorithm (Tierney, 1994). Proposal distribution $q$ is independent of $x$, i.e. $q(y|x)=q(y)$. In this case
$$\alpha(X_i,Y)= \min \Big( \frac{\pi(Y)}{\pi(X_i)}\frac{q(X_i)}{q(Y)}, 1\Big).$$
This method does may not work well if $q$ is very similar to $\pi$. Given $X_i$,

1. Generate $Y \sim q(y)$. \\
2. $X_{i+1} = Y$ with probability $\alpha(X_i,Y)$ and $X_{i+1}=X_i$ otherwise.\\ 


The independent sampler can be compared to Accept-reject method for generating random numbers. In AR method,\\
1. Generate $Y \sim q(y)$\\
2. $X= Y$ with probability $\frac{\pi(Y)}{cq(Y)}$.\\
It can be shown that the independent Metropolis-Hastings algorithm is more efficient than the Accept-Reject method since independent M-H will accept more proposed values( see Robert and Casella, Monte Carlo Statistical Method for detail). \\


\item The {\em Gibbs sampler} is a special case of the Metropolis-Hastings algorithm but it differ in two ways:\\
1. We always accept $Y$ (candidate point). \\
2. Need to know full conditional distributions.\\
By construction, the Gibbs sampler is multidimensional. Here we will only consider 2-dimensional case. Given joint density $f(x,y)$, the Gibbs sampler is a way to generate the marginal density $f_X(x) = \int f(x,y) \; dy$ and $f_Y(y)= \int f(x,y) \; dx$.\\

We will study the Gibbs sampler in lecture 23.
  
\end{enumerate}

\end{document}

