1533 lines
74 KiB
HTML
1533 lines
74 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="Solving quantum mechanical problems with Machine Learning and Boltzmann machines">
|
|
|
|
<title>Solving quantum mechanical problems with Machine Learning and Boltzmann machines</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 { color: #8A0808; }
|
|
a { color: #8A0808; text-decoration:none; }
|
|
tt { font-family: "Courier New", Courier; }
|
|
/* pre style removed because it will interfer with pygments */
|
|
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}
|
|
.alert-text-small { font-size: 80%; }
|
|
.alert-text-large { font-size: 130%; }
|
|
.alert-text-normal { font-size: 90%; }
|
|
.alert {
|
|
padding:8px 35px 8px 14px; margin-bottom:18px;
|
|
text-shadow:0 1px 0 rgba(255,255,255,0.5);
|
|
border:1px solid #bababa;
|
|
border-radius: 4px;
|
|
-webkit-border-radius: 4px;
|
|
-moz-border-radius: 4px;
|
|
color: #555;
|
|
background-color: #f8f8f8;
|
|
background-position: 10px 5px;
|
|
background-repeat: no-repeat;
|
|
background-size: 38px;
|
|
padding-left: 55px;
|
|
width: 75%;
|
|
}
|
|
.alert-block {padding-top:14px; padding-bottom:14px}
|
|
.alert-block > p, .alert-block > ul {margin-bottom:1em}
|
|
.alert li {margin-top: 1em}
|
|
.alert-block p+p {margin-top:5px}
|
|
.alert-notice { background-image: url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_notice.png); }
|
|
.alert-summary { background-image:url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_summary.png); }
|
|
.alert-warning { background-image: url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_warning.png); }
|
|
.alert-question {background-image:url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_question.png); }
|
|
|
|
div { text-align: justify; text-justify: inter-word; }
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<!-- tocinfo
|
|
{'highest level': 2,
|
|
'sections': [('What is this talk about?', 2, None, '___sec0'),
|
|
('Why?', 2, None, '___sec1'),
|
|
('Overview', 2, None, '___sec2'),
|
|
('What are the Machine Learning calculations here based on?',
|
|
2,
|
|
None,
|
|
'___sec3'),
|
|
('A new world', 2, None, '___sec4'),
|
|
('Lots of room for creativity', 2, None, '___sec5'),
|
|
('Some members of the ML family', 2, None, '___sec6'),
|
|
('What are the basic ingredients?', 2, None, '___sec7'),
|
|
('What is Machine Learning?', 2, None, '___sec8'),
|
|
('Types of Machine Learning', 2, None, '___sec9'),
|
|
('References', 2, None, '___sec10'),
|
|
('Another interesting article', 2, None, '___sec11'),
|
|
('Just for fun illustration of scikit-learn: Hudson bay data',
|
|
2,
|
|
None,
|
|
'___sec12'),
|
|
('Hares and lynx in Hudson bay from 1900 to 1920',
|
|
2,
|
|
None,
|
|
'___sec13'),
|
|
('Linear regression in Python', 2, None, '___sec14'),
|
|
('Artificial neurons', 2, None, '___sec15'),
|
|
('A simple perceptron model', 2, None, '___sec16'),
|
|
('Neural network types', 2, None, '___sec17'),
|
|
('The system: two electrons in a harmonic oscillator trap in two '
|
|
'dimensions',
|
|
2,
|
|
None,
|
|
'___sec18'),
|
|
('Quantum Monte Carlo Motivation', 2, None, '___sec19'),
|
|
('Quantum Monte Carlo Motivation', 2, None, '___sec20'),
|
|
('Quantum Monte Carlo Motivation', 2, None, '___sec21'),
|
|
('Quantum Monte Carlo', 2, None, '___sec22'),
|
|
('The trial wave function', 2, None, '___sec23'),
|
|
('The correlation part of the wave function',
|
|
2,
|
|
None,
|
|
'___sec24'),
|
|
('Resulting ansatz', 2, None, '___sec25'),
|
|
('The VMC code', 2, None, '___sec26'),
|
|
('Technical aspect, improvements and how to define the cost '
|
|
'function',
|
|
2,
|
|
None,
|
|
'___sec27'),
|
|
('Energy derivatives', 2, None, '___sec28'),
|
|
('Derivatives of the local energy', 2, None, '___sec29'),
|
|
('How do we define our cost function?', 2, None, '___sec30'),
|
|
('Meet the variance and its derivatives', 2, None, '___sec31'),
|
|
('The variance defines the cost function', 2, None, '___sec32'),
|
|
('Boltzmann Machines', 2, None, '___sec33'),
|
|
('Some similarities and differences from DNNs',
|
|
2,
|
|
None,
|
|
'___sec34'),
|
|
('The structure of the RBM network', 2, None, '___sec35'),
|
|
('The network', 2, None, '___sec36'),
|
|
('Goals', 2, None, '___sec37'),
|
|
('Joint distribution and the Energy function',
|
|
2,
|
|
None,
|
|
'___sec38'),
|
|
('Network Elements', 2, None, '___sec39'),
|
|
('Defining different types of RBMs', 2, None, '___sec40'),
|
|
('More about RBMs', 2, None, '___sec41'),
|
|
('Sampling: Metropolis sampling', 2, None, '___sec42'),
|
|
('Sampling: Gibbs sampling', 2, None, '___sec43'),
|
|
('Gaussian RBM', 2, None, '___sec44'),
|
|
('Cost function', 2, None, '___sec45'),
|
|
('Optimization / Training', 2, None, '___sec46'),
|
|
('More on RBMs', 2, None, '___sec47'),
|
|
('Which sampling to use', 2, None, '___sec48'),
|
|
('RBMs for the quantum many body problem', 2, None, '___sec49'),
|
|
('Choose the right RBM', 2, None, '___sec50'),
|
|
('Representing the wave function', 2, None, '___sec51'),
|
|
('Choose the cost function', 2, None, '___sec52'),
|
|
('Running the codes', 2, None, '___sec53'),
|
|
('Energy as function of iterations, $N=2$ electrons',
|
|
2,
|
|
None,
|
|
'___sec54'),
|
|
('Energy as function of iterations, $N=6$ electrons',
|
|
2,
|
|
None,
|
|
'___sec55'),
|
|
('Conclusions and where do we stand', 2, None, '___sec56')]}
|
|
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>Solving quantum mechanical problems with Machine Learning and Boltzmann machines</h1></center> <!-- document title -->
|
|
|
|
<p>
|
|
<!-- author(s): Morten Hjorth-Jensen -->
|
|
|
|
<center>
|
|
<b>Morten Hjorth-Jensen</b>
|
|
</center>
|
|
|
|
<p>
|
|
<!-- institution -->
|
|
|
|
<center><b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University and Department of Physics, University of Oslo, Norway</b></center>
|
|
<br>
|
|
<p>
|
|
<center><h4>Jul 26, 2018 </h4></center> <!-- date -->
|
|
<br>
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec0">What is this talk about? </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
The main aim is to give you a short and pedestrian introduction to how we can use Machine Learning methods
|
|
to solve quantum mechanical many-body problems. And why this could be of interest.
|
|
|
|
<p>
|
|
The hope is that after this talk you have gotten the basic ideas to get you started. Peeping into <a href="https://github.com/mhjensenseminars/MachineLearningTalk" target="_blank"><tt>https://github.com/mhjensenseminars/MachineLearningTalk</tt></a>, you'll find a Jupyter notebook, slides, codes etc that will allow you to reproduce the simulations discussed here, and perhaps run your own very first calculations.
|
|
|
|
<p>
|
|
Furthermore, since we will also talk about Monte Carlo simulations, the exciting idea of Monte Carlo optimization and Machine Learning can be used to mesh strategies for reducing the curse of dimensionality.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec1">Why? </h2>
|
|
|
|
<p>
|
|
How can we avoid the dimensionality curse? Many possibilities
|
|
|
|
<ol>
|
|
<li> smarter basis functions</li>
|
|
<li> resummation of specific correlations</li>
|
|
<li> stochastic sampling of high-lying states (stochastic FCI, CC and soon SRG)</li>
|
|
<li> many more</li>
|
|
</ol>
|
|
|
|
Machine Learning and Quantum Computing hold also great promise in tackling the
|
|
ever increasing dimensionalities. Here we will focus on Machine Learning.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec2">Overview </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
|
|
<ul>
|
|
<li> Short intro to Machine Learning</li>
|
|
<li> Variational Monte Carlo (Markov Chain Monte Carlo, \( \mathrm{MC}^2 \)) and two-electron quantum dots, solving quantum mechanical problems in a stochastic way. It will serve as our motivation for switching to Machine Learning.</li>
|
|
<li> From Variational Monte Carlo to Boltzmann Machines and Machine Learning</li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec3">What are the Machine Learning calculations here based on? </h2>
|
|
|
|
<p>
|
|
This work is inspired by the idea of representing the wave function with
|
|
a restricted Boltzmann machine (RBM), presented recently by <a href="http://science.sciencemag.org/content/355/6325/602" target="_blank">G. Carleo and M. Troyer, Science <b>355</b>, Issue 6325, pp. 602-606 (2017)</a>. They
|
|
named such a wave function/network a <em>neural network quantum state</em> (NQS). In their article they apply it to the quantum mechanical
|
|
spin lattice systems of the Ising model and Heisenberg model, with
|
|
encouraging results.
|
|
|
|
<p>
|
|
Thanks to Vilde Flugsrud and Alfred Alocias Mariadason for many discussions and interpretations of the above paper.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec4">A new world </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
Machine learning (ML) is an extremely rich field, in spite of its young age. The
|
|
increases we have seen during the last three decades in computational
|
|
capabilities have been followed by developments of methods and
|
|
techniques for analyzing and handling large date sets, relying heavily
|
|
on statistics, computer science and mathematics. The field is rather
|
|
new and developing rapidly.
|
|
|
|
<p>
|
|
Popular software packages written in Python for ML are
|
|
|
|
<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>
|
|
|
|
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.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec5">Lots of room for creativity </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
Not all the
|
|
algorithms and methods can be given a rigorous mathematical
|
|
justification, opening up thereby for experimenting
|
|
and trial and error and thereby exciting new developments.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
A solid command of linear algebra, multivariate theory,
|
|
probability theory, statistical data analysis,
|
|
understanding errors and Monte Carlo methods is important in order to understand many of the
|
|
various algorithms and methods.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b><b>Job market, a personal statement</b>.</b>
|
|
<p>
|
|
A familiarity with ML is almost becoming a prerequisite for many of the most exciting employment
|
|
opportunities. Add quantum computing and there you are.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split -->
|
|
|
|
<h2 id="___sec6">Some members of the ML family </h2>
|
|
|
|
<p>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
|
|
<ol>
|
|
<li> Linear regression and its variants, in essence polynomial regression</li>
|
|
<li> Decision tree algorithms, from simpler to more complex ones like random forests</li>
|
|
<li> Nearest neighbors models</li>
|
|
<li> Bayesian statistics and regression</li>
|
|
<li> Support vector machines and finally various variants of</li>
|
|
<li> Artifical neural networks and deep learning</li>
|
|
<li> ....</li>
|
|
</ol>
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec7">What are the basic ingredients? </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
Almost every problem in ML and data science starts with the same ingredients:
|
|
|
|
<ul>
|
|
<li> The dataset \( \mathbf{x} \) (could be some observable quantity of the system we are studying)</li>
|
|
<li> A model which is a function of a set of parameters \( \mathbf{\alpha} \) that relates to the dataset, say a likelihood function \( p(\mathbf{x}\vert \mathbf{\alpha}) \) or just a simple model \( f(\mathbf{\alpha}) \)</li>
|
|
<li> A so-called <b>cost</b> function \( \mathcal{C} (\mathbf{x}, f(\mathbf{\alpha})) \) which allows us to decide how well our model represents the dataset.</li>
|
|
</ul>
|
|
|
|
We seek to minimize the function \( \mathcal{C} (\mathbf{x}, f(\mathbf{\alpha})) \) by finding the parameter values which minimize \( \mathcal{C} \). This leads to various minimization algorithms.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec8">What is Machine Learning? </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
Machine learning is the science of giving computers the ability to
|
|
learn without being explicitly programmed. The idea is that there
|
|
exist generic algorithms which can be used to find patterns in a broad
|
|
class of data sets without having to write code specifically for each
|
|
problem. The algorithm will build its own logic based on the data.
|
|
|
|
<p>
|
|
Machine learning is a subfield of computer science, and is closely
|
|
related to computational statistics. It evolved from the study of
|
|
pattern recognition in artificial intelligence (AI) research, and has
|
|
made contributions to AI tasks like computer vision, natural language
|
|
processing and speech recognition. It has also, especially in later
|
|
years, found applications in a wide variety of other areas, including
|
|
bioinformatics, economy, physics, finance and marketing.
|
|
|
|
<p>
|
|
You will notice however that many of the basic ideas discussed do come from Physics!
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec9">Types of Machine Learning </h2>
|
|
|
|
<p>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
The approaches to machine learning are many, but are often split into two main categories.
|
|
In <em>supervised learning</em> we know the answer to a problem,
|
|
and let the computer deduce the logic behind it. On the other hand, <em>unsupervised learning</em>
|
|
is a method for finding patterns and relationship in data sets without any prior knowledge of the system.
|
|
Some authours also operate with a third category, namely <em>reinforcement learning</em>. This is a paradigm
|
|
of learning inspired by behavioural psychology, where learning is achieved by trial-and-error,
|
|
solely from rewards and punishment.
|
|
|
|
<p>
|
|
Another way to categorize machine learning tasks is to consider the desired output of a system.
|
|
Some of the most common tasks are:
|
|
|
|
<ul>
|
|
<li> Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.</li>
|
|
<li> Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.</li>
|
|
<li> Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.</li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec10">References </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
|
|
<ul>
|
|
<li> An excellent reference, <a href="https://arxiv.org/abs/1803.08823" target="_blank">Mehta <em>et al.</em>, arXiv:1803.08823 and Physics Reports in press (2018)</a></li>
|
|
<li> A cute paper by <a href="https://journals.aps.org/prc/abstract/10.1103/PhysRevC.97.014306" target="_blank">Utama and Piekarewicz, Validating neural-network refinements of nuclear mass models, Phys. Rev. C 97, 014306 </a></li>
|
|
<li> <a href="https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.120.156001" target="_blank">Every issue of Physical Review Letters has now one or more articles on ML</a></li>
|
|
<li> <a href="https://github.com/CompPhysics/MachineLearning" target="_blank">Books and lectures notes</a></li>
|
|
<li> See also Metha and Schwab, arXiv.1410.3831, how to link Variational renormalization group theory with deep learning (recommended read)</li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec11">Another interesting article </h2>
|
|
|
|
<p>
|
|
Here we will use so-called <b>reduced Boltzmann Machines</b> to simulate quantum many-body problems. For Monte Carlo aficionados, there is a very close similarity with what are called <b>shadow wave functions</b>, see the work of <a href="https://journals.aps.org/pre/abstract/10.1103/PhysRevE.90.053304" target="_blank">Pederiva and Kalos and collaborators, Phys Rev. E 90, 053304 (2014)</a>.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec12">Just for fun illustration of scikit-learn: Hudson bay data </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
Most mammalian predators rely on a variety of prey, which complicates mathematical modeling; however, a few predators have become highly specialized and seek almost exclusively a single prey species. An example of this simplified predator-prey interaction is seen in Canadian northern forests, where the populations of the lynx and the snowshoe hare are intertwined in a life and death struggle.
|
|
|
|
<p>
|
|
One reason that this particular system has been so extensively studied is that the Hudson Bay company kept careful records of all furs from the early 1800s into the 1900s. The records for the furs collected by the Hudson Bay company showed distinct oscillations (approximately 12 year periods), suggesting that these species caused almost periodic fluctuations of each other's populations. The table here shows data from 1900 to 1920.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec13">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
|
|
|
|
<p>
|
|
<br /><br /><center><p><img src="figures/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec14">Linear regression in Python </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
<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">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
|
|
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sklearn</span>
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeRegressor
|
|
|
|
|
|
data <span style="color: #666666">=</span> np<span style="color: #666666">.</span>loadtxt(<span style="color: #BA2121">'src/Hudson_Bay.csv'</span>, delimiter<span style="color: #666666">=</span><span style="color: #BA2121">','</span>, skiprows<span style="color: #666666">=1</span>)
|
|
x <span style="color: #666666">=</span> data[:,<span style="color: #666666">0</span>]
|
|
y <span style="color: #666666">=</span> data[:,<span style="color: #666666">1</span>]
|
|
line <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">1900</span>,<span style="color: #666666">1920</span>,<span style="color: #666666">1000</span>,endpoint<span style="color: #666666">=</span><span style="color: #008000">False</span>)<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>)
|
|
reg <span style="color: #666666">=</span> DecisionTreeRegressor(min_samples_split<span style="color: #666666">=3</span>)<span style="color: #666666">.</span>fit(x<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>),y<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>))
|
|
plt<span style="color: #666666">.</span>plot(line, reg<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span><span style="color: #BA2121">"decision tree"</span>)
|
|
regline <span style="color: #666666">=</span> LinearRegression()<span style="color: #666666">.</span>fit(x<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>),y<span style="color: #666666">.</span>reshape(<span style="color: #666666">-1</span>,<span style="color: #666666">1</span>))
|
|
plt<span style="color: #666666">.</span>plot(line, regline<span style="color: #666666">.</span>predict(line), label<span style="color: #666666">=</span> <span style="color: #BA2121">"Linear Regression"</span>)
|
|
plt<span style="color: #666666">.</span>plot(x, y, label<span style="color: #666666">=</span> <span style="color: #BA2121">"Linear Regression"</span>)
|
|
plt<span style="color: #666666">.</span>show()
|
|
</pre></div>
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec15">Artificial neurons </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
|
|
<p>
|
|
The field of artificial neural networks has a long history of
|
|
development, and is closely connected with the advancement of computer
|
|
science and computers in general. A model of artificial neurons was
|
|
first developed by McCulloch and Pitts in 1943 to study signal
|
|
processing in the brain and has later been refined by others. The
|
|
general idea is to mimic neural networks in the human brain, which is
|
|
composed of billions of neurons that communicate with each other by
|
|
sending electrical signals. Each neuron accumulates its incoming
|
|
signals, which must exceed an activation threshold to yield an
|
|
output. If the threshold is not overcome, the neuron remains inactive,
|
|
i.e. has zero output.
|
|
|
|
<p>
|
|
This behaviour has inspired a simple mathematical model for an artificial neuron.
|
|
|
|
$$
|
|
y = f\left(\sum_{i=1}^n w_ix_i\right) = f(u)
|
|
$$
|
|
|
|
Here, the output \( y \) of the neuron is the value of its activation function, which have as input
|
|
a weighted sum of signals \( x_i, \dots ,x_n \) received by \( n \) other neurons.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec16">A simple perceptron model </h2>
|
|
|
|
<p>
|
|
<br /><br /><center><p><img src="figures/perceptron.png" align="bottom" width=700></p></center><br /><br />
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec17">Neural network types </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
An artificial neural network (NN), is a computational model that consists of layers of connected neurons, or <em>nodes</em>.
|
|
It is supposed to mimic a biological nervous system by letting each neuron interact with other neurons
|
|
by sending signals in the form of mathematical functions between layers.
|
|
A wide variety of different NNs have
|
|
been developed, but most of them consist of an input layer, an output layer and eventual layers in-between, called
|
|
<em>hidden layers</em>. All layers can contain an arbitrary number of nodes, and each connection between two nodes
|
|
is associated with a weight variable.
|
|
|
|
<p>
|
|
<br /><br /><center><p><img src="figures/dnn.png" align="bottom" width=500></p></center><br /><br />
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec18">The system: two electrons in a harmonic oscillator trap in two dimensions </h2>
|
|
|
|
<p>
|
|
The Hamiltonian of the quantum dot is given by
|
|
$$ \hat{H} = \hat{H}_0 + \hat{V},
|
|
$$
|
|
|
|
where \( \hat{H}_0 \) is the many-body HO Hamiltonian, and \( \hat{V} \) is the
|
|
inter-electron Coulomb interactions. In dimensionless units,
|
|
$$ \hat{V}= \sum_{i < j}^N \frac{1}{r_{ij}},
|
|
$$
|
|
|
|
with \( r_{ij}=\sqrt{\mathbf{r}_i^2 - \mathbf{r}_j^2} \).
|
|
|
|
<p>
|
|
This leads to the separable Hamiltonian, with the relative motion part given by (\( r_{ij}=r \))
|
|
$$
|
|
\hat{H}_r=-\nabla^2_r + \frac{1}{4}\omega^2r^2+ \frac{1}{r},
|
|
$$
|
|
|
|
plus a standard Harmonic Oscillator problem for the center-of-mass motion.
|
|
This system has analytical solutions in two and three dimensions (<a href="https://journals.aps.org/pra/abstract/10.1103/PhysRevA.48.3561" target="_blank">M. Taut 1993 and 1994</a>).
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec19">Quantum Monte Carlo Motivation </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
Given a hamiltonian \( H \) and a trial wave function \( \Psi_T \), the variational principle states that the expectation value of \( \langle H \rangle \), defined through
|
|
$$
|
|
\langle E \rangle =
|
|
\frac{\int d\boldsymbol{R}\Psi^{\ast}_T(\boldsymbol{R})H(\boldsymbol{R})\Psi_T(\boldsymbol{R})}
|
|
{\int d\boldsymbol{R}\Psi^{\ast}_T(\boldsymbol{R})\Psi_T(\boldsymbol{R})},
|
|
$$
|
|
|
|
is an upper bound to the ground state energy \( E_0 \) of the hamiltonian \( H \), that is
|
|
$$
|
|
E_0 \le \langle H \rangle .
|
|
$$
|
|
|
|
In general, the integrals involved in the calculation of various expectation values are multi-dimensional ones. Traditional integration methods such as the Gauss-Legendre will not be adequate for say the computation of the energy of a many-body system.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec20">Quantum Monte Carlo Motivation </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b>Basic steps.</b>
|
|
<p>
|
|
Choose a trial wave function
|
|
\( \psi_T(\boldsymbol{R}) \).
|
|
$$
|
|
P(\boldsymbol{R},\boldsymbol{\alpha})= \frac{\left|\psi_T(\boldsymbol{R},\boldsymbol{\alpha})\right|^2}{\int \left|\psi_T(\boldsymbol{R},\boldsymbol{\alpha})\right|^2d\boldsymbol{R}}.
|
|
$$
|
|
|
|
This is our model, or likelihood/probability distribution function (PDF). It depends on some variational parameters \( \boldsymbol{\alpha} \).
|
|
The approximation to the expectation value of the Hamiltonian is now
|
|
$$
|
|
\langle E[\boldsymbol{\alpha}] \rangle =
|
|
\frac{\int d\boldsymbol{R}\Psi^{\ast}_T(\boldsymbol{R},\boldsymbol{\alpha})H(\boldsymbol{R})\Psi_T(\boldsymbol{R},\boldsymbol{\alpha})}
|
|
{\int d\boldsymbol{R}\Psi^{\ast}_T(\boldsymbol{R},\boldsymbol{\alpha})\Psi_T(\boldsymbol{R},\boldsymbol{\alpha})}.
|
|
$$
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec21">Quantum Monte Carlo Motivation </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b>Define a new quantity.</b>
|
|
<p>
|
|
$$
|
|
E_L(\boldsymbol{R},\boldsymbol{\alpha})=\frac{1}{\psi_T(\boldsymbol{R},\boldsymbol{\alpha})}H\psi_T(\boldsymbol{R},\boldsymbol{\alpha}),
|
|
$$
|
|
|
|
called the local energy, which, together with our trial PDF yields
|
|
$$
|
|
E[\boldsymbol{\alpha}]=\int P(\boldsymbol{R})E_L(\boldsymbol{R},\boldsymbol{\alpha}) d\boldsymbol{R}\approx \frac{1}{N}\sum_{i=1}^NE_L(\boldsymbol{R_i},\boldsymbol{\alpha})
|
|
$$
|
|
|
|
with \( N \) being the number of Monte Carlo samples.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec22">Quantum Monte Carlo </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
The Algorithm for performing a variational Monte Carlo calculations runs thus as this
|
|
|
|
<ul>
|
|
<li> Initialisation: Fix the number of Monte Carlo steps. Choose an initial \( \boldsymbol{R} \) and variational parameters \( \alpha \) and calculate \( \left|\psi_T(\boldsymbol{R},\boldsymbol{\alpha})\right|^2 \).</li>
|
|
<li> Initialise the energy and the variance and start the Monte Carlo calculation by looping over trials.</li>
|
|
|
|
<ul>
|
|
<li> Calculate a trial position \( \boldsymbol{R}_p=\boldsymbol{R}+r*step \) where \( r \) is a random variable \( r \in [0,1] \).</li>
|
|
<li> Metropolis algorithm to accept or reject this move \( w = P(\boldsymbol{R}_p,\boldsymbol{\alpha})/P(\boldsymbol{R},\boldsymbol{\alpha}) \).</li>
|
|
<li> If the step is accepted, then we set \( \boldsymbol{R}=\boldsymbol{R}_p \).</li>
|
|
<li> Update averages</li>
|
|
</ul>
|
|
|
|
<li> Finish and compute final averages.</li>
|
|
</ul>
|
|
|
|
Observe that the jumping in space is governed by the variable <em>step</em>. This is often called brute-force sampling.
|
|
Need importance sampling to get more relevant sampling.
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec23">The trial wave function </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
We want to perform a Variational Monte Carlo calculation of the ground state of two electrons in a quantum dot well with different oscillator energies, assuming total spin \( S=0 \).
|
|
Our trial wave function has the following form
|
|
$$
|
|
\begin{equation}
|
|
\psi_{T}(\boldsymbol{r}_1,\boldsymbol{r}_2) =
|
|
C\exp{\left(-\alpha_1\omega(r_1^2+r_2^2)/2\right)}
|
|
\exp{\left(\frac{r_{12}}{(1+\alpha_2 r_{12})}\right)},
|
|
\label{eq:trial}
|
|
\end{equation}
|
|
$$
|
|
|
|
where the $\alpha$s represent our variational parameters, two in this case.
|
|
|
|
<p>
|
|
Why does the trial function look like this? How did we get there? <b>This will be our main motivation</b> for switching to
|
|
Machine Learning.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec24">The correlation part of the wave function </h2>
|
|
|
|
<p>
|
|
To find an ansatz for the correlated part of the wave function, it is useful to rewrite the two-particle
|
|
local energy in terms of the relative and center-of-mass motion.
|
|
Let us denote the distance between the two electrons as
|
|
\( r_{12} \). We omit the center-of-mass motion since we are only interested in the case when
|
|
\( r_{12} \rightarrow 0 \). The contribution from the center-of-mass (CoM) variable \( {\bf R}_{\mathrm{CoM}} \)
|
|
gives only a finite contribution.
|
|
We focus only on the terms that are relevant for \( r_{12} \) and for three dimensions. The relevant local energy becomes then
|
|
$$
|
|
\lim_{r_{12} \rightarrow 0}E_L(R)=
|
|
\frac{1}{{\cal R}_T(r_{12})}\left(2\frac{d^2}{dr_{ij}^2}+\frac{4}{r_{ij}}\frac{d}{dr_{ij}}+
|
|
\frac{2}{r_{ij}}-\frac{l(l+1)}{r_{ij}^2}+2E
|
|
\right){\cal R}_T(r_{12}) = 0.
|
|
$$
|
|
|
|
Set \( l=0 \) and we have the so-called <b>cusp</b> condition
|
|
$$
|
|
\frac{d {\cal R}_T(r_{12})}{dr_{12}} = -\frac{1}{2(l+1)}
|
|
{\cal R}_T(r_{12})\qquad r_{12}\to 0
|
|
$$
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec25">Resulting ansatz </h2>
|
|
The above results in
|
|
$$
|
|
{\cal R}_T \propto \exp{(r_{ij}/2)},
|
|
$$
|
|
|
|
for anti-parallel spins and
|
|
$$
|
|
{\cal R}_T \propto \exp{(r_{ij}/4)},
|
|
$$
|
|
|
|
for anti-parallel spins.
|
|
This is the so-called cusp condition for the relative motion, resulting in a minimal requirement
|
|
for the correlation part of the wave fuction.
|
|
For general systems containing more than say two electrons, we have this
|
|
condition for each electron pair \( ij \).
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec26">The VMC code </h2>
|
|
|
|
<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: #408080; font-style: italic"># Importing various packages</span>
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">math</span> <span style="color: #008000; font-weight: bold">import</span> exp, sqrt
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">random</span> <span style="color: #008000; font-weight: bold">import</span> random, seed
|
|
<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">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">mpl_toolkits.mplot3d</span> <span style="color: #008000; font-weight: bold">import</span> Axes3D
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> cm
|
|
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib.ticker</span> <span style="color: #008000; font-weight: bold">import</span> LinearLocator, FormatStrFormatter
|
|
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">sys</span>
|
|
|
|
<span style="color: #408080; font-style: italic">#Trial wave function for quantum dots in two dims</span>
|
|
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">WaveFunction</span>(r,alpha,beta):
|
|
r1 <span style="color: #666666">=</span> r[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>]<span style="color: #666666">**2</span> <span style="color: #666666">+</span> r[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>]<span style="color: #666666">**2</span>
|
|
r2 <span style="color: #666666">=</span> r[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>]<span style="color: #666666">**2</span> <span style="color: #666666">+</span> r[<span style="color: #666666">1</span>,<span style="color: #666666">1</span>]<span style="color: #666666">**2</span>
|
|
r12 <span style="color: #666666">=</span> sqrt((r[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>]<span style="color: #666666">-</span>r[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>])<span style="color: #666666">**2</span> <span style="color: #666666">+</span> (r[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>]<span style="color: #666666">-</span>r[<span style="color: #666666">1</span>,<span style="color: #666666">1</span>])<span style="color: #666666">**2</span>)
|
|
deno <span style="color: #666666">=</span> r12<span style="color: #666666">/</span>(<span style="color: #666666">1+</span>beta<span style="color: #666666">*</span>r12)
|
|
<span style="color: #008000; font-weight: bold">return</span> exp(<span style="color: #666666">-0.5*</span>alpha<span style="color: #666666">*</span>(r1<span style="color: #666666">+</span>r2)<span style="color: #666666">+</span>deno)
|
|
|
|
<span style="color: #408080; font-style: italic">#Local energy for quantum dots in two dims, using analytical local energy</span>
|
|
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">LocalEnergy</span>(r,alpha,beta):
|
|
|
|
r1 <span style="color: #666666">=</span> (r[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>]<span style="color: #666666">**2</span> <span style="color: #666666">+</span> r[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>]<span style="color: #666666">**2</span>)
|
|
r2 <span style="color: #666666">=</span> (r[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>]<span style="color: #666666">**2</span> <span style="color: #666666">+</span> r[<span style="color: #666666">1</span>,<span style="color: #666666">1</span>]<span style="color: #666666">**2</span>)
|
|
r12 <span style="color: #666666">=</span> sqrt((r[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>]<span style="color: #666666">-</span>r[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>])<span style="color: #666666">**2</span> <span style="color: #666666">+</span> (r[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>]<span style="color: #666666">-</span>r[<span style="color: #666666">1</span>,<span style="color: #666666">1</span>])<span style="color: #666666">**2</span>)
|
|
deno <span style="color: #666666">=</span> <span style="color: #666666">1.0/</span>(<span style="color: #666666">1+</span>beta<span style="color: #666666">*</span>r12)
|
|
deno2 <span style="color: #666666">=</span> deno<span style="color: #666666">*</span>deno
|
|
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">0.5*</span>(<span style="color: #666666">1-</span>alpha<span style="color: #666666">*</span>alpha)<span style="color: #666666">*</span>(r1 <span style="color: #666666">+</span> r2) <span style="color: #666666">+2.0*</span>alpha <span style="color: #666666">+</span> <span style="color: #666666">1.0/</span>r12<span style="color: #666666">+</span>deno2<span style="color: #666666">*</span>(alpha<span style="color: #666666">*</span>r12<span style="color: #666666">-</span>deno2<span style="color: #666666">+2*</span>beta<span style="color: #666666">*</span>deno<span style="color: #666666">-1.0/</span>r12)
|
|
|
|
<span style="color: #408080; font-style: italic"># The Monte Carlo sampling with the Metropolis algo</span>
|
|
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">MonteCarloSampling</span>():
|
|
|
|
NumberMCcycles<span style="color: #666666">=</span> <span style="color: #666666">100000</span>
|
|
StepSize <span style="color: #666666">=</span> <span style="color: #666666">1.0</span>
|
|
<span style="color: #408080; font-style: italic"># positions</span>
|
|
PositionOld <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((NumberParticles,Dimension), np<span style="color: #666666">.</span>double)
|
|
PositionNew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((NumberParticles,Dimension), np<span style="color: #666666">.</span>double)
|
|
<span style="color: #408080; font-style: italic"># seed for rng generator</span>
|
|
seed()
|
|
<span style="color: #408080; font-style: italic"># start variational parameter</span>
|
|
alpha <span style="color: #666666">=</span> <span style="color: #666666">0.9</span>
|
|
<span style="color: #008000; font-weight: bold">for</span> ia <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(MaxVariations):
|
|
alpha <span style="color: #666666">+=</span> <span style="color: #666666">.025</span>
|
|
AlphaValues[ia] <span style="color: #666666">=</span> alpha
|
|
beta <span style="color: #666666">=</span> <span style="color: #666666">0.2</span>
|
|
<span style="color: #008000; font-weight: bold">for</span> jb <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(MaxVariations):
|
|
beta <span style="color: #666666">+=</span> <span style="color: #666666">.01</span>
|
|
BetaValues[jb] <span style="color: #666666">=</span> beta
|
|
energy <span style="color: #666666">=</span> energy2 <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
|
DeltaE <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
|
<span style="color: #408080; font-style: italic">#Initial position</span>
|
|
<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>(NumberParticles):
|
|
<span style="color: #008000; font-weight: bold">for</span> j <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(Dimension):
|
|
PositionOld[i,j] <span style="color: #666666">=</span> StepSize <span style="color: #666666">*</span> (random() <span style="color: #666666">-</span> <span style="color: #666666">.5</span>)
|
|
wfold <span style="color: #666666">=</span> WaveFunction(PositionOld,alpha,beta)
|
|
|
|
<span style="color: #408080; font-style: italic">#Loop over MC MCcycles</span>
|
|
<span style="color: #008000; font-weight: bold">for</span> MCcycle <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(NumberMCcycles):
|
|
<span style="color: #408080; font-style: italic">#Trial position</span>
|
|
<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>(NumberParticles):
|
|
<span style="color: #008000; font-weight: bold">for</span> j <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(Dimension):
|
|
PositionNew[i,j] <span style="color: #666666">=</span> PositionOld[i,j] <span style="color: #666666">+</span> StepSize <span style="color: #666666">*</span> (random() <span style="color: #666666">-</span> <span style="color: #666666">.5</span>)
|
|
wfnew <span style="color: #666666">=</span> WaveFunction(PositionNew,alpha,beta)
|
|
|
|
<span style="color: #408080; font-style: italic">#Metropolis test to see whether we accept the move</span>
|
|
<span style="color: #008000; font-weight: bold">if</span> random() <span style="color: #666666"><</span> wfnew<span style="color: #666666">**2</span> <span style="color: #666666">/</span> wfold<span style="color: #666666">**2</span>:
|
|
PositionOld <span style="color: #666666">=</span> PositionNew<span style="color: #666666">.</span>copy()
|
|
wfold <span style="color: #666666">=</span> wfnew
|
|
DeltaE <span style="color: #666666">=</span> LocalEnergy(PositionOld,alpha,beta)
|
|
energy <span style="color: #666666">+=</span> DeltaE
|
|
energy2 <span style="color: #666666">+=</span> DeltaE<span style="color: #666666">**2</span>
|
|
|
|
<span style="color: #408080; font-style: italic">#We calculate mean, variance and error ...</span>
|
|
energy <span style="color: #666666">/=</span> NumberMCcycles
|
|
energy2 <span style="color: #666666">/=</span> NumberMCcycles
|
|
variance <span style="color: #666666">=</span> energy2 <span style="color: #666666">-</span> energy<span style="color: #666666">**2</span>
|
|
error <span style="color: #666666">=</span> sqrt(variance<span style="color: #666666">/</span>NumberMCcycles)
|
|
Energies[ia,jb] <span style="color: #666666">=</span> energy
|
|
<span style="color: #008000; font-weight: bold">return</span> Energies, AlphaValues, BetaValues
|
|
|
|
|
|
<span style="color: #408080; font-style: italic">#Here starts the main program with variable declarations</span>
|
|
NumberParticles <span style="color: #666666">=</span> <span style="color: #666666">2</span>
|
|
Dimension <span style="color: #666666">=</span> <span style="color: #666666">2</span>
|
|
MaxVariations <span style="color: #666666">=</span> <span style="color: #666666">10</span>
|
|
Energies <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((MaxVariations,MaxVariations))
|
|
AlphaValues <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(MaxVariations)
|
|
BetaValues <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(MaxVariations)
|
|
(Energies, AlphaValues, BetaValues) <span style="color: #666666">=</span> MonteCarloSampling()
|
|
|
|
<span style="color: #408080; font-style: italic"># Prepare for plots</span>
|
|
fig <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>figure()
|
|
ax <span style="color: #666666">=</span> fig<span style="color: #666666">.</span>gca(projection<span style="color: #666666">=</span><span style="color: #BA2121">'3d'</span>)
|
|
<span style="color: #408080; font-style: italic"># Plot the surface.</span>
|
|
X, Y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>meshgrid(AlphaValues, BetaValues)
|
|
surf <span style="color: #666666">=</span> ax<span style="color: #666666">.</span>plot_surface(X, Y, Energies,cmap<span style="color: #666666">=</span>cm<span style="color: #666666">.</span>coolwarm,linewidth<span style="color: #666666">=0</span>, antialiased<span style="color: #666666">=</span><span style="color: #008000">False</span>)
|
|
<span style="color: #408080; font-style: italic"># Customize the z axis.</span>
|
|
zmin <span style="color: #666666">=</span> np<span style="color: #666666">.</span>matrix(Energies)<span style="color: #666666">.</span>min()
|
|
zmax <span style="color: #666666">=</span> np<span style="color: #666666">.</span>matrix(Energies)<span style="color: #666666">.</span>max()
|
|
ax<span style="color: #666666">.</span>set_zlim(zmin, zmax)
|
|
ax<span style="color: #666666">.</span>set_xlabel(<span style="color: #BA2121">r'$\alpha$'</span>)
|
|
ax<span style="color: #666666">.</span>set_ylabel(<span style="color: #BA2121">r'$\beta$'</span>)
|
|
ax<span style="color: #666666">.</span>set_zlabel(<span style="color: #BA2121">r'$\langle E \rangle$'</span>)
|
|
ax<span style="color: #666666">.</span>zaxis<span style="color: #666666">.</span>set_major_locator(LinearLocator(<span style="color: #666666">10</span>))
|
|
ax<span style="color: #666666">.</span>zaxis<span style="color: #666666">.</span>set_major_formatter(FormatStrFormatter(<span style="color: #BA2121">'</span><span style="color: #BB6688; font-weight: bold">%.02f</span><span style="color: #BA2121">'</span>))
|
|
<span style="color: #408080; font-style: italic"># Add a color bar which maps values to colors.</span>
|
|
fig<span style="color: #666666">.</span>colorbar(surf, shrink<span style="color: #666666">=0.5</span>, aspect<span style="color: #666666">=5</span>)
|
|
plt<span style="color: #666666">.</span>show()
|
|
</pre></div>
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec27">Technical aspect, improvements and how to define the cost function </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
|
|
<p>
|
|
<b>The above procedure is not the smartest one</b>. Looping over all variational parameters becomes expensive.
|
|
Also, we don't use importance sampling and optimizations of the standard deviation (blocking, bootstrap, jackknife).
|
|
Such codes are included in the above Github address.
|
|
|
|
<p>
|
|
We can also be smarter and use minimization methods to find the <b>optimal</b> variational parameters with fewer Monte Carlo cycles and then
|
|
fire up our heavy artillery.
|
|
|
|
<p>
|
|
One way to achieve this is to minimize the energy as function of the variational parameters.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec28">Energy derivatives </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
To find the derivatives of the local energy expectation value as function of the variational parameters, we can use the chain rule and the hermiticity of the Hamiltonian.
|
|
|
|
<p>
|
|
Let us define
|
|
$$
|
|
\bar{E}_{\alpha_i}=\frac{d\langle E_L\rangle}{d\alpha_i}.
|
|
$$
|
|
|
|
as the derivative of the energy with respect to the variational parameter \( \alpha_i \)
|
|
We define also the derivative of the trial function (skipping the subindex \( T \)) as
|
|
$$
|
|
\bar{\Psi}_{i}=\frac{d\Psi}{d\alpha_i}.
|
|
$$
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec29">Derivatives of the local energy </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
The elements of the gradient of the local energy are then (using the chain rule and the hermiticity of the Hamiltonian)
|
|
$$
|
|
\bar{E}_{i}= 2\left( \langle \frac{\bar{\Psi}_{i}}{\Psi}E_L\rangle -\langle \frac{\bar{\Psi}_{i}}{\Psi}\rangle\langle E_L \rangle\right).
|
|
$$
|
|
|
|
From a computational point of view it means that you need to compute the expectation values of
|
|
$$
|
|
\langle \frac{\bar{\Psi}_{i}}{\Psi}E_L\rangle,
|
|
$$
|
|
|
|
and
|
|
$$
|
|
\langle \frac{\bar{\Psi}_{i}}{\Psi}\rangle\langle E_L\rangle
|
|
$$
|
|
|
|
These integrals are evaluted using MC intergration (with all its possible error sources).
|
|
We can then use methods like stochastic gradient or other minimization methods to find the optimal variational parameters (I don't discuss this topic here, but these methods are very important in ML).
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec30">How do we define our cost function? </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
We have a model, our likelihood function.
|
|
|
|
<p>
|
|
How should we define the cost function?
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec31">Meet the variance and its derivatives </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b>Why the variance?</b>
|
|
<p>
|
|
Suppose the trial function (our model) is the exact wave function. The action of the hamiltionan
|
|
on the wave function
|
|
$$
|
|
H\Psi = \mathrm{constant}\times \Psi,
|
|
$$
|
|
|
|
The integral which defines various
|
|
expectation values involving moments of the hamiltonian becomes then
|
|
$$
|
|
\langle E^n \rangle = \langle H^n \rangle =
|
|
\frac{\int d\boldsymbol{R}\Psi^{\ast}(\boldsymbol{R})H^n(\boldsymbol{R})\Psi(\boldsymbol{R})}
|
|
{\int d\boldsymbol{R}\Psi^{\ast}(\boldsymbol{R})\Psi(\boldsymbol{R})}=
|
|
\mathrm{constant}\times\frac{\int d\boldsymbol{R}\Psi^{\ast}(\boldsymbol{R})\Psi(\boldsymbol{R})}
|
|
{\int d\boldsymbol{R}\Psi^{\ast}(\boldsymbol{R})\Psi(\boldsymbol{R})}=\mathrm{constant}.
|
|
$$
|
|
|
|
<b>This gives an important information: If I want the variance, the exact wave function leads to zero variance!</b>
|
|
The variance is defined as
|
|
$$
|
|
\sigma_E = \langle E^2\rangle - \langle E\rangle^2.
|
|
$$
|
|
|
|
Variation is then performed by minimizing both the energy and the variance.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec32">The variance defines the cost function </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
We can then take the derivatives of
|
|
$$
|
|
\sigma_E = \langle E^2\rangle - \langle E\rangle^2,
|
|
$$
|
|
|
|
with respect to the variational parameters. The derivatives of the variance can then be used to defined the
|
|
so-called Hessian matrix, which in turn allows us to use minimization methods like Newton's method or
|
|
standard gradient methods.
|
|
|
|
<p>
|
|
This leads to however a more complicated expression, with obvious errors when evaluating integrals by Monte Carlo integration. Less used, see however <a href="https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.94.150201" target="_blank">Filippi and Umrigar</a>. The expression becomes complicated
|
|
$$
|
|
\bar{E}_{ij} = 2\left[ \langle (\frac{\bar{\Psi}_{ij}}{\Psi}+\frac{\bar{\Psi}_{j}}{\Psi}\frac{\bar{\Psi}_{i}}{\Psi})(E_L-\langle E\rangle)\rangle -\langle \frac{\bar{\Psi}_{i}}{\Psi}\rangle\bar{E}_j-\langle \frac{\bar{\Psi}_{j}}{\Psi}\rangle\bar{E}_i\right] +\langle \frac{\bar{\Psi}_{i}}{\Psi}E_L{_j}\rangle +\langle \frac{\bar{\Psi}_{j}}{\Psi}E_L{_i}\rangle -\langle \frac{\bar{\Psi}_{i}}{\Psi}\rangle\langle E_L{_j}\rangle \langle \frac{\bar{\Psi}_{j}}{\Psi}\rangle\langle E_L{_i}\rangle.
|
|
$$
|
|
|
|
<p>
|
|
Evaluating the cost function means having to evaluate the above second derivative of the energy.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec33">Boltzmann Machines </h2>
|
|
|
|
<p>
|
|
Why use a generative model rather than the more well known discriminative deep neural networks (DNN)?
|
|
|
|
<ul>
|
|
<li> Discriminitave methods have several limitations: They are mainly supervised learning methods, thus requiring labeled data. And there are tasks they cannot accomplish, like drawing new examples from an unknown probability distribution.</li>
|
|
<li> A generative model can learn to represent and sample from a probability distribution. The core idea is to learn a parametric model of the probability distribution from which the training data was drawn. As an example
|
|
|
|
<ol type="a"></li>
|
|
<li> A model for images could learn to draw new examples of cats and dogs, given a training dataset of images of cats and dogs.</li>
|
|
<li> Generate a sample of an ordered or disordered Ising model phase, having been given samples of such phases.</li>
|
|
<li> Model the trial wave function for Monte Carlo calculations</li>
|
|
</ol>
|
|
|
|
</ul>
|
|
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec34">Some similarities and differences from DNNs </h2>
|
|
|
|
<ol>
|
|
<li> Both use gradient-descent based learning procedures for minimizing cost functions</li>
|
|
<li> Energy based models don't use backpropagation and automatic differentiation for computing gradients, instead turning to Markov Chain Monte Carlo methods.</li>
|
|
<li> DNNs often have several hidden layers. A restricted Boltzmann machine has only one hidden layer, however several RBMs can be stacked to make up Deep Belief Networks, of which they constitute the building blocks.</li>
|
|
</ol>
|
|
|
|
History: The RBM was developed by amongst others Geoffrey Hinton, called by some the "Godfather of Deep Learning", working with the University of Toronto and Google.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec35">The structure of the RBM network </h2>
|
|
|
|
<p>
|
|
<br /><br /><center><p><img src="figures/RBM.png" align="bottom" width=800></p></center><br /><br />
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec36">The network </h2>
|
|
|
|
<p>
|
|
<b>The network layers</b>:
|
|
|
|
<ol>
|
|
<li> A function \( \mathbf{x} \) that represents the visible layer, a vector of \( M \) elements (nodes). This layer represents both what the RBM might be given as training input, and what we want it to be able to reconstruct. This might for example be the pixels of an image, the spin values of the Ising model, or coefficients representing speech.</li>
|
|
<li> The function \( \mathbf{h} \) represents the hidden, or latent, layer. A vector of \( N \) elements (nodes). Also called "feature detectors".</li>
|
|
</ol>
|
|
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec37">Goals </h2>
|
|
|
|
<p>
|
|
The goal of the hidden layer is to increase the model's expressive power. We encode complex interactions between visible variables by introducing additional, hidden variables that interact with visible degrees of freedom in a simple manner, yet still reproduce the complex correlations between visible degrees in the data once marginalized over (integrated out).
|
|
|
|
<p>
|
|
Examples of this trick being employed in physics:
|
|
|
|
<ol>
|
|
<li> The Hubbard-Stratonovich transformation</li>
|
|
<li> The introduction of ghost fields in gauge theory</li>
|
|
<li> Shadow wave functions in Quantum Monte Carlo simulations</li>
|
|
</ol>
|
|
|
|
<b>The network parameters, to be optimized/learned</b>:
|
|
|
|
<ol>
|
|
<li> \( \mathbf{a} \) represents the visible bias, a vector of same length as \( \mathbf{x} \).</li>
|
|
<li> \( \mathbf{b} \) represents the hidden bias, a vector of same lenght as \( \mathbf{h} \).</li>
|
|
<li> \( W \) represents the interaction weights, a matrix of size \( M\times N \).</li>
|
|
</ol>
|
|
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec38">Joint distribution and the Energy function </h2>
|
|
The restricted Boltzmann machine is described by a Bolztmann distribution
|
|
$$
|
|
\begin{align}
|
|
P_{rbm}(\mathbf{x},\mathbf{h}) = \frac{1}{Z} e^{-\frac{1}{T_0}E(\mathbf{x},\mathbf{h})},
|
|
\label{_auto1}
|
|
\end{align}
|
|
$$
|
|
|
|
where \( Z \) is the normalization constant or partition function, defined as
|
|
$$
|
|
\begin{align}
|
|
Z = \int \int e^{-\frac{1}{T_0}E(\mathbf{x},\mathbf{h})} d\mathbf{x} d\mathbf{h}.
|
|
\label{_auto2}
|
|
\end{align}
|
|
$$
|
|
|
|
It is common to ignore \( T_0 \) by setting it to one.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec39">Network Elements </h2>
|
|
|
|
<p>
|
|
The function \( E(\mathbf{x},\mathbf{h}) \) gives the <b>energy</b> of a
|
|
configuration (pair of vectors) \( (\mathbf{x}, \mathbf{h}) \). The lower
|
|
the energy of a configuration, the higher the probability of it. This
|
|
function also depends on the parameters \( \mathbf{a} \), \( \mathbf{b} \) and
|
|
\( W \). Thus, when we adjust them during the learning procedure, we are
|
|
adjusting the energy function to best fit our problem.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec40">Defining different types of RBMs </h2>
|
|
There are different variants of RBMs, and the differences lie in the types of visible and hidden units we choose as well as in the implementation of the energy function \( E(\mathbf{x},\mathbf{h}) \).
|
|
|
|
<p>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b>Binary-Binary RBM:</b>
|
|
<p>
|
|
|
|
<p>
|
|
RBMs were first developed using binary units in both the visible and hidden layer. The corresponding energy function is defined as follows:
|
|
$$
|
|
\begin{align}
|
|
E(\mathbf{x}, \mathbf{h}) = - \sum_i^M x_i a_i- \sum_j^N b_j h_j - \sum_{i,j}^{M,N} x_i w_{ij} h_j,
|
|
\label{_auto3}
|
|
\end{align}
|
|
$$
|
|
|
|
where the binary values taken on by the nodes are most commonly 0 and 1.
|
|
</div>
|
|
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b>Gaussian-Binary RBM:</b>
|
|
<p>
|
|
|
|
<p>
|
|
Another varient is the RBM where the visible units are Gaussian while the hidden units remain binary:
|
|
$$
|
|
\begin{align}
|
|
E(\mathbf{x}, \mathbf{h}) = \sum_i^M \frac{(x_i - a_i)^2}{2\sigma_i^2} - \sum_j^N b_j h_j - \sum_{i,j}^{M,N} \frac{x_i w_{ij} h_j}{\sigma_i^2}.
|
|
\label{_auto4}
|
|
\end{align}
|
|
$$
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec41">More about RBMs </h2>
|
|
|
|
<ol>
|
|
<li> Useful when we model continuous data (i.e., we wish \( \mathbf{x} \) to be continuous)</li>
|
|
<li> Requires a smaller learning rate, since there's no upper bound to the value a component might take in the reconstruction</li>
|
|
</ol>
|
|
|
|
Other types of units include:
|
|
|
|
<ol>
|
|
<li> Softmax and multinomial units</li>
|
|
<li> Gaussian visible and hidden units</li>
|
|
<li> Binomial units</li>
|
|
<li> Rectified linear units</li>
|
|
</ol>
|
|
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec42">Sampling: Metropolis sampling </h2>
|
|
In order to sample from the RBM probability distribution it is common to use Markov Chain Monte Carlo (MCMC) algorithms such as Metropolis-Hastings or Gibbs sampling.
|
|
|
|
<p>
|
|
Metropolis sampling starts by suggesting a new configuration \( \boldsymbol{x}^{k+1} \). In the brute force method this is done by some random change of the visible units. The new configuration is then accepted with the acceptance probability
|
|
$$
|
|
\begin{align}
|
|
A(\boldsymbol{x}^k \rightarrow \boldsymbol{x}^{k+1}) = \text{min} (1, \frac{P(\boldsymbol{x}^{k+1})}{P(\boldsymbol{x}^k)}),
|
|
\label{_auto5}
|
|
\end{align}
|
|
$$
|
|
|
|
where we need the marginalized probability
|
|
$$
|
|
\begin{align}
|
|
P(\boldsymbol{x}) &= \sum_\mathbf{h} P_{rbm}(\mathbf{x}, \mathbf{h})
|
|
\label{_auto6}\\
|
|
&= \frac{1}{Z}\sum_\mathbf{h} e^{-E(\mathbf{x}, \mathbf{h})}.
|
|
\label{_auto7}
|
|
\end{align}
|
|
$$
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec43">Sampling: Gibbs sampling </h2>
|
|
|
|
<p>
|
|
In this method we sample from the joint probability \( P_{rbm} (\mathbf{x}, \mathbf{h}) \) by way of a two step sampling process. We alternately update the visible and hidden units.
|
|
New samples are generated according to the conditional probabilities \( P(x_i|\mathbf{h}) \) and \( P(h_j|\mathbf{x}) \) respectively and accepted with the probability of \( 1 \). While the the visible nodes are dependent on the hidden nodes and vice versa, the nodes are independent of other nodes within the same layer. This is due to there being no intra layer interactions in the restricted Boltzmann machine.
|
|
|
|
<p>
|
|
The conditional probabilities are often referred to as the activitation functions in the neural networks context due to their role in determining the node outputs. For the binary-binary RBM they are
|
|
$$
|
|
\begin{align}
|
|
P(h_j = 1 | \boldsymbol{x}) &= \frac{1}{1 + e^{-b_j - \sum_i x_i w_{ij}}}
|
|
\label{_auto8}\\
|
|
P(x_i = 1 | \boldsymbol{h}) &= \frac{1}{1 + e^{-a_j - \sum_j h_j w_{ij}}},
|
|
\label{_auto9}
|
|
\end{align}
|
|
$$
|
|
|
|
where we recognize the logistic sigmoid function \( \sigma (x) = 1/(1+exp(-x)) \).
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec44">Gaussian RBM </h2>
|
|
For the Gaussian-Binary RBM the conditional probabilities are
|
|
$$
|
|
\begin{align}
|
|
P(x_i|\mathbf{h}) &= \mathcal{N}(x_i; a_i+ \sum_j h_j w_{ij}, \sigma^2)
|
|
\label{_auto10}\\
|
|
P(h_j=1|\mathbf{x}) &= \frac{1}{1+e^{-b_j-\frac{1}{\sigma^2} \sum_i x_i w_{ij}}},
|
|
\label{_auto11}
|
|
\end{align}
|
|
$$
|
|
|
|
while the visible units now follow a normal distribution, we see the hidden units again follow the logistic sigmoid function.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec45">Cost function </h2>
|
|
|
|
<p>
|
|
When working with a training dataset, the most common training approach is maximizing the log-likelihood of the training data. The log likelihood characterizes the log-probability of generating the observed data using our generative model. Using this method our cost function is chosen as the negative log-likelihood. The learning then consists of trying to find parameters that maximize the probability of the dataset, and is known as Maximum Likelihood Estimation (MLE).
|
|
Denoting the parameters as \( \boldsymbol{\theta} = a_1,...,a_M,b_1,...,b_N,w_{11},...,w_{MN} \), the log-likelihood is given by
|
|
$$
|
|
\begin{align}
|
|
\mathcal{L}(\{ \theta_i \}) &= \langle \text{log} P_\theta(\boldsymbol{x}) \rangle_{data}
|
|
\label{_auto12}\\
|
|
&= - \langle E(\boldsymbol{x}; \{ \theta_i\}) \rangle_{data} - \text{log} Z(\{ \theta_i\}),
|
|
\label{_auto13}
|
|
\end{align}
|
|
$$
|
|
|
|
where we used that the normalization constant does not depend on the data, \( \langle \text{log} Z(\{ \theta_i\}) \rangle = \text{log} Z(\{ \theta_i\}) \)
|
|
Our cost function is the negative log-likelihood, \( \mathcal{C}(\{ \theta_i \}) = - \mathcal{L}(\{ \theta_i \}) \)
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec46">Optimization / Training </h2>
|
|
The training procedure of choice often is Stochastic Gradient Descent (SGD). It consists of a series of iterations where we update the parameters according to the equation
|
|
$$
|
|
\begin{align}
|
|
\boldsymbol{\theta}_{k+1} = \boldsymbol{\theta}_k - \eta \nabla \mathcal{C} (\boldsymbol{\theta}_k)
|
|
\label{_auto14}
|
|
\end{align}
|
|
$$
|
|
|
|
at each \( k \)-th iteration. There are a range of variants of the algorithm which aim at making the learning rate \( \eta \) more adaptive so the method might be more efficient while remaining stable.
|
|
|
|
<p>
|
|
We now need the gradient of the cost function in order to minimize it. We find that
|
|
$$
|
|
\begin{align}
|
|
\frac{\partial \mathcal{C}(\{ \theta_i\})}{\partial \theta_i}
|
|
&= \langle \frac{\partial E(\boldsymbol{x}; \theta_i)}{\partial \theta_i} \rangle_{data}
|
|
+ \frac{\partial \text{log} Z(\{ \theta_i\})}{\partial \theta_i}
|
|
\label{_auto15}\\
|
|
&= \langle O_i(\boldsymbol{x}) \rangle_{data} - \langle O_i(\boldsymbol{x}) \rangle_{model},
|
|
\label{_auto16}
|
|
\end{align}
|
|
$$
|
|
|
|
where in order to simplify notation we defined the "operator"
|
|
$$
|
|
\begin{align}
|
|
O_i(\boldsymbol{x}) = \frac{\partial E(\boldsymbol{x}; \theta_i)}{\partial \theta_i},
|
|
\label{_auto17}
|
|
\end{align}
|
|
$$
|
|
|
|
and used the statistical mechanics relationship between expectation values and the log-partition function:
|
|
$$
|
|
\begin{align}
|
|
\langle O_i(\boldsymbol{x}) \rangle_{model} = \text{Tr} P_\theta(\boldsymbol{x})O_i(\boldsymbol{x}) = - \frac{\partial \text{log} Z(\{ \theta_i\})}{\partial \theta_i}.
|
|
\label{_auto18}
|
|
\end{align}
|
|
$$
|
|
|
|
<p>
|
|
<!-- !split -->
|
|
|
|
<h2 id="___sec47">More on RBMs </h2>
|
|
|
|
<p>
|
|
The data-dependent term in the gradient is known as the positive phase of the gradient, while the model-dependent term is known as the negative phase of the gradient. The aim of the training is to lower the energy of configurations that are near observed data points (increasing their probability), and raising the energy of configurations that are far from observed data points (decreasing their probability).
|
|
|
|
<p>
|
|
The gradient of the negative log-likelihood cost function of a Binary-Binary RBM is then
|
|
$$
|
|
\begin{align}
|
|
\frac{\partial \mathcal{C} (w_{ij}, a_i, b_j)}{\partial w_{ij}} =& \langle x_i h_j \rangle_{data} - \langle x_i h_j \rangle_{model}
|
|
\label{_auto19}\\
|
|
\frac{\partial \mathcal{C} (w_{ij}, a_i, b_j)}{\partial a_{ij}} =& \langle x_i \rangle_{data} - \langle x_i \rangle_{model}
|
|
\label{_auto20}\\
|
|
\frac{\partial \mathcal{C} (w_{ij}, a_i, b_j)}{\partial b_{ij}} =& \langle h_i \rangle_{data} - \langle h_i \rangle_{model}.
|
|
\label{_auto21}\\
|
|
\label{_auto22}
|
|
\end{align}
|
|
$$
|
|
|
|
To get the expecation values with respect to the <em>data</em>, we set the visible units to each of the observed samples in the training data, then update the hidden units according to the conditional probability found before. We then average over all samples in the training data to calculate expectation values with respect to the data.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec48">Which sampling to use </h2>
|
|
|
|
<p>
|
|
To get the expectation values with respect to the <em>model</em>, we use Gibbs sampling. We can either initialize the \( \boldsymbol{x} \) randomly or with a training sample. While we ideally want a large number of Gibbs iterations \( n\rightarrow n \), one might decide to truncate it earlier for efficiency. Doing this while having intialized \( \boldsymbol{x} \) with a training data vector is referred to as contrastive divergence (CD), because one is then closer to approximating the gradient of this function than the negative log-likelihood. The contrastive divergence function is the difference between two Kullback-Leibler divergences (also called relative entropy), which measure how one probability distribution diverges from a second, expected probability distribution (in this case the estimated one from the ground truth one).
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec49">RBMs for the quantum many body problem </h2>
|
|
|
|
<p>
|
|
The idea of applying RBMs to quantum many body problems was presented by G. Carleo and M. Troyer, working with ETH Zurich and Microsoft Research.
|
|
|
|
<p>
|
|
Some of their motivation included
|
|
|
|
<ul>
|
|
<li> "The wave function \( \Psi \) is a monolithic mathematical quantity that contains all the information on a quantum state, be it a single particle or a complex molecule. In principle, an exponential amount of information is needed to fully encode a generic many-body quantum state."</li>
|
|
<li> There are still interesting open problems, including fundamental questions ranging from the dynamical properties of high-dimensional systems to the exact ground-state properties of strongly interacting fermions.</li>
|
|
<li> The difficulty lies in finding a general strategy to reduce the exponential complexity of the full many-body wave function down to its most essential features. That is
|
|
|
|
<ol type="a"></li>
|
|
<li> \( \rightarrow \) Dimensional reduction</li>
|
|
<li> \( \rightarrow \) Feature extraction</li>
|
|
</ol>
|
|
|
|
<li> Among the most successful techniques to attack these challenges, artifical neural networks play a prominent role.</li>
|
|
<li> Want to understand whether an artifical neural network may adapt to describe a quantum system.</li>
|
|
</ul>
|
|
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec50">Choose the right RBM </h2>
|
|
|
|
<p>
|
|
Carleo and Troyer applied the RBM to the quantum mechanical spin lattice systems of the Ising model and Heisenberg model, with encouraging results. Our goal is to test the method on systems of moving particles. For the spin lattice systems it was natural to use a binary-binary RBM, with the nodes taking values of 1 and -1. For moving particles, on the other hand, we want the visible nodes to be continuous, representing position coordinates. Thus, we start by choosing a Gaussian-binary RBM, where the visible nodes are continuous and hidden nodes take on values of 0 or 1. If eventually we would like the hidden nodes to be continuous as well the rectified linear units seem like the most relevant choice.
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec51">Representing the wave function </h2>
|
|
The wavefunction should be a probability amplitude depending on \( \boldsymbol{x} \). The RBM model is given by the joint distribution of \( \boldsymbol{x} \) and \( \boldsymbol{h} \)
|
|
$$
|
|
\begin{align}
|
|
F_{rbm}(\mathbf{x},\mathbf{h}) = \frac{1}{Z} e^{-\frac{1}{T_0}E(\mathbf{x},\mathbf{h})}.
|
|
\label{_auto23}
|
|
\end{align}
|
|
$$
|
|
|
|
To find the marginal distribution of \( \boldsymbol{x} \) we set:
|
|
$$
|
|
\begin{align}
|
|
F_{rbm}(\mathbf{x}) &= \sum_\mathbf{h} F_{rbm}(\mathbf{x}, \mathbf{h})
|
|
\label{_auto24}\\
|
|
&= \frac{1}{Z}\sum_\mathbf{h} e^{-E(\mathbf{x}, \mathbf{h})}.
|
|
\label{_auto25}
|
|
\end{align}
|
|
$$
|
|
|
|
Now this is what we use to represent the wave function, calling it a neural-network quantum state (NQS)
|
|
$$
|
|
\begin{align}
|
|
\Psi (\mathbf{X}) &= F_{rbm}(\mathbf{x})
|
|
\label{_auto26}\\
|
|
&= \frac{1}{Z}\sum_{\boldsymbol{h}} e^{-E(\mathbf{x}, \mathbf{h})}
|
|
\label{_auto27}\\
|
|
&= \frac{1}{Z} \sum_{\{h_j\}} e^{-\sum_i^M \frac{(x_i - a_i)^2}{2\sigma^2} + \sum_j^N b_j h_j + \sum_{i,j}^{M,N} \frac{x_i w_{ij} h_j}{\sigma^2}}
|
|
\label{_auto28}\\
|
|
&= \frac{1}{Z} e^{-\sum_i^M \frac{(x_i - a_i)^2}{2\sigma^2}} \prod_j^N (1 + e^{b_j + \sum_i^M \frac{x_i w_{ij}}{\sigma^2}}).
|
|
\label{_auto29}\\
|
|
\label{_auto30}
|
|
\end{align}
|
|
$$
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec52">Choose the cost function </h2>
|
|
Now we don't necessarily have training data (unless we generate it by using some other method). However, what we do have is the variational principle which allows us to obtain the ground state wave function by minimizing the expectation value of the energy of a trial wavefunction (corresponding to the untrained NQS). Similarly to the traditional variational Monte Carlo method then, it is the local energy we wish to minimize. The gradient to use for the stochastic gradient descent procedure is
|
|
$$
|
|
\begin{align}
|
|
G_i = \frac{\partial \langle E_L \rangle}{\partial \theta_i}
|
|
= 2(\langle E_L \frac{1}{\Psi}\frac{\partial \Psi}{\partial \theta_i} \rangle - \langle E_L \rangle \langle \frac{1}{\Psi}\frac{\partial \Psi}{\partial \theta_i} \rangle ),
|
|
\label{_auto31}
|
|
\end{align}
|
|
$$
|
|
|
|
where the local energy is given by
|
|
$$
|
|
\begin{align}
|
|
E_L = \frac{1}{\Psi} \hat{\mathbf{H}} \Psi.
|
|
\label{_auto32}
|
|
\end{align}
|
|
$$
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec53">Running the codes </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
You can find the codes for the simple two-electron case at the Github repository <a href="https://github.com/mhjensenseminars/MachineLearningTalk/tree/master/doc/Programs/MLcpp/src" target="_blank"><tt>https://github.com/mhjensenseminars/MachineLearningTalk/tree/master/doc/Programs/MLcpp/src</tt></a>. Python codes to come, only c++ as of now.
|
|
|
|
<p>
|
|
The trial wave function is based on the product of a Slater determinant with Gaussian orbitals, a simple Jastrow factor \( \exp{(r_{ij})} \) and the reduced Boltzmann machines.
|
|
|
|
<p>
|
|
The Broyden-Fletcher-Goldfarb-Shanno algorithm was used to perform the minimization. We used \( 14 \) hidden nodes in the calculations below.
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec54">Energy as function of iterations, \( N=2 \) electrons </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
<br /><br /><center><p><img src="figures/figN2.png" align="bottom" width=700></p></center><br /><br />
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec55">Energy as function of iterations, \( N=6 \) electrons </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
<br /><br /><center><p><img src="figures/figN6.png" align="bottom" width=700></p></center><br /><br />
|
|
</div>
|
|
|
|
|
|
<p>
|
|
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
|
|
|
<h2 id="___sec56">Conclusions and where do we stand </h2>
|
|
<div class="alert alert-block alert-block alert-text-normal">
|
|
<b></b>
|
|
<p>
|
|
|
|
<ul>
|
|
<li> A simple extension of the work of <a href="http://science.sciencemag.org/content/355/6325/602" target="_blank">G. Carleo and M. Troyer, Science <b>355</b>, Issue 6325, pp. 602-606 (2017)</a> gives excellent results for two-electron systems as well as good agreement with standard VMC calculations for \( N=6 \) and \( N=12 \) electrons.</li>
|
|
<li> Minimization problem can be tricky.</li>
|
|
<li> Anti-symmetry dealt with multiplying the trail wave function with an optimized Slater determinant.</li>
|
|
<li> To come: Analysis of wave function from ML and compare with diffusion and Variational Monte Carlo calculations as well as the analytical results of Taut for the two-electron case.</li>
|
|
<li> Extend to more fermions. How do we deal with the antisymmetry of the multi-fermion wave function?
|
|
|
|
<ol type="a"></li>
|
|
<li> Here we used standard Hartree-Fock theory to define an optimal Slater determinant. Takes care of the antisymmetry. What about constructing an anti-symmetrized network function?</li>
|
|
<li> Use thereafter ML to determine the correlated part of the wafe function (including a standard Jastrow factor).</li>
|
|
<li> Test this for multi-fermion systems and compare with other many-body methods.</li>
|
|
</ol>
|
|
|
|
<li> Can we use ML to find out which correlations are relevant and thereby diminish the dimensionality problem in say CC or SRG theories?</li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<p>
|
|
|
|
<!-- ------------------- end of main content --------------- -->
|
|
|
|
|
|
<center style="font-size:80%">
|
|
<!-- copyright --> © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
|
</center>
|
|
|
|
|
|
</body>
|
|
</html>
|
|
|
|
|