Difference between revisions of "2017 Machine Learning for Physicists, by Florian Marquardt"

From Institute for Theoretical Physics II / University of Erlangen-Nuremberg

Jump to: navigation, search
(fixed stupid copy-paste mistake)
 
(46 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[File:MachineLearningHeader.png]]
 
[[File:MachineLearningHeader.png]]
 +
 +
'''Visit the new official domain [https://machine-learning-for-physicists.org machine-learning-for-physicists.org], where we collected all the videos and slides for quick download!'''
  
 
=== Basic Information about this Lecture Series ===
 
=== Basic Information about this Lecture Series ===
Line 6: Line 8:
 
* 2 hours/week, 5 ECTS credit points
 
* 2 hours/week, 5 ECTS credit points
 
* '''Mailing list''': If you are a regular student, please join the [https://www.studon.fau.de/studon/ilias.php?ref_id=1877317&cmdClass=ilcourseregistrationgui&cmd=show&cmdNode=r4:h3:72&baseClass=ilRepositoryGUI studon course "Machine Learning for Physicists 2017"]. If you are a PhD student (without a studon account), please send an email to [mailto:marquardt-office@mpl.mpg.de marquardt-office@mpl.mpg.de] (Gesine Murphy), with the subject line "MACHINE LEARNING". Then you will be added to a mailing list.  
 
* '''Mailing list''': If you are a regular student, please join the [https://www.studon.fau.de/studon/ilias.php?ref_id=1877317&cmdClass=ilcourseregistrationgui&cmd=show&cmdNode=r4:h3:72&baseClass=ilRepositoryGUI studon course "Machine Learning for Physicists 2017"]. If you are a PhD student (without a studon account), please send an email to [mailto:marquardt-office@mpl.mpg.de marquardt-office@mpl.mpg.de] (Gesine Murphy), with the subject line "MACHINE LEARNING". Then you will be added to a mailing list.  
* '''Time/place''': Monday 18:00-20:00 and Thursday, 18:00-20:00. The reason for reserving two slots per week is that I will be traveling quite a bit during the summer term, so in some weeks we will have no lectures, whereas in others there will be two (i.e., on average, one lecture per week). The reason I believe such a late time slot is helpful is that it will not conflict with other lectures or tutorials, hopefully enabling anyone interested to attend. Note: Some students may also wish to attend the lecture on complex systems by Claus Metzner, which has some common themes with the present lecture.
+
* '''Time/place''': Monday 18:00-20:00 and Thursday, 18:00-20:00. (though not every week; see schedule below!)
 +
* '''Video''': [https://www.video.uni-erlangen.de/course/id/574.html Videos of the lectures] (made available weekly)
 
* '''First lecture''': Monday, May 8, 2017; 18:00, lecture hall F
 
* '''First lecture''': Monday, May 8, 2017; 18:00, lecture hall F
 
* '''Second lecture''': Thursday, May 11, 18:00, lecture hall D (!)
 
* '''Second lecture''': Thursday, May 11, 18:00, lecture hall D (!)
* '''Further lecture times''': See time table below. We are still figuring out the place: we try to reserve the largest lecture hall available. You will find the place here.
+
* '''Third lecture''': Monday, May 22, 18:00, lecture hall G
 +
* '''Further lecture times''': See time table below. From now on, we will always be in lecture hall G.
 +
* '''EXAM''': Written exam August 9th, 10:00-12:00. Lecture hall D. Please be there a few minutes earlier! During the exam, one A4 page of notes (handwritten by yourself, both sides if needed) is allowed, but nothing more.
 +
* '''REPEAT EXAM''': Written exam, Wednesday, October 11, 10:00-12:00. Lecture hall B. Please be there a few minutes earlier! During the exam, one A4 page of notes (handwritten by yourself, both sides if needed) is allowed, but nothing more.
 +
* '''Example Questions''': Here is a '''[[Media:2017_MachineLearning_TestQuestionsV2.pdf | test problem set]]''', for practice.
 +
* Repetition exam on October 11, 10:00-12:00, lecture hall E.
  
 
'''Description''': This is a course introducing modern techniques of machine learning, especially deep neural networks, to an audience of physicists. Neural networks can be trained to perform many challenging tasks, including image recognition and natural language processing, just by showing them many examples. While neural networks have been introduced already in the 50s, they really have taken off in the past decade, with spectacular successes in many areas. Often, their performance now surpasses humans, as proven by the recent achievements in handwriting recognition and in [http://www.nature.com/news/google-ai-algorithm-masters-ancient-game-of-go-1.19234 winning the game of 'Go'] against expert human players. They are now also being considered more and more for applications in physics, ranging from predictions of material properties to analyzing phase transitions.
 
'''Description''': This is a course introducing modern techniques of machine learning, especially deep neural networks, to an audience of physicists. Neural networks can be trained to perform many challenging tasks, including image recognition and natural language processing, just by showing them many examples. While neural networks have been introduced already in the 50s, they really have taken off in the past decade, with spectacular successes in many areas. Often, their performance now surpasses humans, as proven by the recent achievements in handwriting recognition and in [http://www.nature.com/news/google-ai-algorithm-masters-ancient-game-of-go-1.19234 winning the game of 'Go'] against expert human players. They are now also being considered more and more for applications in physics, ranging from predictions of material properties to analyzing phase transitions.
Line 29: Line 37:
 
All the software above is open source and freely available for a large number of platforms. See also the [[#Installation instructions|Installation instructions]] section below.
 
All the software above is open source and freely available for a large number of platforms. See also the [[#Installation instructions|Installation instructions]] section below.
  
=== Files ===
+
=== Lecture Notes and Files ===
  
* [[Media:MachineLearning2017_1.pdf | PDF Slides Lecture 1 (8.5.2017)]]
+
* '''[[Media:MachineLearning2017_1.pdf | PDF Slides Lecture 1 (8.5.2017)]]'''
* Here you would find the python source code, once we find out how to upload that into the wiki (which refuses code...)
+
* '''[[Media:MachineLearning2017_2_v2.pdf | PDF Slides Lecture 2 v2 (11.5.2017)]]'''
* [[Media:MachineLearning2017_2_v2.pdf | PDF Slides Lecture 2 v2 (11.5.2017)]]
+
* '''[[Media:PythonCheatSheet.pdf | PDF The Python Cheat Sheet]] (many useful examples, on 2 pages)'''
 +
* [[Media:MultiLayerNet_SimpleExample.py | python code for visualizing the output of a multilayer network]] (demonstrates batch processing and produces a nice picture)
 +
* '''[[Media:MachineLearning2017_3_v4.pdf | PDF Slides Lecture 3 v4 (22.5.2017)]]'''
 +
* [[Media:MachineLearning_2017_BackProp.py | python code for full backpropagation algorithm (without example)]]
 +
* [https://www.dropbox.com/s/6jyo1a86m8rgev4/MultiLayerBackProp.ipynb?dl=0 Jupyter Notebook for backpropagation and example] (as in the lecture; '''Note''': After downloading, in some browsers, you may have to remove the ending ".txt", such that the file has the ending ".ipynb"; then use "jupyter notebook" and open the file!)
 +
* '''[[Media:MachineLearning2017_4_v1.pdf | PDF Slides Lecture 4 v1 (29.5.2017)]]'''
 +
* [https://www.dropbox.com/s/7qd38brzm310ug5/MultiLayer_ImageCompression.ipynb?dl=0 Jupyter Notebook for Image Representation], also download the sample pictures: [https://www.dropbox.com/s/e14tlsioldjy2f7/ImageCompression_ExampleSimple.png?dl=0 Smiley] and [https://www.dropbox.com/s/tzvmdc5pgaracpy/ImageCompression_Example.png?dl=0 Emmy] (if you want to use your own image, use a square image or revise the code!)
 +
* [https://www.dropbox.com/s/dk9gora6xfer77f/KerasMultiLayer_ImageCompression.ipynb?dl=0 Jupyter Notebook Image Representation with Keras] (uses keras, otherwise the same functionality as above)
 +
* '''[[Media:MachineLearning2017_5_v1.pdf | PDF Slides Lecture 5 v1 (8.6.2017)]]'''
 +
* [https://www.dropbox.com/s/1dlnz0efuvbrfsf/HandwrittenDigitsRecognition_MNISTclean.ipynb?dl=0 Jupyter Notebook Handwritten Digit Recognition with Keras] (needs MNIST data file, see below)
 +
* [https://www.dropbox.com/s/g800iwm5atocj0h/mnist.pkl.gz?dl=0 MNIST training images] (17 MB, in a compressed format which can be read by the notebook above); Note: This is the version available from Nielsen's website for his [http://neuralnetworksanddeeplearning.com/chap1.html deep learning book]: it is contained in the [https://github.com/mnielsen/neural-networks-and-deep-learning/archive/master.zip  code package for that book]. The original version is available from [http://yann.lecun.com/exdb/mnist/ Yann LeCun's website], together with a list of training results for various machine learning approaches!
 +
* '''[[Media:MachineLearning2017_6_v1.pdf | PDF Slides Lecture 6 v1 (19.6.2017)]]'''
 +
* [https://www.dropbox.com/s/m9c9iu3ob4z8sgg/AutoencoderExample.ipynb?dl=0 Autoencoder Example] (jupyter notebook)
 +
* [https://www.dropbox.com/s/zqr36bt3afpw0sd/HandwrittenDigitsRecognition_MNISTclean_Conv.ipynb?dl=0 MNIST recognition with a convolutional net]
 +
* '''[https://www.dropbox.com/s/9vjnbyg0u3bzgpy/MachineLearning_7.pdf?dl=0 PDF Slides Lecture 7 v1 (26.6.2017)]''' (10 MB due to some large example images!)
 +
* '''[[Media:MachineLearning2017_8_v1.pdf | PDF Slides Lecture 8 v1 (29.6.2017)]]'''
 +
* [https://www.dropbox.com/s/31yab5qvggt8qwy/LSTM_simpleExamples_clean.ipynb?dl=0 Jupyter Notebook: Simple LSTM examples] (a network that memorizes a number and recalls it later upon request, and a network that counts down)
 +
* '''[[Media:MachineLearning2017_9_v1.pdf | PDF Slides Lecture 9 v1 (3.7.2017)]]'''
 +
* [https://www.dropbox.com/s/t7l1zj16teo8czm/Convolutional_Image_Recognition.ipynb?dl=0 Convolutional Image Recognition] - jupyter notebook for tutorial on 6.7. (simple image classification)
 +
* '''[[Media:MachineLearning2017_10_v1.pdf | PDF Slides Lecture 10 v1 (10.7.2017)]]'''
 +
* [https://www.dropbox.com/s/mehcsxmh0bhl2rw/SimpleRL_WalkerTarget.ipynb?dl=0 Simple Reinforcement Learning Example] - "Walker/Target" example, as explained in the lectures (jupyter notebook).
 +
* '''[[Media:MachineLearning2017_11_v1.pdf | PDF Slides Lecture 11 v1 (17.7.2017)]]'''
 +
* '''[[Media:MachineLearning2017_12_v1.pdf | PDF Slides Lecture 12 v1 (24.7.2017)]]'''
  
 
=== Preliminary Schedule ===
 
=== Preliminary Schedule ===

Latest revision as of 12:23, 21 January 2018

MachineLearningHeader.png

Visit the new official domain machine-learning-for-physicists.org, where we collected all the videos and slides for quick download!

Basic Information about this Lecture Series

  • Contact: Florian.Marquardt@fau.de
  • 2 hours/week, 5 ECTS credit points
  • Mailing list: If you are a regular student, please join the studon course "Machine Learning for Physicists 2017". If you are a PhD student (without a studon account), please send an email to marquardt-office@mpl.mpg.de (Gesine Murphy), with the subject line "MACHINE LEARNING". Then you will be added to a mailing list.
  • Time/place: Monday 18:00-20:00 and Thursday, 18:00-20:00. (though not every week; see schedule below!)
  • Video: Videos of the lectures (made available weekly)
  • First lecture: Monday, May 8, 2017; 18:00, lecture hall F
  • Second lecture: Thursday, May 11, 18:00, lecture hall D (!)
  • Third lecture: Monday, May 22, 18:00, lecture hall G
  • Further lecture times: See time table below. From now on, we will always be in lecture hall G.
  • EXAM: Written exam August 9th, 10:00-12:00. Lecture hall D. Please be there a few minutes earlier! During the exam, one A4 page of notes (handwritten by yourself, both sides if needed) is allowed, but nothing more.
  • REPEAT EXAM: Written exam, Wednesday, October 11, 10:00-12:00. Lecture hall B. Please be there a few minutes earlier! During the exam, one A4 page of notes (handwritten by yourself, both sides if needed) is allowed, but nothing more.
  • Example Questions: Here is a test problem set, for practice.
  • Repetition exam on October 11, 10:00-12:00, lecture hall E.

Description: This is a course introducing modern techniques of machine learning, especially deep neural networks, to an audience of physicists. Neural networks can be trained to perform many challenging tasks, including image recognition and natural language processing, just by showing them many examples. While neural networks have been introduced already in the 50s, they really have taken off in the past decade, with spectacular successes in many areas. Often, their performance now surpasses humans, as proven by the recent achievements in handwriting recognition and in winning the game of 'Go' against expert human players. They are now also being considered more and more for applications in physics, ranging from predictions of material properties to analyzing phase transitions.

Contents: We will cover the basics of neural networks (backpropagation), convolutional networks, autoencoders, restricted Boltzmann machines, and recurrent neural networks, as well as the recently emerging applications in physics. Time permitting, we will address other topics, like the relation to spin glass models, curriculum learning, reinforcement learning, adversarial learning, active learning, "robot scientists", deducing nonlinear dynamics, and dynamical neural computers.

Prerequisites: As a prerequisite you will only need matrix multiplication and the chain rule, i.e. the course will be understandable to bachelor students, master students and graduate students. However, knowledge of any computer programming language will make it much more fun. We will sometimes present examples using the 'python' programming language, which is a modern interpreted language with powerful linear algebra and plotting functions.

Book: The first parts of the course will rely heavily on the excellent and free online book by Nielsen: "Neural Networks and Deep Learning"

Software: Modern standard computers are powerful enough to run neural networks in a reasonable time. The following list of software packages helps to keep the programming effort low (it is possible to implement advanced structures like a deep convolutional neural network in only a dozen lines of code, which is quite amazing):

  • Python is a widely used high-level programming language for general-purpose programming; both Theano and Keras are Python moduls. We highly recommend the usage of the 3.x branch (cmp. Python2 vs Python3).
  • Theano is a numerical computation library for Python. In Theano, computations are expressed using a NumPy-like syntax and compiled to run efficiently on either CPU or GPU architectures. Therefore, Theano provides the low-level tools (multi-dimensional arrays, convolutional layers, efficient computation of the gradient, ...) needed to implement artificial neural networks.
  • Keras is a high-level framework for neural networks, running on top of Theano. Designed to enable fast experimentation with deep neural networks, it focuses on being minimal, modular and extensible.
  • Matplotlib is a plotting library for the Python programming language. We use it to visualize our results.
  • Jupyter is a browser-based application that allows to create and share documents that contain live (Python) code, equations, visualizations and explanatory text. So, Jupyter serves a similar purpose like Mathematica notebooks.

All the software above is open source and freely available for a large number of platforms. See also the Installation instructions section below.

Lecture Notes and Files

Preliminary Schedule

MachineLearningSchedule.png

Installation instructions

The following instructions should be quite detailed and easy to follow. If you nevertheless encounter a problem which you cannot solve for yourself, please write an email to Thomas Foesel.

Note: the monospaced text in this section are commands which have to be executed in a terminal.

  • for Linux/Mac: The terminal is simply the system shell. The "#" at the start of the line indicates that root privileges are required (so log in as root via su, or use sudo if this is configured suitably), whereas the commands starting with "$" can be executed as a normal user.
  • for Windows: Type the commands into the Conda terminal which is part of the Miniconda installation (see below).

Installing Python, Theano, Keras, Matplotlib and Jupyter

In the following, we show how to install these packages on the three common operating systems. There might be alternative ways to do so; if you prefer another one that works for you, this is also fine, of course.

  • Linux
    • Debian/Mint/Ubuntu/...
      1. # apt-get install python3 python3-dev python3-matplotlib python3-nose python3-numpy python3-pip
      2. # pip3 install jupyter keras Theano
    • openSUSE
      1. # zypper in python3 python3-devel python3-jupyter_notebook python3-matplotlib python3-nose python3-numpy-devel
      2. # pip3 install Theano keras
  • Mac
    1. Download the installation script for the Miniconda collection (make sure to select Python 3.x, the upper row). In the terminal, go into the directory of this file ($ cd ...) and run # bash Miniconda3-latest-MacOSX-x86_64.sh.
    2. Because there are more recent Conda versions than on the website, update it via conda update conda.
    3. Create a Conda environment with
      $ conda create --name neuralnets python=3.5
      (note that keras does not run on python 3.6 yet) and activate it via
      $ source activate neuralnets.
    4. $ conda install numpy scipy mkl nose sphinx theano pygpu yaml hdf5 h5py jupyter matplotlib
    5. $ pip install keras
  • Windows
    1. Download and install the Miniconda collection (make sure to select Python 3.x, the upper row).
    2. Because there are more recent Conda versions than on the website, update it via conda update conda.
    3. Create a Conda environment with
      conda create --name neuralnets python=3.5
      (note that keras does not run on python 3.6 yet) and activate it via
      activate neuralnets.
    4. conda install jupyter h5py hdf5 libpython m2w64-toolchain matplotlib mkl-service nose nose-parameterized numpy scipy sphinx theano yaml
    5. pip install keras

Configuration: protecting Jupyter

Important: If you intend to run Jupyter on a multi-user system (like the CIP pool), it is absolutely necessary to protect it against arbitrary code execution by other users. The instructions can be found here.

Configuration: tell Keras to use the Theano backend

  1. Load Keras into Python (this command will probably fail as it tries to load TensorFlow, but this is OK. Its purpose is to initialize the ".keras" folder):
    • on Linux: $ python3 -c "import keras"
    • on Mac: $ source activate neuralnets; python -c "import keras"
    • on Windows:
      activate neuralnets
      python -c "import keras"
  2. edit file ".keras/keras.json" in your home directory: replace "tensorflow" with "theano". To do that,
    • on Linux/Mac: open file "~/.keras/keras.json" in your home directory with your preferred text editor (either with command line editors like $ vi ~/.keras/keras.json, $ emacs ~/.keras/keras.json and $ nano ~/.keras/keras.json, or any graphical text editor)
    • on Windows:
      cd %USERPROFILE%
      notepad .keras/keras.json

Minimal examples

After the previous steps, the following scripts should work for you :

Minimal example for Matplotlib

Minimal example for Theano

Minimal example for Keras

To check this, download the scripts, rename the file extension from ".txt" to ".py", and execute them

  • on Linux: $ python3 <script.py>, e.g. $ python3 theano_minimal.py
  • on Mac (with Miniconda):
    1. $ source activate neuralnets (has to be done once in each new shell session)
    2. $ python <script.py>, e.g. $ python theano_minimal.py
  • on Windows (with Miniconda):
    1. activate neuralnets (has to be done once in each new shell session)
    2. python.exe <script.py>, e.g. $ python.exe theano_minimal.py (in the Conda shell, also python <script.py> should work)

In the same way, you should also be able to execute your own Python scripts. If you call $ python3/$ python/python.exe without an argument, an interactive session is started, i.e. you can directly enter Python commands into the terminal.

In addition, you should be able to start a Jupyter notebook via $ jupyter notebook (will automatically open a browser tab where you can work).

Links