\documentclass[10pt]{article}

\usepackage{fullpage}
\usepackage{setspace}
\usepackage{parskip}
\usepackage{titlesec}
\usepackage[section]{placeins}
\usepackage{xcolor}
\usepackage{breakcites}
\usepackage{lineno}
\usepackage{hyphenat}





\PassOptionsToPackage{hyphens}{url}
\usepackage[colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}
\usepackage{etoolbox}
\makeatletter
\patchcmd\@combinedblfloats{\box\@outputbox}{\unvbox\@outputbox}{}{%
  \errmessage{\noexpand\@combinedblfloats could not be patched}%
}%
\makeatother


\usepackage{natbib}




\renewenvironment{abstract}
  {{\bfseries\noindent{\abstractname}\par\nobreak}\footnotesize}
  {\bigskip}

\titlespacing{\section}{0pt}{*3}{*1}
\titlespacing{\subsection}{0pt}{*2}{*0.5}
\titlespacing{\subsubsection}{0pt}{*1.5}{0pt}


\usepackage{authblk}


\usepackage{graphicx}
\usepackage[space]{grffile}
\usepackage{latexsym}
\usepackage{textcomp}
\usepackage{longtable}
\usepackage{tabulary}
\usepackage{booktabs,array,multirow}
\usepackage{amsfonts,amsmath,amssymb}
\providecommand\citet{\cite}
\providecommand\citep{\cite}
\providecommand\citealt{\cite}
% You can conditionalize code for latexml or normal latex using this.
\newif\iflatexml\latexmlfalse
\providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}%

\AtBeginDocument{\DeclareGraphicsExtensions{.pdf,.PDF,.eps,.EPS,.png,.PNG,.tif,.TIF,.jpg,.JPG,.jpeg,.JPEG}}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}



\usepackage{float}








\begin{document}

\title{Exam 2}



\author[1]{xian chen}%
\affil[1]{Affiliation not available}%


\vspace{-1em}



  
  \date{May 05, 2024}


\begingroup
\let\center\flushleft
\let\endcenter\endflushleft
\maketitle
\endgroup








\sloppy




\textbf{Q1 (a)}

By the Bayes' rule, 

\(P[x] = \sum_{i=1}^{J} {P}[x| y=i]{P}[y=i] = \sum_{i=1}^{J} f_{X}(x|y=i) \pi_{i}\)

\begin{equation}\begin{align} 
P[y=i | x] &=\frac{P[x|y=i]P[y=i]}{P[x]}\\
&= \frac{f_{X}(x | y=i)P[y=i]}{P[x]}\\
&= \frac{e^{-\frac{1}{2}\left(x-\mu_{i}\right)^{\top} \Sigma_{i}^{-1}\left(x-\mu_{i}\right)}\pi_i}{(2 \pi)^{p / 2} {det}\left(\sum_{i}\right)^{1 / 2}} / P[x]
\end{align} \end{equation}

\textbf{(b)} Since the denominator $P[x]$ and $(2\pi)^{p/2}$ do not depend on i, we can write them as a constant  \[P[y=i | x]  = C*f_{X}(x | y=i)\pi_i =  \frac{C\pi_i }{ {det}\left(\sum_{i}\right)^{1 / 2}} e^{-\frac{1}{2}\left(x-\mu_{i}\right)^{\top} \Sigma_{i}^{-1}\left(x-\mu_{i}\right)}\]

Take the log of both sides, we have
\[\log P[y=i | x]  = \log C + \log \pi_{i}-\frac{1}{2}\left(x-\mu_{i}\right)^{T} {\Sigma_{i}}^{-1}\left(x-\mu_{i}\right) - \frac{1}{2} \log|\Sigma_i|\]

Thus, \begin{equation}\begin{align} \delta_{i}(x) &= -\frac{1}{2}\left(x-\mu_{i}\right)^{T} {\Sigma_{i}}^{-1}\left(x-\mu_{i}\right) - \frac{1}{2} \log|\Sigma_i|+\log \pi_{i}\\
&=-\frac{1}{2} x^{T} {\Sigma}_{i}^{-1} x+x^{T} {\Sigma}_{i}^{-1} \hat{\mu}_{i}-\frac{1}{2} \hat{\mu}_{i}^{T} {\Sigma}_{i}^{-1} \hat{\mu}_{i}-\frac{1}{2} \log \left|{\Sigma}_{i}\right|+\log {\pi}_{i}\end{align} \end{equation}

\textbf{(c)}\selectlanguage{english}
\begin{figure}[H]
\begin{center}
\includegraphics[width=0.70\columnwidth]{figures/WechatIMG48/WechatIMG48}

\end{center}
\end{figure}



\textbf{(e)} 
Estimate sample mean and sample covariance for each class given the training data 

\begin{equation}
\hat{\pi}_{j}=n_{j}/n, \quad \hat{\boldsymbol{\mu}}_{j}=\frac{1}{n_{j}} \sum_{\mathbf{x}_{i} \in C_{j}} \mathbf{x}_{i}, \quad \hat{{\Sigma}}_{j}=\frac{1}{n_{j}-1} \sum_{\mathbf{x}_{i} \in C_{j}}\left(\mathbf{x}_{i}-\hat{\boldsymbol{\mu}}_{j}\right)\left(\mathbf{x}_{i}-\hat{\boldsymbol{\mu}}_{j}\right)^{T}\end{equation}

where $j \in (1,2,3)$.

Thus, we have \[\hat{\pi_1} =0.57, \hat{\pi_2} =0.37 , \hat{\pi_3} = 0.06  \]
\[\hat{{\mu}}_{1}= (-0.053, 0.953)^T, \hat{{\mu}}_{2}=( 1.082, 0.05067374)^T, \hat{{\mu}}_{3} =(-0.825, 1.241)^T \]
\[\Sigma_{1}=\left[\begin{array}{cc}{  0.502} & {-0.219} \\ {-0.219} & {0.460}\end{array}\right], \quad \Sigma_{2}=\left[\begin{array}{cc}{0.608} & {-0.159} \\ {-0.159} & { 0.421}\end{array}\right], \quad \Sigma_{3}=\left[\begin{array}{cc}{2.181} & {1.965} \\ {1.965} & {1.816}\end{array}\right]\]
The desicion boundary of QDA is given by $\delta_{1}(x)=\delta_{2}(x)=\delta_{3}(x)$.

\textbf{(f)~}Scatter plot of the training data with labels\textbf{~}

\par\null

QDA: When n increased from 100 to 1000, the number of data points with
predicted labels of 3 and 2 increased while the number of data points
with predicted labels of 1 decreased.~

\par\null

\[\hat{\pi_1} =0.606, \hat{\pi_2} = 0.284   , \hat{\pi_3} = 0.11 \]
\[\hat{{\mu}}_{1}= (-0.024 , 0.979)^T, \hat{{\mu}}_{2}=( 1.026, 0.006)^T, \hat{{\mu}}_{3} =(-1.157,  0.923)^T \]
\[\Sigma_{1}=\left[\begin{array}{cc}{0.534} & {0.326} \\ {0.326} & {0.500}\end{array}\right], \quad \Sigma_{2}=\left[\begin{array}{cc}{ 0.554} & {0.402} \\ {0.402} & { 0.535}\end{array}\right], \quad \Sigma_{3}=\left[\begin{array}{cc}{1.376} & {1.296} \\ {1.296} & {1.323}\end{array}\right]\]

\selectlanguage{english}
\FloatBarrier
\end{document}

