\documentclass{article}[12pt]

% useful packages
\usepackage{titlesec}
\usepackage{fullpage}
\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage{algorithm,algorithmic}
\usepackage{xcolor}
\usepackage{bbm}
\usepackage{url}
\usepackage{hyperref}

% theorem type environments
\newtheorem{thm}{Theorem}
\newtheorem{prop}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{cor}{Corollary}
\newtheorem{defn}{Definition}
\newtheorem{assump}{Assumption}
\newtheorem{example}{Example}
\newtheorem{conjecture}{Conjecture}

% frequently used symbols
\newcommand{\bE}{\mathbb{E}}
\newcommand{\bP}{\mathbb{P}}
\newcommand{\bQ}{\mathbb{Q}}
\newcommand{\bR}{\mathbb{R}}
\newcommand{\bS}{\mathbb{S}}
\newcommand{\bN}{\mathbb{N}}
\newcommand{\bZ}{\mathbb{Z}}
\newcommand{\sC}{{\mathcal C}} 
\newcommand{\sD}{{\mathcal D}} 
\newcommand{\sE}{{\mathcal E}} 
\newcommand{\sF}{{\mathcal F}} 
\newcommand{\sL}{{\mathcal L}} 
\newcommand{\sH}{{\mathcal H}} 
\newcommand{\sN}{{\mathcal N}} 
\newcommand{\sO}{{\mathcal O}} 
\newcommand{\sP}{{\mathcal P}} 
\newcommand{\sR}{{\mathcal R}} 
\newcommand{\sS}{{\mathcal S}}
\newcommand{\sU}{{\mathcal U}} 
\newcommand{\sX}{{\mathcal X}} 
\newcommand{\sY}{{\mathcal Y}} 
\newcommand{\sZ}{{\mathcal Z}}

