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
(Improving the "Minimal examples" section)
(how to install Theano, Keras, Matplotlib, ... on Windows)
Line 34: Line 34:
 
=== Installation instructions ===
 
=== Installation instructions ===
  
Note for Linux/Mac: the monospaced text in this section are commands which are considered to be executed in the terminal. The "#" at the start of the line indicates that root privileges are required (so log in as root via <code>su</code>, or use <code>sudo</code> if this is configured suitably), whereas the commands starting with "$" can be executed as a normal user.
+
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 <code>su</code>, or use <code>sudo</code> 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 ====
 
==== Installing Python, Theano, Keras, Matplotlib and Jupyter ====
Line 53: Line 55:
 
*# <code># pip install keras</code>
 
*# <code># pip install keras</code>
  
* Windows: Sorry, we still have to figure out how it works for Windows.
+
* Windows
 +
*# Download and install the [https://conda.io/miniconda.html Miniconda collection] (make sure to select Python 3.x, the upper row).
 +
*# Create a Conda environment with <br/> <code>conda create --name neuralnets python=3.5</code> <br/> (note that keras does not run on python 3.6 yet) and activate it via <br/> <code>activate neuralnets</code>.
 +
*# <code>conda install jupyter h5py hdf5 libpython m2w64-toolchain matplotlib mkl-service nose nose-parameterized numpy scipy sphinx theano yaml</code>
 +
*# <code>pip install keras</code>
  
 
==== Configuration: tell Keras to use the Theano backend ====
 
==== Configuration: tell Keras to use the Theano backend ====

Revision as of 17:18, 6 May 2017

MachineLearningHeader.png

Basic Information about this Lecture Series

  • Contact: Florian.Marquardt@fau.de
  • 2 hours/week, 5 ECTS credit points
  • Time/place: This can still be discussed, but for now I have reserved lecture hall F on Monday 18:00-20:00 and on 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.
  • First lecture: Monday, May 8, 2017; 18:00, lecture hall F
  • Further lecture times: See time table below.

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 70s, 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.


Preliminary Schedule

MachineLearningSchedule.png

Installation instructions

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 and install the Anaconda collection (make sure to select Python 3.x, the green button).
    2. # conda install jupyter Theano
    3. # pip install keras
  • Windows
    1. Download and install the Miniconda collection (make sure to select Python 3.x, the upper row).
    2. 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.
    3. conda install jupyter h5py hdf5 libpython m2w64-toolchain matplotlib mkl-service nose nose-parameterized numpy scipy sphinx theano yaml
    4. pip install keras

Configuration: tell Keras to use the Theano backend

  • Linux/Mac:
    1. $ python3 -c "import keras"
      This command will probably fail as it tries to load TensorFlow, but this is OK. Its purpose is to initialize a .keras folder in your home directory
    2. edit file ".keras/keras.json" in your home directory: replace "tensorflow" with "theano"
  • Windows: Sorry, we still have to figure out how it works for Windows.

Minimal examples

After the previous steps, the following scripts should work for you (download the scripts, rename the file extension from ".txt" to ".py", and execute via $ python3 <script.py>, e.g. $ python3 theano_minimal.py):

Minimal example for Theano

TODO: minimal example for keras

Minimal example for Matplotlib

In addition, you should be able to start a Jupyter notebook via $ jupyter notebook.

Links