added introduction chapter

This commit is contained in:
mhjensen
2018-05-21 10:59:37 -04:00
parent 6437af32ef
commit 06c18466e5
55 changed files with 4077 additions and 2764 deletions
+133 -237
View File
@@ -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>
<style type="text/css">
@@ -66,68 +66,70 @@ div { text-align: justify; text-justify: inter-word; }
<!-- 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>
@@ -153,7 +155,7 @@ MathJax.Hub.Config({
<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 -->
@@ -169,7 +171,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>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -177,166 +179,7 @@ MathJax.Hub.Config({
<h2 id="___sec0">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="_blank">Scikit-learn</a>, <a href="https://www.tensorflow.org/" target="_blank">Tensorflow</a>,
<a href="http://pytorch.org/" target="_blank">PyTorch</a> and <a href="https://keras.io/" target="_blank">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">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 --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec2">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.
@@ -362,7 +205,7 @@ Finally, our last example consists of economic data from the OECD.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec3">Software and needed installations </h2>
<h2 id="___sec1">Software and needed installations </h2>
<p>
We will make intensive use of python as programming language and the myriad of available libraries.
@@ -399,7 +242,7 @@ etc etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec4">Python installers </h2>
<h2 id="___sec2">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
@@ -410,7 +253,7 @@ all relevant dependencies for Python, namely
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<h2 id="___sec3">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R.
@@ -423,7 +266,7 @@ To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-ke
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec6">Installing R, C++, cython or Julia </h2>
<h2 id="___sec4">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
@@ -447,7 +290,7 @@ formats, ipython notebooks, latex files, pdf files etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec7">Introduction to Jupyter notebook and available tools </h2>
<h2 id="___sec5">Introduction to Jupyter notebook and available tools </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -480,7 +323,7 @@ display(data_pandas)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, more examples </h2>
<h2 id="___sec6">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -511,7 +354,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec9">Simple regression model </h2>
<h2 id="___sec7">Simple regression model </h2>
Add info about the equations
<p>
@@ -541,7 +384,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Simple regression model, now using <b>scikit-learn</b> </h2>
<h2 id="___sec8">Simple regression model, now using <b>scikit-learn</b> </h2>
Add info about the equations
<p>
@@ -570,7 +413,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Simple regression model with gradient descent </h2>
<h2 id="___sec9">Simple regression model with gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -614,7 +457,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Simple regression model with stochastic gradient descent </h2>
<h2 id="___sec10">Simple regression model with stochastic gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -639,7 +482,7 @@ sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Polynomial regression </h2>
<h2 id="___sec11">Polynomial regression </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
@@ -648,7 +491,7 @@ sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Predator-Prey model from ecology </h2>
<h2 id="___sec12">Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -672,7 +515,7 @@ scientific method:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Case study from Hudson bay </h2>
<h2 id="___sec13">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -693,7 +536,7 @@ Here we start by
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Hudson bay data </h2>
<h2 id="___sec14">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -742,7 +585,7 @@ One reason that this particular system has been so extensively studied is that t
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">Plotting the data </h2>
<h2 id="___sec15">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -778,7 +621,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<h2 id="___sec16">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 />
@@ -786,7 +629,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">Why now create a computer model for the hare and lynx populations? </h2>
<h2 id="___sec17">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -819,7 +662,7 @@ climate and other complicating factors. How significant are these?
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">The traditional (top-down) approach </h2>
<h2 id="___sec18">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -852,7 +695,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec21">Basic mathematics notation </h2>
<h2 id="___sec19">Basic mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -872,7 +715,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec22">Basic dynamics of the population of hares </h2>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -900,7 +743,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Basic dynamics of the population of lynx </h2>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -929,7 +772,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">Evolution equations </h2>
<h2 id="___sec22">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -958,7 +801,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">Adapt the model to the Hudson Bay case </h2>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -981,7 +824,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec26">The program </h2>
<h2 id="___sec24">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1041,7 +884,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec27">The plot </h2>
<h2 id="___sec25">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
@@ -1052,7 +895,7 @@ If we perform a least-square fitting, we can find optimal values for the paramet
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec28">Linear regression in Python </h2>
<h2 id="___sec26">Linear regression in Python </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1085,7 +928,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec29">Linear Least squares in R </h2>
<h2 id="___sec27">Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1119,7 +962,7 @@ predict(linearMod,<span style="color: #B00040">data.frame</span>(Year<span style
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec30">Non-Linear Least squares in R </h2>
<h2 id="___sec28">Non-Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1153,7 +996,7 @@ text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</sp
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec31">Example: ecoli lab experiment </h2>
<h2 id="___sec29">Example: ecoli lab experiment </h2>
<p>
<div class="alert alert-block alert-notice alert-text-normal">
@@ -1186,7 +1029,7 @@ The population grows faster and faster. <a href="http://www.zo.utexas.edu/course
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec32">The program </h2>
<h2 id="___sec30">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1219,7 +1062,7 @@ r <span style="color: #666666">=</span> <span style="color: #666666">0.5</span>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec33">The output </h2>
<h2 id="___sec31">The output </h2>
<p>
@@ -1251,7 +1094,7 @@ N[20]=86.7
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec34">Parameter estimation </h2>
<h2 id="___sec32">Parameter estimation </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1280,7 +1123,7 @@ Use experimental data in the fraction, say \( t_1=600 \), \( t_2=1200 \),
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec35">A program relevant for the biological problem </h2>
<h2 id="___sec33">A program relevant for the biological problem </h2>
<p>
<!-- exact r = 0.000694 -->
@@ -1328,7 +1171,7 @@ Change <code>r</code> in the program and play around to make a better fit!
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec36">Simulating financial transcations </h2>
<h2 id="___sec34">Simulating financial transcations </h2>
<p>
The aim here is to simulate financial transactions among financial agents
@@ -1402,7 +1245,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">Simulation of Transactions </h3>
<h3 id="___sec35">Simulation of Transactions </h3>
Our task is to first set up an algorithm which simulates the above transactions with an initial
amount \( m_0 \).
@@ -1530,7 +1373,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="_blank">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="_blank">Goswami and Sen</a>.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec36">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">&lt;=</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">&#39;green&#39;</span>)
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">&#39;$v$&#39;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&#39;Velocity distribution P(v)&#39;</span>)
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r&#39;Velocity histogram at $k_BT=2$&#39;</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 --------------- -->