% operators
\newcommand{\sign}{\mathop{\mathrm{sign}}}
\newcommand{\supp}{\mathop{\mathrm{supp}}} % support
\newcommand{\argmin}{\operatornamewithlimits{arg\ min}}
\newcommand{\argmax}{\operatornamewithlimits{arg\ max}}
\newcommand{\dist}{\operatorname{dist}}
\newcommand{\tr}{\text{tr}}
\newcommand{\vecop}{\text{vec}}
\newcommand{\st}{\operatorname{s.t.}}
\newcommand{\cut}{\setminus}
\newcommand{\ind}[1]{\mathbbm{1}\left\{#1\right\}} 
\newcommand{\given}{\ | \ }

% grouping operators
\newcommand{\brac}[1]{\left[#1\right]}
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\paren}[1]{\left(#1\right)}
\newcommand{\norm}[1]{\left\|#1\right\|}
\newcommand{\ip}[2]{\left\langle #1,#2 \right\rangle}

% code commands
\newcommand{\matlab}{\textsc{Matlab }}
\newcommand{\python}{\textsc{Python }}
\newcommand{\todo}[1]{\textcolor{red}{#1}}

% header command
\newcommand{\project}[3]{
    \pagestyle{myheadings}
    \thispagestyle{plain}
    \newpage
    \setcounter{page}{1}
    \setlength{\headsep}{10mm}
    \noindent
    \begin{center}
    \framebox{
        \vbox{\vspace{2mm}
            \hbox to 6.28in { {\bf EE 519: Deep Learning Theory \& Fundamentals
            \hfill Spring \the\year} }
        \vspace{4mm}
        \hbox to 6.28in { {\Large \hfill Mini Project #1 \hfill} }
        \vspace{2mm}
        \hbox to 6.28in { \Large \hfill Due: #2, 11:59PM PT \hfill }
        \vspace{2mm}
        \hbox to 6.28in { {\it Student Name: #3} \hfill {\it Instructor Name: John Lipor}}
        \vspace{2mm}}
   }
   \end{center}
   \markboth{Mini Project #1}{Mini Project #1}
   \vspace*{4mm}
}

\begin{document}

% PUT YOUR NAME BELOW WHERE I HAVE \X
\project{2}{May 21, \the\year}{\X}
% PUT YOUR NAME ABOVE WHERE I HAVE \X

\section*{Introduction}

In this project, you will continue working on the same target problem as mini project 1 (MP1), in which you are sought to predict heat flow residuals and bin them into one of four groups. In MP1, we treated the data as tabular, i.e., as sets of features that may have no natural structure across examples. However, in reality, each feature is an estimated surface across the study area, which is the greater Nevada region. In this project, we will treat one such feature as an image and
aim to predict heat flow residuals using a CNN.

The detrended elevation map for the entire study region is shown in Fig.~\ref{fig:dem}, with the wells used to measure heatflow indicated in red. Among geoscientists, there is a belief that changes in the elevation/topography may be indicative of geothermal activity. This is known as a search for ``favorable structural settings.'' The goal of this project is to see whether a CNN trained to predict heatflow residuals utilizes such favorable structural settings in order to make its
predictions. Hence, while part of the aim of this project is to train an accurate predictor, an equally important goal is to examine the resulting saliency maps to see \emph{how} that predictor makes its decisions.

\begin{figure}[ht]
    \centering
    \includegraphics[width=0.5\textwidth]{Data/dem.pdf}
    \caption{Detrended elevation map for entire study region. Red dots indicate wells used to measure heat flow.}
    \label{fig:dem}
\end{figure}

To create the dataset, the detrended elevation map is processed into patches of size 40 km $\times$ 40 km. For each patch, the corresponding label is taken to be the maximum residual value among all wells in the patch. Patches containing zero wells are discarded, and the training and test datasets are created in an 80/20 split.
For a residual $r_{i}$, we will again utilize the categories
\begin{enumerate}
    \item low: $r_{i} \leq 25$
    \item transition: $r_{i} \in (25, 50]$
    \item high: $r_{i} \in (50, 200]$
    \item very high: $r_{i} > 200$
\end{enumerate}
The resulting labels 1-4 are \textit{ordinal labels}. As with MP1, your final predictor will be evaluated using the following loss
\begin{equation}
    \ell(y, \hat{y}) = \abs{y - \hat{y}},
    \label{eq:ordinalLoss}
\end{equation}
where $y, \hat{y} \in \set{1,\cdots,4}$.
 
Your task is to train an accurate CNN-based predictor of the heatflow residual given an elevation image patch. You are provided with the image and corresponding heat flow residual for each patch in the training set. You will also be provided with the images only of a test dataset. As part of your project, you will
submit your predictions on the test set, and I will return your score evaluated using \eqref{eq:ordinalLoss}.\footnote{The top scoring project will receive 500 Lipor points.}

%\vspace{1em}
%\noindent \textbf{Notes:} 
\subsection*{Notes}
\begin{enumerate}
    \item Your network must be coded and trained using PyTorch and D2L (not Keras or other similar packages).
    \item You may make full use of StackExchange, Medium, or any other online resource you can find.
    \item You may copy code from the internet, but you must \textbf{understand} what the code is doing and \textbf{cite} the source you copied it from.
    \item You may \textbf{not} copy code from other students in this class. You \textbf{may} share MP1 code among yourselves.
\end{enumerate}

\section*{Requirements}

You must create a report in either \LaTeX or an approved type setting language (\textbf{not} Microsoft Word) that contains the following sections:

\begin{enumerate}
    \item Problem description 
        \begin{itemize}
            \item Explain what data you have to work with, what algorithms you will use, what your goal is, and why anyone should care.
        \end{itemize}
    \item Exploratory data analysis (EDA)
        \begin{itemize}
            \item \textbf{(NEW)} Since we are working with images, EDA will look different and perhaps be less involved than for MP1. You should still examine the ranges of image values (hint: they are not 0-255, which may be important for training\dots or it may not) and residuals, remove outliers, etc.
            \item There are many excellent tutorials on EDA online. Cite whichever ones you found helpful.
            \item Be sure to make any significant findings stand out and try to keep this concise.
        \end{itemize}
    \clearpage
    \item Challenges
        \begin{itemize}
            \item What were the challenges you encountered when applying machine learning to this dataset?
            \item Did these challenges mainly result from the data? From results? Installing libraries to perform preprocessing?
        \end{itemize}
    \item Approach
        \begin{itemize}
            \item \textbf{(NEW)} Upon opening the dataset, you may notice that there are fewer than 300 images to use for training, which will be further reduced when you create training and validation sets. As a result, you \textbf{must} describe approaches you took to overcoming the limited dataset size. This need not be through image augmentation,\footnote{See \texttt{torchvision.transforms}.} but it could be.
            \item Provide a thorough but concise description of your approach, including (but not limited to) your approach to wrangling, preprocessing, and improving the performance of your predictor.
            \item To avoid overfitting, you must use some form of validation (either a single validation set or cross validation) to tune your hyperparameters. Describe how you went about this and why.
            \item A summary paragraph at the beginning of this section could be helpful.
        \end{itemize}
    \item Evaluation and summary
        \begin{itemize}
            \item \textbf{(NEW)} As stated above, you must provide some insights into which parts of the images your CNN is utilizing for prediction. For example, you may use class activation maps or guided backpropagation to visualize this.
            \item \textbf{(NEW)} You may also wish to display the learned feature maps and filters, but only do so if they are informative and you are able to draw a conclusion from them.
            \item Make use of any meaningful metrics (e.g., the loss \eqref{eq:ordinalLoss}, regression MSE, classification error), but only include metrics that tell you something different.
            \item Consider diving into the data to see if you can determine any trends regarding which points were misclassified.
            \item Likewise consider if there were any features that were particularly important or unimportant.
            \item Summarize your solution, describing what worked, what didn't, what the main limitations are (e.g., if nonlinear classifiers would improve results), and any general conclusions about the dataset.
        \end{itemize}
    \item What I learned
        \begin{itemize}
            \item Describe the main skills/tools that you learned and used for this project and how you learned them.
        \end{itemize}
\end{enumerate}

\clearpage
\section*{Grading}

The grading breakdown is below. Each section will be graded according to technical correctness, effort, and creativity. Note that clarity of writing is a major component. You should put yourself in the place of writing for a boss or senior in a workplace. If your writing is terrible, they will assume your work is terrible.
\begin{table}[h!]
\centering
\normalsize % The size of the table text can be changed depending on content. Remove if desired.
\begin{tabular}{ | c | c | }
\hline
\textbf{Item} & \textbf{Percentage} \\
\hline
Description & 5\% \\
\hline
EDA & 20\% \\
\hline
Challenges & 10\% \\
\hline
Approach & 30\% \\
\hline
Evaluation & 20\% \\
\hline
What I learned & 5\% \\
\hline
Clarity/conciseness of written communication & 10\% \\
\hline
\end{tabular}
\end{table}

\clearpage
\bibliographystyle{IEEEtran}
\bibliography{bibliography}

\end{document}
