604 lines
32 KiB
HTML
604 lines
32 KiB
HTML
<!--
|
|
Automatically generated HTML file from DocOnce source
|
|
(https://github.com/hplgit/doconce/)
|
|
-->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
|
|
<meta name="description" content="Project 2 on Machine Learning, deadline November 5">
|
|
|
|
<title>Project 2 on Machine Learning, deadline November 5</title>
|
|
|
|
<!-- Bootstrap style: bootstrap -->
|
|
<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': 2,
|
|
'sections': [('Classification and Regression, from linear and logistic '
|
|
'regression to neural networks',
|
|
2,
|
|
None,
|
|
'___sec0'),
|
|
('Part a): Producing the data for the one-dimensional Ising '
|
|
'model',
|
|
3,
|
|
None,
|
|
'___sec1'),
|
|
('Part b): Estimating the coupling constant of the '
|
|
'one-dimensional Ising model using linear regression',
|
|
3,
|
|
None,
|
|
'___sec2'),
|
|
('Part c): Determine the phase of the two-dimensional Ising '
|
|
'model',
|
|
3,
|
|
None,
|
|
'___sec3'),
|
|
('Part d): Regression analysis of the one-dimensional Ising '
|
|
'model using neural networks',
|
|
3,
|
|
None,
|
|
'___sec4'),
|
|
('Part e): Classifying the Ising model phase using neural '
|
|
'networks',
|
|
3,
|
|
None,
|
|
'___sec5'),
|
|
('Part f) Critical evaluation of the various algorithms',
|
|
3,
|
|
None,
|
|
'___sec6'),
|
|
('Background literature', 2, None, '___sec7'),
|
|
('Introduction to numerical projects', 2, None, '___sec8'),
|
|
('Format for electronic delivery of report and programs',
|
|
2,
|
|
None,
|
|
'___sec9'),
|
|
('Software and needed installations', 2, None, '___sec10')]}
|
|
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="Project2-bs.html">Project 2 on Machine Learning, deadline November 5</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="#___sec0" style="font-size: 80%;"><b>Classification and Regression, from linear and logistic regression to neural networks</b></a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;"> Part a): Producing the data for the one-dimensional Ising model</a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;"> Part b): Estimating the coupling constant of the one-dimensional Ising model using linear regression</a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;"> Part c): Determine the phase of the two-dimensional Ising model</a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;"> Part d): Regression analysis of the one-dimensional Ising model using neural networks</a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;"> Part e): Classifying the Ising model phase using neural networks</a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;"> Part f) Critical evaluation of the various algorithms</a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;"><b>Background literature</b></a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;"><b>Introduction to numerical projects</b></a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;"><b>Format for electronic delivery of report and programs</b></a></li>
|
|
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;"><b>Software and needed installations</b></a></li>
|
|
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div> <!-- end of navigation bar -->
|
|
|
|
<div class="container">
|
|
|
|
<p> </p><p> </p><p> </p> <!-- add vertical space -->
|
|
|
|
<a name="part0000"></a>
|
|
<!-- ------------------- main content ---------------------- -->
|
|
|
|
|
|
|
|
<div class="jumbotron">
|
|
<center><h1>Project 2 on Machine Learning, deadline November 5</h1></center> <!-- document title -->
|
|
|
|
<p>
|
|
<!-- 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>
|
|
|
|
<p>
|
|
<!-- institution -->
|
|
|
|
<center><b>Department of Physics, University of Oslo, Norway</b></center>
|
|
<br>
|
|
<p>
|
|
<center><h4>Oct 9, 2018</h4></center> <!-- date -->
|
|
<br>
|
|
<p>
|
|
</div> <!-- end jumbotron -->
|
|
|
|
<h2 id="___sec0" class="anchor">Classification and Regression, from linear and logistic regression to neural networks </h2>
|
|
|
|
<p>
|
|
The main aim of this project is to study both classification and
|
|
regression problems, starting with the regression algorithms studied
|
|
in project 1. We will include logistic regresion for classification
|
|
problems and write our own multilayer perceptron code for studying
|
|
both regression and classification problems. The codes developed in
|
|
project 1, including bootstrap and/or cross-validation as well as the
|
|
computation of the mean-squared error and the R2 score function can
|
|
also be utilized (and included in logistic regression and the neural
|
|
network codes) in the present analysis.
|
|
|
|
<p>
|
|
We will use the so-called Ising model for our training data and will
|
|
focus on supervised training. We will follow closely the recent
|
|
article of <a href="https://arxiv.org/abs/1803.08823" target="_self">Mehta et al, arXiv
|
|
1803.08823</a>. This article stands
|
|
out as an excellent review on machine learning (ML) algorithms.
|
|
The added benefit is that each figure and
|
|
model presented in <a href="https://physics.bu.edu/~pankajm/MLnotebooks.html" target="_self">this article is accompanied by its jupyter
|
|
notebook</a>. This
|
|
means that we can start using these and compare with our own results.
|
|
They provide also the data set for the regression and classification
|
|
analysis that we will explore. In this sense, with their available
|
|
notebooks, it makes life easier since we can compare our own codes
|
|
with their codes.
|
|
|
|
<p>
|
|
With the abovementioned configurations we will determine, using first
|
|
various regression methods, the value of the coupling constant for the
|
|
energy of the one-dimensional Ising model. Thereafter, we will use the
|
|
two-dimensional data, but now computed at different temperatures, in
|
|
order to classify the phase of the Ising model. Below the critical
|
|
temperature, the system will be in a so-called ferromagnetic
|
|
phase. Close to the critical temperature, the final magnetization
|
|
becomes smaller and smaller in absolute value while above the critical
|
|
temperature, the net magnetization is zero. This classification case,
|
|
that is the two-dimensional Ising model, will be studied using
|
|
logistic regression and deep neural networks. The aim is to develop
|
|
your own logistic regression code for the classification of the phases
|
|
(this is a binary model) and your multilayer perceptron code for the
|
|
classification and regression case. You can compare your own results with those obtained
|
|
using <b>scikit-learn</b> or <b>tensorflow</b> or other Python packages such as <b>keras</b> or other.
|
|
|
|
<p>
|
|
Feel free to use the notebooks to benchmark your code. If you wish to
|
|
write your own C++ or Fortran program for say a multilayer neural network
|
|
model and a logistic regression model, please feel free to do so.
|
|
|
|
<h3 id="___sec1" class="anchor">Part a): Producing the data for the one-dimensional Ising model </h3>
|
|
|
|
<p>
|
|
The model we will employ in our studies is the so-called <a href="https://en.wikipedia.org/wiki/Ising_model" target="_self">Ising
|
|
model</a>. Together with
|
|
models like the <a href="https://en.wikipedia.org/wiki/Potts_model" target="_self">Potts
|
|
model</a> and similar
|
|
so-called lattice models, the Ising model has been widely studied in
|
|
mathematics (in statistics in particular), physics, <a href="https://journals.aps.org/pre/abstract/10.1103/PhysRevE.93.062402" target="_self">life
|
|
science</a>,
|
|
chemistry and even in the <a href="https://www.springer.com/gp/book/9781461420316" target="_self">social sciences in order to model social
|
|
behavior</a>. It is a
|
|
simple binary value system where the variables of the model (spins often in
|
|
physics) can take two values only, for example \( \pm 1 \) or \( 0 \) and \( 1 \).
|
|
The system exhibits a phase transition in two or higher dimensions and
|
|
the first person to find the analytical expressions for various
|
|
expectation values was the Norwegian chemist <a href="https://en.wikipedia.org/wiki/Lars_Onsager" target="_self">Lars
|
|
Onsager</a> (Nobel prize in
|
|
chemistry) after a tour de force mathematics exercise.
|
|
|
|
<p>
|
|
In our discussions here we will stay with a physicist's approach and
|
|
call the variables for spin. You could replace this with any other
|
|
type of binary variables, ranging from a two political parties to blue
|
|
and red spheres. In its simplest form we define the energy of the
|
|
system as
|
|
|
|
$$
|
|
\begin{equation*}
|
|
E=-J\sum_{< kl>}^{N}s_ks_l,
|
|
\end{equation*}
|
|
$$
|
|
|
|
with \( s_k=\pm 1 \), \( N \) is the total number of spins,
|
|
\( J \) is a coupling constant expressing the strength of the interaction
|
|
between neighboring spins.
|
|
|
|
<p>
|
|
The symbol \( < kl> \) indicates that we sum over nearest
|
|
neighbors only.
|
|
Notice that for \( J>0 \) it is energetically favorable for neighboring spins
|
|
to be aligned. This feature leads to, at low enough temperatures,
|
|
a cooperative phenomenon called spontaneous magnetization. That is,
|
|
through interactions between nearest neighbors, a given magnetic
|
|
moment can influence the alignment of spins that are separated
|
|
from the given spin by a macroscopic distance. These long range correlations
|
|
between spins are associated with a long-range order in which
|
|
the lattice has a net magnetization in the absence of a magnetic field.
|
|
|
|
<p>
|
|
We start by considering the one-dimensional Ising model with nearest neighbor interactions. This model does not exhibit any phase transition.
|
|
|
|
<p>
|
|
Consider the 1D Ising model with nearest-neighbor interactions
|
|
|
|
$$
|
|
\begin{equation*}
|
|
E[\hat{s}]=-J\sum_{j=1}^{N}s_{j}s_{j+1},
|
|
\end{equation*}
|
|
$$
|
|
|
|
<p>
|
|
on a chain of length \( N \) with so-called periodic boundary conditions and \( S_j=\pm 1 \) Ising spin variables.
|
|
In one dimension, this model has no phase transition at finite temperature.
|
|
|
|
<p>
|
|
In the Python code below we generate, with a coupling coefficient set to \( J=1 \), a large number of spin configurations say \( 10000 \) as shown in the code below.
|
|
It means that our data will be a set of \( i=1\ldots n \) points of the form
|
|
\( \{(E[\boldsymbol{s}^i],\boldsymbol{s}^i)\} \).
|
|
Our task is to find the value of \( J \) from the data set using linear regression.
|
|
|
|
<p>
|
|
Here is the Python code you need to generate the training data, see
|
|
also the <a href="https://physics.bu.edu/~pankajm/ML-Notebooks/HTML/NB_CVI-linreg_ising.html" target="_self">notebook of Mehta et
|
|
al</a>.
|
|
|
|
<p>
|
|
|
|
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
|
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
|
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">scipy.sparse</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">sp</span>
|
|
np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>seed(<span style="color: #666666">12</span>)
|
|
|
|
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">warnings</span>
|
|
<span style="color: #408080; font-style: italic">#Comment this to turn on warnings</span>
|
|
warnings<span style="color: #666666">.</span>filterwarnings(<span style="color: #BA2121">'ignore'</span>)
|
|
|
|
<span style="color: #408080; font-style: italic">### define Ising model aprams</span>
|
|
<span style="color: #408080; font-style: italic"># system size</span>
|
|
L<span style="color: #666666">=40</span>
|
|
|
|
<span style="color: #408080; font-style: italic"># create 10000 random Ising states</span>
|
|
states<span style="color: #666666">=</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>choice([<span style="color: #666666">-1</span>, <span style="color: #666666">1</span>], size<span style="color: #666666">=</span>(<span style="color: #666666">10000</span>,L))
|
|
|
|
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">ising_energies</span>(states,L):
|
|
<span style="color: #BA2121; font-style: italic">"""</span>
|
|
<span style="color: #BA2121; font-style: italic"> This function calculates the energies of the states in the nn Ising Hamiltonian</span>
|
|
<span style="color: #BA2121; font-style: italic"> """</span>
|
|
J<span style="color: #666666">=</span>np<span style="color: #666666">.</span>zeros((L,L),)
|
|
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(L):
|
|
J[i,(i<span style="color: #666666">+1</span>)<span style="color: #666666">%</span>L]<span style="color: #666666">-=1.0</span>
|
|
<span style="color: #408080; font-style: italic"># compute energies</span>
|
|
E <span style="color: #666666">=</span> np<span style="color: #666666">.</span>einsum(<span style="color: #BA2121">'...i,ij,...j->...'</span>,states,J,states)
|
|
|
|
<span style="color: #008000; font-weight: bold">return</span> E
|
|
<span style="color: #408080; font-style: italic"># calculate Ising energies</span>
|
|
energies<span style="color: #666666">=</span>ising_energies(states,L)
|
|
</pre></div>
|
|
<p>
|
|
We can now recast the problem as a linear regression model using our codes from project 1.
|
|
The way we are going to build our model mimicks the way we could think of finding say the gravitional constant for the graviational force between two planets.
|
|
In the absence of any prior knowledge, one sensible choice is the all-to-all Ising model
|
|
|
|
$$
|
|
E_\mathrm{model}[\boldsymbol{s}^i] = - \sum_{j=1}^N \sum_{k=1}^N J_{j,k}s_{j}^is_{k}^i.
|
|
$$
|
|
|
|
<p>
|
|
Here \( i \) represents a particular spin configuration (one of the possible \( n \) configurations we generated with the code above).
|
|
|
|
<p>
|
|
This model is uniquely defined by the non-local coupling strengths \( J_{jk} \) which we want to learn.
|
|
The model is linear in \( \mathbf{J} \) which makes it possible to use linear regression.
|
|
|
|
<p>
|
|
To apply linear regression, we recast this model in the form
|
|
$$
|
|
E_\mathrm{model}^i \equiv \mathbf{X}^i \cdot \mathbf{J},
|
|
$$
|
|
|
|
<p>
|
|
where the vectors \( \mathbf{X}^i \) represent all two-body interactions
|
|
\( \{s_{j}^is_{k}^i \}_{j,k=1}^N \), and the index \( i \) runs over the
|
|
samples in the data set. To make the analogy complete, we can also
|
|
represent the dot product by a single index \( p = \{j,k\} \),
|
|
i.e. \( \mathbf{X}^i \cdot \mathbf{J}=X^i_pJ_p \). Note that the
|
|
regression model does not include the minus sign, so we expect to
|
|
learn negative \( J \)'s.
|
|
|
|
<p>
|
|
With these preliminaries, we are now ready to reutilize our codes from project 1.
|
|
|
|
<h3 id="___sec2" class="anchor">Part b): Estimating the coupling constant of the one-dimensional Ising model using linear regression </h3>
|
|
|
|
<p>
|
|
We start with the one-dimensional Ising model and use the data we have
|
|
generated with \( J=1 \) in the previous point. Use linear regression,
|
|
Lasso and Ridge regression as done in project 1. You can compare your
|
|
results with those of <a href="https://physics.bu.edu/~pankajm/ML-Notebooks/HTML/NB_CVI-linreg_ising.html" target="_self">Mehta
|
|
et al.</a>.
|
|
Make sure it is the 1D data which is used.
|
|
|
|
<p>
|
|
Discuss the methods and how they perform in computing the coupling
|
|
constant \( J \) and include a bias-variance analysis using either
|
|
cross-validation or bootstrap. Discuss also the mean squared error and
|
|
the \( R2 \) score as measures to assess your model.
|
|
|
|
<p>
|
|
Give a critical analysis of your results.
|
|
|
|
<h3 id="___sec3" class="anchor">Part c): Determine the phase of the two-dimensional Ising model </h3>
|
|
|
|
<p>
|
|
We switch now to binary classification methods and use logistic
|
|
regression to define the phases of the Ising model. This means that we switch to the two-dimensional Ising model
|
|
and use the data sets generated by <a href="https://physics.bu.edu/~pankajm/ML-Review-Datasets/isingMC/" target="_self">Mehta et al</a>
|
|
These energies and their corresponding spin orientation configurations
|
|
represent then your data. We will use a fixed lattice of \( L\times L =
|
|
40 \times 40 \) spins in two dimensions. The link above contains data for several temperatures.
|
|
The theoretical critical temperature for a phase transition is \( T_C\approx 2.269 \) in units of energy.
|
|
However, for a finite lattice the results representing the critical temperature are slightly higher (\( T_C \approx 2.3 \)).
|
|
|
|
<p>
|
|
Our goal here, using logistic regression, is to train our model to
|
|
predict the phase of a sample given the spin configuration, whether it
|
|
represents a state above the critical temperature or below. The
|
|
configurations representing states below the critical temperature are
|
|
called ordered states (the spins tend to point in one direction,
|
|
resulting in a net magnetic moment) while those above the critical
|
|
temperature are called disordered. Since a finite lattice like this
|
|
does not exhibit a clear sign of a phase transition we will mainly
|
|
stay with either orderer or disoredered phases. You could include the
|
|
critical phase if you want.
|
|
|
|
<p>
|
|
Your aim here is thus to read in these data (use the examples from
|
|
<a href="https://physics.bu.edu/~pankajm/ML-Notebooks/HTML/NB_CVII-logreg_ising.html" target="_self">Mehta et
|
|
al</a>)
|
|
and write your own code for doing logistic regression, see the lecture
|
|
notes on <a href="https://compphysics.github.io/MachineLearning/doc/pub/LogReg/html/LogReg-bs.html" target="_self">logistic
|
|
regression</a>.
|
|
|
|
<p>
|
|
You should include either bootstrap or cross-validation in setting up
|
|
your model (as done in project 1) and compute the \( R2 \) score and the
|
|
mean-square error.
|
|
We will use both ordered and disordered states to train
|
|
the logistic regressor and, once the supervised training procedure is
|
|
complete, you should evaluate the performance of your classification model on
|
|
unseen ordered, disordered and possibly critical states.
|
|
|
|
<p>
|
|
In order to find the optimal parameters of your logistic regressor you should
|
|
include a gradient descent solver, as discussed in the <a href="https://compphysics.github.io/MachineLearning/doc/pub/Splines/html/Splines-bs.html" target="_self">gradient
|
|
descent
|
|
lectures</a>.
|
|
Since we don't have so many data points, you may just code the
|
|
standard gradient descent with a given learning rate, or even attempt
|
|
to use the Newton-Raphson method. Alternatively, it may be useful for
|
|
the next part on neural networks to implement a stochastic gradient
|
|
descent. For all gradient methods, you can use <b>scikit-learn</b>'s toolbox for
|
|
optimization methods instead of writing your own code.
|
|
|
|
<p>
|
|
The notebook of <a href="https://physics.bu.edu/~pankajm/ML-Notebooks/HTML/NB_CVII-logreg_ising.html" target="_self">Mehta et al</a> is highly recommended in order to benchmark your code and results.
|
|
|
|
<h3 id="___sec4" class="anchor">Part d): Regression analysis of the one-dimensional Ising model using neural networks </h3>
|
|
|
|
<p>
|
|
Your aim now, and this is the central part of this project, is to
|
|
write to your own multilayer perceptron model implementing the back
|
|
propagation algorithm discussed in the <a href="https://compphysics.github.io/MachineLearning/doc/pub/NeuralNet/html/NeuralNet-bs.html" target="_self">lecture
|
|
slides</a>. We
|
|
start with the regression case discussed in parts a) and b) but train
|
|
now the network to find the optimal weights and biases. You are free
|
|
to use the codes in the above lecture slides as starting points.
|
|
|
|
<p>
|
|
Train your network and compare the results with those from your linear regression code.
|
|
You can test your results against a similar code using _scikit_learn_ (see the examples in teh above lecture notes) or <b>tensorflow/keras</b>.
|
|
|
|
<p>
|
|
You should have the same elements as in the regression examples, including the \( R2 \) score, the MSE, and bootstrap or cross-validation.
|
|
|
|
<p>
|
|
A useful reference on the back progagation algorithm is <a href="http://neuralnetworksanddeeplearning.com/" target="_self">Nielsen's book</a>. It is an excellent read.
|
|
|
|
<h3 id="___sec5" class="anchor">Part e): Classifying the Ising model phase using neural networks </h3>
|
|
|
|
<p>
|
|
Finally, change now your cost function to the \( log \) cross-entropy classification cost function for the case discussed in part c). Train your network again and
|
|
compare the results with those from your logistic regression code i c).
|
|
Here again you can compare your results with those of <a href="https://physics.bu.edu/~pankajm/ML-Notebooks/HTML/NB_CIX-DNN_ising_TFlow.html" target="_self">Mehta et al</a>. There they used <b>tensorflow</b> to classify the phases.
|
|
|
|
<h3 id="___sec6" class="anchor">Part f) Critical evaluation of the various algorithms </h3>
|
|
|
|
<p>
|
|
After all these glorious calculations, you should now summarize the various algorithms and come with a critical evaluation of their pros and cons. Which algorithm works best for the regression case and which is best for the classification case. These codes will also be part of your final project 3, but now applied to other data sets.
|
|
|
|
<h2 id="___sec7" class="anchor">Background literature </h2>
|
|
|
|
<ol>
|
|
<li> The text of Michael Nielsen is highly recommended, see <a href="http://neuralnetworksanddeeplearning.com/" target="_self">Nielsen's book</a>. It is an excellent read.</li>
|
|
<li> The textbook of <a href="https://www.springer.com/gp/book/9780387848570" target="_self">Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer</a>, chapters 3 and 7 are the most relevant ones for the analysis here.</li>
|
|
<li> <a href="https://arxiv.org/abs/1803.08823" target="_self">Mehta et al, arXiv 1803.08823</a>, <em>A high-bias, low-variance introduction to Machine Learning for physicists</em>, ArXiv:1803.08823.</li>
|
|
</ol>
|
|
|
|
If you wish to read more about the Ising model and statistical physics here are three suggestions.
|
|
|
|
<ol>
|
|
<li> <a href="http://www.worldscientific.com/worldscibooks/10.1142/5660" target="_self">M. Plischke and B. Bergersen</a>, <em>Equilibrium Statistical Physics</em>, World Scientific, see chapters 5 and 6.</li>
|
|
<li> <a href="http://www.cambridge.org/no/academic/subjects/physics/computational-science-and-modelling/guide-monte-carlo-simulations-statistical-physics-4th-edition?format=HB" target="_self">D. P. Landau and K. Binder</a>, <em>A Guide to Monte Carlo Simulations in Statistical Physics</em>, Cambridge, see chapters 2,3 and 4.</li>
|
|
<li> <a href="https://global.oup.com/academic/product/monte-carlo-methods-in-statistical-physics-9780198517979?cc=no&lang=en&" target="_self">M. E. J. Newman and T. Barkema</a>, <em>Monte Carlo Methods in Statistical Physics</em>, Oxford, see chapters 3 and 4.</li>
|
|
</ol>
|
|
|
|
<h2 id="___sec8" class="anchor">Introduction to numerical projects </h2>
|
|
|
|
<p>
|
|
Here follows a brief recipe and recommendation on how to write a report for each
|
|
project.
|
|
|
|
<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="___sec9" 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:
|
|
|
|
<ul>
|
|
<li> Use Devilry to hand in your projects, log in at <a href="http://devilry.ifi.uio.no" target="_self"><tt>http://devilry.ifi.uio.no</tt></a> with your normal UiO username and password and choose either 'fysstk3155' or 'fysstk4155'. There you can load up the files within the deadline.</li>
|
|
<li> Upload <b>only</b> the report file! For the source code file(s) you have developed please provide us with your link to your github domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.</li>
|
|
<li> In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.</li>
|
|
<li> In this and all later projects, you should include tests (for example unit tests) of your code(s).</li>
|
|
<li> Comments from us on your projects, approval or not, corrections to be made etc can be found under your Devilry domain and are only visible to you and the teachers of the course.</li>
|
|
</ul>
|
|
|
|
Finally,
|
|
we encourage you to collaborate. Optimal working groups consist of
|
|
2-3 students. You can then hand in a common report.
|
|
|
|
<h2 id="___sec10" 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
|
|
|
|
<ol>
|
|
<li> pip install numpy scipy matplotlib ipython scikit-learn tensorflow sympy pandas pillow</li>
|
|
</ol>
|
|
|
|
For Python3, replace <b>pip</b> with <b>pip3</b>.
|
|
|
|
<p>
|
|
See below for a discussion of <b>tensorflow</b> and <b>scikit-learn</b>.
|
|
|
|
<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
|
|
|
|
<ol>
|
|
<li> brew install python3</li>
|
|
</ol>
|
|
|
|
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
|
|
|
|
<ol>
|
|
<li> sudo apt-get install python3 (or python for python2.7)</li>
|
|
</ol>
|
|
|
|
etc etc.
|
|
|
|
<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
|
|
|
|
<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>
|
|
|
|
Popular software packages written in Python for ML are
|
|
|
|
<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>
|
|
|
|
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="._Project2-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="http://..."><img width="250" align=right src="http://..."></a>
|
|
</footer>
|
|
-->
|
|
|
|
|
|
<center style="font-size:80%">
|
|
<!-- copyright --> © 1999-2018, "Data Analysis and Machine Learning FYS-STK3155/FYS4155":"http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license
|
|
</center>
|
|
|
|
|
|
</body>
|
|
</html>
|
|
|
|
|