diff --git a/doc/src/week34/latex.sh b/doc/src/week34/latex.sh index a9966ac71..30596a447 100755 --- a/doc/src/week34/latex.sh +++ b/doc/src/week34/latex.sh @@ -34,9 +34,9 @@ system doconce ptex2tex $name envir=minted # Add special packages doconce subst "% Add user's preamble" "\g<1>\n\\usepackage{simplewick}" $name.tex system doconce slides_beamer $name --beamer_slide_theme=$beamertheme -system pdflatex -shell-escape ${name} -system pdflatex -shell-escape ${name} -cp $name.pdf ${name}-beamer.pdf -cp $name.tex ${name}-beamer.tex +#system pdflatex -shell-escape ${name} +#system pdflatex -shell-escape ${name} +#cp $name.pdf ${name}-beamer.pdf +#cp $name.tex ${name}-beamer.tex diff --git a/doc/src/week34/week34.pdf b/doc/src/week34/week34.pdf new file mode 100644 index 000000000..340076cf7 Binary files /dev/null and b/doc/src/week34/week34.pdf differ diff --git a/doc/src/week34/week34.tex b/doc/src/week34/week34.tex new file mode 100644 index 000000000..9ffdd8ea0 --- /dev/null +++ b/doc/src/week34/week34.tex @@ -0,0 +1,3886 @@ + +% LaTeX Beamer file automatically generated from DocOnce +% https://github.com/doconce/doconce + +%-------------------- begin beamer-specific preamble ---------------------- + +\documentclass{beamer} + +\usetheme{red_plain} +\usecolortheme{default} + +% turn off the almost invisible, yet disturbing, navigation symbols: +\setbeamertemplate{navigation symbols}{} + +% Examples on customization: +%\usecolortheme[named=RawSienna]{structure} +%\usetheme[height=7mm]{Rochester} +%\setbeamerfont{frametitle}{family=\rmfamily,shape=\itshape} +%\setbeamertemplate{items}[ball] +%\setbeamertemplate{blocks}[rounded][shadow=true] +%\useoutertheme{infolines} +% +%\usefonttheme{} +%\useinntertheme{} +% +%\setbeameroption{show notes} +%\setbeameroption{show notes on second screen=right} + +% fine for B/W printing: +%\usecolortheme{seahorse} + +\usepackage{pgf} +\usepackage{graphicx} +\usepackage{epsfig} +\usepackage{relsize} + +\usepackage{fancybox} % make sure fancybox is loaded before fancyvrb + +\usepackage{fancyvrb} +\usepackage{minted} % requires pygments and latex -shell-escape filename +%\usepackage{anslistings} +%\usepackage{listingsutf8} + +\usepackage{amsmath,amssymb,bm} +%\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage[utf8]{inputenc} +\usepackage{colortbl} +\usepackage[english]{babel} +\usepackage{tikz} +\usepackage{framed} +% Use some nice templates +\beamertemplatetransparentcovereddynamic + +% --- begin table of contents based on sections --- +% Delete this, if you do not want the table of contents to pop up at +% the beginning of each section: +% (Only section headings can enter the table of contents in Beamer +% slides generated from DocOnce source, while subsections are used +% for the title in ordinary slides.) +\AtBeginSection[] +{ + \begin{frame}[plain] + \frametitle{} + %\frametitle{Outline} + \tableofcontents[currentsection] + \end{frame} +} +% --- end table of contents based on sections --- + +% If you wish to uncover everything in a step-wise fashion, uncomment +% the following command: + +%\beamerdefaultoverlayspecification{<+->} + +\newcommand{\shortinlinecomment}[3]{\note{\textbf{#1}: #2}} +\newcommand{\longinlinecomment}[3]{\shortinlinecomment{#1}{#2}{#3}} + +\definecolor{linkcolor}{rgb}{0,0,0.4} +\hypersetup{ + colorlinks=true, + linkcolor=linkcolor, + urlcolor=linkcolor, + pdfmenubar=true, + pdftoolbar=true, + bookmarksdepth=3 + } +\setlength{\parskip}{0pt} % {1em} + +\newenvironment{doconceexercise}{}{} +\newcounter{doconceexercisecounter} +\newenvironment{doconce:movie}{}{} +\newcounter{doconce:movie:counter} + +\newcommand{\subex}[1]{\noindent\textbf{#1}} % for subexercises: a), b), etc + +\logo{{\tiny \copyright\ 1999-2023, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license}} + +%-------------------- end beamer-specific preamble ---------------------- + +% Add user's preamble + + + + +% insert custom LaTeX commands... + +\raggedbottom +\makeindex + +%-------------------- end preamble ---------------------- + +\begin{document} + +% matching end for #ifdef PREAMBLE + +\newcommand{\exercisesection}[1]{\subsection*{#1}} + + + +% ------------------- main content ---------------------- + + + +% ----------------- title ------------------------- + +\title{Week 34: Introduction to the course, Logistics and Practicalities} + +% ----------------- author(s) ------------------------- + +\author{Morten Hjorth-Jensen\inst{1,2}} +\institute{Department of Physics and Center for Computing in Science Education, University of Oslo, Norway\inst{1} +\and +Department of Physics and Astronomy and Facility for Rare Isotope Beams, Michigan State University, USA\inst{2}} +% ----------------- end author(s) ------------------------- + +\date{Week 34, August 21-25, 2021 +% +\ \\ +{\tiny \copyright\ 1999-2023, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license} +} + +\begin{frame}[plain,fragile] +\titlepage +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Overview of first week} + +\begin{enumerate} +\item The sessions on Tuesdays and Wednesdays last four hours for each group (four groups in total) and will include lectures in a flipped mode (promoting active learning) and work on exercices and projects. + +\item The sessions will begin with lectures, discussions, questions and answers about the material to be covered every week. + +\item There are four groups: +\begin{itemize} + + \item Tuesdays 815am-12pm and 1215pm-4pm + + \item Wednesdays 815am-12pm and 1215pm-4pm. +\end{itemize} + +\noindent +\end{enumerate} + +\noindent +Please sign up as soon as +possible for one of the groups. Max capacity per group is 30-40 +participants. The labs are also available till 6pm Tuesdays and Wednesdays. Videos and learning material with reading suggestions will be made available before each week starts. + +\begin{enumerate} +\item On Thursdays we have a regular lecture. These lectures start at 1215pm and end at 2pm and serve the aims of giving an overview over various topics. +\end{enumerate} + +\noindent +The first week we start with simple linear regression, a repetition of +linear algebra and elements of statistics needed for the course. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Schedule first week} + +\begin{block}{} +\begin{itemize} + \item August 22: Presentation of the course, aims and content. Introduction to software and repetition of Python Programming, linear algebra and basic elements of statistics. Please select group. + + \item August 23: Presentation of the course, aims and content. Introduction to software and repetition of Python Programming, linear algebra and basic elements of statistics. Please select group. + + \item August 24: Lecture: Linear regression, examples and theory +\end{itemize} + +\noindent +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Reading Recommendations} + +\begin{block}{} +For the reading assignments we use the following abbreviations: +\begin{itemize} +\item GBC: \href{{https://www.deeplearningbook.org/}}{Goodfellow, Bengio, and Courville, Deep Learning} + +\item CMB: Christopher M. Bishop, Pattern Recognition and Machine Learning + +\item HTF: Hastie, Tibshirani, and Friedman, The Elements of Statistical Learning + +\item AG: Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow + +\item KM: \href{{https://probml.github.io/pml-book/book1.html}}{Kevin Murphy, Probabilistic Machine Learning} +\end{itemize} + +\noindent +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 \href{{https://compphysics.github.io/MachineLearning/doc/web/course.html}}{\nolinkurl{https://compphysics.github.io/MachineLearning/doc/web/course.html}} (these notes). +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Lectures and ComputerLab} + +\begin{block}{} +\begin{itemize} + \item The sessions on Tuesdays and Wednesdays last four hours and will include partly lectures in a flipped mode (promoting active learning) and work on exercices and projects. + + \item Thursdays: regular lectures (12.15pm-2pm) + + \item Weekly reading assignments and videos needed to solve projects and exercises. + + \item Weekly exercises when not working on projects. You can hand in exercises if you want. + + \item Detailed lecture notes, exercises, all programs presented, projects etc can be found at the homepage of the course. + + \item Weekly plans and all other information are on the official webpage. + + \item No final exam, three projects that are graded and have to be approved. +\end{itemize} + +\noindent +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Communication channels} + +\begin{itemize} +\item Chat and communications via \href{{canvas.uio.no}}{\nolinkurl{canvas.uio.no}} + +\item \textbf{Slack} channel: machinelearninguio.slack.com +\end{itemize} + +\noindent +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Course Format} + +\begin{block}{} +\begin{itemize} + \item Three compulsory projects. Electronic reports only using \href{{https://www.uio.no/english/services/it/education/canvas/}}{Canvas} to hand in projects and \href{{https://git-scm.com/}}{git} as version control software and \href{{https://github.com/}}{GitHub} for repository (or \href{{https://about.gitlab.com/}}{GitLab}) of all your material. + + \item Evaluation and grading: The three projects are graded and each counts 1/3 of the final mark. No final written or oral exam. +\begin{enumerate} + + \item For the last project each group/participant submits a proposal or works with suggested (by us) proposals for the project. + + \item 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 + + \item Poster session where all participants can study and discuss the other proposals. + + \item Based on feedback etc, each group finalizes the report and submits for grading. + +\end{enumerate} + +\noindent + \item 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 \href{{https://github.com/CompPhysics/MachineLearning/tree/master/doc/Programs}}{github address} of the course. +\end{itemize} + +\noindent +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Teachers} + +\begin{block}{} + +\textbf{Teachers :} +\begin{itemize} +\item Morten Hjorth-Jensen, morten.hjorth-jensen@fys.uio.no +\begin{itemize} + + \item \textbf{Phone}: +47-48257387 + + \item \textbf{Office}: Department of Physics, University of Oslo, Eastern wing, room FØ470 + + \item \textbf{Office hours}: \emph{Anytime}! Individual or group office hours can be arranged either in person or via zoom. Feel free to send an email for planning. + +\end{itemize} + +\noindent +\item Ida Torkjellsdatter Storehaug, i.t.storehaug@fys.uio.no + +\item Fahimeh Najafi, fahim.n.20@gmail.com + +\item Mia-Katrin Ose Kvalsund, m.k.o.kvalsund@fys.uio.no + +\item Karl Henrik Fredly, k.h.fredly@fys.uio.no + +\item Adam Jakobsen, adam.jakobsen@fys.uio.no + +\item Daniel Haas Beccatini Lima, d.h.b.lima@fys.uio.no +\end{itemize} + +\noindent +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Deadlines for projects (tentative)} + +\begin{block}{} + +\begin{enumerate} +\item Project 1: October 9 (available September 4) graded with feedback) + +\item Project 2: November 6 (available October 6, graded with feedback) + +\item Project 3: December 11 (available November 10, graded with feedback) +\end{enumerate} + +\noindent +Projects are handed in using \textbf{Canvas}. We use Github as repository for codes, benchmark calculations etc. Comments and feedback on projects only via \textbf{Canvas}. + +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Recommended textbooks} + +\begin{enumerate} +\item The lecture notes are collected as a jupyter-book at \href{{https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/intro.html}}{\nolinkurl{https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/intro.html}}. +\end{enumerate} + +\noindent +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. + +\begin{enumerate} +\item Christopher M. Bishop, Pattern Recognition and Machine Learning, Springer, \href{{https://www.springer.com/gp/book/9780387310732}}{\nolinkurl{https://www.springer.com/gp/book/9780387310732}}. + +\item Ian Goodfellow, Yoshua Bengio, and Aaron Courville. The different chapters are available for free at \href{{https://www.deeplearningbook.org/}}{\nolinkurl{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. +\end{enumerate} + +\noindent +Additional textbooks: + +\begin{enumerate} +\item Trevor Hastie, Robert Tibshirani, Jerome H. Friedman, The Elements of Statistical Learning, Springer, \href{{https://www.springer.com/gp/book/9780387848570}}{\nolinkurl{https://www.springer.com/gp/book/9780387848570}}. This is a well-known text and serves as additional literature. + +\item Aurelien Geron, Hands‑On Machine Learning with Scikit‑Learn and TensorFlow, O'Reilly, \href{{https://www.oreilly.com/library/view/hands-on-machine-learning/9781492032632/.}}{\nolinkurl{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. +\end{enumerate} + +\noindent +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Learning outcomes} + +\begin{block}{} + +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 + +\begin{itemize} +\item Learn about basic data analysis, statistical analysis, Bayesian statistics, Monte Carlo sampling, data optimization and machine learning; + +\item Be capable of extending the acquired knowledge to other systems and cases; + +\item Have an understanding of central algorithms used in data analysis and machine learning; + +\item Understand linear methods for regression and classification, from ordinary least squares, via Lasso and Ridge to Logistic regression; + +\item Learn about neural networks and deep learning methods for supervised and unsupervised learning. Emphasis on feed forward neural networks, convolutional and recurrent neural networks; + +\item Learn about about decision trees, random forests, bagging and boosting methods; + +\item Learn about support vector machines and kernel transformations; + +\item Reduction of data sets, from PCA to clustering; + +\item Autoencoders and Reinforcement Learning; + +\item 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. +\end{itemize} + +\noindent +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Topics covered in this course: Statistical analysis and optimization of data} + +The course has two central parts + +\begin{enumerate} +\item Statistical analysis and optimization of data + +\item Machine learning +\end{enumerate} + +\noindent +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 + +\begin{block}{Statistical analysis and optimization of data } + +We plan to cover the following topics: +\begin{itemize} +\item Basic concepts, expectation values, variance, covariance, correlation functions and errors; + +\item Simpler models, binomial distribution, the Poisson distribution, simple and multivariate normal distributions; + +\item Central elements of Bayesian statistics and modeling; + +\item Gradient methods for data optimization; + +\item Monte Carlo methods, Markov chains, Gibbs sampling and Metropolis-Hastings sampling (tentative); + +\item Estimation of errors and resampling techniques such as the cross-validation, blocking, bootstrapping and jackknife methods; + +\item Principal Component Analysis (PCA) and its mathematical foundation; +\end{itemize} + +\noindent +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Topics covered in this course} + +\begin{block}{} +The following topics will be covered + +\begin{itemize} +\item Pre deep-learning revolution (2008 approx) +\begin{itemize} + + \item Linear Regression and Logistic Regression, classification and regression problems; + + \item Bayesian linear and logistic regression, kernel regression; + + \item Decisions trees, Random Forests, Bagging and Boosting methods; + + \item Support vector machines (only survey); + + \item Unsupervised learning and dimensionality reduction, from PCA to clustering; + +\end{itemize} + +\noindent +\item Deep learning +\begin{itemize} + + \item Neural networks and deep learning; + + \item Convolutional neural networks; + + \item Recurrent neural networks; + + \item Autoencoders + + \item Generative methods with an emphasis on Boltzmann Machines, Variational Autoencoders and Generalized Adversarial Networks; +\end{itemize} + +\noindent +\end{itemize} + +\noindent +Hands-on demonstrations, exercises and projects aim at deepening your understanding of these topics. + +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Extremely useful tools, strongly recommended} + +\begin{block}{and discussed at the lab sessions } +\begin{itemize} + \item GIT for version control, and GitHub or GitLab as repositories, highly recommended. This will be discussed during the first exercise session + + \item Anaconda and other Python environments, see intro slides and links to programming resources at \href{{https://computationalscienceuio.github.io/RefreshProgrammingSkills/intro.html}}{\nolinkurl{https://computationalscienceuio.github.io/RefreshProgrammingSkills/intro.html}} +\end{itemize} + +\noindent +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Other courses on Data science and Machine Learning at UiO} + +The link here \href{{https://www.mn.uio.no/english/research/about/centre-focus/innovation/data-science/studies/}}{\nolinkurl{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. +\begin{enumerate} +\item \href{{https://www.uio.no/studier/emner/matnat/fys/FYS5419/index-eng.html}}{FYS5419 Quantum Computing and Quantum Machine Learning} + +\item \href{{https://www.uio.no/studier/emner/matnat/fys/FYS5429/index-eng.html}}{FYS5429 Advanced Machine Learning for the Physical Sciences} + +\item \href{{http://www.uio.no/studier/emner/matnat/math/STK2100/index-eng.html}}{STK2100 Machine learning and statistical methods for prediction and classification}. + +\item \href{{https://www.uio.no/studier/emner/matnat/ifi/IN3050/index-eng.html}}{IN3050/4050 Introduction to Artificial Intelligence and Machine Learning}. Introductory course in machine learning and AI with an algorithmic approach. + +\item \href{{http://www.uio.no/studier/emner/matnat/math/STK-INF3000/index-eng.html}}{STK-INF3000/4000 Selected Topics in Data Science}. The course provides insight into selected contemporary relevant topics within Data Science. + +\item \href{{https://www.uio.no/studier/emner/matnat/ifi/IN4080/index.html}}{IN4080 Natural Language Processing}. Probabilistic and machine learning techniques applied to natural language processing. + +\item \href{{https://www.uio.no/studier/emner/matnat/math/STK-IN4300/index-eng.html}}{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. + +\item \href{{https://www.uio.no/studier/emner/matnat/ifi/IN4310/index.html}}{IN3310/4310 Deep Learnig for Image Analysis} + +\item \href{{https://www.uio.no/studier/emner/matnat/math/STK4051/index-eng.html}}{STK4051 Computational Statistics} + +\item \href{{https://www.uio.no/studier/emner/matnat/math/STK4021/index-eng.html}}{STK4021 Applied Bayesian Analysis and Numerical Methods} +\end{enumerate} + +\noindent +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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 \href{{http://scikit-learn.org/stable/}}{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 +\textbf{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. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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 +\href{{http://scikit-learn.org/stable/}}{Scikit-learn}, +\href{{https://www.tensorflow.org/}}{Tensorflow}, +\href{{http://pytorch.org/}}{PyTorch} and \href{{https://keras.io/}}{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. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Types of Machine Learning} + +The approaches to machine learning are many, but are often split into +two main categories. In \emph{supervised learning} we know the answer to a +problem, and let the computer deduce the logic behind it. On the other +hand, \emph{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 +\emph{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: + +\begin{itemize} + \item 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. + + \item 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. + + \item Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning. +\end{itemize} + +\noindent +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Essential elements of ML} + +The methods we cover have three main topics in common, irrespective of +whether we deal with supervised or unsupervised learning. +\begin{itemize} +\pause +\item 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. + +\pause +\item 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. + +\pause +\item The last ingredient is a so-called \textbf{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. +\end{itemize} + +\noindent +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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 \textbf{gradient methods}. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{A Frequentist approach to data analysis} + +When you hear phrases like \textbf{predictions and estimations} and +\textbf{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 \href{{https://en.wikipedia.org/wiki/Frequentist_inference}}{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$. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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 $\bm{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 \emph{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 \emph{correct} model, there +could easily be many different models that fit the given data set \emph{equally well}. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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 \textbf{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. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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 \textbf{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 \textbf{pip} as + +\begin{enumerate} +\item pip install numpy scipy matplotlib ipython scikit-learn mglearn sympy pandas pillow +\end{enumerate} + +\noindent +For Python3, replace \textbf{pip} with \textbf{pip3}. + +For OSX users we recommend, after having installed Xcode, to +install \textbf{brew}. Brew allows for a seamless installation of additional +software via for example + +\begin{enumerate} +\item brew install python3 +\end{enumerate} + +\noindent +For Linux users, with its variety of distributions like for example the widely popular Ubuntu distribution, +you can use \textbf{pip} as well and simply install Python as + +\begin{enumerate} +\item sudo apt-get install python3 (or python for pyhton2.7) +\end{enumerate} + +\noindent +etc etc. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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 + +\begin{itemize} +\item \href{{https://docs.anaconda.com/}}{Anaconda}, +\end{itemize} + +\noindent +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 \textbf{conda}. + +\begin{itemize} +\item \href{{https://www.enthought.com/product/canopy/}}{Enthought canopy} +\end{itemize} + +\noindent +is a Python +distribution for scientific and analytic computing distribution and +analysis environment, available for free and under a commercial +license. + +Furthermore, \href{{https://colab.research.google.com/notebooks/welcome.ipynb}}{Google's Colab} is a free Jupyter notebook environment that requires +no setup and runs entirely in the cloud. Try it out! +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Useful Python libraries} + +Here we list several useful Python libraries we strongly recommend (if you use anaconda many of these are already there) + +\begin{itemize} +\item \href{{https://www.numpy.org/}}{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 + +\item \href{{https://pandas.pydata.org/}}{The pandas} library provides high-performance, easy-to-use data structures and data analysis tools + +\item \href{{http://xarray.pydata.org/en/stable/}}{Xarray} is a Python package that makes working with labelled multi-dimensional arrays simple, efficient, and fun! + +\item \href{{https://www.scipy.org/}}{Scipy} (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering. + +\item \href{{https://matplotlib.org/}}{Matplotlib} is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. + +\item \href{{https://github.com/HIPS/autograd}}{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 + +\item \href{{https://jax.readthedocs.io/en/latest/index.html}}{JAX} has now more or less replaced \textbf{Autograd}. JAX is Autograd and XLA, brought together for high-performance numerical computing and machine learning research. It provides composable transformations of Python+NumPy programs: differentiate, vectorize, parallelize, Just-In-Time compile to GPU/TPU, and more. + +\item \href{{https://www.sympy.org/en/index.html}}{SymPy} is a Python library for symbolic mathematics. + +\item \href{{https://scikit-learn.org/stable/}}{scikit-learn} has simple and efficient tools for machine learning, data mining and data analysis + +\item \href{{https://www.tensorflow.org/}}{TensorFlow} is a Python library for fast numerical computing created and released by Google + +\item \href{{https://keras.io/}}{Keras} is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano + +\item And many more such as \href{{https://pytorch.org/}}{pytorch}, \href{{https://pypi.org/project/Theano/}}{Theano} etc +\end{itemize} + +\noindent +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Installing R, C++, cython or Julia} + +You will also find it convenient to utilize \textbf{R}. We will mainly +use Python during our lectures and in various projects and exercises. +Those of you +already familiar with \textbf{R} should feel free to continue using \textbf{R}, keeping +however an eye on the parallel Python set ups. Similarly, if you are a +Python afecionado, feel free to explore \textbf{R} as well. Jupyter/Ipython +notebook allows you to run \textbf{R} codes interactively in your +browser. The software library \textbf{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 \textbf{R} with Jupyter notebook +\href{{https://mpacer.org/maths/r-kernel-for-ipython-notebook}}{follow the link here} +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{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, \textbf{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 +\href{{https://numba.pydata.org/}}{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 \textbf{PDF} file or a Latex file for +further processing. For example, convert to latex as + + + +\begin{minted}[fontsize=\fontsize{9pt}{9pt},linenos=false,mathescape,baselinestretch=1.0,fontfamily=tt,xleftmargin=2mm]{text} +pycod jupyter nbconvert filename.ipynb --to latex + +\end{minted} + + +And to add more versatility, the Python package \href{{http://www.sympy.org/en/index.html}}{SymPy} is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) and is entirely written in Python. + +Finally, if you wish to use the light mark-up language +\href{{https://github.com/hplgit/doconce}}{doconce} you can convert a standard ascii text file into various HTML +formats, ipython notebooks, latex files, pdf files etc with minimal edits. These lectures were generated using \textbf{doconce}. +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Numpy examples and Important Matrix and vector handling packages} + +There are several central software libraries for linear algebra and eigenvalue problems. Several of the more +popular ones have been wrapped into ofter software packages like those from the widely used text \textbf{Numerical Recipes}. The original source codes in many of the available packages are often taken from the widely used +software package LAPACK, which follows two other popular packages +developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly here. + +\begin{itemize} + \item LINPACK: package for linear equations and least square problems. + + \item LAPACK:package for solving symmetric, unsymmetric and generalized eigenvalue problems. From LAPACK's website \href{{http://www.netlib.org}}{\nolinkurl{http://www.netlib.org}} it is possible to download for free all source codes from this library. Both C/C++ and Fortran versions are available. + + \item BLAS (I, II and III): (Basic Linear Algebra Subprograms) are routines that provide standard building blocks for performing basic vector and matrix operations. Blas I is vector operations, II vector-matrix operations and III matrix-matrix operations. Highly parallelized and efficient codes, all available for download from \href{{http://www.netlib.org}}{\nolinkurl{http://www.netlib.org}}. +\end{itemize} + +\noindent +\end{frame} + +\begin{frame}[plain,fragile] +\frametitle{Basic Matrix Features} + +\begin{block}{Matrix properties reminder } +\[ + \mathbf{A} = + \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ + a_{21} & a_{22} & a_{23} & a_{24} \\ + a_{31} & a_{32} & a_{33} & a_{34} \\ + a_{41} & a_{42} & a_{43} & a_{44} + \end{bmatrix}\qquad +\mathbf{I} = + \begin{bmatrix} 1 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 0 \\ + 0 & 0 & 1 & 0 \\ + 0 & 0 & 0 & 1 + \end{bmatrix} +\] + +The inverse of a matrix is defined by + +\[ +\mathbf{A}^{-1} \cdot \mathbf{A} = I +\] + + +{\footnotesize +\begin{tabular}{ccc} +\hline +\multicolumn{1}{c}{ Relations } & \multicolumn{1}{c}{ Name } & \multicolumn{1}{c}{ matrix elements } \\ +\hline +$A=A^{T}$ & symmetric & $a_{ij}=a_{ji}$ \\ +$A=\left (A^{T}\right )^{-1}$ & real orthogonal & $\sum_k a_{ik}a_{jk}=\sum_k a_{ki} a_{kj}=\delta_{ij}$ \\ +$A=A^*$ & real matrix & $a_{ij}=a_{ij}^*$ \\ +$A=A^{\dagger}$ & hermitian & $a_{ij}=a_{ji}^*$ \\ +$A=\left(A^{\dagger}\right )^{-1}$ & unitary & $\sum_k a_{ik}a_{jk}^*=\sum_k a_{ki}^* a_{kj}=\delta_{ij}$ \\ +\hline +\end{tabular} +} + +\noindent +\end{block} +\end{frame} + +\begin{frame}[plain,fragile] +% No title on this slide + +\noindent\textbf{Some famous Matrices.} +\begin{itemize} + \item Diagonal if $a_{ij}=0$ for $i\ne j$ + + \item Upper triangular if $a_{ij}=0$ for $i>j$ + + \item Lower triangular if $a_{ij}=0$ for $ij+1$ + + \item Lower Hessenberg if $a_{ij}=0$ for $i1$ + + \item Lower banded with bandwidth $p$: $a_{ij}=0$ for $i>j+p$ + + \item Upper banded with bandwidth $p$: $a_{ij}=0$ for $i