added introduction chapter
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<!-- dom:TITLE: Data Analysis and Machine Learning: Introduction and Representing data -->\n",
|
||||
"# Data Analysis and Machine Learning: Introduction and Representing data\n",
|
||||
"<!-- dom:TITLE: Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters -->\n",
|
||||
"# Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters\n",
|
||||
"<!-- dom:AUTHOR: Morten Hjorth-Jensen at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University -->\n",
|
||||
"<!-- Author: --> \n",
|
||||
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
|
||||
"\n",
|
||||
"Date: **May 11, 2018**\n",
|
||||
"Date: **May 21, 2018**\n",
|
||||
"\n",
|
||||
"Copyright 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
|
||||
"\n",
|
||||
@@ -19,164 +19,7 @@
|
||||
"\n",
|
||||
"## Introduction\n",
|
||||
"\n",
|
||||
"Statistics, data science and machine learning form important fields of\n",
|
||||
"research in modern science. They describe how to learn and make\n",
|
||||
"predictions from data, as well allowing us to extract important\n",
|
||||
"correlations about physical process and the underlying laws of motion\n",
|
||||
"in large data sets. The latter, big data sets, appear\n",
|
||||
"frequently in essentially all disciplines, from the traditional Science,\n",
|
||||
"Technology, Mathematics and Engineering fields to Life Science, Law, education research, \n",
|
||||
"the Humanities and\n",
|
||||
"the Social Sciences. It has become more and more common to see\n",
|
||||
"research projects on big data in for example the Social\n",
|
||||
"Sciences where extracting patterns from complicated survey data is one of many research directions. \n",
|
||||
"Having a solid grasp of data analysis and machine learning\n",
|
||||
"is thus becoming central to scientific computing in many\n",
|
||||
"fields, and competences and skills within the fields of machine learning\n",
|
||||
"and scientific computing are nowadays strongly requested by many\n",
|
||||
"potential employers. The latter cannot be overstated, familiarity with\n",
|
||||
"machine learning has almost become a prerequisite for many of the most\n",
|
||||
"exciting employment opportunities, whether they are in bioinformatics,\n",
|
||||
"life science, physics or finance, in the private or the public\n",
|
||||
"sector. This author has had several students or met students who have\n",
|
||||
"been hired recently based on their skills and competences in\n",
|
||||
"scientific computing and data science, often with marginal knowledge\n",
|
||||
"of machine learning.\n",
|
||||
"\n",
|
||||
"Machine learning is a subfield of computer science, and is closely\n",
|
||||
"related to computational statistics. It evolved from the study of\n",
|
||||
"pattern recognition in artificial intelligence (AI) research, and has\n",
|
||||
"made contributions to AI tasks like computer vision, natural language\n",
|
||||
"processing and speech recognition. \n",
|
||||
"Machine learning represents the\n",
|
||||
"science of giving computers the ability to learn without being\n",
|
||||
"explicitly programmed. The idea is that there exist generic\n",
|
||||
"algorithms which can be used to find patterns in a broad class of data\n",
|
||||
"sets without having to write code specifically for each problem. The\n",
|
||||
"algorithm will build its own logic based on the data. \n",
|
||||
"\n",
|
||||
"Machine learning is an extremely rich field, in spite of its young age. The\n",
|
||||
"increases we have seen during the last three decades in computational\n",
|
||||
"capabilities have been followed by developments of methods and\n",
|
||||
"techniques for analyzing and handling large date sets, relying heavily\n",
|
||||
"on statistics, computer science and mathematics. The field is rather\n",
|
||||
"new and developing rapidly. Popular software packages written in\n",
|
||||
"Python for machine learning like [Scikit-learn](http://scikit-learn.org/stable/), [Tensorflow](https://www.tensorflow.org/),\n",
|
||||
"[PyTorch](http://pytorch.org/) and [Keras](https://keras.io/), all freely available at their respective GitHub sites,\n",
|
||||
"encompass communities of developers in the thousands or more. And the number\n",
|
||||
"of code developers and contributors keeps increasing. Not all the\n",
|
||||
"algorithms and methods can be given a rigorous mathematical\n",
|
||||
"justification, opening up thereby large rooms for experimenting\n",
|
||||
"and trial and error and thereby exciting new developments. \n",
|
||||
"However, a solid command of linear algebra, multivariate theory, \n",
|
||||
"probability theory, statistical data analysis,\n",
|
||||
"understanding errors and Monte Carlo methods are central elements in a proper understanding of many of \n",
|
||||
"algorithms and methods we will discuss. \n",
|
||||
"\n",
|
||||
"<!-- !split -->\n",
|
||||
"## Learning outcomes\n",
|
||||
"\n",
|
||||
"These lectures aim at giving you an overview of central aspects of\n",
|
||||
"statistical data analysis as well as some of the central algorithms\n",
|
||||
"used in machine learning. We will introduce a variety of central\n",
|
||||
"algorithms and methods essential for studies of data analysis and\n",
|
||||
"machine learning. \n",
|
||||
"\n",
|
||||
"Hands-on projects and experimenting with data and algorithms plays a central role in\n",
|
||||
"these lectures, and our hope is, through the various\n",
|
||||
"projects and exercies, to expose you to fundamental\n",
|
||||
"research problems in these fields, with the aim to reproduce state of\n",
|
||||
"the art scientific results. You will learn to develop and\n",
|
||||
"structure large codes for studying these systems, get acquainted with\n",
|
||||
"computing facilities and learn to handle large scientific projects. A\n",
|
||||
"good scientific and ethical conduct is emphasized throughout the\n",
|
||||
"course. More specifically, you will\n",
|
||||
"\n",
|
||||
"1. learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;\n",
|
||||
"\n",
|
||||
"2. be capable of extending the acquired knowledge to other systems and cases;\n",
|
||||
"\n",
|
||||
"3. Have an understanding of central algorithms used in data analysis and machine learning;\n",
|
||||
"\n",
|
||||
"4. 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;\n",
|
||||
"\n",
|
||||
"5. Understand methods for regression and classification;\n",
|
||||
"\n",
|
||||
"6. Learn about neural network, genetic algorithms and Boltzmann machines;\n",
|
||||
"\n",
|
||||
"7. 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).\n",
|
||||
"\n",
|
||||
"There are several topics we will cover here, spanning from a\n",
|
||||
"statistical data analysis and its basic concepts such expectation\n",
|
||||
"values, variance, covariance, correlation functions and errors, via\n",
|
||||
"well-known probability distribution functions like uniform\n",
|
||||
"distribution, the binomial distribution, the Poisson distribution and\n",
|
||||
"simple and multivariate normal distributions to central elements of\n",
|
||||
"Bayesian statistics and modeling. We will also remind the reader about\n",
|
||||
"central elements from linear algebra and standard methods based on\n",
|
||||
"linear algebra used to fit functions such Cubic splines and gradient\n",
|
||||
"methods for data optimization and the Singular-value decomposition and\n",
|
||||
"least square methods for parameterizing data.\n",
|
||||
"\n",
|
||||
"We will also cover Monte Carlo methods, Markov chains, well-known\n",
|
||||
"algorithms for sampling stochastic events like the Metropolis-Hastings\n",
|
||||
"and Gibbs sampling methods. An important aspect of all our\n",
|
||||
"calculations is a proper estimation of errors. Here we will also\n",
|
||||
"discuss famous resampling techniques like the blocking, bootstrapping\n",
|
||||
"and jackknife methods.\n",
|
||||
"\n",
|
||||
"The second part of the material covers several algorithms used in\n",
|
||||
"machine learning.\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"## Types of Machine Learning\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"The approaches to machine learning are many, but are often split into two main categories. \n",
|
||||
"In *supervised learning* we know the answer to a problem,\n",
|
||||
"and let the computer deduce the logic behind it. On the other hand, *unsupervised learning*\n",
|
||||
"is a method for finding patterns and relationship in data sets without any prior knowledge of the system.\n",
|
||||
"Some authours also operate with a third category, namely *reinforcement learning*. This is a paradigm \n",
|
||||
"of learning inspired by behavioral psychology, where learning is achieved by trial-and-error, \n",
|
||||
"solely from rewards and punishment.\n",
|
||||
"\n",
|
||||
"Another way to categorize machine learning tasks is to consider the desired output of a system.\n",
|
||||
"Some of the most common tasks are:\n",
|
||||
"\n",
|
||||
" * 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.\n",
|
||||
"\n",
|
||||
" * 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.\n",
|
||||
"\n",
|
||||
" * Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.\n",
|
||||
"\n",
|
||||
"The methods we cover have three main topics in common, irrespective of\n",
|
||||
"whether we deal with supervised or unsupervised learning. The first\n",
|
||||
"ingredient is normally our data set, the second is a model which is\n",
|
||||
"normally a function of some parameters. The last ingredient is a\n",
|
||||
"so-called **cost** function which allows us to present an estimate on\n",
|
||||
"how good our model is in reproducing the data it is supposed to train.\n",
|
||||
"\n",
|
||||
"Here we will build our machine learning approach on elements of the\n",
|
||||
"statistical foundation discussed above, with elements from data\n",
|
||||
"analysis, stochastic processes etc. We will discuss the following\n",
|
||||
"machine learning algorithms\n",
|
||||
"\n",
|
||||
"1. Linear regression and its variants, in essence polynomial regression\n",
|
||||
"\n",
|
||||
"2. Decision tree algorithms, from simpler to more complex ones\n",
|
||||
"\n",
|
||||
"3. Nearest neighbors models\n",
|
||||
"\n",
|
||||
"4. Bayesian statistics and regression\n",
|
||||
"\n",
|
||||
"5. Support vector machines and finally various variants of\n",
|
||||
"\n",
|
||||
"6. Artifical neural networks and deep learning\n",
|
||||
"\n",
|
||||
"Before we proceed however, there are several practicalities with data\n",
|
||||
"Before we proceed there are several practicalities with data\n",
|
||||
"analysis and software tools we would like to present. These tools will\n",
|
||||
"help us in our understanding of various machine learning algorithms.\n",
|
||||
"\n",
|
||||
@@ -1552,7 +1395,62 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"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 [Goswami and Sen](http://www.sciencedirect.com/science/article/pii/S0378437114006967)."
|
||||
"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 [Goswami and Sen](http://www.sciencedirect.com/science/article/pii/S0378437114006967). \n",
|
||||
"\n",
|
||||
"## Particle in one dimension an velocity distribution"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Program to test the Metropolis algorithm with one particle at given temp in one dimension\n",
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.mlab as mlab\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import random\n",
|
||||
"from math import sqrt, exp, log\n",
|
||||
"# initialize the rng with a seed\n",
|
||||
"random.seed()\n",
|
||||
"# Hard coding of input parameters\n",
|
||||
"MCcycles = 100000\n",
|
||||
"Temperature = 2.0\n",
|
||||
"beta = 1./Temperature\n",
|
||||
"InitialVelocity = -2.0\n",
|
||||
"CurrentVelocity = InitialVelocity\n",
|
||||
"Energy = 0.5*InitialVelocity*InitialVelocity\n",
|
||||
"VelocityRange = 10*sqrt(Temperature)\n",
|
||||
"VelocityStep = 2*VelocityRange/10.\n",
|
||||
"AverageEnergy = Energy\n",
|
||||
"AverageEnergy2 = Energy*Energy\n",
|
||||
"VelocityValues = np.zeros(MCcycles)\n",
|
||||
"# The Monte Carlo sampling with Metropolis starts here\n",
|
||||
"for i in range (1, MCcycles, 1):\n",
|
||||
" TrialVelocity = CurrentVelocity + (2.0*random.random() - 1.0)*VelocityStep\n",
|
||||
" EnergyChange = 0.5*(TrialVelocity*TrialVelocity -CurrentVelocity*CurrentVelocity);\n",
|
||||
" if random.random() <= exp(-beta*EnergyChange):\n",
|
||||
" CurrentVelocity = TrialVelocity\n",
|
||||
" Energy += EnergyChange\n",
|
||||
" VelocityValues[i] = CurrentVelocity\n",
|
||||
" AverageEnergy += Energy\n",
|
||||
" AverageEnergy2 += Energy*Energy\n",
|
||||
"#Final averages\n",
|
||||
"AverageEnergy = AverageEnergy/MCcycles\n",
|
||||
"AverageEnergy2 = AverageEnergy2/MCcycles\n",
|
||||
"Variance = AverageEnergy2 - AverageEnergy*AverageEnergy\n",
|
||||
"print(AverageEnergy, Variance)\n",
|
||||
"n, bins, patches = plt.hist(VelocityValues, 400, facecolor='green')\n",
|
||||
"\n",
|
||||
"plt.xlabel('$v$')\n",
|
||||
"plt.ylabel('Velocity distribution P(v)')\n",
|
||||
"plt.title(r'Velocity histogram at $k_BT=2$')\n",
|
||||
"plt.axis([-5, 5, 0, 600])\n",
|
||||
"plt.grid(True)\n",
|
||||
"plt.show()"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user