%%
%% Automatically generated file from DocOnce source
%% (https://github.com/hplgit/doconce/)
%%
%%


%-------------------- begin preamble ----------------------

\documentclass[%
oneside,                 % oneside: electronic viewing, twoside: printing
final,                   % draft: marks overfull hboxes, figures with paths
10pt]{article}

\listfiles               %  print all files needed to compile this document

\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
\usepackage[table]{xcolor}
\usepackage{bm,ltablex,microtype}

\usepackage[pdftex]{graphicx}

\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

\usepackage{lmodern}         % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF:
\definecolor{linkcolor}{rgb}{0,0,0.4}
\usepackage{hyperref}
\hypersetup{
    breaklinks=true,
    colorlinks=true,
    linkcolor=linkcolor,
    urlcolor=linkcolor,
    citecolor=black,
    filecolor=black,
    %filecolor=blue,
    pdfmenubar=true,
    pdftoolbar=true,
    bookmarksdepth=3   % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
    }
%\hyperbaseurl{}   % hyperlinks are relative to this root

\setcounter{tocdepth}{2}  % levels in table of contents

% --- fancyhdr package for fancy headers ---
\usepackage{fancyhdr}
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[LE,RO]{\thepage}
% Ensure copyright on titlepage (article style) and chapter pages (book style)
\fancypagestyle{plain}{
  \fancyhf{}
  \fancyfoot[C]{{\footnotesize \copyright\ 1999-2018, "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
%  \renewcommand{\footrulewidth}{0mm}
  \renewcommand{\headrulewidth}{0mm}
}
% Ensure copyright on titlepages with \thispagestyle{empty}
\fancypagestyle{empty}{
  \fancyhf{}
  \fancyfoot[C]{{\footnotesize \copyright\ 1999-2018, "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
  \renewcommand{\footrulewidth}{0mm}
  \renewcommand{\headrulewidth}{0mm}
}

\pagestyle{fancy}


% prevent orhpans and widows
\clubpenalty = 10000
\widowpenalty = 10000

% --- end of standard preamble for documents ---


% insert custom LaTeX commands...

\raggedbottom
\makeindex
\usepackage[totoc]{idxlayout}   % for index in the toc
\usepackage[nottoc]{tocbibind}  % for references/bibliography in the toc

%-------------------- end preamble ----------------------

\begin{document}

% matching end for #ifdef PREAMBLE

\newcommand{\exercisesection}[1]{\subsection*{#1}}


% ------------------- main content ----------------------



% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center}
{\LARGE\bf
\begin{spacing}{1.25}
Project 3 on Machine Learning, deadline December 17
\end{spacing}
}
\end{center}

% ----------------- author(s) -------------------------

\begin{center}
{\bf \href{{http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html}}{Data Analysis and Machine Learning FYS-STK3155/FYS4155}}
\end{center}

    \begin{center}
% List of all institutions:
\centerline{{\small Department of Physics, University of Oslo, Norway}}
\end{center}
    
% ----------------- end author(s) -------------------------

% --- begin date ---
\begin{center}
Nov 26, 2018
\end{center}
% --- end date ---

\vspace{1cm}


\section*{Paths for project 3}

\subsection*{Defining the data sets to analyze yourself}

For project 3, you can propose own data sets that relate to your research interests or just use existing data sets from say
\begin{enumerate}
\item \href{{https://www.kaggle.com/datasets}}{Kaggle} 

\item The \href{{http://archive.ics.uci.edu/ml/datasets.html}}{University of California at Irvine (UCI) with its  machine learning repository}

\item The credit card data set from \href{{https://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients}}{UCI} is also interesting and links to a \href{{https://bradzzz.gitbooks.io/ga-seattle-dsi/content/dsi/dsi_05_classification_databases/2.1-lesson/assets/datasets/DefaultCreditCardClients_yeh_2009.pdf}}{recent scientific article}.  See however below for possible project example

\item Another interesting case is the bitcoin example discussed at the piazza link \href{{https://piazza.com/class/ji78s1cduul39a?cid=104}}{\nolinkurl{https://piazza.com/class/ji78s1cduul39a?cid=104}}, read more there to see if this could of interest.
\end{enumerate}

\noindent
The approach to the analysis of these new data sets should follow to a large extent what you did in projects 1 and 2. That is:
\begin{enumerate}
\item Whether you end up with a regression or a classification problem, you should employ at least two of the methods we have discussed among \textbf{linear regression (including Ridge and Lasso)}, \textbf{Logistic Regression}, \textbf{Neural Networks}, \textbf{Support Vector Machines} and \textbf{Decision Trees and Random Forests}.  If you wish to venture into \textbf{convolutional neural networks} or \textbf{recurrent neural networks}, or extensions of neural networkds, feel free to do so. 

\item For project 3, you should feel free to use your own codes from projects 1 and 2, eventually write your own for SVMs and/or Decision trees and random forests' or use the available functionality of \textbf{scikit-learn}, \textbf{tensorflow}, etc. 

\item The estimates you used and tested in projects 1 and 2 should also be included, that is the $R2$-score, \textbf{MSE}, cross-validation and/or bootstrap if these are relevant. 

\item If possible, you should link the data sets with exisiting research and analyses thereof. Scientific articles which have used Machine Learning algorithms to analyze the data are highly welcome. Perhaps you can improve previous analyses and even publish a new article? 

\item A critical assessment of the methods with ditto perspectives and recommendations is also something you need to include.
\end{enumerate}

\noindent
All in all, the report should follow the same pattern with abstract, introduction, methods, code, results, conclusions etc as the two previous projects. 

We propose also an alternative to the above. This is a project on using machine learning methods (neural networks mainly) to the solution of ordinary differential equations and partial differential equations. 

This is a field with a large interest recently, spanning from studies of turbulence in meteorology to the solution of quantum mechanical systems. 

\subsection*{Studying the credit card data set as possible project}

We include this data set as an example on how one could study new data sets with the algorithms we have discussed during the lectures, using either your own codes or the functionality of \textbf{scikit-learn}, \textbf{tensorflow} or other Python packages.

The data set is presented at the site of  \href{{https://archive.ics.uci.edu/ml/datasets/default+of+credit+card+clients}}{UCI}. It is particularly interesting since it is also analyzed using ML methods in a \href{{https://bradzzz.gitbooks.io/ga-seattle-dsi/content/dsi/dsi_05_classification_databases/2.1-lesson/assets/datasets/DefaultCreditCardClients_yeh_2009.pdf}}{recent scientific article}.  

The authors apply several ML methods, from nearest neighbors via logistic regression to neural networks and Bayesian analysis (not covered much in our course).
Here follows a set up on how to analyze these data.

\paragraph{Part a).}
The first part deals with structuring and reading the data, much along the same lines as done in projects 1 and 2. 

\paragraph{Part b).}
Perform a logistic regression analysis and see if you can reproduce the results of figure 3 of the above article. 

\paragraph{Part c).}
The next step is to use either your own code for neural networks from project 2 or the functionality provided by tensorflow/keras or scikit-learn's MLP method. Compare and discuss again your results with those from the above article.

\paragraph{Part d).}
The above article does not study random forests or support vector machine algorithms. Try to apply one of these methods or both to the credit card data and see if these methods provide a better description of the data. Can you outperform the authors of the article? 

\paragraph{Part e).}
Finally, here you should present a critical assessment of the methods you have studied and link your results with the existing literature. 

\subsection*{Solving partial differential equations with neural networks}

For this variant of project 3, we will assume that you have some background in the solution of partial differential equations using finite difference schemes. We will study the solution of the diffusion equation in one dimension using a standard explicit scheme and neural networks to solve the same equations. 

For the explicit scheme, you can study for example chapter 10 of the lecture notes in \href{{https://github.com/CompPhysics/ComputationalPhysics/blob/master/doc/Lectures/lectures2015.pdf}}{Computational Physics} or alternative sources. For the solution of ordinary and partial differential equations using neural networks, the lectures by \href{{https://compphysics.github.io/MachineLearning/doc/pub/odenn/html/odenn-bs.html}}{Kristine Baluka Hein} at this course are highly recommended.

For the machine learning part you can use your own code from project 2 or the functionality of for example \textbf{tensorflow/Keras}. 

\paragraph{Part a), setting up the problem.}
The physical problem can be that of the temperature gradient in a rod of length $L=1$ at $x=0$ and $x=1$.
We are looking at a one-dimensional
problem

\begin{equation*}
 \frac{\partial^2 u(x,t)}{\partial x^2} =\frac{\partial u(x,t)}{\partial t}, t> 0, x\in [0,L]
\end{equation*}
or

\begin{equation*}
u_{xx} = u_t,
\end{equation*}
with initial conditions, i.e., the conditions at $t=0$,
\begin{equation*}
u(x,0)= \sin{(\pi x)} \hspace{0.5cm} 0 < x < L,
\end{equation*}
with $L=1$ the length of the $x$-region of interest. The 
boundary conditions are

\begin{equation*}
u(0,t)= 0 \hspace{0.5cm} t \ge 0,
\end{equation*}
and

\begin{equation*}
u(L,t)= 0 \hspace{0.5cm} t \ge 0.
\end{equation*}
The function $u(x,t)$  can be the temperature gradient of a  rod.
As time increases, the velocity approaches a linear variation with $x$. 

We will limit ourselves to the so-called explicit forward Euler algorithm with discretized versions of time given by a forward formula and a centered difference in space resulting in   
\begin{equation*} 
u_t\approx \frac{u(x,t+\Delta t)-u(x,t)}{\Delta t}=\frac{u(x_i,t_j+\Delta t)-u(x_i,t_j)}{\Delta t}
\end{equation*}
and

\begin{equation*}
u_{xx}\approx \frac{u(x+\Delta x,t)-2u(x,t)+u(x-\Delta x,t)}{\Delta x^2},
\end{equation*}
or

\begin{equation*}
u_{xx}\approx \frac{u(x_i+\Delta x,t_j)-2u(x_i,t_j)+u(x_i-\Delta x,t_j)}{\Delta x^2}.
\end{equation*}

Write down the algorithm and the equations you need to implement.
Find also the analytical solution to the problem. 

\paragraph{Part b).}
Implement the explicit scheme  algorithm and perform tests of the solution 
for $\Delta x=1/10$, $\Delta x=1/100$ using  $\Delta t$ as dictated by the stability limit of the explicit scheme. The stability criterion for the explicit scheme requires that $\Delta t/\Delta x^2 \leq 1/2$. 

Study the solutions at two time points $t_1$ and $t_2$ where $u(x,t_1)$ is smooth but still significantly curved
and $u(x,t_2)$ is almost linear, close to the stationary state.


\paragraph{Part c) Neural networks.}
Study now the lecture notes on solving ODEs and PDEs with neural network and use either your own code from project 2 or the functionality of tensorflow/keras to solve the same equation as in part b). 
Discuss your results and compare them with the standard explicit scheme. Include also the analytical solution and compare with that.

\paragraph{Part d).}
Finally, present a critical assessment of the methods you have studied and discuss the potential for the solving differential equations with machine learning methods. 


\subsection*{Introduction to numerical projects}

Here follows a brief recipe and recommendation on how to write a report for each
project.

\begin{itemize}
  \item Give a short description of the nature of the problem and the eventual  numerical methods you have used.

  \item Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.

  \item Include the source code of your program. Comment your program properly.

  \item If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.

  \item Include your results either in figure form or in a table. Remember to        label your results. All tables and figures should have relevant captions        and labels on the axes.

  \item Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.

  \item Try to give an interpretation of you results in your answers to  the problems.

  \item Critique: if possible include your comments and reflections about the  exercise, whether you felt you learnt something, ideas for improvements and  other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.

  \item Try to establish a practice where you log your work at the  computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember  what a previous test version  of your program did. Here you could also record  the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
\end{itemize}

\noindent
\subsection*{Format for electronic delivery of report and programs}

The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file.  As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:

\begin{itemize}
  \item Use Devilry to hand in your projects, log in  at  \href{{http://devilry.ifi.uio.no}}{\nolinkurl{http://devilry.ifi.uio.no}} with your normal UiO username and password and choose either 'fysstk3155' or 'fysstk4155'. There you can load up the files within the deadline.

  \item Upload \textbf{only} the report file!  For the source code file(s) you have developed please provide us with your link to your github domain.  The report file should include all of your discussions and a list of the codes you have developed.  Do not include library files which are available at the course homepage, unless you have made specific changes to them.

  \item In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.

  \item In this and all later projects, you should include tests (for example unit tests) of your code(s).

  \item Comments  from us on your projects, approval or not, corrections to be made  etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
\end{itemize}

\noindent
Finally, 
we encourage you to collaborate. Optimal working groups consist of 
2-3 students. You can then hand in a common report. 



\subsection*{Software and needed installations}

If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages, 
we recommend that you install the following Python packages via \textbf{pip} as
\begin{enumerate}
\item pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow
\end{enumerate}

\noindent
For Python3, replace \textbf{pip} with \textbf{pip3}.

See below for a discussion of \textbf{tensorflow} and \textbf{scikit-learn}. 

For OSX users we recommend also, after having installed Xcode, to install \textbf{brew}. Brew allows 
for a seamless installation of additional software via for example
\begin{enumerate}
\item brew install python3
\end{enumerate}

\noindent
For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
you can use \textbf{pip} as well and simply install Python as 
\begin{enumerate}
\item sudo apt-get install python3  (or python for python2.7)
\end{enumerate}

\noindent
etc etc. 

If you don't want to install various Python packages with their dependencies separately, we recommend two widely used distrubutions which set up  all relevant dependencies for Python, namely
\begin{enumerate}
\item \href{{https://docs.anaconda.com/}}{Anaconda} Anaconda is an open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing, that aims to simplify package management and deployment. Package versions are managed by the package management system \textbf{conda}

\item \href{{https://www.enthought.com/product/canopy/}}{Enthought canopy}  is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.
\end{enumerate}

\noindent
Popular software packages written in Python for ML are

\begin{itemize}
\item \href{{http://scikit-learn.org/stable/}}{Scikit-learn}, 

\item \href{{https://www.tensorflow.org/}}{Tensorflow},

\item \href{{http://pytorch.org/}}{PyTorch} and 

\item \href{{https://keras.io/}}{Keras}.
\end{itemize}

\noindent
These are all freely available at their respective GitHub sites. They 
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing.













% ------------------- end of main content ---------------

\end{document}

