% Created 2016-09-05 Mon 12:40
\documentclass[listings, a4paper, fleqn, pdftex, 12pt, openany, oneside, final]{memoir}
\makeatletter
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{bm}
\usepackage{fourier}
\usepackage[pdftex]{graphicx}
\usepackage{subfig}
\usepackage{color}
\usepackage{natbib}
\usepackage{hyperref}%[pdftex,colorlinks=true,citecolor=blue]{hyperref}
\usepackage{lscape}
\usepackage{soul}
\usepackage{tabularx}
\usepackage{booktabs}
%\usepackage{listings}
%\usepackage{listing}
\usepackage{minted}
\chapterstyle{verville}
\beforechapskip=-17mm
\textwidth=167mm
\textheight=230mm
\voffset=-10mm
\oddsidemargin=-4mm
\evensidemargin=-4mm
%%%               Vectors                          %%%
\renewcommand{\vec}[1]{\bm{#1}}
\renewcommand{\Vec}[1]{\overline{#1}}
\newcommand{\mat}[1]{\mathbf{#1}}
\newcommand{\gmat}[1]{\vec{#1}}
%%%     Products, derivatives etc.         %%%
\newcommand{\vprod}[2]{\left[#1\times #2\right]}
\newcommand{\sprod}[2]{#1\cdot #2}
\newcommand{\der}[2]{\frac{d #1}{d #2}}
\newcommand{\Der}[2]{\frac{d}{d #2}\left(#1\right)}
\newcommand{\pder}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\Pder}[2]{\frac{\partial}{\partial #2}\left(#1\right)}
\newcommand{\dder}[2]{\frac{\delta #1}{\delta #2}}
\DeclareMathOperator{\grad}{grad}
\DeclareMathOperator{\Div}{div}
\DeclareMathOperator{\erfc}{erfc}
\DeclareMathOperator{\Expect}{E}
\DeclareMathOperator{\Var}{Var}
\newcommand{\mean}[1]{\langle #1 \rangle}
\newcommand{\const}{\mathop{\mathrm{const}}}
\newcommand{\dimension}[1]{\left[\mathrm{#1}\right]}
%%%     Project specific                         %%%
\newcommand{\Diff}{\mathcal{D}}
%%%%%%%%%%          Alexey's comments                       %%%%%%%%%%
\newcommand{\alemph}[1]{\colorbox{yellow}{#1}}
\newcommand{\red}[1]{{\color{red}#1}}
\newcommand{\alnew}[1]{%\\ul{%
  \textit{#1}%}%
}
%%%%%%%%%%    Hypothesis                                          %%%%%%%%%%
\theoremstyle{definition}
\newtheorem{hypothesis}{Hypothesis}
%%%%% to avoid orphans and widows
\widowpenalty3000
\clubpenalty3000
%%% Common Lisp shortcut for minted
\newminted{cl}{}
\makeatother
\author{alexey}
\date{\today}
\title{}
\hypersetup{
 pdfauthor={alexey},
 pdftitle={},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 24.5.1 (Org mode 8.3.5)},
 pdflang={English}}
\begin{document}

\tableofcontents

\chapter{Parameter container: complete example}
\label{sec:orgheadline7}
\section{Model}
\label{sec:orgheadline6}
\subsection{Description}
\label{sec:orgheadline1}
This model is based on plug-flow reactor (PFR) example (Levenspiel,
1999; page 106). PFR can be viualised as a tube whith input steam
flowing into one side and output streams coming from another
side. Inside the tube some conversion occurs that alters the
composition of the input stream. The typical characteristic of a
(ideal) PFR are:
\begin{itemize}
\item Conversion is gradual and
\item There is no back-mixing of the flowing stream.
\end{itemize}

These characteristics make it easy to write mass-balance of PFR find
the extent of conversion of the input stream. Conversion is defined as
one minus the ratio of what is coming out over what came in, or more
formally, conversion of the species \(A\) is

\begin{equation}
\label{eq:1}
X_{A} = \left(1 - \frac{F_{A,out}}{F_{A,in}} \right)\times 100\%
\end{equation}
where \(F_{A}\) is molar (or mass) flow rate (in, for example, mol/h). For
bravity, we will not be deriing any mass balance equations for PFR,
but only use a couple of results from Levenspiel, 1999.

PFR is proposed for the decomposition of
phosphine
\begin{equation*}
4\mathrm{PH}_{3g }\to \mathrm{P}_{4(g)} + 6\mathrm{H}_{2}
\end{equation*}
Denote \(A = \mathrm{PH}_{3}\), \(B = \mathrm{P}_{4}\) and \(S =
\mathrm{H}_{2}\). Reaction rate (i.e. the rate at which \(A\) disappears) is
defined using equation:
\begin{equation}
-r_{A}=kC_{A}
\end{equation}
with rate constant \(k\) being dependent on temperature according to
\emph{Arrhenius law}:
\begin{equation}
k=k_{0} e^{-E/R(1/T-1/T_{0})}
\end{equation}

The volume of the reactor required to achieve the conversion \(X_{A}\) is
defined by the equation (Levenspiel, 1999; equation 21):
\begin{equation}
\label{eq:pfr-vol}
V=\frac{F_{A0}}{kC_{A0}}\left[(1+\varepsilon_{A})\ln{\frac{1}{1-X_{A}}} -\varepsilon_{A}X_{A}\right]
\end{equation}
where \(F_{A0}\) is input flow rate of A and \(C_{A0}\) is initial concentration
of A. Constant \(\varepsilon_{A}=(7-4)/4=0.75\) is defined via stoichiometry
(fractional change in volume).

Concentration can be determined from ideal gas law:
\begin{equation}
C_{A0}=\frac{p_{A0}}{RT}
\end{equation}
where \(p_{A0}\) is initial partial pressure of A, \(R\) is universal gas
constant and \(T\) is operating temperature.

This model can be used to estimate the volume of the reactor given
economical constraints. A default parameters are provided as a
guidence but are the subject to change (except for constant \(R\)).

\begin{center}
\begin{tabular}{lrl}
Parameter & Default value & Units\\
\hline
\(k_{0}\) & 10 & 1/h\\
\(E\) & 160 & kJ/mol\\
\(T_{0}\) & 600 & C\\
\(T\) & 650 & C\\
\(F_{A0}\) & 40 & mol/h\\
\(p\) & 4 & atm\\
\(R\) & 8.314 & J/ mol K\\
\end{tabular}
\end{center}

Our goal is to develop computer representation of this model.

\subsection{Reaction rate representation}
\label{sec:orgheadline2}
First, we need to represent the temperature dependence of the rate
constant

\begin{minted}[]{common-lisp}
(defconstant +universal-gas-constant+ 8.314d0
  "Universal gas constant R=8.314 J/mol K")

(defclass arrhenius-law ()
  ((reference-rate-constant
    :initarg :reference-rate-constant
    :accessor reference-rate-constant
    :documentation "Reference rate constant (k0)")
   (activation-energy
    :initarg :activation-energy
    :accessor activation-energy
    :documentation "Activation energy (Ea) in J/mol")
   (reference-temperature
    :initarg :reference-temperature
    :accessor reference-temperature
    :documentation "Reference temperature (T0) in K"))
  (:documentation
   "Arrhenius law of the reaction rate constant:
    k(T) = k0 * exp[- E/R * (1/T - 1/T0)]"))

(defmethod print-object ((object arrhenius-law) out)
  (with-slots ((k0 reference-rate-constant)
               (e activation-energy)
               (t0 reference-temperature))
      object
    (print-unreadable-object (object out :type t)
      (format out "~@<~:_k0 = ~A ~:_Ea = ~A J/mol ~:_T0 = ~A K~:>"
              k0 e t0))))

(defmethod rate-constant ((model arrhenius-law) temperature)
  (with-accessors ((k0 reference-rate-constant)
                   (e activation-energy)
                   (t0 reference-temperature))
      model
    (* k0 (exp (- (* (/ e +universal-gas-constant+) (- (/ temperature) (/ t0))))))))
\end{minted}

\subsection{Ideal gas law}
\label{sec:orgheadline3}
To find the concentration from given pressure and temperature:

\begin{minted}[]{common-lisp}
(defun ideal-gas-concentration (pressure temperature)
  "Calculates concentration (mol/m3) based in PRESSURE (Pa) and
temperature (K) using ideal gas law: c = p / RT"
  (/ pressure (* +universal-gas-constant+ temperature)))
\end{minted}

\subsection{Plug-flow reactor model for phosphine decomposition}
\label{sec:orgheadline4}
Plug flow reactor model is composed of the following parts:
\begin{itemize}
\item Inlet flow rate \(F_{A0}\),
\item Final (target) conversion \(X_{A}\),
\item Operating temperature \(T\),
\item Operating pressure \(p\), and
\item Reaction rate constant defined by Arrhenius law.
\end{itemize}

\begin{minted}[]{common-lisp}
(defclass PFR-phosphine ()
  ((inlet-flow-rate
    :initarg :inlet-flow-rate
    :documentation "F_A0 in mol/s"
    :accessor inlet-flow-rate)
   (final-conversion
    :initarg :final-conversion
    :accessor final-conversion
    :documentation "Target conversion X_A")
   (operating-temperature
    :initarg :operating-temperature
    :accessor operating-temperature
    :documentation "PFR operating temperature (K)")
   (operating-pressure
    :initarg :operating-pressure
    :accessor operating-pressure
    :documentation "PFR operating pressure (Pa)")
   (phosphine-decomposition-rate-coefficient
    :initarg :rate-coefficient
    :accessor phosphine-decomposition-rate-coefficient
    :documentation
    "Rate constant 'k' object specializing RATE-CONSTANT generic function"))
  (:documentation
   "Plug-flow-reactor for phosphine decomposition
    4PH3 -> P4 + 6H2"))

(defmethod print-object ((object PFR-phosphine) out)
  (with-slots ((f inlet-flow-rate)
               (x final-conversion)
               (temperature operating-temperature)
               (p operating-pressure)
               (rate-expression phosphine-decomposition-rate-coefficient))
      object
    (print-unreadable-object (object out :type t)
      (format out "~@<~:_F = ~A mol/s ~:_X = ~A ~:_T = ~A K ~:_p = ~A Pa~:>"
              f x temperature p))))
\end{minted}

Use equation \eqref{eq:pfg-vol} to calculate volume of the reactor:

\begin{minted}[]{common-lisp}
(defmethod PFR-phosphine-volume ((model pfr-phosphine))
  "Uses equation (Levenspiel, 1999; equation 21):
     F   _                          _
      A0|               1            |
V = ----| (1 + e )ln{------}  - e X  |
    kC  |       A    1 - X       A A |
      A0|_                A         _|

to calculate the volume of the plug-flow reactor
"
  (with-accessors ((f inlet-flow-rate)
                   (x final-conversion)
                   (temperature operating-temperature)
                   (p operating-pressure)
                   (rate phosphine-decomposition-rate-coefficient))
      model
    (let ((k (rate-constant rate temperature))
          (eps 0.75d0)
          (c (ideal-gas-concentration p temperature)))
      (* (/ f (* k c))
         (- (* (1+ eps) (log (/ (- 1 x))))
            (* eps x))))))
\end{minted}

\subsection{Model parameters}
\label{sec:orgheadline5}
The model consists of a large number of parameters. To complicate the
matter further, some parameters can be represented in different units
of measure. Just to keep the description short, the only different
units parameter we will consider is temperature. To assist in defining
the temperature in different units (Celcius, Kelvin or Fahrenheit) we
will use the following function:

\begin{minted}[]{common-lisp}
(defun make-temperature (default-value default-units name id)
  "Produces PARAMETER-OPTIONS parameter for temperature, represented
in different units: Celsius, Kelvin and Fahrenheit. Arguments:

DEFAULT-VALUE : default numerical value to be used
DEFAULT-UNITS : a keyword (:C, :K or :F) denoting default units
NAME          : a string name of the resulting PARAMETER-OPTIONS
ID            : a symbolic ID of the resulting PARAMETER-OPTIONS"
  (let* ((units (reverse
                 (remove-duplicates
                  (reverse (cons default-units '(:C :K :F))))))
         (values-units (mapcar
                        (lambda (to-units)
                          (list
                           to-units
                           (convert-temperature default-units
                                                to-units
                                                default-value)))
                        units)))
    (parameter
     :name name
     :id id
     :options
     (loop for (units value) in values-units
        collect (let ((units units))
                  (parameter
                   :name (format nil "Temperature in ~A" units)
                   :id units
                   :value value
                   :units (format nil "~A" units)
                   :constructor (lambda (x) (convert-temperature units :K x))))))))
\end{minted}

This function produces a value of type \texttt{PARAMETER-OPTIONS} to specify
the temperature in convenient units. It makes sure that the provided
\texttt{DEFAULT-UNITS} will be the default choice for units. It uses
\texttt{CONVERT-TEMPERATURE} to provide the conversions between different
units:

\begin{minted}[]{common-lisp}
(defmethod convert-temperature ((from (eql :C)) (to (eql :C)) value)
  "Converts temperature VALUE from units FROM to units TO"
  value)

(defmethod convert-temperature ((from (eql :F)) (to (eql :F)) value)
  value)

(defmethod convert-temperature ((from (eql :K)) (to (eql :K)) value)
  value)

(defmethod convert-temperature ((from (eql :F)) (to (eql :C)) value)
  (* 5/9 (- value 32d0)))

(defmethod convert-temperature ((from (eql :C)) (to (eql :F)) value)
  (+ 32d0 (* 9/5 value)))

(defmethod convert-temperature ((from (eql :C)) (to (eql :K)) value)
  (+ value 273.15d0))

(defmethod convert-temperature ((from (eql :K)) (to (eql :C)) value)
  (- value 273.15d0))

(defmethod convert-temperature ((from (eql :F)) (to (eql :K)) value)
  (convert-temperature :C :K (convert-temperature :F :C value)))

(defmethod convert-temperature ((from (eql :K)) (to (eql :F)) value)
  (convert-temperature :C :F (convert-temperature :K :C value)))
\end{minted}

Arrhenius law
parameters are grouped together to form \texttt{ARRHENIUS-LAW} object and the
rest: to form \texttt{PFR-PHOSPHINE}.

Firts, Arrhenius law parameters:

\begin{minted}[]{common-lisp}
(defun make-phosphine-default-arrhenius-law ()
  (parameter
   :name "Arrhenius law for phosphine decomposition"
   :id :rate-coefficient
   :children
   (list
    (parameter
     :name "Reference rate, k0"
     :id :reference-rate-constant
     :value 10d0
     :units "1/h"
     :constructor (lambda (x) (/ x 3600d0)))
    (parameter
     :name "Activation energy, Ea"
     :id :activation-energy
     :value 160d0
     :units "kJ/mol"
     :constructor (lambda (x) (* x 1000d0)))
    (make-temperature 649d0 :C "Reference temperature, T0" :reference-temperature))
   :constructor (lambda (&rest args)
                  (apply #'make-instance 'arrhenius-law args))))
\end{minted}

In PFR model parameters, to make things a bit more interesting and
help with testing, temperature is provided as an option of temperature
in either Celcius or Fahrenheit.

\begin{minted}[]{common-lisp}
(defun make-default-pfr-phosphine ()
  (parameter
   :name "PFR for phosphine decomposition"
   :children
   (list
    (parameter
     :name "Inlet flow rate"
     :value 40d0
     :perturbation 0.2d0
     :units "mol/h"
     :constructor (lambda (x) (/ x 3600d0)))
    (parameter
     :name "Final conversion"
     :value 80d0
     :units "%"
     :constructor (lambda (x) (/ x 100d0)))
    (make-temperature 1200.2d0 :F "Operating temperature" :operating-temperature)
    (parameter
     :name "Operating pressure"
     :value 4.55d0
     :units "atm"
     :constructor (lambda (x) (* x 1.01d5)))
    (make-phosphine-default-arrhenius-law))
   :constructor (lambda (&rest args)
                  (apply #'make-instance 'PFR-phosphine args))))

(defvar *PFR-synonyms*
  '(:temperature :operating-temperature
    :ref-rate :reference-rate-constant
    :ref-temperature :reference-temperature))
\end{minted}
\end{document}


\subsection{Diffeomorphisms}


\PassOptionsToPackage{log-declarations=false}{xparse}
\PassOptionsToPackage{no-math}{fontspec}
%\PassOptionsToPackage{draft}{graphicx}
\documentclass[aspectratio=169]{beamer}
\usepackage{fontspec,amsmath,unicode-math,physics,siunitx,subcaption,appendixnumberbeamer}

\useoutertheme{metropolis}
\useinnertheme{metropolis}
\usecolortheme{metropolis}
\usefonttheme{professionalfonts}

\setbeamerfont{title}{size=\LARGE, series=\bfseries}
\setbeamerfont{frametitle}{series=\bfseries}
\setbeamerfont{caption}{size=\footnotesize}
\setbeamerfont{caption name}{series=\bfseries}
\setbeamerfont{footnote}{size=\tiny}
\setbeamertemplate{title page}{
  \begin{minipage}[b]{\textwidth}
    \mbox{}\vfill
    \usebeamertemplate*{title}
    \usebeamertemplate*{title separator}
    \usebeamertemplate*{author}
    \usebeamertemplate*{date}
    \usebeamertemplate*{institute}
    \mbox{}\hfill\inserttitlegraphic
    \vspace{-1.5cm}
  \end{minipage}
}
\setbeamertemplate{section in toc}[sections numbered]
\makeatletter
\AtBeginSection{
  \ifbeamer@inframe
    \sectionpage
  \else
    \frame[plain]{\sectionpage}
  \fi
}
\makeatother

\setsansfont{FiraGO}[BoldFont=* SemiBold]
\setmonofont{Iosevka}
\setmathfont{fira-math.otf}[Path=fonts/, BoldFont=*, math-style=ISO, bold-style=ISO, mathrm=sym]

\captionsetup[sub]{font=footnotesize}

% Constants
\def\ee{{\symup{e}}}
\def\Tc{T_{\!\symup{c}}}
% Operators
\def\incr{{\symup{\Delta}}}
\def\trans{{\symup{T}}}
\def\opT{{\symbfup{T}}}
\def\opO{O}
\newcommand\trR[2][]{\symbfup{R}^{\,#1}_{#2}}
% Set
\def\domD{D}
\def\domN{{N_{\symup{s}}}}
% Decorations
\def\bm#1{{\symbf{#1}}}
\def\nearest#1{\langle#1\rangle}
\def\q#1{{\{#1\}}}
% Text
\def\const{\text{const}}

\newcommand\imageinput[2][]{\includegraphics[#1]{figures/#2}}

\def\CDk{CD-$k$}
\def\AdSCFT{AdS/CFT}

\title{Machine Learning and Ising Model}
\date{\today}
\author{Xiangdong Zeng (supervised by Ling-Yan Hung)}
\institute{Department of Physics, Fudan University}
\titlegraphic{\includegraphics[height=1.2cm]{figures/fudan-emblem.pdf}}
\date{June 8, 2018}

\begin{document}

\maketitle

\begin{frame}{Table of contents}
\begin{itemize}
  \item \textbf{Ising model}
    \begin{itemize}
      \item Statistical physics, critical behaviors, etc
      \item \textcolor{lightgray}{Monte Carlo simulation}
    \end{itemize}
  \item \textbf{Machine learning}
    \begin{itemize}
      \item Basic ideas
      \item Linear model
      \item Neural network
    \end{itemize}
  \item \textbf{Machine learning and renormalization group (RG)}
    \begin{itemize}
      \item Boltzmann machine and restricted Boltzmann machine (RBM)
      \item \textcolor{lightgray}{Contrastive divergence (\CDk{}) algorithm}
      \item RBM for MNIST and Ising model
      \item Convolution, wavelet transform, etc
    \end{itemize}
\end{itemize}
\end{frame}

\section{Part 1. Ising model}

\begin{frame}{Ising model}
\begin{itemize}
  \item ``Binary'' spins ($+1$ or $-1$) arranged in a lattice
  \item Simplest model for (anti)-ferromagnetism and phase transition
  \item Hamiltonian:
    \[
      H(\q{\sigma_i}) = -\sum_{\nearest{ij}} J_{ij}\sigma_i\sigma_j - \mu \sum_{i} B_i\sigma_i
                      = -J \sum_{\nearest{ij}} \sigma_i\sigma_j - \mu B \sum_{i} \sigma_i
    \]
  \item Probability of configuration $\q{\sigma_i}$:
    \[
      P(\q{\sigma_i}) = \frac{\ee^{-\beta H(\q{\sigma_i})}}{Z_N} \qc
      Z_N = \sum_\q{\sigma_i} \ee^{-\beta H(\q{\sigma_i})}
    \]
\end{itemize}
\end{frame}

\begin{frame}{Critical behaviors and RG}
\begin{itemize}
  \item Universality: $\xi\to\infty$ at critical point
  \item Partition function is scale-invariant
    \begin{itemize}
      \item Partition function:
        \[ Z_N = \sum_\q{\sigma_i} \ee^{-\beta H(\q{\sigma_i},\,\bm{K})} \]
      \item Hamiltonian:
        \[
            H(\q{\sigma_i},\,\bm{K})
          = - \sum_i K^{(1)}_i \sigma_i
            - \sum_{\nearest{ij}}  K^{(2)}_{ij}  \sigma_i\sigma_j
            - \sum_{\nearest{ijk}} K^{(3)}_{ijk} \sigma_i\sigma_j\sigma_k - \cdots
        \]
      \item Scale transformation:
        \[ N' = L^{-d} N \qc \xi' = L^{-1} \xi \]
      \item Summation over Kadanoff's block $\q{\sigma_i'}$:
        \[
          Z_{N'}
          = \sum_\q{\sigma'_i} \ee^{-\beta H^{\text{RG}}(\q{\sigma_i'},\,\bm{K}')}
          = \sum_\q{\sigma'_i} \sum_\q{\sigma_i}
            \ee^{-\beta \qty\big[H(\q{\sigma_i},\,\bm{K})
                 -\opT_\lambda(\q{\sigma_i},\,\q{\sigma_i'})]} \qc
          \bm{K}' = \trR{L}(\bm{K})
        \]
    \end{itemize}
\end{itemize}
\end{frame}

\section{Part 2. Machine learning}

\begin{frame}{Basic ideas}
\begin{itemize}
  \item Extract features from data, build models, make predictions or decisions with the help of
    computers
  \item Give machine the ability to ``learn''
  \item Categories:
    \begin{itemize}
      \item Supervised learning: regression, classification, etc
      \item Unsupervised learning: clustering, dimensionality reduction, etc
    \end{itemize}
  \item Main steps:
    \begin{enumerate}
      \item Build a reasonable model based on data's feature;
      \item Give the \alert{loss function};
      \item Train on the dataset (training set), find the parameters to minimize the loss function;
      \item Validate the model and parameters, fine tuning (validation set);
      \item Test the trained model on \emph{new} dataset (test set).
    \end{enumerate}
\end{itemize}
\end{frame}

\begin{frame}{Linear classifier (logistic regression)}
\begin{columns}[t]
  \begin{column}{0.52\textwidth}
    \begin{itemize}
      \item Hypothesis:
        \[ h_\bm{\theta} (\bm{x}) = \sigma(\bm{\theta}^\trans \bm{x}) \]
      \item Activation function:
        \[ \sigma(z) = \frac{1}{1+\ee^{-z}} \]
      \item Loss function:
        \[
          L(\bm{\theta})
          = \sum_{i=1}^m \log\qty\Big{1+\exp[-y^{(i)} h_\bm{\theta}\qty\big(\bm{x}^{(i)})]}
        \]
    \end{itemize}
  \end{column}
  \begin{column}{0.44\textwidth}
    \begin{figure}
      \centering
      \imageinput[width=0.9\textwidth]{linear-layer.pdf}
      \caption{Network structure of the linear classifier}
    \end{figure}
  \end{column}
\end{columns}
\end{frame}

\begin{frame}{Neural network}
\begin{columns}[t]
  \begin{column}{0.44\textwidth}
    \begin{figure}
      \centering
      \imageinput[height=3.8cm]{multipolar-neuron.png}
      \caption{A multipolar neuron \footnotemark}
    \end{figure}
  \end{column}
  \begin{column}{0.54\textwidth}
    \begin{figure}
      \centering
      \imageinput[height=3.8cm]{neural-net.pdf}
      \caption{A two-layer neural network (perceptron)}
    \end{figure}
  \end{column}
\end{columns}
\footnotetext{Source: \url{https://en.wikipedia.org/wiki/File:Blausen_0657_MultipolarNeuron.png}}
\end{frame}

\begin{frame}{Training results (linear model)}
\begin{figure}
  \centering
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \imageinput[width=4.5cm]{ising-learning-linear.pdf}
  \end{subfigure}
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \imageinput[width=4.5cm]{ising-learning-linear-scaled.pdf}
  \end{subfigure}
  \caption{Predict results on Ising lattice. (a) Original; (b) after scale transformation.}
\end{figure}
\end{frame}

\begin{frame}{Training results (neural network)}
\begin{figure}
  \centering
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \imageinput[width=4.5cm]{ising-learning-net.pdf}
  \end{subfigure}
  \begin{subfigure}[b]{0.45\textwidth}
    \centering
    \imageinput[width=4.5cm]{ising-learning-net-scaled.pdf}
  \end{subfigure}
  \caption{Predict results on Ising lattice. (a) Original; (b) after scale transformation.}
\end{figure}
\end{frame}

\section{Part 3. Machine learning and RG}

\begin{frame}{Energy-based model}
\begin{columns}[t]
  \makebox[0.42\textwidth][l]{%
    \begin{column}{0.48\textwidth}
      \begin{itemize}
        \item Boltzmann machine
          \begin{itemize}
            \item Energy function:
              \begin{align*}
                E(\bm{s}) &= E(\q{s_i}) \\
                          &= - \sum_{i<j} W_{ij} s_i s_j - \sum_i \theta_i s_i
              \end{align*}
            \item Structure:
              \begin{figure}
                \centering
                \imageinput[scale=0.6]{boltzmann-machine.pdf}
              \end{figure}
          \end{itemize}
      \end{itemize}
    \end{column}}
  \begin{column}{0.56\textwidth}
    \begin{itemize}
      \item Restricted Boltzmann machine (RBM)
        \begin{itemize}
          \item Energy function:
            \begin{align*}
              E(\bm{v},\,\bm{h})
              &= - \bm{v}^\trans \bm{W} \bm{h} - \bm{b}^\trans \bm{v} - \bm{c}^\trans \bm{h} \\
              &= - \sum_{i,\,j} W_{ij} v_i h_j - \sum_i b_i v_i - \sum_j c_j h_j
            \end{align*}
          \item Structure:
            \begin{figure}
              \centering
              \imageinput[scale=0.6]{rbm.pdf}
            \end{figure}
        \end{itemize}
    \end{itemize}
  \end{column}
\end{columns}
\end{frame}

\begin{frame}{RBM trained on MNIST}
\begin{columns}
  \begin{column}{0.44\textwidth}
    \begin{figure}
      \centering
      \imageinput[height=5.2cm]{mnist-weight.pdf}
      \caption{Weight matrix (reshaped)}
    \end{figure}
  \end{column}
  \begin{column}{0.55\textwidth}
    \begin{figure}
      \centering
      \imageinput[height=5.2cm]{mnist-samples.pdf}
      \caption{Reconstructed images}
    \end{figure}
  \end{column}
\end{columns}
\end{frame}

\begin{frame}{RBM trained on Ising lattice}
\begin{columns}
  \begin{column}{0.44\textwidth}
    \begin{figure}
      \centering
      \imageinput[height=5.2cm]{ising-weight-raw.pdf}
      \caption{Weight matrix (reshaped)}
    \end{figure}
  \end{column}
  \begin{column}{0.55\textwidth}
    \begin{figure}
      \centering
      \imageinput[height=5.2cm]{ising-samples.pdf}
      \caption{Reconstructed images}
    \end{figure}
  \end{column}
\end{columns}
\end{frame}

\begin{frame}{Exact mapping between RBM and RG}
\begin{itemize}
  \item Partition function under coarse graining:
    \[
      Z_{N'}
      = \sum_\q{\sigma'_i} \ee^{-\beta H^{\text{RG}}(\q{\sigma_i'},\,\bm{K}')}
      = \sum_\q{\sigma'_i} \sum_\q{\sigma_i}
        \ee^{-\beta \qty\big[H(\q{\sigma_i},\,\bm{K})
              -\opT_\lambda(\q{\sigma_i},\,\q{\sigma_i'})]}
    \]
  \item Express in RBM:
    \[
        \ee^{-H^{\text{RG}}(\bm{h})}
      = \sum_{\bm{v}} \ee^{\opT(\bm{v},\,\bm{h})-H(\bm{v})}
    \]
  \item Let $\opT(\bm{v},\,\bm{h}) = H(\bm{v}) - E(\bm{v},\,\bm{h})$, then
    \[
        \frac{1}{Z} \ee^{-H^{\text{RG}}(\bm{h})}
      = \frac{1}{Z} \sum_{\bm{v}} \ee^{-E(\bm{v},\,\bm{h})}
      = P(\bm{h})
      = \frac{1}{Z} \ee^{-H^{\text{RBM}}(\bm{h})}
      \implies \alert{H^{\text{RG}}(\bm{h}) = H^{\text{RBM}}(\bm{h})}
    \]
\end{itemize}
\end{frame}

\begin{frame}{Convolution and wavelet transform}
\begin{itemize}
  \item Convolution:
    \[ (f \ast g) (t) = \int_{-\infty}^{+\infty} f(\tau) \, g(t-\tau) \dd{\tau} \]
  \item A kind of ``weighted average''
  \item Expand function with \emph{daughter wavelet}:
    \[ \psi_{\bm{a},\,s}(\bm{x}) = \frac{1}{s^{d/2}} \psi\qty(\frac{\bm{x}-\bm{a}}{s}) \]
  \item Wavelet transform:
    \[ W_f(\bm{a},\,s) = \int \dd[d]{x} f(\bm{x}) \psi^\dagger_{\bm{a},\,s}(\bm{x}) \]
\end{itemize}
\end{frame}

\begin{frame}{\AdSCFT{} and wavelet transform}
\begin{itemize}
  \item Reconstruct fields in the bulk from boundary operators:
    \begingroup\footnotesize
      \begin{align*}
           \phi^i(\bm{x},z)
        &= \int \dd[d]{y} K_i(\bm{x},z|\bm{y}) \opO^i(\bm{y}) \\
        &+ \sum_{j,k} \frac{\lambda^i_{jk}}{N}
             \int \dd[d]{x'} \dd{z'} G_i(\bm{x},z|\bm{x}'\!,z')
             \int \dd[d]{y_1} K_j(\bm{x}'\!,z'|\bm{y}_1) \opO^j(\bm{y}_1)
             \int \dd[d]{y_2} K_k(\bm{x}'\!,z'|\bm{y}_2) \opO^k(\bm{y}_2) + \cdots
      \end{align*}
    \endgroup
  \item Boundary--bulk kernel:
    \begingroup\footnotesize
      \[
        K_i(\bm{x},z|\bm{y})
        = \qty[\frac{z}{z^2-\norm{\bm{x}-\bm{y}}^2}]^{d-\Delta_i} \,
          \Theta\qty\big(z^2-\norm{\bm{x}-\bm{y}}^2)
      \]
    \endgroup
  \item Mother and daughter wavelets:
    \begingroup\footnotesize
      \[
        \psi_\Delta(\bm{x}) = \qty(\frac{1}{1-\norm{\bm{x}}^2})^{d-\Delta} \,
                              \Theta\qty\big(1-\norm{\bm{x}}^2) \qc
        \psi_{\bm{a},\,s}(\bm{x})
        = \frac{1}{z^{d/2}} \psi\qty(\frac{\bm{y}-\bm{x}}{z})
      \]
    \endgroup
  \item Then
    \begingroup\footnotesize
      \[ K(\bm{x},z|\bm{y}) = z^{\Delta-d/2} \psi_{\bm{x},\,z}(\bm{y}) \]
    \endgroup
\end{itemize}
\end{frame}

\begin{frame}{Convolutional RBM (CRBM)}
\begin{columns}[t]
  \begin{column}{0.68\textwidth}
    \begin{itemize}
      \item Linear to convolutional:
        \[
          h_j+c_j \sim \sum_i W_{ij} (v_i+b_i) \to
          h_{\bm{j}} + c_{\bm{j}} \sim
            \sum_{\bm{i}} W_{\bm{i}} (v_{\bm{i}+\bm{j}} + b_{\bm{i}+\bm{j}})
        \]
      \item Energy function:
        \[
          E(\bm{v},\,\bm{h})
          = - \sum_{\bm{i},\,\bm{j}} W_{\bm{i}} v_{\bm{i}+\bm{j}} h_{\bm{j}}
            - \sum_{\bm{i}} b_{\bm{i}} v_{\bm{i}} - \sum_{\bm{j}} c_{\bm{j}} h_{\bm{j}}
        \]
      \item Our conjecture: filter $\bm{W}$ in CRBM is the Green's function $K$ in \AdSCFT{}
    \end{itemize}
  \end{column}
  \begin{column}{0.3\textwidth}
    \begin{figure}
      \centering
      \imageinput[width=\textwidth]{crbm.pdf}
    \end{figure}
  \end{column}
\end{columns}
\end{frame}

\section{Conclusion}

\begin{frame}{Conclusion}
\begin{itemize}
  \item Supervised learning can be used to classify phases of Ising model
  \item RBM can be considered as an implementation of renormalization
  \item Convolution and wavelet transform that root in \AdSCFT{} can be mapped to
    machine learning (e.g. CRBM)
\end{itemize}
\end{frame}

\begin{frame}[standout]
\LARGE\itshape
Thank you!
\end{frame}

\appendix

\begin{frame}{Exact solutions}
\begin{itemize}
  \item One dimension: no phase transition
  \item Two dimension
    \begin{itemize}
      \item Critical temperature:
        \[ \frac{\Tc}{J} = \frac{2}{\ln(1+\sqrt{2})} \approx \num{2.2692} \]
      \item Heat capacity (logarithmic divergence):
        \[ \frac{C}{N} \simeq \num{-0.4945} \ln\abs{1-\frac{T}{\Tc}} + \const \]
      \item Spontaneous magnetization:
        \[
          \frac{\bar{M}}{N\mu} =
          \begin{cases}
            \qty(1 - \sinh^{-4} 2\beta J)^{1/8}, & T<\Tc \\
            0, & T>\Tc
          \end{cases}
        \]
    \end{itemize}
\end{itemize}
\end{frame}

\begin{frame}{Monte Carlo simulation}
\small
\begin{itemize}
  \item Basic idea: average over samples instead of all configurations
  \item Distribution evolution:
    \begin{align*}
      P\qty\big(\q{\sigma_i},\,t+1) = P\qty\big(\q{\sigma_i},\,t)
      &+ \sum_{\q{\sigma'_i}} P\qty\big(\q{\sigma'_i},\,t) W\qty\big(\q{\sigma'_i}\to\q{\sigma_i})
         \notag \\
      &- \sum_{\q{\sigma'_i}} P\qty\big(\q{\sigma_i},\,t)  W\qty\big(\q{\sigma_i}\to\q{\sigma'_i})
    \end{align*}
  \item Detailed balance condition:
    \[
        P_{\text{eq}}(\q{\sigma_i})  W\qty\big(\q{\sigma_i}\to\q{\sigma'_i})
      = P_{\text{eq}}(\q{\sigma'_i}) W\qty\big(\q{\sigma'_i}\to\q{\sigma_i})
    \]
  \item Metropolis transition rates:
    \[
      W\qty\big(\q{\sigma_i}\to\q{\sigma'_i}) =
      \begin{cases}
        1, & \incr{E} \leqslant 0 \\
        \ee^{-\beta \incr{E}}, & \incr{E} > 0
      \end{cases}
    \]
\end{itemize}
\end{frame}

\begin{frame}{Algorithm}
\begin{enumerate}
  \item Initialize all the spins: set spins to be 0 or 1 \emph{randomly}.
  \item Generate a trial state $\q{\sigma'_i}$ that is near the current state $\q{\sigma_i}$
    \begin{itemize}
      \item Usually we can flip a single spin.
    \end{itemize}
  \item Calculate $\incr{E}$ and accept probability $P$. If random number $\xi<P$, then flip the
    corresponding spin.
  \item Perform step 2 and 3 for all the lattice (one Monte Carlo step, MCS).
    \begin{itemize}
      \item To maintain detailed balance, we should choose the spin \emph{randomly}.
      \item Flipping one-by-one is also acceptable for efficiency.
    \end{itemize}
  \item Repeat step 2--4 for some time, then we can measure the thermodynamic observables and
    calculate their mean values and standard errors.
\end{enumerate}
\end{frame}

\begin{frame}{Simulation results (1)}
\begin{figure}
  \centering
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \imageinput[width=3cm]{ising-lattice-1-0.pdf}
    \caption{}
  \end{subfigure}
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \imageinput[width=3cm]{ising-lattice-2-3.pdf}
    \caption{}
  \end{subfigure}
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \imageinput[width=3cm]{ising-lattice-3-6.pdf}
    \caption{}
  \end{subfigure}
  \caption{$64 \times 64$ Ising lattice at (a) $\Tc/J=1.0$; (b) $\Tc/J=2.3$; (c) $\Tc/J=3.6$.}
\end{figure}
\end{frame}

\begin{frame}{Simulation results (2)}
\begin{figure}
  \centering
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \imageinput[height=3.4cm]{ising-energy.pdf}
  \end{subfigure}
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \imageinput[height=3.4cm]{ising-magnet.pdf}
  \end{subfigure}
  \begin{subfigure}[b]{0.32\textwidth}
    \centering
    \imageinput[height=3.4cm]{ising-cv.pdf}
  \end{subfigure}
  \caption{(a) Energy; (b) spontaneous magnetization; (c) heat capacity.
    Sampling density is increased near $\Tc$. Error bar means one $\sigma$.}
\end{figure}
\end{frame}

\begin{frame}{Linear regression}
\begin{itemize}
  \item Hypothesis:
    \[ h_\bm{\theta} (\bm{x}) = \sum_{j=0}^n \theta_j x_j = \bm{\theta}^\trans \bm{x} \]
  \item Loss function:
    \[
      L(\bm{\theta})
      = \frac{1}{2} \sum_{i=1}^m \qty\Big[y^{(i)} - h_\bm{\theta}\qty\big(\bm{x}^{(i)})]^2
    \]
  \item Exact solution:
    \[ \hat{\bm{\theta}} = \qty\big(\bm{X}^\trans\bm{X})^{-1} \bm{X}^\trans \bm{y} \]
  \item Not realistic with large dataset --- \alert{gradient descent}
    \[ \bm{\theta} \coloneq \bm{\theta} - \alpha \, \nabla\bm{\theta} \]
\end{itemize}
\end{frame}

\begin{frame}{Neural network --- details}
\begin{columns}[t]
  \makebox[0.52\textwidth][l]{%
    \begin{column}{0.6\textwidth}
      \begin{itemize}
        \item Loss function (mean squared error):
          \[ L = \frac{1}{2} \sum_{i=1}^m \qty\big[y^{(i)} - \hat{y}^{(i)}]^2 \]
        \item Loss function (cross-entropy):
          \[
            L = - \frac{1}{m} \sum_{i=1}^m
                  \qty\Big[y^{(i)}\ln\hat{y}^{(i)}
                           - \qty\big(1-y^{(i)})\ln\qty\big(1-\hat{y}^{(i)})]^2
          \]
        \item Training algorithm: backpropagation
      \end{itemize}
    \end{column}}
  \begin{column}{0.48\textwidth}
    \begin{itemize}
      \item Regularization
        \begin{itemize}
          \item Prevent overfitting
          \item A kind of ``penalty'': force the parameters to be sparse
          \item Weight decay ($L^2$ reg\-u\-lar\-iza\-tion):
            \[ \frac{\lambda}{2m} \sum_k \norm{\bm{\theta}_k}^2 \]
        \end{itemize}
    \end{itemize}
  \end{column}
\end{columns}
\end{frame}

\begin{frame}{CD-\textit{k} algorithm (1)}
\begin{itemize}
  \item Loss function:
    \[
      L(\bm{\theta})
      = - \frac{1}{\abs{\domD}} \sum_{\bm{x}^{(i)}\in\domD} \ln P\qty\big(\bm{x}^{(i)})
    \]
  \item Gradient:
    \[
        - \pdv{\bm{\theta}} \ln P\qty\big(\bm{x}^{(i)})
      = - \pdv{\bm{\theta}} \ln P\qty\big(\bm{v}^{(i)})
      = \pdv{F(\bm{v}^{(i)})}{\bm{\theta}}
      - \sum_{\bm{v}} P(\bm{v}) \pdv{F(\bm{v})}{\bm{\theta}}
    \]
    where $F$ is the free energy
    \[ F(\bm{v}) = - \ln \sum_{\bm{h}} \ee^{-E(\bm{v},\,\bm{h})} \]
  \item Positive phase and negative phase (difficult)
\end{itemize}
\end{frame}

\begin{frame}{CD-\textit{k} algorithm (2)}
\begin{columns}
  \begin{column}{0.49\textwidth}
    \begin{itemize}
      \item Monte Carlo again:
        \[
          \sum_{\bm{v}} P(\bm{v}) \pdv{F(\bm{v})}{\bm{\theta}}
          \approx \frac{1}{\abs{\domN}} \sum_{\bm{v}\in\domN} \pdv{F(\bm{v})}{\bm{\theta}}
        \]
      \item Gibbs sampling:
        %\[
        %  \bm{h}  \sim P(\bm{h}\big|\bm{v}) \qc
        %  \bm{v}' \sim P(\bm{v}\big|\bm{h})
        %\]
        \begin{figure}
          \centering
          \imageinput[scale=0.64]{gibbs-sampling.pdf}
        \end{figure}
    \end{itemize}
  \end{column}
  \begin{column}{0.49\textwidth}
    \begin{itemize}
      \item Gradient:
        \[
          - \pdv{\bm{\theta}} \ln P\qty\big(\bm{v}^{(i)})
          \approx \pdv{F(\bm{v}^{(i)})}{\bm{\theta}}
                - \pdv{F({\bm{v}'}^{(i)})}{\bm{\theta}}
        \]
      \item Update parameters:
        \[
          \left\{
          \begin{aligned}
            \bm{W} \! &\gets \bm{W} \! - \alpha \, (  \bm{v} \bm{h}^\trans
                                                    - \bm{v}' {\bm{h}'}^\trans) \\
            \bm{b}    &\gets \, \bm{b} - \alpha \, (\bm{v} - \bm{v}') \\
            \bm{c}    &\gets \, \bm{c} - \alpha \, (\bm{h} - \bm{h}')
          \end{aligned}
          \right.
        \]
    \end{itemize}
  \end{column}
\end{columns}
\end{frame}

\begin{frame}{Basic of \AdSCFT{}}
\begin{columns}
  \begin{column}{0.68\textwidth}
    \begin{itemize}
      \item Anti-de Sitter space:
        \[ \dd{s}^2 = \sum_i \dd{x_i}^2 - \sum_j \dd{t_j}^2 \]
      \item Conformal field theory: QFT with conformal symmetry
      \item Ising model: one of a minimal model in 2D CFT
      \item Holographic duality:
        \[ \text{quantum gravity in $M$} \simeq \text{a QFT in $\partial{M}$}\]
    \end{itemize}
  \end{column}
  \begin{column}{0.31\textwidth}
    \begin{figure}
      \centering
      \imageinput[width=\textwidth]{hyperbolic-plane.png}
      \caption{Hyperbolic plane \footnotemark}
    \end{figure}
  \end{column}
\end{columns}
\footnotetext{Source: \url{https://en.wikipedia.org/wiki/File:Uniform_tiling_433-t0.png}}
\end{frame}

\end{document}


\subsection{Colorimetry}

\textit{The current recommended source for colorimetry is \gls{CIE} document `\gls{CIE} 015:2018'\citep{cie_cie_2018}\footnote{Though as \citet{fairchild_cie_2019} notes, this document is `expensive and somewhat difficult to find', and as such I have been using a draft of the now superseded `\gls{CIE} 15.3:2004'\citep{cie_cie_2004-2} as my personal guide. All equations listed in this chapter come from this source.}. Whilst this is the authoritative reference, my personal opinion is that an understanding of \gls{CIE} colorimetry is best gained from an understanding of its history, and for this I recommend Janos Schanda's book `Colorimetry: Understanding the \gls{CIE} System' \citep{schanda_colorimetry_2007}. Another valuable, and perhaps more easily accessed, reference source is \citet{stockman_color_2010}.}

\bigskip

I define `colorimetry' as the study of the quantitative specification of colour. As a subjective, internal and anthropocentric concept, in order to measure anything meaningful and comparable, we use a standard observer, or more precisely, one of a number of defined standard observers \cite{cie_bs_2011}.

The classic standard observer was defined by the \gls{CIE} in 1931, following experiments by Wright and Guild \cite{wright_re-determination_1929, guild_colorimetric_1931}. Despite several more recently published standard observers, the 1931 observer is still much used, and I shall use it in the following example of how a basic colorimetric computation is performed.

\glsreset{SPD}
\glsreset{SRF}
\glsreset{CMF}
\glsreset{SSF}

An illuminant is defined by its \gls{SPD}, a surface by its \gls{SRF}, and the sensitivity of a sensor (such as a photosensitive cell in the retina, or a pixel in a camera) by its \gls{CMF} (or in the case that biologically based measurements are used - the \gls{SSF}). Examples of these are shown in Figure \ref{fig:specFun}.

\begin{figure}[htbp]
\includegraphics[max width=\textwidth]{figs/LitRev/SPDetc.pdf}
\caption{An \gls{SPD} (D65), a set of \glspl{SRF} (from a Macbeth Colour Checker) and three \glspl{CMF} (\gls{CIE} 1931 observer).}
\label{fig:specFun}
\end{figure}
% % How is D65 normalised here?

The light reaching the eye for a given reflecting surface under a given illuminant (termed the `colour signal') can be computed by multiplying the \gls{SPD} by the \gls{SRF} at each sampled interval.

\begin{equation}
\phi(\lambda)=R(\lambda) \cdot S(\lambda)
\end{equation}

where $R(\lambda)$ is the \gls{SRF}, $S(\lambda)$ is the \gls{SPD} and $\phi(\lambda)$ is the resulting colour signal. From this a set of values termed `tristimulus values' may be computed. Tristimulus values are computed by multiplying the colour signal by the \glspl{CMF} or \glspl{SSF}, and following the principle of univariance (that each cone type cannot alone distinguish between different wavelengths) the tristimulus values can, to some extent, be thought of as containing the entirety of the chromatic information about a surface (for a human standard observer, excluding high level colour appearance phenomena predicted by \Glspl{CAM}, and properties such as gloss).

%KC: make sure these equations are on the same page as the explanation

\begin{subequations}
\begin{align}
X=k \sum_{\lambda} \phi(\lambda) \overline{x}(\lambda) \Delta \lambda \\
Y=k \sum_{\lambda} \phi(\lambda) \overline{y}(\lambda) \Delta \lambda \\
Z=k \sum_{\lambda} \phi(\lambda) \overline{z}(\lambda) \Delta \lambda
\end{align}
\label{eq:XYZ}
\end{subequations}

\nopagebreak %this doesn't work currently

where $\overline{x}(\lambda)$ (said `x bar'), $\overline{y}(\lambda)$ and $\overline{z}(\lambda)$ are the \glspl{CMF} of the 1931 observer (or are replaced by the \Glspl{CMF}/\Glspl{SSF} of the chosen observer), $\phi(\lambda)$ is as defined above, $k$ is a normalising factor, and $\Delta\lambda$ is 1nm. It is traditional to set $k$ such that $Y=100$, though in the case of relative colorimetry (most cases) this is often not done since the following equation renders it superfluous.

From the tristimulus values ($X,Y$ and $Z$) chromaticity co-ordinates ($x$ and $y$) can be computed. These can then be plotted on a 1931 chromaticity space diagram, shown as Figure \ref{fig:1931}.

\begin{subequations}
\begin{align}
x=\frac{X}{X+Y+Z} \\
y=\frac{Y}{X+Y+Z}
\end{align}
\label{eq:1931chrom}
\end{subequations}

% Here's a \gls{MATLAB} example, using \gls{PTB} for data:

% \begin{lstlisting}[language=MATLAB]
% load spd_D65 % SPD: CIE D-series illuminant D65
% load sur_macbeth % SRF: macbeth colour checker
% load T_xyz1931 % CMF: CIE 1931

% colourSignals = sur_macbeth.*spd_D65;
% XYZ = T_xyz1931*colourSignals;
% xy = [XYZ(1,:)./sum(XYZ);XYZ(2,:)./sum(XYZ)];
% \end{lstlisting}

% Plotting:

% \begin{lstlisting}[language=MATLAB]
% spectralLocus = [T_xyz1931(1,:)./sum(T_xyz1931);T_xyz1931(2,:)./sum(T_xyz1931)];
% sRGBSpectralLocus = XYZToSRGBPrimary(T_xyz1931);

% figure, hold on,
% scatter(spectralLocus(1,1:70),spectralLocus(2,1:70),[],sRGBSpectralLocus(:,1:70)','filled')
% scatter(xy(1,:),xy(2,:),'k')
% axis equal, axis([0 1 0 1])
% xticks([0 1]), yticks([0 1])
% xlabel('x'), ylabel('y')
% \end{lstlisting}

\begin{figure}[htbp]
\includegraphics[max width=\textwidth]{figs/LitRev/ColorimetryDemo1.pdf}
\caption{The \gls{CIE} 1931 chromaticity space, showing the chromaticity of the Macbeth colour checker patches under D65. Note that for all of the plots in this section, the colours used for the spectral loci are only approximations.}
\label{fig:1931}
\end{figure}

\subsubsection{Specific Colour Spaces} \label{sec:speccolspac}

Over time various other colour spaces have been proposed and formally accepted by the \gls{CIE}, each aiming to improve upon a prior space in one or more ways. One of the most frequently sought characteristics for a colour space is perceptual uniformity, whereby a set distance in one part of the space is comparable in terms of apparent colour difference to that same distance in another part of the space.

One such chromaticity space which shall be used extensively in this thesis is the \gls{CIE} 1976 UCS (uniform chromaticity scale) space (colloquially \gls{CIE} u'v'), which is a relatively simple transformation of the 1931 chromaticity space. The conversion can be accomplished in a number of analogous fashions, one of which is shown below.

\begin{subequations}
\begin{align}
u' &= 4x / (-2x + 12y + 3) \\
v' &= 9y / (-2x + 12y + 3)
\end{align}
\end{subequations}

where $x$ and $y$ are the 1931 chromaticity co-ordinates as defined in Equation \ref{eq:1931chrom}. The data presented in Figure \ref{fig:1931} are re-plotted in this new space in Figure \ref{fig:UCS}.

\begin{figure}[htbp]
\includegraphics[max width=\textwidth]{figs/LitRev/ColorimetryDemo3.pdf}
\caption{\gls{CIE} 1976 UCS (uniform chromaticity scale) space, showing the chromaticity of the macbeth colour checker patches under D65 (as in Figure \ref{fig:1931}).}
\label{fig:UCS}
\end{figure}

A three-dimensional extension to the CIE 1976 UCS space is the \gls{CIE} 1976 L*u*v* colour space, often abbreviated to CIELUV, which aims to provide perceptual uniformity in a space that includes both chromaticity and lightness (relative to a white object under the same illumination). It is defined as follows:

\begin{subequations}
\begin{align}
L^{*} &= 116 f(Y/Y_{n})-16 \\
\textrm{where} f(Y/Y_{n}) &= (Y/Y_{n})^{1/3} &\textrm{ if } (Y/Y_{n}) > (24/116)^{3} \\
\textrm{or} f(Y/Y_{n}) &= (841/108)(Y/Y_{n})+16/116 &\textrm{ if } (Y/Y_{n}) \leq (24/116)^{3} \\
u^{*} &= 13L^{*}(u'-u'_{n}) \\
v^{*} &= 13L^{*}(v'-v'_{n})
\end{align}
\end{subequations}

where $Y_{n}$, $u'_{n}$ and $v'_{n}$ refer to the colour stimulus of a perfect reflector. The same data presented in Figures \ref{fig:1931} and \ref{fig:UCS} is presented in CIELUV in Figure \ref{fig:CIELUV} (though of course the three-dimensional quality of the data is somewhat lost in this presentation).

\begin{figure}[hbtp]
\includegraphics[max width=0.8\textwidth]{figs/LitRev/ColorimetryDemo4.pdf}
\caption{A representation of CIELUV, showing the values for the macbeth colour checker patches under D65 (as in Figure \ref{fig:1931} and \ref{fig:UCS}). Note that if viewed from above, the distribution of points would appear similar to as in Figure \ref{fig:UCS}. If all of the points were of uniform $L^{*}$, then the distribution would be identical, only with different scaling and offsetting.}
\label{fig:CIELUV}
\end{figure}

Introduced at the same time as CIELUV was a colourspace with a similar goal of perceptual uniformity: CIELAB. They are similar in many ways, and share $L^{*}$. CIELAB seems to be in slightly more common usage, but CIELUV is used in this thesis (particularly Chapter \ref{chap:Tablet}) due to the neat mathematical link to an associated chromaticity space (the CIE 1976 UCS space).

The two spaces suit subtly different purposes, requested by two different user groups identified at the time of the creation of these spaces: ``lighting engineers interested in a space and formula that is a linear transformation of the CIE chromaticity diagram, and industrial colorists interested in a formula predicting perceived average color differences better than any existing one'' \citep{kuehni_color_2008}. CIELUV satisfied the first group, and CIELAB was designed to better suit the second, using a cube root function for the chromaticity values, mirroring $L^{*}$. CIELAB is defined as follows:

\begin{subequations}
\begin{align}
L^{*} &= 116 f(Y/Y_{n})-16 \\
\textrm{where} f(Y/Y_{n}) &= (Y/Y_{n})^{1/3} &\textrm{ if } (Y/Y_{n}) > (24/116)^{3} \\
\textrm{or} f(Y/Y_{n}) &= (841/108)(Y/Y_{n})+16/116 &\textrm{ if } (Y/Y_{n}) \leq (24/116)^{3} \\
a^{*} &= 500[f(X/X_{n}) - f(Y/Y_{n})] \\
b^{*} &= 200[f(Y/Y_{n}) - f(Z/Z_{n})]
\end{align}
\end{subequations}

where $f(X/X_{n})$ and $f(Z/Z_{n})$ follow the same format as $f(Y/Y_{n})$.

The final colour space presented here is the \acrfull{MB} colour space. This space does not aspire to be perceptually uniform\footnote{This can be clearly noted by comparing Figure \ref{fig:lrMB} with previous figures. Where this set of chromaticities previously spanned the spaces fairly broadly, here all the chromaticities inhabit only a small portion of the chromaticity space.}. Instead, it aspires to provide a colour space which has a physiological underpinning. As such, the standard observer model consists of nominal \glspl{SSF} (rather than \glspl{CMF}), and the conversion from tristimulus values to chromaticity space attempts to mirror the way in which this actually occurs physiologically.

It was originally proposed by \citet{macleod_chromaticity_1979}, but was recently revised and endorsed by the \gls{CIE}, in documents `CIE 170-1:2006' \citep{cie_cie_2006} and `CIE 170-2:2015' \citep{cie_cie_2015}\footnote{I understand that the final publication in the series (`CIE 170-3:XXXX') is in preparation.}. The revisions included the definition of a new observer (formally the `TC 1-36 Modified Colorimetric Observer', colloquially refered to as the \gls{CIE} 2006 observer), based on the work of \citet{stockman_spectral_1999} and \citet{stockman_spectral_2000} (and referred to below as $\overline{lms}$), and the introduction of a set of new normalising terms, such that it is now calculated as follows.

\begin{subequations}
\begin{align}
L_{\text{MB}}&=k_{l} \sum_{\lambda} \phi(\lambda) \overline{l}(\lambda) \Delta \lambda \\
M_{\text{MB}}&=k_{m} \sum_{\lambda} \phi(\lambda) \overline{m}(\lambda) \Delta \lambda \\
S_{\text{MB}}&=k_{s} \sum_{\lambda} \phi(\lambda) \overline{s}(\lambda) \Delta \lambda
\end{align}
\label{eq:MBTristim}
\end{subequations}

where $k_{l}$ = 0.68990272, $k_{m}$ = 0.34832189, $k_{s}$ = 0.03715971. This set differs minimally but purposefully from Equation \ref{eq:XYZ}; in the choice of observer ($\overline{lms}$), and in the use of different scaling factors for each tristimulus value. The different scaling values dictate the relative contributions of $L_{\text{MB}}$ and $M_{\text{MB}}$ to luminance, and constrict $s_{\text{MB}}$ to a maximum value of 1 in the following equation (Equation \ref{eq:MB}). \gls{MB} chromaticity values are then calculated as follows:

\begin{subequations}
\begin{align}
l_{\text{MB}}&= \frac{L_{\text{MB}}}{L_{\text{MB}}+M_{\text{MB}}} \\
s_{\text{MB}}&= \frac{S_{\text{MB}}}{L_{\text{MB}}+M_{\text{MB}}}
\end{align}
\label{eq:MB}
\end{subequations}

Whereas the relationship between the axes of previous colour spaces was important, here the axes are nominally independent (representing different post-receptoral mechanisms) and so the scaling between the axes is arbitrary. As such, in vision science the axes of this diagram are often re-scaled to suit the task at hand (see for example \citet{christiansen_chromatic_2017,bosten_what_2015,danilova_superior_2016}). The same data as presented previously is presented again in Figure \ref{fig:lrMB} in a \gls{MB} chromaticity space.

\begin{figure}[htbp]
\includegraphics[max width=\textwidth]{figs/LitRev/ColorimetryDemo5.pdf}
\caption{A \gls{MB} chromaticity space diagram (as per \gls{CIE} 170-2:2015 \citep{cie_cie_2015}) showing the values for the macbeth colour checker patches under D65, as in previous figures.}
\label{fig:lrMB}
\end{figure}

\subsubsection{Correlated Colour Temperature}

The \acrfull{CCT} of an illuminant is defined by CIE 15.3:2004 \citep{cie_cie_2004-2} as follows:

\begin{itquote}{}
The temperature of a Planckian radiator having the chromaticity nearest the chromaticity associated with the given spectral distribution on a diagram where the (CIE 1931 standard observer based) u', 2/3v' coordinates of the Planckian locus and the test stimulus are depicted.
\end{itquote}

Whilst by this definition a light source of any chromaticity could be assigned a \gls{CCT}, as the distance between the Planckian locus and the test stimulus increases, the \gls{CCT} becomes a less meaningful descriptor. CIE 15.3:2004 \citep{cie_cie_2004-2} defines chromaticity limits on the maximum distance between the Planckian locus and the test stimulus, beyond which \gls{CCT} should not be used, which are described in Equation \ref{eq:CCTlim}.

\begin{equation}
\Delta C=\left[\left(u_{t}^{\prime}-u_{P}^{\prime}\right)^{2}+\frac{4}{9} \cdot\left(v_{t}^{\prime}-v_{P}^{\prime}\right)^{2}\right]^{1 / 2}=5 \cdot 10^{-2}
\label{eq:CCTlim}
\end{equation}

where $u^{\prime}_{t}, v^{\prime}_{t}$ refer to the test source and $u^{\prime}_{P}, v^{\prime}_{P}$ to the Planckian radiator.

Figure \ref{fig:BBR} shows the Planckian locus (the curve formed by a set of black body radiators of different temperatures) in \gls{CIE} 1931 chromaticity space. It is worth noting that most real light sources (natural and artificial) fall upon the relatively straight section of the left-hand part of this line.

\gls{CCT} is often used as the independent variable in experiments, with the implicit assumption that this can be considered a complete descriptor of a light source. This assumption only holds to the extent that the spectral form is similar between conditions (for example if only a single light source is used and well defined filtration is applied, which shifts the chromaticity of the light source along the Planckian locus), and that the only difference between conditions is a shift along the Planckian locus.

A shift in chromaticity perpendicular to the Planckian locus would result in no change to the \gls{CCT}. To counter this issue, an additional parameter ($D_{\text {uv }}$) is defined \citep{ohno_practical_2014} as per Equation \ref{eq:Duv}, which provides a value for the distance from the Planckian locus.

\begin{equation}
D_{\mathrm{uv}}=\left[\left(u^{\prime}-u_{0}^{\prime}\right)^{2}+\left(\frac{2}{3} v^{\prime}-\frac{2}{3} v_{0}^{\prime}\right)^{2}\right]^{\frac{1}{2}} \cdot \operatorname{sgn}\left(v^{\prime}-v_{0}^{\prime}\right)
\label{eq:Duv}
\end{equation}

where $\operatorname{sgn}(z)=1$ for $z\geq0$ and $\operatorname{sgn}(z)=-1$ for $z<0$.

\citet{ohno_practical_2014} notes that the combination of \gls{CCT} and $D_{\text {uv }}$ is sufficient to describe the chromaticity of most light sources, and does so in a fashion which is slightly more intuitive than values of chromaticity.

\begin{figure}[htbp]
\includegraphics[max width=\textwidth]{figs/LitRev/BBR.pdf}
\caption{The Planckian locus on a \gls{CIE} 1931 chromaticity chart, highlighting \glspl{CCT} of 1000K, 6500K and 10000K.}
\label{fig:BBR}
\end{figure}

\clearpage


\subsection{Arrows}
\label{sec:arrows}
Arrows were introduced by \citet{HughesArrows} as a general interface for computation and a less restrictive generalisation of Monads. \citeauthor{HughesArrows} motivates the broader interface of Arrows with the example of a parser with added static meta-information that can not satisfy the monadic bind operator |(>>=) :: m a -> (a -> m b) -> m b| (with |m| being a Monad)\footnote{In the example a parser of the type |Parser s a| with static meta information |s| and result |a| is shown to not be able to use the static information |s| without applying the monadic function |a -> m b|. With Arrows this is possible.}.

An Arrow |arr a b| represents a computation that converts an input |a| to an output |b|. This is defined in the |Arrow| type class shown in Fig.~\ref{fig:ArrowDefinition}.
%
To lift an ordinary function to an Arrow, |arr| is used, analogous to the monadic |return|. Similarly, the composition operator |>>>| is analogous to the monadic composition |>>=| and combines two Arrows |arr a b| and |arr b c| by \enquote{wiring} the outputs of the first to the inputs to the second to get a new Arrow |arr a c|. Lastly, the |first| operator takes the input Arrow |arr a b| and converts it into an Arrow on pairs |arr (a, c) (b, c)| that leaves the second argument untouched. It allows us to to save input across Arrows. Figure~\ref{fig:arrows-viz} shows a graphical representation of these basic Arrow combinators.
The most prominent instances of this interface are regular functions |(->)|
and the Kleisli type (Fig.~\ref{fig:ArrowDefinition}), which wraps monadic functions, e.g.  |a -> m b|.

\begin{figure}[t]
\centering
\begin{code}
class Arrow arr where
  arr :: (a -> b) -> arr a b
  (>>>) :: arr a b -> arr b c -> arr a c
  first :: arr a b -> arr (a,c) (b,c)

instance Arrow (->) where
	arr f = f
	f >>> g = g . f
	first f = \(a, c) -> (f a, c)

data Kleisli m a b = Kleisli { run :: a -> m b }

instance Monad m => Arrow (Kleisli m) where
	arr f = Kleisli (return . f)
	f >>> g = Kleisli (\a -> f a >>= g)
	first f = Kleisli (\(a,c) -> f a >>= \b -> return (b,c))
\end{code}
\vfill
\caption{The |Arrow| type class and its two most typical instances.}
\label{fig:ArrowDefinition}
\end{figure}

\begin{figure}[t]
\centering
\parbox[c][17em]{0.49\linewidth}{%
\vfill
\centering
	\includegraphics{images/arrow}
\vfill
%	\caption{Schematic depiction of an Arrow.}
%\label{fig:arrow-sch}
}
\parbox[c][17em]{0.49\linewidth}{%
\vfill
\centering
	{\includegraphics[scale=0.6]{images/arr}}
	{\includegraphics[scale=0.6]{images/compose}}
	{\includegraphics[scale=0.6]{images/first}}
\vfill
%\caption{Schematic depiction of |Arrow| combinators |arr|, |>>>| and |first|.}
%\label{fig:arrows-viz}
}
\caption{Schematic depiction of  an Arrow (left) and its basic
  combinators |arr|, |>>>| and |first| (right).}
\label{fig:arrow-sch}
\label{fig:arrows-viz}
\end{figure}

\begin{figure}[h]
	\centering
	\begin{tabular}{cc}
		% \subcaptionbox
{\label{t1}}{\includegraphics[width = 1.5in]{images/first}} &
		% \subcaptionbox
{\label{fig:secondImg}}{\includegraphics[width = 1.5in]{images/second}} \\
|first| & |second| \\
\midrule
		% \subcaptionbox
{}{\includegraphics[width = 1.5in]{images/starstarstar}} &
		% \subcaptionbox
{}{\includegraphics[width = 1.5in]{images/andandand}}\\
|(***)|\label{fig:***Img} & |(&&&)| \label{fig:&&&Img} \\
	\end{tabular}
	\caption{Visual depiction of syntactic sugar for Arrows.}
	\label{fig:syntacticSugarArrows}
\end{figure}
Hughes also defined some syntactic sugar (Fig.~\ref{fig:syntacticSugarArrows}): |second|, |***| and |&&&|.
|second| is the mirrored version of |first| (Appendix~\ref{utilfns}).
The |***| function combines |first| and |second| to handle two inputs in one arrow, and is defined as follows:
% \begin{figure}[h]
\begin{code}
(***) :: Arrow arr => arr a b -> arr c d -> arr (a, c) (b, d)
f *** g = first f >>> second g
\end{code}
% \caption{The (***) combinator}
% \label{fig:***}
% \end{figure}
The |&&&| combinator, which constructs an Arrow that outputs two different values like |***|, but takes only one input, is:
% \begin{figure}[h]
\begin{code}
(&&&) :: Arrow arr => arr a b -> arr a c -> arr a (b, c)
f &&& g = arr (\a -> (a, a)) >>> f *** g
\end{code}
% \caption{The (\&\&\&) combinator}
% \label{fig:&&&}
% \end{figure}
A~first short example given by Hughes on how to use Arrows is addition with Arrows:
%|add| over Arrows, which can be seen in Fig.~\ref{fig:addArrows}.
% \begin{figure}[h]
\begin{code}
add :: Arrow arr => arr a Int -> arr a Int -> arr a Int
add f g = f &&& g >>> arr (\(u, v) -> u + v)
\end{code}

As we can rewrite the monadic bind operation |(>>=)| with only the Kleisli type into |m a -> Kleisli m a b -> m b|, but not with a general Arrow |arr a b|, we can intuitively get an idea of why Arrows must be a generalisation of Monads. While this also means that a general Arrow can not express everything a Monad can, \citet{HughesArrows} shows in his parser example that this trade-off is worth it in some cases.

In this paper we will show that parallel computations can be expressed with this more general interface of Arrows without requiring Monads. We also do not restrict the compatible Arrows to ones which have |ArrowApply| instances but instead only require instances for |ArrowChoice| (for if-then-else constructs) and |ArrowLoop| (for looping). Because of this, we have a truly more general interface as compared to a monadic one.

While we could have based our DSL on Profunctors \cite{boisseau_what_2018} as well, we chose Arrows\mbcomment{cite missing?} for this paper since they they allow for a more direct way of thinking about parallelism than general Profunctors because of their composability. However, they are a promising candidate for future improvements of our DSL. Some Profunctors, especially ones supporting a composition operation, choice, and looping, can already be adapted to our interface as shown in Appendix~\ref{app:profunctorArrows}.


% Spencer Todd
% April 2018, AP Computer Science Principles, Mr. Tull

\documentclass[11pt]{article}

\usepackage{graph}

\begin{document}\fontfamily{lmr}\selectfont
\section{a}\\
This project was written in Python and uses a number of Python third-party libraries, such as Matplotlib, NumPy, and
SymPy.\double

This program implements a level surface visualization for functions of three variables by graphing the function's level
surfaces. The visualization is an analog to level curves for functions of two variables. Functions of one and two variables
are trivial to represent in our three dimensional world, but functions of three dimensions are not. On a level surface graph,
the surfaces represent where the function has the same value. An application of level surfaces would be to visualize how a
variable changes over three dimensions, such as temperature, air pressure, or brightness from a light source.\double
The video demonstrates the visualization of the function $f\paren{x,y,z}=\frac{z}{\sqrt{x^2+y^2}}$, as well as one possible interface
to the program, the command line parameters.\double

\section{b}\\
Before starting this project, I was already familiar with Matplotlib 2D plotting, as well as how I can use NumPy matrices to
plot data. In order to become familiar with the Matplotlib 3D interface, I initially plotted two variable functions by hard
coding transformations of the $x$ and $y$ domain matrices. To make the program interactive, I replaced the hard coded
expressions with evaluated interactive input. Then, I familiarized myself with enough relevant functions of the SymPy library
in order to implement my mathematical algorithm. Using the interactive Python console to tinker with the libraries readily
sped up my learning process. For the program as a whole, I initially implemented the program all in one to two functions,
then I would separate different chunks into more readable, individual functions.\double

All development and library research was independent.\double

\section{c}
\lstinputlisting[firstline=60,lastline=63,firstnumber=60]{graph.py}

The \verb|solve_z_prompt()| function integrates a mathematical algorithm with a logical algorithm in order to collect a string
and manipulate it mathematically. There are two main branches of the algorithm in order to achieve this, the functions
\verb|solve_z()| and \verb|prompt_expression()|.\double

The function \verb|prompt_expression()| gathers a string of text from the user, deciding whether to read the command line artguments,
from an interactive prompt, or from a shell pipe. The algorithm implemented by the function also decides whether the shell pipe
flag should or should not have been supplied. The algorithm does not decide whether the string is a valid expression.\double

The function \verb|solve_z()| implements the following algorithm: the expression $f\paren{x,y,z}$ is put into an
equation, $C=f\paren{x,y,z}$, whereas $C$ is an arbitrary constant; the equation is solved for $z$; then the solutions to the
equation are returned. The library call dictates that a list of expressions that satisfy the solution is returned.\double

Putting these functions together, \verb|solve_z_prompt()| prompts the user for an expression, then returns the list of solutions
of that expression set equal to $C$ and solved for $z$.\double

\section{d}
\lstinputlisting[firstline=83,lastline=93,firstnumber=83]{graph.py}

The function \verb|map_f_xy()| makes it simple to iterate over a 2D table of coordinate pairs (which is a 3D table of numbers).
The function is analogous to a Numpy vector function, like the functions \verb|np.sin()| or \verb|np.sqrt()|, which apply the
same function to each individual number in the matrix, but \verb|map_f_xy()| applies the same function to each coordinate pair
in the input meshgrid. The structure of the meshgrid is that $x$ and $y$ values are stored in separate tables but in the same
index, so working with individual coordinate pairs is difficult. Applying a transposition to the meshgrid will pair each
corresponding $x$ and $y$ and arrange them in a 2D table. Then, it is simple to iterate through each row. On each iteration,
the input function is applied to the coordinate pair, and the answer is stored in the output matrix.\double

This abstraction is required, because the main purpose of the program is to plot 3D functions over a 2D domain.
\end{document}


\section{Content}
	\paragraph*{Structure of lectures}
	The lectures are an adaptation of traditional frontal lectures. In order to improve attention and retention, the following interactive elements are also used:
	\begin{inparaenum}[\itshape i\upshape)]
	\item questions and quizzes to the class, followed by discussion;
	\item short group assignments, followed by discussion.
	\end{inparaenum}

	\paragraph*{List of topics}
	 	The following is a comprehensive and detailed list of the program of the course:
 		\begin{enumerate}
			\item Linear motion
			\item Rotational motion
			\item Linear acceleration
			\item Rotational acceleration
			\item Inertia tensor
			\item Euler integration
			\item Runge-Kutta integration
			\item Quaternions
			\item Time-derivative of matrices
			\item Time-derivative of quaternions
		\end{enumerate}
\ \\