first iteration p3, addition to be made

This commit is contained in:
Morten Hjorth-Jensen
2022-11-14 18:03:58 +01:00
parent 95b516d715
commit 967fe02f2d
11 changed files with 3174 additions and 0 deletions
@@ -0,0 +1,457 @@
<!--
HTML file automatically generated from DocOnce source
(https://github.com/doconce/doconce/)
doconce format html Project3.do.txt --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=Project3-bs
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/doconce/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Project 3 on Machine Learning, deadline December 15 (midnight), 2021">
<title>Project 3 on Machine Learning, deadline December 15 (midnight), 2021</title>
<!-- Bootstrap style: bootstrap -->
<!-- doconce format html Project3.do.txt --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=Project3-bs -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 1,
'sections': [('Paths for project 3', 1, None, 'paths-for-project-3'),
('Defining the data sets to analyze yourself',
2,
None,
'defining-the-data-sets-to-analyze-yourself'),
('The basic structure of your project',
2,
None,
'the-basic-structure-of-your-project'),
('Part a)', 3, None, 'part-a'),
('Part b)', 3, None, 'part-b'),
('Part c)', 3, None, 'part-c'),
('Part d)', 3, None, 'part-d'),
('Part e)', 3, None, 'part-e'),
('Solving partial differential equations with neural networks',
2,
None,
'solving-partial-differential-equations-with-neural-networks'),
('Part a), setting up the problem',
3,
None,
'part-a-setting-up-the-problem'),
('Part b)', 3, None, 'part-b'),
('Part c) Neural networks', 3, None, 'part-c-neural-networks'),
('Part d) Solving eigenvalue problems',
3,
None,
'part-d-solving-eigenvalue-problems'),
('Part e)', 3, None, 'part-e'),
('Additonal (optional) exercise, adding 30 more points to final '
'score',
2,
None,
'additonal-optional-exercise-adding-30-more-points-to-final-score'),
('Introduction to numerical projects',
2,
None,
'introduction-to-numerical-projects'),
('Format for electronic delivery of report and programs',
2,
None,
'format-for-electronic-delivery-of-report-and-programs'),
('Software and needed installations',
2,
None,
'software-and-needed-installations')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Project3-bs.html">Project 3 on Machine Learning, deadline December 15 (midnight), 2021</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="#paths-for-project-3" style="font-size: 80%;"><b>Paths for project 3</b></a></li>
<!-- navigation toc: --> <li><a href="#defining-the-data-sets-to-analyze-yourself" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Defining the data sets to analyze yourself</a></li>
<!-- navigation toc: --> <li><a href="#the-basic-structure-of-your-project" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;The basic structure of your project</a></li>
<!-- navigation toc: --> <li><a href="#part-a" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part a)</a></li>
<!-- navigation toc: --> <li><a href="#part-b" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part b)</a></li>
<!-- navigation toc: --> <li><a href="#part-c" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part c)</a></li>
<!-- navigation toc: --> <li><a href="#part-d" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part d)</a></li>
<!-- navigation toc: --> <li><a href="#part-e" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part e)</a></li>
<!-- navigation toc: --> <li><a href="#solving-partial-differential-equations-with-neural-networks" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Solving partial differential equations with neural networks</a></li>
<!-- navigation toc: --> <li><a href="#part-a-setting-up-the-problem" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part a), setting up the problem</a></li>
<!-- navigation toc: --> <li><a href="#part-b" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part b)</a></li>
<!-- navigation toc: --> <li><a href="#part-c-neural-networks" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part c) Neural networks</a></li>
<!-- navigation toc: --> <li><a href="#part-d-solving-eigenvalue-problems" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part d) Solving eigenvalue problems</a></li>
<!-- navigation toc: --> <li><a href="#part-e" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part e)</a></li>
<!-- navigation toc: --> <li><a href="#additonal-optional-exercise-adding-30-more-points-to-final-score" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Additonal (optional) exercise, adding 30 more points to final score</a></li>
<!-- navigation toc: --> <li><a href="#introduction-to-numerical-projects" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Introduction to numerical projects</a></li>
<!-- navigation toc: --> <li><a href="#format-for-electronic-delivery-of-report-and-programs" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Format for electronic delivery of report and programs</a></li>
<!-- navigation toc: --> <li><a href="#software-and-needed-installations" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Software and needed installations</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0000"></a>
<!-- ------------------- main content ---------------------- -->
<div class="jumbotron">
<center>
<h1>Project 3 on Machine Learning, deadline December 15 (midnight), 2021</h1>
</center> <!-- document title -->
<!-- author(s): <a href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html" target="_self">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a> -->
<center>
<b><a href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html" target="_self">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a></b>
</center>
<!-- institution -->
<center>
<b>Department of Physics, University of Oslo, Norway</b>
</center>
<br>
<center>
<h4>Nov 14, 2022</h4>
</center> <!-- date -->
<br>
</div> <!-- end jumbotron -->
<h1 id="paths-for-project-3" class="anchor">Paths for project 3 </h1>
<h2 id="defining-the-data-sets-to-analyze-yourself" class="anchor">Defining the data sets to analyze yourself </h2>
<p>For project 3, you can propose own data sets that relate to your research interests or just use existing data sets from say</p>
<ol>
<li> <a href="https://www.kaggle.com/datasets" target="_self">Kaggle</a></li>
<li> The <a href="https://archive.ics.uci.edu/ml/index.php" target="_self">University of California at Irvine (UCI) with its machine learning repository</a>.</li>
<li> Or other sources.</li>
</ol>
<p>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:</p>
<ol>
<li> Whether you end up with a regression or a classification problem, you should employ at least two of the methods we have discussed among <b>linear regression (including Ridge and Lasso)</b>, <b>Logistic Regression</b>, <b>Neural Networks</b>, <b>Convolution Neural Networks</b>, <b>Recurrent Neural Networks</b>, <b>Adversarial Neural Networks</b>, <b>Support Vector Machines</b> and <b>Decision Trees, Random Forests, Bagging and Boosting</b>. You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. If you wish to venture into <b>convolutional neural networks</b> or <b>recurrent neural networks</b>, or extensions of neural networkds, feel free to do so. You can also study unsupervised methods, although we in this course have mainly paid attendtion to supervised learning. The methods we have explored as <b>Principal Component Analysis</b> and <b>k-means Clustering</b>.</li>
</ol>
<p>For Boosting, feel also free to write your own codes.</p>
<ol>
<li> 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/random forests/bagging/boosting' or use the available functionality of <b>Scikit-Learn</b>, <b>Tensorflow</b>, etc.</li>
<li> The estimates you used and tested in projects 1 and 2 should also be included, that is the \( R2 \)-score, <b>MSE</b>, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.</li>
<li> Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.</li>
<li> 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?</li>
<li> A critical assessment of the methods with ditto perspectives and recommendations is also something you need to include.</li>
</ol>
<p>All in all, the report should follow the same pattern as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..</p>
<p>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, with a final twist on how to diagonalize a symmetric matrix with neural networks.</p>
<p>This is a field with a large interest recently, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides <a href="https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html" target="_self">from week 42</a> and/or the textbook by <a href="https://www.springer.com/gp/book/9789401798150" target="_self">Yadav et al</a>.</p>
<p><b>Note</b>: Project 3 has an additional exercise which can give you an additional score of 30 (thirty) points. These are added to the total score from all projects. See below for the additional exercise. </p>
<h2 id="the-basic-structure-of-your-project" class="anchor">The basic structure of your project </h2>
<p>Here follows a set up on how to structure your report and analyze the data you have opted for.</p>
<h3 id="part-a" class="anchor">Part a) </h3>
<p>The first part deals with structuring and reading the data, much along the same lines as done in projects 1 and 2. Explain how the data are produced and place them in a proper context.</p>
<h3 id="part-b" class="anchor">Part b) </h3>
<p>You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part.</p>
<h3 id="part-c" class="anchor">Part c) </h3>
<p>Then describe your algorithm and its implementation and tests you have performed.</p>
<h3 id="part-d" class="anchor">Part d) </h3>
<p>Then presents your results and findings, link with existing literature and more.</p>
<h3 id="part-e" class="anchor">Part e) </h3>
<p>Finally, here you should present a critical assessment of the methods you have studied and link your results with the existing literature. </p>
<h2 id="solving-partial-differential-equations-with-neural-networks" class="anchor">Solving partial differential equations with neural networks </h2>
<p>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.
</p>
<p>For the explicit scheme, you can study for example chapter 10 of the lecture notes in <a href="https://github.com/CompPhysics/ComputationalPhysics/blob/master/doc/Lectures/lectures2015.pdf" target="_self">Computational Physics</a> or alternative sources. For the solution of ordinary and partial differential equations using neural networks, the lectures by <a href="https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html" target="_self">Kristine Baluka Hein and included in the lectures of week 42</a> at this course are highly recommended.</p>
<p>For the machine learning part you can use your own code from project 2 or the functionality of for example <b>Tensorflow/Keras</b>.. </p>
<h3 id="part-a-setting-up-the-problem" class="anchor">Part a), setting up the problem </h3>
<p>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
</p>
$$
\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*}
$$
<p>or</p>
$$
\begin{equation*}
u_{xx} = u_t,
\end{equation*}
$$
<p>with initial conditions, i.e., the conditions at \( t=0 \),</p>
$$
\begin{equation*}
u(x,0)= \sin{(\pi x)} \hspace{0.5cm} 0 < x < L,
\end{equation*}
$$
<p>with \( L=1 \) the length of the \( x \)-region of interest. The
boundary conditions are
</p>
$$
\begin{equation*}
u(0,t)= 0 \hspace{0.5cm} t \ge 0,
\end{equation*}
$$
<p>and</p>
$$
\begin{equation*}
u(L,t)= 0 \hspace{0.5cm} t \ge 0.
\end{equation*}
$$
<p>The function \( u(x,t) \) can be the temperature gradient of a rod.
As time increases, the velocity approaches a linear variation with \( x \).
</p>
<p>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 </p>
$$
\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*}
$$
<p>and</p>
$$
\begin{equation*}
u_{xx}\approx \frac{u(x+\Delta x,t)-2u(x,t)+u(x-\Delta x,t)}{\Delta x^2},
\end{equation*}
$$
<p>or</p>
$$
\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*}
$$
<p>Write down the algorithm and the equations you need to implement.
Find also the analytical solution to the problem.
</p>
<h3 id="part-b" class="anchor">Part b) </h3>
<p>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 \).
</p>
<p>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.
</p>
<h3 id="part-c-neural-networks" class="anchor">Part c) Neural networks </h3>
<p>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.
</p>
<h3 id="part-d-solving-eigenvalue-problems" class="anchor">Part d) Solving eigenvalue problems </h3>
<p>Follow the discussion in the work of Yi <em>et al.</em> in the article from
<a href="https://www.sciencedirect.com/science/article/pii/S0898122104901101" target="_self">Computers and Mathematics with Applications 47, 1155 (2004)</a>, and
use your differential equation solver with neural networks, set up a
simple square, real and symmetric \( 6\times 6 \) matrix and find the
eigenvalues. Compare with the solution from numerical diagonalization with standard eigenvalue solvers from linear algebra.
</p>
<h3 id="part-e" class="anchor">Part e) </h3>
<p>Finally, present a critical assessment of the methods you have studied and discuss the potential for the solving differential equations and eigenvalue problems with machine learning methods. </p>
<h2 id="additonal-optional-exercise-adding-30-more-points-to-final-score" class="anchor">Additonal (optional) exercise, adding 30 more points to final score </h2>
<p>This exercise can be done independently of the other tasks. Here you
can also choose the data set you want to use. Furthermore, you can use
your codes from projects 1 and 2 as well as the codes here or simply use
libraries like <b>Scikit-Learn</b>, <b>Tensorflow</b> or similar.
</p>
<p>Your task is to perform an analysis of the bias-variance tradeoff
using at least three of the main sets of algorithms we have discussed in this
course. We will limit ourselves to a regression problem (fitting). However, feel free to venture into a classification problem.
</p>
<p>You
are free to choose between bootstrap for resampling (recommended) or
cross-validation in order to get the best possible estimates. The
methods you could study are Linear Regression (OLS, Ridge and Lasso),
deep learning (feed forward neural networks and/or recurrent neural
networks), Ensemble methods (decision trees, bagging, random forests
and boosting) and support vector machines.
</p>
<p>Study the bias-variance tradeoff for at least three of these sets of
algorithms for a data set of your choice as function of the complexity
of your model. Comment and discuss the results. Discuss the pros and
cons of the various methods. Are there some methods which provide both
low variance and low bias?
</p>
<p><b>Hint</b>: when you use different methods, pay attention to how you represent (and understand) the complexity of the model. For example, when using decision trees you may represent the complexity of your model by the depth of the tree. </p>
<h2 id="introduction-to-numerical-projects" class="anchor">Introduction to numerical projects </h2>
<p>Here follows a brief recipe and recommendation on how to write a report for each
project.
</p>
<ul>
<li> Give a short description of the nature of the problem and the eventual numerical methods you have used.</li>
<li> 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.</li>
<li> Include the source code of your program. Comment your program properly.</li>
<li> If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.</li>
<li> 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.</li>
<li> 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.</li>
<li> Try to give an interpretation of you results in your answers to the problems.</li>
<li> 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.</li>
<li> 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.</li>
</ul>
<h2 id="format-for-electronic-delivery-of-report-and-programs" class="anchor">Format for electronic delivery of report and programs </h2>
<p>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:</p>
<ul>
<li> Use Canvas to hand in your projects, log in at <a href="https://www.uio.no/english/services/it/education/canvas/" target="_self"><tt>https://www.uio.no/english/services/it/education/canvas/</tt></a> with your normal UiO username and password.</li>
<li> Upload <b>only</b> the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar 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.</li>
<li> In your GitHub/GitLab or similar 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.</li>
</ul>
<p>Finally,
we encourage you to collaborate. Optimal working groups consist of
2-3 students. You can then hand in a common report.
</p>
<h2 id="software-and-needed-installations" class="anchor">Software and needed installations </h2>
<p>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 <b>pip</b> as
</p>
<ol>
<li> pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow</li>
</ol>
<p>For Python3, replace <b>pip</b> with <b>pip3</b>.</p>
<p>See below for a discussion of <b>tensorflow</b> and <b>scikit-learn</b>. </p>
<p>For OSX users we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
for a seamless installation of additional software via for example
</p>
<ol>
<li> brew install python3</li>
</ol>
<p>For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
you can use <b>pip</b> as well and simply install Python as
</p>
<ol>
<li> sudo apt-get install python3 (or python for python2.7)</li>
</ol>
<p>etc etc. </p>
<p>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</p>
<ol>
<li> <a href="https://docs.anaconda.com/" target="_self">Anaconda</a> 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 <b>conda</b></li>
<li> <a href="https://www.enthought.com/product/canopy/" target="_self">Enthought canopy</a> is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.</li>
</ol>
<p>Popular software packages written in Python for ML are</p>
<ul>
<li> <a href="http://scikit-learn.org/stable/" target="_self">Scikit-learn</a>,</li>
<li> <a href="https://www.tensorflow.org/" target="_self">Tensorflow</a>,</li>
<li> <a href="http://pytorch.org/" target="_self">PyTorch</a> and</li>
<li> <a href="https://keras.io/" target="_self">Keras</a>.</li>
</ul>
<p>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.
</p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li class="active"><a href="._Project3-bs000.html">1</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="https://..."><img width="250" align=right src="https://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright --> &copy; 1999-2022, "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
</center>
</body>
</html>
@@ -0,0 +1,457 @@
<!--
HTML file automatically generated from DocOnce source
(https://github.com/doconce/doconce/)
doconce format html Project3.do.txt --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=Project3-bs
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/doconce/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Project 3 on Machine Learning, deadline December 15 (midnight), 2021">
<title>Project 3 on Machine Learning, deadline December 15 (midnight), 2021</title>
<!-- Bootstrap style: bootstrap -->
<!-- doconce format html Project3.do.txt --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=Project3-bs -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<!-- not necessary
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
-->
<style type="text/css">
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
.dropdown-menu {
height: auto;
max-height: 400px;
overflow-x: hidden;
}
/* Adds an invisible element before each target to offset for the navigation
bar */
.anchor::before {
content:"";
display:block;
height:50px; /* fixed header height for style bootstrap */
margin:-50px 0 0; /* negative fixed header height */
}
</style>
</head>
<!-- tocinfo
{'highest level': 1,
'sections': [('Paths for project 3', 1, None, 'paths-for-project-3'),
('Defining the data sets to analyze yourself',
2,
None,
'defining-the-data-sets-to-analyze-yourself'),
('The basic structure of your project',
2,
None,
'the-basic-structure-of-your-project'),
('Part a)', 3, None, 'part-a'),
('Part b)', 3, None, 'part-b'),
('Part c)', 3, None, 'part-c'),
('Part d)', 3, None, 'part-d'),
('Part e)', 3, None, 'part-e'),
('Solving partial differential equations with neural networks',
2,
None,
'solving-partial-differential-equations-with-neural-networks'),
('Part a), setting up the problem',
3,
None,
'part-a-setting-up-the-problem'),
('Part b)', 3, None, 'part-b'),
('Part c) Neural networks', 3, None, 'part-c-neural-networks'),
('Part d) Solving eigenvalue problems',
3,
None,
'part-d-solving-eigenvalue-problems'),
('Part e)', 3, None, 'part-e'),
('Additonal (optional) exercise, adding 30 more points to final '
'score',
2,
None,
'additonal-optional-exercise-adding-30-more-points-to-final-score'),
('Introduction to numerical projects',
2,
None,
'introduction-to-numerical-projects'),
('Format for electronic delivery of report and programs',
2,
None,
'format-for-electronic-delivery-of-report-and-programs'),
('Software and needed installations',
2,
None,
'software-and-needed-installations')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "none" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Bootstrap navigation bar -->
<div class="navbar navbar-default navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Project3-bs.html">Project 3 on Machine Learning, deadline December 15 (midnight), 2021</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="#paths-for-project-3" style="font-size: 80%;"><b>Paths for project 3</b></a></li>
<!-- navigation toc: --> <li><a href="#defining-the-data-sets-to-analyze-yourself" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Defining the data sets to analyze yourself</a></li>
<!-- navigation toc: --> <li><a href="#the-basic-structure-of-your-project" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;The basic structure of your project</a></li>
<!-- navigation toc: --> <li><a href="#part-a" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part a)</a></li>
<!-- navigation toc: --> <li><a href="#part-b" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part b)</a></li>
<!-- navigation toc: --> <li><a href="#part-c" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part c)</a></li>
<!-- navigation toc: --> <li><a href="#part-d" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part d)</a></li>
<!-- navigation toc: --> <li><a href="#part-e" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part e)</a></li>
<!-- navigation toc: --> <li><a href="#solving-partial-differential-equations-with-neural-networks" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Solving partial differential equations with neural networks</a></li>
<!-- navigation toc: --> <li><a href="#part-a-setting-up-the-problem" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part a), setting up the problem</a></li>
<!-- navigation toc: --> <li><a href="#part-b" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part b)</a></li>
<!-- navigation toc: --> <li><a href="#part-c-neural-networks" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part c) Neural networks</a></li>
<!-- navigation toc: --> <li><a href="#part-d-solving-eigenvalue-problems" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part d) Solving eigenvalue problems</a></li>
<!-- navigation toc: --> <li><a href="#part-e" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Part e)</a></li>
<!-- navigation toc: --> <li><a href="#additonal-optional-exercise-adding-30-more-points-to-final-score" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Additonal (optional) exercise, adding 30 more points to final score</a></li>
<!-- navigation toc: --> <li><a href="#introduction-to-numerical-projects" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Introduction to numerical projects</a></li>
<!-- navigation toc: --> <li><a href="#format-for-electronic-delivery-of-report-and-programs" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Format for electronic delivery of report and programs</a></li>
<!-- navigation toc: --> <li><a href="#software-and-needed-installations" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Software and needed installations</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div> <!-- end of navigation bar -->
<div class="container">
<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p> <!-- add vertical space -->
<a name="part0000"></a>
<!-- ------------------- main content ---------------------- -->
<div class="jumbotron">
<center>
<h1>Project 3 on Machine Learning, deadline December 15 (midnight), 2021</h1>
</center> <!-- document title -->
<!-- author(s): <a href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html" target="_self">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a> -->
<center>
<b><a href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html" target="_self">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a></b>
</center>
<!-- institution -->
<center>
<b>Department of Physics, University of Oslo, Norway</b>
</center>
<br>
<center>
<h4>Nov 14, 2022</h4>
</center> <!-- date -->
<br>
</div> <!-- end jumbotron -->
<h1 id="paths-for-project-3" class="anchor">Paths for project 3 </h1>
<h2 id="defining-the-data-sets-to-analyze-yourself" class="anchor">Defining the data sets to analyze yourself </h2>
<p>For project 3, you can propose own data sets that relate to your research interests or just use existing data sets from say</p>
<ol>
<li> <a href="https://www.kaggle.com/datasets" target="_self">Kaggle</a></li>
<li> The <a href="https://archive.ics.uci.edu/ml/index.php" target="_self">University of California at Irvine (UCI) with its machine learning repository</a>.</li>
<li> Or other sources.</li>
</ol>
<p>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:</p>
<ol>
<li> Whether you end up with a regression or a classification problem, you should employ at least two of the methods we have discussed among <b>linear regression (including Ridge and Lasso)</b>, <b>Logistic Regression</b>, <b>Neural Networks</b>, <b>Convolution Neural Networks</b>, <b>Recurrent Neural Networks</b>, <b>Adversarial Neural Networks</b>, <b>Support Vector Machines</b> and <b>Decision Trees, Random Forests, Bagging and Boosting</b>. You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. If you wish to venture into <b>convolutional neural networks</b> or <b>recurrent neural networks</b>, or extensions of neural networkds, feel free to do so. You can also study unsupervised methods, although we in this course have mainly paid attendtion to supervised learning. The methods we have explored as <b>Principal Component Analysis</b> and <b>k-means Clustering</b>.</li>
</ol>
<p>For Boosting, feel also free to write your own codes.</p>
<ol>
<li> 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/random forests/bagging/boosting' or use the available functionality of <b>Scikit-Learn</b>, <b>Tensorflow</b>, etc.</li>
<li> The estimates you used and tested in projects 1 and 2 should also be included, that is the \( R2 \)-score, <b>MSE</b>, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.</li>
<li> Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.</li>
<li> 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?</li>
<li> A critical assessment of the methods with ditto perspectives and recommendations is also something you need to include.</li>
</ol>
<p>All in all, the report should follow the same pattern as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..</p>
<p>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, with a final twist on how to diagonalize a symmetric matrix with neural networks.</p>
<p>This is a field with a large interest recently, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides <a href="https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html" target="_self">from week 42</a> and/or the textbook by <a href="https://www.springer.com/gp/book/9789401798150" target="_self">Yadav et al</a>.</p>
<p><b>Note</b>: Project 3 has an additional exercise which can give you an additional score of 30 (thirty) points. These are added to the total score from all projects. See below for the additional exercise. </p>
<h2 id="the-basic-structure-of-your-project" class="anchor">The basic structure of your project </h2>
<p>Here follows a set up on how to structure your report and analyze the data you have opted for.</p>
<h3 id="part-a" class="anchor">Part a) </h3>
<p>The first part deals with structuring and reading the data, much along the same lines as done in projects 1 and 2. Explain how the data are produced and place them in a proper context.</p>
<h3 id="part-b" class="anchor">Part b) </h3>
<p>You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part.</p>
<h3 id="part-c" class="anchor">Part c) </h3>
<p>Then describe your algorithm and its implementation and tests you have performed.</p>
<h3 id="part-d" class="anchor">Part d) </h3>
<p>Then presents your results and findings, link with existing literature and more.</p>
<h3 id="part-e" class="anchor">Part e) </h3>
<p>Finally, here you should present a critical assessment of the methods you have studied and link your results with the existing literature. </p>
<h2 id="solving-partial-differential-equations-with-neural-networks" class="anchor">Solving partial differential equations with neural networks </h2>
<p>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.
</p>
<p>For the explicit scheme, you can study for example chapter 10 of the lecture notes in <a href="https://github.com/CompPhysics/ComputationalPhysics/blob/master/doc/Lectures/lectures2015.pdf" target="_self">Computational Physics</a> or alternative sources. For the solution of ordinary and partial differential equations using neural networks, the lectures by <a href="https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html" target="_self">Kristine Baluka Hein and included in the lectures of week 42</a> at this course are highly recommended.</p>
<p>For the machine learning part you can use your own code from project 2 or the functionality of for example <b>Tensorflow/Keras</b>.. </p>
<h3 id="part-a-setting-up-the-problem" class="anchor">Part a), setting up the problem </h3>
<p>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
</p>
$$
\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*}
$$
<p>or</p>
$$
\begin{equation*}
u_{xx} = u_t,
\end{equation*}
$$
<p>with initial conditions, i.e., the conditions at \( t=0 \),</p>
$$
\begin{equation*}
u(x,0)= \sin{(\pi x)} \hspace{0.5cm} 0 < x < L,
\end{equation*}
$$
<p>with \( L=1 \) the length of the \( x \)-region of interest. The
boundary conditions are
</p>
$$
\begin{equation*}
u(0,t)= 0 \hspace{0.5cm} t \ge 0,
\end{equation*}
$$
<p>and</p>
$$
\begin{equation*}
u(L,t)= 0 \hspace{0.5cm} t \ge 0.
\end{equation*}
$$
<p>The function \( u(x,t) \) can be the temperature gradient of a rod.
As time increases, the velocity approaches a linear variation with \( x \).
</p>
<p>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 </p>
$$
\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*}
$$
<p>and</p>
$$
\begin{equation*}
u_{xx}\approx \frac{u(x+\Delta x,t)-2u(x,t)+u(x-\Delta x,t)}{\Delta x^2},
\end{equation*}
$$
<p>or</p>
$$
\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*}
$$
<p>Write down the algorithm and the equations you need to implement.
Find also the analytical solution to the problem.
</p>
<h3 id="part-b" class="anchor">Part b) </h3>
<p>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 \).
</p>
<p>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.
</p>
<h3 id="part-c-neural-networks" class="anchor">Part c) Neural networks </h3>
<p>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.
</p>
<h3 id="part-d-solving-eigenvalue-problems" class="anchor">Part d) Solving eigenvalue problems </h3>
<p>Follow the discussion in the work of Yi <em>et al.</em> in the article from
<a href="https://www.sciencedirect.com/science/article/pii/S0898122104901101" target="_self">Computers and Mathematics with Applications 47, 1155 (2004)</a>, and
use your differential equation solver with neural networks, set up a
simple square, real and symmetric \( 6\times 6 \) matrix and find the
eigenvalues. Compare with the solution from numerical diagonalization with standard eigenvalue solvers from linear algebra.
</p>
<h3 id="part-e" class="anchor">Part e) </h3>
<p>Finally, present a critical assessment of the methods you have studied and discuss the potential for the solving differential equations and eigenvalue problems with machine learning methods. </p>
<h2 id="additonal-optional-exercise-adding-30-more-points-to-final-score" class="anchor">Additonal (optional) exercise, adding 30 more points to final score </h2>
<p>This exercise can be done independently of the other tasks. Here you
can also choose the data set you want to use. Furthermore, you can use
your codes from projects 1 and 2 as well as the codes here or simply use
libraries like <b>Scikit-Learn</b>, <b>Tensorflow</b> or similar.
</p>
<p>Your task is to perform an analysis of the bias-variance tradeoff
using at least three of the main sets of algorithms we have discussed in this
course. We will limit ourselves to a regression problem (fitting). However, feel free to venture into a classification problem.
</p>
<p>You
are free to choose between bootstrap for resampling (recommended) or
cross-validation in order to get the best possible estimates. The
methods you could study are Linear Regression (OLS, Ridge and Lasso),
deep learning (feed forward neural networks and/or recurrent neural
networks), Ensemble methods (decision trees, bagging, random forests
and boosting) and support vector machines.
</p>
<p>Study the bias-variance tradeoff for at least three of these sets of
algorithms for a data set of your choice as function of the complexity
of your model. Comment and discuss the results. Discuss the pros and
cons of the various methods. Are there some methods which provide both
low variance and low bias?
</p>
<p><b>Hint</b>: when you use different methods, pay attention to how you represent (and understand) the complexity of the model. For example, when using decision trees you may represent the complexity of your model by the depth of the tree. </p>
<h2 id="introduction-to-numerical-projects" class="anchor">Introduction to numerical projects </h2>
<p>Here follows a brief recipe and recommendation on how to write a report for each
project.
</p>
<ul>
<li> Give a short description of the nature of the problem and the eventual numerical methods you have used.</li>
<li> 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.</li>
<li> Include the source code of your program. Comment your program properly.</li>
<li> If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.</li>
<li> 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.</li>
<li> 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.</li>
<li> Try to give an interpretation of you results in your answers to the problems.</li>
<li> 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.</li>
<li> 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.</li>
</ul>
<h2 id="format-for-electronic-delivery-of-report-and-programs" class="anchor">Format for electronic delivery of report and programs </h2>
<p>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:</p>
<ul>
<li> Use Canvas to hand in your projects, log in at <a href="https://www.uio.no/english/services/it/education/canvas/" target="_self"><tt>https://www.uio.no/english/services/it/education/canvas/</tt></a> with your normal UiO username and password.</li>
<li> Upload <b>only</b> the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar 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.</li>
<li> In your GitHub/GitLab or similar 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.</li>
</ul>
<p>Finally,
we encourage you to collaborate. Optimal working groups consist of
2-3 students. You can then hand in a common report.
</p>
<h2 id="software-and-needed-installations" class="anchor">Software and needed installations </h2>
<p>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 <b>pip</b> as
</p>
<ol>
<li> pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow</li>
</ol>
<p>For Python3, replace <b>pip</b> with <b>pip3</b>.</p>
<p>See below for a discussion of <b>tensorflow</b> and <b>scikit-learn</b>. </p>
<p>For OSX users we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
for a seamless installation of additional software via for example
</p>
<ol>
<li> brew install python3</li>
</ol>
<p>For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
you can use <b>pip</b> as well and simply install Python as
</p>
<ol>
<li> sudo apt-get install python3 (or python for python2.7)</li>
</ol>
<p>etc etc. </p>
<p>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</p>
<ol>
<li> <a href="https://docs.anaconda.com/" target="_self">Anaconda</a> 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 <b>conda</b></li>
<li> <a href="https://www.enthought.com/product/canopy/" target="_self">Enthought canopy</a> is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.</li>
</ol>
<p>Popular software packages written in Python for ML are</p>
<ul>
<li> <a href="http://scikit-learn.org/stable/" target="_self">Scikit-learn</a>,</li>
<li> <a href="https://www.tensorflow.org/" target="_self">Tensorflow</a>,</li>
<li> <a href="http://pytorch.org/" target="_self">PyTorch</a> and</li>
<li> <a href="https://keras.io/" target="_self">Keras</a>.</li>
</ul>
<p>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.
</p>
<p>
<!-- navigation buttons at the bottom of the page -->
<ul class="pagination">
<li class="active"><a href="._Project3-bs000.html">1</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
</div> <!-- end container -->
<!-- include javascript, jQuery *first* -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<!-- Bootstrap footer
<footer>
<a href="https://..."><img width="250" align=right src="https://..."></a>
</footer>
-->
<center style="font-size:80%">
<!-- copyright --> &copy; 1999-2022, "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
</center>
</body>
</html>
@@ -0,0 +1,474 @@
<!--
HTML file automatically generated from DocOnce source
(https://github.com/doconce/doconce/)
doconce format html Project3.do.txt --pygments_html_style=default --html_style=bloodish --html_links_in_new_window --html_output=Project3
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/doconce/doconce/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Project 3 on Machine Learning, deadline December 15 (midnight), 2021">
<title>Project 3 on Machine Learning, deadline December 15 (midnight), 2021</title>
<style type="text/css">
/* bloodish style */
body {
font-family: Helvetica, Verdana, Arial, Sans-serif;
color: #404040;
background: #ffffff;
}
h1 { font-size: 1.8em; color: #8A0808; }
h2 { font-size: 1.6em; color: #8A0808; }
h3 { font-size: 1.4em; color: #8A0808; }
h4 { font-size: 1.2em; color: #8A0808; }
a { color: #8A0808; text-decoration:none; }
tt { font-family: "Courier New", Courier; }
p { text-indent: 0px; }
hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
p.caption { width: 80%; font-style: normal; text-align: left; }
hr.figure { border: 0; width: 80%; border-bottom: 1px solid #aaa; }div.highlight {
border: 1px solid #cfcfcf;
border-radius: 2px;
line-height: 1.21429em;
}
div.cell {
width: 100%;
padding: 5px 5px 5px 0;
margin: 0;
outline: none;
}
div.input {
page-break-inside: avoid;
box-orient: horizontal;
box-align: stretch;
display: flex;
flex-direction: row;
align-items: stretch;
}
div.inner_cell {
box-orient: vertical;
box-align: stretch;
display: flex;
flex-direction: column;
align-items: stretch;
box-flex: 1;
flex: 1;
}
div.input_area {
border: 1px solid #cfcfcf;
border-radius: 4px;
background: #f7f7f7;
line-height: 1.21429em;
}
div.input_area > div.highlight {
margin: .4em;
border: none;
padding: 0;
background-color: transparent;
}
div.output_wrapper {
position: relative;
box-orient: vertical;
box-align: stretch;
display: flex;
flex-direction: column;
align-items: stretch;
}
.output {
box-orient: vertical;
box-align: stretch;
display: flex;
flex-direction: column;
align-items: stretch;
}
div.output_area {
padding: 0;
page-break-inside: avoid;
box-orient: horizontal;
box-align: stretch;
display: flex;
flex-direction: row;
align-items: stretch;
}
div.output_subarea {
padding: .4em .4em 0 .4em;
box-flex: 1;
flex: 1;
}
div.output_text {
text-align: left;
color: #000;
line-height: 1.21429em;
}
div { text-align: justify; text-justify: inter-word; }
.tab {
padding-left: 1.5em;
}
div.toc p,a {
line-height: 1.3;
margin-top: 1.1;
margin-bottom: 1.1;
}
</style>
</head>
<!-- tocinfo
{'highest level': 1,
'sections': [('Paths for project 3', 1, None, 'paths-for-project-3'),
('Defining the data sets to analyze yourself',
2,
None,
'defining-the-data-sets-to-analyze-yourself'),
('The basic structure of your project',
2,
None,
'the-basic-structure-of-your-project'),
('Part a)', 3, None, 'part-a'),
('Part b)', 3, None, 'part-b'),
('Part c)', 3, None, 'part-c'),
('Part d)', 3, None, 'part-d'),
('Part e)', 3, None, 'part-e'),
('Solving partial differential equations with neural networks',
2,
None,
'solving-partial-differential-equations-with-neural-networks'),
('Part a), setting up the problem',
3,
None,
'part-a-setting-up-the-problem'),
('Part b)', 3, None, 'part-b'),
('Part c) Neural networks', 3, None, 'part-c-neural-networks'),
('Part d) Solving eigenvalue problems',
3,
None,
'part-d-solving-eigenvalue-problems'),
('Part e)', 3, None, 'part-e'),
('Additonal (optional) exercise, adding 30 more points to final '
'score',
2,
None,
'additonal-optional-exercise-adding-30-more-points-to-final-score'),
('Introduction to numerical projects',
2,
None,
'introduction-to-numerical-projects'),
('Format for electronic delivery of report and programs',
2,
None,
'format-for-electronic-delivery-of-report-and-programs'),
('Software and needed installations',
2,
None,
'software-and-needed-installations')]}
end of tocinfo -->
<body>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
}
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- ------------------- main content ---------------------- -->
<center>
<h1>Project 3 on Machine Learning, deadline December 15 (midnight), 2021</h1>
</center> <!-- document title -->
<!-- author(s): <a href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html" target="_blank">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a> -->
<center>
<b><a href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html" target="_blank">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a></b>
</center>
<!-- institution -->
<center>
<b>Department of Physics, University of Oslo, Norway</b>
</center>
<br>
<center>
<h4>Nov 14, 2022</h4>
</center> <!-- date -->
<br>
<h1 id="paths-for-project-3">Paths for project 3 </h1>
<h2 id="defining-the-data-sets-to-analyze-yourself">Defining the data sets to analyze yourself </h2>
<p>For project 3, you can propose own data sets that relate to your research interests or just use existing data sets from say</p>
<ol>
<li> <a href="https://www.kaggle.com/datasets" target="_blank">Kaggle</a></li>
<li> The <a href="https://archive.ics.uci.edu/ml/index.php" target="_blank">University of California at Irvine (UCI) with its machine learning repository</a>.</li>
<li> Or other sources.</li>
</ol>
<p>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:</p>
<ol>
<li> Whether you end up with a regression or a classification problem, you should employ at least two of the methods we have discussed among <b>linear regression (including Ridge and Lasso)</b>, <b>Logistic Regression</b>, <b>Neural Networks</b>, <b>Convolution Neural Networks</b>, <b>Recurrent Neural Networks</b>, <b>Adversarial Neural Networks</b>, <b>Support Vector Machines</b> and <b>Decision Trees, Random Forests, Bagging and Boosting</b>. You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. If you wish to venture into <b>convolutional neural networks</b> or <b>recurrent neural networks</b>, or extensions of neural networkds, feel free to do so. You can also study unsupervised methods, although we in this course have mainly paid attendtion to supervised learning. The methods we have explored as <b>Principal Component Analysis</b> and <b>k-means Clustering</b>.</li>
</ol>
<p>For Boosting, feel also free to write your own codes.</p>
<ol>
<li> 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/random forests/bagging/boosting' or use the available functionality of <b>Scikit-Learn</b>, <b>Tensorflow</b>, etc.</li>
<li> The estimates you used and tested in projects 1 and 2 should also be included, that is the \( R2 \)-score, <b>MSE</b>, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.</li>
<li> Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.</li>
<li> 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?</li>
<li> A critical assessment of the methods with ditto perspectives and recommendations is also something you need to include.</li>
</ol>
<p>All in all, the report should follow the same pattern as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..</p>
<p>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, with a final twist on how to diagonalize a symmetric matrix with neural networks.</p>
<p>This is a field with a large interest recently, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides <a href="https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html" target="_blank">from week 42</a> and/or the textbook by <a href="https://www.springer.com/gp/book/9789401798150" target="_blank">Yadav et al</a>.</p>
<p><b>Note</b>: Project 3 has an additional exercise which can give you an additional score of 30 (thirty) points. These are added to the total score from all projects. See below for the additional exercise. </p>
<h2 id="the-basic-structure-of-your-project">The basic structure of your project </h2>
<p>Here follows a set up on how to structure your report and analyze the data you have opted for.</p>
<h3 id="part-a">Part a) </h3>
<p>The first part deals with structuring and reading the data, much along the same lines as done in projects 1 and 2. Explain how the data are produced and place them in a proper context.</p>
<h3 id="part-b">Part b) </h3>
<p>You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part.</p>
<h3 id="part-c">Part c) </h3>
<p>Then describe your algorithm and its implementation and tests you have performed.</p>
<h3 id="part-d">Part d) </h3>
<p>Then presents your results and findings, link with existing literature and more.</p>
<h3 id="part-e">Part e) </h3>
<p>Finally, here you should present a critical assessment of the methods you have studied and link your results with the existing literature. </p>
<h2 id="solving-partial-differential-equations-with-neural-networks">Solving partial differential equations with neural networks </h2>
<p>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.
</p>
<p>For the explicit scheme, you can study for example chapter 10 of the lecture notes in <a href="https://github.com/CompPhysics/ComputationalPhysics/blob/master/doc/Lectures/lectures2015.pdf" target="_blank">Computational Physics</a> or alternative sources. For the solution of ordinary and partial differential equations using neural networks, the lectures by <a href="https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html" target="_blank">Kristine Baluka Hein and included in the lectures of week 42</a> at this course are highly recommended.</p>
<p>For the machine learning part you can use your own code from project 2 or the functionality of for example <b>Tensorflow/Keras</b>.. </p>
<h3 id="part-a-setting-up-the-problem">Part a), setting up the problem </h3>
<p>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
</p>
$$
\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*}
$$
<p>or</p>
$$
\begin{equation*}
u_{xx} = u_t,
\end{equation*}
$$
<p>with initial conditions, i.e., the conditions at \( t=0 \),</p>
$$
\begin{equation*}
u(x,0)= \sin{(\pi x)} \hspace{0.5cm} 0 < x < L,
\end{equation*}
$$
<p>with \( L=1 \) the length of the \( x \)-region of interest. The
boundary conditions are
</p>
$$
\begin{equation*}
u(0,t)= 0 \hspace{0.5cm} t \ge 0,
\end{equation*}
$$
<p>and</p>
$$
\begin{equation*}
u(L,t)= 0 \hspace{0.5cm} t \ge 0.
\end{equation*}
$$
<p>The function \( u(x,t) \) can be the temperature gradient of a rod.
As time increases, the velocity approaches a linear variation with \( x \).
</p>
<p>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 </p>
$$
\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*}
$$
<p>and</p>
$$
\begin{equation*}
u_{xx}\approx \frac{u(x+\Delta x,t)-2u(x,t)+u(x-\Delta x,t)}{\Delta x^2},
\end{equation*}
$$
<p>or</p>
$$
\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*}
$$
<p>Write down the algorithm and the equations you need to implement.
Find also the analytical solution to the problem.
</p>
<h3 id="part-b">Part b) </h3>
<p>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 \).
</p>
<p>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.
</p>
<h3 id="part-c-neural-networks">Part c) Neural networks </h3>
<p>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.
</p>
<h3 id="part-d-solving-eigenvalue-problems">Part d) Solving eigenvalue problems </h3>
<p>Follow the discussion in the work of Yi <em>et al.</em> in the article from
<a href="https://www.sciencedirect.com/science/article/pii/S0898122104901101" target="_blank">Computers and Mathematics with Applications 47, 1155 (2004)</a>, and
use your differential equation solver with neural networks, set up a
simple square, real and symmetric \( 6\times 6 \) matrix and find the
eigenvalues. Compare with the solution from numerical diagonalization with standard eigenvalue solvers from linear algebra.
</p>
<h3 id="part-e">Part e) </h3>
<p>Finally, present a critical assessment of the methods you have studied and discuss the potential for the solving differential equations and eigenvalue problems with machine learning methods. </p>
<h2 id="additonal-optional-exercise-adding-30-more-points-to-final-score">Additonal (optional) exercise, adding 30 more points to final score </h2>
<p>This exercise can be done independently of the other tasks. Here you
can also choose the data set you want to use. Furthermore, you can use
your codes from projects 1 and 2 as well as the codes here or simply use
libraries like <b>Scikit-Learn</b>, <b>Tensorflow</b> or similar.
</p>
<p>Your task is to perform an analysis of the bias-variance tradeoff
using at least three of the main sets of algorithms we have discussed in this
course. We will limit ourselves to a regression problem (fitting). However, feel free to venture into a classification problem.
</p>
<p>You
are free to choose between bootstrap for resampling (recommended) or
cross-validation in order to get the best possible estimates. The
methods you could study are Linear Regression (OLS, Ridge and Lasso),
deep learning (feed forward neural networks and/or recurrent neural
networks), Ensemble methods (decision trees, bagging, random forests
and boosting) and support vector machines.
</p>
<p>Study the bias-variance tradeoff for at least three of these sets of
algorithms for a data set of your choice as function of the complexity
of your model. Comment and discuss the results. Discuss the pros and
cons of the various methods. Are there some methods which provide both
low variance and low bias?
</p>
<p><b>Hint</b>: when you use different methods, pay attention to how you represent (and understand) the complexity of the model. For example, when using decision trees you may represent the complexity of your model by the depth of the tree. </p>
<h2 id="introduction-to-numerical-projects">Introduction to numerical projects </h2>
<p>Here follows a brief recipe and recommendation on how to write a report for each
project.
</p>
<ul>
<li> Give a short description of the nature of the problem and the eventual numerical methods you have used.</li>
<li> 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.</li>
<li> Include the source code of your program. Comment your program properly.</li>
<li> If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.</li>
<li> 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.</li>
<li> 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.</li>
<li> Try to give an interpretation of you results in your answers to the problems.</li>
<li> 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.</li>
<li> 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.</li>
</ul>
<h2 id="format-for-electronic-delivery-of-report-and-programs">Format for electronic delivery of report and programs </h2>
<p>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:</p>
<ul>
<li> Use Canvas to hand in your projects, log in at <a href="https://www.uio.no/english/services/it/education/canvas/" target="_blank"><tt>https://www.uio.no/english/services/it/education/canvas/</tt></a> with your normal UiO username and password.</li>
<li> Upload <b>only</b> the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar 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.</li>
<li> In your GitHub/GitLab or similar 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.</li>
</ul>
<p>Finally,
we encourage you to collaborate. Optimal working groups consist of
2-3 students. You can then hand in a common report.
</p>
<h2 id="software-and-needed-installations">Software and needed installations </h2>
<p>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 <b>pip</b> as
</p>
<ol>
<li> pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow</li>
</ol>
<p>For Python3, replace <b>pip</b> with <b>pip3</b>.</p>
<p>See below for a discussion of <b>tensorflow</b> and <b>scikit-learn</b>. </p>
<p>For OSX users we recommend also, after having installed Xcode, to install <b>brew</b>. Brew allows
for a seamless installation of additional software via for example
</p>
<ol>
<li> brew install python3</li>
</ol>
<p>For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
you can use <b>pip</b> as well and simply install Python as
</p>
<ol>
<li> sudo apt-get install python3 (or python for python2.7)</li>
</ol>
<p>etc etc. </p>
<p>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</p>
<ol>
<li> <a href="https://docs.anaconda.com/" target="_blank">Anaconda</a> 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 <b>conda</b></li>
<li> <a href="https://www.enthought.com/product/canopy/" target="_blank">Enthought canopy</a> is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.</li>
</ol>
<p>Popular software packages written in Python for ML are</p>
<ul>
<li> <a href="http://scikit-learn.org/stable/" target="_blank">Scikit-learn</a>,</li>
<li> <a href="https://www.tensorflow.org/" target="_blank">Tensorflow</a>,</li>
<li> <a href="http://pytorch.org/" target="_blank">PyTorch</a> and</li>
<li> <a href="https://keras.io/" target="_blank">Keras</a>.</li>
</ul>
<p>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.
</p>
<!-- ------------------- end of main content --------------- -->
<center style="font-size:80%">
<!-- copyright --> &copy; 1999-2022, "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
</center>
</body>
</html>
@@ -0,0 +1,567 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0c2e93c2",
"metadata": {
"editable": true
},
"source": [
"<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)\n",
"doconce format html Project3.do.txt -->\n",
"<!-- dom:TITLE: Project 3 on Machine Learning, deadline December 15 (midnight), 2021 -->"
]
},
{
"cell_type": "markdown",
"id": "2dc0413d",
"metadata": {
"editable": true
},
"source": [
"# Project 3 on Machine Learning, deadline December 15 (midnight), 2021\n",
"**[Data Analysis and Machine Learning FYS-STK3155/FYS4155](http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html)**, Department of Physics, University of Oslo, Norway\n",
"\n",
"Date: **Nov 14, 2022**\n",
"\n",
"Copyright 1999-2022, [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"
]
},
{
"cell_type": "markdown",
"id": "92237bb9",
"metadata": {
"editable": true
},
"source": [
"# Paths for project 3"
]
},
{
"cell_type": "markdown",
"id": "9b6ca5fb",
"metadata": {
"editable": true
},
"source": [
"## Defining the data sets to analyze yourself\n",
"\n",
"For project 3, you can propose own data sets that relate to your research interests or just use existing data sets from say\n",
"1. [Kaggle](https://www.kaggle.com/datasets) \n",
"\n",
"2. The [University of California at Irvine (UCI) with its machine learning repository](https://archive.ics.uci.edu/ml/index.php).\n",
"\n",
"3. Or other sources.\n",
"\n",
"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:\n",
"1. Whether you end up with a regression or a classification problem, you should employ at least two of the methods we have discussed among **linear regression (including Ridge and Lasso)**, **Logistic Regression**, **Neural Networks**, **Convolution Neural Networks**, **Recurrent Neural Networks**, **Adversarial Neural Networks**, **Support Vector Machines** and **Decision Trees, Random Forests, Bagging and Boosting**. You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. If you wish to venture into **convolutional neural networks** or **recurrent neural networks**, or extensions of neural networkds, feel free to do so. You can also study unsupervised methods, although we in this course have mainly paid attendtion to supervised learning. The methods we have explored as **Principal Component Analysis** and **k-means Clustering**.\n",
"\n",
"For Boosting, feel also free to write your own codes.\n",
"\n",
"1. 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/random forests/bagging/boosting' or use the available functionality of **Scikit-Learn**, **Tensorflow**, etc. \n",
"\n",
"2. The estimates you used and tested in projects 1 and 2 should also be included, that is the $R2$-score, **MSE**, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.\n",
"\n",
"3. Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.\n",
"\n",
"4. 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? \n",
"\n",
"5. A critical assessment of the methods with ditto perspectives and recommendations is also something you need to include.\n",
"\n",
"All in all, the report should follow the same pattern as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..\n",
"\n",
"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, with a final twist on how to diagonalize a symmetric matrix with neural networks.\n",
"\n",
"This is a field with a large interest recently, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides [from week 42](https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html) and/or the textbook by [Yadav et al](https://www.springer.com/gp/book/9789401798150).\n",
"\n",
"**Note**: Project 3 has an additional exercise which can give you an additional score of 30 (thirty) points. These are added to the total score from all projects. See below for the additional exercise."
]
},
{
"cell_type": "markdown",
"id": "d3d26ef5",
"metadata": {
"editable": true
},
"source": [
"## The basic structure of your project\n",
"\n",
"Here follows a set up on how to structure your report and analyze the data you have opted for."
]
},
{
"cell_type": "markdown",
"id": "a03830d7",
"metadata": {
"editable": true
},
"source": [
"### Part a)\n",
"\n",
"The first part deals with structuring and reading the data, much along the same lines as done in projects 1 and 2. Explain how the data are produced and place them in a proper context."
]
},
{
"cell_type": "markdown",
"id": "3bf25ce5",
"metadata": {
"editable": true
},
"source": [
"### Part b)\n",
"\n",
"You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part."
]
},
{
"cell_type": "markdown",
"id": "0ba7777e",
"metadata": {
"editable": true
},
"source": [
"### Part c)\n",
"\n",
"Then describe your algorithm and its implementation and tests you have performed."
]
},
{
"cell_type": "markdown",
"id": "129fff02",
"metadata": {
"editable": true
},
"source": [
"### Part d)\n",
"\n",
"Then presents your results and findings, link with existing literature and more."
]
},
{
"cell_type": "markdown",
"id": "da24bb44",
"metadata": {
"editable": true
},
"source": [
"### Part e)\n",
"\n",
"Finally, here you should present a critical assessment of the methods you have studied and link your results with the existing literature."
]
},
{
"cell_type": "markdown",
"id": "b4d8bd6f",
"metadata": {
"editable": true
},
"source": [
"## Solving partial differential equations with neural networks\n",
"\n",
"For this variant of project 3, we will assume that you have some\n",
"background in the solution of partial differential equations using\n",
"finite difference schemes. We will study the solution of the diffusion\n",
"equation in one dimension using a standard explicit scheme and neural\n",
"networks to solve the same equations.\n",
"\n",
"For the explicit scheme, you can study for example chapter 10 of the lecture notes in [Computational Physics](https://github.com/CompPhysics/ComputationalPhysics/blob/master/doc/Lectures/lectures2015.pdf) or alternative sources. For the solution of ordinary and partial differential equations using neural networks, the lectures by [Kristine Baluka Hein and included in the lectures of week 42](https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html) at this course are highly recommended.\n",
"\n",
"For the machine learning part you can use your own code from project 2 or the functionality of for example **Tensorflow/Keras**.."
]
},
{
"cell_type": "markdown",
"id": "9fb8b554",
"metadata": {
"editable": true
},
"source": [
"### Part a), setting up the problem\n",
"\n",
"The physical problem can be that of the temperature gradient in a rod of length $L=1$ at $x=0$ and $x=1$.\n",
"We are looking at a one-dimensional\n",
"problem"
]
},
{
"cell_type": "markdown",
"id": "9c1a12d5",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"\\frac{\\partial^2 u(x,t)}{\\partial x^2} =\\frac{\\partial u(x,t)}{\\partial t}, t> 0, x\\in [0,L]\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "81df663e",
"metadata": {
"editable": true
},
"source": [
"or"
]
},
{
"cell_type": "markdown",
"id": "3d639530",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u_{xx} = u_t,\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "b4a3d10e",
"metadata": {
"editable": true
},
"source": [
"with initial conditions, i.e., the conditions at $t=0$,"
]
},
{
"cell_type": "markdown",
"id": "e72fff12",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u(x,0)= \\sin{(\\pi x)} \\hspace{0.5cm} 0 < x < L,\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "1448ffdc",
"metadata": {
"editable": true
},
"source": [
"with $L=1$ the length of the $x$-region of interest. The \n",
"boundary conditions are"
]
},
{
"cell_type": "markdown",
"id": "4a10dc7f",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u(0,t)= 0 \\hspace{0.5cm} t \\ge 0,\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "665a89f8",
"metadata": {
"editable": true
},
"source": [
"and"
]
},
{
"cell_type": "markdown",
"id": "bfb1865c",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u(L,t)= 0 \\hspace{0.5cm} t \\ge 0.\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "caac2a80",
"metadata": {
"editable": true
},
"source": [
"The function $u(x,t)$ can be the temperature gradient of a rod.\n",
"As time increases, the velocity approaches a linear variation with $x$. \n",
"\n",
"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"
]
},
{
"cell_type": "markdown",
"id": "864c151d",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"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}\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "0e7ee4f9",
"metadata": {
"editable": true
},
"source": [
"and"
]
},
{
"cell_type": "markdown",
"id": "e40b01ba",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"u_{xx}\\approx \\frac{u(x+\\Delta x,t)-2u(x,t)+u(x-\\Delta x,t)}{\\Delta x^2},\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "bde8abf8",
"metadata": {
"editable": true
},
"source": [
"or"
]
},
{
"cell_type": "markdown",
"id": "fbb28a61",
"metadata": {
"editable": true
},
"source": [
"$$\n",
"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}.\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "88fdfd23",
"metadata": {
"editable": true
},
"source": [
"Write down the algorithm and the equations you need to implement.\n",
"Find also the analytical solution to the problem."
]
},
{
"cell_type": "markdown",
"id": "ae0f5018",
"metadata": {
"editable": true
},
"source": [
"### Part b)\n",
"\n",
"Implement the explicit scheme algorithm and perform tests of the solution \n",
"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$. \n",
"\n",
"Study the solutions at two time points $t_1$ and $t_2$ where $u(x,t_1)$ is smooth but still significantly curved\n",
"and $u(x,t_2)$ is almost linear, close to the stationary state."
]
},
{
"cell_type": "markdown",
"id": "64e90ef9",
"metadata": {
"editable": true
},
"source": [
"### Part c) Neural networks\n",
"\n",
"Study now the lecture notes on solving ODEs and PDEs with neural\n",
"network and use either your own code from project 2 or the\n",
"functionality of tensorflow/keras to solve the same equation as in\n",
"part b). Discuss your results and compare them with the standard\n",
"explicit scheme. Include also the analytical solution and compare with\n",
"that."
]
},
{
"cell_type": "markdown",
"id": "ea02a377",
"metadata": {
"editable": true
},
"source": [
"### Part d) Solving eigenvalue problems\n",
"\n",
"Follow the discussion in the work of Yi *et al.* in the article from\n",
"[Computers and Mathematics with Applications 47, 1155 (2004)](https://www.sciencedirect.com/science/article/pii/S0898122104901101), and\n",
"use your differential equation solver with neural networks, set up a\n",
"simple square, real and symmetric $6\\times 6$ matrix and find the\n",
"eigenvalues. Compare with the solution from numerical diagonalization with standard eigenvalue solvers from linear algebra."
]
},
{
"cell_type": "markdown",
"id": "57f27bd3",
"metadata": {
"editable": true
},
"source": [
"### Part e)\n",
"\n",
"Finally, present a critical assessment of the methods you have studied and discuss the potential for the solving differential equations and eigenvalue problems with machine learning methods."
]
},
{
"cell_type": "markdown",
"id": "684f4cd8",
"metadata": {
"editable": true
},
"source": [
"## Additonal (optional) exercise, adding 30 more points to final score\n",
"\n",
"This exercise can be done independently of the other tasks. Here you\n",
"can also choose the data set you want to use. Furthermore, you can use\n",
"your codes from projects 1 and 2 as well as the codes here or simply use\n",
"libraries like **Scikit-Learn**, **Tensorflow** or similar.\n",
"\n",
"Your task is to perform an analysis of the bias-variance tradeoff\n",
"using at least three of the main sets of algorithms we have discussed in this\n",
"course. We will limit ourselves to a regression problem (fitting). However, feel free to venture into a classification problem.\n",
"\n",
"You\n",
"are free to choose between bootstrap for resampling (recommended) or\n",
"cross-validation in order to get the best possible estimates. The\n",
"methods you could study are Linear Regression (OLS, Ridge and Lasso),\n",
"deep learning (feed forward neural networks and/or recurrent neural\n",
"networks), Ensemble methods (decision trees, bagging, random forests\n",
"and boosting) and support vector machines.\n",
"\n",
"Study the bias-variance tradeoff for at least three of these sets of\n",
"algorithms for a data set of your choice as function of the complexity\n",
"of your model. Comment and discuss the results. Discuss the pros and\n",
"cons of the various methods. Are there some methods which provide both\n",
"low variance and low bias?\n",
"\n",
"**Hint**: when you use different methods, pay attention to how you represent (and understand) the complexity of the model. For example, when using decision trees you may represent the complexity of your model by the depth of the tree."
]
},
{
"cell_type": "markdown",
"id": "2a6962e8",
"metadata": {
"editable": true
},
"source": [
"## Introduction to numerical projects\n",
"\n",
"Here follows a brief recipe and recommendation on how to write a report for each\n",
"project.\n",
"\n",
" * Give a short description of the nature of the problem and the eventual numerical methods you have used.\n",
"\n",
" * 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.\n",
"\n",
" * Include the source code of your program. Comment your program properly.\n",
"\n",
" * If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.\n",
"\n",
" * 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.\n",
"\n",
" * 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.\n",
"\n",
" * Try to give an interpretation of you results in your answers to the problems.\n",
"\n",
" * 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.\n",
"\n",
" * 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."
]
},
{
"cell_type": "markdown",
"id": "4c047e8f",
"metadata": {
"editable": true
},
"source": [
"## Format for electronic delivery of report and programs\n",
"\n",
"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:\n",
"\n",
" * Use Canvas to hand in your projects, log in at <https://www.uio.no/english/services/it/education/canvas/> with your normal UiO username and password.\n",
"\n",
" * Upload **only** the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar 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.\n",
"\n",
" * In your GitHub/GitLab or similar 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.\n",
"\n",
"Finally, \n",
"we encourage you to collaborate. Optimal working groups consist of \n",
"2-3 students. You can then hand in a common report."
]
},
{
"cell_type": "markdown",
"id": "d7750944",
"metadata": {
"editable": true
},
"source": [
"## Software and needed installations\n",
"\n",
"If you have Python installed (we recommend Python3) and you feel pretty familiar with installing different packages, \n",
"we recommend that you install the following Python packages via **pip** as\n",
"1. pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow\n",
"\n",
"For Python3, replace **pip** with **pip3**.\n",
"\n",
"See below for a discussion of **tensorflow** and **scikit-learn**. \n",
"\n",
"For OSX users we recommend also, after having installed Xcode, to install **brew**. Brew allows \n",
"for a seamless installation of additional software via for example\n",
"1. brew install python3\n",
"\n",
"For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution\n",
"you can use **pip** as well and simply install Python as \n",
"1. sudo apt-get install python3 (or python for python2.7)\n",
"\n",
"etc etc. \n",
"\n",
"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\n",
"1. [Anaconda](https://docs.anaconda.com/) 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 **conda**\n",
"\n",
"2. [Enthought canopy](https://www.enthought.com/product/canopy/) is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.\n",
"\n",
"Popular software packages written in Python for ML are\n",
"\n",
"* [Scikit-learn](http://scikit-learn.org/stable/), \n",
"\n",
"* [Tensorflow](https://www.tensorflow.org/),\n",
"\n",
"* [PyTorch](http://pytorch.org/) and \n",
"\n",
"* [Keras](https://keras.io/).\n",
"\n",
"These are all freely available at their respective GitHub sites. They \n",
"encompass communities of developers in the thousands or more. And the number\n",
"of code developers and contributors keeps increasing."
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
@@ -0,0 +1,437 @@
%%
%% Automatically generated file from DocOnce source
%% (https://github.com/doconce/doconce/)
%% doconce format latex Project3.do.txt --print_latex_style=trac --latex_admon=paragraph
%%
% #ifdef PTEX2TEX_EXPLANATION
%%
%% The file follows the ptex2tex extended LaTeX format, see
%% ptex2tex: https://code.google.com/p/ptex2tex/
%%
%% Run
%% ptex2tex myfile
%% or
%% doconce ptex2tex myfile
%%
%% to turn myfile.p.tex into an ordinary LaTeX file myfile.tex.
%% (The ptex2tex program: https://code.google.com/p/ptex2tex)
%% Many preprocess options can be added to ptex2tex or doconce ptex2tex
%%
%% ptex2tex -DMINTED myfile
%% doconce ptex2tex myfile envir=minted
%%
%% ptex2tex will typeset code environments according to a global or local
%% .ptex2tex.cfg configure file. doconce ptex2tex will typeset code
%% according to options on the command line (just type doconce ptex2tex to
%% see examples). If doconce ptex2tex has envir=minted, it enables the
%% minted style without needing -DMINTED.
% #endif
% #define PREAMBLE
% #ifdef PREAMBLE
%-------------------- 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-2022, "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-2022, "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
% #endif
\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 15 (midnight), 2021
\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 14, 2022
\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{{https://archive.ics.uci.edu/ml/index.php}}{University of California at Irvine (UCI) with its machine learning repository}.
\item Or other sources.
\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{Convolution Neural Networks}, \textbf{Recurrent Neural Networks}, \textbf{Adversarial Neural Networks}, \textbf{Support Vector Machines} and \textbf{Decision Trees, Random Forests, Bagging and Boosting}. You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. 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. You can also study unsupervised methods, although we in this course have mainly paid attendtion to supervised learning. The methods we have explored as \textbf{Principal Component Analysis} and \textbf{k-means Clustering}.
\end{enumerate}
\noindent
For Boosting, feel also free to write your own codes.
\begin{enumerate}
\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/random forests/bagging/boosting' 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}, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.
\item Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.
\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 as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..
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, with a final twist on how to diagonalize a symmetric matrix with neural networks.
This is a field with a large interest recently, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides \href{{https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html}}{from week 42} and/or the textbook by \href{{https://www.springer.com/gp/book/9789401798150}}{Yadav et al}.
\textbf{Note}: Project 3 has an additional exercise which can give you an additional score of 30 (thirty) points. These are added to the total score from all projects. See below for the additional exercise.
\subsection{The basic structure of your project}
Here follows a set up on how to structure your report and analyze the data you have opted for.
\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. Explain how the data are produced and place them in a proper context.
\paragraph{Part b).}
You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part.
\paragraph{Part c).}
Then describe your algorithm and its implementation and tests you have performed.
\paragraph{Part d).}
Then presents your results and findings, link with existing literature and more.
\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/week42/html/week42.html}}{Kristine Baluka Hein and included in the lectures of week 42} 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) Solving eigenvalue problems.}
Follow the discussion in the work of Yi \emph{et al.} in the article from
\href{{https://www.sciencedirect.com/science/article/pii/S0898122104901101}}{Computers and Mathematics with Applications 47, 1155 (2004)}, and
use your differential equation solver with neural networks, set up a
simple square, real and symmetric $6\times 6$ matrix and find the
eigenvalues. Compare with the solution from numerical diagonalization with standard eigenvalue solvers from linear algebra.
\paragraph{Part e).}
Finally, present a critical assessment of the methods you have studied and discuss the potential for the solving differential equations and eigenvalue problems with machine learning methods.
\subsection{Additonal (optional) exercise, adding 30 more points to final score}
This exercise can be done independently of the other tasks. Here you
can also choose the data set you want to use. Furthermore, you can use
your codes from projects 1 and 2 as well as the codes here or simply use
libraries like \textbf{Scikit-Learn}, \textbf{Tensorflow} or similar.
Your task is to perform an analysis of the bias-variance tradeoff
using at least three of the main sets of algorithms we have discussed in this
course. We will limit ourselves to a regression problem (fitting). However, feel free to venture into a classification problem.
You
are free to choose between bootstrap for resampling (recommended) or
cross-validation in order to get the best possible estimates. The
methods you could study are Linear Regression (OLS, Ridge and Lasso),
deep learning (feed forward neural networks and/or recurrent neural
networks), Ensemble methods (decision trees, bagging, random forests
and boosting) and support vector machines.
Study the bias-variance tradeoff for at least three of these sets of
algorithms for a data set of your choice as function of the complexity
of your model. Comment and discuss the results. Discuss the pros and
cons of the various methods. Are there some methods which provide both
low variance and low bias?
\textbf{Hint}: when you use different methods, pay attention to how you represent (and understand) the complexity of the model. For example, when using decision trees you may represent the complexity of your model by the depth of the tree.
\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 Canvas to hand in your projects, log in at \href{{https://www.uio.no/english/services/it/education/canvas/}}{\nolinkurl{https://www.uio.no/english/services/it/education/canvas/}} with your normal UiO username and password.
\item Upload \textbf{only} the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar 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 GitHub/GitLab or similar 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.
\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 ---------------
% #ifdef PREAMBLE
\end{document}
% #endif
Binary file not shown.
+409
View File
@@ -0,0 +1,409 @@
%%
%% Automatically generated file from DocOnce source
%% (https://github.com/doconce/doconce/)
%% doconce format latex Project3.do.txt --print_latex_style=trac --latex_admon=paragraph
%%
%-------------------- 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-2022, "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-2022, "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 15 (midnight), 2021
\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 14, 2022
\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{{https://archive.ics.uci.edu/ml/index.php}}{University of California at Irvine (UCI) with its machine learning repository}.
\item Or other sources.
\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{Convolution Neural Networks}, \textbf{Recurrent Neural Networks}, \textbf{Adversarial Neural Networks}, \textbf{Support Vector Machines} and \textbf{Decision Trees, Random Forests, Bagging and Boosting}. You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. 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. You can also study unsupervised methods, although we in this course have mainly paid attendtion to supervised learning. The methods we have explored as \textbf{Principal Component Analysis} and \textbf{k-means Clustering}.
\end{enumerate}
\noindent
For Boosting, feel also free to write your own codes.
\begin{enumerate}
\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/random forests/bagging/boosting' 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}, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.
\item Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.
\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 as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..
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, with a final twist on how to diagonalize a symmetric matrix with neural networks.
This is a field with a large interest recently, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides \href{{https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html}}{from week 42} and/or the textbook by \href{{https://www.springer.com/gp/book/9789401798150}}{Yadav et al}.
\textbf{Note}: Project 3 has an additional exercise which can give you an additional score of 30 (thirty) points. These are added to the total score from all projects. See below for the additional exercise.
\subsection*{The basic structure of your project}
Here follows a set up on how to structure your report and analyze the data you have opted for.
\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. Explain how the data are produced and place them in a proper context.
\paragraph{Part b).}
You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part.
\paragraph{Part c).}
Then describe your algorithm and its implementation and tests you have performed.
\paragraph{Part d).}
Then presents your results and findings, link with existing literature and more.
\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/week42/html/week42.html}}{Kristine Baluka Hein and included in the lectures of week 42} 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) Solving eigenvalue problems.}
Follow the discussion in the work of Yi \emph{et al.} in the article from
\href{{https://www.sciencedirect.com/science/article/pii/S0898122104901101}}{Computers and Mathematics with Applications 47, 1155 (2004)}, and
use your differential equation solver with neural networks, set up a
simple square, real and symmetric $6\times 6$ matrix and find the
eigenvalues. Compare with the solution from numerical diagonalization with standard eigenvalue solvers from linear algebra.
\paragraph{Part e).}
Finally, present a critical assessment of the methods you have studied and discuss the potential for the solving differential equations and eigenvalue problems with machine learning methods.
\subsection*{Additonal (optional) exercise, adding 30 more points to final score}
This exercise can be done independently of the other tasks. Here you
can also choose the data set you want to use. Furthermore, you can use
your codes from projects 1 and 2 as well as the codes here or simply use
libraries like \textbf{Scikit-Learn}, \textbf{Tensorflow} or similar.
Your task is to perform an analysis of the bias-variance tradeoff
using at least three of the main sets of algorithms we have discussed in this
course. We will limit ourselves to a regression problem (fitting). However, feel free to venture into a classification problem.
You
are free to choose between bootstrap for resampling (recommended) or
cross-validation in order to get the best possible estimates. The
methods you could study are Linear Regression (OLS, Ridge and Lasso),
deep learning (feed forward neural networks and/or recurrent neural
networks), Ensemble methods (decision trees, bagging, random forests
and boosting) and support vector machines.
Study the bias-variance tradeoff for at least three of these sets of
algorithms for a data set of your choice as function of the complexity
of your model. Comment and discuss the results. Discuss the pros and
cons of the various methods. Are there some methods which provide both
low variance and low bias?
\textbf{Hint}: when you use different methods, pay attention to how you represent (and understand) the complexity of the model. For example, when using decision trees you may represent the complexity of your model by the depth of the tree.
\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 Canvas to hand in your projects, log in at \href{{https://www.uio.no/english/services/it/education/canvas/}}{\nolinkurl{https://www.uio.no/english/services/it/education/canvas/}} with your normal UiO username and password.
\item Upload \textbf{only} the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar 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 GitHub/GitLab or similar 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.
\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}
@@ -0,0 +1,283 @@
TITLE: Project 3 on Machine Learning, deadline December 15 (midnight), 2021
AUTHOR: "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html" {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo, Norway
DATE: today
======= Paths for project 3 =======
===== 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
o "Kaggle":"https://www.kaggle.com/datasets"
o The "University of California at Irvine (UCI) with its machine learning repository":"https://archive.ics.uci.edu/ml/index.php".
o Or other sources.
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:
o Whether you end up with a regression or a classification problem, you should employ at least two of the methods we have discussed among _linear regression (including Ridge and Lasso)_, _Logistic Regression_, _Neural Networks_, _Convolution Neural Networks_, _Recurrent Neural Networks_, _Adversarial Neural Networks_, _Support Vector Machines_ and _Decision Trees, Random Forests, Bagging and Boosting_. You could for example explore all of the approaches from decision trees, via bagging and voting classifiers, to random forests, boosting and finally XGboost. If you wish to venture into _convolutional neural networks_ or _recurrent neural networks_, or extensions of neural networkds, feel free to do so. You can also study unsupervised methods, although we in this course have mainly paid attendtion to supervised learning. The methods we have explored as _Principal Component Analysis_ and _k-means Clustering_.
For Boosting, feel also free to write your own codes.
o 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/random forests/bagging/boosting' or use the available functionality of _Scikit-Learn_, _Tensorflow_, etc.
o The estimates you used and tested in projects 1 and 2 should also be included, that is the $R2$-score, _MSE_, confusion matrix, accuracy score, information gain, ROC and Cumulative gains curves and other, cross-validation and/or bootstrap if these are relevant.
o Similarly, feel free to explore various activations functions in deep learning and various approachs to stochastic gradient descent approaches.
o 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?
o A critical assessment of the methods with ditto perspectives and recommendations is also something you need to include.
All in all, the report should follow the same pattern as the two previous ones, with abstract, introduction, methods, code, results, conclusions etc..
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, with a final twist on how to diagonalize a symmetric matrix with neural networks.
This is a field with a large interest recently, spanning from studies of turbulence in fluid mechanics and meteorology to the solution of quantum mechanical systems. As reading background you can use the slides "from week 42":"https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html" and/or the textbook by "Yadav et al":"https://www.springer.com/gp/book/9789401798150".
_Note_: Project 3 has an additional exercise which can give you an additional score of 30 (thirty) points. These are added to the total score from all projects. See below for the additional exercise.
===== The basic structure of your project =====
Here follows a set up on how to structure your report and analyze the data you have opted for.
=== Part a) ===
The first part deals with structuring and reading the data, much along the same lines as done in projects 1 and 2. Explain how the data are produced and place them in a proper context.
=== Part b) ===
You need to include at least two central algorithms, or as an alternative explore methods from decisions tree to bagging, random forests and boosting. Explain the basics of the methods you have chosen to work with. This would be your theory part.
=== Part c) ===
Then describe your algorithm and its implementation and tests you have performed.
=== Part d) ===
Then presents your results and findings, link with existing literature and more.
=== Part e) ===
Finally, here you should present a critical assessment of the methods you have studied and link your results with the existing literature.
===== 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 "Computational Physics":"https://github.com/CompPhysics/ComputationalPhysics/blob/master/doc/Lectures/lectures2015.pdf" or alternative sources. For the solution of ordinary and partial differential equations using neural networks, the lectures by "Kristine Baluka Hein and included in the lectures of week 42":"https://compphysics.github.io/MachineLearning/doc/pub/week42/html/week42.html" 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 _Tensorflow/Keras_..
=== 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
!bt
\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*}
!et
or
!bt
\begin{equation*}
u_{xx} = u_t,
\end{equation*}
!et
with initial conditions, i.e., the conditions at $t=0$,
!bt
\begin{equation*}
u(x,0)= \sin{(\pi x)} \hspace{0.5cm} 0 < x < L,
\end{equation*}
!et
with $L=1$ the length of the $x$-region of interest. The
boundary conditions are
!bt
\begin{equation*}
u(0,t)= 0 \hspace{0.5cm} t \ge 0,
\end{equation*}
!et
and
!bt
\begin{equation*}
u(L,t)= 0 \hspace{0.5cm} t \ge 0.
\end{equation*}
!et
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
!bt
\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*}
!et
and
!bt
\begin{equation*}
u_{xx}\approx \frac{u(x+\Delta x,t)-2u(x,t)+u(x-\Delta x,t)}{\Delta x^2},
\end{equation*}
!et
or
!bt
\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*}
!et
Write down the algorithm and the equations you need to implement.
Find also the analytical solution to the problem.
=== 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.
=== 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.
=== Part d) Solving eigenvalue problems ===
Follow the discussion in the work of Yi *et al.* in the article from
"Computers and Mathematics with Applications 47, 1155 (2004)":"https://www.sciencedirect.com/science/article/pii/S0898122104901101", and
use your differential equation solver with neural networks, set up a
simple square, real and symmetric $6\times 6$ matrix and find the
eigenvalues. Compare with the solution from numerical diagonalization with standard eigenvalue solvers from linear algebra.
=== Part e) ===
Finally, present a critical assessment of the methods you have studied and discuss the potential for the solving differential equations and eigenvalue problems with machine learning methods.
===== Additonal (optional) exercise, adding 30 more points to final score =====
This exercise can be done independently of the other tasks. Here you
can also choose the data set you want to use. Furthermore, you can use
your codes from projects 1 and 2 as well as the codes here or simply use
libraries like _Scikit-Learn_, _Tensorflow_ or similar.
Your task is to perform an analysis of the bias-variance tradeoff
using at least three of the main sets of algorithms we have discussed in this
course. We will limit ourselves to a regression problem (fitting). However, feel free to venture into a classification problem.
You
are free to choose between bootstrap for resampling (recommended) or
cross-validation in order to get the best possible estimates. The
methods you could study are Linear Regression (OLS, Ridge and Lasso),
deep learning (feed forward neural networks and/or recurrent neural
networks), Ensemble methods (decision trees, bagging, random forests
and boosting) and support vector machines.
Study the bias-variance tradeoff for at least three of these sets of
algorithms for a data set of your choice as function of the complexity
of your model. Comment and discuss the results. Discuss the pros and
cons of the various methods. Are there some methods which provide both
low variance and low bias?
_Hint_: when you use different methods, pay attention to how you represent (and understand) the complexity of the model. For example, when using decision trees you may represent the complexity of your model by the depth of the tree.
===== Introduction to numerical projects =====
Here follows a brief recipe and recommendation on how to write a report for each
project.
* Give a short description of the nature of the problem and the eventual numerical methods you have used.
* 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.
* Include the source code of your program. Comment your program properly.
* If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.
* 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.
* 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.
* Try to give an interpretation of you results in your answers to the problems.
* 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.
* 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.
===== 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:
* Use Canvas to hand in your projects, log in at URL:"https://www.uio.no/english/services/it/education/canvas/" with your normal UiO username and password.
* Upload _only_ the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar 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.
* In your GitHub/GitLab or similar 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.
Finally,
we encourage you to collaborate. Optimal working groups consist of
2-3 students. You can then hand in a common report.
===== 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 _pip_ as
o pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow
For Python3, replace _pip_ with _pip3_.
See below for a discussion of _tensorflow_ and _scikit-learn_.
For OSX users we recommend also, after having installed Xcode, to install _brew_. Brew allows
for a seamless installation of additional software via for example
o brew install python3
For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution
you can use _pip_ as well and simply install Python as
o sudo apt-get install python3 (or python for python2.7)
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
o "Anaconda":"https://docs.anaconda.com/" 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 _conda_
o "Enthought canopy":"https://www.enthought.com/product/canopy/" is a Python distribution for scientific and analytic computing distribution and analysis environment, available for free and under a commercial license.
Popular software packages written in Python for ML are
* "Scikit-learn":"http://scikit-learn.org/stable/",
* "Tensorflow":"https://www.tensorflow.org/",
* "PyTorch":"http://pytorch.org/" and
* "Keras":"https://keras.io/".
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.
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
doconce clean
rm -rf *.pdf *.tex ipynb*.tar.gz *.html ._*.html *~ reveal.js Trash README.txt
+87
View File
@@ -0,0 +1,87 @@
#!/bin/sh
set -x
function system {
"$@"
if [ $? -ne 0 ]; then
echo "make.sh: unsuccessful command $@"
echo "abort!"
exit 1
fi
}
if [ $# -eq 0 ]; then
echo 'bash make.sh slides1|slides2'
exit 1
fi
name=$1
rm -f *.tar.gz
opt="--encoding=utf-8"
opt=
rm -f *.aux
# Plain HTML documents
html=${name}
system doconce format html $name --pygments_html_style=default --html_style=bloodish --html_links_in_new_window --html_output=$html $opt
system doconce split_html $html.html --method=space10
# Bootstrap style
html=${name}-bs
system doconce format html $name --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=$html $opt
system doconce split_html $html.html --method=split --pagination --nav_button=bottom
# IPython notebook
system doconce format ipynb $name $opt
# Ordinary plain LaTeX document
system doconce format pdflatex $name --print_latex_style=trac --latex_admon=paragraph $opt
system doconce ptex2tex $name envir=verbatim
# Add special packages
doconce subst "% Add user's preamble" "\g<1>\n\\usepackage{simplewick}" $name.tex
doconce replace 'section{' 'section*{' $name.tex
pdflatex -shell-escape $name
pdflatex -shell-escape $name
mv -f $name.pdf ${name}.pdf
cp $name.tex ${name}.tex
# Publish
dest=../../../../Projects/2022
if [ ! -d $dest/$name ]; then
mkdir $dest/$name
mkdir $dest/$name/pdf
mkdir $dest/$name/html
mkdir $dest/$name/ipynb
fi
cp ${name}*.tex $dest/$name/pdf
cp ${name}*.pdf $dest/$name/pdf
cp -r ${name}*.html ._${name}*.html $dest/$name/html
# Figures: cannot just copy link, need to physically copy the files
if [ -d fig-${name} ]; then
if [ ! -d $dest/$name/html/fig-$name ]; then
mkdir $dest/$name/html/fig-$name
fi
cp -r fig-${name}/* $dest/$name/html/fig-$name
fi
cp ${name}.ipynb $dest/$name/ipynb
ipynb_tarfile=ipynb-${name}-src.tar.gz
if [ ! -f ${ipynb_tarfile} ]; then
cat > README.txt <<EOF
This IPython notebook ${name}.ipynb does not require any additional
programs.
EOF
tar czf ${ipynb_tarfile} README.txt
fi
cp ${ipynb_tarfile} $dest/$name/ipynb