% 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[10pt,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}{10.5in} \setlength{\textwidth}{7.6in}
%\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{0in}
\setlength{\headheight}{0in} \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*}}
\newcommand{\bq}{\begin{eqnarray}}
\newcommand{\eq}{\end{eqnarray}}

\begin{document}

% Make title bold and 14 pt font (Latex default is non-bold, 16pt)
\title{Stat 471: Lecture 31\\
Kernel Density Estimation.}
% 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 Let us consider the problem of estimating a probability
density $f$ of observations $y_1, \cdots,y_n$. The most simple
approach would be to use histogram which count the number of
observations that belong to $m$ disjoint bins. But it gives a
discrete estimation. Suppose $S=\bigcup_{i=1}^m A_i$ is the
partition of $S$.

$$\hat f(x) =\frac{\# \mbox{ in the }i \mbox{-th interval }}{n}.$$

\begin{verbatim}
x=50:250;
h=hist(intensity,x)/19660;
plot(h,'.');
\end{verbatim}
\item  But we know the true density to be continuous. Using the
Kernel density estimator of Rosenblatt (1956) and Parzen (1962),
$$ \hat f_{\sigma} (x) = \frac{1}{n}\sum_{i=1}^n K_{\sigma}(x -
x_i)$$ where the proper choice of kernel $K_{\sigma}$ would be
that it should be symmetric probability density. Some other boring
conditions are assumed from time to time. It can be shown that
$\hat f_{\sigma}$ is a probability density as well - it is related
with a mixture model. We will use the discrete version of
$K_{\sigma} \sim N(0,\sigma^2)$ (see lecture 28-30).
\begin{verbatim}
kernel=inline('exp(-x.^2/sigma^2)/
sum(exp(-x.^2/sigma^2))','x','sigma')
sigma=1, %1, 5, 15
fhat=zeros(1,length(x));
for i=1:19660 %number of sample
  fhat = fhat + kernel(x-intensity(i)
                        ,sigma)/19660;
end;
hold on; plot(fhat);
\end{verbatim}

\begin{figure}[t]
\centering
\renewcommand{\baselinestretch}{1}
\includegraphics[scale=0.27]{lecture31-4.eps}
\includegraphics[scale=0.27]{lecture31-3.eps}
\includegraphics[scale=0.27]{lecture31-1.eps}
\includegraphics[scale=0.27]{lecture31-2.eps}
\includegraphics[scale=0.24]{lecture31-5.eps}
\includegraphics[scale=0.24]{lecture31-6.eps}
\end{figure}

\item How good is our density estimator and how we choose
$\sigma$? We can try to minimize the mean integrated squared error
($\sigma$):
$$MISE(\sigma) = \mathbb{E} \int \big[ \hat f_{\sigma} - f(x)\big]^2 \;dx.$$
See Ruppert, Wand and Carroll's semiparametric regression.

\item {\em Bivariate kernel density estimate} of observations
$z_i=(x_i,y_i)'$ is given by \bqn \hat f_{\sigma}(x,y)
&=&\frac{1}{n}\sum_{i=1}^n
K_{\sigma}(x-x_i)K_{\sigma}(y-y_i)\\
&=& \frac{1}{n}\sum_{i=1}^n {\bf K}_{\sigma}(z-z_i)\eqn where
${\bf K}_{\sigma}$ is the discrete version of bivariate normal
$N(0,\sigma^2I)$. For $\tt{strength.data}$,
\begin{verbatim}
[x,y]=meshgrid(0:4:200,0:4:140);
kernel=inline('exp((-x.^2-y.^2)/sigma^2)/
sum(sum(exp((-x.^2-y.^2)/sigma^2)))',
'x','y','sigma')
sigma=10, %10, 15, 20
fhat=zeros(size(x));
for i=1:147
  fhat=fhat+kernel(x-grip(i),
                   y-arm(i),sigma)/147;
end;
>> sum(sum(fhat))
ans =
    1.0000
surfc(x,y,fhat); colorbar
\end{verbatim}
Our discrete version gives a probability function rather than a
probability density such that $\hat f_{\sigma}$ sum over all
possible grid points should be 1, i.e.
$$\sum_{i,j} \hat f_{\sigma}(x_i,y_j) =1.$$

\end{enumerate}
\end{document}
