From 85078d88c20357d08af8ee7e7520dc37684d385c Mon Sep 17 00:00:00 2001 From: mhjensen Date: Sat, 24 Mar 2018 12:48:20 -0400 Subject: [PATCH] Started adding material about Boltzmann Machines --- doc/src/BoltzmannMachines/BM.do.txt | 136 ++++++++++++++++++ .../beamerthemered_plain.sty | 12 ++ .../beamerthemered_shadow.sty | 15 ++ doc/src/BoltzmannMachines/clean.sh | 3 + doc/src/BoltzmannMachines/make.sh | 118 +++++++++++++++ doc/web/course.do.txt | 3 +- doc/web/course.html | 81 ++++++++--- 7 files changed, 345 insertions(+), 23 deletions(-) create mode 100644 doc/src/BoltzmannMachines/BM.do.txt create mode 100644 doc/src/BoltzmannMachines/beamerthemered_plain.sty create mode 100644 doc/src/BoltzmannMachines/beamerthemered_shadow.sty create mode 100755 doc/src/BoltzmannMachines/clean.sh create mode 100755 doc/src/BoltzmannMachines/make.sh diff --git a/doc/src/BoltzmannMachines/BM.do.txt b/doc/src/BoltzmannMachines/BM.do.txt new file mode 100644 index 000000000..e180f1acb --- /dev/null +++ b/doc/src/BoltzmannMachines/BM.do.txt @@ -0,0 +1,136 @@ +TITLE: Data Analysis and Machine Learning: Unsupervised Learning and Boltzmann Machines +AUTHOR: Morten Hjorth-Jensen {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University +DATE: today + +!split +===== What is Unsupervised Learning? ===== + + +The idea of representing the wave function in quantum mechanics with +a restricted Boltzmann machine (RBM) was presented recently by "G. Carleo and M. Troyer, Science _355_, Issue 6325, pp. 602-606 (2017)":"http://science.sciencemag.org/content/355/6325/602". They +named such a wave function/network a \textit{neural network quantum +state} (NQS). In their article they apply it to the quantum mechanical +spin lattice systems of the Ising model and Heisenberg model, with +encouraging results. + +=== Representing the wave function with a neural network === + +Our neural network of choice is the restricted Boltzmann machine. It +is a two layer net where one is called the layer of visible nodes and +the other the layer of hidden nodes. It is called restricted because +there are no connections between nodes in the same layer. Meaning +there's only a connection between two nodes if one is visible and the +other hidden. These type of networks constitute the building blocks of +the deep belief networks. The RBM is a +generative network, meaning that the idea is for it to learn a +\textit{probability distribution}. Thus the network does not produce +an output directly, but a probability distribution from which we can +generate an output. In our case this distribution corresponds to the +wave function and the output we wish to generate are the positions +taken by the particles in our system. + +Neural networks are referred to as falling +under either supervised or unsupervised learning. Here we are not +working with training data, thus it is not supervised. It's rather +called reinforcement learning. From the variational principle we know +that the NQS wave fucntion represents the ground state once the +quantum mechanical energy is minimized. This information is used to +optimize the weights and biases of the network. + +For more information and practical guides to the RBM, check out the links in the literature section. + +When working with the restricted Boltzmann machine we are given the joint probability distribution between the hidden and visible nodes. + +=== Restricted Boltzmann Machine (RBM) === + +The joint probability distribution is defined as +!bt +\begin{align} + F_{rbm}(\mathbf{X},\mathbf{H}) = \frac{1}{Z} e^{-\frac{1}{T_0}E(\mathbf{X},\mathbf{H})} +\end{align} +!et +where $Z$ is the partition function/normalization constant +!bt +\begin{align} + Z = \int \int \frac{1}{Z} e^{-\frac{1}{T_0}E(\mathbf{x},\mathbf{h})} d\mathbf{x} d\mathbf{h} +\end{align} +!et + +It is common to ignore $T_0$ by setting it to one. Here $E$ is known +as the energy of a configuration of the nodes. Do not confuse this +with the energy of the quantum mechanical system. Here it is a +function which gives the specifics of the relation between the hidden +and visible nodes. Different versions of RBMs will implement the +energy function differently. + +=== Gaussian-Binary RBM === + +The original and most common version of an RBM is called "binary-binary", meaning both visible and hidden nodes only take on binary values. In our case we wish to model continuous values (positions), thus the visible nodes should be continuous. We therefore choose an RBM called "Gaussian-binary". +!bt +\begin{align} + E(\mathbf{X}, \mathbf{H}) = \sum_i^M \frac{(X_i - a_i)^2}{2\sigma_i^2} - \sum_j^N b_j H_j - \sum_{i,j}^{M,N} \frac{X_i w_{ij} H_j}{\sigma_i^2} +\end{align} +!et +If $\sigma_i = \sigma$ then +!bt +\begin{align} + E(\mathbf{X}, \mathbf{H})= \frac{||\mathbf{X} - \mathbf{a}||^2}{2\sigma^2} - \mathbf{b}^T \mathbf{H} - \frac{\mathbf{X}^T \mathbf{W} \mathbf{H}}{\sigma^2} +\end{align} +!et +Here $\mathbf{X}$ are the visible nodes (the position coordinates), $\mathbf{H}$ are the hidden nodes, $\mathbf{a}$ are the visible biases, $\mathbf{b}$ are the hidden biases and $\mathbf{W}$ is a matrix containing the weights characterizing the connection of each visible node to a hidden node. + +=== The Wave Function === +To find the marginal probability $F_{rbm}(X)$ we set: +!bt +\begin{align} + F_{rbm}(\mathbf{X}) &= \sum_\mathbf{h} F_{rbm}(\mathbf{X}, \mathbf{h}) \\ + &= \frac{1}{Z}\sum_\mathbf{h} e^{-E(\mathbf{X}, \mathbf{h})} +\end{align} +!et +This is used to represent the wave function: +!bt +\begin{align} +\Psi (\mathbf{X}) &= F_{rbm}(\mathbf{X}) \\ +&= \frac{1}{Z}\sum_{\{h_j\}} e^{-E(\mathbf{X}, \mathbf{h})} \\ +&= \frac{1}{Z} \sum_{\{h_j\}} e^{-\sum_i^M \frac{(X_i - a_i)^2}{2\sigma^2} + \sum_j^N b_j h_j + \sum_{i,j}^{M,N} \frac{X_i w_{ij} h_j}{\sigma^2}} \\ +&= \frac{1}{Z} e^{-\sum_i^M \frac{(X_i - a_i)^2}{2\sigma^2}} \prod_j^N (1 + e^{b_j + \sum_i^M \frac{X_i w_{ij}}{\sigma^2}}) \\ +\end{align} +!et + +=== The Monte Carlo procedure === + +In many aspects, the procedure of optimizing the NQS wave function +will be very similar to the VMC method in project one. However, it +requires a heavier emphasis on the minimization process. Whereas in +project one you only had one or two parameters to optimize and could +even determine them analytically, in this situation the biases and +weights quickly add up to a high number of parameters to optimize, and +it's hard, if possible at all, to determine them analytically. Thus +minimizing the quantum mechanical energy and optimizing the parameters +is important from the beginning. Still, the structure of the process +is similar. You set up an initial guess of the NQS wave function by +giving the weights and biases random, preferably small values. The +process then follows the same structure as the VMC method. + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/src/BoltzmannMachines/beamerthemered_plain.sty b/doc/src/BoltzmannMachines/beamerthemered_plain.sty new file mode 100644 index 000000000..a6b2d33bd --- /dev/null +++ b/doc/src/BoltzmannMachines/beamerthemered_plain.sty @@ -0,0 +1,12 @@ +\mode +\usecolortheme[rgb={0.8, 0.2, 0}]{structure} +\usefonttheme[onlysmall]{structurebold} + +\setbeamertemplate{navigation symbols}{} +%\setbeamertemplate{footline}[frame number] + +\usepackage{tikz} +\usetikzlibrary{arrows,shapes,backgrounds,decorations,mindmap} + +\mode + diff --git a/doc/src/BoltzmannMachines/beamerthemered_shadow.sty b/doc/src/BoltzmannMachines/beamerthemered_shadow.sty new file mode 100644 index 000000000..eff5ac479 --- /dev/null +++ b/doc/src/BoltzmannMachines/beamerthemered_shadow.sty @@ -0,0 +1,15 @@ +\mode + +\useoutertheme{smoothbars} +\useinnertheme[shadow=true]{rounded} +\usecolortheme{orchid} +\usecolortheme{whale} +\usecolortheme[rgb={0.7, 0.2, 0}]{structure} % (darker red) +\useoutertheme{shadow} +\usefonttheme[onlysmall]{structurebold} + +\setbeamercolor{title}{use=structure,fg=white,bg=structure.fg} +\setbeamerfont{block title}{size={}} + +\mode + diff --git a/doc/src/BoltzmannMachines/clean.sh b/doc/src/BoltzmannMachines/clean.sh new file mode 100755 index 000000000..2e5da2c72 --- /dev/null +++ b/doc/src/BoltzmannMachines/clean.sh @@ -0,0 +1,3 @@ +#!/bin/sh +doconce clean +rm -rf *.pdf *.tex ipynb*.tar.gz *.html ._*.html *~ reveal.js Trash README.txt diff --git a/doc/src/BoltzmannMachines/make.sh b/doc/src/BoltzmannMachines/make.sh new file mode 100755 index 000000000..cd6f9422e --- /dev/null +++ b/doc/src/BoltzmannMachines/make.sh @@ -0,0 +1,118 @@ +v#!/bin/sh +set -x + +function system { + "$@" + if [ $? -ne 0 ]; then + echo "make.sh: unsuccessful command $@" + echo "abort!" + exit 1 + fi +} + +if [ $# -eq 0 ]; then +echo 'bash make.sh slides1|slides2' +exit 1 +fi + +name=$1 +rm -f *.tar.gz + +opt="--encoding=utf-8" +# Note: Makefile examples contain constructions like ${PROG} which +# looks like Mako constructions, but they are not. Use --no_mako +# to turn off Mako processing. +opt="--no_mako" + +rm -f *.aux + + +html=${name}-reveal +system doconce format html $name --pygments_html_style=perldoc --keep_pygments_html_bg --html_links_in_new_window --html_output=$html $opt +system doconce slides_html $html reveal --html_slide_theme=beige + +# Plain HTML documents + +html=${name}-solarized +system doconce format html $name --pygments_html_style=perldoc --html_style=solarized3 --html_links_in_new_window --html_output=$html $opt +system doconce split_html $html.html --method=space10 + +html=${name} +system doconce format html $name --pygments_html_style=default --html_style=bloodish --html_links_in_new_window --html_output=$html $opt +system doconce split_html $html.html --method=space10 + +# Bootstrap style +html=${name}-bs +system doconce format html $name --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=$html $opt +#system doconce split_html $html.html --method=split --pagination --nav_button=bottom + +# IPython notebook +system doconce format ipynb $name $opt + +# LaTeX Beamer slides +beamertheme=red_plain +system doconce format pdflatex $name --latex_title_layout=beamer --latex_table_format=footnotesize $opt +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 + +# Handouts +system doconce format pdflatex $name --latex_title_layout=beamer --latex_table_format=footnotesize $opt +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=red_shadow --handout +system pdflatex -shell-escape $name +pdflatex -shell-escape $name +pdflatex -shell-escape $name +pdfnup --nup 2x3 --frame true --delta "1cm 1cm" --scale 0.9 --outfile ${name}-beamer-handouts2x3.pdf ${name}.pdf +rm -f ${name}.pdf + +# Ordinary plain LaTeX document +rm -f *.aux # important after beamer +system doconce format pdflatex $name --minted_latex_style=trac --latex_admon=paragraph $opt +system doconce ptex2tex $name envir=minted +# Add special packages +doconce subst "% Add user's preamble" "\g<1>\n\\usepackage{simplewick}" $name.tex +doconce replace 'section{' 'section*{' $name.tex +pdflatex -shell-escape $name +pdflatex -shell-escape $name +mv -f $name.pdf ${name}-minted.pdf +cp $name.tex ${name}-plain-minted.tex + + + +# Publish +dest=../../pub +if [ ! -d $dest/$name ]; then +mkdir $dest/$name +mkdir $dest/$name/pdf +mkdir $dest/$name/html +mkdir $dest/$name/ipynb +fi +cp ${name}*.pdf $dest/$name/pdf +cp -r ${name}*.html ._${name}*.html reveal.js $dest/$name/html + +# Figures: cannot just copy link, need to physically copy the files +if [ -d fig-${name} ]; then +if [ ! -d $dest/$name/html/fig-$name ]; then +mkdir $dest/$name/html/fig-$name +fi +cp -r fig-${name}/* $dest/$name/html/fig-$name +fi + +cp ${name}.ipynb $dest/$name/ipynb +ipynb_tarfile=ipynb-${name}-src.tar.gz +if [ ! -f ${ipynb_tarfile} ]; then +cat > README.txt < diff --git a/doc/web/course.html b/doc/web/course.html index 1a97c2c40..47d8d1ef0 100644 --- a/doc/web/course.html +++ b/doc/web/course.html @@ -83,24 +83,25 @@ div { text-align: justify; text-justify: inter-word; } None, '___sec7'), ('Support Vector Machines', 2, None, '___sec8'), - ('Python and Scikit Learn, a short guide', 2, None, '___sec9'), - ('Teach yourself C++', 2, None, '___sec10'), - ('Projects Fall 2017', 2, None, '___sec11'), - ('Project', 3, None, '___sec12'), - ('Course content', 3, None, '___sec13'), - ('Learning outcomes', 2, None, '___sec14'), - ('Prerequisites', 2, None, '___sec15'), - ('The course has two central parts', 2, None, '___sec16'), + ('Unsupervised Learning, Boltzmann Machines', 2, None, '___sec9'), + ('Python and Scikit Learn, a short guide', 2, None, '___sec10'), + ('Teach yourself C++', 2, None, '___sec11'), + ('Projects Fall 2017', 2, None, '___sec12'), + ('Project', 3, None, '___sec13'), + ('Course content', 3, None, '___sec14'), + ('Learning outcomes', 2, None, '___sec15'), + ('Prerequisites', 2, None, '___sec16'), + ('The course has two central parts', 2, None, '___sec17'), ('Statistical analysis and optimization of data', 3, None, - '___sec17'), - ('Machine learning', 3, None, '___sec18'), + '___sec18'), + ('Machine learning', 3, None, '___sec19'), ('"Possible ' 'textbooks":"https://github.com/CompPhysics/MachineLearning/tree/master/doc/Textbooks"', 2, None, - '___sec19')]} + '___sec20')]} end of tocinfo --> @@ -487,9 +488,45 @@ formulas in HTML or ipython notebook files. +

Unsupervised Learning, Boltzmann Machines

+ + + -

Python and Scikit Learn, a short guide

+

Python and Scikit Learn, a short guide

  • HTML format only:
  • @@ -502,7 +539,7 @@ formulas in HTML or ipython notebook files. -

    Teach yourself C++

    +

    Teach yourself C++

    • HTML format only:
    • @@ -515,9 +552,9 @@ formulas in HTML or ipython notebook files. -

      Projects Fall 2017

      +

      Projects Fall 2017

      -

      Project

      +

      Project

      • LaTeX and PDF:
      • @@ -536,7 +573,7 @@ formulas in HTML or ipython notebook files.
      -

      Course content

      +

      Course content

      Probability theory and statistical methods play a central role in science. Nowadays we are @@ -555,7 +592,7 @@ tools of probability theory, the aim of this course is to expose you to central This course covers thus topics like Monte Carlo methods and Markov chains, Bayesian statistics, error estimates, various linear methods, optimization of data and error analysis and central algorithms in machine learning. The course has several numerical projects and numerical exercises that are meant to illustrate the theory. -

      Learning outcomes

      +

      Learning outcomes

      The course introduces a variety of central algorithms and methods @@ -572,19 +609,19 @@ essential for studies of data analysis and machine learning. The course is proje

    • Work on numerical projects to illustrate the theory. The projects play a central role and students are expected to know modern programming languages like Python or C++.
    -

    Prerequisites

    +

    Prerequisites

    Basic knowledge in programming and numerics. 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-INF1xxx. -

    The course has two central parts

    +

    The course has two central parts

    1. Statistical analysis and optimization of data
    2. Machine learning
    -

    Statistical analysis and optimization of data

    +

    Statistical analysis and optimization of data

    The following topics will be covered @@ -601,7 +638,7 @@ The following topics will be covered

  • Practical optimization using Singular-value decomposition and least squares for parameterizing data.
-

Machine learning

+

Machine learning

The following topics will be covered @@ -617,7 +654,7 @@ The following topics will be covered All the above topics will be supported by examples, hands-on exercises and project work. -

Possible textbooks

+

Possible textbooks

General learning book on statistical analysis: