added introduction chapter
This commit is contained in:
@@ -6,9 +6,9 @@ Automatically generated HTML file from DocOnce source
|
||||
<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="Data Analysis and Machine Learning: Introduction and Representing data">
|
||||
<meta name="description" content="Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters">
|
||||
|
||||
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
|
||||
<title>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</title>
|
||||
|
||||
<!-- Bootstrap style: bootstrap -->
|
||||
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
|
||||
@@ -41,68 +41,70 @@ Automatically generated HTML file from DocOnce source
|
||||
<!-- tocinfo
|
||||
{'highest level': 2,
|
||||
'sections': [('Introduction', 2, None, '___sec0'),
|
||||
('Learning outcomes', 2, None, '___sec1'),
|
||||
('Types of Machine Learning', 2, None, '___sec2'),
|
||||
('Software and needed installations', 2, None, '___sec3'),
|
||||
('Python installers', 2, None, '___sec4'),
|
||||
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
|
||||
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
|
||||
('Software and needed installations', 2, None, '___sec1'),
|
||||
('Python installers', 2, None, '___sec2'),
|
||||
('Installing R, C++, cython or Julia', 2, None, '___sec3'),
|
||||
('Installing R, C++, cython or Julia', 2, None, '___sec4'),
|
||||
('Introduction to Jupyter notebook and available tools',
|
||||
2,
|
||||
None,
|
||||
'___sec7'),
|
||||
('Representing data, more examples', 2, None, '___sec8'),
|
||||
('Simple regression model', 2, None, '___sec9'),
|
||||
'___sec5'),
|
||||
('Representing data, more examples', 2, None, '___sec6'),
|
||||
('Simple regression model', 2, None, '___sec7'),
|
||||
('Simple regression model, now using _scikit-learn_',
|
||||
2,
|
||||
None,
|
||||
'___sec10'),
|
||||
'___sec8'),
|
||||
('Simple regression model with gradient descent',
|
||||
2,
|
||||
None,
|
||||
'___sec11'),
|
||||
'___sec9'),
|
||||
('Simple regression model with stochastic gradient descent',
|
||||
2,
|
||||
None,
|
||||
'___sec12'),
|
||||
('Polynomial regression', 2, None, '___sec13'),
|
||||
('Predator-Prey model from ecology', 2, None, '___sec14'),
|
||||
('Case study from Hudson bay', 2, None, '___sec15'),
|
||||
('Hudson bay data', 2, None, '___sec16'),
|
||||
('Plotting the data', 2, None, '___sec17'),
|
||||
'___sec10'),
|
||||
('Polynomial regression', 2, None, '___sec11'),
|
||||
('Predator-Prey model from ecology', 2, None, '___sec12'),
|
||||
('Case study from Hudson bay', 2, None, '___sec13'),
|
||||
('Hudson bay data', 2, None, '___sec14'),
|
||||
('Plotting the data', 2, None, '___sec15'),
|
||||
('Hares and lynx in Hudson bay from 1900 to 1920',
|
||||
2,
|
||||
None,
|
||||
'___sec18'),
|
||||
'___sec16'),
|
||||
('Why now create a computer model for the hare and lynx '
|
||||
'populations?',
|
||||
2,
|
||||
None,
|
||||
'___sec19'),
|
||||
('The traditional (top-down) approach', 2, None, '___sec20'),
|
||||
('Basic mathematics notation', 2, None, '___sec21'),
|
||||
'___sec17'),
|
||||
('The traditional (top-down) approach', 2, None, '___sec18'),
|
||||
('Basic mathematics notation', 2, None, '___sec19'),
|
||||
('Basic dynamics of the population of hares',
|
||||
2,
|
||||
None,
|
||||
'___sec22'),
|
||||
('Basic dynamics of the population of lynx', 2, None, '___sec23'),
|
||||
('Evolution equations', 2, None, '___sec24'),
|
||||
('Adapt the model to the Hudson Bay case', 2, None, '___sec25'),
|
||||
('The program', 2, None, '___sec26'),
|
||||
('The plot', 2, None, '___sec27'),
|
||||
('Linear regression in Python', 2, None, '___sec28'),
|
||||
('Linear Least squares in R', 2, None, '___sec29'),
|
||||
('Non-Linear Least squares in R', 2, None, '___sec30'),
|
||||
('Example: ecoli lab experiment', 2, None, '___sec31'),
|
||||
('The program', 2, None, '___sec32'),
|
||||
('The output', 2, None, '___sec33'),
|
||||
('Parameter estimation', 2, None, '___sec34'),
|
||||
'___sec20'),
|
||||
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
|
||||
('Evolution equations', 2, None, '___sec22'),
|
||||
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
|
||||
('The program', 2, None, '___sec24'),
|
||||
('The plot', 2, None, '___sec25'),
|
||||
('Linear regression in Python', 2, None, '___sec26'),
|
||||
('Linear Least squares in R', 2, None, '___sec27'),
|
||||
('Non-Linear Least squares in R', 2, None, '___sec28'),
|
||||
('Example: ecoli lab experiment', 2, None, '___sec29'),
|
||||
('The program', 2, None, '___sec30'),
|
||||
('The output', 2, None, '___sec31'),
|
||||
('Parameter estimation', 2, None, '___sec32'),
|
||||
('A program relevant for the biological problem',
|
||||
2,
|
||||
None,
|
||||
'___sec35'),
|
||||
('Simulating financial transcations', 2, None, '___sec36'),
|
||||
('Simulation of Transactions', 3, None, '___sec37')]}
|
||||
'___sec33'),
|
||||
('Simulating financial transcations', 2, None, '___sec34'),
|
||||
('Simulation of Transactions', 3, None, '___sec35'),
|
||||
('Particle in one dimension an velocity distribution',
|
||||
2,
|
||||
None,
|
||||
'___sec36')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -132,7 +134,7 @@ MathJax.Hub.Config({
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
|
||||
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</a>
|
||||
</div>
|
||||
|
||||
<div class="navbar-collapse collapse navbar-responsive-collapse">
|
||||
@@ -141,43 +143,42 @@ MathJax.Hub.Config({
|
||||
<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>Introduction</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;"><b>Learning outcomes</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;"><b>Types of Machine Learning</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;"><b>Software and needed installations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;"><b>Python installers</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;"><b>Introduction to Jupyter notebook and available tools</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;"><b>Representing data, more examples</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;"><b>Simple regression model</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;"><b>Simple regression model, now using <b>scikit-learn</b></b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;"><b>Simple regression model with gradient descent</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;"><b>Simple regression model with stochastic gradient descent</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;"><b>Polynomial regression</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;"><b>Predator-Prey model from ecology</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;"><b>Case study from Hudson bay</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;"><b>Hudson bay data</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;"><b>Plotting the data</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;"><b>Hares and lynx in Hudson bay from 1900 to 1920</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;"><b>Why now create a computer model for the hare and lynx populations?</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;"><b>The traditional (top-down) approach</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;"><b>Basic mathematics notation</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;"><b>Basic dynamics of the population of hares</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;"><b>Basic dynamics of the population of lynx</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;"><b>Evolution equations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec25" style="font-size: 80%;"><b>Adapt the model to the Hudson Bay case</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec26" style="font-size: 80%;"><b>The program</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec27" style="font-size: 80%;"><b>The plot</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec28" style="font-size: 80%;"><b>Linear regression in Python</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec29" style="font-size: 80%;"><b>Linear Least squares in R</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec30" style="font-size: 80%;"><b>Non-Linear Least squares in R</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec31" style="font-size: 80%;"><b>Example: ecoli lab experiment</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec32" style="font-size: 80%;"><b>The program</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec33" style="font-size: 80%;"><b>The output</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;"><b>Parameter estimation</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;"><b>A program relevant for the biological problem</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;"><b>Simulating financial transcations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;"> Simulation of Transactions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;"><b>Software and needed installations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;"><b>Python installers</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;"><b>Introduction to Jupyter notebook and available tools</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;"><b>Representing data, more examples</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;"><b>Simple regression model</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;"><b>Simple regression model, now using <b>scikit-learn</b></b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;"><b>Simple regression model with gradient descent</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;"><b>Simple regression model with stochastic gradient descent</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;"><b>Polynomial regression</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;"><b>Predator-Prey model from ecology</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;"><b>Case study from Hudson bay</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;"><b>Hudson bay data</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;"><b>Plotting the data</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;"><b>Hares and lynx in Hudson bay from 1900 to 1920</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;"><b>Why now create a computer model for the hare and lynx populations?</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;"><b>The traditional (top-down) approach</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;"><b>Basic mathematics notation</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;"><b>Basic dynamics of the population of hares</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;"><b>Basic dynamics of the population of lynx</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;"><b>Evolution equations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;"><b>Adapt the model to the Hudson Bay case</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;"><b>The program</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec25" style="font-size: 80%;"><b>The plot</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec26" style="font-size: 80%;"><b>Linear regression in Python</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec27" style="font-size: 80%;"><b>Linear Least squares in R</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec28" style="font-size: 80%;"><b>Non-Linear Least squares in R</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec29" style="font-size: 80%;"><b>Example: ecoli lab experiment</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec30" style="font-size: 80%;"><b>The program</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec31" style="font-size: 80%;"><b>The output</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec32" style="font-size: 80%;"><b>Parameter estimation</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec33" style="font-size: 80%;"><b>A program relevant for the biological problem</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;"><b>Simulating financial transcations</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;"> Simulation of Transactions</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;"><b>Particle in one dimension an velocity distribution</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -195,7 +196,7 @@ MathJax.Hub.Config({
|
||||
|
||||
|
||||
<div class="jumbotron">
|
||||
<center><h1>Data Analysis and Machine Learning: Introduction and Representing data</h1></center> <!-- document title -->
|
||||
<center><h1>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</h1></center> <!-- document title -->
|
||||
|
||||
<p>
|
||||
<!-- author(s): Morten Hjorth-Jensen -->
|
||||
@@ -211,7 +212,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>May 11, 2018</h4></center> <!-- date -->
|
||||
<center><h4>May 21, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- potential-jumbotron-button -->
|
||||
@@ -222,166 +223,7 @@ MathJax.Hub.Config({
|
||||
<h2 id="___sec0" class="anchor">Introduction </h2>
|
||||
|
||||
<p>
|
||||
Statistics, data science and machine learning form important fields of
|
||||
research in modern science. They describe how to learn and make
|
||||
predictions from data, as well allowing us to extract important
|
||||
correlations about physical process and the underlying laws of motion
|
||||
in large data sets. The latter, big data sets, appear
|
||||
frequently in essentially all disciplines, from the traditional Science,
|
||||
Technology, Mathematics and Engineering fields to Life Science, Law, education research,
|
||||
the Humanities and
|
||||
the Social Sciences. It has become more and more common to see
|
||||
research projects on big data in for example the Social
|
||||
Sciences where extracting patterns from complicated survey data is one of many research directions.
|
||||
Having a solid grasp of data analysis and machine learning
|
||||
is thus becoming central to scientific computing in many
|
||||
fields, and competences and skills within the fields of machine learning
|
||||
and scientific computing are nowadays strongly requested by many
|
||||
potential employers. The latter cannot be overstated, familiarity with
|
||||
machine learning has almost become a prerequisite for many of the most
|
||||
exciting employment opportunities, whether they are in bioinformatics,
|
||||
life science, physics or finance, in the private or the public
|
||||
sector. This author has had several students or met students who have
|
||||
been hired recently based on their skills and competences in
|
||||
scientific computing and data science, often with marginal knowledge
|
||||
of machine learning.
|
||||
|
||||
<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.
|
||||
Machine learning represents 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 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. Popular software packages written in
|
||||
Python for machine learning like <a href="http://scikit-learn.org/stable/" target="_self">Scikit-learn</a>, <a href="https://www.tensorflow.org/" target="_self">Tensorflow</a>,
|
||||
<a href="http://pytorch.org/" target="_self">PyTorch</a> and <a href="https://keras.io/" target="_self">Keras</a>, all freely available at their respective GitHub sites,
|
||||
encompass communities of developers in the thousands or more. And the number
|
||||
of code developers and contributors keeps increasing. Not all the
|
||||
algorithms and methods can be given a rigorous mathematical
|
||||
justification, opening up thereby large rooms for experimenting
|
||||
and trial and error and thereby exciting new developments.
|
||||
However, a solid command of linear algebra, multivariate theory,
|
||||
probability theory, statistical data analysis,
|
||||
understanding errors and Monte Carlo methods are central elements in a proper understanding of many of
|
||||
algorithms and methods we will discuss.
|
||||
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec1" class="anchor">Learning outcomes </h2>
|
||||
|
||||
<p>
|
||||
These lectures aim at giving you an overview of central aspects of
|
||||
statistical data analysis as well as some of the central algorithms
|
||||
used in machine learning. We will introduce a variety of central
|
||||
algorithms and methods essential for studies of data analysis and
|
||||
machine learning.
|
||||
|
||||
<p>
|
||||
Hands-on projects and experimenting with data and algorithms plays a central role in
|
||||
these lectures, and our hope is, through the various
|
||||
projects and exercies, to expose you to fundamental
|
||||
research problems in these fields, with the aim to reproduce state of
|
||||
the art scientific results. You will learn to develop and
|
||||
structure large codes for studying these systems, get acquainted with
|
||||
computing facilities and learn to handle large scientific projects. A
|
||||
good scientific and ethical conduct is emphasized throughout the
|
||||
course. More specifically, you will
|
||||
|
||||
<ol>
|
||||
<li> learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;</li>
|
||||
<li> be capable of extending the acquired knowledge to other systems and cases;</li>
|
||||
<li> Have an understanding of central algorithms used in data analysis and machine learning;</li>
|
||||
<li> Gain knowledge of central aspects of Monte Carlo methods, Markov chains, Gibbs samplers and their possible applications, from numerical integration to simulation of stock markets;</li>
|
||||
<li> Understand methods for regression and classification;</li>
|
||||
<li> Learn about neural network, genetic algorithms and Boltzmann machines;</li>
|
||||
<li> Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++, in addition to a basic knowledge of linear algebra (typically taught during the first one or two years of undergraduate studies).</li>
|
||||
</ol>
|
||||
|
||||
There are several topics we will cover here, spanning from a
|
||||
statistical data analysis and its basic concepts such expectation
|
||||
values, variance, covariance, correlation functions and errors, via
|
||||
well-known probability distribution functions like uniform
|
||||
distribution, the binomial distribution, the Poisson distribution and
|
||||
simple and multivariate normal distributions to central elements of
|
||||
Bayesian statistics and modeling. We will also remind the reader about
|
||||
central elements from linear algebra and standard methods based on
|
||||
linear algebra used to fit functions such Cubic splines and gradient
|
||||
methods for data optimization and the Singular-value decomposition and
|
||||
least square methods for parameterizing data.
|
||||
|
||||
<p>
|
||||
We will also cover Monte Carlo methods, Markov chains, well-known
|
||||
algorithms for sampling stochastic events like the Metropolis-Hastings
|
||||
and Gibbs sampling methods. An important aspect of all our
|
||||
calculations is a proper estimation of errors. Here we will also
|
||||
discuss famous resampling techniques like the blocking, bootstrapping
|
||||
and jackknife methods.
|
||||
|
||||
<p>
|
||||
The second part of the material covers several algorithms used in
|
||||
machine learning.
|
||||
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec2" class="anchor">Types of Machine Learning </h2>
|
||||
|
||||
<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 behavioral 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>
|
||||
|
||||
The methods we cover have three main topics in common, irrespective of
|
||||
whether we deal with supervised or unsupervised learning. The first
|
||||
ingredient is normally our data set, the second is a model which is
|
||||
normally a function of some parameters. The last ingredient is a
|
||||
so-called <b>cost</b> function which allows us to present an estimate on
|
||||
how good our model is in reproducing the data it is supposed to train.
|
||||
|
||||
<p>
|
||||
Here we will build our machine learning approach on elements of the
|
||||
statistical foundation discussed above, with elements from data
|
||||
analysis, stochastic processes etc. We will discuss the following
|
||||
machine learning algorithms
|
||||
|
||||
<ol>
|
||||
<li> Linear regression and its variants, in essence polynomial regression</li>
|
||||
<li> Decision tree algorithms, from simpler to more complex ones</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>
|
||||
</ol>
|
||||
|
||||
Before we proceed however, there are several practicalities with data
|
||||
Before we proceed there are several practicalities with data
|
||||
analysis and software tools we would like to present. These tools will
|
||||
help us in our understanding of various machine learning algorithms.
|
||||
|
||||
@@ -407,7 +249,7 @@ Finally, our last example consists of economic data from the OECD.
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec3" class="anchor">Software and needed installations </h2>
|
||||
<h2 id="___sec1" class="anchor">Software and needed installations </h2>
|
||||
|
||||
<p>
|
||||
We will make intensive use of python as programming language and the myriad of available libraries.
|
||||
@@ -444,7 +286,7 @@ etc etc.
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec4" class="anchor">Python installers </h2>
|
||||
<h2 id="___sec2" class="anchor">Python installers </h2>
|
||||
If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up
|
||||
all relevant dependencies for Python, namely
|
||||
|
||||
@@ -455,7 +297,7 @@ all relevant dependencies for Python, namely
|
||||
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec5" class="anchor">Installing R, C++, cython or Julia </h2>
|
||||
<h2 id="___sec3" class="anchor">Installing R, C++, cython or Julia </h2>
|
||||
|
||||
<p>
|
||||
You will also find it convenient to utilize R.
|
||||
@@ -468,7 +310,7 @@ To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-ke
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec6" class="anchor">Installing R, C++, cython or Julia </h2>
|
||||
<h2 id="___sec4" class="anchor">Installing R, C++, cython or Julia </h2>
|
||||
|
||||
<p>
|
||||
For the C++ aficionados, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
|
||||
@@ -492,7 +334,7 @@ formats, ipython notebooks, latex files, pdf files etc.
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec7" class="anchor">Introduction to Jupyter notebook and available tools </h2>
|
||||
<h2 id="___sec5" class="anchor">Introduction to Jupyter notebook and available tools </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -526,7 +368,7 @@ display(data_pandas)
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec8" class="anchor">Representing data, more examples </h2>
|
||||
<h2 id="___sec6" class="anchor">Representing data, more examples </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
@@ -558,7 +400,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec9" class="anchor">Simple regression model </h2>
|
||||
<h2 id="___sec7" class="anchor">Simple regression model </h2>
|
||||
Add info about the equations
|
||||
<p>
|
||||
|
||||
@@ -588,7 +430,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec10" class="anchor">Simple regression model, now using <b>scikit-learn</b> </h2>
|
||||
<h2 id="___sec8" class="anchor">Simple regression model, now using <b>scikit-learn</b> </h2>
|
||||
Add info about the equations
|
||||
<p>
|
||||
|
||||
@@ -617,7 +459,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec11" class="anchor">Simple regression model with gradient descent </h2>
|
||||
<h2 id="___sec9" class="anchor">Simple regression model with gradient descent </h2>
|
||||
Add info about the equations, play around with different learning rates
|
||||
<p>
|
||||
|
||||
@@ -661,7 +503,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec12" class="anchor">Simple regression model with stochastic gradient descent </h2>
|
||||
<h2 id="___sec10" class="anchor">Simple regression model with stochastic gradient descent </h2>
|
||||
Add info about the equations, play around with different learning rates
|
||||
<p>
|
||||
|
||||
@@ -686,7 +528,7 @@ sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec13" class="anchor">Polynomial regression </h2>
|
||||
<h2 id="___sec11" class="anchor">Polynomial regression </h2>
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
@@ -695,7 +537,7 @@ sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec14" class="anchor">Predator-Prey model from ecology </h2>
|
||||
<h2 id="___sec12" class="anchor">Predator-Prey model from ecology </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -720,7 +562,7 @@ scientific method:
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec15" class="anchor">Case study from Hudson bay </h2>
|
||||
<h2 id="___sec13" class="anchor">Case study from Hudson bay </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -742,7 +584,7 @@ Here we start by
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec16" class="anchor">Hudson bay data </h2>
|
||||
<h2 id="___sec14" class="anchor">Hudson bay data </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -797,7 +639,7 @@ One reason that this particular system has been so extensively studied is that t
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec17" class="anchor">Plotting the data </h2>
|
||||
<h2 id="___sec15" class="anchor">Plotting the data </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -834,7 +676,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec18" class="anchor">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
|
||||
<h2 id="___sec16" class="anchor">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
|
||||
@@ -842,7 +684,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec19" class="anchor">Why now create a computer model for the hare and lynx populations? </h2>
|
||||
<h2 id="___sec17" class="anchor">Why now create a computer model for the hare and lynx populations? </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
@@ -876,7 +718,7 @@ climate and other complicating factors. How significant are these?
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec20" class="anchor">The traditional (top-down) approach </h2>
|
||||
<h2 id="___sec18" class="anchor">The traditional (top-down) approach </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -910,7 +752,7 @@ ODEs</em> (which cannot be solved)
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec21" class="anchor">Basic mathematics notation </h2>
|
||||
<h2 id="___sec19" class="anchor">Basic mathematics notation </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
@@ -931,7 +773,7 @@ ODEs</em> (which cannot be solved)
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec22" class="anchor">Basic dynamics of the population of hares </h2>
|
||||
<h2 id="___sec20" class="anchor">Basic dynamics of the population of hares </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -960,7 +802,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec23" class="anchor">Basic dynamics of the population of lynx </h2>
|
||||
<h2 id="___sec21" class="anchor">Basic dynamics of the population of lynx </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -991,7 +833,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec24" class="anchor">Evolution equations </h2>
|
||||
<h2 id="___sec22" class="anchor">Evolution equations </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -1021,7 +863,7 @@ Note:
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec25" class="anchor">Adapt the model to the Hudson Bay case </h2>
|
||||
<h2 id="___sec23" class="anchor">Adapt the model to the Hudson Bay case </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -1045,7 +887,7 @@ Note:
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec26" class="anchor">The program </h2>
|
||||
<h2 id="___sec24" class="anchor">The program </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -1106,7 +948,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec27" class="anchor">The plot </h2>
|
||||
<h2 id="___sec25" class="anchor">The plot </h2>
|
||||
|
||||
<p>
|
||||
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
|
||||
@@ -1117,7 +959,7 @@ If we perform a least-square fitting, we can find optimal values for the paramet
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec28" class="anchor">Linear regression in Python </h2>
|
||||
<h2 id="___sec26" class="anchor">Linear regression in Python </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
@@ -1151,7 +993,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec29" class="anchor">Linear Least squares in R </h2>
|
||||
<h2 id="___sec27" class="anchor">Linear Least squares in R </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
@@ -1186,7 +1028,7 @@ predict(linearMod,<span style="color: #B00040">data.frame</span>(Year<span style
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec30" class="anchor">Non-Linear Least squares in R </h2>
|
||||
<h2 id="___sec28" class="anchor">Non-Linear Least squares in R </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
@@ -1221,7 +1063,7 @@ text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</sp
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec31" class="anchor">Example: ecoli lab experiment </h2>
|
||||
<h2 id="___sec29" class="anchor">Example: ecoli lab experiment </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-primary">
|
||||
@@ -1259,7 +1101,7 @@ The population grows faster and faster. <a href="http://www.zo.utexas.edu/course
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec32" class="anchor">The program </h2>
|
||||
<h2 id="___sec30" class="anchor">The program </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -1293,7 +1135,7 @@ r <span style="color: #666666">=</span> <span style="color: #666666">0.5</span>
|
||||
% if FORMAT != 'ipynb':
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec33" class="anchor">The output </h2>
|
||||
<h2 id="___sec31" class="anchor">The output </h2>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -1325,7 +1167,7 @@ N[20]=86.7
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec34" class="anchor">Parameter estimation </h2>
|
||||
<h2 id="___sec32" class="anchor">Parameter estimation </h2>
|
||||
|
||||
<p>
|
||||
<div class="panel panel-default">
|
||||
@@ -1355,7 +1197,7 @@ Use experimental data in the fraction, say \( t_1=600 \), \( t_2=1200 \),
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec35" class="anchor">A program relevant for the biological problem </h2>
|
||||
<h2 id="___sec33" class="anchor">A program relevant for the biological problem </h2>
|
||||
|
||||
<p>
|
||||
<!-- exact r = 0.000694 -->
|
||||
@@ -1404,7 +1246,7 @@ Change <code>r</code> in the program and play around to make a better fit!
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec36" class="anchor">Simulating financial transcations </h2>
|
||||
<h2 id="___sec34" class="anchor">Simulating financial transcations </h2>
|
||||
|
||||
<p>
|
||||
The aim here is to simulate financial transactions among financial agents
|
||||
@@ -1478,7 +1320,7 @@ exponentially decreases with \( m' \).
|
||||
We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need
|
||||
several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments).
|
||||
|
||||
<h3 id="___sec37" class="anchor">Simulation of Transactions </h3>
|
||||
<h3 id="___sec35" class="anchor">Simulation of Transactions </h3>
|
||||
|
||||
Our task is to first set up an algorithm which simulates the above transactions with an initial
|
||||
amount \( m_0 \).
|
||||
@@ -1606,7 +1448,60 @@ $$
|
||||
p_{ij} \propto \vert m_i-m_j\vert^{-\alpha}\left(c_{ij}+1\right)^{\gamma},
|
||||
$$
|
||||
|
||||
where \( c_{ij} \) represents the number of previous interactions that have taken place between \( i \) and \( j \). The factor \( 1 \) is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with \( N=1000 \), \( \alpha=1.0 \) and \( \alpha=2.0 \) using \( \gamma = 0.0, 1.0, 2.0, 3.0 \) and \( 4.0 \). Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving \( \lambda \) in each transaction. Comment your results and compare them with figures 5 and 6 of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_self">Goswami and Sen</a>.
|
||||
where \( c_{ij} \) represents the number of previous interactions that have taken place between \( i \) and \( j \). The factor \( 1 \) is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with \( N=1000 \), \( \alpha=1.0 \) and \( \alpha=2.0 \) using \( \gamma = 0.0, 1.0, 2.0, 3.0 \) and \( 4.0 \). Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving \( \lambda \) in each transaction. Comment your results and compare them with figures 5 and 6 of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_self">Goswami and Sen</a>.
|
||||
|
||||
<p>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec36" class="anchor">Particle in one dimension an velocity distribution </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"># Program to test the Metropolis algorithm with one particle at given temp in one dimension</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.mlab</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mlab</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">import</span> <span style="color: #0000FF; font-weight: bold">random</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> sqrt, exp, log
|
||||
<span style="color: #408080; font-style: italic"># initialize the rng with a seed</span>
|
||||
random<span style="color: #666666">.</span>seed()
|
||||
<span style="color: #408080; font-style: italic"># Hard coding of input parameters</span>
|
||||
MCcycles <span style="color: #666666">=</span> <span style="color: #666666">100000</span>
|
||||
Temperature <span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
|
||||
beta <span style="color: #666666">=</span> <span style="color: #666666">1./</span>Temperature
|
||||
InitialVelocity <span style="color: #666666">=</span> <span style="color: #666666">-2.0</span>
|
||||
CurrentVelocity <span style="color: #666666">=</span> InitialVelocity
|
||||
Energy <span style="color: #666666">=</span> <span style="color: #666666">0.5*</span>InitialVelocity<span style="color: #666666">*</span>InitialVelocity
|
||||
VelocityRange <span style="color: #666666">=</span> <span style="color: #666666">10*</span>sqrt(Temperature)
|
||||
VelocityStep <span style="color: #666666">=</span> <span style="color: #666666">2*</span>VelocityRange<span style="color: #666666">/10.</span>
|
||||
AverageEnergy <span style="color: #666666">=</span> Energy
|
||||
AverageEnergy2 <span style="color: #666666">=</span> Energy<span style="color: #666666">*</span>Energy
|
||||
VelocityValues <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(MCcycles)
|
||||
<span style="color: #408080; font-style: italic"># The Monte Carlo sampling with Metropolis starts here</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> (<span style="color: #666666">1</span>, MCcycles, <span style="color: #666666">1</span>):
|
||||
TrialVelocity <span style="color: #666666">=</span> CurrentVelocity <span style="color: #666666">+</span> (<span style="color: #666666">2.0*</span>random<span style="color: #666666">.</span>random() <span style="color: #666666">-</span> <span style="color: #666666">1.0</span>)<span style="color: #666666">*</span>VelocityStep
|
||||
EnergyChange <span style="color: #666666">=</span> <span style="color: #666666">0.5*</span>(TrialVelocity<span style="color: #666666">*</span>TrialVelocity <span style="color: #666666">-</span>CurrentVelocity<span style="color: #666666">*</span>CurrentVelocity);
|
||||
<span style="color: #008000; font-weight: bold">if</span> random<span style="color: #666666">.</span>random() <span style="color: #666666"><=</span> exp(<span style="color: #666666">-</span>beta<span style="color: #666666">*</span>EnergyChange):
|
||||
CurrentVelocity <span style="color: #666666">=</span> TrialVelocity
|
||||
Energy <span style="color: #666666">+=</span> EnergyChange
|
||||
VelocityValues[i] <span style="color: #666666">=</span> CurrentVelocity
|
||||
AverageEnergy <span style="color: #666666">+=</span> Energy
|
||||
AverageEnergy2 <span style="color: #666666">+=</span> Energy<span style="color: #666666">*</span>Energy
|
||||
<span style="color: #408080; font-style: italic">#Final averages</span>
|
||||
AverageEnergy <span style="color: #666666">=</span> AverageEnergy<span style="color: #666666">/</span>MCcycles
|
||||
AverageEnergy2 <span style="color: #666666">=</span> AverageEnergy2<span style="color: #666666">/</span>MCcycles
|
||||
Variance <span style="color: #666666">=</span> AverageEnergy2 <span style="color: #666666">-</span> AverageEnergy<span style="color: #666666">*</span>AverageEnergy
|
||||
<span style="color: #008000; font-weight: bold">print</span>(AverageEnergy, Variance)
|
||||
n, bins, patches <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>hist(VelocityValues, <span style="color: #666666">400</span>, facecolor<span style="color: #666666">=</span><span style="color: #BA2121">'green'</span>)
|
||||
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">'$v$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">'Velocity distribution P(v)'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Velocity histogram at $k_BT=2$'</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">-5</span>, <span style="color: #666666">5</span>, <span style="color: #666666">0</span>, <span style="color: #666666">600</span>])
|
||||
plt<span style="color: #666666">.</span>grid(<span style="color: #008000">True</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
|
||||
Reference in New Issue
Block a user