2017 Machine Learning for Physicists, by Florian Marquardt

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

Jump to: navigation, search

MachineLearningHeader.png

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.
  • 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