Week 34: Introduction to the course, Logistics and Practicalities
Morten Hjorth-Jensen, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
Date: Oct 12, 2021
Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
Overview of first week
-
Wednesday August 25: Introduction to software and repetition of Python Programming
-
Thursday August 26: First lecture: Presentation of the course, aims and content
-
Thursday: Second Lecture: Start with simple linear regression and repetition of linear algebra and elements of statistics
-
Friday August 27: Linear regression
-
Computer lab: Wednesdays, 8am-6pm. First time: Wednesday August 25.
Reading Recommendations
For the reading assignments we use the following abbreviations:
-
GBC: Goodfellow, Bengio, and Courville, Deep Learning
-
CMB: Christopher M. Bishop, Pattern Recognition and Machine Learning
-
HTF: Hastie, Tibshirani, and Friedman, The Elements of Statistical Learning
-
AG: Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow
Reading recommendations this week: Refresh linear algebra, GBC chapters 1 and 2. CMB sections 1.1 and 3.1. HTF chapters 2 and 3. Install scikit-learn. See lecture notes for week 34 at https://compphysics.github.io/MachineLearning/doc/web/course.html
Thursday August 26
The lectures will be recorded and updated videos will be posted after the lectures.
"Video of Lecture August 26, 2021":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h21/forelesningsvideoer/LectureThursdayAugust26.mp4?vrtx=view-as-webpage
Zoom link for lectures: https://msu.zoom.us/j/93311529525?pwd=a1VXSzY4aTFWVy9Rb05mNDJTZ09lZz09
Video of Lecture from Fall Semester 2020.
Lectures and ComputerLab
-
Lectures: Thursday (12.15pm-2pm and Friday (12.15pm-2pm).
-
Weekly reading assignments and videos needed to solve projects and exercises.
-
Weekly exercises when not working on projects. You can hand in exercises if you want.
-
Detailed lecture notes, exercises, all programs presented, projects etc can be found at the homepage of the course.
-
Weekly plans and all other information are on the official webpage.
-
No final exam, three projects that are graded and have to be approved.
Announcement
NORA AI competetion: See the link here https://www.nora.ai/Competition/image-segmentation.html
Communication channels
Course Format
-
Three compulsory projects. Electronic reports only using Canvas to hand in projects and git as version control software and GitHub for repository (or GitLab) of all your material.
-
Evaluation and grading: The three projects are graded and each counts 1/3 of the final mark. No final written or oral exam.
a. For the last project each group/participant submits a proposal or works with suggested (by us) proposals for the project.
b. If possible, we would like to organize the last project as a workshop where each group makes a poster and presents this to all other participants of the course
c. Poster session where all participants can study and discuss the other proposals.
d. Based on feedback etc, each group finalizes the report and submits for grading.
- Python is the default programming language, but feel free to use C/C++ and/or Fortran or other programming languages. All source codes discussed during the lectures can be found at the webpage and github address of the course.
Teachers
Teachers :
-
Morten Hjorth-Jensen, morten.hjorth-jensen@fys.uio.no
-
Phone: +47-48257387
-
Office: Department of Physics, University of Oslo, Eastern wing, room FØ470
-
Office hours: Anytime! Individual or group office hours can be arranged either in person or via zoom. Feel free to send an email for planning.
-
Øyvind Sigmundson Schøyen, oyvinssc@student.matnat.uio.no
- Office: Department of Physics, University of Oslo, Eastern wing, room FØ452
-
Stian Dysthe Bilek stian.bilek@fys.uio.no
- Office: Department of Physics, University of Oslo, Eastern wing, room FØ450
-
Linus Ekstrøm, linueks@gmail.com, linus.ekstrom@fys.uio.no
-
Nicholas Karlsen, nicholaskarlsen1102@gmail.com, nicholas.karlsen@fys.uio.no
-
Bendik Steinsvåg Dalen, b.s.dalen@fys.uio.no
-
Philip Karim Sørli Niane, p.k.s.niane@fys.uio.no
Deadlines for projects (tentative)
-
Project 1: October 11 (available September 10) graded with feedback)
-
Project 2: November 15 (available October 12, graded with feedback)
-
Project 3: December 13 (available November 8, graded with feedback)
Projects are handed in using Canvas. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via Canvas.
Recommended textbooks
- The lecture notes are collected as a jupyter-book at https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/intro.html.
In addition to the lecture notes, we recommend the books of Bishop and Goodfellow et al. We will follow these texts closely and the weekly reading assignments refer to these two texts. The text by Hastie et al is also widely used in the Machine Learning community. Finally, we also recommend the hands-on text by Geron, see below.
-
Christopher M. Bishop, Pattern Recognition and Machine Learning, Springer, https://www.springer.com/gp/book/9780387310732.
-
Ian Goodfellow, Yoshua Bengio, and Aaron Courville. The different chapters are available for free at https://www.deeplearningbook.org/. Chapters 2-14 are highly recommended. The lectures follow to a larg extent this text. The weekly plans will include reading suggestions from these two textbooks.
Additional textbooks:
-
Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer, https://www.springer.com/gp/book/9780387848570. This is a well-known text and serves as additional literature.
-
Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly, https://www.oreilly.com/library/view/hands-on-machine-learning/9781492032632/. This text is very useful since it contains many code examples and hands-on applications of all algorithms discussed in this course.
Prerequisites
Basic knowledge in programming and mathematics, with an emphasis on
linear algebra. Knowledge of Python or/and C++ as programming
languages is strongly recommended and experience with Jupiter notebook
is recommended. Required courses are the equivalents to the University
of Oslo mathematics courses MAT1100, MAT1110, MAT1120 and at least one
of the corresponding computing and programming courses INF1000/INF1110
or MAT-INF1100/MAT-INF1100L/BIOS1100/KJM-INF1100. Most universities
offer nowadays a basic programming course (often compulsory) where
Python is the recurring programming language.
Learning outcomes
This course aims at giving you insights and knowledge about many of
the central algorithms used in Data Analysis and Machine Learning.
The course is project based and through various numerical projects,
normally three, you will be exposed to fundamental research problems
in these fields, with the aim to reproduce state of the art scientific
results. Both supervised and unsupervised methods will be covered. The
emphasis is on a frequentist approach, although we will try to link it
with a Bayesian approach as well. You will learn to develop and
structure large codes for studying different cases where Machine
Learning is applied to, 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, after this course you will
-
Learn about basic data analysis, statistical analysis, Bayesian statistics, Monte Carlo sampling, data optimization and machine learning;
-
Be capable of extending the acquired knowledge to other systems and cases;
-
Have an understanding of central algorithms used in data analysis and machine learning;
-
Understand linear methods for regression and classification, from ordinary least squares, via Lasso and Ridge to Logistic regression;
-
Learn about neural networks and deep learning methods for supervised and unsupervised learning. Emphasis on feed forward neural networks, convolutional and recurrent neural networks;
-
Learn about about decision trees, random forests, bagging and boosting methods;
-
Learn about support vector machines and kernel transformations;
-
Reduction of data sets, from PCA to clustering;
-
Autoencoders and Reinforcement Learning;
-
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++ and/or Fortran (Fortran2003 or later) or Julia or other.
Topics covered in this course: Statistical analysis and optimization of data
The course has two central parts
-
Statistical analysis and optimization of data
-
Machine learning
These topics will be scattered thorughout the course and may not necessarily be taught separately. Rather, we will often take an approach (during the lectures and project/exercise sessions) where say elements from statistical data analysis are mixed with specific Machine Learning algorithms
Statistical analysis and optimization of data.
We plan to cover the following topics:
-
Basic concepts, expectation values, variance, covariance, correlation functions and errors;
-
Simpler models, binomial distribution, the Poisson distribution, simple and multivariate normal distributions;
-
Central elements of Bayesian statistics and modeling;
-
Gradient methods for data optimization,
-
Monte Carlo methods, Markov chains, Gibbs sampling and Metropolis-Hastings sampling;
-
Estimation of errors and resampling techniques such as the cross-validation, blocking, bootstrapping and jackknife methods;
-
Principal Component Analysis (PCA) and its mathematical foundation
Topics covered in this course: Machine Learning
The following topics will be covered
-
Linear Regression and Logistic Regression;
-
Neural networks and deep learning, including convolutional and recurrent neural networks
-
Decisions trees, Random Forests, Bagging and Boosting
-
Support vector machines
-
Bayesian linear and logistic regression
-
Boltzmann Machines
-
Unsupervised learning Dimensionality reduction, from PCA to clustering
Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics.
Extremely useful tools, strongly recommended
and discussed at the lab sessions.
Other courses on Data science and Machine Learning at UiO
The link here https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/ gives an excellent overview of courses on Machine learning at UiO.
-
STK2100 Machine learning and statistical methods for prediction and classification.
-
IN3050/4050 Introduction to Artificial Intelligence and Machine Learning. Introductory course in machine learning and AI with an algorithmic approach.
-
STK-INF3000/4000 Selected Topics in Data Science. The course provides insight into selected contemporary relevant topics within Data Science.
-
IN4080 Natural Language Processing. Probabilistic and machine learning techniques applied to natural language processing.
-
STK-IN4300 Statistical learning methods in Data Science. An advanced introduction to statistical and machine learning. For students with a good mathematics and statistics background.
-
INF4490 Biologically Inspired Computing. An introduction to self-adapting methods also called artificial intelligence or machine learning.
-
IN-STK5000 Adaptive Methods for Data-Based Decision Making. Methods for adaptive collection and processing of data based on machine learning techniques.
-
IN5400/INF5860 Machine Learning for Image Analysis. An introduction to deep learning with particular emphasis on applications within Image analysis, but useful for other application areas too.
-
TEK5040 Deep learning for autonomous systems. The course addresses advanced algorithms and architectures for deep learning with neural networks. The course provides an introduction to how deep-learning techniques can be used in the construction of key parts of advanced autonomous systems that exist in physical environments and cyber environments.
-
STK4051 Computational Statistics
-
STK4021 Applied Bayesian Analysis and Numerical Methods
Introduction
Our emphasis throughout this series of lectures
is on understanding the mathematical aspects of
different algorithms used in the fields of data analysis and machine learning.
However, where possible we will emphasize the
importance of using available software. We start thus with a hands-on
and top-down approach to machine learning. The aim is thus to start with
relevant data or data we have produced
and use these to introduce statistical data analysis
concepts and machine learning algorithms before we delve into the
algorithms themselves. The examples we will use in the beginning, start with simple
polynomials with random noise added. We will use the Python
software package Scikit-Learn and
introduce various machine learning algorithms to make fits of
the data and predictions. We move thereafter to more interesting
cases such as data from say experiments (below we will look at experimental nuclear binding energies as an example).
These are examples where we can easily set up the data and
then use machine learning algorithms included in for example
Scikit-Learn.
These examples will serve us the purpose of getting
started. Furthermore, they allow us to catch more than two birds with
a stone. They will allow us to bring in some programming specific
topics and tools as well as showing the power of various Python
libraries for machine learning and statistical data analysis.
Here, we will mainly focus on two
specific Python packages for Machine Learning, Scikit-Learn and
Tensorflow (see below for links etc). Moreover, the examples we
introduce will serve as inputs to many of our discussions later, as
well as allowing you to set up models and produce your own data and
get started with programming.
What is Machine Learning?
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 as 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.
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. Many of the methods we will study are also
strongly rooted in basic mathematics and physics research.
Ideally, 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. You should however always keep in mind that
machines and algorithms are to a large extent developed by humans. The
insights and knowledge we have about a specific system, play a central
role when we develop a specific machine learning algorithm.
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
Scikit-learn,
Tensorflow,
PyTorch and Keras, 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.
Types of Machine Learning
The approaches to machine learning are many, but are often split into
two main categories. In supervised learning we know the answer to a
problem, and let the computer deduce the logic behind it. On the other
hand, unsupervised learning 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
reinforcement learning. This is a paradigm of learning inspired by
behavioral psychology, where learning is achieved by trial-and-error,
solely from rewards and punishment.
Another way to categorize machine learning tasks is to consider the
desired output of a system. Some of the most common tasks are:
-
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.
-
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.
-
Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.
Essential elements of ML
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 (which can be subdivided into training, validation and test data). Many find the most difficult part of using Machine Learning to be the set up of your data in a meaningful way.
-
The second item is a model which is normally a function of some parameters. The model reflects our knowledge of the system (or lack thereof). As an example, if we know that our data show a behavior similar to what would be predicted by a polynomial, fitting our data to a polynomial of some degree would then determin our model.
-
The last ingredient is a so-called cost/loss function (or error or risk function) which allows us to present an estimate on how good our model is in reproducing the data it is supposed to train.
An optimization/minimization problem
At the heart of basically all Machine Learning algorithms we will encounter so-called minimization or optimization algorithms. A large family of such methods are so-called gradient methods.
A Frequentist approach to data analysis
When you hear phrases like predictions and estimations and
correlations and causations, what do you think of? May be you think
of the difference between classifying new data points and generating
new data points.
Or perhaps you consider that correlations represent some kind of symmetric statements like
if A is correlated with B, then B is correlated with
A. Causation on the other hand is directional, that is if A causes B, B does not
necessarily cause A.
These concepts are in some sense the difference between machine
learning and statistics. In machine learning and prediction based
tasks, we are often interested in developing algorithms that are
capable of learning patterns from given data in an automated fashion,
and then using these learned patterns to make predictions or
assessments of newly given data. In many cases, our primary concern
is the quality of the predictions or assessments, and we are less
concerned about the underlying patterns that were learned in order
to make these predictions.
In machine learning we normally use a so-called frequentist approach,
where the aim is to make predictions and find correlations. We focus
less on for example extracting a probability distribution function (PDF). The PDF can be
used in turn to make estimations and find causations such as given A
what is the likelihood of finding B.
What is a good model?
In science and engineering we often end up in situations where we want to infer (or learn) a
quantitative model M for a given set of sample points \boldsymbol{X} \in [x_1, x_2,\dots x_N].
As we will see repeatedely in these lectures, we could try to fit these data points to a model given by a
straight line, or if we wish to be more sophisticated to a more complex
function.
The reason for inferring such a model is that it
serves many useful purposes. On the one hand, the model can reveal information
encoded in the data or underlying mechanisms from which the data were generated. For instance, we could discover important
corelations that relate interesting physics interpretations.
In addition, it can simplify the representation of the given data set and help
us in making predictions about future data samples.
A first important consideration to keep in mind is that inferring the correct model
for a given data set is an elusive, if not impossible, task. The fundamental difficulty
is that if we are not specific about what we mean by a correct model, there
could easily be many different models that fit the given data set equally well.
What is a good model? Can we define it?
The central question is this: what leads us to say that a model is correct or
optimal for a given data set? To make the model inference problem well posed, i.e.,
to guarantee that there is a unique optimal model for the given data, we need to
impose additional assumptions or restrictions on the class of models considered. To
this end, we should not be looking for just any model that can describe the data.
Instead, we should look for a model M that is the best among a restricted class
of models. In addition, to make the model inference problem computationally
tractable, we need to specify how restricted the class of models needs to be. A
common strategy is to start
with the simplest possible class of models that is just necessary to describe the data
or solve the problem at hand. More precisely, the model class should be rich enough
to contain at least one model that can fit the data to a desired accuracy and yet be
restricted enough that it is relatively simple to find the best model for the given data.
Thus, the most popular strategy is to start from the
simplest class of models and increase the complexity of the models only when the
simpler models become inadequate. For instance, if we work with a regression problem to fit a set of sample points, one
may first try the simplest class of models, namely linear models, followed obviously by more complex models.
How to evaluate which model fits best the data is something we will come back to over and over again in these sets of lectures.
Software and needed installations
We will make extensive use of Python as programming language and its
myriad of available libraries. You will find
Jupyter notebooks invaluable in your work. You can run R
codes in the Jupyter/IPython notebooks, with the immediate benefit of
visualizing your data. You can also use compiled languages like C++,
Rust, Julia, Fortran etc if you prefer. The focus in these lectures will be
on Python.
If you have Python installed (we strongly recommend Python3) and you feel
pretty familiar with installing different packages, we recommend that
you install the following Python packages via pip as
- pip install numpy scipy matplotlib ipython scikit-learn mglearn sympy pandas pillow
For Python3, replace pip with pip3.
For OSX users we recommend, after having installed Xcode, to
install brew. Brew allows for a seamless installation of additional
software via for example
- brew install python3
For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution,
you can use pip as well and simply install Python as
- sudo apt-get install python3 (or python for pyhton2.7)
etc etc.
Python installers
If you don't want to perform these operations separately and venture
into the hassle of exploring how to set up dependencies and paths, we
recommend two widely used distrubutions which set up all relevant
dependencies for Python, namely
which is an open source
distribution of the Python and R programming languages for large-scale
data processing, predictive analytics, and scientific computing, that
aims to simplify package management and deployment. Package versions
are managed by the package management system conda.
is a Python
distribution for scientific and analytic computing distribution and
analysis environment, available for free and under a commercial
license.
Furthermore, Google's Colab is a free Jupyter notebook environment that requires
no setup and runs entirely in the cloud. Try it out!
Useful Python libraries
Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there)
-
NumPy is a highly popular library for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays
-
The pandas library provides high-performance, easy-to-use data structures and data analysis tools
-
Xarray is a Python package that makes working with labelled multi-dimensional arrays simple, efficient, and fun!
-
Scipy (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering.
-
Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.
-
Autograd can automatically differentiate native Python and Numpy code. It can handle a large subset of Python's features, including loops, ifs, recursion and closures, and it can even take derivatives of derivatives of derivatives
-
SymPy is a Python library for symbolic mathematics.
-
scikit-learn has simple and efficient tools for machine learning, data mining and data analysis
-
TensorFlow is a Python library for fast numerical computing created and released by Google
-
Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano
-
And many more such as pytorch, Theano etc
Installing R, C++, cython or Julia
You will also find it convenient to utilize R. We will mainly
use Python during our lectures and in various projects and exercises.
Those of you
already familiar with R should feel free to continue using R, keeping
however an eye on the parallel Python set ups. Similarly, if you are a
Python afecionado, feel free to explore R as well. Jupyter/Ipython
notebook allows you to run R codes interactively in your
browser. The software library R is really tailored for statistical data analysis
and allows for an easy usage of the tools and algorithms we will discuss in these
lectures.
To install R with Jupyter notebook
follow the link here
Installing R, C++, cython, Numba etc
For the C++ aficionados, Jupyter/IPython notebook allows you also to
install C++ and run codes written in this language interactively in
the browser. Since we will emphasize writing many of the algorithms
yourself, you can thus opt for either Python or C++ (or Fortran or other compiled languages) as programming
languages.
To add more entropy, cython can also be used when running your
notebooks. It means that Python with the jupyter notebook
setup allows you to integrate widely popular softwares and tools for
scientific computing. Similarly, the
Numba Python package delivers increased performance
capabilities with minimal rewrites of your codes. With its
versatility, including symbolic operations, Python offers a unique
computational environment. Your jupyter notebook can easily be
converted into a nicely rendered PDF file or a Latex file for
further processing. For example, convert to latex as