diff --git a/doc/LectureNotes/_build/.doctrees/environment.pickle b/doc/LectureNotes/_build/.doctrees/environment.pickle index 6b08a3726..9e191ff76 100644 Binary files a/doc/LectureNotes/_build/.doctrees/environment.pickle and b/doc/LectureNotes/_build/.doctrees/environment.pickle differ diff --git a/doc/LectureNotes/_build/.doctrees/week41.doctree b/doc/LectureNotes/_build/.doctrees/week41.doctree index 4399af0af..b247dc645 100644 Binary files a/doc/LectureNotes/_build/.doctrees/week41.doctree and b/doc/LectureNotes/_build/.doctrees/week41.doctree differ diff --git a/doc/LectureNotes/_build/html/_images/week41_304_0.png b/doc/LectureNotes/_build/html/_images/week41_304_0.png new file mode 100644 index 000000000..492df86d6 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/week41_304_0.png differ diff --git a/doc/LectureNotes/_build/html/_images/week41_304_1.png b/doc/LectureNotes/_build/html/_images/week41_304_1.png new file mode 100644 index 000000000..90948aee6 Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/week41_304_1.png differ diff --git a/doc/LectureNotes/_build/html/_images/week41_304_2.png b/doc/LectureNotes/_build/html/_images/week41_304_2.png new file mode 100644 index 000000000..a76574b3e Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/week41_304_2.png differ diff --git a/doc/LectureNotes/_build/html/_images/week41_304_3.png b/doc/LectureNotes/_build/html/_images/week41_304_3.png new file mode 100644 index 000000000..fc2c8902f Binary files /dev/null and b/doc/LectureNotes/_build/html/_images/week41_304_3.png differ diff --git a/doc/LectureNotes/_build/html/_sources/week41.ipynb b/doc/LectureNotes/_build/html/_sources/week41.ipynb index 3def9b7f3..5f563d4fd 100644 --- a/doc/LectureNotes/_build/html/_sources/week41.ipynb +++ b/doc/LectureNotes/_build/html/_sources/week41.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "4fed6eef", + "id": "4411828b", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "6a758aaa", + "id": "c234e82d", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "7436d60f", + "id": "e602572c", "metadata": { "editable": true }, @@ -37,7 +37,7 @@ }, { "cell_type": "markdown", - "id": "4a06fa29", + "id": "8c040a6e", "metadata": { "editable": true }, @@ -70,7 +70,7 @@ }, { "cell_type": "markdown", - "id": "c77f547a", + "id": "d7c3f47c", "metadata": { "editable": true }, @@ -87,7 +87,7 @@ }, { "cell_type": "markdown", - "id": "a1ba6a50", + "id": "ee26bc0e", "metadata": { "editable": true }, @@ -97,7 +97,7 @@ }, { "cell_type": "markdown", - "id": "9ef418c8", + "id": "604a7680", "metadata": { "editable": true }, @@ -115,7 +115,7 @@ }, { "cell_type": "markdown", - "id": "b58ec2e6", + "id": "df00fb0e", "metadata": { "editable": true }, @@ -139,7 +139,7 @@ }, { "cell_type": "markdown", - "id": "7d1b99e3", + "id": "b60314ed", "metadata": { "editable": true }, @@ -157,7 +157,7 @@ }, { "cell_type": "markdown", - "id": "367512fa", + "id": "9d2e1d85", "metadata": { "editable": true }, @@ -197,7 +197,7 @@ }, { "cell_type": "markdown", - "id": "3d79cfce", + "id": "c6af91e7", "metadata": { "editable": true }, @@ -226,7 +226,7 @@ }, { "cell_type": "markdown", - "id": "cbcafcdc", + "id": "1b2b8e1c", "metadata": { "editable": true }, @@ -247,7 +247,7 @@ }, { "cell_type": "markdown", - "id": "1ab04b48", + "id": "db4860d5", "metadata": { "editable": true }, @@ -276,7 +276,7 @@ }, { "cell_type": "markdown", - "id": "e4cf80b3", + "id": "4c21c5ca", "metadata": { "editable": true }, @@ -297,7 +297,7 @@ }, { "cell_type": "markdown", - "id": "f27655c6", + "id": "4314d49c", "metadata": { "editable": true }, @@ -318,7 +318,7 @@ }, { "cell_type": "markdown", - "id": "fa00e7d8", + "id": "94acdaed", "metadata": { "editable": true }, @@ -335,7 +335,7 @@ }, { "cell_type": "markdown", - "id": "7b05bd13", + "id": "5c342880", "metadata": { "editable": true }, @@ -356,7 +356,7 @@ }, { "cell_type": "markdown", - "id": "3600caa3", + "id": "f8e04154", "metadata": { "editable": true }, @@ -372,7 +372,7 @@ }, { "cell_type": "markdown", - "id": "99af52bb", + "id": "80e11a79", "metadata": { "editable": true }, @@ -389,7 +389,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "04ecfb00", + "id": "60cf9550", "metadata": { "collapsed": false, "editable": true @@ -430,7 +430,7 @@ }, { "cell_type": "markdown", - "id": "0026adeb", + "id": "72e221bf", "metadata": { "editable": true }, @@ -440,7 +440,7 @@ }, { "cell_type": "markdown", - "id": "e23f3056", + "id": "67d0709a", "metadata": { "editable": true }, @@ -451,7 +451,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "a30fe879", + "id": "4afcb37f", "metadata": { "collapsed": false, "editable": true @@ -513,7 +513,7 @@ }, { "cell_type": "markdown", - "id": "7773ba9d", + "id": "ac931e42", "metadata": { "editable": true }, @@ -523,7 +523,7 @@ }, { "cell_type": "markdown", - "id": "4a85ef26", + "id": "e5455ad8", "metadata": { "editable": true }, @@ -534,7 +534,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "2f8dd9ef", + "id": "cfbed3e7", "metadata": { "collapsed": false, "editable": true @@ -554,58 +554,3097 @@ }, { "cell_type": "markdown", - "id": "5b0fb3ff", + "id": "a619dfb2", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", + "## Mathematics of deep learning\n", "\n", - "The output $y$ is produced via the activation function $f$" + "**Two recent books online.**\n", + "\n", + "1. [The Modern Mathematics of Deep Learning, by Julius Berner, Philipp Grohs, Gitta Kutyniok, Philipp Petersen](https://arxiv.org/abs/2105.04026), published as [Mathematical Aspects of Deep Learning, pp. 1-111. Cambridge University Press, 2022](https://doi.org/10.1017/9781009025096.002)\n", + "\n", + "2. [Mathematical Introduction to Deep Learning: Methods, Implementations, and Theory, Arnulf Jentzen, Benno Kuckuck, Philippe von Wurstemberger](https://doi.org/10.48550/arXiv.2310.20360)" ] }, { "cell_type": "markdown", - "id": "f5c984c2", + "id": "2cc88c73", + "metadata": { + "editable": true + }, + "source": [ + "## Reminder on books with hands-on material and codes\n", + "* [Sebastian Rashcka et al, Machine learning with Sickit-Learn and PyTorch](https://sebastianraschka.com/blog/2022/ml-pytorch-book.html)" + ] + }, + { + "cell_type": "markdown", + "id": "233d2972", + "metadata": { + "editable": true + }, + "source": [ + "## Reading recommendations\n", + "\n", + "1. Rashkca et al., chapter 11, jupyter-notebook sent separately, from [GitHub](https://github.com/rasbt/machine-learning-book)\n", + "\n", + "2. Goodfellow et al, chapter 6 and 7 contain most of the neural network background." + ] + }, + { + "cell_type": "markdown", + "id": "27cc80b0", + "metadata": { + "editable": true + }, + "source": [ + "## Mathematics of deep learning and neural networks\n", + "\n", + "Neural networks, in its so-called feed-forward form, where each\n", + "iterations contains a feed-forward stage and a back-propgagation\n", + "stage, consist of series of affine matrix-matrix and matrix-vector\n", + "multiplications. The unknown parameters (the so-called biases and\n", + "weights which deternine the architecture of a neural network), are\n", + "uptaded iteratively using the so-called back-propagation algorithm.\n", + "This algorithm corresponds to the so-called reverse mode of \n", + "automatic differentation." + ] + }, + { + "cell_type": "markdown", + "id": "ea3a3c02", + "metadata": { + "editable": true + }, + "source": [ + "## Basics of an NN\n", + "\n", + "A neural network consists of a series of hidden layers, in addition to\n", + "the input and output layers. Each layer $l$ has a set of parameters\n", + "$\\boldsymbol{\\Theta}^{(l)}=(\\boldsymbol{W}^{(l)},\\boldsymbol{b}^{(l)})$ which are related to the\n", + "parameters in other layers through a series of affine transformations,\n", + "for a standard NN these are matrix-matrix and matrix-vector\n", + "multiplications. For all layers we will simply use a collective variable $\\boldsymbol{\\Theta}$.\n", + "\n", + "It consist of two basic steps:\n", + "1. a feed forward stage which takes a given input and produces a final output which is compared with the target values through our cost/loss function.\n", + "\n", + "2. a back-propagation state where the unknown parameters $\\boldsymbol{\\Theta}$ are updated through the optimization of the their gradients. The expressions for the gradients are obtained via the chain rule, starting from the derivative of the cost/function.\n", + "\n", + "These two steps make up one iteration. This iterative process is continued till we reach an eventual stopping criterion." + ] + }, + { + "cell_type": "markdown", + "id": "502d4ad7", + "metadata": { + "editable": true + }, + "source": [ + "## Overarching view of a neural network\n", + "\n", + "The architecture of a neural network defines our model. This model\n", + "aims at describing some function $f(\\boldsymbol{x}$ which represents\n", + "some final result (outputs or tagrget values) given a specific inpput\n", + "$\\boldsymbol{x}$. Note that here $\\boldsymbol{y}$ and $\\boldsymbol{x}$ are not limited to be\n", + "vectors.\n", + "\n", + "The architecture consists of\n", + "1. An input and an output layer where the input layer is defined by the inputs $\\boldsymbol{x}$. The output layer produces the model ouput $\\boldsymbol{\\tilde{y}}$ which is compared with the target value $\\boldsymbol{y}$\n", + "\n", + "2. A given number of hidden layers and neurons/nodes/units for each layer (this may vary)\n", + "\n", + "3. A given activation function $\\sigma(\\boldsymbol{z})$ with arguments $\\boldsymbol{z}$ to be defined below. The activation functions may differ from layer to layer.\n", + "\n", + "4. The last layer, normally called **output** layer has normally an activation function tailored to the specific problem\n", + "\n", + "5. Finally we define a so-called cost or loss function which is used to gauge the quality of our model." + ] + }, + { + "cell_type": "markdown", + "id": "9182519a", + "metadata": { + "editable": true + }, + "source": [ + "## The optimization problem\n", + "\n", + "The cost function is a function of the unknown parameters\n", + "$\\boldsymbol{\\Theta}$ where the latter is a container for all possible\n", + "parameters needed to define a neural network\n", + "\n", + "If we are dealing with a regression task a typical cost/loss function\n", + "is the mean squared error" + ] + }, + { + "cell_type": "markdown", + "id": "15b78cfd", "metadata": { "editable": true }, "source": [ "$$\n", - "y = f\\left(\\sum_{i=1}^n w_ix_i + b_i\\right) = f(z),\n", + "C(\\boldsymbol{\\Theta})=\\frac{1}{n}\\left\\{\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\theta}\\right)^T\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\theta}\\right)\\right\\}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "9743f4cb", + "id": "093b77f1", "metadata": { "editable": true }, "source": [ - "This function receives $x_i$ as inputs.\n", - "Here the activation $z=(\\sum_{i=1}^n w_ix_i+b_i)$. \n", - "In an FFNN of such neurons, the *inputs* $x_i$ are the *outputs* of\n", - "the neurons in the preceding layer. Furthermore, an MLP is\n", - "fully-connected, which means that each neuron receives a weighted sum\n", - "of the outputs of *all* neurons in the previous layer." + "This function represents one of many possible ways to define\n", + "the so-called cost function. Note that here we have assumed a linear dependence in terms of the paramters $\\boldsymbol{\\Theta}$. This is in general not the case." ] }, { "cell_type": "markdown", - "id": "e89c3e3f", + "id": "b6c8a224", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", + "## Parameters of neural networks\n", + "For neural networks the parameters\n", + "$\\boldsymbol{\\Theta}$ are given by the so-called weights and biases (to be\n", + "defined below).\n", "\n", - "First, for each node $i$ in the first hidden layer, we calculate a weighted sum $z_i^1$ of the input coordinates $x_j$," + "The weights are given by matrix elements $w_{ij}^{(l)}$ where the\n", + "superscript indicates the layer number. The biases are typically given\n", + "by vector elements representing each single node of a given layer,\n", + "that is $b_j^{(l)}$." ] }, { "cell_type": "markdown", - "id": "21c83fef", + "id": "f30d7e81", + "metadata": { + "editable": true + }, + "source": [ + "## Other ingredients of a neural network\n", + "\n", + "Having defined the architecture of a neural network, the optimization\n", + "of the cost function with respect to the parameters $\\boldsymbol{\\Theta}$,\n", + "involves the calculations of gradients and their optimization. The\n", + "gradients represent the derivatives of a multidimensional object and\n", + "are often approximated by various gradient methods, including\n", + "1. various quasi-Newton methods,\n", + "\n", + "2. plain gradient descent (GD) with a constant learning rate $\\eta$,\n", + "\n", + "3. GD with momentum and other approximations to the learning rates such as\n", + "\n", + " * Adapative gradient (ADAgrad)\n", + "\n", + " * Root mean-square propagation (RMSprop)\n", + "\n", + " * Adaptive gradient with momentum (ADAM) and many other\n", + "\n", + "4. Stochastic gradient descent and various families of learning rate approximations" + ] + }, + { + "cell_type": "markdown", + "id": "5089007e", + "metadata": { + "editable": true + }, + "source": [ + "## Other parameters\n", + "\n", + "In addition to the above, there are often additional hyperparamaters\n", + "which are included in the setup of a neural network. These will be\n", + "discussed below." + ] + }, + { + "cell_type": "markdown", + "id": "3f9eedcb", + "metadata": { + "editable": true + }, + "source": [ + "## Universal approximation theorem\n", + "\n", + "The universal approximation theorem plays a central role in deep\n", + "learning. [Cybenko (1989)](https://link.springer.com/article/10.1007/BF02551274) showed\n", + "the following:\n", + "\n", + "Let $\\sigma$ be any continuous sigmoidal function such that" + ] + }, + { + "cell_type": "markdown", + "id": "ac052134", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\sigma(z) = \\left\\{\\begin{array}{cc} 1 & z\\rightarrow \\infty\\\\ 0 & z \\rightarrow -\\infty \\end{array}\\right.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c0e639b1", + "metadata": { + "editable": true + }, + "source": [ + "Given a continuous and deterministic function $F(\\boldsymbol{x})$ on the unit\n", + "cube in $d$-dimensions $F\\in [0,1]^d$, $x\\in [0,1]^d$ and a parameter\n", + "$\\epsilon >0$, there is a one-layer (hidden) neural network\n", + "$f(\\boldsymbol{x};\\boldsymbol{\\Theta})$ with $\\boldsymbol{\\Theta}=(\\boldsymbol{W},\\boldsymbol{b})$ and $\\boldsymbol{W}\\in\n", + "\\mathbb{R}^{m\\times n}$ and $\\boldsymbol{b}\\in \\mathbb{R}^{n}$, for which" + ] + }, + { + "cell_type": "markdown", + "id": "6d2878d4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert < \\epsilon \\hspace{0.1cm} \\forall \\boldsymbol{x}\\in[0,1]^d.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dbb5133d", + "metadata": { + "editable": true + }, + "source": [ + "## Some parallels from real analysis\n", + "\n", + "For those of you familiar with for example the [Stone-Weierstrass\n", + "theorem](https://en.wikipedia.org/wiki/Stone%E2%80%93Weierstrass_theorem)\n", + "for polynomial approximations or the convergence criterion for Fourier\n", + "series, there are similarities in the derivation of the proof for\n", + "neural networks." + ] + }, + { + "cell_type": "markdown", + "id": "0da134a5", + "metadata": { + "editable": true + }, + "source": [ + "## The approximation theorem in words\n", + "\n", + "**Any continuous function $y=F(\\boldsymbol{x})$ supported on the unit cube in\n", + "$d$-dimensions can be approximated by a one-layer sigmoidal network to\n", + "arbitrary accuracy.**\n", + "\n", + "[Hornik (1991)](https://www.sciencedirect.com/science/article/abs/pii/089360809190009T) extended the theorem by letting any non-constant, bounded activation function to be included using that the expectation value" + ] + }, + { + "cell_type": "markdown", + "id": "5346e8a0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathbb{E}[\\vert F(\\boldsymbol{x})\\vert^2] =\\int_{\\boldsymbol{x}\\in D} \\vert F(\\boldsymbol{x})\\vert^2p(\\boldsymbol{x})d\\boldsymbol{x} < \\infty.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "36737d10", + "metadata": { + "editable": true + }, + "source": [ + "Then we have" + ] + }, + { + "cell_type": "markdown", + "id": "d81b95ba", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathbb{E}[\\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert^2] =\\int_{\\boldsymbol{x}\\in D} \\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert^2p(\\boldsymbol{x})d\\boldsymbol{x} < \\epsilon.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8432cac2", + "metadata": { + "editable": true + }, + "source": [ + "## More on the general approximation theorem\n", + "\n", + "None of the proofs give any insight into the relation between the\n", + "number of of hidden layers and nodes and the approximation error\n", + "$\\epsilon$, nor the magnitudes of $\\boldsymbol{W}$ and $\\boldsymbol{b}$.\n", + "\n", + "Neural networks (NNs) have what we may call a kind of universality no matter what function we want to compute.\n", + "\n", + "It does not mean that an NN can be used to exactly compute any function. Rather, we get an approximation that is as good as we want." + ] + }, + { + "cell_type": "markdown", + "id": "04d4d751", + "metadata": { + "editable": true + }, + "source": [ + "## Class of functions we can approximate\n", + "\n", + "The class of functions that can be approximated are the continuous ones.\n", + "If the function $F(\\boldsymbol{x})$ is discontinuous, it won't in general be possible to approximate it. However, an NN may still give an approximation even if we fail in some points." + ] + }, + { + "cell_type": "markdown", + "id": "df8f957e", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the equations for a neural network\n", + "\n", + "The questions we want to ask are how do changes in the biases and the\n", + "weights in our network change the cost function and how can we use the\n", + "final output to modify the weights and biases?\n", + "\n", + "To derive these equations let us start with a plain regression problem\n", + "and define our cost function as" + ] + }, + { + "cell_type": "markdown", + "id": "0fc51d93", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\cal C}(\\boldsymbol{\\Theta}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - \\tilde{y}_i\\right)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "fc372df4", + "metadata": { + "editable": true + }, + "source": [ + "where the $y_i$s are our $n$ targets (the values we want to\n", + "reproduce), while the outputs of the network after having propagated\n", + "all inputs $\\boldsymbol{x}$ are given by $\\boldsymbol{\\tilde{y}}_i$." + ] + }, + { + "cell_type": "markdown", + "id": "e1cbafd1", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a neural network with three hidden layers\n", + "\n", + "\n", + "\n", + "\n", + "

Figure 1:

\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "aadba1e0", + "metadata": { + "editable": true + }, + "source": [ + "## Definitions\n", + "\n", + "With our definition of the targets $\\boldsymbol{y}$, the outputs of the\n", + "network $\\boldsymbol{\\tilde{y}}$ and the inputs $\\boldsymbol{x}$ we\n", + "define now the activation $z_j^l$ of node/neuron/unit $j$ of the\n", + "$l$-th layer as a function of the bias, the weights which add up from\n", + "the previous layer $l-1$ and the forward passes/outputs\n", + "$\\hat{a}^{l-1}$ from the previous layer as" + ] + }, + { + "cell_type": "markdown", + "id": "4f0a354f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_j^l = \\sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5b489754", + "metadata": { + "editable": true + }, + "source": [ + "where $b_k^l$ are the biases from layer $l$. Here $M_{l-1}$\n", + "represents the total number of nodes/neurons/units of layer $l-1$. The\n", + "figure in the whiteboard notes illustrates this equation. We can rewrite this in a more\n", + "compact form as the matrix-vector products we discussed earlier," + ] + }, + { + "cell_type": "markdown", + "id": "109a6626", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\hat{z}^l = \\left(\\hat{W}^l\\right)^T\\hat{a}^{l-1}+\\hat{b}^l.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d075c31b", + "metadata": { + "editable": true + }, + "source": [ + "## Inputs to the activation function\n", + "\n", + "With the activation values $\\boldsymbol{z}^l$ we can in turn define the\n", + "output of layer $l$ as $\\boldsymbol{a}^l = f(\\boldsymbol{z}^l)$ where $f$ is our\n", + "activation function. In the examples here we will use the sigmoid\n", + "function discussed in our logistic regression lectures. We will also use the same activation function $f$ for all layers\n", + "and their nodes. It means we have" + ] + }, + { + "cell_type": "markdown", + "id": "ea32a509", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a_j^l = \\sigma(z_j^l) = \\frac{1}{1+\\exp{-(z_j^l)}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8ac36725", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives and the chain rule\n", + "\n", + "From the definition of the activation $z_j^l$ we have" + ] + }, + { + "cell_type": "markdown", + "id": "f3600e09", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z_j^l}{\\partial w_{ij}^l} = a_i^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3e537038", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "34b99ae7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z_j^l}{\\partial a_i^{l-1}} = w_{ji}^l.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e4faa2f2", + "metadata": { + "editable": true + }, + "source": [ + "With our definition of the activation function we have that (note that this function depends only on $z_j^l$)" + ] + }, + { + "cell_type": "markdown", + "id": "b4243031", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a_j^l}{\\partial z_j^{l}} = a_j^l(1-a_j^l)=\\sigma(z_j^l)(1-\\sigma(z_j^l)).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b528c44c", + "metadata": { + "editable": true + }, + "source": [ + "## Derivative of the cost function\n", + "\n", + "With these definitions we can now compute the derivative of the cost function in terms of the weights.\n", + "\n", + "Let us specialize to the output layer $l=L$. Our cost function is" + ] + }, + { + "cell_type": "markdown", + "id": "602e81ab", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\cal C}(\\boldsymbol{\\Theta}^L) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - \\tilde{y}_i\\right)^2=\\frac{1}{2}\\sum_{i=1}^n\\left(a_i^L - y_i\\right)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4ac5e382", + "metadata": { + "editable": true + }, + "source": [ + "The derivative of this function with respect to the weights is" + ] + }, + { + "cell_type": "markdown", + "id": "02edfab2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}(\\boldsymbol{\\Theta}^L)}{\\partial w_{jk}^L} = \\left(a_j^L - y_j\\right)\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "02fffe9d", + "metadata": { + "editable": true + }, + "source": [ + "The last partial derivative can easily be computed and reads (by applying the chain rule)" + ] + }, + { + "cell_type": "markdown", + "id": "f4d679cc", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}} = \\frac{\\partial a_j^L}{\\partial z_{j}^{L}}\\frac{\\partial z_j^L}{\\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3638d432", + "metadata": { + "editable": true + }, + "source": [ + "## Simpler examples first, and automatic differentiation\n", + "\n", + "In order to understand the back propagation algorithm and its\n", + "derivation (an implementation of the chain rule), let us first digress\n", + "with some simple examples. These examples are also meant to motivate\n", + "the link with back propagation and [automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation)." + ] + }, + { + "cell_type": "markdown", + "id": "d3039347", + "metadata": { + "editable": true + }, + "source": [ + "## Reminder on the chain rule and gradients\n", + "\n", + "If we have a multivariate function $f(x,y)$ where $x=x(t)$ and $y=y(t)$ are functions of a variable $t$, we have that the gradient of $f$ with respect to $t$ (without the explicit unit vector components)" + ] + }, + { + "cell_type": "markdown", + "id": "f48bfb76", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dt} = \\begin{bmatrix}\\frac{\\partial f}{\\partial x} & \\frac{\\partial f}{\\partial y} \\end{bmatrix} \\begin{bmatrix}\\frac{\\partial x}{\\partial t} \\\\ \\frac{\\partial y}{\\partial t} \\end{bmatrix}=\\frac{\\partial f}{\\partial x} \\frac{\\partial x}{\\partial t} +\\frac{\\partial f}{\\partial y} \\frac{\\partial y}{\\partial t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "63176c54", + "metadata": { + "editable": true + }, + "source": [ + "## Multivariable functions\n", + "\n", + "If we have a multivariate function $f(x,y)$ where $x=x(t,s)$ and $y=y(t,s)$ are functions of the variables $t$ and $s$, we have that the partial derivatives" + ] + }, + { + "cell_type": "markdown", + "id": "f966f6f1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial s}=\\frac{\\partial f}{\\partial x}\\frac{\\partial x}{\\partial s}+\\frac{\\partial f}{\\partial y}\\frac{\\partial y}{\\partial s},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b0a5a64e", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "fedfd000", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial t}=\\frac{\\partial f}{\\partial x}\\frac{\\partial x}{\\partial t}+\\frac{\\partial f}{\\partial y}\\frac{\\partial y}{\\partial t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "49281876", + "metadata": { + "editable": true + }, + "source": [ + "the gradient of $f$ with respect to $t$ and $s$ (without the explicit unit vector components)" + ] + }, + { + "cell_type": "markdown", + "id": "78dc9b72", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{d(s,t)} = \\begin{bmatrix}\\frac{\\partial f}{\\partial x} & \\frac{\\partial f}{\\partial y} \\end{bmatrix} \\begin{bmatrix}\\frac{\\partial x}{\\partial s} &\\frac{\\partial x}{\\partial t} \\\\ \\frac{\\partial y}{\\partial s} & \\frac{\\partial y}{\\partial t} \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "bf854510", + "metadata": { + "editable": true + }, + "source": [ + "## Automatic differentiation through examples\n", + "\n", + "A great introduction to automatic differentiation is given by Baydin et al., see .\n", + "\n", + "Automatic differentiation is a represented by a repeated application\n", + "of the chain rule on well-known functions and allows for the\n", + "calculation of derivatives to numerical precision. It is not the same\n", + "as the calculation of symbolic derivatives via for example SymPy, nor\n", + "does it use approximative formulae based on Taylor-expansions of a\n", + "function around a given value. The latter are error prone due to\n", + "truncation errors and values of the step size $\\Delta$." + ] + }, + { + "cell_type": "markdown", + "id": "35771431", + "metadata": { + "editable": true + }, + "source": [ + "## Simple example\n", + "\n", + "Our first example is rather simple," + ] + }, + { + "cell_type": "markdown", + "id": "6570ba80", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) =\\exp{x^2},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c30b4d72", + "metadata": { + "editable": true + }, + "source": [ + "with derivative" + ] + }, + { + "cell_type": "markdown", + "id": "183d5f0b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) =2x\\exp{x^2}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b2363c0a", + "metadata": { + "editable": true + }, + "source": [ + "We can use SymPy to extract the pertinent lines of Python code through the following simple example" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "0b51ea21", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "from __future__ import division\n", + "from sympy import *\n", + "x = symbols('x')\n", + "expr = exp(x*x)\n", + "simplify(expr)\n", + "derivative = diff(expr,x)\n", + "print(python(expr))\n", + "print(python(derivative))" + ] + }, + { + "cell_type": "markdown", + "id": "07e24343", + "metadata": { + "editable": true + }, + "source": [ + "## Smarter way of evaluating the above function\n", + "If we study this function, we note that we can reduce the number of operations by introducing an intermediate variable" + ] + }, + { + "cell_type": "markdown", + "id": "1337dd0f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a = x^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a7589947", + "metadata": { + "editable": true + }, + "source": [ + "leading to" + ] + }, + { + "cell_type": "markdown", + "id": "3586c972", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) = f(a(x)) = b= \\exp{a}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0ac52a19", + "metadata": { + "editable": true + }, + "source": [ + "We now assume that all operations can be counted in terms of equal\n", + "floating point operations. This means that in order to calculate\n", + "$f(x)$ we need first to square $x$ and then compute the exponential. We\n", + "have thus two floating point operations only." + ] + }, + { + "cell_type": "markdown", + "id": "18b67b7b", + "metadata": { + "editable": true + }, + "source": [ + "## Reducing the number of operations\n", + "\n", + "With the introduction of a precalculated quantity $a$ and thereby $f(x)$ we have that the derivative can be written as" + ] + }, + { + "cell_type": "markdown", + "id": "75f72d6b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) = 2xb,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ff72bef0", + "metadata": { + "editable": true + }, + "source": [ + "which reduces the number of operations from four in the orginal\n", + "expression to two. This means that if we need to compute $f(x)$ and\n", + "its derivative (a common task in optimizations), we have reduced the\n", + "number of operations from six to four in total.\n", + "\n", + "**Note** that the usage of a symbolic software like SymPy does not\n", + "include such simplifications and the calculations of the function and\n", + "the derivatives yield in general more floating point operations." + ] + }, + { + "cell_type": "markdown", + "id": "ef55737f", + "metadata": { + "editable": true + }, + "source": [ + "## Chain rule, forward and reverse modes\n", + "\n", + "In the above example we have introduced the variables $a$ and $b$, and our function is" + ] + }, + { + "cell_type": "markdown", + "id": "35ab7175", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) = f(a(x)) = b= \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "edc79b33", + "metadata": { + "editable": true + }, + "source": [ + "with $a=x^2$. We can decompose the derivative of $f$ with respect to $x$ as" + ] + }, + { + "cell_type": "markdown", + "id": "4dc12ed8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\frac{db}{da}\\frac{da}{dx}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "bc945b59", + "metadata": { + "editable": true + }, + "source": [ + "We note that since $b=f(x)$ that" + ] + }, + { + "cell_type": "markdown", + "id": "68eac5d0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{db}=1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6ea49d77", + "metadata": { + "editable": true + }, + "source": [ + "leading to" + ] + }, + { + "cell_type": "markdown", + "id": "4a65d6fd", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{db}{da}\\frac{da}{dx}=2x\\exp{x^2},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c66da8ef", + "metadata": { + "editable": true + }, + "source": [ + "as before." + ] + }, + { + "cell_type": "markdown", + "id": "b055e013", + "metadata": { + "editable": true + }, + "source": [ + "## Forward and reverse modes\n", + "\n", + "We have that" + ] + }, + { + "cell_type": "markdown", + "id": "006ef4f0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\frac{db}{da}\\frac{da}{dx},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "99fd1e13", + "metadata": { + "editable": true + }, + "source": [ + "which we can rewrite either as" + ] + }, + { + "cell_type": "markdown", + "id": "d711ba8b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\left[\\frac{df}{db}\\frac{db}{da}\\right]\\frac{da}{dx},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "394f38fd", + "metadata": { + "editable": true + }, + "source": [ + "or" + ] + }, + { + "cell_type": "markdown", + "id": "2f589cea", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\left[\\frac{db}{da}\\frac{da}{dx}\\right].\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "783c3588", + "metadata": { + "editable": true + }, + "source": [ + "The first expression is called reverse mode (or back propagation)\n", + "since we start by evaluating the derivatives at the end point and then\n", + "propagate backwards. This is the standard way of evaluating\n", + "derivatives (gradients) when optimizing the parameters of a neural\n", + "network. In the context of deep learning this is computationally\n", + "more efficient since the output of a neural network consists of either\n", + "one or some few other output variables.\n", + "\n", + "The second equation defines the so-called **forward mode**." + ] + }, + { + "cell_type": "markdown", + "id": "d1627f43", + "metadata": { + "editable": true + }, + "source": [ + "## More complicated function\n", + "\n", + "We increase our ambitions and introduce a slightly more complicated function" + ] + }, + { + "cell_type": "markdown", + "id": "53035043", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) =\\sqrt{x^2+exp{x^2}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f3293e4c", + "metadata": { + "editable": true + }, + "source": [ + "with derivative" + ] + }, + { + "cell_type": "markdown", + "id": "b6087529", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) =\\frac{x(1+\\exp{x^2})}{\\sqrt{x^2+exp{x^2}}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "9a91562c", + "metadata": { + "editable": true + }, + "source": [ + "The corresponding SymPy code reads" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "49153549", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "from __future__ import division\n", + "from sympy import *\n", + "x = symbols('x')\n", + "expr = sqrt(x*x+exp(x*x))\n", + "simplify(expr)\n", + "derivative = diff(expr,x)\n", + "print(python(expr))\n", + "print(python(derivative))" + ] + }, + { + "cell_type": "markdown", + "id": "3f8e08c9", + "metadata": { + "editable": true + }, + "source": [ + "## Counting the number of floating point operations\n", + "\n", + "A simple count of operations shows that we need five operations for\n", + "the function itself and ten for the derivative. Fifteen operations in total if we wish to proceed with the above codes.\n", + "\n", + "Can we reduce this to\n", + "say half the number of operations?" + ] + }, + { + "cell_type": "markdown", + "id": "9479dadf", + "metadata": { + "editable": true + }, + "source": [ + "## Defining intermediate operations\n", + "\n", + "We can indeed reduce the number of operation to half of those listed in the brute force approach above.\n", + "We define the following quantities" + ] + }, + { + "cell_type": "markdown", + "id": "9e5f867e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a = x^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "21ee2a8a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "e09cf187", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b = \\exp{x^2} = \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c999c36b", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "8fbf66c6", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "c= a+b,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dd11cc6a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "69e9e950", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "d=f(x)=\\sqrt{c}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "970b6167", + "metadata": { + "editable": true + }, + "source": [ + "## New expression for the derivative\n", + "\n", + "With these definitions we obtain the following partial derivatives" + ] + }, + { + "cell_type": "markdown", + "id": "5655fa59", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a}{\\partial x} = 2x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1c8a1f68", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "edaf4340", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial b}{\\partial a} = \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f39563ef", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "c3fad1fe", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial c}{\\partial a} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2f26318c", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "75e08a4f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial c}{\\partial b} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2729f6dc", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "7ccfc31a", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial d}{\\partial c} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1e39402f", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "a8313c23", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial d} = 1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "64f5a96d", + "metadata": { + "editable": true + }, + "source": [ + "## Final derivatives\n", + "Our final derivatives are thus" + ] + }, + { + "cell_type": "markdown", + "id": "e087f8b8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial c} = \\frac{\\partial f}{\\partial d} \\frac{\\partial d}{\\partial c} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ab9adb45", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial b} = \\frac{\\partial f}{\\partial c} \\frac{\\partial c}{\\partial b} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e7125560", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial a} = \\frac{\\partial f}{\\partial c} \\frac{\\partial c}{\\partial a}+\n", + "\\frac{\\partial f}{\\partial b} \\frac{\\partial b}{\\partial a} = \\frac{1+\\exp{a}}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6c4ad559", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "b42e32a4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x} = \\frac{\\partial f}{\\partial a} \\frac{\\partial a}{\\partial x} = \\frac{x(1+\\exp{a})}{\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "40de97ba", + "metadata": { + "editable": true + }, + "source": [ + "which is just" + ] + }, + { + "cell_type": "markdown", + "id": "22d0d252", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x} = \\frac{x(1+b)}{d},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "be68a064", + "metadata": { + "editable": true + }, + "source": [ + "and requires only three operations if we can reuse all intermediate variables." + ] + }, + { + "cell_type": "markdown", + "id": "ed92fb3c", + "metadata": { + "editable": true + }, + "source": [ + "## In general not this simple\n", + "\n", + "In general, see the generalization below, unless we can obtain simple\n", + "analytical expressions which we can simplify further, the final\n", + "implementation of automatic differentiation involves repeated\n", + "calculations (and thereby operations) of derivatives of elementary\n", + "functions." + ] + }, + { + "cell_type": "markdown", + "id": "b565b39a", + "metadata": { + "editable": true + }, + "source": [ + "## Automatic differentiation\n", + "\n", + "We can make this example more formal. Automatic differentiation is a\n", + "formalization of the previous example (see graph).\n", + "\n", + "We define $\\boldsymbol{x}\\in x_1,\\dots, x_l$ input variables to a given function $f(\\boldsymbol{x})$ and $x_{l+1},\\dots, x_L$ intermediate variables.\n", + "\n", + "In the above example we have only one input variable, $l=1$ and four intermediate variables, that is" + ] + }, + { + "cell_type": "markdown", + "id": "587ae22d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix} x_1=x & x_2 = x^2=a & x_3 =\\exp{a}= b & x_4=c=a+b & x_5 = \\sqrt{c}=d \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a54b74ca", + "metadata": { + "editable": true + }, + "source": [ + "Furthemore, for $i=l+1, \\dots, L$ (here $i=2,3,4,5$ and $f=x_L=d$), we\n", + "define the elementary functions $g_i(x_{Pa(x_i)})$ where $x_{Pa(x_i)}$ are the parent nodes of the variable $x_i$.\n", + "\n", + "In our case, we have for example for $x_3=g_3(x_{Pa(x_i)})=\\exp{a}$, that $g_3=\\exp{()}$ and $x_{Pa(x_3)}=a$." + ] + }, + { + "cell_type": "markdown", + "id": "bcfc076a", + "metadata": { + "editable": true + }, + "source": [ + "## Chain rule\n", + "\n", + "We can now compute the gradients by back-propagating the derivatives using the chain rule.\n", + "We have defined" + ] + }, + { + "cell_type": "markdown", + "id": "b4194098", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x_L} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "acc7030d", + "metadata": { + "editable": true + }, + "source": [ + "which allows us to find the derivatives of the various variables $x_i$ as" + ] + }, + { + "cell_type": "markdown", + "id": "02f92f41", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x_i} = \\sum_{x_j:x_i\\in Pa(x_j)}\\frac{\\partial f}{\\partial x_j} \\frac{\\partial x_j}{\\partial x_i}=\\sum_{x_j:x_i\\in Pa(x_j)}\\frac{\\partial f}{\\partial x_j} \\frac{\\partial g_j}{\\partial x_i}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5541dfd1", + "metadata": { + "editable": true + }, + "source": [ + "Whenever we have a function which can be expressed as a computation\n", + "graph and the various functions can be expressed in terms of\n", + "elementary functions that are differentiable, then automatic\n", + "differentiation works. The functions may not need to be elementary\n", + "functions, they could also be computer programs, although not all\n", + "programs can be automatically differentiated." + ] + }, + { + "cell_type": "markdown", + "id": "f73cf263", + "metadata": { + "editable": true + }, + "source": [ + "## First network example, simple percepetron with one input\n", + "\n", + "As yet another example we define now a simple perceptron model with\n", + "all quantities given by scalars. We consider only one input variable\n", + "$x$ and one target value $y$. We define an activation function\n", + "$\\sigma_1$ which takes as input" + ] + }, + { + "cell_type": "markdown", + "id": "4b8722cb", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_1 = w_1x+b_1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a604334f", + "metadata": { + "editable": true + }, + "source": [ + "where $w_1$ is the weight and $b_1$ is the bias. These are the\n", + "parameters we want to optimize. The output is $a_1=\\sigma(z_1)$ (see\n", + "graph from whiteboard notes). This output is then fed into the\n", + "**cost/loss** function, which we here for the sake of simplicity just\n", + "define as the squared error" + ] + }, + { + "cell_type": "markdown", + "id": "0017f42e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(x;w_1,b_1)=\\frac{1}{2}(a_1-y)^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8c47d806", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with no hidden layer\n", + "\n", + "\n", + "\n", + "\n", + "

Figure 1:

\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "df503def", + "metadata": { + "editable": true + }, + "source": [ + "## Optimizing the parameters\n", + "\n", + "In setting up the feed forward and back propagation parts of the\n", + "algorithm, we need now the derivative of the various variables we want\n", + "to train.\n", + "\n", + "We need" + ] + }, + { + "cell_type": "markdown", + "id": "bdc97982", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1} \\hspace{0.1cm}\\mathrm{and}\\hspace{0.1cm}\\frac{\\partial C}{\\partial b_1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "42716985", + "metadata": { + "editable": true + }, + "source": [ + "Using the chain rule we find" + ] + }, + { + "cell_type": "markdown", + "id": "6df9aa60", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1}=\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial w_1}=(a_1-y)\\sigma_1'x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "30f9e077", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "77e9d494", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_1}=\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial b_1}=(a_1-y)\\sigma_1',\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1136c644", + "metadata": { + "editable": true + }, + "source": [ + "which we later will just define as" + ] + }, + { + "cell_type": "markdown", + "id": "b9f253ba", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}=\\delta_1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "14d41c44", + "metadata": { + "editable": true + }, + "source": [ + "## Adding a hidden layer\n", + "\n", + "We change our simple model to (see graph)\n", + "a network with just one hidden layer but with scalar variables only.\n", + "\n", + "Our output variable changes to $a_2$ and $a_1$ is now the output from the hidden node and $a_0=x$.\n", + "We have then" + ] + }, + { + "cell_type": "markdown", + "id": "d7c607f5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_1 = w_1a_0+b_1 \\hspace{0.1cm} \\wedge a_1 = \\sigma_1(z_1),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "609e28e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_2 = w_2a_1+b_2 \\hspace{0.1cm} \\wedge a_2 = \\sigma_2(z_2),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "494580d5", + "metadata": { + "editable": true + }, + "source": [ + "and the cost function" + ] + }, + { + "cell_type": "markdown", + "id": "03665a6f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(x;\\boldsymbol{\\Theta})=\\frac{1}{2}(a_2-y)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "911b5d2c", + "metadata": { + "editable": true + }, + "source": [ + "with $\\boldsymbol{\\Theta}=[w_1,w_2,b_1,b_2]$." + ] + }, + { + "cell_type": "markdown", + "id": "91e4f869", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with one hidden layer\n", + "\n", + "\n", + "\n", + "\n", + "

Figure 1:

\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "43efdd27", + "metadata": { + "editable": true + }, + "source": [ + "## The derivatives\n", + "\n", + "The derivatives are now, using the chain rule again" + ] + }, + { + "cell_type": "markdown", + "id": "25d99018", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_2}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial w_2}=(a_2-y)\\sigma_2'a_1=\\delta_2a_1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6924f790", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_2}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial b_2}=(a_2-y)\\sigma_2'=\\delta_2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f457fe37", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial w_1}=(a_2-y)\\sigma_2'a_1\\sigma_1'a_0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "81e40678", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_1}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial b_1}=(a_2-y)\\sigma_2'\\sigma_1'=\\delta_1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c954b1f9", + "metadata": { + "editable": true + }, + "source": [ + "Can you generalize this to more than one hidden layer?" + ] + }, + { + "cell_type": "markdown", + "id": "87d10fa3", + "metadata": { + "editable": true + }, + "source": [ + "## Important observations\n", + "\n", + "From the above equations we see that the derivatives of the activation\n", + "functions play a central role. If they vanish, the training may\n", + "stop. This is called the vanishing gradient problem, see discussions below. If they become\n", + "large, the parameters $w_i$ and $b_i$ may simply go to infinity. This\n", + "is referenced as the exploding gradient problem." + ] + }, + { + "cell_type": "markdown", + "id": "c20ef010", + "metadata": { + "editable": true + }, + "source": [ + "## The training\n", + "\n", + "The training of the parameters is done through various gradient descent approximations with" + ] + }, + { + "cell_type": "markdown", + "id": "e9de19ea", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}\\leftarrow w_{i}- \\eta \\delta_i a_{i-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3487e8b8", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "7baa62bc", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_i \\leftarrow b_i-\\eta \\delta_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a3c1590a", + "metadata": { + "editable": true + }, + "source": [ + "with $\\eta$ is the learning rate.\n", + "\n", + "One iteration consists of one feed forward step and one back-propagation step. Each back-propagation step does one update of the parameters $\\boldsymbol{\\Theta}$.\n", + "\n", + "For the first hidden layer $a_{i-1}=a_0=x$ for this simple model." + ] + }, + { + "cell_type": "markdown", + "id": "3c3dc625", + "metadata": { + "editable": true + }, + "source": [ + "## Code example\n", + "\n", + "The code here implements the above model with one hidden layer and\n", + "scalar variables for the same function we studied in the previous\n", + "example. The code is however set up so that we can add multiple\n", + "inputs $x$ and target values $y$. Note also that we have the\n", + "possibility of defining a feature matrix $\\boldsymbol{X}$ with more than just\n", + "one column for the input values. This will turn useful in our next example. We have also defined matrices and vectors for all of our operations although it is not necessary here." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "e9fb1fc9", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "# We use the Sigmoid function as activation function\n", + "def sigmoid(z):\n", + " return 1.0/(1.0+np.exp(-z))\n", + "\n", + "def forwardpropagation(x):\n", + " # weighted sum of inputs to the hidden layer\n", + " z_1 = np.matmul(x, w_1) + b_1\n", + " # activation in the hidden layer\n", + " a_1 = sigmoid(z_1)\n", + " # weighted sum of inputs to the output layer\n", + " z_2 = np.matmul(a_1, w_2) + b_2\n", + " a_2 = z_2\n", + " return a_1, a_2\n", + "\n", + "def backpropagation(x, y):\n", + " a_1, a_2 = forwardpropagation(x)\n", + " # parameter delta for the output layer, note that a_2=z_2 and its derivative wrt z_2 is just 1\n", + " delta_2 = a_2 - y\n", + " print(0.5*((a_2-y)**2))\n", + " # delta for the hidden layer\n", + " delta_1 = np.matmul(delta_2, w_2.T) * a_1 * (1 - a_1)\n", + " # gradients for the output layer\n", + " output_weights_gradient = np.matmul(a_1.T, delta_2)\n", + " output_bias_gradient = np.sum(delta_2, axis=0)\n", + " # gradient for the hidden layer\n", + " hidden_weights_gradient = np.matmul(x.T, delta_1)\n", + " hidden_bias_gradient = np.sum(delta_1, axis=0)\n", + " return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient\n", + "\n", + "\n", + "# ensure the same random numbers appear every time\n", + "np.random.seed(0)\n", + "# Input variable\n", + "x = np.array([4.0],dtype=np.float64)\n", + "# Target values\n", + "y = 2*x+1.0 \n", + "\n", + "# Defining the neural network, only scalars here\n", + "n_inputs = x.shape\n", + "n_features = 1\n", + "n_hidden_neurons = 1\n", + "n_outputs = 1\n", + "\n", + "# Initialize the network\n", + "# weights and bias in the hidden layer\n", + "w_1 = np.random.randn(n_features, n_hidden_neurons)\n", + "b_1 = np.zeros(n_hidden_neurons) + 0.01\n", + "\n", + "# weights and bias in the output layer\n", + "w_2 = np.random.randn(n_hidden_neurons, n_outputs)\n", + "b_2 = np.zeros(n_outputs) + 0.01\n", + "\n", + "eta = 0.1\n", + "for i in range(50):\n", + " # calculate gradients\n", + " derivW2, derivB2, derivW1, derivB1 = backpropagation(x, y)\n", + " # update weights and biases\n", + " w_2 -= eta * derivW2\n", + " b_2 -= eta * derivB2\n", + " w_1 -= eta * derivW1\n", + " b_1 -= eta * derivB1" + ] + }, + { + "cell_type": "markdown", + "id": "351debb8", + "metadata": { + "editable": true + }, + "source": [ + "We see that after some few iterations (the results do depend on the learning rate however), we get an error which is rather small." + ] + }, + { + "cell_type": "markdown", + "id": "c6579e36", + "metadata": { + "editable": true + }, + "source": [ + "## Exercise 1: Including more data\n", + "\n", + "Try to increase the amount of input and\n", + "target/output data. Try also to perform calculations for more values\n", + "of the learning rates. Feel free to add either hyperparameters with an\n", + "$l_1$ norm or an $l_2$ norm and discuss your results.\n", + "Discuss your results as functions of the amount of training data and various learning rates.\n", + "\n", + "**Challenge:** Try to change the activation functions and replace the hard-coded analytical expressions with automatic derivation via either **autograd** or **JAX**." + ] + }, + { + "cell_type": "markdown", + "id": "2c80a4b1", + "metadata": { + "editable": true + }, + "source": [ + "## Simple neural network and the back propagation equations\n", + "\n", + "Let us now try to increase our level of ambition and attempt at setting \n", + "up the equations for a neural network with two input nodes, one hidden\n", + "layer with two hidden nodes and one output layer with one output node/neuron only (see graph)..\n", + "\n", + "We need to define the following parameters and variables with the input layer (layer $(0)$) \n", + "where we label the nodes $x_0$ and $x_1$" + ] + }, + { + "cell_type": "markdown", + "id": "c834edc8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "x_0 = a_0^{(0)} \\wedge x_1 = a_1^{(0)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "79bd199b", + "metadata": { + "editable": true + }, + "source": [ + "The hidden layer (layer $(1)$) has nodes which yield the outputs $a_0^{(1)}$ and $a_1^{(1)}$) with weight $\\boldsymbol{w}$ and bias $\\boldsymbol{b}$ parameters" + ] + }, + { + "cell_type": "markdown", + "id": "0a856855", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{ij}^{(1)}=\\left\\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)}\\right\\} \\wedge b^{(1)}=\\left\\{b_0^{(1)},b_1^{(1)}\\right\\}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "54280198", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with two input nodes, one hidden layer and one output node\n", + "\n", + "\n", + "\n", + "\n", + "

Figure 1:

\n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "b2cee09c", + "metadata": { + "editable": true + }, + "source": [ + "## The ouput layer\n", + "\n", + "Finally, we have the ouput layer given by layer label $(2)$ with output $a^{(2)}$ and weights and biases to be determined given by the variables" + ] + }, + { + "cell_type": "markdown", + "id": "710131c9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}^{(2)}=\\left\\{w_{0}^{(2)},w_{1}^{(2)}\\right\\} \\wedge b^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "cd8b54e5", + "metadata": { + "editable": true + }, + "source": [ + "Our output is $\\tilde{y}=a^{(2)}$ and we define a generic cost function $C(a^{(2)},y;\\boldsymbol{\\Theta})$ where $y$ is the target value (a scalar here).\n", + "The parameters we need to optimize are given by" + ] + }, + { + "cell_type": "markdown", + "id": "8998ad11", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{\\Theta}=\\left\\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)},w_{0}^{(2)},w_{1}^{(2)},b_0^{(1)},b_1^{(1)},b^{(2)}\\right\\}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7d430cf7", + "metadata": { + "editable": true + }, + "source": [ + "## Compact expressions\n", + "\n", + "We can define the inputs to the activation functions for the various layers in terms of various matrix-vector multiplications and vector additions.\n", + "The inputs to the first hidden layer are" + ] + }, + { + "cell_type": "markdown", + "id": "9b5a6c95", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix}z_0^{(1)} \\\\ z_1^{(1)} \\end{bmatrix}=\\begin{bmatrix}w_{00}^{(1)} & w_{01}^{(1)}\\\\ w_{10}^{(1)} &w_{11}^{(1)} \\end{bmatrix}\\begin{bmatrix}a_0^{(0)} \\\\ a_1^{(0)} \\end{bmatrix}+\\begin{bmatrix}b_0^{(1)} \\\\ b_1^{(1)} \\end{bmatrix},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "31d044d8", + "metadata": { + "editable": true + }, + "source": [ + "with outputs" + ] + }, + { + "cell_type": "markdown", + "id": "f5125cb7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix}a_0^{(1)} \\\\ a_1^{(1)} \\end{bmatrix}=\\begin{bmatrix}\\sigma^{(1)}(z_0^{(1)}) \\\\ \\sigma^{(1)}(z_1^{(1)}) \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0eed1fab", + "metadata": { + "editable": true + }, + "source": [ + "## Output layer\n", + "\n", + "For the final output layer we have the inputs to the final activation function" + ] + }, + { + "cell_type": "markdown", + "id": "9a9811d2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z^{(2)} = w_{0}^{(2)}a_0^{(1)} +w_{1}^{(2)}a_1^{(1)}+b^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "98bf5097", + "metadata": { + "editable": true + }, + "source": [ + "resulting in the output" + ] + }, + { + "cell_type": "markdown", + "id": "e749c895", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a^{(2)}=\\sigma^{(2)}(z^{(2)}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ea6692ce", + "metadata": { + "editable": true + }, + "source": [ + "## Explicit derivatives\n", + "\n", + "In total we have nine parameters which we need to train. Using the\n", + "chain rule (or just the back-propagation algorithm) we can find all\n", + "derivatives. Since we will use automatic differentiation in reverse\n", + "mode, we start with the derivatives of the cost function with respect\n", + "to the parameters of the output layer, namely" + ] + }, + { + "cell_type": "markdown", + "id": "bf74eae4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{i}^{(2)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\\frac{\\partial z^{(2)}}{\\partial w_{i}^{(2)}}=\\delta^{(2)}a_i^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d590dc50", + "metadata": { + "editable": true + }, + "source": [ + "with" + ] + }, + { + "cell_type": "markdown", + "id": "eb0b8e3c", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta^{(2)}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7928cd11", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "8fc852e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b^{(2)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\\frac{\\partial z^{(2)}}{\\partial b^{(2)}}=\\delta^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "634713ba", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives of the hidden layer\n", + "\n", + "Using the chain rule we have the following expressions for say one of the weight parameters (it is easy to generalize to the other weight parameters)" + ] + }, + { + "cell_type": "markdown", + "id": "0f6ca3e6", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{00}^{(1)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\n", + "\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}}= \\delta^{(2)}\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3b54e63f", + "metadata": { + "editable": true + }, + "source": [ + "which, noting that" + ] + }, + { + "cell_type": "markdown", + "id": "a69c61ff", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z^{(2)} =w_0^{(2)}a_0^{(1)}+w_1^{(2)}a_1^{(1)}+b^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a73b8fe2", + "metadata": { + "editable": true + }, + "source": [ + "allows us to rewrite" + ] + }, + { + "cell_type": "markdown", + "id": "093c845d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}}=w_0^{(2)}\\frac{\\partial a_0^{(1)}}{\\partial z_0^{(1)}}a_0^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dcd12209", + "metadata": { + "editable": true + }, + "source": [ + "## Final expression\n", + "Defining" + ] + }, + { + "cell_type": "markdown", + "id": "5d5e8985", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_0^{(1)}=w_0^{(2)}\\frac{\\partial a_0^{(1)}}{\\partial z_0^{(1)}}\\delta^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "506f74bf", + "metadata": { + "editable": true + }, + "source": [ + "we have" + ] + }, + { + "cell_type": "markdown", + "id": "b474afaa", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{00}^{(1)}}=\\delta_0^{(1)}a_0^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7d14d370", + "metadata": { + "editable": true + }, + "source": [ + "Similarly, we obtain" + ] + }, + { + "cell_type": "markdown", + "id": "ca679e05", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{01}^{(1)}}=\\delta_0^{(1)}a_1^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "251a03fd", + "metadata": { + "editable": true + }, + "source": [ + "## Completing the list\n", + "\n", + "Similarly, we find" + ] + }, + { + "cell_type": "markdown", + "id": "b7575ec0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{10}^{(1)}}=\\delta_1^{(1)}a_0^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "02453de3", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "4e989854", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{11}^{(1)}}=\\delta_1^{(1)}a_1^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "05a25565", + "metadata": { + "editable": true + }, + "source": [ + "where we have defined" + ] + }, + { + "cell_type": "markdown", + "id": "d9e571d7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_1^{(1)}=w_1^{(2)}\\frac{\\partial a_1^{(1)}}{\\partial z_1^{(1)}}\\delta^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f96632e9", + "metadata": { + "editable": true + }, + "source": [ + "## Final expressions for the biases of the hidden layer\n", + "\n", + "For the sake of completeness, we list the derivatives of the biases, which are" + ] + }, + { + "cell_type": "markdown", + "id": "e15002e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_{0}^{(1)}}=\\delta_0^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8c683755", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "da56a290", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_{1}^{(1)}}=\\delta_1^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e42a9d6c", + "metadata": { + "editable": true + }, + "source": [ + "As we will see below, these expressions can be generalized in a more compact form." + ] + }, + { + "cell_type": "markdown", + "id": "21dd6563", + "metadata": { + "editable": true + }, + "source": [ + "## Gradient expressions\n", + "\n", + "For this specific model, with just one output node and two hidden\n", + "nodes, the gradient descent equations take the following form for output layer" + ] + }, + { + "cell_type": "markdown", + "id": "67fc0189", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}^{(2)}\\leftarrow w_{i}^{(2)}- \\eta \\delta^{(2)} a_{i}^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "daddd95e", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "5bf8af85", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b^{(2)} \\leftarrow b^{(2)}-\\eta \\delta^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5a72ea0a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "edd32da2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{ij}^{(1)}\\leftarrow w_{ij}^{(1)}- \\eta \\delta_{i}^{(1)} a_{j}^{(0)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "75c31af5", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "c037d92b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_{i}^{(1)} \\leftarrow b_{i}^{(1)}-\\eta \\delta_{i}^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5937fd51", + "metadata": { + "editable": true + }, + "source": [ + "where $\\eta$ is the learning rate." + ] + }, + { + "cell_type": "markdown", + "id": "3f0f6cd3", + "metadata": { + "editable": true + }, + "source": [ + "## Exercise 2: Extended program\n", + "\n", + "We extend our simple code to a function which depends on two variable $x_0$ and $x_1$, that is" + ] + }, + { + "cell_type": "markdown", + "id": "057366c1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "y=f(x_0,x_1)=x_0^2+3x_0x_1+x_1^2+5.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "293fa11b", + "metadata": { + "editable": true + }, + "source": [ + "We feed our network with $n=100$ entries $x_0$ and $x_1$. We have thus two features represented by these variable and an input matrix/design matrix $\\boldsymbol{X}\\in \\mathbf{R}^{n\\times 2}$" + ] + }, + { + "cell_type": "markdown", + "id": "d652c45d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{X}=\\begin{bmatrix} x_{00} & x_{01} \\\\ x_{00} & x_{01} \\\\ x_{10} & x_{11} \\\\ x_{20} & x_{21} \\\\ \\dots & \\dots \\\\ \\dots & \\dots \\\\ x_{n-20} & x_{n-21} \\\\ x_{n-10} & x_{n-11} \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8ca9d167", + "metadata": { + "editable": true + }, + "source": [ + "Write a code, based on the previous code examples, which takes as input these data and fit the above function.\n", + "You can extend your code to include automatic differentiation.\n", + "\n", + "With these examples, we are now ready to embark upon the writing of more a general code for neural networks." + ] + }, + { + "cell_type": "markdown", + "id": "8fed1e03", + "metadata": { + "editable": true + }, + "source": [ + "## Getting serious, the back propagation equations for a neural network\n", + "\n", + "Now it is time to move away from one node in each layer only. Our inputs are also represented either by several inputs.\n", + "\n", + "We have thus" + ] + }, + { + "cell_type": "markdown", + "id": "6394a2a5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}((\\boldsymbol{\\Theta}^L)}{\\partial w_{jk}^L} = \\left(a_j^L - y_j\\right)a_j^L(1-a_j^L)a_k^{L-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c2e22893", + "metadata": { + "editable": true + }, + "source": [ + "Defining" + ] + }, + { + "cell_type": "markdown", + "id": "5e054d69", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L = a_j^L(1-a_j^L)\\left(a_j^L - y_j\\right) = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dd5f9a8d", + "metadata": { + "editable": true + }, + "source": [ + "and using the Hadamard product of two vectors we can write this as" + ] + }, + { + "cell_type": "markdown", + "id": "ff6e8f86", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{\\delta}^L = \\sigma'(\\hat{z}^L)\\circ\\frac{\\partial {\\cal C}}{\\partial (\\boldsymbol{a}^L)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6e186667", + "metadata": { + "editable": true + }, + "source": [ + "## Analyzing the last results\n", + "\n", + "This is an important expression. The second term on the right handside\n", + "measures how fast the cost function is changing as a function of the $j$th\n", + "output activation. If, for example, the cost function doesn't depend\n", + "much on a particular output node $j$, then $\\delta_j^L$ will be small,\n", + "which is what we would expect. The first term on the right, measures\n", + "how fast the activation function $f$ is changing at a given activation\n", + "value $z_j^L$." + ] + }, + { + "cell_type": "markdown", + "id": "0e0a514f", + "metadata": { + "editable": true + }, + "source": [ + "## More considerations\n", + "\n", + "Notice that everything in the above equations is easily computed. In\n", + "particular, we compute $z_j^L$ while computing the behaviour of the\n", + "network, and it is only a small additional overhead to compute\n", + "$\\sigma'(z^L_j)$. The exact form of the derivative with respect to the\n", + "output depends on the form of the cost function.\n", + "However, provided the cost function is known there should be little\n", + "trouble in calculating" + ] + }, + { + "cell_type": "markdown", + "id": "e8259ee9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3c817881", + "metadata": { + "editable": true + }, + "source": [ + "With the definition of $\\delta_j^L$ we have a more compact definition of the derivative of the cost function in terms of the weights, namely" + ] + }, + { + "cell_type": "markdown", + "id": "0f3e5b1c", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4e14ef60", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives in terms of $z_j^L$\n", + "\n", + "It is also easy to see that our previous equation can be written as" + ] + }, + { + "cell_type": "markdown", + "id": "886fbebf", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L =\\frac{\\partial {\\cal C}}{\\partial z_j^L}= \\frac{\\partial {\\cal C}}{\\partial a_j^L}\\frac{\\partial a_j^L}{\\partial z_j^L},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "16d62157", + "metadata": { + "editable": true + }, + "source": [ + "which can also be interpreted as the partial derivative of the cost function with respect to the biases $b_j^L$, namely" + ] + }, + { + "cell_type": "markdown", + "id": "4a81d6b5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L}\\frac{\\partial b_j^L}{\\partial z_j^L}=\\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0bcee50c", + "metadata": { + "editable": true + }, + "source": [ + "That is, the error $\\delta_j^L$ is exactly equal to the rate of change of the cost function as a function of the bias." + ] + }, + { + "cell_type": "markdown", + "id": "0ed7f7a0", + "metadata": { + "editable": true + }, + "source": [ + "## Bringing it together\n", + "\n", + "We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are" + ] + }, + { + "cell_type": "markdown", + "id": "a502b908", "metadata": { "editable": true }, @@ -614,7 +3653,8 @@ "
\n", "\n", "$$\n", - "\\begin{equation} z_i^1 = \\sum_{j=1}^{M} w_{ij}^1 x_j + b_i^1\n", + "\\begin{equation}\n", + "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1},\n", "\\label{_auto1} \\tag{2}\n", "\\end{equation}\n", "$$" @@ -622,95 +3662,17 @@ }, { "cell_type": "markdown", - "id": "3267338f", + "id": "fa4de05b", "metadata": { "editable": true }, "source": [ - "Here $b_i$ is the so-called bias which is normally needed in\n", - "case of zero activation weights or inputs. How to fix the biases and\n", - "the weights will be discussed below. The value of $z_i^1$ is the\n", - "argument to the activation function $f_i$ of each node $i$, The\n", - "variable $M$ stands for all possible inputs to a given node $i$ in the\n", - "first layer. We define the output $y_i^1$ of all neurons in layer 1 as" + "and" ] }, { "cell_type": "markdown", - "id": "04a1a613", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
\n", - "\n", - "$$\n", - "\\begin{equation}\n", - " y_i^1 = f(z_i^1) = f\\left(\\sum_{j=1}^M w_{ij}^1 x_j + b_i^1\\right)\n", - "\\label{outputLayer1} \\tag{3}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bc8b70e2", - "metadata": { - "editable": true - }, - "source": [ - "where we assume that all nodes in the same layer have identical\n", - "activation functions, hence the notation $f$. In general, we could assume in the more general case that different layers have different activation functions.\n", - "In this case we would identify these functions with a superscript $l$ for the $l$-th layer," - ] - }, - { - "cell_type": "markdown", - "id": "10686541", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
\n", - "\n", - "$$\n", - "\\begin{equation}\n", - " y_i^l = f^l(u_i^l) = f^l\\left(\\sum_{j=1}^{N_{l-1}} w_{ij}^l y_j^{l-1} + b_i^l\\right)\n", - "\\label{generalLayer} \\tag{4}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "a92cdf36", - "metadata": { - "editable": true - }, - "source": [ - "where $N_l$ is the number of nodes in layer $l$. When the output of\n", - "all the nodes in the first hidden layer are computed, the values of\n", - "the subsequent layer can be calculated and so forth until the output\n", - "is obtained." - ] - }, - { - "cell_type": "markdown", - "id": "74dcfa13", - "metadata": { - "editable": true - }, - "source": [ - "## Mathematical model\n", - "\n", - "The output of neuron $i$ in layer 2 is thus," - ] - }, - { - "cell_type": "markdown", - "id": "0147afef", + "id": "cea42eaf", "metadata": { "editable": true }, @@ -720,43 +3682,25 @@ "\n", "$$\n", "\\begin{equation}\n", - " y_i^2 = f^2\\left(\\sum_{j=1}^N w_{ij}^2 y_j^1 + b_i^2\\right) \n", - "\\label{_auto2} \\tag{5}\n", + "\\delta_j^L = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", + "\\label{_auto2} \\tag{3}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "4a4d5b2e", + "id": "d04fa6e6", "metadata": { "editable": true }, "source": [ - "\n", - "
\n", - "\n", - "$$\n", - "\\begin{equation} \n", - " = f^2\\left[\\sum_{j=1}^N w_{ij}^2f^1\\left(\\sum_{k=1}^M w_{jk}^1 x_k + b_j^1\\right) + b_i^2\\right]\n", - "\\label{outputLayer2} \\tag{6}\n", - "\\end{equation}\n", - "$$" + "and" ] }, { "cell_type": "markdown", - "id": "31742756", - "metadata": { - "editable": true - }, - "source": [ - "where we have substituted $y_k^1$ with the inputs $x_k$. Finally, the ANN output reads" - ] - }, - { - "cell_type": "markdown", - "id": "123af90c", + "id": "8716ad2e", "metadata": { "editable": true }, @@ -766,224 +3710,304 @@ "\n", "$$\n", "\\begin{equation}\n", - " y_i^3 = f^3\\left(\\sum_{j=1}^N w_{ij}^3 y_j^2 + b_i^3\\right) \n", - "\\label{_auto3} \\tag{7}\n", + "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", + "\\label{_auto3} \\tag{4}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "aeb7cc95", + "id": "f64753b2", "metadata": { "editable": true }, "source": [ - "\n", - "
\n", + "## Final back propagating equation\n", "\n", + "We have that (replacing $L$ with a general layer $l$)" + ] + }, + { + "cell_type": "markdown", + "id": "4ad6d6d3", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation} \n", - " = f_3\\left[\\sum_{j} w_{ij}^3 f^2\\left(\\sum_{k} w_{jk}^2 f^1\\left(\\sum_{m} w_{km}^1 x_m + b_k^1\\right) + b_j^2\\right)\n", - " + b_1^3\\right]\n", - "\\label{_auto4} \\tag{8}\n", - "\\end{equation}\n", + "\\delta_j^l =\\frac{\\partial {\\cal C}}{\\partial z_j^l}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "3ab7d88c", + "id": "a8d42ee3", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", - "\n", - "We can generalize this expression to an MLP with $l$ hidden\n", - "layers. The complete functional form is," + "We want to express this in terms of the equations for layer $l+1$." ] }, { "cell_type": "markdown", - "id": "9b07f5bb", + "id": "0628c4b8", "metadata": { "editable": true }, "source": [ - "\n", - "
\n", + "## Using the chain rule and summing over all $k$ entries\n", "\n", + "We obtain" + ] + }, + { + "cell_type": "markdown", + "id": "0868f3d3", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation}\n", - "y^{l+1}_i = f^{l+1}\\left[\\!\\sum_{j=1}^{N_l} w_{ij}^3 f^l\\left(\\sum_{k=1}^{N_{l-1}}w_{jk}^{l-1}\\left(\\dots f^1\\left(\\sum_{n=1}^{N_0} w_{mn}^1 x_n+ b_m^1\\right)\\dots\\right)+b_k^2\\right)+b_1^3\\right] \n", - "\\label{completeNN} \\tag{9}\n", - "\\end{equation}\n", + "\\delta_j^l =\\sum_k \\frac{\\partial {\\cal C}}{\\partial z_k^{l+1}}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}}=\\sum_k \\delta_k^{l+1}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}},\n", "$$" ] }, { "cell_type": "markdown", - "id": "e9b4beb5", + "id": "89190c24", "metadata": { "editable": true }, "source": [ - "which illustrates a basic property of MLPs: The only independent\n", - "variables are the input values $x_n$." + "and recalling that" ] }, { "cell_type": "markdown", - "id": "57213d71", + "id": "96af414a", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", - "\n", - "This confirms that an MLP, despite its quite convoluted mathematical\n", - "form, is nothing more than an analytic function, specifically a\n", - "mapping of real-valued vectors $\\hat{x} \\in \\mathbb{R}^n \\rightarrow\n", - "\\hat{y} \\in \\mathbb{R}^m$.\n", - "\n", - "Furthermore, the flexibility and universality of an MLP can be\n", - "illustrated by realizing that the expression is essentially a nested\n", - "sum of scaled activation functions of the form" - ] - }, - { - "cell_type": "markdown", - "id": "85dc952c", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
\n", - "\n", "$$\n", - "\\begin{equation}\n", - " f(x) = c_1 f(c_2 x + c_3) + c_4\n", - "\\label{_auto5} \\tag{10}\n", - "\\end{equation}\n", + "z_j^{l+1} = \\sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1},\n", "$$" ] }, { "cell_type": "markdown", - "id": "4a67580f", + "id": "fe790abf", "metadata": { "editable": true }, "source": [ - "where the parameters $c_i$ are weights and biases. By adjusting these\n", - "parameters, the activation functions can be shifted up and down or\n", - "left and right, change slope or be rescaled which is the key to the\n", - "flexibility of a neural network." + "with $M_l$ being the number of nodes in layer $l$, we obtain" ] }, { "cell_type": "markdown", - "id": "19f79e3c", + "id": "ece1f6fe", "metadata": { "editable": true }, "source": [ - "### Matrix-vector notation\n", - "\n", - "We can introduce a more convenient notation for the activations in an A NN. \n", - "\n", - "Additionally, we can represent the biases and activations\n", - "as layer-wise column vectors $\\hat{b}_l$ and $\\hat{y}_l$, so that the $i$-th element of each vector \n", - "is the bias $b_i^l$ and activation $y_i^l$ of node $i$ in layer $l$ respectively. \n", - "\n", - "We have that $\\mathrm{W}_l$ is an $N_{l-1} \\times N_l$ matrix, while $\\hat{b}_l$ and $\\hat{y}_l$ are $N_l \\times 1$ column vectors. \n", - "With this notation, the sum becomes a matrix-vector multiplication, and we can write\n", - "the equation for the activations of hidden layer 2 (assuming three nodes for simplicity) as" - ] - }, - { - "cell_type": "markdown", - "id": "e350b83c", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
\n", - "\n", "$$\n", - "\\begin{equation}\n", - " \\hat{y}_2 = f_2(\\mathrm{W}_2 \\hat{y}_{1} + \\hat{b}_{2}) = \n", - " f_2\\left(\\left[\\begin{array}{ccc}\n", - " w^2_{11} &w^2_{12} &w^2_{13} \\\\\n", - " w^2_{21} &w^2_{22} &w^2_{23} \\\\\n", - " w^2_{31} &w^2_{32} &w^2_{33} \\\\\n", - " \\end{array} \\right] \\cdot\n", - " \\left[\\begin{array}{c}\n", - " y^1_1 \\\\\n", - " y^1_2 \\\\\n", - " y^1_3 \\\\\n", - " \\end{array}\\right] + \n", - " \\left[\\begin{array}{c}\n", - " b^2_1 \\\\\n", - " b^2_2 \\\\\n", - " b^2_3 \\\\\n", - " \\end{array}\\right]\\right).\n", - "\\label{_auto6} \\tag{11}\n", - "\\end{equation}\n", + "\\delta_j^l =\\sum_k \\delta_k^{l+1}w_{kj}^{l+1}\\sigma'(z_j^l),\n", "$$" ] }, { "cell_type": "markdown", - "id": "3b64eaf6", + "id": "9cafdde6", "metadata": { "editable": true }, "source": [ - "### Matrix-vector notation and activation\n", + "This is our final equation.\n", "\n", - "The activation of node $i$ in layer 2 is" + "We are now ready to set up the algorithm for back propagation and learning the weights and biases." ] }, { "cell_type": "markdown", - "id": "dc8ca05e", + "id": "0766f482", "metadata": { "editable": true }, "source": [ - "\n", - "
\n", + "## Setting up the back propagation algorithm\n", "\n", + "The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", + "\n", + "**First**, we set up the input data $\\hat{x}$ and the activations\n", + "$\\hat{z}_1$ of the input layer and compute the activation function and\n", + "the pertinent outputs $\\hat{a}^1$.\n", + "\n", + "**Secondly**, we perform then the feed forward till we reach the output\n", + "layer and compute all $\\hat{z}_l$ of the input layer and compute the\n", + "activation function and the pertinent outputs $\\hat{a}^l$ for\n", + "$l=1,2,3,\\dots,L$.\n", + "\n", + "**Notation**: The first hidden layer has $l=1$ as label and the final output layer has $l=L$." + ] + }, + { + "cell_type": "markdown", + "id": "e29ae382", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the back propagation algorithm, part 2\n", + "\n", + "Thereafter we compute the ouput error $\\hat{\\delta}^L$ by computing all" + ] + }, + { + "cell_type": "markdown", + "id": "518b6578", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation}\n", - " y^2_i = f_2\\Bigr(w^2_{i1}y^1_1 + w^2_{i2}y^1_2 + w^2_{i3}y^1_3 + b^2_i\\Bigr) = \n", - " f_2\\left(\\sum_{j=1}^3 w^2_{ij} y_j^1 + b^2_i\\right).\n", - "\\label{_auto7} \\tag{12}\n", - "\\end{equation}\n", + "\\delta_j^L = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "079a6c4b", + "id": "4f804851", "metadata": { "editable": true }, "source": [ - "This is not just a convenient and compact notation, but also a useful\n", - "and intuitive way to think about MLPs: The output is calculated by a\n", - "series of matrix-vector multiplications and vector additions that are\n", - "used as input to the activation functions. For each operation\n", - "$\\mathrm{W}_l \\hat{y}_{l-1}$ we move forward one layer." + "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,1$ as" ] }, { "cell_type": "markdown", - "id": "3498dab8", + "id": "359aae81", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}\\sigma'(z_j^l).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "70123228", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the Back propagation algorithm, part 3\n", + "\n", + "Finally, we update the weights and the biases using gradient descent\n", + "for each $l=L-1,L-2,\\dots,1$ and update the weights and biases\n", + "according to the rules" + ] + }, + { + "cell_type": "markdown", + "id": "2df5a3de", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8081e4e4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3c40603c", + "metadata": { + "editable": true + }, + "source": [ + "with $\\eta$ being the learning rate." + ] + }, + { + "cell_type": "markdown", + "id": "26de0b47", + "metadata": { + "editable": true + }, + "source": [ + "## Updating the gradients\n", + "\n", + "With the back propagate error for each $l=L-1,L-2,\\dots,1$ as" + ] + }, + { + "cell_type": "markdown", + "id": "a172a64a", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}sigma'(z_j^l),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dfd6fc88", + "metadata": { + "editable": true + }, + "source": [ + "we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,1$ and update the weights and biases according to the rules" + ] + }, + { + "cell_type": "markdown", + "id": "a7df4398", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "cfd24fc1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "869c3364", "metadata": { "editable": true }, @@ -1006,7 +4030,7 @@ }, { "cell_type": "markdown", - "id": "c0b93415", + "id": "91102a3c", "metadata": { "editable": true }, @@ -1025,7 +4049,7 @@ }, { "cell_type": "markdown", - "id": "74a5d31d", + "id": "9609f422", "metadata": { "editable": true }, @@ -1037,7 +4061,7 @@ }, { "cell_type": "markdown", - "id": "539998aa", + "id": "cdd8d562", "metadata": { "editable": true }, @@ -1047,7 +4071,7 @@ }, { "cell_type": "markdown", - "id": "e4b4b760", + "id": "118a47f2", "metadata": { "editable": true }, @@ -1059,7 +4083,7 @@ }, { "cell_type": "markdown", - "id": "b98e352b", + "id": "5d6387b5", "metadata": { "editable": true }, @@ -1075,8 +4099,8 @@ }, { "cell_type": "code", - "execution_count": 4, - "id": "9f6ead02", + "execution_count": 7, + "id": "33449cca", "metadata": { "collapsed": false, "editable": true @@ -1158,2811 +4182,459 @@ }, { "cell_type": "markdown", - "id": "95f54888", + "id": "e8fafa8a", "metadata": { "editable": true }, "source": [ - "## The multilayer perceptron (MLP)\n", + "## Fine-tuning neural network hyperparameters\n", "\n", - "The multilayer perceptron is a very popular, and easy to implement approach, to deep learning. It consists of\n", - "1. A neural network with one or more layers of nodes between the input and the output nodes.\n", + "The flexibility of neural networks is also one of their main\n", + "drawbacks: there are many hyperparameters to tweak. Not only can you\n", + "use any imaginable network topology (how neurons/nodes are\n", + "interconnected), but even in a simple FFNN you can change the number\n", + "of layers, the number of neurons per layer, the type of activation\n", + "function to use in each layer, the weight initialization logic, the\n", + "stochastic gradient optmized and much more. How do you know what\n", + "combination of hyperparameters is the best for your task?\n", "\n", - "2. The multilayer network structure, or architecture, or topology, consists of an input layer, one or more hidden layers, and one output layer.\n", + "* You can use grid search with cross-validation to find the right hyperparameters.\n", "\n", - "3. The input nodes pass values to the first hidden layer, its nodes pass the information on to the second and so on till we reach the output layer.\n", + "However,since there are many hyperparameters to tune, and since\n", + "training a neural network on a large dataset takes a lot of time, you\n", + "will only be able to explore a tiny part of the hyperparameter space.\n", "\n", - "As a convention it is normal to call a network with one layer of input units, one layer of hidden\n", - "units and one layer of output units as a two-layer network. A network with two layers of hidden units is called a three-layer network etc etc.\n", + "* You can use randomized search.\n", "\n", - "For an MLP network there is no direct connection between the output nodes/neurons/units and the input nodes/neurons/units.\n", - "Hereafter we will call the various entities of a layer for nodes.\n", - "There are also no connections within a single layer.\n", - "\n", - "The number of input nodes does not need to equal the number of output\n", - "nodes. This applies also to the hidden layers. Each layer may have its\n", - "own number of nodes and activation functions.\n", - "\n", - "The hidden layers have their name from the fact that they are not\n", - "linked to observables and as we will see below when we define the\n", - "so-called activation $\\hat{z}$, we can think of this as a basis\n", - "expansion of the original inputs $\\hat{x}$. The difference however\n", - "between neural networks and say linear regression is that now these\n", - "basis functions (which will correspond to the weights in the network)\n", - "are learned from data. This results in an important difference between\n", - "neural networks and deep learning approaches on one side and methods\n", - "like logistic regression or linear regression and their modifications on the other side." + "* Or use tools like [Oscar](http://oscar.calldesk.ai/), which implements more complex algorithms to help you find a good set of hyperparameters quickly." ] }, { "cell_type": "markdown", - "id": "91bf2419", + "id": "00965f5d", "metadata": { "editable": true }, "source": [ - "## From one to many layers, the universal approximation theorem\n", + "## Hidden layers\n", "\n", - "A neural network with only one layer, what we called the simple\n", - "perceptron, is best suited if we have a standard binary model with\n", - "clear (linear) boundaries between the outcomes. As such it could\n", - "equally well be replaced by standard linear regression or logistic\n", - "regression. Networks with one or more hidden layers approximate\n", - "systems with more complex boundaries.\n", + "For many problems you can start with just one or two hidden layers and\n", + "it will work just fine. For the MNIST data set you ca easily get a\n", + "high accuracy using just one hidden layer with a few hundred neurons.\n", + "You can reach for this data set above 98% accuracy using two hidden\n", + "layers with the same total amount of neurons, in roughly the same\n", + "amount of training time.\n", "\n", - "As stated earlier, \n", - "an important theorem in studies of neural networks, restated without\n", - "proof here, is the [universal approximation\n", - "theorem](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.441.7873&rep=rep1&type=pdf).\n", - "\n", - "It states that a feed-forward network with a single hidden layer\n", - "containing a finite number of neurons can approximate continuous\n", - "functions on compact subsets of real functions. The theorem thus\n", - "states that simple neural networks can represent a wide variety of\n", - "interesting functions when given appropriate parameters. It is the\n", - "multilayer feedforward architecture itself which gives neural networks\n", - "the potential of being universal approximators." + "For more complex problems, you can gradually ramp up the number of\n", + "hidden layers, until you start overfitting the training set. Very\n", + "complex tasks, such as large image classification or speech\n", + "recognition, typically require networks with dozens of layers and they\n", + "need a huge amount of training data. However, you will rarely have to\n", + "train such networks from scratch: it is much more common to reuse\n", + "parts of a pretrained state-of-the-art network that performs a similar\n", + "task." ] }, { "cell_type": "markdown", - "id": "6500ed58", + "id": "d90316a8", "metadata": { "editable": true }, "source": [ - "## Deriving the back propagation code for a multilayer perceptron model\n", + "## Vanishing gradients\n", "\n", - "As we have seen now in a feed forward network, we can express the final output of our network in terms of basic matrix-vector multiplications.\n", - "The unknowwn quantities are our weights $w_{ij}$ and we need to find an algorithm for changing them so that our errors are as small as possible.\n", - "This leads us to the famous [back propagation algorithm](https://www.nature.com/articles/323533a0).\n", + "The Back propagation algorithm we derived above works by going from\n", + "the output layer to the input layer, propagating the error gradient on\n", + "the way. Once the algorithm has computed the gradient of the cost\n", + "function with regards to each parameter in the network, it uses these\n", + "gradients to update each parameter with a Gradient Descent (GD) step.\n", "\n", - "The questions we want to ask are how do changes in the biases and the\n", - "weights in our network change the cost function and how can we use the\n", - "final output to modify the weights?\n", - "\n", - "To derive these equations let us start with a plain regression problem\n", - "and define our cost function as" + "Unfortunately for us, the gradients often get smaller and smaller as\n", + "the algorithm progresses down to the first hidden layers. As a result,\n", + "the GD update leaves the lower layer connection weights virtually\n", + "unchanged, and training never converges to a good solution. This is\n", + "known in the literature as **the vanishing gradients problem**." ] }, { "cell_type": "markdown", - "id": "703f7235", + "id": "441fe8d9", + "metadata": { + "editable": true + }, + "source": [ + "## Exploding gradients\n", + "\n", + "In other cases, the opposite can happen, namely the the gradients can\n", + "grow bigger and bigger. The result is that many of the layers get\n", + "large updates of the weights the algorithm diverges. This is the\n", + "**exploding gradients problem**, which is mostly encountered in\n", + "recurrent neural networks. More generally, deep neural networks suffer\n", + "from unstable gradients, different layers may learn at widely\n", + "different speeds" + ] + }, + { + "cell_type": "markdown", + "id": "ae55ad1c", + "metadata": { + "editable": true + }, + "source": [ + "## Is the Logistic activation function (Sigmoid) our choice?\n", + "\n", + "Although this unfortunate behavior has been empirically observed for\n", + "quite a while (it was one of the reasons why deep neural networks were\n", + "mostly abandoned for a long time), it is only around 2010 that\n", + "significant progress was made in understanding it.\n", + "\n", + "A paper titled [Understanding the Difficulty of Training Deep\n", + "Feedforward Neural Networks by Xavier Glorot and Yoshua Bengio](http://proceedings.mlr.press/v9/glorot10a.html) found that\n", + "the problems with the popular logistic\n", + "sigmoid activation function and the weight initialization technique\n", + "that was most popular at the time, namely random initialization using\n", + "a normal distribution with a mean of 0 and a standard deviation of\n", + "1." + ] + }, + { + "cell_type": "markdown", + "id": "96bbf798", + "metadata": { + "editable": true + }, + "source": [ + "## Logistic function as the root of problems\n", + "\n", + "They showed that with this activation function and this\n", + "initialization scheme, the variance of the outputs of each layer is\n", + "much greater than the variance of its inputs. Going forward in the\n", + "network, the variance keeps increasing after each layer until the\n", + "activation function saturates at the top layers. This is actually made\n", + "worse by the fact that the logistic function has a mean of 0.5, not 0\n", + "(the hyperbolic tangent function has a mean of 0 and behaves slightly\n", + "better than the logistic function in deep networks)." + ] + }, + { + "cell_type": "markdown", + "id": "4b03e108", + "metadata": { + "editable": true + }, + "source": [ + "## The derivative of the Logistic funtion\n", + "\n", + "Looking at the logistic activation function, when inputs become large\n", + "(negative or positive), the function saturates at 0 or 1, with a\n", + "derivative extremely close to 0. Thus when backpropagation kicks in,\n", + "it has virtually no gradient to propagate back through the network,\n", + "and what little gradient exists keeps getting diluted as\n", + "backpropagation progresses down through the top layers, so there is\n", + "really nothing left for the lower layers.\n", + "\n", + "In their paper, Glorot and Bengio propose a way to significantly\n", + "alleviate this problem. We need the signal to flow properly in both\n", + "directions: in the forward direction when making predictions, and in\n", + "the reverse direction when backpropagating gradients. We don’t want\n", + "the signal to die out, nor do we want it to explode and saturate. For\n", + "the signal to flow properly, the authors argue that we need the\n", + "variance of the outputs of each layer to be equal to the variance of\n", + "its inputs, and we also need the gradients to have equal variance\n", + "before and after flowing through a layer in the reverse direction." + ] + }, + { + "cell_type": "markdown", + "id": "2898691d", + "metadata": { + "editable": true + }, + "source": [ + "## Insights from the paper by Glorot and Bengio\n", + "\n", + "One of the insights in the 2010 paper by Glorot and Bengio was that\n", + "the vanishing/exploding gradients problems were in part due to a poor\n", + "choice of activation function. Until then most people had assumed that\n", + "if Nature had chosen to use roughly sigmoid activation functions in\n", + "biological neurons, they must be an excellent choice. But it turns out\n", + "that other activation functions behave much better in deep neural\n", + "networks, in particular the ReLU activation function, mostly because\n", + "it does not saturate for positive values (and also because it is quite\n", + "fast to compute)." + ] + }, + { + "cell_type": "markdown", + "id": "4ac964f3", + "metadata": { + "editable": true + }, + "source": [ + "## The RELU function family\n", + "\n", + "The ReLU activation function suffers from a problem known as the dying\n", + "ReLUs: during training, some neurons effectively die, meaning they\n", + "stop outputting anything other than 0.\n", + "\n", + "In some cases, you may find that half of your network’s neurons are\n", + "dead, especially if you used a large learning rate. During training,\n", + "if a neuron’s weights get updated such that the weighted sum of the\n", + "neuron’s inputs is negative, it will start outputting 0. When this\n", + "happen, the neuron is unlikely to come back to life since the gradient\n", + "of the ReLU function is 0 when its input is negative." + ] + }, + { + "cell_type": "markdown", + "id": "c18a90e1", + "metadata": { + "editable": true + }, + "source": [ + "## ELU function\n", + "\n", + "To solve this problem, nowadays practitioners use a variant of the\n", + "ReLU function, such as the leaky ReLU discussed above or the so-called\n", + "exponential linear unit (ELU) function" + ] + }, + { + "cell_type": "markdown", + "id": "eed9db84", "metadata": { "editable": true }, "source": [ "$$\n", - "{\\cal C}(\\hat{W}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - t_i\\right)^2,\n", + "ELU(z) = \\left\\{\\begin{array}{cc} \\alpha\\left( \\exp{(z)}-1\\right) & z < 0,\\\\ z & z \\ge 0.\\end{array}\\right.\n", "$$" ] }, { "cell_type": "markdown", - "id": "667ef874", + "id": "b375c182", "metadata": { "editable": true }, "source": [ - "where the $t_i$s are our $n$ targets (the values we want to\n", - "reproduce), while the outputs of the network after having propagated\n", - "all inputs $\\hat{x}$ are given by $y_i$. Below we will demonstrate\n", - "how the basic equations arising from the back propagation algorithm\n", - "can be modified in order to study classification problems with $K$\n", - "classes." - ] - }, - { - "cell_type": "markdown", - "id": "dd53c6c8", - "metadata": { - "editable": true - }, - "source": [ - "## Definitions\n", - "\n", - "With our definition of the targets $\\hat{t}$, the outputs of the\n", - "network $\\hat{y}$ and the inputs $\\hat{x}$ we\n", - "define now the activation $z_j^l$ of node/neuron/unit $j$ of the\n", - "$l$-th layer as a function of the bias, the weights which add up from\n", - "the previous layer $l-1$ and the forward passes/outputs\n", - "$\\hat{a}^{l-1}$ from the previous layer as" - ] - }, - { - "cell_type": "markdown", - "id": "4f58ed9b", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_j^l = \\sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c60762cd", - "metadata": { - "editable": true - }, - "source": [ - "where $b_k^l$ are the biases from layer $l$. Here $M_{l-1}$\n", - "represents the total number of nodes/neurons/units of layer $l-1$. The\n", - "figure here illustrates this equation. We can rewrite this in a more\n", - "compact form as the matrix-vector products we discussed earlier," - ] - }, - { - "cell_type": "markdown", - "id": "5c1c5162", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\hat{z}^l = \\left(\\hat{W}^l\\right)^T\\hat{a}^{l-1}+\\hat{b}^l.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "080b6f9a", - "metadata": { - "editable": true - }, - "source": [ - "With the activation values $\\hat{z}^l$ we can in turn define the\n", - "output of layer $l$ as $\\hat{a}^l = f(\\hat{z}^l)$ where $f$ is our\n", - "activation function. In the examples here we will use the sigmoid\n", - "function discussed in our logistic regression lectures. We will also use the same activation function $f$ for all layers\n", - "and their nodes. It means we have" - ] - }, - { - "cell_type": "markdown", - "id": "12e261bb", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "a_j^l = f(z_j^l) = \\frac{1}{1+\\exp{-(z_j^l)}}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "49a48c09", - "metadata": { - "editable": true - }, - "source": [ - "## Derivatives and the chain rule\n", - "\n", - "From the definition of the activation $z_j^l$ we have" - ] - }, - { - "cell_type": "markdown", - "id": "6dc08f48", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial z_j^l}{\\partial w_{ij}^l} = a_i^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "b8211d41", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "96822eda", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial z_j^l}{\\partial a_i^{l-1}} = w_{ji}^l.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f0b1660f", - "metadata": { - "editable": true - }, - "source": [ - "With our definition of the activation function we have that (note that this function depends only on $z_j^l$)" - ] - }, - { - "cell_type": "markdown", - "id": "df85f033", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial a_j^l}{\\partial z_j^{l}} = a_j^l(1-a_j^l)=f(z_j^l)(1-f(z_j^l)).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "ea90d738", - "metadata": { - "editable": true - }, - "source": [ - "## Derivative of the cost function\n", - "\n", - "With these definitions we can now compute the derivative of the cost function in terms of the weights.\n", - "\n", - "Let us specialize to the output layer $l=L$. Our cost function is" - ] - }, - { - "cell_type": "markdown", - "id": "fafb43b4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "{\\cal C}(\\hat{W^L}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - t_i\\right)^2=\\frac{1}{2}\\sum_{i=1}^n\\left(a_i^L - t_i\\right)^2,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "41afcc45", - "metadata": { - "editable": true - }, - "source": [ - "The derivative of this function with respect to the weights is" - ] - }, - { - "cell_type": "markdown", - "id": "aed16939", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\left(a_j^L - t_j\\right)\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "4ece624c", - "metadata": { - "editable": true - }, - "source": [ - "The last partial derivative can easily be computed and reads (by applying the chain rule)" - ] - }, - { - "cell_type": "markdown", - "id": "7fbf4fe4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}} = \\frac{\\partial a_j^L}{\\partial z_{j}^{L}}\\frac{\\partial z_j^L}{\\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "dba0e4a4", - "metadata": { - "editable": true - }, - "source": [ - "## Bringing it together, first back propagation equation\n", - "\n", - "We have thus" - ] - }, - { - "cell_type": "markdown", - "id": "c32147af", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\left(a_j^L - t_j\\right)a_j^L(1-a_j^L)a_k^{L-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "4b6176c8", - "metadata": { - "editable": true - }, - "source": [ - "Defining" - ] - }, - { - "cell_type": "markdown", - "id": "b87747a4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = a_j^L(1-a_j^L)\\left(a_j^L - t_j\\right) = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "1547289e", - "metadata": { - "editable": true - }, - "source": [ - "and using the Hadamard product of two vectors we can write this as" - ] - }, - { - "cell_type": "markdown", - "id": "ef9854e4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\hat{\\delta}^L = f'(\\hat{z}^L)\\circ\\frac{\\partial {\\cal C}}{\\partial (\\hat{a}^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c9ce87bb", - "metadata": { - "editable": true - }, - "source": [ - "This is an important expression. The second term on the right handside\n", - "measures how fast the cost function is changing as a function of the $j$th\n", - "output activation. If, for example, the cost function doesn't depend\n", - "much on a particular output node $j$, then $\\delta_j^L$ will be small,\n", - "which is what we would expect. The first term on the right, measures\n", - "how fast the activation function $f$ is changing at a given activation\n", - "value $z_j^L$.\n", - "\n", - "Notice that everything in the above equations is easily computed. In\n", - "particular, we compute $z_j^L$ while computing the behaviour of the\n", - "network, and it is only a small additional overhead to compute\n", - "$f'(z^L_j)$. The exact form of the derivative with respect to the\n", - "output depends on the form of the cost function.\n", - "However, provided the cost function is known there should be little\n", - "trouble in calculating" - ] - }, - { - "cell_type": "markdown", - "id": "5b74b869", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "42b1eab9", - "metadata": { - "editable": true - }, - "source": [ - "With the definition of $\\delta_j^L$ we have a more compact definition of the derivative of the cost function in terms of the weights, namely" - ] - }, - { - "cell_type": "markdown", - "id": "27331743", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8f1b672f", - "metadata": { - "editable": true - }, - "source": [ - "## Derivatives in terms of $z_j^L$\n", - "\n", - "It is also easy to see that our previous equation can be written as" - ] - }, - { - "cell_type": "markdown", - "id": "543a0ba2", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L =\\frac{\\partial {\\cal C}}{\\partial z_j^L}= \\frac{\\partial {\\cal C}}{\\partial a_j^L}\\frac{\\partial a_j^L}{\\partial z_j^L},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "628ee133", - "metadata": { - "editable": true - }, - "source": [ - "which can also be interpreted as the partial derivative of the cost function with respect to the biases $b_j^L$, namely" - ] - }, - { - "cell_type": "markdown", - "id": "94f361e5", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L}\\frac{\\partial b_j^L}{\\partial z_j^L}=\\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "13e5c5d5", - "metadata": { - "editable": true - }, - "source": [ - "That is, the error $\\delta_j^L$ is exactly equal to the rate of change of the cost function as a function of the bias." - ] - }, - { - "cell_type": "markdown", - "id": "4887a3d7", - "metadata": { - "editable": true - }, - "source": [ - "## Bringing it together\n", - "\n", - "We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are\n", - "\n", - "**The starting equations.**" - ] - }, - { - "cell_type": "markdown", - "id": "8f4d75dd", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
\n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1},\n", - "\\label{_auto8} \\tag{13}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "69864347", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "e654f179", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
\n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", - "\\label{_auto9} \\tag{14}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f650a917", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "b8169c55", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
\n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", - "\\label{_auto10} \\tag{15}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "5567d66c", - "metadata": { - "editable": true - }, - "source": [ - "An interesting consequence of the above equations is that when the\n", - "activation $a_k^{L-1}$ is small, the gradient term, that is the\n", - "derivative of the cost function with respect to the weights, will also\n", - "tend to be small. We say then that the weight learns slowly, meaning\n", - "that it changes slowly when we minimize the weights via say gradient\n", - "descent. In this case we say the system learns slowly.\n", - "\n", - "Another interesting feature is that is when the activation function,\n", - "represented by the sigmoid function here, is rather flat when we move towards\n", - "its end values $0$ and $1$ (see the above Python codes). In these\n", - "cases, the derivatives of the activation function will also be close\n", - "to zero, meaning again that the gradients will be small and the\n", - "network learns slowly again.\n", - "\n", - "We need a fourth equation and we are set. We are going to propagate\n", - "backwards in order to the determine the weights and biases. In order\n", - "to do so we need to represent the error in the layer before the final\n", - "one $L-1$ in terms of the errors in the final output layer." - ] - }, - { - "cell_type": "markdown", - "id": "f5c09470", - "metadata": { - "editable": true - }, - "source": [ - "## Final back propagating equation\n", - "\n", - "We have that (replacing $L$ with a general layer $l$)" - ] - }, - { - "cell_type": "markdown", - "id": "d66ef5ca", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\frac{\\partial {\\cal C}}{\\partial z_j^l}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e96004a2", - "metadata": { - "editable": true - }, - "source": [ - "We want to express this in terms of the equations for layer $l+1$. Using the chain rule and summing over all $k$ entries we have" - ] - }, - { - "cell_type": "markdown", - "id": "0ee94485", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\sum_k \\frac{\\partial {\\cal C}}{\\partial z_k^{l+1}}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}}=\\sum_k \\delta_k^{l+1}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "1c2ac190", - "metadata": { - "editable": true - }, - "source": [ - "and recalling that" - ] - }, - { - "cell_type": "markdown", - "id": "f89f9c76", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_j^{l+1} = \\sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f8293787", - "metadata": { - "editable": true - }, - "source": [ - "with $M_l$ being the number of nodes in layer $l$, we obtain" - ] - }, - { - "cell_type": "markdown", - "id": "a2914db3", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "297a2622", - "metadata": { - "editable": true - }, - "source": [ - "This is our final equation.\n", - "\n", - "We are now ready to set up the algorithm for back propagation and learning the weights and biases." - ] - }, - { - "cell_type": "markdown", - "id": "c952f57b", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\hat{x}$ and the activations\n", - "$\\hat{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\hat{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\hat{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\hat{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\hat{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "37d4f242", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "ff2e732a", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "97a96714", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "3ee8ad1b", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "c4d2d1a1", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "d412dae3", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "64129a91", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "681d8bd9", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\boldsymbol{x}$ and the activations\n", - "$\\boldsymbol{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\boldsymbol{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\boldsymbol{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\boldsymbol{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\boldsymbol{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "62904d70", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bb5b2dde", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "51828c66", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c4124232", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "80791bf2", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "107737c9", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "720ad834", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "6854da89", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations derived discussed above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\boldsymbol{x}$ and the activations\n", - "$\\boldsymbol{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\boldsymbol{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\boldsymbol{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\boldsymbol{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\boldsymbol{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "b5c0c6c7", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "43403932", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "08f3064e", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f5d698a4", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "3ae56fb5", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "b822ca59", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e0593696", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "c77a2a17", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up a Multi-layer perceptron model for classification\n", - "\n", - "We are now gong to develop an example based on the MNIST data\n", - "base. This is a classification problem and we need to use our\n", - "cross-entropy function we discussed in connection with logistic\n", - "regression. The cross-entropy defines our cost function for the\n", - "classificaton problems with neural networks.\n", - "\n", - "In binary classification with two classes $(0, 1)$ we define the\n", - "logistic/sigmoid function as the probability that a particular input\n", - "is in class $0$ or $1$. This is possible because the logistic\n", - "function takes any input from the real numbers and inputs a number\n", - "between 0 and 1, and can therefore be interpreted as a probability. It\n", - "also has other nice properties, such as a derivative that is simple to\n", - "calculate.\n", - "\n", - "For an input $\\boldsymbol{a}$ from the hidden layer, the probability that the input $\\boldsymbol{x}$\n", - "is in class 0 or 1 is just. We let $\\theta$ represent the unknown weights and biases to be adjusted by our equations). The variable $x$\n", - "represents our activation values $z$. We have" - ] - }, - { - "cell_type": "markdown", - "id": "093f5d87", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y = 0 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) = \\frac{1}{1 + \\exp{(- \\boldsymbol{x}})} ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7bd03f69", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "fe5226a0", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y = 1 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) = 1 - P(y = 0 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "45f1532a", - "metadata": { - "editable": true - }, - "source": [ - "where $y \\in \\{0, 1\\}$ and $\\boldsymbol{\\theta}$ represents the weights and biases\n", - "of our network." - ] - }, - { - "cell_type": "markdown", - "id": "1b07418e", - "metadata": { - "editable": true - }, - "source": [ - "## Defining the cost function\n", - "\n", - "Our cost function is given as (see the Logistic regression lectures)" - ] - }, - { - "cell_type": "markdown", - "id": "c7f5232f", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\theta}) = - \\ln P(\\mathcal{D} \\mid \\boldsymbol{\\theta}) = - \\sum_{i=1}^n\n", - "y_i \\ln[P(y_i = 0)] + (1 - y_i) \\ln [1 - P(y_i = 0)] = \\sum_{i=1}^n \\mathcal{L}_i(\\boldsymbol{\\theta}) .\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e1af7b47", - "metadata": { - "editable": true - }, - "source": [ - "This last equality means that we can interpret our *cost* function as a sum over the *loss* function\n", - "for each point in the dataset $\\mathcal{L}_i(\\boldsymbol{\\theta})$. \n", - "The negative sign is just so that we can think about our algorithm as minimizing a positive number, rather\n", - "than maximizing a negative number. \n", - "\n", - "In *multiclass* classification it is common to treat each integer label as a so called *one-hot* vector: \n", - "\n", - "$y = 5 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,$ and\n", - "\n", - "$y = 1 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,$ \n", - "\n", - "i.e. a binary bit string of length $C$, where $C = 10$ is the number of classes in the MNIST dataset (numbers from $0$ to $9$).. \n", - "\n", - "If $\\boldsymbol{x}_i$ is the $i$-th input (image), $y_{ic}$ refers to the $c$-th component of the $i$-th\n", - "output vector $\\boldsymbol{y}_i$. \n", - "The probability of $\\boldsymbol{x}_i$ being in class $c$ will be given by the softmax function:" - ] - }, - { - "cell_type": "markdown", - "id": "db469d35", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y_{ic} = 1 \\mid \\boldsymbol{x}_i, \\boldsymbol{\\theta}) = \\frac{\\exp{((\\boldsymbol{a}_i^{hidden})^T \\boldsymbol{w}_c)}}\n", - "{\\sum_{c'=0}^{C-1} \\exp{((\\boldsymbol{a}_i^{hidden})^T \\boldsymbol{w}_{c'})}} ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "deb48962", - "metadata": { - "editable": true - }, - "source": [ - "which reduces to the logistic function in the binary case. \n", - "The likelihood of this $C$-class classifier\n", - "is now given as:" - ] - }, - { - "cell_type": "markdown", - "id": "36443e39", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(\\mathcal{D} \\mid \\boldsymbol{\\theta}) = \\prod_{i=1}^n \\prod_{c=0}^{C-1} [P(y_{ic} = 1)]^{y_{ic}} .\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8076d9fa", - "metadata": { - "editable": true - }, - "source": [ - "Again we take the negative log-likelihood to define our cost function:" - ] - }, - { - "cell_type": "markdown", - "id": "292dad0a", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\theta}) = - \\log{P(\\mathcal{D} \\mid \\boldsymbol{\\theta})}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7803b746", - "metadata": { - "editable": true - }, - "source": [ - "See the logistic regression lectures for a full definition of the cost function.\n", - "\n", - "The back propagation equations need now only a small change, namely the definition of a new cost function. We are thus ready to use the same equations as before!" - ] - }, - { - "cell_type": "markdown", - "id": "a71f1366", - "metadata": { - "editable": true - }, - "source": [ - "## Example: binary classification problem\n", - "\n", - "As an example of the above, relevant for project 2 as well, let us consider a binary class. As discussed in our logistic regression lectures, we defined a cost function in terms of the parameters $\\beta$ as" - ] - }, - { - "cell_type": "markdown", - "id": "25efb288", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\beta}) = - \\sum_{i=1}^n \\left(y_i\\log{p(y_i \\vert x_i,\\boldsymbol{\\beta})}+(1-y_i)\\log{1-p(y_i \\vert x_i,\\boldsymbol{\\beta})}\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "6192694f", - "metadata": { - "editable": true - }, - "source": [ - "where we had defined the logistic (sigmoid) function" - ] - }, - { - "cell_type": "markdown", - "id": "f6786106", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "p(y_i =1\\vert x_i,\\boldsymbol{\\beta})=\\frac{\\exp{(\\beta_0+\\beta_1 x_i)}}{1+\\exp{(\\beta_0+\\beta_1 x_i)}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "be663cac", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "a6953973", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "p(y_i =0\\vert x_i,\\boldsymbol{\\beta})=1-p(y_i =1\\vert x_i,\\boldsymbol{\\beta}).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "de08816b", - "metadata": { - "editable": true - }, - "source": [ - "The parameters $\\boldsymbol{\\beta}$ were defined using a minimization method like gradient descent or Newton-Raphson's method. \n", - "\n", - "Now we replace $x_i$ with the activation $z_i^l$ for a given layer $l$ and the outputs as $y_i=a_i^l=f(z_i^l)$, with $z_i^l$ now being a function of the weights $w_{ij}^l$ and biases $b_i^l$. \n", - "We have then" - ] - }, - { - "cell_type": "markdown", - "id": "d9b14b33", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "a_i^l = y_i = \\frac{\\exp{(z_i^l)}}{1+\\exp{(z_i^l)}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8072c452", - "metadata": { - "editable": true - }, - "source": [ - "with" - ] - }, - { - "cell_type": "markdown", - "id": "34a5cb25", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_i^l = \\sum_{j}w_{ij}^l a_j^{l-1}+b_i^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "833dc972", - "metadata": { - "editable": true - }, - "source": [ - "where the superscript $l-1$ indicates that these are the outputs from layer $l-1$.\n", - "Our cost function at the final layer $l=L$ is now" - ] - }, - { - "cell_type": "markdown", - "id": "3c52b850", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{W}) = - \\sum_{i=1}^n \\left(t_i\\log{a_i^L}+(1-t_i)\\log{(1-a_i^L)}\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "01c24d99", - "metadata": { - "editable": true - }, - "source": [ - "where we have defined the targets $t_i$. The derivatives of the cost function with respect to the output $a_i^L$ are then easily calculated and we get" - ] - }, - { - "cell_type": "markdown", - "id": "692fbd5a", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial \\mathcal{C}(\\boldsymbol{W})}{\\partial a_i^L} = \\frac{a_i^L-t_i}{a_i^L(1-a_i^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "cdd8c203", - "metadata": { - "editable": true - }, - "source": [ - "In case we use another activation function than the logistic one, we need to evaluate other derivatives." - ] - }, - { - "cell_type": "markdown", - "id": "1e7eba9c", - "metadata": { - "editable": true - }, - "source": [ - "## The Softmax function\n", - "In case we employ the more general case given by the Softmax equation, we need to evaluate the derivative of the activation function with respect to the activation $z_i^l$, that is we need" - ] - }, - { - "cell_type": "markdown", - "id": "8ca62ded", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial f(z_i^l)}{\\partial w_{jk}^l} =\n", - "\\frac{\\partial f(z_i^l)}{\\partial z_j^l} \\frac{\\partial z_j^l}{\\partial w_{jk}^l}= \\frac{\\partial f(z_i^l)}{\\partial z_j^l}a_k^{l-1}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "479d6d33", - "metadata": { - "editable": true - }, - "source": [ - "For the Softmax function we have" - ] - }, - { - "cell_type": "markdown", - "id": "3a63ba14", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "f(z_i^l) = \\frac{\\exp{(z_i^l)}}{\\sum_{m=1}^K\\exp{(z_m^l)}}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bed10528", - "metadata": { - "editable": true - }, - "source": [ - "Its derivative with respect to $z_j^l$ gives" - ] - }, - { - "cell_type": "markdown", - "id": "6a77ac39", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial f(z_i^l)}{\\partial z_j^l}= f(z_i^l)\\left(\\delta_{ij}-f(z_j^l)\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7fd16de8", - "metadata": { - "editable": true - }, - "source": [ - "which in case of the simply binary model reduces to having $i=j$." - ] - }, - { - "cell_type": "markdown", - "id": "a598757e", - "metadata": { - "editable": true - }, - "source": [ - "## Developing a code for doing neural networks with back propagation\n", - "\n", - "One can identify a set of key steps when using neural networks to solve supervised learning problems: \n", - "\n", - "1. Collect and pre-process data \n", - "\n", - "2. Define model and architecture \n", - "\n", - "3. Choose cost function and optimizer \n", - "\n", - "4. Train the model \n", - "\n", - "5. Evaluate model performance on test data \n", - "\n", - "6. Adjust hyperparameters (if necessary, network architecture)" - ] - }, - { - "cell_type": "markdown", - "id": "0dc69031", - "metadata": { - "editable": true - }, - "source": [ - "## Collect and pre-process data\n", - "\n", - "Here we will be using the MNIST dataset, which is readily available through the **scikit-learn**\n", - "package. You may also find it for example [here](http://yann.lecun.com/exdb/mnist/). \n", - "The *MNIST* (Modified National Institute of Standards and Technology) database is a large database\n", - "of handwritten digits that is commonly used for training various image processing systems. \n", - "The MNIST dataset consists of 70 000 images of size $28\\times 28$ pixels, each labeled from 0 to 9. \n", - "The scikit-learn dataset we will use consists of a selection of 1797 images of size $8\\times 8$ collected and processed from this database. \n", - "\n", - "To feed data into a feed-forward neural network we need to represent\n", - "the inputs as a design/feature matrix $X = (n_{inputs}, n_{features})$. Each\n", - "row represents an *input*, in this case a handwritten digit, and\n", - "each column represents a *feature*, in this case a pixel. The\n", - "correct answers, also known as *labels* or *targets* are\n", - "represented as a 1D array of integers \n", - "$Y = (n_{inputs}) = (5, 3, 1, 8,...)$.\n", - "\n", - "As an example, say we want to build a neural network using supervised learning to predict Body-Mass Index (BMI) from\n", - "measurements of height (in m) \n", - "and weight (in kg). If we have measurements of 5 people the design/feature matrix could be for example: \n", - "\n", - "$$ X = \\begin{bmatrix}\n", - "1.85 & 81\\\\\n", - "1.71 & 65\\\\\n", - "1.95 & 103\\\\\n", - "1.55 & 42\\\\\n", - "1.63 & 56\n", - "\\end{bmatrix} ,$$ \n", - "\n", - "and the targets would be: \n", - "\n", - "$$ Y = (23.7, 22.2, 27.1, 17.5, 21.1) $$ \n", - "\n", - "Since each input image is a 2D matrix, we need to flatten the image\n", - "(i.e. \"unravel\" the 2D matrix into a 1D array) to turn the data into a\n", - "design/feature matrix. This means we lose all spatial information in the\n", - "image, such as locality and translational invariance. More complicated\n", - "architectures such as Convolutional Neural Networks can take advantage\n", - "of such information, and are most commonly applied when analyzing\n", - "images." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "d7c49d9c", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn import datasets\n", - "\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# display images in notebook\n", - "%matplotlib inline\n", - "plt.rcParams['figure.figsize'] = (12,12)\n", - "\n", - "\n", - "# download MNIST dataset\n", - "digits = datasets.load_digits()\n", - "\n", - "# define inputs and labels\n", - "inputs = digits.images\n", - "labels = digits.target\n", - "\n", - "print(\"inputs = (n_inputs, pixel_width, pixel_height) = \" + str(inputs.shape))\n", - "print(\"labels = (n_inputs) = \" + str(labels.shape))\n", - "\n", - "\n", - "# flatten the image\n", - "# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64\n", - "n_inputs = len(inputs)\n", - "inputs = inputs.reshape(n_inputs, -1)\n", - "print(\"X = (n_inputs, n_features) = \" + str(inputs.shape))\n", - "\n", - "\n", - "# choose some random images to display\n", - "indices = np.arange(n_inputs)\n", - "random_indices = np.random.choice(indices, size=5)\n", - "\n", - "for i, image in enumerate(digits.images[random_indices]):\n", - " plt.subplot(1, 5, i+1)\n", - " plt.axis('off')\n", - " plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n", - " plt.title(\"Label: %d\" % digits.target[random_indices[i]])\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "672723bb", - "metadata": { - "editable": true - }, - "source": [ - "## Train and test datasets\n", - "\n", - "Performing analysis before partitioning the dataset is a major error, that can lead to incorrect conclusions. \n", - "\n", - "We will reserve $80 \\%$ of our dataset for training and $20 \\%$ for testing. \n", - "\n", - "It is important that the train and test datasets are drawn randomly from our dataset, to ensure\n", - "no bias in the sampling. \n", - "Say you are taking measurements of weather data to predict the weather in the coming 5 days.\n", - "You don't want to train your model on measurements taken from the hours 00.00 to 12.00, and then test it on data\n", - "collected from 12.00 to 24.00." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "3b0db869", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "from sklearn.model_selection import train_test_split\n", - "\n", - "# one-liner from scikit-learn library\n", - "train_size = 0.8\n", - "test_size = 1 - train_size\n", - "X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,\n", - " test_size=test_size)\n", - "\n", - "# equivalently in numpy\n", - "def train_test_split_numpy(inputs, labels, train_size, test_size):\n", - " n_inputs = len(inputs)\n", - " inputs_shuffled = inputs.copy()\n", - " labels_shuffled = labels.copy()\n", - " \n", - " np.random.shuffle(inputs_shuffled)\n", - " np.random.shuffle(labels_shuffled)\n", - " \n", - " train_end = int(n_inputs*train_size)\n", - " X_train, X_test = inputs_shuffled[:train_end], inputs_shuffled[train_end:]\n", - " Y_train, Y_test = labels_shuffled[:train_end], labels_shuffled[train_end:]\n", - " \n", - " return X_train, X_test, Y_train, Y_test\n", - "\n", - "#X_train, X_test, Y_train, Y_test = train_test_split_numpy(inputs, labels, train_size, test_size)\n", - "\n", - "print(\"Number of training images: \" + str(len(X_train)))\n", - "print(\"Number of test images: \" + str(len(X_test)))" - ] - }, - { - "cell_type": "markdown", - "id": "a52c7acf", - "metadata": { - "editable": true - }, - "source": [ - "## Define model and architecture\n", - "\n", - "Our simple feed-forward neural network will consist of an *input* layer, a single *hidden* layer and an *output* layer. The activation $y$ of each neuron is a weighted sum of inputs, passed through an activation function. In case of the simple perceptron model we have \n", - "\n", - "$$ z = \\sum_{i=1}^n w_i a_i ,$$\n", - "\n", - "$$ y = f(z) ,$$\n", - "\n", - "where $f$ is the activation function, $a_i$ represents input from neuron $i$ in the preceding layer\n", - "and $w_i$ is the weight to input $i$. \n", - "The activation of the neurons in the input layer is just the features (e.g. a pixel value). \n", - "\n", - "The simplest activation function for a neuron is the *Heaviside* function:\n", - "\n", - "$$ f(z) = \n", - "\\begin{cases}\n", - "1, & z > 0\\\\\n", - "0, & \\text{otherwise}\n", - "\\end{cases}\n", - "$$\n", - "\n", - "A feed-forward neural network with this activation is known as a *perceptron*. \n", - "For a binary classifier (i.e. two classes, 0 or 1, dog or not-dog) we can also use this in our output layer. \n", - "This activation can be generalized to $k$ classes (using e.g. the *one-against-all* strategy), \n", - "and we call these architectures *multiclass perceptrons*. \n", - "\n", - "However, it is now common to use the terms Single Layer Perceptron (SLP) (1 hidden layer) and \n", - "Multilayer Perceptron (MLP) (2 or more hidden layers) to refer to feed-forward neural networks with any activation function. \n", - "\n", - "Typical choices for activation functions include the sigmoid function, hyperbolic tangent, and Rectified Linear Unit (ReLU). \n", - "We will be using the sigmoid function $\\sigma(x)$: \n", - "\n", - "$$ f(x) = \\sigma(x) = \\frac{1}{1 + e^{-x}} ,$$\n", - "\n", - "which is inspired by probability theory (see logistic regression) and was most commonly used until about 2011. See the discussion below concerning other activation functions." - ] - }, - { - "cell_type": "markdown", - "id": "f1ef08f4", - "metadata": { - "editable": true - }, - "source": [ - "## Layers\n", - "\n", - "* Input \n", - "\n", - "Since each input image has 8x8 = 64 pixels or features, we have an input layer of 64 neurons. \n", - "\n", - "* Hidden layer\n", - "\n", - "We will use 50 neurons in the hidden layer receiving input from the neurons in the input layer. \n", - "Since each neuron in the hidden layer is connected to the 64 inputs we have 64x50 = 3200 weights to the hidden layer. \n", - "\n", - "* Output\n", - "\n", - "If we were building a binary classifier, it would be sufficient with a single neuron in the output layer,\n", - "which could output 0 or 1 according to the Heaviside function. This would be an example of a *hard* classifier, meaning it outputs the class of the input directly. However, if we are dealing with noisy data it is often beneficial to use a *soft* classifier, which outputs the probability of being in class 0 or 1. \n", - "\n", - "For a soft binary classifier, we could use a single neuron and interpret the output as either being the probability of being in class 0 or the probability of being in class 1. Alternatively we could use 2 neurons, and interpret each neuron as the probability of being in each class. \n", - "\n", - "Since we are doing multiclass classification, with 10 categories, it is natural to use 10 neurons in the output layer. We number the neurons $j = 0,1,...,9$. The activation of each output neuron $j$ will be according to the *softmax* function: \n", - "\n", - "$$ P(\\text{class $j$} \\mid \\text{input $\\boldsymbol{a}$}) = \\frac{\\exp{(\\boldsymbol{a}^T \\boldsymbol{w}_j)}}\n", - "{\\sum_{c=0}^{9} \\exp{(\\boldsymbol{a}^T \\boldsymbol{w}_c)}} ,$$ \n", - "\n", - "i.e. each neuron $j$ outputs the probability of being in class $j$ given an input from the hidden layer $\\boldsymbol{a}$, with $\\boldsymbol{w}_j$ the weights of neuron $j$ to the inputs. \n", - "The denominator is a normalization factor to ensure the outputs (probabilities) sum up to 1. \n", - "The exponent is just the weighted sum of inputs as before: \n", - "\n", - "$$ z_j = \\sum_{i=1}^n w_ {ij} a_i+b_j.$$ \n", - "\n", - "Since each neuron in the output layer is connected to the 50 inputs from the hidden layer we have 50x10 = 500\n", - "weights to the output layer." - ] - }, - { - "cell_type": "markdown", - "id": "867b3b89", - "metadata": { - "editable": true - }, - "source": [ - "## Weights and biases\n", - "\n", - "Typically weights are initialized with small values distributed around zero, drawn from a uniform\n", - "or normal distribution. Setting all weights to zero means all neurons give the same output, making the network useless. \n", - "\n", - "Adding a bias value to the weighted sum of inputs allows the neural network to represent a greater range\n", - "of values. Without it, any input with the value 0 will be mapped to zero (before being passed through the activation). The bias unit has an output of 1, and a weight to each neuron $j$, $b_j$: \n", - "\n", - "$$ z_j = \\sum_{i=1}^n w_ {ij} a_i + b_j.$$ \n", - "\n", - "The bias weights $\\boldsymbol{b}$ are often initialized to zero, but a small value like $0.01$ ensures all neurons have some output which can be backpropagated in the first training cycle." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "8ec462da", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# building our neural network\n", - "\n", - "n_inputs, n_features = X_train.shape\n", - "n_hidden_neurons = 50\n", - "n_categories = 10\n", - "\n", - "# we make the weights normally distributed using numpy.random.randn\n", - "\n", - "# weights and bias in the hidden layer\n", - "hidden_weights = np.random.randn(n_features, n_hidden_neurons)\n", - "hidden_bias = np.zeros(n_hidden_neurons) + 0.01\n", - "\n", - "# weights and bias in the output layer\n", - "output_weights = np.random.randn(n_hidden_neurons, n_categories)\n", - "output_bias = np.zeros(n_categories) + 0.01" - ] - }, - { - "cell_type": "markdown", - "id": "cf228009", - "metadata": { - "editable": true - }, - "source": [ - "## Feed-forward pass\n", - "\n", - "Denote $F$ the number of features, $H$ the number of hidden neurons and $C$ the number of categories. \n", - "For each input image we calculate a weighted sum of input features (pixel values) to each neuron $j$ in the hidden layer $l$: \n", - "\n", - "$$ z_{j}^{l} = \\sum_{i=1}^{F} w_{ij}^{l} x_i + b_{j}^{l},$$\n", - "\n", - "this is then passed through our activation function \n", - "\n", - "$$ a_{j}^{l} = f(z_{j}^{l}) .$$ \n", - "\n", - "We calculate a weighted sum of inputs (activations in the hidden layer) to each neuron $j$ in the output layer: \n", - "\n", - "$$ z_{j}^{L} = \\sum_{i=1}^{H} w_{ij}^{L} a_{i}^{l} + b_{j}^{L}.$$ \n", - "\n", - "Finally we calculate the output of neuron $j$ in the output layer using the softmax function: \n", - "\n", - "$$ a_{j}^{L} = \\frac{\\exp{(z_j^{L})}}\n", - "{\\sum_{c=0}^{C-1} \\exp{(z_c^{L})}} .$$" - ] - }, - { - "cell_type": "markdown", - "id": "c57ea8b9", - "metadata": { - "editable": true - }, - "source": [ - "## Matrix multiplications\n", - "\n", - "Since our data has the dimensions $X = (n_{inputs}, n_{features})$ and our weights to the hidden\n", - "layer have the dimensions \n", - "$W_{hidden} = (n_{features}, n_{hidden})$,\n", - "we can easily feed the network all our training data in one go by taking the matrix product \n", - "\n", - "$$ X W^{h} = (n_{inputs}, n_{hidden}),$$ \n", - "\n", - "and obtain a matrix that holds the weighted sum of inputs to the hidden layer\n", - "for each input image and each hidden neuron. \n", - "We also add the bias to obtain a matrix of weighted sums to the hidden layer $Z^{h}$: \n", - "\n", - "$$ \\boldsymbol{z}^{l} = \\boldsymbol{X} \\boldsymbol{W}^{l} + \\boldsymbol{b}^{l} ,$$\n", - "\n", - "meaning the same bias (1D array with size equal number of hidden neurons) is added to each input image. \n", - "This is then passed through the activation: \n", - "\n", - "$$ \\boldsymbol{a}^{l} = f(\\boldsymbol{z}^l) .$$ \n", - "\n", - "This is fed to the output layer: \n", - "\n", - "$$ \\boldsymbol{z}^{L} = \\boldsymbol{a}^{L} \\boldsymbol{W}^{L} + \\boldsymbol{b}^{L} .$$\n", - "\n", - "Finally we receive our output values for each image and each category by passing it through the softmax function: \n", - "\n", - "$$ output = softmax (\\boldsymbol{z}^{L}) = (n_{inputs}, n_{categories}) .$$" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "9c286c15", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# setup the feed-forward pass, subscript h = hidden layer\n", - "\n", - "def sigmoid(x):\n", - " return 1/(1 + np.exp(-x))\n", - "\n", - "def feed_forward(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " \n", - " return probabilities\n", - "\n", - "probabilities = feed_forward(X_train)\n", - "print(\"probabilities = (n_inputs, n_categories) = \" + str(probabilities.shape))\n", - "print(\"probability that image 0 is in category 0,1,2,...,9 = \\n\" + str(probabilities[0]))\n", - "print(\"probabilities sum up to: \" + str(probabilities[0].sum()))\n", - "print()\n", - "\n", - "# we obtain a prediction by taking the class with the highest likelihood\n", - "def predict(X):\n", - " probabilities = feed_forward(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - "predictions = predict(X_train)\n", - "print(\"predictions = (n_inputs) = \" + str(predictions.shape))\n", - "print(\"prediction for image 0: \" + str(predictions[0]))\n", - "print(\"correct label for image 0: \" + str(Y_train[0]))" - ] - }, - { - "cell_type": "markdown", - "id": "a6cf75c3", - "metadata": { - "editable": true - }, - "source": [ - "## Choose cost function and optimizer\n", - "\n", - "To measure how well our neural network is doing we need to introduce a cost function. \n", - "We will call the function that gives the error of a single sample output the *loss* function, and the function\n", - "that gives the total error of our network across all samples the *cost* function.\n", - "A typical choice for multiclass classification is the *cross-entropy* loss, also known as the negative log likelihood. \n", - "\n", - "In *multiclass* classification it is common to treat each integer label as a so called *one-hot* vector: \n", - "\n", - "$$ y = 5 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,$$ \n", - "\n", - "$$ y = 1 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,$$ \n", - "\n", - "i.e. a binary bit string of length $C$, where $C = 10$ is the number of classes in the MNIST dataset. \n", - "\n", - "Let $y_{ic}$ denote the $c$-th component of the $i$-th one-hot vector. \n", - "We define the cost function $\\mathcal{C}$ as a sum over the cross-entropy loss for each point $\\boldsymbol{x}_i$ in the dataset.\n", - "\n", - "In the one-hot representation only one of the terms in the loss function is non-zero, namely the\n", - "probability of the correct category $c'$ \n", - "(i.e. the category $c'$ such that $y_{ic'} = 1$). This means that the cross entropy loss only punishes you for how wrong\n", - "you got the correct label. The probability of category $c$ is given by the softmax function. The vector $\\boldsymbol{\\theta}$ represents the parameters of our network, i.e. all the weights and biases." - ] - }, - { - "cell_type": "markdown", - "id": "e69ffdc8", - "metadata": { - "editable": true - }, - "source": [ - "## Optimizing the cost function\n", - "\n", - "The network is trained by finding the weights and biases that minimize the cost function. One of the most widely used classes of methods is *gradient descent* and its generalizations. The idea behind gradient descent\n", - "is simply to adjust the weights in the direction where the gradient of the cost function is large and negative. This ensures we flow toward a *local* minimum of the cost function. \n", - "Each parameter $\\theta$ is iteratively adjusted according to the rule \n", - "\n", - "$$ \\theta_{i+1} = \\theta_i - \\eta \\nabla \\mathcal{C}(\\theta_i) ,$$\n", - "\n", - "where $\\eta$ is known as the *learning rate*, which controls how big a step we take towards the minimum. \n", - "This update can be repeated for any number of iterations, or until we are satisfied with the result. \n", - "\n", - "A simple and effective improvement is a variant called *Batch Gradient Descent*. \n", - "Instead of calculating the gradient on the whole dataset, we calculate an approximation of the gradient\n", - "on a subset of the data called a *minibatch*. \n", - "If there are $N$ data points and we have a minibatch size of $M$, the total number of batches\n", - "is $N/M$. \n", - "We denote each minibatch $B_k$, with $k = 1, 2,...,N/M$. The gradient then becomes: \n", - "\n", - "$$ \\nabla \\mathcal{C}(\\theta) = \\frac{1}{N} \\sum_{i=1}^N \\nabla \\mathcal{L}_i(\\theta) \\quad \\rightarrow \\quad\n", - "\\frac{1}{M} \\sum_{i \\in B_k} \\nabla \\mathcal{L}_i(\\theta) ,$$\n", - "\n", - "i.e. instead of averaging the loss over the entire dataset, we average over a minibatch. \n", - "\n", - "This has two important benefits: \n", - "1. Introducing stochasticity decreases the chance that the algorithm becomes stuck in a local minima. \n", - "\n", - "2. It significantly speeds up the calculation, since we do not have to use the entire dataset to calculate the gradient. \n", - "\n", - "The various optmization methods, with codes and algorithms, are discussed in our lectures on [Gradient descent approaches](https://compphysics.github.io/MachineLearning/doc/pub/Splines/html/Splines-bs.html)." - ] - }, - { - "cell_type": "markdown", - "id": "ef19d1e0", - "metadata": { - "editable": true - }, - "source": [ - "## Regularization\n", - "\n", - "It is common to add an extra term to the cost function, proportional\n", - "to the size of the weights. This is equivalent to constraining the\n", - "size of the weights, so that they do not grow out of control.\n", - "Constraining the size of the weights means that the weights cannot\n", - "grow arbitrarily large to fit the training data, and in this way\n", - "reduces *overfitting*.\n", - "\n", - "We will measure the size of the weights using the so called *L2-norm*, meaning our cost function becomes: \n", - "\n", - "$$ \\mathcal{C}(\\theta) = \\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}_i(\\theta) \\quad \\rightarrow \\quad\n", - "\\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}_i(\\theta) + \\lambda \\lvert \\lvert \\boldsymbol{w} \\rvert \\rvert_2^2 \n", - "= \\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}(\\theta) + \\lambda \\sum_{ij} w_{ij}^2,$$ \n", + "## Which activation function should we use?\n", "\n", - "i.e. we sum up all the weights squared. The factor $\\lambda$ is known as a regularization parameter.\n", + "In general it seems that the ELU activation function is better than\n", + "the leaky ReLU function (and its variants), which is better than\n", + "ReLU. ReLU performs better than $\\tanh$ which in turn performs better\n", + "than the logistic function.\n", "\n", - "In order to train the model, we need to calculate the derivative of\n", - "the cost function with respect to every bias and weight in the\n", - "network. In total our network has $(64 + 1)\\times 50=3250$ weights in\n", - "the hidden layer and $(50 + 1)\\times 10=510$ weights to the output\n", - "layer ($+1$ for the bias), and the gradient must be calculated for\n", - "every parameter. We use the *backpropagation* algorithm discussed\n", - "above. This is a clever use of the chain rule that allows us to\n", - "calculate the gradient efficently." + "If runtime performance is an issue, then you may opt for the leaky\n", + "ReLU function over the ELU function If you don’t want to tweak yet\n", + "another hyperparameter, you may just use the default $\\alpha$ of\n", + "$0.01$ for the leaky ReLU, and $1$ for ELU. If you have spare time and\n", + "computing power, you can use cross-validation or bootstrap to evaluate\n", + "other activation functions." ] }, { "cell_type": "markdown", - "id": "d93c5dfb", - "metadata": { - "editable": true - }, - "source": [ - "## Matrix multiplication\n", - "\n", - "To more efficently train our network these equations are implemented using matrix operations. \n", - "The error in the output layer is calculated simply as, with $\\boldsymbol{t}$ being our targets, \n", - "\n", - "$$ \\delta_L = \\boldsymbol{t} - \\boldsymbol{y} = (n_{inputs}, n_{categories}) .$$ \n", - "\n", - "The gradient for the output weights is calculated as \n", - "\n", - "$$ \\nabla W_{L} = \\boldsymbol{a}^T \\delta_L = (n_{hidden}, n_{categories}) ,$$\n", - "\n", - "where $\\boldsymbol{a} = (n_{inputs}, n_{hidden})$. This simply means that we are summing up the gradients for each input. \n", - "Since we are going backwards we have to transpose the activation matrix. \n", - "\n", - "The gradient with respect to the output bias is then \n", - "\n", - "$$ \\nabla \\boldsymbol{b}_{L} = \\sum_{i=1}^{n_{inputs}} \\delta_L = (n_{categories}) .$$ \n", - "\n", - "The error in the hidden layer is \n", - "\n", - "$$ \\Delta_h = \\delta_L W_{L}^T \\circ f'(z_{h}) = \\delta_L W_{L}^T \\circ a_{h} \\circ (1 - a_{h}) = (n_{inputs}, n_{hidden}) ,$$ \n", - "\n", - "where $f'(a_{h})$ is the derivative of the activation in the hidden layer. The matrix products mean\n", - "that we are summing up the products for each neuron in the output layer. The symbol $\\circ$ denotes\n", - "the *Hadamard product*, meaning element-wise multiplication. \n", - "\n", - "This again gives us the gradients in the hidden layer: \n", - "\n", - "$$ \\nabla W_{h} = X^T \\delta_h = (n_{features}, n_{hidden}) ,$$ \n", - "\n", - "$$ \\nabla b_{h} = \\sum_{i=1}^{n_{inputs}} \\delta_h = (n_{hidden}) .$$" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "0a62b82a", + "id": "edb42800", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "# to categorical turns our integer vector into a onehot representation\n", - "from sklearn.metrics import accuracy_score\n", + "## More on activation functions, output layers\n", "\n", - "# one-hot in numpy\n", - "def to_categorical_numpy(integer_vector):\n", - " n_inputs = len(integer_vector)\n", - " n_categories = np.max(integer_vector) + 1\n", - " onehot_vector = np.zeros((n_inputs, n_categories))\n", - " onehot_vector[range(n_inputs), integer_vector] = 1\n", - " \n", - " return onehot_vector\n", + "In most cases you can use the ReLU activation function in the hidden\n", + "layers (or one of its variants).\n", "\n", - "#Y_train_onehot, Y_test_onehot = to_categorical(Y_train), to_categorical(Y_test)\n", - "Y_train_onehot, Y_test_onehot = to_categorical_numpy(Y_train), to_categorical_numpy(Y_test)\n", + "It is a bit faster to compute than other activation functions, and the\n", + "gradient descent optimization does in general not get stuck.\n", "\n", - "def feed_forward_train(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " \n", - " # for backpropagation need activations in hidden and output layers\n", - " return a_h, probabilities\n", + "**For the output layer:**\n", "\n", - "def backpropagation(X, Y):\n", - " a_h, probabilities = feed_forward_train(X)\n", - " \n", - " # error in the output layer\n", - " error_output = probabilities - Y\n", - " # error in the hidden layer\n", - " error_hidden = np.matmul(error_output, output_weights.T) * a_h * (1 - a_h)\n", - " \n", - " # gradients for the output layer\n", - " output_weights_gradient = np.matmul(a_h.T, error_output)\n", - " output_bias_gradient = np.sum(error_output, axis=0)\n", - " \n", - " # gradient for the hidden layer\n", - " hidden_weights_gradient = np.matmul(X.T, error_hidden)\n", - " hidden_bias_gradient = np.sum(error_hidden, axis=0)\n", + "* For classification the softmax activation function is generally a good choice for classification tasks (when the classes are mutually exclusive).\n", "\n", - " return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient\n", - "\n", - "print(\"Old accuracy on training data: \" + str(accuracy_score(predict(X_train), Y_train)))\n", - "\n", - "eta = 0.01\n", - "lmbd = 0.01\n", - "for i in range(1000):\n", - " # calculate gradients\n", - " dWo, dBo, dWh, dBh = backpropagation(X_train, Y_train_onehot)\n", - " \n", - " # regularization term gradients\n", - " dWo += lmbd * output_weights\n", - " dWh += lmbd * hidden_weights\n", - " \n", - " # update weights and biases\n", - " output_weights -= eta * dWo\n", - " output_bias -= eta * dBo\n", - " hidden_weights -= eta * dWh\n", - " hidden_bias -= eta * dBh\n", - "\n", - "print(\"New accuracy on training data: \" + str(accuracy_score(predict(X_train), Y_train)))" + "* For regression tasks, you can simply use no activation function at all." ] }, { "cell_type": "markdown", - "id": "b666f091", + "id": "1a8fafc0", "metadata": { "editable": true }, "source": [ - "## Improving performance\n", - "\n", - "As we can see the network does not seem to be learning at all. It seems to be just guessing the label for each image. \n", - "In order to obtain a network that does something useful, we will have to do a bit more work. \n", + "## Batch Normalization\n", "\n", - "The choice of *hyperparameters* such as learning rate and regularization parameter is hugely influential for the performance of the network. Typically a *grid-search* is performed, wherein we test different hyperparameters separated by orders of magnitude. For example we could test the learning rates $\\eta = 10^{-6}, 10^{-5},...,10^{-1}$ with different regularization parameters $\\lambda = 10^{-6},...,10^{-0}$. \n", + "Batch Normalization aims to address the vanishing/exploding gradients\n", + "problems, and more generally the problem that the distribution of each\n", + "layer’s inputs changes during training, as the parameters of the\n", + "previous layers change.\n", "\n", - "Next, we haven't implemented minibatching yet, which introduces stochasticity and is though to act as an important regularizer on the weights. We call a feed-forward + backward pass with a minibatch an *iteration*, and a full training period\n", - "going through the entire dataset ($n/M$ batches) an *epoch*.\n", - "\n", - "If this does not improve network performance, you may want to consider altering the network architecture, adding more neurons or hidden layers. \n", - "Andrew Ng goes through some of these considerations in this [video](https://youtu.be/F1ka6a13S9I). You can find a summary of the video [here](https://kevinzakka.github.io/2016/09/26/applying-deep-learning/)." + "The technique consists of adding an operation in the model just before\n", + "the activation function of each layer, simply zero-centering and\n", + "normalizing the inputs, then scaling and shifting the result using two\n", + "new parameters per layer (one for scaling, the other for shifting). In\n", + "other words, this operation lets the model learn the optimal scale and\n", + "mean of the inputs for each layer. In order to zero-center and\n", + "normalize the inputs, the algorithm needs to estimate the inputs’ mean\n", + "and standard deviation. It does so by evaluating the mean and standard\n", + "deviation of the inputs over the current mini-batch, from this the\n", + "name batch normalization." ] }, { "cell_type": "markdown", - "id": "79055893", - "metadata": { - "editable": true - }, - "source": [ - "## Full object-oriented implementation\n", - "\n", - "It is very natural to think of the network as an object, with specific instances of the network\n", - "being realizations of this object with different hyperparameters. An implementation using Python classes provides a clean structure and interface, and the full implementation of our neural network is given below." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "85af4a1c", + "id": "feef1d4d", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "class NeuralNetwork:\n", - " def __init__(\n", - " self,\n", - " X_data,\n", - " Y_data,\n", - " n_hidden_neurons=50,\n", - " n_categories=10,\n", - " epochs=10,\n", - " batch_size=100,\n", - " eta=0.1,\n", - " lmbd=0.0):\n", - "\n", - " self.X_data_full = X_data\n", - " self.Y_data_full = Y_data\n", - "\n", - " self.n_inputs = X_data.shape[0]\n", - " self.n_features = X_data.shape[1]\n", - " self.n_hidden_neurons = n_hidden_neurons\n", - " self.n_categories = n_categories\n", - "\n", - " self.epochs = epochs\n", - " self.batch_size = batch_size\n", - " self.iterations = self.n_inputs // self.batch_size\n", - " self.eta = eta\n", - " self.lmbd = lmbd\n", - "\n", - " self.create_biases_and_weights()\n", - "\n", - " def create_biases_and_weights(self):\n", - " self.hidden_weights = np.random.randn(self.n_features, self.n_hidden_neurons)\n", - " self.hidden_bias = np.zeros(self.n_hidden_neurons) + 0.01\n", - "\n", - " self.output_weights = np.random.randn(self.n_hidden_neurons, self.n_categories)\n", - " self.output_bias = np.zeros(self.n_categories) + 0.01\n", - "\n", - " def feed_forward(self):\n", - " # feed-forward for training\n", - " self.z_h = np.matmul(self.X_data, self.hidden_weights) + self.hidden_bias\n", - " self.a_h = sigmoid(self.z_h)\n", - "\n", - " self.z_o = np.matmul(self.a_h, self.output_weights) + self.output_bias\n", - "\n", - " exp_term = np.exp(self.z_o)\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - "\n", - " def feed_forward_out(self, X):\n", - " # feed-forward for output\n", - " z_h = np.matmul(X, self.hidden_weights) + self.hidden_bias\n", - " a_h = sigmoid(z_h)\n", - "\n", - " z_o = np.matmul(a_h, self.output_weights) + self.output_bias\n", - " \n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " return probabilities\n", + "## Dropout\n", "\n", - " def backpropagation(self):\n", - " error_output = self.probabilities - self.Y_data\n", - " error_hidden = np.matmul(error_output, self.output_weights.T) * self.a_h * (1 - self.a_h)\n", + "It is a fairly simple algorithm: at every training step, every neuron\n", + "(including the input neurons but excluding the output neurons) has a\n", + "probability $p$ of being temporarily dropped out, meaning it will be\n", + "entirely ignored during this training step, but it may be active\n", + "during the next step.\n", "\n", - " self.output_weights_gradient = np.matmul(self.a_h.T, error_output)\n", - " self.output_bias_gradient = np.sum(error_output, axis=0)\n", - "\n", - " self.hidden_weights_gradient = np.matmul(self.X_data.T, error_hidden)\n", - " self.hidden_bias_gradient = np.sum(error_hidden, axis=0)\n", - "\n", - " if self.lmbd > 0.0:\n", - " self.output_weights_gradient += self.lmbd * self.output_weights\n", - " self.hidden_weights_gradient += self.lmbd * self.hidden_weights\n", - "\n", - " self.output_weights -= self.eta * self.output_weights_gradient\n", - " self.output_bias -= self.eta * self.output_bias_gradient\n", - " self.hidden_weights -= self.eta * self.hidden_weights_gradient\n", - " self.hidden_bias -= self.eta * self.hidden_bias_gradient\n", - "\n", - " def predict(self, X):\n", - " probabilities = self.feed_forward_out(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - " def predict_probabilities(self, X):\n", - " probabilities = self.feed_forward_out(X)\n", - " return probabilities\n", - "\n", - " def train(self):\n", - " data_indices = np.arange(self.n_inputs)\n", - "\n", - " for i in range(self.epochs):\n", - " for j in range(self.iterations):\n", - " # pick datapoints with replacement\n", - " chosen_datapoints = np.random.choice(\n", - " data_indices, size=self.batch_size, replace=False\n", - " )\n", - "\n", - " # minibatch training data\n", - " self.X_data = self.X_data_full[chosen_datapoints]\n", - " self.Y_data = self.Y_data_full[chosen_datapoints]\n", - "\n", - " self.feed_forward()\n", - " self.backpropagation()" + "The hyperparameter $p$ is called the dropout rate, and it is typically\n", + "set to 50%. After training, the neurons are not dropped anymore. It\n", + "is viewed as one of the most popular regularization techniques." ] }, { "cell_type": "markdown", - "id": "d0ef37e8", - "metadata": { - "editable": true - }, - "source": [ - "## Evaluate model performance on test data\n", - "\n", - "To measure the performance of our network we evaluate how well it does it data it has never seen before, i.e. the test data. \n", - "We measure the performance of the network using the *accuracy* score. \n", - "The accuracy is as you would expect just the number of images correctly labeled divided by the total number of images. A perfect classifier will have an accuracy score of $1$. \n", - "\n", - "$$ \\text{Accuracy} = \\frac{\\sum_{i=1}^n I(\\tilde{y}_i = y_i)}{n} ,$$ \n", - "\n", - "where $I$ is the indicator function, $1$ if $\\tilde{y}_i = y_i$ and $0$ otherwise." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "d2891643", + "id": "9428c225", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "epochs = 100\n", - "batch_size = 100\n", - "\n", - "dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,\n", - " n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)\n", - "dnn.train()\n", - "test_predict = dnn.predict(X_test)\n", + "## Gradient Clipping\n", "\n", - "# accuracy score from scikit library\n", - "print(\"Accuracy score on test set: \", accuracy_score(Y_test, test_predict))\n", - "\n", - "# equivalent in numpy\n", - "def accuracy_score_numpy(Y_test, Y_pred):\n", - " return np.sum(Y_test == Y_pred) / len(Y_test)\n", - "\n", - "#print(\"Accuracy score on test set: \", accuracy_score_numpy(Y_test, test_predict))" - ] - }, - { - "cell_type": "markdown", - "id": "5c91c8fc", - "metadata": { - "editable": true - }, - "source": [ - "## Adjust hyperparameters\n", + "A popular technique to lessen the exploding gradients problem is to\n", + "simply clip the gradients during backpropagation so that they never\n", + "exceed some threshold (this is mostly useful for recurrent neural\n", + "networks).\n", "\n", - "We now perform a grid search to find the optimal hyperparameters for the network. \n", - "Note that we are only using 1 layer with 50 neurons, and human performance is estimated to be around $98\\%$ ($2\\%$ error rate)." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "c245d23d", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "eta_vals = np.logspace(-5, 1, 7)\n", - "lmbd_vals = np.logspace(-5, 1, 7)\n", - "# store the models for later use\n", - "DNN_numpy = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", + "This technique is called Gradient Clipping.\n", "\n", - "# grid search\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,\n", - " n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)\n", - " dnn.train()\n", - " \n", - " DNN_numpy[i][j] = dnn\n", - " \n", - " test_predict = dnn.predict(X_test)\n", - " \n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on test set: \", accuracy_score(Y_test, test_predict))\n", - " print()" + "In general however, Batch\n", + "Normalization is preferred." ] }, { "cell_type": "markdown", - "id": "ea3be61a", - "metadata": { - "editable": true - }, - "source": [ - "## Visualization" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "d26e1748", + "id": "504b21ae", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "# visual representation of grid search\n", - "# uses seaborn heatmap, you can also do this with matplotlib imshow\n", - "import seaborn as sns\n", - "\n", - "sns.set()\n", - "\n", - "train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_numpy[i][j]\n", - " \n", - " train_pred = dnn.predict(X_train) \n", - " test_pred = dnn.predict(X_test)\n", - "\n", - " train_accuracy[i][j] = accuracy_score(Y_train, train_pred)\n", - " test_accuracy[i][j] = accuracy_score(Y_test, test_pred)\n", + "## A top-down perspective on Neural networks\n", "\n", - " \n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Training Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()\n", + "The first thing we would like to do is divide the data into two or\n", + "three parts. A training set, a validation or dev (development) set,\n", + "and a test set. The test set is the data on which we want to make\n", + "predictions. The dev set is a subset of the training data we use to\n", + "check how well we are doing out-of-sample, after training the model on\n", + "the training dataset. We use the validation error as a proxy for the\n", + "test error in order to make tweaks to our model. It is crucial that we\n", + "do not use any of the test data to train the algorithm. This is a\n", + "cardinal sin in ML. Then:\n", "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "572f3f4b", - "metadata": { - "editable": true - }, - "source": [ - "## scikit-learn implementation\n", + "1. Estimate optimal error rate\n", "\n", - "**scikit-learn** focuses more\n", - "on traditional machine learning methods, such as regression,\n", - "clustering, decision trees, etc. As such, it has only two types of\n", - "neural networks: Multi Layer Perceptron outputting continuous values,\n", - "*MPLRegressor*, and Multi Layer Perceptron outputting labels,\n", - "*MLPClassifier*. We will see how simple it is to use these classes.\n", - "\n", - "**scikit-learn** implements a few improvements from our neural network,\n", - "such as early stopping, a varying learning rate, different\n", - "optimization methods, etc. We would therefore expect a better\n", - "performance overall." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "fdb38053", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "from sklearn.neural_network import MLPClassifier\n", - "# store models for later use\n", - "DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", + "2. Minimize underfitting (bias) on training data set.\n", "\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic',\n", - " alpha=lmbd, learning_rate_init=eta, max_iter=epochs)\n", - " dnn.fit(X_train, Y_train)\n", - " \n", - " DNN_scikit[i][j] = dnn\n", - " \n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on test set: \", dnn.score(X_test, Y_test))\n", - " print()" + "3. Make sure you are not overfitting." ] }, { "cell_type": "markdown", - "id": "5fc3dd13", + "id": "c51837a9", "metadata": { "editable": true }, "source": [ - "## Visualization" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "cd9e4505", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# optional\n", - "# visual representation of grid search\n", - "# uses seaborn heatmap, could probably do this in matplotlib\n", - "import seaborn as sns\n", - "\n", - "sns.set()\n", + "## More top-down perspectives\n", "\n", - "train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", + "If the validation and test sets are drawn from the same distributions,\n", + "then a good performance on the validation set should lead to similarly\n", + "good performance on the test set. \n", "\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_scikit[i][j]\n", - " \n", - " train_pred = dnn.predict(X_train) \n", - " test_pred = dnn.predict(X_test)\n", - "\n", - " train_accuracy[i][j] = accuracy_score(Y_train, train_pred)\n", - " test_accuracy[i][j] = accuracy_score(Y_test, test_pred)\n", - "\n", - " \n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Training Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()\n", - "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" + "However, sometimes\n", + "the training data and test data differ in subtle ways because, for\n", + "example, they are collected using slightly different methods, or\n", + "because it is cheaper to collect data in one way versus another. In\n", + "this case, there can be a mismatch between the training and test\n", + "data. This can lead to the neural network overfitting these small\n", + "differences between the test and training sets, and a poor performance\n", + "on the test set despite having a good performance on the validation\n", + "set. To rectify this, Andrew Ng suggests making two validation or dev\n", + "sets, one constructed from the training data and one constructed from\n", + "the test data. The difference between the performance of the algorithm\n", + "on these two validation sets quantifies the train-test mismatch. This\n", + "can serve as another important diagnostic when using DNNs for\n", + "supervised learning." ] }, { "cell_type": "markdown", - "id": "30d61094", + "id": "a7357657", "metadata": { "editable": true }, "source": [ - "## Testing our code for the XOR, OR and AND gates\n", - "\n", - "Last week we discussed three different types of gates, the so-called\n", - "XOR, the OR and the AND gates. Their inputs and outputs can be\n", - "summarized using the following tables, first for the OR gate with\n", - "inputs $x_1$ and $x_2$ and outputs $y$:\n", + "## Limitations of supervised learning with deep networks\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
$x_1$ $x_2$ $y$
0 0 0
0 1 1
1 0 1
1 1 1
" + "Like all statistical methods, supervised learning using neural\n", + "networks has important limitations. This is especially important when\n", + "one seeks to apply these methods, especially to physics problems. Like\n", + "all tools, DNNs are not a universal solution. Often, the same or\n", + "better performance on a task can be achieved by using a few\n", + "hand-engineered features (or even a collection of random\n", + "features)." ] }, { "cell_type": "markdown", - "id": "9b4cd63f", + "id": "e92c8a84", "metadata": { "editable": true }, "source": [ - "## The AND and XOR Gates\n", + "## Limitations of NNs\n", "\n", - "The AND gate is defined as\n", + "Here we list some of the important limitations of supervised neural network based models. \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
$x_1$ $x_2$ $y$
0 0 0
0 1 0
1 0 0
1 1 1
\n", - "\n", - "And finally we have the XOR gate\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
$x_1$ $x_2$ $y$
0 0 0
0 1 1
1 0 1
1 1 0
" - ] - }, - { - "cell_type": "markdown", - "id": "1a2bd6f1", - "metadata": { - "editable": true - }, - "source": [ - "## Representing the Data Sets\n", + "* **Need labeled data**. All supervised learning methods, DNNs for supervised learning require labeled data. Often, labeled data is harder to acquire than unlabeled data (e.g. one must pay for human experts to label images).\n", "\n", - "Our design matrix is defined by the input values $x_1$ and $x_2$. Since we have four possible outputs, our design matrix reads" - ] - }, - { - "cell_type": "markdown", - "id": "a569e669", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\boldsymbol{X}=\\begin{bmatrix} 0 & 0 \\\\\n", - " 0 & 1 \\\\\n", - "\t\t 1 & 0 \\\\\n", - "\t\t 1 & 1 \\end{bmatrix},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "51363b82", - "metadata": { - "editable": true - }, - "source": [ - "while the vector of outputs is $\\boldsymbol{y}^T=[0,1,1,0]$ for the XOR gate, $\\boldsymbol{y}^T=[0,0,0,1]$ for the AND gate and $\\boldsymbol{y}^T=[0,1,1,1]$ for the OR gate." + "* **Supervised neural networks are extremely data intensive.** DNNs are data hungry. They perform best when data is plentiful. This is doubly so for supervised methods where the data must also be labeled. The utility of DNNs is extremely limited if data is hard to acquire or the datasets are small (hundreds to a few thousand samples). In this case, the performance of other methods that utilize hand-engineered features can exceed that of DNNs." ] }, { "cell_type": "markdown", - "id": "e4172d21", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Neural Network\n", - "\n", - "We define first our design matrix and the various output vectors for the different gates." - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "b8640651", + "id": "793aee7d", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "\"\"\"\n", - "Simple code that tests XOR, OR and AND gates with linear regression\n", - "\"\"\"\n", - "\n", - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn import datasets\n", - "\n", - "def sigmoid(x):\n", - " return 1/(1 + np.exp(-x))\n", + "## Homogeneous data\n", "\n", - "def feed_forward(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " probabilities = sigmoid(z_o)\n", - " return probabilities\n", - "\n", - "# we obtain a prediction by taking the class with the highest likelihood\n", - "def predict(X):\n", - " probabilities = feed_forward(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# Design matrix\n", - "X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64)\n", - "\n", - "# The XOR gate\n", - "yXOR = np.array( [ 0, 1 ,1, 0])\n", - "# The OR gate\n", - "yOR = np.array( [ 0, 1 ,1, 1])\n", - "# The AND gate\n", - "yAND = np.array( [ 0, 0 ,0, 1])\n", - "\n", - "# Defining the neural network\n", - "n_inputs, n_features = X.shape\n", - "n_hidden_neurons = 2\n", - "n_categories = 2\n", - "n_features = 2\n", - "\n", - "# we make the weights normally distributed using numpy.random.randn\n", - "\n", - "# weights and bias in the hidden layer\n", - "hidden_weights = np.random.randn(n_features, n_hidden_neurons)\n", - "hidden_bias = np.zeros(n_hidden_neurons) + 0.01\n", - "\n", - "# weights and bias in the output layer\n", - "output_weights = np.random.randn(n_hidden_neurons, n_categories)\n", - "output_bias = np.zeros(n_categories) + 0.01\n", - "\n", - "probabilities = feed_forward(X)\n", - "print(probabilities)\n", - "\n", - "\n", - "predictions = predict(X)\n", - "print(predictions)" - ] - }, - { - "cell_type": "markdown", - "id": "f6b2c036", - "metadata": { - "editable": true - }, - "source": [ - "Not an impressive result, but this was our first forward pass with randomly assigned weights. Let us now add the full network with the back-propagation algorithm discussed above." + "* **Homogeneous data.** Almost all DNNs deal with homogeneous data of one type. It is very hard to design architectures that mix and match data types (i.e. some continuous variables, some discrete variables, some time series). In applications beyond images, video, and language, this is often what is required. In contrast, ensemble models like random forests or gradient-boosted trees have no difficulty handling mixed data types." ] }, { "cell_type": "markdown", - "id": "49fdf701", - "metadata": { - "editable": true - }, - "source": [ - "## The Code using Scikit-Learn" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "45dae979", + "id": "739960d6", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn.neural_network import MLPClassifier\n", - "from sklearn.metrics import accuracy_score\n", - "import seaborn as sns\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# Design matrix\n", - "X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64)\n", - "\n", - "# The XOR gate\n", - "yXOR = np.array( [ 0, 1 ,1, 0])\n", - "# The OR gate\n", - "yOR = np.array( [ 0, 1 ,1, 1])\n", - "# The AND gate\n", - "yAND = np.array( [ 0, 0 ,0, 1])\n", - "\n", - "# Defining the neural network\n", - "n_inputs, n_features = X.shape\n", - "n_hidden_neurons = 2\n", - "n_categories = 2\n", - "n_features = 2\n", - "\n", - "eta_vals = np.logspace(-5, 1, 7)\n", - "lmbd_vals = np.logspace(-5, 1, 7)\n", - "# store models for later use\n", - "DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", - "epochs = 100\n", - "\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic',\n", - " alpha=lmbd, learning_rate_init=eta, max_iter=epochs)\n", - " dnn.fit(X, yXOR)\n", - " DNN_scikit[i][j] = dnn\n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on data set: \", dnn.score(X, yXOR))\n", - " print()\n", + "## More limitations\n", "\n", - "sns.set()\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_scikit[i][j]\n", - " test_pred = dnn.predict(X)\n", - " test_accuracy[i][j] = accuracy_score(yXOR, test_pred)\n", + "* **Many problems are not about prediction.** In natural science we are often interested in learning something about the underlying distribution that generates the data. In this case, it is often difficult to cast these ideas in a supervised learning setting. While the problems are related, it is possible to make good predictions with a *wrong* model. The model might or might not be useful for understanding the underlying science.\n", "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" + "Some of these remarks are particular to DNNs, others are shared by all supervised learning methods. This motivates the use of unsupervised methods which in part circumvent these problems." ] } ], diff --git a/doc/LectureNotes/_build/html/searchindex.js b/doc/LectureNotes/_build/html/searchindex.js index ff6fa84d3..23ec9cdf5 100644 --- a/doc/LectureNotes/_build/html/searchindex.js +++ b/doc/LectureNotes/_build/html/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["chapter1","chapter10","chapter11","chapter12","chapter13","chapter2","chapter3","chapter4","chapter5","chapter6","chapter7","chapter8","chapter9","chapteroptimization","clustering","exercisesweek34","exercisesweek35","exercisesweek36","exercisesweek37","exercisesweek38","exercisesweek39","exercisesweek41","intro","linalg","project1","schedule","statistics","teachers","textbooks","week34","week35","week36","week37","week38","week39","week40","week41"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":4,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":3,"sphinx.domains.rst":2,"sphinx.domains.std":2,"sphinx.ext.intersphinx":1,sphinx:56},filenames:["chapter1.ipynb","chapter10.ipynb","chapter11.ipynb","chapter12.ipynb","chapter13.ipynb","chapter2.ipynb","chapter3.ipynb","chapter4.ipynb","chapter5.ipynb","chapter6.ipynb","chapter7.ipynb","chapter8.ipynb","chapter9.ipynb","chapteroptimization.ipynb","clustering.ipynb","exercisesweek34.ipynb","exercisesweek35.ipynb","exercisesweek36.ipynb","exercisesweek37.ipynb","exercisesweek38.ipynb","exercisesweek39.ipynb","exercisesweek41.ipynb","intro.md","linalg.ipynb","project1.ipynb","schedule.md","statistics.ipynb","teachers.md","textbooks.md","week34.ipynb","week35.ipynb","week36.ipynb","week37.ipynb","week38.ipynb","week39.ipynb","week40.ipynb","week41.ipynb"],objects:{},objnames:{},objtypes:{},terms:{"0":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,27,29,30,31,32,33,34,35,36],"00":[0,1,5,6,9,11,29,30,31,35,36],"000":[1,3,9,36],"0000":[5,9],"00000":[9,34],"000000":[5,11,30],"00000000e":[5,30,35,36],"00001":34,"00001572":[],"00001716":35,"00002":34,"00002585e":30,"00003":34,"00003828":35,"00005":34,"00007":34,"00007706":35,"00007738":[],"00009":34,"0001":[1,17,36],"00010067":34,"00010366":[],"00011577":21,"00012":34,"000137":26,"00013955":21,"00014166":21,"00016062":21,"00016449":21,"00016535":[],"00016719":34,"00017733":[],"00018":34,"00018053":[],"00018212":21,"00018651":21,"00019258":35,"00019998":5,"0002065":21,"00021147":21,"00021270681344726395":[],"000225":34,"00022969":[],"00023":34,"00023414":21,"00023813":[],"00023978":21,"00024087":5,"00024929":34,"00025662":34,"00026549":21,"00027188":21,"0002762":34,"00027746":34,"00028":34,"00028167":34,"00029012":5,"0002926":[],"00030102":21,"00030601":34,"00030827":21,"00031208":34,"00031535148309577417":[6,31],"0003153514830958095":[6,31],"00033904":34,"00034132":21,"00034576":34,"00034688149480437765":[],"00034944":5,"00034953":21,"0003701342170783489":9,"00037564":34,"00037737":21,"00038309":34,"000387":21,"00039632":21,"00041619":34,"000417932":2,"00042089":5,"00042093":34,"00042444":34,"00042721":[],"0004388":21,"00044":34,"00044937":21,"00046006":34,"00046111":34,"000464088":2,"00046631":[],"00047025":34,"00048158":21,"00049754":21,"00050694":5,"00050952":21,"00051088":34,"00051916":[],"00052102":34,"00053001":[],"00053122":[],"00056414":21,"00056603":34,"00057726":34,"00057772":21,"00058016":[6,31],"00060":34,"00060704":6,"00061058":5,"00062592":6,"00062668":[],"000626681519836":[],"00062713":34,"00063362":32,"00063866":32,"00063957":34,"00063965":21,"00065505":21,"00066668":[6,31],"00067008":34,"00068091":32,"00068734":[6,31],"00069":34,"00069123":6,"00069482":34,"0007086":34,"00072527":21,"00073541":5,"00074274":21,"00075590":32,"00076202":34,"00076495":[6,31],"00076908":6,"00076983":34,"0007698473260556325":[6,31],"0007698473260556343":[6,31],"000783":[],"00078324":[],"00078509":34,"00079125":6,"00079904":32,"00079968":5,"00080497":[],"00082235":21,"0008297120772365539":[],"00083355":32,"00084215":21,"00084707":6,"00085292":34,"00085892":6,"00086984":34,"00087697":[6,31],"00088573":5,"00089193":32,"00092678":6,"00092898":32,"00093243":21,"00094499":34,"00095488":21,"00095624":[],"00096314":5,"00096373":34,"00099778":[],"001":[1,2,8,13,17,31,33,34,36],"00100081":[],"00100519":[6,31],"00100913":[],"001047":34,"0010479245693919886":[6,32],"00105081":[6,31],"00105724":21,"00106677":5,"00106776":34,"00107405":[6,31],"00108":34,"0010827":21,"00108471":[],"00109354":[],"00111756":[6,31],"00114401":[],"00114451":[],"00114855":[],"0011526":[6,31],"00115631":34,"00115999":5,"00116001":34,"00118302":34,"00118584":6,"00119688":32,"00119876":21,"00122762":21,"00125057":[],"00126053":34,"00128479":5,"00128523":34,"00130885":[],"00131072":34,"001323":[6,31],"00133638":[],"00134424":35,"00135922":21,"00136125":[],"00137814":6,"00139195":21,"00139705":5,"00140846":32,"00141727":34,"00142396":34,"00143013":[],"00144539":34,"0014522":34,"001468":[],"00146807":[],"00149311":[6,31],"00149679":[],"00149956":[6,31],"00151416":[],"00151426":35,"00152117":[6,31],"00154115":21,"00154733":5,"00154853":32,"00156374":6,"00157766":34,"00157826":21,"00158":34,"00160895":34,"00161463":35,"00162921":[],"00163548":[],"00167329":34,"00168251":5,"00168745":[],"00169":34,"00170579":35,"00170809":[],"00171171":[],"00172865":[],"00174276":[6,31],"00174738":[],"00174743":21,"00174795":34,"00175331":[6,31],"00178263":34,"00178952":21,"001795":[],"00180673":34,"00181885":35,"0018310257999764163":[],"00186347":5,"00187032":[],"0018798":[],"001880":5,"00191076":[],"00192154":35,"00193661":34,"0019575":[],"00197505":34,"00198129":21,"00200":8,"00202624":5,"00202756":[6,31],"00202904":21,"0020489":35,"00206234":[],"00208188":34,"00209403":[],"00211418":[],"00211924":21,"00212766":[],"00213888":[],"00214559":34,"00216458":35,"00217499":[6,31],"00217968":[],"00218823":34,"00219195":32,"00220013":[],"00223857":[],"00224413":5,"00224638":21,"00225842":34,"0022626":[],"00228740":6,"00229111":[],"00230059":21,"00230805":35,"0023548":[6,31],"00236918":[],"00237699":34,"002381316302584885":[6,31],"0023813163025848865":[6,31],"00242441":34,"0024271":[],"00242954":32,"00242999":6,"00243186":[6,31],"00243835":35,"0024401":5,"002446":[],"00248232":[],"00249435":[6,31],"00250787":[],"00251359":[],"00254671":21,"00254973":[],"00256001":[],"00256622":[],"00259997":35,"00260839":21,"00263296":34,"00263755":[],"00263812":[],"00264":34,"00266858":2,"00268602":34,"00270244":5,"00270262":[],"00272337":[],"00274676":35,"00274989":[6,31],"00275768":[],"00279722":[],"00282226":[],"00282302":34,"00288656":21,"00289724":[6,31],"00290613":[],"00291535":34,"0029276":[],"00292882":35,"00293758":[],"00293838":5,"00295713":21,"00297571":34,"00298783":[],"0030094":[],"00302547":[],"00309418":35,"00310113":2,"00312361":[6,31],"00315593":6,"00319887":[],"0032153180657605116":[6,32],"00322456":34,"00323332":[6,31],"0032542":5,"00325450":32,"00326986":21,"00327104":[],"00327797":[],"00329616":34,"00329927":35,"00330046":[],"003301":[6,31],"00331927":[],"00334047":[],"00334797":[],"00335101":[],"00335174":21,"0033955154592040936":[6,32],"0034318":34,"00348246":[],"00348553":35,"00352878":34,"00353823":5,"00353938":[],"00355614":34,"00359628":[],"0036237":[6,31],"0036367":[6,31],"00363823":35,"00364159":[],"00364235":[],"00364967":34,"00365819":[],"00369758":[6,31],"00369852":21,"00371656":35,"0037314":[],"00379682":21,"0038287":[],"0038335":[6,31],"00389038":34,"003909404072811226":[6,32],"00391839":5,"0039259":[],"00392639":35,"0039455":[],"00399521":[],"0039987":[6,31],"00399972":[],"004":[5,31,32],"00403677":34,"00405581":[],"0040792":[],"00408":34,"004091940707753939":[6,32],"00410387":[6,31],"00410478":6,"004113634617443131":[6,30,31],"00411363461744314":[6,30,31],"004113634617443147":[6,30,31],"0041148":[],"00412":34,"00415497":[],"00415598634586135":[6,32],"00416103":34,"00416704":21,"00418347":[],"00418664":35,"00420072":32,"00424909":2,"00424967":[6,31],"00426027":5,"00429456":21,"0042992":34,"00432864":[],"00433417":11,"00434043":[],"0043587":[],"00437846":[],"00438318":[],"00440346":[6,31],"00441097":34,"004423":35,"00443743":[6,31],"0044505":34,"00445186":34,"00445655":11,"0045162":[],"00455966":[],"004579219539673834":[6,32],"00458631":[],"00458878":[6,31],"004610275230656212":[6,32],"00462287":[6,31],"00462662":[],"00464677":21,"00465099":32,"0046544":[],"00468914":26,"00471617":35,"00471782":5,"00472199":6,"00472276":[],"00472512":[6,31],"00474898":[],"00476012":34,"00478417":[],"00480881":[],"00483858":21,"00487029":34,"0049544":[6,31],"00497837":31,"00498243":35,"004999999999999991":[],"005":0,"005000000000000001":[],"00500716":[],"00502886":[],"00503932":21,"00507531":[],"00509128":34,"00512599":[],"00512927":5,"00513051":[],"00515181":[],"00515889":21,"00517114":[6,31],"00519717":[],"00520911":34,"00521014":[],"00522055":[],"00526348":[6,31],"00527578":[],"0053018":[6,31],"00531268":35,"00537955":[],"00539563":21,"00544547":34,"00546503":21,"00547113":[],"00551372":34,"00552462":[],"00554202":[],"00554552":[6,31],"00556826":[6,31],"00556946":[],"0055715":34,"00557893":[],"0055997":[],"00560098":[],"00561262":35,"005643":[],"00564344":[],"00564365":34,"00566707":[],"0056799":5,"00569512":[],"00570321":[],"0057065":[],"00571608":[],"00572613":[],"00573661":[],"00573727":[],"00574735":[],"00578809":[],"00579953":[6,31],"0058243":34,"00585143":21,"00586355":[],"00588657":[6,31],"0059267":21,"00593362":[],"0059591":34,"00597698":[],"00598464":35,"00606382":[],"00607783":6,"006162":[6,31],"00617221":[],"00617499":5,"0062202":[],"00622949":34,"00623535":[],"00625051":[],"00625672":[],"00627115":[],"00630331":[6,31],"00632251":35,"00633289":[],"00634299":[],"00634575":21,"00635016":[],"00637188":[],"00637367":34,"0063878":[],"00641423":[],"00642221":[6,31],"00642737":21,"00644":34,"0064472":31,"00647029":[],"00654835":[],"00659604":[],"00660427":[6,31],"00666287":34,"00667611":[],"00672607":[6,31],"00673407":[6,31],"00674158":35,"00676256":23,"00676387":[6,31],"00679013":[],"0068011":[6,31],"00681708":34,"00683748":5,"00683875021199284":[],"00683964":[6,31],"00685287":[],"00687309":[],"00688012":[],"00688182":21,"00689214":34,"00691012":[],"00694315":[],"0069668":[],"00697033":21,"007024126888938232":[6,32],"00702721":[],"0071129":[],"00712219":35,"0071264":34,"00715512":[],"00719176":[6,31],"00727646693":[0,29],"00729134":34,"00731392e":30,"007315":30,"00732665":[],"0074331":5,"00746317":21,"00747773":[],"00748862":[],"00754823":[],"00755917":21,"00759119":6,"00759427":35,"00762217":34,"00764333":[],"007658477904313023":[],"0076989":[],"0077313":[],"00779859":34,"00781918":32,"00784393":[6,31],"00789262":[],"00791263":[],"00792032":[],"00798909":[],"00802302":35,"00803064":[6,31],"008043811612683473":[],"00805074":32,"00809364":21,"00812487":[],"00813803":6,"00815244":34,"00816675":[],"00817631":[6,31],"00818251":[],"00819774":21,"00823002":5,"00827728":[6,31],"00828121":[],"00831018":[6,31],"00834112":34,"00834567":[6,31],"00838555":[],"00848904":[6,31],"0085548":35,"008560581831215528":[],"0085639":[],"00859693":[],"00860892":[],"00861518":34,"0086649156":[0,29],"008675369724975977":5,"00871959":34,"008753288788081405":30,"00877737":21,"00881939":[],"00885858":35,"00889027":21,"00889475":[],"00891702":[],"0089214":34,"00894639":5,"00903778":35,"00905423":[6,31],"00908537":[],"009163470508352218":5,"009164545680330616":[6,32],"00917248":[6,31],"00919984":[],"009211602191395454":30,"00925406":34,"00930146":[],"0093262":34,"009338082195270294":[],"00934327e":30,"00934499":[6,31],"00935742":[],"00939407":[],"009396472959497925":[],"00940611":[],"00942574":[],"00943959":[],"00951885":21,"00954206":34,"00955125":[],"00956827":[],"00958615":[],"0096208":[6,31],"00963683":35,"00964129":21,"00974758":[],"00979357":[],"00982052":[],"00989834e":[],"00990475":5,"00992331":[6,31],"00996754":[6,31],"00996762":[],"00997502":34,"01":[0,1,2,5,6,9,11,13,17,21,28,29,30,31,34,35,36],"010018312644137363":[6,32],"01003519":[],"01006":34,"01006984":[],"0100706":[6,31],"01009321":[],"01013849":[],"01014331":[],"01018089":35,"01020588":34,"01024875":[],"01031":34,"01032298":21,"01032533":[],"010331721306655127":[6,32],"010348289064969316":[],"01035006":[],"01039879":[],"01044475":[],"01045576":21,"010516485576645508":[6,32],"01060492":[],"010612904886352397":[],"01066519":[6,31],"01066897":34,"01067432":[],"01070103":[],"01075018":[],"01076611":5,"01076897":34,"01080465e":[],"01084359":[],"01085571":35,"01091589":34,"01093529":[],"01093553":[],"01098247":[],"0110":26,"01107333":[],"011076219011379514":[6,32],"011156605304609659":[],"01119504":21,"01119738":[],"01119981":[],"011208613520466846":[],"011225":2,"01123792e":30,"01129731":35,"0113104":[6,31],"01131771":[],"01133903":21,"01141119":34,"01146857":35,"01161645":[],"0116753":34,"01178857":[],"01179128":[],"01179415":[],"01179792":[6,31],"011818646101922625":30,"011886":[],"01191824":5,"01199741":[],"01206221":[],"012073649446193166":[6,32],"0121289":[],"01214076":21,"01214862":[],"0121766":[],"01219292":[6,31],"01220505":34,"01222822":30,"01222875":35,"01223198":[6,31],"01223754":[],"01229102":21,"01229692":21,"01231917":[6,31],"01234":[],"01234261":[],"01241284":[],"01244297":[],"01247909":[],"01248754":34,"01249445":35,"01250964":[],"01261048":[],"01265755":30,"012658":30,"01266999":[],"01267007":31,"0126711":[],"01268737":[],"01280793":[],"01288787":[],"01290947":[6,31],"0129191":35,"01295356":5,"01305415":34,"013121574015585152":[6,32],"013121574015585155":[6,32],"01315875":[],"01316233":[],"01316638":21,"01318643":[6,31],"01323523":[],"01327148e":[],"01329403":[],"01332832":[],"01333573":21,"01335628":34,"0134113":[],"01346122":34,"01347916":[6,31],"01348565":[6,31],"01349244":[],"01353638":[],"01355882":[],"01367553":[6,31],"0137297":34,"01373484":[],"01376216":[],"01377545":35,"01393496":[],"01396231":34,"01397146":[6,31],"01399457":[],"01405935":[6,31],"01406777":[],"01409478":[],"01416528":[6,31],"01427864":21,"01428546":34,"01433809":5,"014436800088904942":[6,32],"01444013":[],"0144623":21,"01449782":[6,31],"01455304":35,"01458337":[6,31],"014586":30,"01458611":30,"0146081":[6,31],"01462254":[],"01463049":[6,31],"01464686":[],"01473759":[],"01480256":[],"01493365":34,"014934":34,"01499192":[],"01506354":[],"01507238889517706":[6,31],"01507238889517717":[6,31],"01509793":[],"01511937":34,"01522108":21,"01527928":34,"01530321":[],"01531845":[6,31],"01532738":[],"01543076":[],"01548486":21,"01549377":[6,31],"01551724":[],"01551775":35,"015518":[],"01551815":[],"01552874":[],"01558197":5,"01568403":21,"01572":34,"01573062":[],"01573768":[],"01584129":[],"01594452":32,"01597256":34,"01600363":[],"01604235":[],"01620955":[],"01624447":[],"01625794":[],"01628578269596628":[6,32],"01633913":[6,31],"01634224":34,"01639344":35,"01640891":6,"01641044":[],"01643795":[],"0164974":[],"01654574":[],"01655318":[6,31],"01655384":[],"016587414993043573":[6,32],"01674956":[],"01679297":21,"01681173":[],"01681612":[],"01682652":34,"01691985":[6,31],"0169643":5,"01700897":21,"01706166":[],"01708375":34,"01708781":[6,31],"01708852":[6,31],"01713366":[6,31],"01717549":[],"01724499":5,"017355848195593347":[6,32],"01735584819559336":[6,32],"01737634":[],"01747915":34,"01748034":35,"01756114":[],"01759442":[],"01759974":[],"01760144":[],"017665":5,"01772779":[],"01779091e":[],"01783096":[],"01783414e":30,"0178462":[],"01793261":[],"0179826":[],"01811279":[],"01817048":[],"0182116":21,"018232":30,"01826811e":[],"01827225":34,"01827302":[],"01830039":[],"01831050e":[6,31],"01831190e":[6,31],"01844584":21,"01844822":[],"01846605":35,"01863203":[],"01866537":[6,31],"01869515":34,"01872002":[],"01873344":11,"01873869":5,"01881237":[],"01897462":[],"01898855":[6,31],"01905384":[],"01905883":[6,31],"01908936":[6,31],"01915337":[],"01922269":[],"0193075":[],"0195302":[],"01954342":34,"01963611":[6,31],"01969093":35,"01969145":[6,31],"01975006":21,"01975416527185249":[6,32],"01975848":[6,31],"01979808":[],"01999575":34,"02":[0,4,6,7,12,29,30,31,33,35,36],"0200041":21,"02014577":[],"02016185":[],"02024962":[6,31],"02026756":[],"02031987":[],"02032056":[],"02034655":[],"02054837e":[6,31],"0206033":[],"02068067":[6,31],"02073509":5,"02077431":31,"02079913":35,"02084474":[],"02087411":[],"02090304":34,"02091662":[],"02092464":[],"02098261":[6,31],"02102403":[],"02103315":34,"0211429":[],"02117843":[],"02123176":[6,31],"02126205":[],"02137508":23,"02138683":34,"02141849":21,"02148021":34,"02151521":[],"021544346900318832":31,"02156196":[],"02156565":[],"021592704588025022":[6,32],"021592704588025025":[6,32],"02164667":[],"02169399":21,"02175561":23,"02183817":[],"02189606":35,"02189863":[],"02189994":[],"02198702e":[6,31],"02198703e":[6,31],"022":[],"02207054":[],"02208512":[6,31],"02214409916811925":26,"02218045":35,"02218076":[],"02228115":[6,31],"02229529":[6,31],"02235723":34,"02252765":5,"02265404":[],"02281004":[],"02286267":[],"02287468":34,"02296298":34,"022999498260366312":[6,32],"0231353":[],"0232":[],"0232101":[],"02322297":[],"02322594":[],"02322786":21,"023295599127611474":[],"02330799":[],"02334754":[],"02338085":[],"02342235":35,"02345858":[],"02348765":[6,31],"02352663":21,"02354386":23,"02355756":[],"02358547":[],"02361665":[],"02365049":[6,31],"02374496":[],"02386932":[],"0239126":34,"02391906":[],"024":[],"024011020121022356":[],"02404706":[],"0241039":[],"02413786":21,"02424794":32,"02432309":[],"02441422":[],"02446604":34,"02447063e":[],"0245528":[6,31],"02456":34,"02459084":34,"02472936":[],"02474828":[],"024792624800382218":5,"02492265":5,"02496085":34,"02498282":35,"02498832":[6,31],"02500488":[],"02502325":[],"02503392":[],"02503753":[6,31],"02511518":6,"02519009":21,"02521917":[],"02522069":6,"02527621":[],"0253208":[],"02540212":[],"02544154":[],"02545":34,"02546675":32,"0255141":21,"02552966":23,"02557617":34,"02564828":[],"02566356":[],"025709":[11,30],"02572685":[],"02576358":[],"02576685":[],"02584233":[],"02586427":[6,31],"02594314":[],"02601643":[],"0260906":[6,31],"02612988e":30,"02616812":34,"02622039":[],"0262517":[],"02625193":8,"02629144":34,"0263106":[],"02631942":[],"02632742":[],"02636268":35,"02649469":[],"026495":[],"02651857":[],"02654585":[],"02660572763718093":[6,32],"026605727637180936":[6,32],"02664408":[],"02693015":[],"02693858":31,"02707227":5,"02723445":[6,31],"02731808":21,"02732402":[],"02735547":34,"02754248":[],"027609773491022525":[6,32],"02760977349102253":[6,32],"02766946":21,"02769274":[],"02780107":[],"02784266":[],"02787184":[],"02797154":[],"0279886":34,"02806268":[],"02808229":[],"02809972":[],"02813369":35,"02850506e":30,"02857":4,"02859759":[],"028638258927275215":[],"02876848":[],"02895918":31,"02900153e":34,"029003":[],"02901273e":30,"02909574":[],"02920675":[],"02923006":[],"0292555":21,"02925855":34,"02928194":[],"02930753":21,"02944152":[],"02946852":[],"029483":5,"02962583":21,"02963147":35,"02965159":[],"02970225":21,"029733":30,"02973733":[],"02976145":[6,31],"02980537":[],"02993573":34,"02994311":5,"02f":[6,24],"03":[1,6,30,31,36],"03000689":21,"03015288036252618":[],"03016341":[],"03032441e":[6,31],"03033791":[],"0303586629618948":[],"03057995":[],"030645975175292262":[],"03076019":[],"03077640549":4,"03099776":5,"031":[5,31,32],"03115122":[],"0311613":[],"03119062":[],"03158013":[],"0316146":[],"03166546":35,"0317606":[],"03177331":23,"03196357":[6,31],"03201179e":[],"03201217":[],"03201832":34,"03205795":[],"03206757":[],"03212854":21,"032142":[],"03214247":[],"03214829":[],"0321956":11,"032196":11,"03239393":[],"03244944":[],"03247316":[],"03251863":5,"03254179":21,"03256632e":[1,36],"03261373":[],"03267527":[6,31],"03274273":[],"03279636":[6,31],"03285784":[],"0328643":34,"0330308045183194":[6,31],"0330308045187757":[6,31],"03306538":34,"03308408":5,"03309191e":30,"03311432":[],"03313259e":30,"03317599":[],"03318519":35,"0332335":26,"033233504714921":26,"03358833":[],"03361037":[],"03365012":[],"033657685071527665":[6,32],"0337609":[],"03382942":29,"03396658":[],"034":[],"03400724e":30,"03404758":[],"034048":[],"03409194":[],"0342028":[],"0342458":34,"03447512":[6,31],"034476":11,"03447649":11,"034557":30,"03455885":[],"03476611e":30,"03479236":[],"03484266":21,"03511387":[],"03529083":21,"03529801":[],"03538463":[],"03538673e":30,"03558034":[],"03559176":35,"03562355":[6,31],"03568439":[6,31],"03573214":[],"03578526":[],"0359565":5,"03596557":[],"03624411":[],"0362483569261072":[],"03630548":[6,31],"03642173":[],"03648711":[],"036527092051294":[],"03662823":34,"03664879":[],"03680811":35,"03681479262838276":[],"0369544130635358":[],"03701105":[],"03703391":[],"03707133":11,"03778607":21,"037813671417389005":[6,32],"03781367141738902":[6,32],"03796359":[],"03796582":[],"03798785":[],"03814292":[6,31],"03815288":[6,31],"0382721":21,"038300":[11,30],"03837":34,"03844073":[],"03846169":31,"03853213":[],"03853268":[],"03853313":[],"03868372":[],"03872795610436844":[],"03873507":[],"03887801":[],"039039":5,"03916813":[],"0394226":[],"03948301":[],"03960002":[],"03973359":[],"039764":35,"03976851":34,"03979291":[],"0398603":35,"039967668952797":[6,31],"0399676689527975":[6,31],"04":[1,6,11,30,31,36],"04000457":21,"040102":5,"04010697":[6,31],"04018043":35,"04018985":[],"04033524":21,"04038595":[],"04046513":[],"04061345":[],"04063602":[6,31],"040684":[],"04072235":[],"04073097":[],"0408223":[],"0409646":[],"04097813":21,"041":[6,9],"04101344":[],"04108038":34,"04110474":[],"0411487294305088":[6,31],"0411487294305226":[6,31],"04150522":21,"04158557":[],"04161572":[],"04191323":[],"04193203":30,"042060":[],"04206048":[],"042136":[],"04216532":[],"0422":[],"04220758":[6,31],"04224929":[],"04238763":[],"04262217":[],"04293545":[],"04295726":35,"04295757":32,"043":9,"043072":[],"04307275":26,"04315108":5,"04315855":[],"04323936e":[],"04330558":[],"04330907":[],"04346721":5,"04353549":[],"04355062":[],"04355837":[6,31],"04362":9,"043637":[],"04369752":[],"0437499":2,"043839":[],"04389027":[6,31],"044014":[],"04401421":[],"04413243":[],"04421197":35,"04423486":[6,31],"04426744e":30,"044334":30,"04443985":21,"044613":[6,31],"04487298":[],"0449":[],"04495752":[],"04501146":21,"04504728e":30,"045161":[],"045258":[],"04532405":[],"04537385":[6,31],"04543942":[6,31],"045630":[],"04564589":[],"04566964":[6,31],"0458":9,"04588592":[],"045963":[],"0462999":[],"04640695":35,"04641529":[],"04646338":[],"04648335":5,"04652794":[],"04657426":[],"04664255":6,"046663":[],"046678":[],"046764":[],"04683565":5,"04688012":[],"04719868":[],"047299":[],"0473916":[],"047447724189861":[],"0474753":34,"047489":[],"04757138":23,"047760":[],"04776242":35,"04784395":[6,31],"04794409":[],"048020":[],"04808723":[],"0481872773043029":[6,32],"048194":21,"04832356":[],"04838148":[],"04852743":[],"04877931":[],"048781":[],"0488139":21,"04892055":[6,31],"04899367":[],"049060":[],"04909093":[6,31],"04912436":6,"049196":[],"04922273":[],"04926746":32,"049276":[],"04933083":[],"049380":[],"04939861":[],"049479":[],"049481":[],"049556996627824":[6,31],"0495569966278269":[6,31],"04955942":[],"04963309":[],"049677":[],"04984743":[],"05":[1,4,6,24,30,31,34,35,36],"050015":[],"05002471":[],"05005634426334421":[],"05006037":[],"05009826":[6,31],"05013368":35,"05029018":[],"05029453":[],"050315327923114654":29,"05034088e":30,"05040878":[],"05045":[],"05054319":30,"05060379":[],"05068486":[],"050796":[],"05087018":[],"05098714":[],"05100875":[6,31],"051021":[],"051042":[],"05135047":34,"051368":[],"05141614":[],"051418":5,"05144177":[],"051554":[],"05159088":[],"051598":35,"051645":[],"051649":[11,30],"0517473":5,"05176711":[],"051787":[],"052010":11,"05201041":11,"05224117":[],"0522653":21,"052279218012056844":[6,32],"05227921801205686":[6,32],"052305":30,"05233008":[],"052370":[],"05240397":[],"052427":[],"0524497":30,"0525733":[],"05263":9,"052692":[],"052738":[],"052856":[],"05293756":21,"05296475":23,"05302":9,"053036":[],"05336637":[],"053387":[],"053417":30,"053462":[],"05347795":[],"053599":[],"05364854":8,"053787":[],"05383795":[6,31],"05383947":[],"053849":5,"053854":[],"05395761":[],"05401912":[],"05415968":35,"054197":[],"054286":[],"054434":[],"05447415":[6,31],"054609":[],"054617":30,"054655":30,"05484773":[],"054932":[],"055000":[],"05505310046363":2,"055091049054481":[],"05509105":[],"05519999":31,"05533":9,"055477":[],"05549529":[],"05563358":[],"055653":[],"055676":30,"055734":30,"055737":[],"05574159":35,"05577845931438246":[],"055876":[],"055910":30,"055987":30,"056026":[],"056041":[],"0560663":[],"05614483":5,"0562":32,"05623":9,"056287":[],"056328":[],"05641352":[],"056414":[],"05648":9,"05651951":[6,31],"05665429e":30,"05667":9,"05668052":21,"056683":30,"056717":[],"056826":[],"056856":[],"05716368155342608":[6,32],"057216":[],"057287":[],"057300":30,"057316":[],"05737289":[],"057387":[],"057393":30,"057418":30,"057420":[],"057457":30,"05747369":[],"057514":[],"057607":[],"057609":[],"057722":30,"057835":30,"05785343":[6,31],"05788748":[],"05789007":[6,31],"057913350391706":[],"057929":[],"05792927":[],"057951":[],"057961":[],"05796251":[6,31],"057964":[],"05804539":[],"05804744e":34,"05807125":[6,31],"058133":[],"058152":[],"058234":[],"058245":[],"058254":[],"05831017":[],"058361":[],"058422":[],"058427":[],"05850899":35,"058552":30,"058582":[],"058593":[],"058641":[],"058645":30,"0586484":34,"05867956":[],"058721":[],"058770":[],"05883":9,"05884":9,"058854":30,"05888195":[],"058952":30,"058967":[],"058970":[],"058996":30,"058997":[],"059031":30,"05914563":[],"059181":21,"059201":[],"059243":[],"059340":[],"05941988e":35,"059624":[],"059669":[],"059761":11,"05978512":[],"059807":30,"059876":[],"059951":30,"059956":11,"05996":34,"059977":[],"05999":9,"059992":[],"059993":30,"06":[6,30,31,34,35],"060071":[],"060083":30,"060085":[],"060087":[],"060171":[],"06020264":[],"06020587":[6,31],"06021793":35,"060251":[],"060254":30,"060275":11,"060288":[],"060312":[],"06043581":[6,31],"060453":[],"060470":[],"060471":[],"060475":[],"0604888":[],"060490":[],"060547":[],"060629":[],"060631":[],"060652":[],"0606958":[],"060716":30,"06072":34,"060726":11,"060734":[],"060735":[],"060756":30,"060870":[],"060872":30,"060898":[],"060994":[],"061025":[],"06110658":[],"061154":[],"061163":30,"061284":[],"061319":11,"061359":30,"061386":[],"061443":30,"061452":30,"06146873":21,"06155151":[],"061588":[],"061614":30,"061637":[],"061656":[],"061706":[],"061724":[],"061848":[],"061862":[],"061898":11,"061921":[],"06199119":[],"06200174":5,"062016":30,"062053":[],"062058":[],"06208238634231949":[6,32],"06210358":[],"062161":[],"06216141":[],"062173":[],"062199":[],"062216":5,"062231":[],"062260":[],"062263":[],"062282":[],"062292565":4,"062300":[],"062337":30,"062356":[],"062429":[],"062520":11,"062599":30,"06260611":[],"062616":[],"062624":30,"06263176":[],"062637":[],"062691":[],"062700":[],"06277313":[],"062797":[],"062853":[],"062874":30,"06287939":[],"062932":[],"063017":[],"063019":30,"063048":[],"063061":30,"063064":[],"063080":30,"063130":11,"063133":[],"063161":11,"063163":[],"063197":11,"063206":11,"06320757":35,"063260":30,"063294":11,"063332":11,"063354":[],"063395":11,"063518":[],"063525":[],"063526":[],"063536":5,"063545":[],"063549":[],"063560":[],"063637":[],"063653":30,"063673":[],"0637712":[],"063781":[],"063786":5,"063791":[],"063802":[],"0638484":34,"063862":[],"063894":30,"06392846":[],"063933":11,"063954":[],"06395476":[],"063959":[],"063977":[],"063995":[],"064000":[],"064074":30,"064077":[],"06410638":[],"064107":[],"06416459":[],"064166":[],"06418809":34,"064189":11,"064202":[],"064218":[],"064294":[],"06430789":[],"06432267":[],"064382":[],"064427":[],"064428":[],"06444":9,"06444224":[],"064501":30,"064505":[],"064507":[],"06453579006728324":[6,32],"064547":[],"064573":[],"064604":[],"064606":[5,30],"064609":30,"064615":[],"064668":[],"064690":[],"064695":[],"064699":30,"064728":11,"064739":[],"064793":30,"064820":[],"064834":[],"064873":[],"064878":[],"06491736":[6,31],"064978":[],"065001":[],"065007":[],"065028":[],"06505375":35,"065062":[],"065077":30,"065096":11,"065108":[],"065121":5,"065149":[],"065212":[],"065217":11,"065352":[],"065358":[],"06536971":[],"065378":30,"065390":30,"065410":30,"06547790180152355":[6,32],"06547790180152359":[6,32],"065482":[],"065556":[],"065616":[],"065619":5,"065654":5,"065679":[],"065788":[],"065818":[],"065821":5,"065830":[],"06590458":[],"065949":[],"065963":[],"06603447":[],"066054":11,"066059":5,"066066":30,"066127":5,"066145":5,"066153":[],"066199":5,"066205":5,"06622369":[],"066256":[],"066286":11,"066358":5,"0663596":[],"06637":9,"066425":5,"066458":[],"066474":30,"066500":30,"06659997":[],"066612":30,"06662069e":[],"06662675":[],"066633":[],"066647":30,"066653":[],"0666807":2,"066686":11,"06674611e":[],"066763":[],"066766":5,"06677444e":[],"066778":5,"066787":30,"066824":[],"066837":[11,30],"066838":[],"06684886":[],"06685171":[],"066854":30,"066855":[],"066865":[],"06690071":[],"066912":5,"066948":5,"066988":11,"066997":[],"066999":30,"067000":5,"067003":[],"067074":[],"067141":[],"067164":[],"067168":[],"06724062":5,"067270675787016":[34,35],"067367":[],"067374":11,"067380":[],"067400":11,"067431":11,"067511":11,"067515":5,"067539":5,"067637":30,"067671":[],"067707":30,"067764":[],"06777772":[],"067793":[],"067809":[],"067843":11,"067922":11,"067948":[],"067967":[],"067974":11,"06804775":[],"06808421":23,"068116":[],"068206":[],"068215":11,"068264":30,"068268":[],"06828347":35,"068307":30,"068353":5,"068360":[],"068369":[],"068394":11,"068408":[],"068441":30,"06844519414009445":[6,32],"06844519414009446":[6,32],"068446":[],"06849372":[],"068494":[],"068504":[],"068512":5,"068533":[],"068539":11,"068587":11,"068592":[],"068607":[],"068629":30,"068680":[],"068684":[],"068727":30,"068758":[],"068775":11,"068827":11,"068843":11,"068897":[],"068903":[],"068906":30,"068912":[],"068924":11,"068967":[],"068977":11,"068985":11,"06901081":[],"069028":30,"069045":11,"069129":11,"069179":[],"069203":5,"06926192":29,"069270":11,"069293":5,"069317":[],"069320":11,"069322":[],"069399":[],"06942115e":[],"0694226":[],"069427":[],"069439":[],"069452":30,"069484":[],"069486":[],"069584":30,"06970419":[],"069802":[],"069811":11,"06984502":[],"069866":5,"069873":[],"069885":[],"069907":5,"0699274":26,"069978":[],"069979":[],"07":[6,30,31,34],"070024":11,"070027":11,"070043":30,"07006502":[],"070095":[],"070098":11,"070135":5,"070146":30,"070150":[],"07016":9,"07017":9,"070183":11,"070213":30,"070274":11,"070275":11,"07027791":35,"07039":9,"070432":[],"070441":[],"070457":30,"070462":[],"070514":[],"070531":5,"070547":11,"070552":5,"070556":[],"070558":[],"070582":30,"070600":[],"070605":5,"070622":5,"07062318":[6,31],"070630":[],"070655":5,"070696":11,"070712":5,"070737":30,"070772":11,"070780":5,"070805":5,"07084394":[],"070855":5,"070859":[],"070886":[],"070889":[11,30],"070891":[],"070898":[],"070916":11,"070918":11,"070950":[],"070980":[],"070986":30,"071049":5,"071055":11,"07106891":[],"071103":[],"07115":9,"071173":5,"071186":11,"071191":11,"071208":[],"07123177":[],"071252":[],"071279":[],"071291":[],"071294":5,"0713":[0,29],"071314":[],"071356":[],"071379":11,"071433":[],"071436":5,"071437":5,"071449":[],"07145103":11,"07147935":[],"071530":[],"071560":5,"071572":[],"071578":[],"071580":11,"07160048164233102":[6,32],"07160048164233104":[6,32],"071608":[],"071638":5,"071643":11,"071655":[],"071656":11,"071680":5,"071758":[],"071803":[],"071831":[],"0718316":34,"071868":[],"071921":[],"071935":[],"071937":[],"072000":30,"072015":5,"072031":5,"072037":5,"072092":[],"072111":30,"072132":[11,30],"072147":[],"07218473624441492":23,"072200":11,"072209":[],"072286":[],"072290639572326":26,"07229064":26,"072304":[],"072344":[],"072380":5,"07241855":[],"072476":30,"072500":[],"0725872":[],"072590":[],"072591":5,"072621":30,"072638":[],"072684":[],"072689":[],"072697":[],"072728":[],"072752":[],"072817":[],"072824":11,"072826":5,"072843":[],"072849":5,"07285":3,"072863":[],"072947":11,"072961":5,"072997":5,"073048":[],"073102":[],"073109":[],"073253":[],"073258":11,"073262":11,"073288":[],"07332248":[],"073339":[],"073405":[],"073408":[],"073415":[],"073422":[],"073499":[],"073514":5,"073528":11,"073576975500551":26,"073598":[11,30],"073612":5,"073644":30,"073647":11,"073672":[],"073685":[],"07373479":[],"07376699":35,"07378525":[],"073791":[],"073800":5,"073858":[],"073866":[],"073882":11,"073911":5,"073923":[],"07405556":[],"074067":[11,30],"074084":30,"074112":[],"074114":[],"074115":11,"074130":[],"074210":30,"07421084":5,"074221":[],"07429886e":[],"074323":30,"074368":[],"074374":5,"074417":[],"074454":5,"0744881":[],"074531":[],"074561":11,"07456491":5,"07469645":[],"074807":[],"074824":[],"074859":[],"074892":[],"07490892":[6,31],"074971":[],"07517385":35,"075176":[],"075177":[],"075198":[],"075239":5,"075289":5,"075298":[],"075302":11,"07531349":[],"075356":[],"075385":[],"075392":[],"075463":[],"075513":11,"075522":[],"07555537":[],"075557":[],"075602":[],"075615":[],"075771":[],"075794":[],"075816":30,"075822":[],"075842":5,"075876":5,"075885":26,"075889":30,"075909":[],"0759216":35,"075956":[],"07597049":[],"075978":5,"07600369":[],"076066":5,"076071":5,"076091":[],"076138":[],"076150":30,"076161":[],"076167":[],"076232":5,"076244":[],"076259":[],"076321":5,"076333":[],"076351":[],"076389":[],"076393":[],"076396":[],"076418":[],"07641937":32,"076434":11,"076435":[],"076436":[],"076448":5,"076459":[],"076479":11,"0764924":[6,31],"076508":11,"076542":[],"076618":[],"076638":[],"076648":11,"076679":11,"07668538":[],"076693":[],"076776262573027":[],"07678":9,"076833":[],"076857":[],"076859":[],"0768805855280187":[],"07692307692307693":9,"076934":[],"076938":[11,30],"076947":11,"076968":[],"077035":5,"07712197e":[],"077141":[],"077168":30,"077226":[],"077248":[],"077280":5,"077301":[],"077304":[],"077329":[],"077341":[],"077382":[],"077391":5,"07740964":26,"077411":[],"07745579":23,"077460":30,"077485":11,"077486":[],"077516":[],"077529":[],"077539":[],"077553":[],"077567":[],"077601":11,"077613":[],"077653":[],"0776532":[],"077683":[],"077736":[],"077745":11,"07776381":11,"077764":11,"07777777777777778":[1,36],"077813":11,"077839":11,"077906":[],"077941":[],"077965":[],"078035":[],"078044":11,"078071":[],"07808426989543932":[],"078110":30,"078118":[],"078123":11,"078146":11,"07820":9,"078210":[],"078238":[],"078268":11,"078282":[],"078284":[],"078313":[],"078324":[],"078336":30,"078359":5,"078363":[],"078386":[],"078447":[],"078540":30,"078541":11,"078544":[],"078557":[],"078573":11,"078588":[],"078636":[],"07864":9,"078684":[],"078688":11,"07871":9,"078731":[],"07890044":[],"078945":5,"078974":30,"078981":[],"078986":30,"079002":5,"079027":[],"079030":5,"079074":[],"079089":[],"079107":11,"07911268":[],"079174":11,"07919041":[],"079202":11,"079240":5,"079334":[],"079347":[],"079391":[],"079420":[],"07944154":[23,29],"079444":[],"07950356694388497":[],"079510":[],"079670":5,"0796891867672603":[6,32],"07969087":35,"079739":[],"079747":11,"07974741":[],"07978850553011713":[],"079887":[],"079903":[],"079946":30,"079947":[],"079953":[],"079959":[],"079976":5,"079977":[],"07998756":[],"079989":[],"079998":[],"08":[9,26,30,34,35],"080082":[],"080094":5,"080171":[],"080205":[],"080222":[],"08023512":34,"080316":[],"08032505":[],"080345":11,"08043851":5,"080453":[],"080549":5,"080555":[],"080616":30,"080630":[],"080657":[],"080702":[],"080706":5,"080747":[],"080764":30,"080832":[],"080903":[],"080947":[],"080987":[],"081038":[],"081103":[],"081195":[],"081217":5,"081221":[],"081235":[],"081252":[],"081276":30,"08131003":6,"0813156":[],"081431":[],"081457":[],"081494":[],"081527":5,"08153923":[],"081544":[],"08156108":[6,31],"08165104":30,"081655":30,"081686":5,"081728":[],"08179906":[],"081835":[],"081871":[],"081955":[],"081978":[],"0820185":35,"082115":[],"082126":[],"082170":[],"082173":[],"082174":[],"08227057":[],"08227668":[],"082303":[],"08233627":[],"082464":[],"082482":[],"08251519":[6,31],"082518":[],"082519":[],"082533":5,"082653":30,"08266769":29,"082742":5,"082764":[],"082784":11,"082785":[],"08280012":[],"082803":[],"082857":[],"082971":[],"08299273e":[6,31],"083016":11,"083119":[],"0831367":[],"083179":5,"083182":[],"08318298e":[1,36],"083248":[],"083259":[],"083260":11,"083268":5,"083288":[],"08333333333333333":9,"083342":11,"08336233266":4,"083446":[],"083465":[],"083471":[],"083479":[],"083499":[],"083501":[],"083527":30,"083547":11,"083548":5,"083564":[],"083734":[],"083765":[],"08376632":[6,30,31],"083766322923899":[6,30,31],"0837663229239043":[6,30,31],"083793":[],"083864":[],"083900":[],"08398399377155011":9,"084018":[],"084042":[],"084076":30,"084091":[],"084122":[],"08418956":[],"084218":11,"08421808":11,"084255":[],"08426840630693411":[6,32],"08426840630693413":[6,32],"084312":11,"084319":[],"084358":[],"084376":[],"084406":[],"084434":[],"084514":[],"08455":9,"08458591":29,"084619":[],"084637":[],"084695":[],"084702":[],"084712":[],"08474":9,"084809":30,"084910":[],"084915":[],"084963":5,"084967":[],"084996":[],"085079":[],"085120":[],"085139":[],"085145":5,"085222":[],"085294":[],"085353":[],"08536248571780691":5,"085390":[],"08539155":34,"085392":[],"08539583":[],"085436":[],"085455":[],"08551306":[6,31],"085518":[],"085548":[],"085592":[],"08576932":6,"085853":5,"08587209":35,"085918":[],"08593216":[6,31],"085973":[],"085996":[],"086026":[],"086068":5,"08609047":35,"086095":[],"086096":[],"08611111111111111":[1,36],"086125":[],"086212":[],"08622478":[],"086230":[],"086239":5,"08624193":[],"086250":[],"086286":[],"086318":[],"086346":[],"086364":[],"086428":[],"086483":5,"08660891":[],"08667591":[],"086694":[],"086712":[],"086730":[],"086799":[],"086808":[],"086809":[],"08687303":34,"08690":9,"08690184845323":11,"086913":[],"086970":[],"08699295e":[],"08702578":[],"087210":[],"087424":[],"087429":5,"08747795":[],"0875061":[],"08758":9,"08758013":[],"087864":[],"087871":5,"08793554992813543":[],"087988":[],"088023":[],"088029":[],"088030":[],"088038":[],"088102":[],"088127":[],"0881981":5,"088199":[],"08824304e":[],"08826182458028335":[],"08826256":[],"088375":[],"08839544":[],"088574":[],"08860502":35,"088651":[],"08871404":5,"08881497884574564":30,"08888888888888889":[1,36],"088970":[],"08902":9,"08931169286872433":[],"08935132374099551":[],"089376":[],"0894015":[],"089404":[],"08946029":[],"0895043":[],"0895387":30,"089539":30,"089548":[],"089578":[],"089600":[],"089619":[],"089626":5,"089718":[],"08996":9,"089996":5,"09":[1,30,36],"090033":[],"090038":[],"09007789":[],"09024373":[],"09028702":[],"090439":[],"090440":[],"090468":[],"09048717285916912":23,"090624":[],"09070064":23,"09078672":[],"0907958":[],"090985":[],"091015":[],"091068":[],"091159":[],"09135059e":[],"091362":5,"091365":[],"091388":[],"09156055":[],"09163947":6,"09166666666666666":[1,36],"0917":9,"09171886":[],"091731":[],"092252":[],"092347":[],"092401":[],"09246293455466892":29,"092486":[],"09251":9,"092607":[],"092608577084595":[],"09291556244521161":[],"09291806":[],"092956":5,"092982":[],"09300398":35,"0930438":[],"093094":[],"09346106":[],"093554":[],"09360113":[],"09368":34,"0938492":[],"09397626":[],"09398153":[],"094044":[],"0940821989627646e":[6,31],"0940821989652176e":[6,31],"094099":[],"094254":[],"094362":[],"094439":[],"09444444444444444":[],"09469095":[],"09487358":23,"09515455":[],"09529067":[],"095465":[],"09572047":35,"095805":[],"09590269e":30,"09604976":[],"09609807":5,"09610694":26,"096270":[],"096365":[],"096511363983559":[],"09651792":[],"0973900819831327":26,"09740532e":[],"0974119":23,"09744":9,"09755017":[],"09780":9,"09790216282081063":[],"09791":9,"09808622":[],"09829902":26,"0983565":[],"098414":[],"09846933":[],"09861229":[23,29],"09903804":8,"09913654":[],"09919198949275869":[6,32],"09928714":23,"09951287404314545":[1,36],"0n":[0,29],"0x0006":[3,4,14],"0x1174af160":[],"0x11753f700":35,"0x117715eb0":[],"0x117893340":[],"0x117c17be0":[],"0x11975e550":[],"0x11b160a60":[],"0x11bc3a1f0":35,"0x11f13fb20":34,"0x120cc1b20":[],"0x121cf68e0":[],"0x124b30190":21,"0x124b96d60":21,"0x1273ffac0":[],"0x1279bd460":[],"0x12e13a850":34,"1":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,21,23,25,26,27,28,31,32,33,34,35,36],"10":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,21,23,24,25,26,27,29,30,31,32,33,34,35,36],"100":[0,1,2,3,4,5,6,8,9,10,11,13,14,15,16,17,21,23,26,27,29,30,31,32,33,34,35,36],"1000":[0,1,2,4,5,8,11,13,14,21,22,26,29,30,33,34,35,36],"10000":[2,5,6,10,11,13,26,31,32],"100000":8,"10001":10,"100083":[],"10008326":[],"1000911":[],"1001":[9,26],"1002":26,"10029389":34,"1003":26,"10030":9,"10036694":[],"10041812":31,"1004727":35,"1005":26,"10068448":[],"1007":32,"1007711427354898":[6,32],"1009":26,"10107914":26,"1011":26,"101150":5,"10115017":5,"10116149":[],"101263":[],"1013":26,"1013904243":26,"10141413e":[6,31],"1015":26,"1015491":34,"10158754":[],"1015am":29,"1023":26,"10230":9,"1024":3,"10242458":[],"1026":26,"10261093":[],"1027":26,"10276112":[],"103":[1,36],"1030":26,"1033455":[],"10340":9,"10340733":35,"1037":26,"10378326e":[1,36],"1038":26,"10391807":[6,31],"10398646080125032":[6,32],"10398646080125035":[6,32],"1040":26,"10405456":11,"10426556":35,"10430":9,"104411":30,"1047":26,"10499357":34,"105":31,"10520":9,"10539984":[],"105400":[],"10541723644166373":[],"10555555555555556":[1,36],"10572":32,"10587277":[],"10589577":5,"10595991":[],"10604579e":30,"106095":[11,30],"1064601390492845":26,"10646014":26,"10719554":[],"10719859":[],"10747579":5,"107476":5,"1074792":[],"10754764":[],"1079":32,"10790125813226321":30,"108":[6,9],"1080176":[],"10837392":23,"10854118":35,"10888197":[],"10898643":[],"10908858":[],"10913":6,"10931453":[6,31],"10960":9,"10994958":[],"10th":9,"10x":[0,29],"11":[0,1,2,5,6,7,8,9,10,11,12,13,15,16,21,23,24,25,26,27,28,29,30,31,32,33,34,35],"1100":26,"1101":26,"11022302e":[5,35,36],"11042239":[],"11081083":[],"1108407":[],"111":[1,7,12,33,35,36],"11100":9,"11113486":11,"111135":11,"11131389":21,"11163239":[],"11171148":35,"1118933":23,"11202337":32,"112383":[11,30],"1124":9,"112619":[],"11261935":[],"11265643e":30,"11277166":5,"112772":5,"11382896":31,"11388888888888889":[],"11390":9,"11433693":[],"114384":11,"11438414":11,"11439407":[],"114550":32,"11462415":5,"11482289e":[6,31],"1148541":[],"11507992e":[1,36],"115356":[],"11535632":[],"11547777218872497":[6,32],"11548661":[],"11571507":[],"115822":6,"1158848":[],"11590":9,"11596834":[],"11597515":[],"11620886":21,"11660":9,"11666666666666667":[1,36],"11683558":[],"1169242":[],"11694":24,"117":8,"11715109e":30,"11725761":35,"11744554e":[6,31],"11747908":23,"11780":9,"118":[0,2,7,33],"11822173":[],"11830757":31,"118318":30,"1184":32,"11840":9,"11844773":[],"11868033":[],"11890":9,"11891833e":21,"119":[0,2,7,33],"11922031":[],"11930916":29,"11992194":11,"119922":11,"119936":2,"12":[0,1,2,3,4,5,6,7,8,9,11,12,21,23,26,28,29,30,32,33,34,35,36],"120":[0,2,3,7,33],"1203":9,"1203284":8,"120435":5,"12043521":5,"12044974":30,"120450":30,"12068251":35,"12081773":34,"121":[8,9,10],"12123488":35,"121292":[],"12155483":[],"1215pm":[27,29],"12166797":[],"12182967":[6,31],"122":[2,8,9,10],"12206013":[],"12220276":[],"12222222222222222":[1,36],"12235593":[],"123":2,"12318726e":[6,31],"12329646":[],"12330033":30,"12333649":[6,31],"12363332":23,"123711":6,"12380":9,"12382443":[],"124":[0,29],"12400":9,"1242":8,"124228866018077":[],"124325":[],"12466453":34,"12498355":[],"12536737":34,"12544009":[],"12552073e":[6,31],"12591227":30,"126":9,"12600095":[],"1261":9,"12618549":5,"1265":9,"12667402":35,"127":4,"1271":6,"12733892":[],"12777777777777777":[],"12790":9,"128":[3,4,13,34,35],"12829994e":30,"12846660e":30,"12871842":30,"129012":6,"12922837":[],"12952339":31,"12957454":26,"1297":9,"1298":9,"129963":32,"12it":[],"12pm":[27,29],"13":[0,1,2,5,6,7,9,11,12,18,21,23,26,29,30,32,33,34,35,36],"130":9,"13003291":[6,31],"13024288":[],"13035147135400782":11,"13037395":35,"13040489":26,"13055555555555556":[],"13055762":[],"130694":30,"13069442":30,"131":9,"13107995":[],"13134148011170077":[],"13137881":[],"131379":[],"13152828":[],"13164176":29,"132":9,"13220608e":[6,31],"1325":6,"1326":9,"13260573":[],"1326197715":29,"13280":9,"133":[7,33],"1332":32,"13337992":[],"134":31,"13457622":[],"135":9,"1350":32,"13535942":[6,31],"13564988":29,"136":[0,7,33],"13600596":[],"13607502":[],"13646574":5,"13659941":[],"13661243e":[6,31],"13663125":29,"13675593":[],"136756":[],"13679863":[6,31],"13684661":35,"13699574":[],"136996":[],"137":[0,7,33],"13729154":29,"13738633":[],"13740":9,"137652":[11,30],"138":[0,7,33],"13819592e":30,"13820":34,"13825388":[],"13847167":[],"1385":6,"1385510301651882":[],"13865173":5,"138775":[11,30],"13878649":[],"1388888888888889":[],"13890":9,"13896095":29,"139":[0,7,33],"13911934":26,"13913033":[],"139224":[],"1392559585020426e":[6,31],"139255958997547e":[6,31],"1393548":[],"13956654":[],"13it":[],"14":[0,2,4,5,6,7,8,9,10,11,12,21,23,26,28,30,32,33,34,35,36],"140":[0,2,7,9,33],"14021063":[6,31],"14046224e":[],"14084366":35,"141":[0,2,7,33],"14100":9,"14104212":26,"1412":[21,34,35],"14122256":[],"1416398":[6,31],"14174745":[6,31],"1418":9,"14187173":[],"142":[0,7,9,33],"14213876":[],"1424112":21,"14250":9,"14260706":[],"14277718e":30,"143":[0,2,7,9,33],"14309433":[],"14369927":[],"1437":[1,36],"144":[0,7,33],"14400":9,"1440501043841336":[1,36],"1441031":[],"14437776":[],"14440":9,"14452678":[],"1446729567":4,"145":2,"14523337e":[],"14550854":11,"145509":11,"14568914":31,"14599499":[],"146":2,"14605929":[],"14629156":32,"14638":34,"14643345e":[],"14708":[],"14710":9,"14716":6,"14721582":35,"14722222222222223":[1,36],"147400":[11,30],"147420":[11,30],"147545":6,"1477190177681485":[],"147836":[],"14783612":35,"1479":9,"148":[3,4,14],"14812206":6,"14815202":[],"14824254":[],"14825560e":30,"14828178":23,"14829228":[],"14841322":29,"14880915":34,"1488598":[],"149063":[],"149266":6,"14934258650797513":[],"149353":32,"149388":[],"149433":[],"149466":[],"149483":[],"149904":[],"149921":[],"14g":[6,32],"14it":[],"15":[0,1,2,4,6,7,8,9,12,13,15,16,17,21,26,29,32,33,34,35,36],"150":[3,4,8,9,14],"15005476":5,"150527":[],"15079545":[],"15098090e":[6,31],"151":[3,4,14],"15126318":[],"15130074e":[6,31],"151522":[],"15173932":[],"152":9,"15200":9,"15202654":[],"15215415":35,"152494":6,"1527777777777778":[],"15283463":[],"153":[3,4,14],"153036":30,"15313054":32,"15351626":[],"15361856":[],"15384615384615385":9,"154":[3,4,14],"1547556":[],"15489318":[],"155":[3,4,9,14],"15527976":[],"15546887":[],"15593478":[],"156":[3,4,14],"15605625":[],"15670921":34,"1567286":34,"156956":5,"157":[3,4,14],"15709522":[],"157128":[],"1571284":[],"1575":9,"1575046":[],"15751952":[],"158":9,"15830902":34,"15833751":[],"15847501":21,"1587":9,"1590":9,"15924557e":30,"15951871":34,"15970814":35,"1598058":[],"15990":9,"15991124e":[],"15am":29,"15g":[6,32],"15it":[],"16":[1,2,3,4,5,6,8,9,10,19,21,26,29,30,31,32,34,35,36],"1603":3,"16063661":[],"16111111111111112":[1,36],"16118615":[],"16158074":[],"161581":[],"16172219e":[],"16180248":35,"16188604":[],"16201555":[],"16209264e":[],"16211139":5,"16220":9,"162246":5,"16231451":4,"1625":9,"16257872":35,"1628":9,"16292908":23,"16304863":30,"163049":30,"1630775253":[1,36],"16312434e":[],"16342407":5,"16343471":[6,31],"1636508":[],"16384":3,"16407038":29,"16411163":[],"164112":[],"16413938":21,"16431956":[],"16437294":35,"16445858":[],"16469725":[],"16486151":[],"16500":9,"165272":[],"16532977":[],"16535252":29,"16567361":[],"166":9,"16617445":[],"1664372":[],"166540":[],"16654048":[],"16710567":29,"16744759":[],"16777789":23,"167787":5,"16791183":23,"168":9,"16805821e":[6,31],"16879134":[],"17":[1,2,5,6,7,8,9,13,21,23,26,30,32,33,34,35,36],"17021424":26,"1709":9,"171":31,"171525":30,"1715252":30,"17168028":[],"17174962e":[1,36],"17214545":23,"17222222222222222":[],"17253354":35,"1726":9,"17260271":[],"17272182":26,"173":[21,35],"17300":9,"1731":9,"1732863504708044":[],"17359583e":[],"17367225":[],"17377547":[],"17405911e":[],"17446471":6,"17483760":32,"175":32,"1752":9,"175300":30,"17547294e":[],"17563274":[],"17567503":[],"17641709":[6,31],"17643975e":30,"17669259":[],"176762":[],"17676247":[],"1767857":29,"17739525":29,"17748881e":34,"17757295":35,"17777777777777778":[1,36],"17801022":5,"17801827":[],"17827738":[],"17834506e":[],"17856374":[],"17861098":6,"17861414":[],"17869861e":30,"179":[],"17913653":[],"17917768":5,"1793417":[],"17934801":[],"17949575":5,"17953942":11,"17968231":[],"1797":[1,3,36],"18":[2,6,7,8,9,10,13,21,26,32,33,34,35],"180":2,"1801709":31,"18019623e":[],"18029127":5,"18043393":26,"1807":4,"1808228":34,"18085537":[],"1809":9,"18093549":34,"18094575":[],"181":9,"1810415856976313":[],"18118338":[],"1812":9,"18120973":[],"181210":[],"18147009":[],"181766185664273":[],"182086698929565":[],"1821":9,"18234308":[],"18277213":[],"18285689e":[],"18307821":31,"18333333333333332":[],"18383522":30,"18388":6,"184":9,"1840":32,"18409254":[],"18418938":[],"184519":30,"18485685":[],"184866696796263":[],"18497496":11,"184975":11,"185":31,"18501900e":30,"18510775":[],"1860":9,"18611111111111112":[],"18613217e":[6,31],"1863889":35,"18660":9,"18670072e":30,"18673098":11,"18702469":23,"18711407":[],"18742521":[],"18816387":[],"18824338":[],"18840034e":[],"18925625":[],"189496":30,"18956157":[],"189622":30,"19":[2,6,9,15,21,26,29,32,34,35],"19009085621304586":[],"190529":[],"19052935":[],"19069576e":34,"19126179":[],"19166666666666668":[1,36],"191833":35,"192":32,"19207979":5,"19220":9,"19299283":[],"1940":0,"194042826649355e":[6,31],"194042826815211e":[6,31],"1943":[12,35,36],"19433318":[],"1944":6,"19547923":[],"19559737e":30,"1956":9,"19569961":[6,30,31],"19583547":[],"19588651":34,"19661197":34,"19677112":[],"1970":[23,29],"1973":9,"197370":[11,30],"19740":9,"1979":[6,32],"19791352":[],"197914":[],"19800":9,"19849513":29,"19852045":[],"1_1":[12,35,36],"1_2":[12,35,36],"1_3":[12,35,36],"1cm":[0,8,10,26,29],"1d":[1,2,3,36],"1e":[1,2,4,13,14,21,34,35,36],"1e10":14,"1e4":6,"1f":1,"1k":23,"1n":[0,29],"1x":[0,29],"2":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,21,22,23,24,25,26,28,32,33,34,35,36],"20":[0,1,2,6,7,8,9,13,19,21,26,27,29,31,32,33,34,35,36],"200":[0,2,3,4,8,9,10],"2000":[0,30],"20015436":6,"2004":[13,33],"20051449":[],"2006":28,"2008":29,"2010":1,"2011":[1,36],"20135691":35,"2014":4,"2015":1,"20158083":5,"201581":5,"2016":[0,29],"2018":[0,6,30,32],"2019":[8,9],"2021":[6,14,30,31,33],"20218457":[],"2022":29,"20228273":[],"2023":24,"2024":[15,16,17,18,19,20,21,29,30,31,32,33],"202698":[],"2026985":[],"2027":9,"20277777777777778":[1,36],"20288581":[],"20336784":[],"20347912":[],"20357736":[],"20367355":23,"20375464":[],"20393534":[],"204049":11,"20404927":11,"20480187":[],"204802":[],"20500":9,"20519189":[],"2060":9,"20601797e":30,"20608548e":30,"20651434":[],"206664":5,"20666447":5,"2069":9,"2072382":35,"20728198":[],"207545":[11,30],"20755569":[],"2077068":[],"20775115":[],"20833333333333334":[1,36],"20834188":[],"20867052175034223":[6,32],"20912557":[],"20916295":30,"20980":9,"21":[0,1,2,5,6,7,9,12,13,21,23,29,30,32,33,34,35,36],"210340":[11,30],"21058097":5,"21070843":29,"21093775":6,"211":[],"21130":9,"2116753732":4,"21169159e":[6,31],"21192602e":[],"212":[],"21277816e":30,"213":[],"213103":[11,30],"2131067":23,"21332621":0,"21333766":29,"21344077":[],"213743":[11,30],"21390371e":[],"21392756":21,"21430643e":34,"21444055":26,"21517262":6,"21531156":[],"21565007e":30,"21596432":6,"2160073466353432":[],"216290":[11,30],"21631786":29,"21655059e":30,"216683":[11,30],"21680864":[],"21699817":[],"21752693":35,"21805426":[],"21813899e":[],"21817966":[],"21998973":[],"22":[0,1,2,5,6,9,12,13,21,23,29,30,32,34,35,36],"22013655":[],"22044605e":[5,30,35,36],"221":8,"221180":30,"2212296":35,"22128142":[],"2216":9,"221666864828611":[],"22169087":[],"2218":9,"221805":2,"221921":5,"22217237e":30,"22226881":[],"222400":30,"22388052":35,"22467274":32,"225":4,"22528536":[],"2257449":[],"22592946e":[],"226014":[],"22601408":[],"22623421":[],"22667819":[],"22688898":[],"22690428":5,"22755839e":[],"22810365":[],"228104":[],"22842468702219465":[6,32],"2284246870221947":[6,32],"22847924":5,"22849742":[],"22871":34,"22897303":[],"22919456":[],"2293":2,"2294":2,"2296":2,"2297":2,"22977659964799":[],"2297766":[],"22it":6,"23":[1,2,6,9,12,15,20,21,23,29,32,35,36],"23002365e":[6,31],"23076923076923078":9,"23093598e":[],"23139242":[],"23164401":[],"23167717":5,"232435":30,"23262877":[],"23303727":23,"23333333333333334":[],"23344210e":30,"2338675":30,"233868":30,"234":6,"23407025":[],"23423987":[],"234496":5,"23449607":5,"23472994":[],"23481471":29,"23499549":35,"2351":6,"23526911":[],"23528337":32,"235969":[],"23596934":[],"23616967":[],"2364":9,"23663482":23,"2373286546935638":[],"23794815":26,"23847441":[],"239":32,"23950884":[],"2397":9,"23971032":30,"23994188e":[],"24":[0,1,6,9,21,23,29,32,34,35,36],"2401":24,"24032019":[],"24071032":[],"24106503":34,"24140":9,"24159785":30,"2416":9,"24175744e":[6,31],"24185931":35,"2419":9,"24224776e":[],"24225043":[],"24254071":[],"24284399":[],"2430":9,"24344979e":35,"24346138":26,"24369936":[],"24377554":[],"243776":[],"24390":9,"24398826":[],"24433117":[],"24444444444444444":[],"24454968":[],"24485814":34,"24493666":32,"246":2,"24602146":34,"24613581":29,"24640494":34,"24688853":[],"24692014":[],"2475908482537097":[],"24759085":[],"24768421e":34,"24780663":23,"24829908":5,"24856992e":[],"24906604e":[6,31],"24999088":21,"24it":[],"25":[2,3,4,5,6,8,9,11,21,23,24,30,32,34,35,36],"250":[2,4,7,9,33],"25000":0,"25018094":21,"25111821":[],"25185716":31,"251879":30,"252008":5,"25200841":5,"25233253":[],"252333":[],"252436":30,"25337053":[],"25343155":32,"25354173":[],"25386687":35,"253891":[],"25389111":[],"25458506e":[],"2546186":[],"254619":[],"2546817701709956":[],"255":3,"255001":30,"25512598":[],"25555619":[],"256":[2,4],"25617655e":[6,31],"25617658e":[6,31],"25673276":[],"256733":[],"25695398":32,"25705685":[],"2572":9,"25729558":[],"2575":9,"25849623":[],"25879315330607":11,"259153":[11,30],"2597":9,"25970297":[],"25986026":[],"25989189":[],"26":[6,9,16,21,26,32,34,35],"26001134":26,"26048873":[],"26083712":[],"26113912":[],"26124692":6,"26128189":35,"26152075":29,"26254957e":30,"262648":[],"26264849":[],"26281735":34,"26292364":32,"26297455":30,"26301436":5,"26307235":[],"2630723514841553":[],"26321660e":30,"26378176e":[],"26402837":[],"26409315307910025":[6,31],"2640931530791004":[6,31],"26464303e":[],"26479234":[],"2650":9,"265109911":4,"26527089":23,"26536626e":21,"2654":9,"265868":[],"26586817":[],"2662452":[],"26646852":35,"2666905":29,"26680052":[],"266801":[],"26710969":5,"26715191":[],"26775644":[],"26780278":5,"2679757":[],"268":9,"26814548":6,"26817703":[],"26821199":[],"2694078":[],"26995402":30,"27":[0,1,6,20,21,32,35,36],"27065633":31,"27124938":[],"271260217275557":26,"27126022":26,"27182417":[],"27231287":29,"27352535e":[],"27425372":35,"27470622":34,"27482829e":30,"2750":9,"2751616":[],"27597777e":[],"27600259":[],"27602210e":[],"27623637":[],"276263":[11,30],"27633474":[],"27693602e":[35,36],"27698328":35,"27700":9,"27760":9,"2781456":[],"27861634e":[],"27924636":5,"27933134":23,"27it":[],"27n_":26,"28":[1,3,4,6,9,21,32,34,35,36],"28000355":[],"280004":[],"28021598":29,"280464e":[],"280573":5,"280647":[11,30],"28109198":[],"2813829":[],"28164443e":[],"28183460e":[],"28205578e":30,"28225179":21,"2822642":35,"28253033":23,"282727":[11,30],"28276275":[],"28306304e":[],"2830637392":4,"28316949":[],"28336218e":[6,31],"28364423":21,"28390":9,"28391978":30,"28399125":[],"28415767":[],"28443039":32,"28457291":[],"28475098":8,"28496213":29,"28542801":[],"2861":26,"28709718":[],"2871":9,"2873":9,"2876045":[],"28776411":[],"28793787":[],"2882":26,"2885519":[],"2886":26,"2890":[0,29],"28902948":[],"2892":26,"28923":[],"28956161":[],"2895786617507":11,"28it":[],"29":[2,6,9,21,32,34,35],"29015871":[],"29033075e":[],"29100624e":[],"291056":[],"2915":26,"29162184":[],"29167186":5,"29223521":[],"29238145":[],"29253213e":[],"29306584e":30,"2931":29,"29350":34,"29390668":[],"29398019":[],"29491144e":30,"29541992e":[],"29620357":[],"29627774":35,"29633608":[],"29653038":34,"2965315":21,"2968":29,"297648":5,"29764815":5,"2976637":[],"2980":29,"298037":[],"29803738":[],"29822833":[6,31],"29860173":34,"2986082":[],"29861395":[],"29881308":[],"2990":29,"29902518":34,"299748":30,"2_":[12,35,36],"2_1":[12,35,36],"2_2":[12,35,36],"2_3":[12,35,36],"2_i":[12,35,36],"2_m":[6,26,32],"2_t":[13,34,35],"2_x":26,"2b":26,"2c8f433990d1":[34,35],"2cm":8,"2d":[1,3,11,12,22,29,35,36],"2e":[6,32],"2f":[0,7,9,10,11,12,29,30,33,35,36],"2g":2,"2g_i":2,"2k":3,"2m":[6,32],"2n":[0,2,3,29,30],"2nd":[9,35],"2p":26,"2pm":27,"2pt":4,"2x":[0,3,8,13,29,34,35],"2x_ix_jy_iy_j":8,"2x_j":8,"2y_i":10,"2y_j":8,"3":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,21,22,23,24,25,26,27,31,32,33,34,35,36],"30":[0,1,2,4,6,7,9,10,13,16,21,27,30,32,33,34],"300":[21,35,36],"30000":[0,29],"30000613":[],"30005983":[],"30010":9,"300231":5,"30023144":5,"30117681":[],"30119421":8,"30124108":[],"30134885":[],"30141906":[],"30190897":11,"301909":11,"302":32,"30258509":[23,29],"30269539":23,"30283188":31,"303":6,"30306759":34,"30334592e":[],"30387411e":[],"30400113":[],"30442964":30,"30466214e":[6,31],"30493151":35,"30506075e":[],"30607268":34,"30637636":[],"3072":3,"3076923076923077":9,"30787294":6,"30915293":[],"309153":[],"30916402":35,"30916988":[],"309170":[],"30917499e":[],"30940":9,"3096154":[],"30982436":[],"3099":32,"30it":[],"31":[2,12,23,26,35,36],"31008026":[],"310579":30,"3105791":30,"310957":[],"31095745":[],"31160886":[],"31162122":[],"312":31,"31227657e":[],"3123314713548606":[6,32],"31248425":34,"31276579e":[6,31],"31286143":[],"313":31,"313155":11,"31315504":11,"31318084":5,"31363366":[],"31367041":35,"31453949":[],"31457796":5,"314869":[],"31486917":[],"315":[6,31],"31541884":35,"3155":[0,5,6,31,32,33],"31555734196707536":[],"31571995":[],"316":31,"31601423":[],"31664443e":34,"31702609":[],"31718909":11,"31727523":[],"317367":11,"31758645":21,"31812561":21,"31849289":29,"31876431e":[],"31896852":8,"31936237":[],"3194467":[],"31it":[],"32":[2,3,4,6,8,12,13,23,26,34,35,36],"3200":[1,36],"32003025":[],"32007041":35,"320656":[],"32065614":[],"32068736":29,"3207":32,"32084559e":30,"32149601703519115":[6,32],"3214960170351912":[6,32],"3215":9,"323059":5,"32305911":5,"323184775146844":[],"32318478":[],"32393078":[],"324":2,"32419549":[],"3241988":[],"32422234e":[],"3245":2,"32450054":30,"3250":[1,36],"325228546249804":[],"32522855":[],"3260513":[],"32606139":[],"3262":6,"326238":30,"32641434":29,"32651488":[],"32684035":[],"32733949":[],"32799141":35,"3280928":[],"328093":[],"32825214":[],"32906581":[],"32932635":[],"32941912":35,"32it":6,"33":[9,12,23,27,35,36],"33000573":29,"33006628":34,"33025801":[],"33049619":26,"33062878":[],"330629":[],"33066907e":[5,30],"33096549":23,"33107417":[],"331075":21,"33145794":[],"33149531":[],"33166055e":5,"331939":30,"33212971":[],"33217312":26,"33220123":[],"33235647":[],"33266422":[],"333":[7,33],"33477019":35,"33528448":35,"33532886":29,"33596404":[],"33615742":[],"33675308":[],"33734605":23,"33742926":29,"33826500e":[],"3388112":[],"33978889":34,"33it":[],"34":[9,23],"340071371496255":30,"34026086":[],"3403":9,"340782":[11,30],"34114547":5,"34182884":[],"34225662":23,"342680":30,"34271514":[],"34332677":[],"34346829":[],"3436":[0,29],"34367970":6,"3437":[0,29],"34412923":30,"344176915013831":[],"34427423":[],"34483937":[],"34483955":29,"34568909":[],"34569596":5,"34569632":[],"34577375":35,"34598722":23,"34599467e":21,"34599598":[],"346000154268618":23,"34620097":[],"34654596":[],"346546":[],"34661376":[],"346614":[],"34759233":[],"3480527":26,"34871778":[],"34904819":[],"35":[0,6,17,24,27,29,35],"35018806":[],"35098705":[],"35140":9,"3514835":[],"351636":[11,30],"35182854":5,"35196964":[],"35243372":[],"35275513":[],"35320952":[],"35354073":[],"35432563":[],"3544313922":6,"35470445e":[5,30],"35506347e":30,"35520169":[],"35533773":6,"35537114e":[],"35587321":35,"35613536e":30,"356399":30,"356673":[],"35667342":[],"35689303":[],"35714377":[],"35731585":29,"35736":34,"357508":30,"3577615":[],"3581341341":4,"35823372e":35,"35870701":26,"359":[5,31],"35957915":[],"35966688":[],"35980374":29,"35986305":[],"35it":6,"36":[0,5,6,24,26],"360":[1,36],"36091273":[],"3613":9,"361541":5,"36154104":5,"361556":30,"36185989":[],"3621311":5,"36235052e":[],"36303682e":30,"3632959111950474e":[6,31],"363295916366933e":[6,31],"36339156":[],"36353321":29,"36401981":[],"36482524":[],"36545697e":[],"3655222":5,"366375489616074":[],"367":[2,9],"36754671":[],"36880327":23,"36895644":32,"369139":[11,30],"36it":6,"37":[9,24,33,34],"37013105":23,"37055062":[],"37057274":21,"370782966":4,"37093787":[],"37135473":[],"37153115":29,"37175575":34,"37239927e":30,"37255873":[],"3727791":29,"37354121":35,"37396662":[6,31],"37415625e":30,"37449168":23,"37454707":23,"374675":[],"37467515":[],"37507799e":[],"37532078":[],"37582891":[],"375829":[],"37600869":29,"37685349":[],"37700967e":30,"377372":30,"37737221":30,"3777801602":6,"378271":[],"37827145":[],"37837864":[],"37900111":[6,31],"37919989":29,"38":[0,9,24,26],"380":9,"38102552":[],"38135733e":[6,31],"3817475779":[6,32],"38198866":29,"38203725":[],"38259084":34,"38298234e":30,"38337498":[],"38381781":[],"38399622":[],"38440469":[],"38445171":35,"38460453":23,"38461538461538464":9,"38461539":34,"38592549":26,"386":9,"38612299e":30,"386161":[],"38616125":[],"38618024":[],"38629436":[23,29],"387":32,"387620":11,"38762019":11,"3882273":[],"38827994":6,"38865681e":[],"38916861e":[6,31],"3892":32,"38934047":29,"38962192e":[6,31],"38992371":[],"39":[0,9,27,29,35,36],"390334838933238":26,"39033484":26,"39039235":23,"3908470004999506":[],"39090680e":[],"3910042":29,"39197698":30,"391977":30,"39214397":30,"392144":30,"39223923":[],"39279291":29,"3939184e":[],"39398622":[],"394":9,"39517073":[],"39525059":[],"39540235":[],"39579407":5,"395980256477532":[],"39598026":[],"39614949":[],"39621036e":[],"39692815":[],"39706038":5,"397700":[11,30],"39789527":[23,29],"3983":6,"39855569":[],"39865452":[],"39922082":[],"39929428":[],"39931051e":30,"39952356":[],"399836":30,"3d":[2,3,4,6,13,24,32,34],"3f":[1,3,9],"3n":23,"3x":[2,8],"3x_i":2,"3y":8,"3yk470mj5p931p9dtkk0y6jw0000gn":[1,6,29,32,36],"4":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,21,23,24,26,29,31,32,33,34,35,36],"40":[1,6,9,24,27,29,32,36],"400":4,"4000":[9,29],"40037367e":[],"40072098":[],"40093324":[],"40140374":[],"401842":[11,30],"40184681":23,"40266454":[],"40354798e":30,"40415979e":[],"40418675":[],"404783":[],"40478305":[],"405":9,"4050":[28,29],"40558184":[],"405890":[11,30],"405964":[],"40596423":[],"40605118":[],"40620066":30,"406201":30,"40632663":[],"4069157":[],"407":9,"408":9,"40800396":35,"40833375":[],"4087":9,"4087793":5,"40927184e":[6,31],"40it":6,"41":[2,9,23],"4107":9,"41146753":29,"4121966338442804":[],"41229845":35,"41310208":[],"41366128e":[],"41408221":[],"41433969":5,"41487642":29,"41511965e":[1,36],"41532521":35,"4155":[2,15],"4162706317":6,"41636775":[],"41664613":26,"4166666666666667":9,"41675053":[],"41744203":[],"41764479":[],"417644792969273":[],"41820116":23,"41842093e":30,"418506":[11,30],"41869784":29,"41882037e":[6,31],"41925189":[],"41987877":[],"4198932":29,"42":[1,4,8,9,10,23,36],"42083463e":[],"42095725":29,"42124182":[],"4215795":23,"42197297e":[],"42305151":[],"4230769230769231":9,"42310878":26,"423646":[],"42364634":[],"42392359":[],"424274":[],"4242743":[],"42441033":5,"42450":9,"42497724":[],"42553096":[],"42575338":23,"426":[6,9],"42644801":21,"42774546":[],"42793344e":[],"42873361":29,"429":32,"42945319":[],"43":[0,1,7,9,23,33,36],"43054282":5,"4310":29,"433":32,"43330971e":[6,31],"43373107":[],"435163":30,"43563433":23,"43579948e":[6,31],"43639284e":30,"436462435":4,"43703545":[],"43727575":[],"43766686":11,"43779698e":[],"438060758":6,"438136":30,"439230":6,"43962226":[],"43976975777097144":[],"43984553e":[],"43it":6,"44":[0,1,23,36],"44089210e":[5,30],"441":[3,4,14],"442":[3,4,14],"44255455":[],"442600":[11,30],"44286735":[],"443":[3,4,14],"443217":30,"44395301":31,"444":[3,4,9,14],"44418124":34,"44454123":29,"445":[3,4,14],"44536331":29,"44563226":[],"446033":32,"44624525e":30,"44658658e":30,"44767398":21,"4477214":5,"44830934":[],"44838546":[],"44867801":35,"44970586e":[1,36],"44995924":23,"45":[9,27,29],"450":9,"450257":[11,30],"4504":9,"45053025":29,"45193407":[],"45430236":[],"455173":32,"45560415":[],"4557763":11,"455947":30,"456":9,"45620975":[],"457":2,"457311":[],"45731144":[],"45731379":23,"4576811":29,"45781905e":34,"458027":30,"458078":[11,30],"4580854":[],"4591127":23,"45915671e":30,"45960079":5,"45it":6,"46":[2,9,27,29],"460":[9,11],"4601":9,"46065811":23,"46086448":23,"46107913":[],"46134248e":[],"46153846153846156":9,"46170878e":34,"4619526":23,"462":[7,33],"46318204":[],"46342934":[],"4635149":[],"46383925e":[6,31],"46383926e":[6,31],"46387965":[],"46415522":[],"46415888336127775":31,"46544987":[],"46593404":[],"46660941e":[],"46713267":31,"46736215":32,"4676059":30,"467606":30,"46891823":[],"46911594e":[],"46954702e":[],"46963249":[],"46984559":[],"46984697e":[6,31],"47":[2,9,27,29],"47042744":5,"47051432":32,"47052809":[],"470714":30,"47075725":6,"47116868e":[6,31],"47125748":5,"47132891":5,"4725246793626128":[],"4729218":[],"47297587e":[],"47313680":32,"47334547e":[],"4735968":35,"47433659":[],"4745474":[],"47478922e":[],"47610036":6,"4761747":[],"47729832":[],"47757553":[],"47815203":11,"47823856":34,"47892661":[],"47910545":[],"479465113":4,"47989224":[],"47991892":[],"47it":6,"48":[2,9,32],"48004784":29,"48062913":[],"48151166":23,"48170743":[],"481979":6,"48200792":[],"48233952":[],"48257387":[27,29],"48268005e":[],"48306473":[],"48307405":[],"4831139":[],"48326853":[],"48399942":[],"48420061":[],"4843772":29,"48476997":11,"484905":5,"48490503":5,"48494803":31,"48521055":30,"48697869":[],"486979":[],"4870934":[],"48786826e":35,"48826894e":30,"48827791":[],"48843174e":[],"48867802":[],"48900413":[],"48931464":[],"489315":[],"48994188":5,"48it":[],"49":[5,6,9,11,24,30,34,35],"49074536":[],"49123502e":[],"49152":3,"49156266e":[],"49211524":[],"49224801":[],"49285045e":35,"4937346":23,"49381549":[],"49392067e":30,"4940954":[0,29],"49470005":[],"49513019":26,"4951301940723654":26,"49584063e":30,"4959161509357395e":[6,31],"4959161509366685e":[6,31],"49608088":35,"49611541":[],"4990":26,"49910481e":[],"4992":26,"49939493":[],"499394932852416":[],"4997":26,"49it":6,"4c4c7f":[9,10],"4d":3,"4f":6,"4pm":[27,29],"4y":8,"4y_i":10,"5":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,21,23,24,26,29,30,31,32,33,34,35,36],"50":[1,2,3,4,6,7,8,9,10,13,21,29,30,32,33,34,35,36],"500":[1,3,4,6,9,10,13,32,33,34,35,36],"50000000e":[35,36],"50000455":5,"50000553":5,"50000718":5,"50000855":5,"50000969":5,"50001063":5,"50001142":5,"50001207":5,"50001261":5,"50001306":5,"50001343":5,"50001374":5,"500014":5,"50001414":5,"50001422":5,"50001439":5,"50001454":5,"50001466":5,"50001476":5,"50001485":5,"50001492":5,"50001498":5,"50001502":5,"50001506":5,"5000151":5,"50001512":5,"50001515":5,"50001517":5,"50001518":5,"50001519":5,"50001521":5,"50001522":5,"50001523":5,"50001524":5,"50001525":5,"5018":26,"5020612":26,"50227564e":[6,31],"50258788e":21,"502698":[],"50269821":[],"50306335":[],"50321091":5,"50327198":23,"50427787":32,"50482139":[],"50530832":32,"506":0,"50600514e":[],"50610071e":34,"506553":30,"50655336":30,"50667812":[],"50714096e":[],"5076963":23,"507d50":[9,10],"50846111e":[6,31],"50846112e":[6,31],"50850373":[],"50887105":[],"50911289":[],"50it":[],"50j":[13,34],"50x10":[1,36],"51":10,"510":[1,36],"5105332296929628":9,"51069279":23,"51104913":[],"51136852":[],"51154388":[],"5116375":[],"511888":5,"51317506":[],"51364117":23,"51374050":32,"514219":30,"5142856":[],"51437058e":30,"51447004":29,"51512235":[],"51546825":29,"51564682":23,"51611732":35,"51643579":[],"51659846":34,"51709529":[],"51728978":[],"5177783846":4,"51858116":[],"51914183e":[],"51928402":23,"51937727":23,"52":[33,34,35],"52031552e":30,"52087499":[],"521422502348998":11,"521558":[],"52155823":[],"52173381":[],"5222222222222223":[1,36],"52284329e":30,"52301447e":30,"52317963":[],"52362157e":30,"52397611":[],"52446101":26,"5257011":[],"52573336":11,"52635761":23,"52654886":[],"52657934":23,"526744":[11,30],"52698542":[],"52706754":11,"527068":11,"52732966":[],"52780600":32,"52874252":5,"52876551":[],"52888979":[],"52989287e":[],"52it":[],"53":[9,33,34],"5303329":11,"53052247":[],"5305555555555556":[1,36],"53105728":[],"53125507":23,"531280":30,"53149078":[],"532":[],"5321613":[],"53269627e":[],"53285379":[],"532854":[],"533":[],"53312817":29,"534":[],"535":[],"53512750e":[],"53534008":26,"53585173":[],"535852":[],"53629564":23,"53640693":[],"537":[],"53703498":6,"53723188":[],"53729411e":30,"53732988":[],"53738247":32,"5378811":11,"538":[],"5384615384615384":9,"539":[],"539261":[11,30],"53942728":[],"53996947":[],"5399913":[],"53it":6,"54":[6,9,26],"540":9,"54011398":[],"54039921":5,"54041041e":5,"54057582":[],"541605":30,"54175461":34,"5426270409877345":[],"543939":30,"54393936":30,"5443909":[],"544439":30,"54490887":[],"54637219":32,"54725976":[],"54760497":35,"54811237":26,"548263635652985":[],"54843215":[],"548432150659993":[],"54856099":[],"54873252":[],"54880148":[],"54921401":[],"54935794":29,"54it":6,"55":[1,9,36],"55020405":[],"55020649":[],"55042779":[],"551023":5,"55102329":5,"55179339":[],"55196383":[],"55386681":29,"55460327e":[],"55542568":[],"5555555555555556":[1,36],"55582742":29,"5567":6,"55688514":26,"557795":[11,30],"55838":34,"55854694":11,"559791959661649":26,"55996153":[],"55it":[],"56":[1,9,36],"56033697":5,"56042437":[],"56072658":[],"561410":[],"56141009":[],"56198284":5,"56342158":[],"564":9,"56423957":[],"56423957069263":[],"564374":[11,30],"56453869":[],"564759":[],"56475921":[],"56476512e":[],"565":9,"5653087":35,"56536":[0,29],"56541622e":[],"56589683":32,"566":9,"56636616e":[6,31],"567":9,"56763673":[],"56783103":23,"56790195e":30,"568":[9,32],"56804783":[],"56832496e":[],"56857739e":[],"569":[1,9],"56912044e":[6,31],"56922102":29,"56939714":5,"56947078":[],"56965674":32,"56967917":[],"56977352":[],"56it":[],"57":[0,8,9,27,29],"570":9,"571":[5,31],"571105947979344e":[6,31],"571105947979412e":[6,31],"57192197":[],"57201944e":[6,31],"57252451e":30,"57261202":[],"574465":[11,30],"57468142":29,"57492326":[],"57521514":[],"57584612":[],"575870409023631":[],"576":32,"5769230769230769":9,"57803254":29,"57819238e":[],"57847325":[],"57881465":[],"57886743":[],"57914918":[],"57933547":26,"58":[9,10,27,29],"58013829":[],"58084123":[],"5833333333333334":9,"583595":30,"58379362":[],"5847256":[],"58492636e":30,"58493493":[],"58493681":[],"58583003":[],"58589719":29,"58735893":[],"58827236":6,"5888888888888889":[1,36],"58890784":[],"58914105":[],"589841":[],"59":9,"59009792":11,"59078383":[],"590784":[],"591317992":4,"59184268":[],"59215613":[],"59244881":[],"59348521":[],"59354079":6,"59355752e":30,"59372982":23,"594241":[],"59424119":[],"5944444444444444":[1,36],"59465457e":[],"59491404e":[],"59630232e":[],"59683811":[],"59698459":26,"59730078":[],"59779819":34,"59875207":[],"59884169":29,"59908884":[],"59963873":[],"59971727":[],"5cm":26,"5f":[8,34],"5x":8,"5y":8,"6":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,21,23,26,27,29,30,31,32,33,34,35,36],"60":[1,3,6,9],"60000":4,"60026673":[],"60041459e":[],"600529":[],"60052901":[],"60160003e":30,"6019067271":4,"6029291":[],"60293962":5,"60342978":32,"60375434":23,"6038642":[],"60418171":[],"60420593":5,"60451189e":[],"60543038":30,"60552651":[],"60570744":[],"60588173":29,"60605083e":[],"606251":[],"60625144":[],"60664448":[],"60673226":11,"606760":5,"60762863":[],"60921896":[],"60929685":32,"60940356":[],"60943791":[23,29],"60999067":[],"61":[1,36],"61069681":23,"61083596e":[],"61106937e":[],"6111111111111112":[1,36],"61113781":[],"61192203":[],"61192712":23,"612939":30,"61321722e":[],"61325173":[],"613579":30,"61382924":[],"613893902124586":26,"61395701":[],"61414743":23,"61468323":26,"614808":[11,30],"6153846153846154":9,"61564092":[],"6156409232714415":[],"61602014e":[],"61621902":[],"61774362":[],"61775176":32,"618746":[],"61883807":[],"618982":30,"61979664e":[],"62":[1,36],"6200":29,"6201":29,"6202":29,"6203":29,"6204":29,"62113349e":30,"621584":[],"62158409":[],"62242138e":[],"62275788":34,"62286539":[],"62351789":[],"62373464":11,"625":[7,33],"62551462":26,"62573269":29,"62617788":23,"62620041e":[],"626635268":[6,32],"626678":[],"6266783":[],"6267112":[],"62671667":[],"62716271":35,"62725226":31,"628":6,"62863106e":30,"62886648":[],"62894215":5,"62905281e":[],"62908496":23,"62918713":21,"62954328e":21,"63":[0,1,6,9,32,36],"63025821e":[6,31],"63030526":[],"63031478":[],"630315":[],"63037846":6,"63042739":21,"63046054":[],"63071772":[],"63142399":29,"63142731":[],"63162342":30,"63207408":[],"63209435":29,"63249532e":[6,31],"63309898":[],"6333349473431832":26,"63347711":21,"63490568":26,"63498144":5,"63546236":[],"63555267e":[],"63619709":30,"6380763200092493":[],"63833441e":[],"6383903":29,"63896182":[],"638962":[],"6389681":[],"63898112e":30,"63919355":5,"639194":5,"64":[1,2,3,4,13,23,29,34,35,36],"64009263":[],"64012627":5,"6401576":[],"6407249":[],"640x480":[6,13],"64316192":32,"64322974":[],"64361375":29,"64362404":[],"64373221":[],"64373635e":34,"64399916":[],"64411666":[],"64412879":[],"6441397":[],"64425744":[],"64516328":35,"64564368e":[],"646283":[11,30],"64713979":[],"64742912e":[6,31],"647473":[11,30],"64796751":29,"64857542":[],"64885265":23,"649":[],"64909048":[],"649382":[11,30],"64976691":[],"64x50":[1,36],"65":[1,2,8,9,36],"650":[],"65082441":[],"651":2,"65183066":[],"651831":[],"652":2,"65293772":[],"653":2,"6533977":[],"653398":[],"6536392":30,"654":2,"65442354":30,"654424":30,"65475653":[],"655":2,"65543115":[],"65554958":[],"65571174e":30,"65591748":[],"65593984":[],"65599456":30,"656":[],"65641173":[],"6568154596723088":[],"6568686180915178":[],"65686862":[],"65720152e":30,"65738717e":30,"65743689":30,"65759901":[],"658":2,"65833132":30,"65885453":5,"65889641e":[],"65891389":30,"658914":30,"659":2,"65900052e":[],"65917558":23,"65944342":34,"65it":[],"66":2,"660":2,"66018725e":30,"66063786":[],"66064822":30,"66080313":30,"66204648":6,"662836197064178":[],"66289235":[],"66294408":30,"6629598":[],"662960":[],"66365453e":[],"6638":9,"664314":5,"66431407":5,"66456459":[],"66487438":[],"66498292":[],"6652177":30,"66560":9,"6663569":[],"667":9,"6671767":[],"66729685":[],"66757105e":[],"66809369":[],"668172":30,"6690108":[],"66951679":[],"67":[1,2,9,36],"67015946e":[],"6702":[],"67047975e":[6,31],"67088558":[],"67100236":[],"67231298":[],"67238764e":[],"672721":30,"672759":[],"67275915":[],"67313212":[],"67314874e":5,"67374815":23,"674":32,"67435043":26,"67464946":[],"67490857":34,"67495943":[],"67524588":23,"67561021":29,"67819487e":[],"67834752":[],"67875366":[],"678754":[],"67it":[],"68":2,"6801":[],"68072161":23,"6809195":[],"680920":[],"68092237e":[],"68110474":35,"6816947":[],"68192193":5,"68257097":[],"68286725":30,"6831505":[],"68352799":[],"68534263e":[6,31],"68542204":5,"68591105":[],"68637642":[],"68655456":23,"6869":9,"68735473":29,"68822559":[],"688226":[],"68826552":29,"68857788":[],"6887363571":4,"68879472":[],"68929213e":[6,31],"689519":[11,30],"69":[2,9,26],"690":9,"690617":30,"69069n_":26,"69089532":23,"691":[],"691364":[],"69136414":[],"69182892e":30,"69227923":[],"69230769":34,"6923076923076923":9,"69247718":23,"6927554":23,"69303453":[],"693035":[],"69391797":[],"69417174":[],"69435454":[],"69438869":[],"69465386":23,"69484813e":5,"69504801":6,"69515531":[],"69566966":29,"69634577e":[6,31],"69695259":5,"697346":[],"69734609":[],"69756791":[],"69768266":11,"6980":[21,34,35],"6988905":29,"69903406":[],"69983227":[],"6999536":11,"69it":[],"6n_":26,"6pm":29,"7":[0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,21,23,25,26,28,29,30,31,32,33,34,35],"70":[1,6,7,9,33,36],"7002164":26,"70037324e":30,"70039784":[],"701370":5,"70241548":[],"7026722043092946":[],"7029975":[],"70301068":[],"70362677":[],"70469324":29,"70474145":[],"70499955":29,"70514808":[],"70587399":[],"705946":[],"70594608":[],"70630967":[],"70653767":4,"70665448":[],"70704566":[],"7070883":29,"70710678":[5,30],"70711022":[],"7074705":[],"70832814":5,"70857635":[],"7086067479626619":30,"70928399":11,"709284":11,"71":[1,36],"71142161":30,"711422":30,"7119":9,"712018":[11,30],"71261809":[],"7127128":29,"71332117":[],"713763":[],"71376303":[],"71384267e":34,"71441086":[],"71469351":[],"7150195":29,"71505132e":35,"71507714e":[],"71524686":[],"71582784":[],"71737253":30,"71761101":30,"718165":5,"71838601":23,"71860732":[],"7198234":[],"720889407643293":[],"72174172":11,"72236654":[],"72271878e":[6,31],"7228852":[],"72288611":[],"72309979e":[],"7236674":5,"724":3,"72427854":[],"7249499":[],"725256":[],"7252563":[],"726017":[],"72601722":[],"72602818":[],"72710494":29,"72744372":[],"72770687":5,"727707":5,"72771857":[],"72848736":[],"72859758":5,"72952595":[],"72962885":23,"72964493e":[],"72981762":8,"72992196":[],"73":[6,9,32],"73018893":[],"73031999":[],"73062648":[],"73063053":[],"73068535":[],"73071831":26,"731000":30,"73122034":[],"73176319":23,"73203674":[],"73252708":34,"73265885":34,"73305640e":[],"733096":30,"73337355":[],"73578772":[],"73595198":[],"73646130e":[],"73690387":34,"737184":[],"73718419":[],"73741131e":[],"73785069":[],"737851":[],"73853838":[],"73958682":[],"73986200e":30,"73994248":[],"74":[6,32,34,35],"740":9,"74028787e":[],"7403629637766833":11,"74038232":[],"74075864":26,"74081822":8,"74171049":[],"74259663":[],"742597":[],"74272285e":[],"74291603e":30,"74384949":30,"74607851":30,"74613334":[],"74724414e":30,"74724774":34,"74829661":30,"74840212":5,"7487814387207385":[],"74878144":[],"74883972":[],"74900488":5,"74957448":[],"749765":30,"75":[5,6,8,9,11,24,30,32,35,36],"75018686":[],"750187":[],"75025744":[],"750445":30,"75050135":30,"75080943":[],"7509571":[],"7510197":[],"7511273":[],"75131415":[],"75138064":23,"751699":[11,30],"75170092":5,"75216828e":34,"75269037":30,"75300068":[],"7539148284817965":29,"75406226e":[],"75424998":35,"75433448":[],"7546682196464342":[],"75532041":[],"75576555":30,"75600095":[],"756352":30,"75654448":[],"75677341":[],"756828":[],"75682834":[],"75760403":[],"7577":32,"75770568":30,"7577113351177733":[],"75956617":23,"76":[9,27,29,33,34],"76120718":[],"761574":[],"76157429":[],"76190591":31,"76262775":[],"76277254":[],"76329289":21,"7642448":[],"764245":[],"765":[7,33],"76527062":[],"76533281":5,"765333":5,"7658599":[],"76612827":[],"766163196245293":[],"76686148":[],"76690383":32,"76692036e":30,"767367275553824":[],"76790092":[],"76807288":[],"76855921":23,"76887316e":30,"7692307692307693":9,"76936315":5,"76940759":26,"76942272":[],"7694444444444445":[1,36],"76996262e":[],"77":[9,27,29,34,35],"77030637":23,"77106886":35,"771128":[],"77152076":5,"77152924":[],"7718":9,"77199379e":[],"772588722239781":[34,35],"77352152e":[],"77354301":[],"774498":[],"77449804":[],"77465911":[],"77482712":[],"77507653":[],"77559615":[],"77635684e":[],"77636e":[34,35],"77652198e":30,"77659961":26,"7766443":[],"77714169":8,"77725472":[],"777255":[],"77803692":[],"7782028952":4,"77845284":[],"77873845e":[],"77959897":[],"78":[],"78009660e":30,"78010668":35,"78156479e":5,"78184120e":[6,31],"78186404":23,"78254537":[],"78278086":[],"78326199e":[],"78459458":35,"78671736":[],"78745927":[],"78758569":[],"78876155e":[],"78892891":[],"78941903":5,"79":[],"79111643":5,"79135536e":30,"79171202":23,"79247398":[],"79280475":[],"793167":30,"794282":[11,30],"79469098":[],"79503363":21,"7953443":31,"79622905":[],"79623487":5,"796235":5,"79633065":32,"79718864":29,"79778008":6,"79787194":11,"797872":11,"797e":6,"79849321":[],"79866484":[],"79870689e":30,"7989356":29,"79898903":23,"7d7d58":[9,10],"8":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,21,23,24,26,29,30,31,32,33,34,35,36],"80":[0,1,5,6,8,9,30,31,32,36],"800":[4,7,33],"80011603e":[],"80056922":[],"801356":[],"8030191":[],"80354994":6,"80410179":[],"80413696":[],"80460179":32,"80469739":5,"8055555555555556":[1,36],"80576215":35,"80609615e":[6,31],"80609616e":[6,31],"80637385":[],"80740939":29,"80847477e":[6,31],"8084934":23,"80855691":[],"808557":[],"80907609":34,"80979265":[],"81":[1,36],"81007381":29,"81035098":[],"81042619e":30,"81048318e":[6,31],"81160425":5,"81218742e":30,"81246697":26,"81283649":[],"81318307":[],"8133":6,"81333808":6,"81425129e":30,"81479491":[],"81506255":[],"81559586":[],"815am":[27,29],"81622636":[],"81633628":11,"816454":30,"816847":30,"81839897":[],"81889188":35,"81919129":[],"819253":[],"81925302":[],"81931348":35,"81947005":23,"81979166":26,"82":[],"82060913e":30,"8207274870895702":5,"82079885":[],"82121282":[],"82146046":35,"82161167":29,"82198978":5,"82242798":[],"8227":[],"8232102961414203":[],"823417":[],"82341746":[],"82376174e":30,"82418008":[],"82418352":[],"8244":[],"8250103":35,"82533209":11,"82551764":23,"82559478":[],"82623709e":[],"8265786":5,"82688363":[],"82802004":[],"82832579":[],"82914126":[],"829252":[],"82925222":[],"83":2,"83020679":[],"8305555555555556":[],"83146596":32,"83363025":[],"83369175":[],"83463634e":30,"83466807":[],"83512277":5,"83641435":34,"83655756":29,"83718206":[],"83816147":[],"83823317e":30,"83870189":6,"8387133":[],"83884553e":[],"839957":[],"83995705":[],"84":2,"84159992":[],"842":[0,7,33],"8423144":23,"842436":30,"84254917":[],"843":[0,7,33],"84351715":[],"84355903e":[1,36],"844":[0,7,33],"84401886":5,"84443254e":[1,36],"84478178":34,"84605507":[],"8461538461538461":9,"84661230e":[],"84707251e":30,"84711297":[],"84726382":[],"84767088":[],"8476874":[],"84780262":6,"84789579e":[],"8485":32,"84858":32,"84862355":29,"8488":32,"84923989e":[6,31],"84972787":[],"84994524":5,"85":[1,9,36],"85005989":[],"85014487":[],"850164":5,"8505072899794293":[],"85064942":11,"85079059":[],"85108001":[],"85112594":23,"8517571":[],"85222243":[],"85259666e":[],"85263220":6,"85276538":23,"85278920e":5,"85293303e":30,"85378708":[],"85408468e":34,"85422602":[],"85437905":35,"85551266e":30,"85601992":5,"85625134":29,"85703369":[],"85711016":29,"85777073":[],"857771":[],"858":9,"8583333333333333":[],"85866294e":21,"85871255":[],"85945208e":30,"86":2,"86009093":[],"86016288":[],"86062977":6,"86066395":[],"86067818":[],"86117291":5,"86123808e":[],"86134827":5,"86143379":[],"86145244":11,"86174943":[],"86192682e":30,"86197958":[],"86240935":[],"86247117":[],"86267497":[],"862675":[],"86273371":31,"8638888888888889":[1,36],"86416941":[],"86445334":[],"86459987":29,"865":[0,7,33],"86519139":23,"866":[0,7,33],"86602331":[],"86629161":26,"86630":9,"86639832e":35,"86643649":[],"8666666666666667":[1,36],"867":[0,7,33],"86737671":[],"86810":9,"86867512":11,"86891741":[],"8691787":29,"86943859":[],"86978877":[],"87":9,"87020155":[],"8702784034":4,"870337":[],"87068171":31,"87070464":[],"870704644539707":[],"87072815e":30,"87093752":[],"87148597":[],"87169607e":30,"87186187":26,"8720648":26,"8722222222222222":[],"87238538":[],"87340054":[],"87381451":5,"87399194":[],"87473452":[],"87494456e":30,"875":[1,36],"87584434":[],"8759":[34,35],"87627342":32,"87696461":[],"877":6,"87732748":[],"87740526":29,"87788573":[],"87818331":[],"87878356":26,"87884833":[],"87981676":[],"88":[29,34,35],"88046261":5,"8805555555555555":[],"88064505":[],"88135577e":[],"88157423":29,"88168312e":[6,31],"8817842e":[],"88182591":30,"88236598e":[],"8825782":[],"88289263":29,"88323026":30,"88336879":5,"8834":[],"88377332":[],"884669":30,"88501323":[],"88529063e":[6,31],"88551766e":30,"88594444":21,"88613493":30,"88614317":[],"88639567":29,"88653291":29,"88738394e":[],"88809826":29,"88860399":26,"8888888888888888":[],"88960947":[],"8896094720230128":[],"89":9,"890033":11,"89003324":11,"89017198e":30,"89044267":21,"89058005":29,"8905826":[],"89069029":21,"89126914e":30,"8917148":[],"891715":23,"89184351":[],"89288636":11,"8931686":34,"89408972":[],"89410423":5,"8944444444444445":[],"89457785":[],"89463761e":[],"89533642":29,"89540936":[],"8962":[],"89654756":[],"89710385e":[],"89724282":[],"89766337e":[],"8978":[],"89845198":26,"8f":[6,32],"8g":[6,32],"8n":23,"8x8":[1,36],"9":[0,1,2,3,4,5,6,7,8,9,11,12,13,14,18,21,23,24,25,26,27,29,30,31,33,34,35,36],"90":[0,1,6,9],"90075537":5,"9011":6,"90114639":29,"90135464e":30,"90220243":5,"90266948":5,"9027777777777778":[],"90300219":[],"90304177e":30,"9040":9,"90475506e":[6,31],"9054":32,"9055555555555556":[],"906589":[],"9065894":[],"906747":5,"90717653":11,"907177":11,"90842732":23,"90860768":23,"90894281":29,"91":[27,29],"910":9,"91099021":[],"91100141e":34,"9111111111111111":[],"91114704":[],"91128596":5,"91270333":[],"91312563":[],"91365263":[],"91410559e":[],"91416944e":[],"91434750e":[],"91492986e":[6,31],"91546928":[],"91648657":[],"9166666666666666":9,"91669165":[],"916692":[],"91672129":29,"91722512e":[],"91744988":[],"91752854":[],"91760278":5,"91811422":[],"91812702":5,"91854134":[],"918785":29,"918992":30,"91933003":23,"919503":11,"9195033":11,"91961463":[],"92":[6,9,27,29],"92003207":[],"92192012":[],"9225384545636204":5,"9230769230769231":9,"92308867":[],"92319842":[],"92326255":[],"92341148":23,"92370959":[],"92376655":[],"924e":6,"925":[1,36],"92507116e":[1,36],"92512799":[],"92527681e":[],"92578916":5,"92599642":[],"92604454":[],"92622842":0,"92661467e":34,"9271707090281667":[],"92756256":31,"9277777777777778":[1,36],"9288904":23,"92921498":26,"9305555555555556":[1,36],"93074023":[],"931":[0,29],"93155188":5,"93158979":5,"93237862":[],"932382":[],"93289669":[],"93293067":26,"933":[5,31],"93366198":[],"933662":[],"93397254e":[],"93492130e":[6,31],"93597168":[],"935972":[],"93601008e":30,"93619369":23,"93668828":[],"936877889972962":[],"937":26,"937057":11,"937082":30,"93787605":[],"93799826":5,"938":26,"9387":9,"93891335e":[],"939":[0,26,29],"93900569e":30,"93909866":[],"93937564":[],"93942872":35,"93968601":[],"93970238":26,"93989887":[],"94":[9,26],"94092702":[],"94099173":[],"94141801":[],"94221383":23,"94226022e":[6,31],"94255277":26,"94273542":30,"94284104":5,"94285762":29,"94291287":[],"94320205":5,"9434":5,"94388948":34,"94419718":[],"9444444444444444":[1,36],"94484047e":[35,36],"94499279":34,"9450635":29,"94591015":[23,29],"946167":[],"94616709":[],"94623184":5,"94625725":[],"946276":[],"94627617":[],"946372":[],"94637206":[],"94639099":11,"946957":5,"94704941e":[],"9472222222222222":[1,36],"947607":[],"94766419e":30,"94781064":31,"9482527":5,"9485531":[],"9495484":[],"94973606":[],"95":[1,9,11,32,36],"95008046":6,"95033155e":[],"950423":[],"95053694e":[],"95115528":[],"95166920e":30,"95226607":[],"95231424":5,"952387":30,"9527777777777777":[],"95284275":5,"953065564":[1,36],"95338273":30,"95343966":23,"95351665":5,"95354276":26,"95395895":[],"953959":[],"954":26,"95400323":29,"95511792":30,"955118":30,"95518112":[],"9555555555555556":[1,36],"95563211":[],"955820c21e8b":4,"95611042":34,"95647867":[],"956563":[11,30],"95684892":5,"95703":[34,35],"95715036":[],"95743466e":[],"95793988e":[],"958228616652075":5,"95845431":21,"95872127":[],"95890587":29,"95906059":34,"959076":[],"95935439":[],"96":[1,6,9,11,32,36],"960":26,"9601304850035702e":[6,31],"9601304850073734e":[6,31],"96015381":23,"96024953":5,"96075051":34,"96080358":26,"96084663":5,"961":26,"962":26,"96231225":[],"96251859":[],"96301764":35,"96305058":[],"963187":[],"9637117593816477":[6,31],"96379806e":[],"96391888":[],"9640435":5,"96432396":[],"96461948":23,"9647801":29,"9649652536":4,"965548":30,"96585824":[],"96631321":30,"96688672":5,"967":6,"9674916":5,"967809":[11,30],"96826039":[],"96850191":[],"96853248":23,"968650":[],"96865004":[],"96866031":[],"968704":11,"96870431":11,"96894842":[],"96916206":[],"969190":[],"96919021":[],"96919836":[],"9692":[],"96991192":[],"97005689":5,"97065359":32,"970827":[],"97082748":[],"97108e":[34,35],"97120565":[],"9712983":[],"97206657":5,"972067":5,"972149":[],"9722222222222222":[],"97228653":[],"9722865317690382":[],"97243128":5,"97243946":[],"972533":[],"97253307":[],"97272223":[],"97300836":5,"97435908":[],"97480604":[],"97482498":11,"974825":11,"97486336":29,"97497404e":[6,31],"97498674":29,"975":[],"97507735":5,"97512176":29,"975484":[],"97548406":[],"97570392":29,"97626519":[],"97630233":32,"9767506308987675":[],"977":6,"97705827":5,"97716508":[],"97758848":5,"9777777777777777":[],"978":32,"9780387310732":28,"9780387848570":28,"9781098134174":29,"9781492032632":28,"9781801819312":29,"97836358":[],"978553":5,"97898392":[6,30,31],"97906022e":30,"9792":[],"97926491":5,"97935648":[],"97979891":6,"98":[0,1,9,36],"980":9,"9805555555555555":[],"98091621":5,"981321":30,"98139097":5,"98140006e":[],"98190064":[],"98232596":21,"98246764":35,"98271562":26,"98275501":5,"98281205":34,"983310":30,"98338288":[],"983383":[],"983450":[],"9834505":[],"9838929":[],"98413059":5,"98413606":[],"9841870203276504":[],"98454786":5,"98473694":[],"985":26,"98566191":5,"986":26,"9861111111111112":[],"98619989":[],"98636199":[],"986362":[],"98654811":[],"986699":5,"98680716":5,"98716878":5,"98723376":[],"98740373":23,"98770503":29,"98808176":5,"98822371":6,"9888888888888889":[],"989":26,"9890348":5,"9893447":5,"98947674e":30,"98947894":30,"9898ff":[9,10],"99":[1,6,9,11,13,21,32,34,35,36],"990":9,"99003341":[],"99009525":5,"9904314810719695":[],"99072374":[],"99088801":5,"991":26,"991047":[],"99104747":[],"99114739e":[],"99115119":5,"99176998":5,"99194201":[],"992":26,"99201684e":[],"99242921":5,"99265097":5,"99294056":[],"993":26,"9930742":23,"99316252":5,"99318183":[],"99360578e":35,"99368326":[],"99370678":23,"99371056":5,"99389612":5,"99415296":[],"99427512":23,"9943201":5,"99434472":[],"994345":[],"994474":[],"99447418":[],"99456598":34,"99475306":34,"9947756":5,"9948998579029953":[],"99492986":5,"99498272":[],"9951059931014423":[],"99512017":23,"9952183728736417":[],"9952505213910134":30,"9952537939995855":[],"99528218":5,"99539415":5,"9955318336036834":30,"99562995":35,"99566069":5,"99578809":5,"9958589197366403":[],"9958983289118531":[],"9959308805732706":30,"996":[5,31,32],"99608161":5,"99619572":21,"9963961":5,"99647992e":[],"99650061":5,"996626":[],"99662602":[],"9967458":5,"9969461173312454":[],"9969513794144311":[],"99700706":5,"99709215":5,"99723951":[],"997252717901263":[],"99729756":5,"99751458":5,"99753321e":30,"99758326":5,"99762142":31,"997746":11,"99774602":11,"99775587":5,"99793613":5,"99799099":5,"99802696":34,"99812668e":[],"99813653":5,"99828624":5,"9983295":5,"99835783":34,"99845267":5,"99848215":[],"99848815":34,"99854557":30,"998577":5,"99861053":5,"99862019":30,"99869482":30,"99871521":5,"99876945":30,"99881845":5,"99883628":30,"99884384":5,"99884409":30,"99884986":31,"99887767":[],"99891093":30,"99891873":30,"99893323":5,"99898558":30,"999":[9,21,26,34,35],"99901896":5,"99903755":5,"99906023":30,"9990927157696581":31,"99911427":5,"99912709":30,"99913489":30,"99916114":34,"99918546":5,"99919837":5,"99920175":30,"99926459":5,"99927642":30,"9993237":5,"99933188":5,"9993511":30,"99938942":5,"99941797":30,"99942911":21,"9994385":5,"99944272":5,"9994574":[],"99949266":30,"99949306":5,"99953381":5,"99953475":5,"99954278":[],"99954434":[],"99954925":34,"99956033":[],"99956181":21,"99956735":30,"99957911":5,"99961294":5,"99965056":5,"99967865":5,"99968451":[],"99970894":30,"99970988":5,"9997332":5,"99975913":5,"99977375":[],"99977849":5,"99978365":30,"99979896":35,"99980002":5,"9998161":5,"99984732":5,"99987324":5,"99989103":34,"99989296":21,"99989476":5,"99990413":[],"99990706":[],"99991245":[],"99991263":5,"99991295":[],"99992107":35,"99992746":5,"99993978":5,"99995":5,"999955585168597":[6,31],"99996755":[],"99997644":21,"99998727":[],"9x":[6,24],"9y":[6,24],"\u00f8yvind":[6,30,31],"abstract":[1,20,34],"boolean":4,"break":[0,4,6,11,14,29],"byte":[23,29],"case":[0,1,2,3,4,5,6,7,11,12,13,14,16,21,22,23,24,29,32,35,36],"catch":0,"class":[0,1,3,4,6,7,8,9,11,12,13,26,29,32,34,35,36],"default":[0,1,2,4,6,7,8,16,23,24,29,30,31,33],"do":[0,2,3,4,5,6,8,9,10,11,12,13,14,15,16,21,23,24,29,30,33],"ekstr\u00f8m":4,"export":9,"f\u00f8470":[27,29],"final":[0,1,2,3,4,5,6,7,8,9,10,11,13,14,16,18,19,20,24,25,26,27,29,32,33],"float":[0,3,4,5,9,11,13,14,23,29,30,34,35],"function":[2,3,4,5,9,14,15,16,17,18,19,22,23],"import":[0,1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,17,24,26,32,33,34,36],"int":[0,1,2,3,4,5,6,11,13,14,21,23,26,30,32,34,35,36],"long":[0,1,3,4,12,13,29,33,34,35,36],"m\u00f8svatn":[6,24],"new":[0,1,2,3,5,6,7,8,9,10,11,13,14,17,21,23,29,30,33,34,35,36],"public":[0,22,29],"return":[0,1,2,3,4,5,6,7,8,9,11,13,14,21,23,24,26,29,30,31,32,33,34,35,36],"sch\u00f8yen":[6,30,31],"short":[4,5,20,24,31,32],"super":[5,30,31],"switch":0,"throw":[3,6,26,32],"true":[0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,19,23,24,26,29,30,31,32,33,34,35,36],"try":[0,1,2,4,5,6,7,8,9,10,11,13,14,15,16,22,23,24,26,29,30,31,32,33,34,35,36],"var":[1,5,6,10,11,18,19,24,26,29,30,31,32,36],"while":[0,1,3,4,5,6,7,8,9,11,12,13,26,29,30,31,32,33,34,35,36],A:[2,3,5,6,7,10,11,12,13,16,18,20,22,23,24,25,26,27,28,30,34,36],AND:2,And:[0,3,4,5,6,9,13,20,22,24,26,36],As:[0,1,2,3,4,5,6,8,10,12,13,16,23,24,26,29,30,31,32,33,34,35,36],At:[0,4,6,13,24,29,34],BE:[0,29],Be:[2,22,29],Being:[13,34],But:[0,1,2,3,5,6,9,10,26,30,31,32],By:[0,3,5,6,12,13,17,23,29,30,31,32,33,34,35,36],For:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23,24,25,26,28,29,31,32,33,34,35,36],IF:[6,31],IN:28,If:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,15,16,21,22,23,24,26,29,30,31,32,33,34,35,36],In:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,22,23,24,26,28,29,30,31,32,33,34,35,36],Is:11,Ising:[5,12,30,35,36],It:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,22,23,24,26,29,30,31,32,33,34,35,36],Its:[1,2,4,11,36],NO:[9,11],No:[0,6,7,9,29,31,33,35],Not:[0,1,5,6,30,31,32,35,36],OR:26,Of:26,On:[0,3,9,15,24,25,26,27,28,29],One:[0,1,3,4,5,6,7,8,11,12,13,17,21,24,26,30,32,33,34,35,36],Or:[0,1,6,24,29,33],Such:[0,6,12,16,26,32,33,34,35,36],That:[0,5,7,10,11,12,14,19,24,26,29,31,32,33,36],The:[4,10,13,14,15,16,18,19,20,21,23,24,25,26,27,28],Their:36,Then:[0,1,6,8,9,10,11,12,13,14,23,24,29,32,33,34,35,36],There:[0,3,4,5,6,8,9,11,12,14,23,24,25,26,27,29,30,31,33,34,35,36],These:[0,3,4,5,8,9,10,11,12,13,14,15,16,23,24,26,27,29,30,31,34,35,36],To:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,21,23,26,31,32,33,34,35,36],With:[0,5,6,8,9,10,11,12,14,18,23,24,26,29,30,32,35,36],_0:[5,8,10,11,13,30,33,34],_1:[2,5,6,8,10,11,12,13,14,23,30,31,33,34,35,36],_2:[2,5,8,11,12,13,23,30,34,35,36],_3:23,_4:23,_9:[13,34,35],_:[0,1,2,4,5,6,7,8,9,10,11,12,13,17,18,19,21,23,24,29,30,31,32,33,34,35,36],__array_function__:2,__class__:10,__doc__:[6,32],__enter__:[0,7,33],__future__:[8,9],__getattr__:31,__getattribute__:29,__getitem__:[0,7,33],__init__:[0,1,3,4,7,14,31,33,35,36],__main__:[2,35],__name__:[2,10,31,35],__rtruediv__:[],_accessor:29,_auto10:[6,12,35,36],_auto11:[6,35],_auto12:[6,35],_auto1:[2,3,4,5,6,7,12,13,21,23,26,30,33,34,35,36],_auto2:[2,3,4,5,6,12,13,23,26,34,35,36],_auto3:[3,4,5,6,12,13,23,34,35,36],_auto4:[4,6,12,13,23,34,35,36],_auto5:[4,6,12,13,23,34,35,36],_auto6:[4,6,12,23,35,36],_auto7:[4,6,12,23,35,36],_auto8:[6,12,35,36],_auto9:[6,12,35,36],_base:8,_build:[0,17,19,22,24,28,29],_c:[1,36],_can_hold_identifiers_and_holds_nam:29,_check_optimize_result:[9,11],_class:8,_compon:11,_coordinate_desc:6,_depth:9,_fraction:9,_generatorcontextmanag:[0,7,33],_i:[0,1,2,5,6,7,8,11,12,13,15,16,17,19,24,29,30,31,32,33,34,35,36],_info_axi:29,_j:[0,1,2,3,5,6,8,13,17,19,24,30,31,32,34,36],_k:[13,33,34,35],_l:[12,35,36],_lambda:[6,29],_leaf:9,_ll:[3,4,14],_logist:[9,11],_m:10,_make_vjp:[],_multilayer_perceptron:[],_n:[2,5,8,11,13,30,33,34],_node:9,_np:[],_o:[3,4,14],_open_file_or_url:[0,7,33],_p:[5,8,30],_plugin_dir:[3,4,14],_ratio:11,_rc_params_in_fil:[0,7,33],_s:[3,4,14],_sampl:9,_split:[6,9,24],_src:[21,35],_t:[13,21,34,35],_test:[6,24],_tf_getinputpropertieslist:[3,4,14],_trace:[],_valu:[],_varianc:11,_weight:9,_wrapreduct:2,a0:3,a0faa0:[9,10],a1:[0,29],a2:[0,29],a3:[0,29],a4:[0,29],a_0:[0,21,29],a_1a:[0,29],a_1x:21,a_2a:[0,29],a_2x:21,a_3:[0,29],a_3a:[0,29],a_4:[0,29],a_4a:[0,29],a_:[0,1,16,23,29,30,36],a_h:[1,36],a_i:[0,1,2,12,29,36],a_j:[1,12,36],a_k:[0,1,12,36],aaron:28,ab:[0,2,5,13,14,21,24,29,30,31,34,35],ab_channel:[22,35,36],abandon:1,abbrevi:25,abid:26,abil:[0,10],abl:[0,1,4,5,6,7,10,12,13,16,24,30,33,34,35,36],about:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,22,23,24,27,31,32,33,34,35,36],abov:[0,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,23,24,26,28,29,30,32,33,34,35,36],abovement:[6,29,32],abscissa:[13,33,34],absolut:[0,2,5,6,13,29,30,31,32,34,35],absorb:[30,31],acceler:[13,21,34,35],accept:[0,3,6,9,24,29,30],access:[0,3,11,26,29],accid:[4,6,32,33],accompani:[0,29,30],accomplish:[8,9,13,34,35],accord:[0,1,2,5,6,9,12,13,14,15,16,26,29,31,32,33,34,35,36],accordingli:11,account:[0,3,5,13,15,26,29,31,32,34,35],accumul:[12,13,21,26,34,35,36],accur:[0,3,4,6,10,13,32,34,35],accuraci:[0,1,3,4,5,6,7,9,10,11,12,29,30,33,35,36],accuracy_scor:[0,1,10,29,36],accuracy_score_numpi:[1,36],achiev:[0,1,5,6,8,12,23,29,31,32,35,36],aco:26,acquaint:22,acquir:[1,22,29],acr:0,across:[1,3,6,9,22,29,32,36],act:[1,3,23,36],action:26,activ:[0,2,3,4,9,25,27,29,33,34],actual:[0,1,4,5,6,8,11,16,23,26,29,30,31,32],ad:[1,3,4,5,8,13,15,16,23,31,32,33,34],ada_clf:10,adaboostclassifi:10,adadelta:[13,34,35],adam:[1,3,4,27,29],adapt:[4,6,13,28,32,33],add:[0,1,2,3,4,5,6,8,10,11,12,15,16,17,21,24,26,29,30,31,32,34,36],add_outgrad:2,add_subplot:[1,7,12,14,24,33,34,35,36],addendum:5,addit:[0,2,3,5,6,7,8,9,10,12,13,15,17,21,22,23,24,26,27,28,29,30,31,32,33,34,35,36],addition:[12,13,33,34,35,36],address:[1,9,11,13,29,34,35],adjac:[3,12,35,36],adjoint:[5,30,31],adjust:[0,5,12,13,33,34,35],admir:[0,29],advanc:[4,6,12,28,29,32,36],advantag:[1,3,5,6,10,13,23,31,32,33,34,35,36],adversari:29,afecionado:29,affect:3,affin:[0,3,8,11,30],afford:3,aficionado:29,aforement:14,african:0,after:[0,1,2,4,5,6,9,11,12,13,15,21,22,23,24,26,29,30,31,32,34,35,36],afterward:[0,29],ag:[0,7,25,29,30,33],ag_0:2,again:[0,1,4,5,6,7,8,10,11,12,13,15,16,21,24,26,29,30,31,32,34,35,36],against:[1,4,7,10,21,33,36],agegroup:[7,33],agegroupmean:[7,33],aggreg:[9,10],agorithm:10,agre:[5,6,26,31,32],agreement:[13,21,34,35],ahead:9,ai:[0,28],aid:[11,20],aim:[0,1,4,6,7,11,14,15,16,22,23,24,30,32,33],ainv:5,airplan:3,aka:[5,31,32],al:[0,2,4,15,16,17,24,28,29,30,31,32,33,34,36],alarm:[5,7,31,32],aldo:30,algebra:[0,3,5,13,21,22,30,31,32,34,35],algorithm:[0,1,2,4,5,6,7,8,13,14,22,23,24,26,28,29,31,32,33],align:[0,2,5,6,7,8,13,24,26,29,30,31,32,33,34],all:[0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],allevi:[1,13,33,34],alloc:[3,23],allow:[0,1,2,3,5,6,8,10,13,15,16,22,23,24,29,30,31,32,33,34,35,36],almost:[0,1,6,8,11,13,21,26,32,33,34,35],alon:[2,9],along:[2,3,4,5,6,9,10,11,22,23,29,30,31,32,33],alpha:[0,1,2,3,4,6,7,8,9,10,13,14,26,29,30,32,33,34,36],alpha_0:3,alpha_1:3,alpha_2:3,alpha_:10,alpha_i:[3,13,34],alpha_k:[13,34],alpha_m:10,alpha_n:3,alpha_opt:[13,34],alreadi:[2,3,4,5,6,10,12,22,23,26,29,30,31,32,35,36],also:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,29,30,31,32,33,34,35,36],alter:[1,36],altern:[0,1,4,5,6,8,9,11,13,23,24,29,30,31,32,33,34,36],although:[0,1,5,6,8,10,13,16,21,29,31,32,34,35],alwai:[0,3,5,6,12,13,16,21,24,26,29,30,31,32,33,34,35,36],am:4,ame2016:[0,29],american:0,among:[0,3,5,9,10,12,23,29,30,31,35,36],amongst:[5,31,32],amount:[0,1,3,4,6,8,10,14,22,32],amp:[35,36],an:[1,2,3,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,26,27,28,30,31,32,33,34,35,36],an_:26,anaconda:[0,1,15,22,24,29],analog:[13,34,35],analys:[6,31,32],analysi:[1,3,4,7,14,15,16,17,19,21,23,28,33,36],analyt:[2,3,5,6,7,12,13,15,22,24,29,30,31,32,33,34,35,36],analytical_gradi:[21,35],analyz:[0,1,3,4,5,6,16,17,24,26,30,31,36],andrew:[1,36],angl:[0,3,9,30],anharmon:3,ani:[0,1,2,3,4,5,6,7,8,9,10,12,14,18,26,29,30,31,32,35,36],anim:[4,12,35,36],ann:[12,35,36],annot:[0,1,3,7,8,29,33,36],announc:29,anoth:[0,1,3,4,5,6,7,8,10,11,12,13,23,24,26,29,30,33,34,35,36],anp:2,ans_vspac:[],ansatz:[0,29],answer:[0,1,3,5,6,23,24,27,29,31,32,36],antialias:[2,6,24],anticip:4,anymor:[1,8],anyon:[4,8],anyth:[1,26],anytim:[27,29],apach:1,apart:[11,13,33,34],api:[1,22,29],appar:2,appear:[0,1,3,13,16,23,26,34,35,36],append:[1,3,4,8,9,13,21,29,34,35],appendix:24,appli:[0,1,2,3,4,6,7,8,9,10,11,12,13,15,16,24,26,28,29,30,31,32,33,34,35,36],applic:[0,1,3,4,5,6,7,9,12,13,21,23,24,26,28,29,30,32,33,34,35,36],apply_gradi:4,approach:[1,2,4,5,6,9,10,11,12,13,17,21,22,26,28,30,33,36],appropri:[2,6,9,12,13,22,26,32,34,35,36],approv:29,approx:[0,2,3,6,10,11,13,26,29,32,33,34,35],approxim:[0,1,2,3,4,5,6,7,10,11,13,18,19,24,26,29,30,31,32,33,34,35],apt:[0,15,22,24,29],aq:26,ar:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],aragorn:29,arang:[1,3,4,6,7,9,10,12,13,24,29,33,34,35,36],arbitrari:[1,4,6,8,12,13,26,32,33,34,35,36],arbitrarili:[0,1,11,29,36],arc:[6,24],architectur:[3,4,12],area:[0,3,6,9,24,28,29],arg:2,argmax:[1,11,36],argmin:[4,10,14],argnum:2,argnum_0:2,argnum_1:2,argsort:11,argu:[1,13,34,35],argument:[0,2,3,5,6,11,12,13,21,29,30,31,32,36],argval:[],aris:[0,6,12,13,26,29,32,33,34,36],arithmet:[0,13,23,29,34,35],arm:[6,31],armadillo:23,around:[0,1,4,5,6,11,26,29,31,32,36],arr:[],arr_list:[],arrai:[0,1,2,3,4,5,6,7,8,9,11,12,13,14,21,22,24,26,30,31,32,33,34,35,36],arrang:[3,29],arraybox:[13,34],arriv:[0,6,9,11,23,26,29,32],arrow:[12,35,36],arrowprop:8,art3d:34,art:[0,1,15,22,29],articl:[0,3,4,6,10,18,24,29,30,31,32],artifici:[0,2,7,12,28,29,33],artificialneuron:[12,35,36],arug:[13,34,35],arxiv:[3,4,21,24,34,35],asarrai:[0,2,6,9,21,30,31,34,35],asid:30,ask:[5,6,11,12,24,31,32,36],aspect:[0,6,22,24,29,30,31],assembl:[0,3,29],assert:4,assess:[0,6,24,29,30,31,32],assici:4,assign:[0,7,8,9,12,13,14,25,27,28,29,33,34,35,36],associ:[0,6,9,12,14,26,29,32,35,36],assum:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,23,24,26,29,30,31,32,33,34,35,36],assumpt:[0,3,5,6,9,11,18,24,26,29,30],ast:[0,5,6,18,24,29,31,32,33],astronomi:[29,31,33,34,35],astyp:[4,9,10],asymmetri:[0,29],asymptot:[4,6,32],atleast_2d:[],atom:[0,29],attempt:[0,4,6,7,8,10,29,31,33],attend:25,attent:[0,23,29],attr:31,attract:[0,10,29],attribut:[0,9,29,31],attributeerror:[29,31],audi:[0,29],audio:[3,4],august:[15,16,29],aurelien:[0,15,25,28,29],austfjel:[6,24],author:[0,1,10,26],authour:29,auto:[8,9,10,26],auto_exampl:[24,31],autocor:26,autocorrelation_tim:26,autocorrelform:26,autocovari:26,autoencod:[4,22,29],autoencond:22,autograd:[22,29],autom:[0,22,28,29],automac:23,automag:29,automat:[0,1,2,3,4,11,16,22,23,29,36],automobil:3,autonom:4,avail:[0,1,4,6,7,10,11,15,20,21,22,23,24,25,27,28,29,32,33,35,36],averag:[0,1,3,6,9,10,13,14,21,26,27,29,30,31,32,33,34,35,36],avoid:[0,4,5,6,9,11,13,21,23,29,30,32,33,34,35],awai:[2,3,6,30,31],awar:[2,10],award:[27,29],ax:[0,1,2,3,4,6,7,8,9,10,11,12,13,14,23,24,29,32,33,34,35,36],axes3d:[2,6,13,24,33,34],axes_grid1:6,axhlin:8,axi:[0,1,2,3,4,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],axiom:[5,31,32],axis_arg:[],axlabel:[0,29],axvlin:[4,8],axvspan:4,b1:8,b2:8,b3:8,b:[0,1,3,4,5,6,8,9,10,12,13,14,15,16,21,26,27,29,30,31,32,33,35,36],b_0:0,b_1:[0,2,12,13,34,35,36],b_2:[0,13,34],b_5:[13,34,35],b_:[0,1,23,36],b_group:9,b_i:[0,1,2,12,29,35,36],b_ia_:[0,29],b_ia_i:0,b_index:9,b_j:[1,12,35,36],b_k:[0,1,12,13,34,35,36],b_m:[12,35,36],b_score:9,b_valu:9,babcock:29,bachelor:[25,27],back:[0,3,4,5,6,8,9,10,15,23,26,29,30,31,33,34,35],backbon:23,backend:[0,1,4,7,21,33,35],background:[28,29,30],backpropag:[1,36],backtrack:9,backup:23,backward:[1,2,4,12,23,36],backward_pass:2,bad:[6,30,31],badli:26,bag:[9,22,29],bag_clf:10,baggin:29,baggingboot:10,baggingclassifi:10,baggingtre:10,balanc:[6,32,33],band:23,bandwidth:23,bar:[0,6,11,15,16,24,29],barber:28,bare:[4,10],base:[0,1,3,4,5,7,8,9,10,14,22,26,27,28,29,30,31,33,36],basi:[5,7,8,10,11,12,13,23,30,31,33,34,35,36],basic:[6,8,12,13,14,22,24,26,29,34,35,36],batch:[3,4,11,12,13,21,33,36],batch_shap:4,batch_siz:[1,3,4,36],batchnorm:4,bay:[7,33],bayesian:[5,22,28,29,31,32],beam:[29,33,34,35],becattini:27,becaus:[0,1,2,3,4,5,6,8,9,12,13,14,29,31,32,33,34,35,36],becom:[0,1,2,5,6,7,9,12,13,21,26,29,30,31,32,33,34,35,36],been:[0,1,2,3,4,5,6,11,12,13,22,23,24,29,30,31,32,34,35,36],befor:[0,1,2,3,4,5,6,7,8,12,13,14,20,23,24,26,29,30,31,32,33,34,35,36],beforehand:[0,26,29],begin:[0,1,2,3,4,5,6,7,8,9,11,12,13,14,21,23,24,26,27,29,30,31,32,33,34,35,36],behav:[1,6,13,32,33,34],behavior:[0,1,13,29,33,34,35],behaviour:[12,35,36],behind:[0,1,6,8,13,29,33,34,36],being:[0,1,2,3,4,5,7,8,10,11,12,13,17,26,29,30,31,32,33,34,35,36],believ:[9,23],belong:[7,8,9,13,14,33,34],below:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,23,24,26,29,30,31,32,33,34,35,36],benchmark:10,benefici:[1,13,34,35,36],benefit:[0,1,4,11,13,15,22,29,33,34,35,36],bengio:[1,21,25,28,29,30,34,35],benign:[1,7,9,33],besid:[4,5,31],bessel:[5,30,31,32],best:[0,1,2,3,4,5,6,7,8,9,10,12,13,24,27,29,30,32,33,34,36],best_estimator_:33,beta1:[21,34,35],beta2:[21,34,35],beta:[0,1,3,5,6,7,10,11,13,16,17,18,19,21,24,29,30,33,34,35,36],beta_0:[0,1,3,5,6,7,13,29,30,31,33,34,36],beta_0x_:[0,29,30],beta_1:[0,1,3,5,6,7,10,13,29,30,31,33,34,35,36],beta_1x_0:[0,29],beta_1x_1:[0,7,29,33],beta_1x_2:[0,29],beta_1x_:[0,29,30],beta_1x_i:[7,13,30,33,34],beta_2:[0,3,13,29,30,34,35],beta_2x_0:[0,29],beta_2x_1:[0,29],beta_2x_2:[0,7,29,33],beta_2x_:[0,29,30],beta_2x_i:30,beta_3:3,beta_3x_i:30,beta_4x_i:30,beta_:[0,3,6,7,13,29,30,31,33,34,35],beta_i:[0,3,5,29,30,31],beta_j:[0,5,6,13,18,24,29,30,31,32,34,35],beta_k:[13,33,34],beta_lasso:35,beta_linreg:[13,21,33,34,35],beta_logreg:35,beta_m:10,beta_mg_m:10,beta_n:3,beta_ol:35,beta_p:[7,33],beta_px_p:[7,33],beta_ridg:35,betavalu:5,better:[0,1,2,3,4,6,9,10,11,12,13,21,29,30,31,32,34],between:[0,1,2,3,4,5,6,7,8,9,11,12,13,14,17,21,24,26,29,30,31,32,33,34,35,36],beyond:[0,1,5,6,8,13,21,24,29,30,33,34,35],bf:[13,14,23,26,33,34],bg:29,bgd:[13,34,35],bia:[0,1,2,3,5,8,9,10,12,13,19,29,30,31,33,34,35,36],bias:[1,2,3,5,6,9,12,31,35],bibliographi:24,big:[0,1,2,5,6,14,18,31,32,36],bigger:[1,6,30,31],bigr:[12,35,36],bike:9,bilbo:29,billion:[3,12,22,35,36],bin:[0,7,26,33],binari:[0,3,5,7,9,10,12,29,31,32,33],binarycrossentropi:4,bind:[0,30],binomi:[22,26,29],binsboot:[6,32],bioinformat:0,biolog:[1,12,35,36],bios1100:[22,29],bird:[0,3],birth:29,bishop:[25,28,29],bit:[1,4,23,26,29,36],bitwis:26,bivari:2,bk:[0,13,34,35],bla:[23,29],black:[8,9,14,21,35],blob:[16,20,24,33,34,35],block:[6,10,22,23,26,29,32],blog:29,blogpost:4,blue:[0,3],bmatrix:[0,1,3,5,7,8,11,13,23,29,30,31,33,34,36],bmi:[1,36],bn:[],bodi:[0,1,4,12,29,35,36],bold:1,boldfac:[0,5,16,30,31],boldsymbol:[0,1,2,3,5,6,7,8,10,11,13,14,15,16,17,18,19,21,24,29,33,34,35,36],boltzmann:[12,22,29,35,36],book1:28,book:[19,24,28,29,30,32],boost:[1,9,22,29],boostrap:10,bootstrap:[1,13,19,22,24,29,33,34,35],borrow:29,boston_dataset:0,bot:8,both:[0,1,4,5,6,8,9,10,13,14,15,16,22,23,24,26,27,29,30,31,32,33,34,35],bottl:[7,33],bound:[0,8,12,34,35,36],boundari:[2,4,8,11,12,36],box:[4,9],boxed_arg:[],boyd:[8,13,33,34],bracket:[4,26],brain:[1,7,12,33,35,36],branch:9,breast:[5,7,11,31,32,33],breviti:[13,21,34,35],brew:[0,15,22,24,29],brg:8,brief:[24,30],briefli:[0,29],bring:[0,5,6,10,30,31],broad:0,broadcast_idx:2,brought:[13,21,22,29,34,35],brownle:4,browser:29,brute:[3,5,11,30,31,33],bs:[8,9,10],buffer_s:4,bui:4,build:[0,4,5,6,10,23,26,29,31,32,33,34,35,36],built:[0,1,3,4,6,32],bunch:11,busi:0,bxe2t:[35,36],c1:[8,11],c2:[8,11],c:[0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,19,22,23,26,27,28,30,31,32,33,34,35,36],c_0:26,c_1:[12,35,36],c_2:[12,35,36],c_3:[12,35,36],c_4:[12,35,36],c_:[0,8,9,10,13,21,26,33,34,35],c_i:[12,13,34,35,36],c_k:26,ca:[1,29],cach:10,cal:[0,8,10,12,13,15,16,29,33,34,36],calcul:[0,1,2,4,5,6,8,9,10,11,12,13,14,15,16,18,21,23,26,29,31,32,33,34,35,36],call:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,19,21,22,23,24,26,27,29,30,31,32,33,34,35,36],calor:[0,30],cambridg:[13,28,33,34],can:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,26,27,28,30,31,33,36],cancel:[0,13,29,30,34,35],cancer:[5,10,31,32],cancerpd:[7,33],candid:[8,9,10,34],cannot:[0,1,4,5,6,7,8,9,25,26,30,31,33,36],canopi:[0,15,22,24,29],canva:[24,29],cap:[5,31,32],capabl:[0,1,8,13,22,29,34,35],capac:[2,27],capita:0,caption:24,captur:[4,11,12,35,36],car:[3,4],card:[0,7,29,33],cardin:1,care:[11,33],carefulli:[13,34],carlo:[0,6,22,26,28,29,32],carri:[2,6,7,24,32,33],cart:10,casella:28,cast:1,cat:[3,4],categor:[0,1,3,9,11,29,36],categori:[0,1,3,7,10,12,14,29,33,35,36],categorical_crossentropi:[1,3],caus:[0,5,6,7,26,29,30,31,32,33],causal:0,causat:[0,29],cax:1,cb:[6,29],cbar:1,cc:[0,1,5,13,29,30,31,33,34],ccc:[5,12,31,35,36],cd_fast:6,cdf:26,cdot:[0,2,6,12,13,14,23,26,29,32,33,34,35,36],celebr:[13,33,34],cell:[0,1,2,3,4,6,7,8,9,10,13,14,24,31,33,36],center:[0,1,6,7,8,9,11,14,24,26,29,31,32,33],central:[0,3,5,6,8,16,23,29,30,31],centroid:[14,26],centroid_differ:14,centuri:3,certain:[0,3,6,7,9,26,29,30,32,33],certainti:32,cg:[13,34],cha:0,chain:[0,1,13,22,26,29,34,35],challeng:[34,35],chanc:[1,5,13,26,31,32,34,35,36],chang:[0,1,2,3,4,5,6,8,9,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],channel:3,chap4:36,chapter3:[0,19,24],chapter:[0,6,10,11,16,18,21,23,24,28,29,30,31,32,33,34,35,36],charact:[0,3,5,8,29,30],character:[8,9,10,12,26,35,36],characterist:[0,1,3,10,13,21,29,34,35],charg:[0,29],charl:0,chase:4,chatgpt:24,chd:[7,33],chddata:[7,33],cheap:[5,30],cheaper:[1,13,34,35],check:[0,1,3,4,5,6,11,13,23,29,34,35],checkmark:3,checkpoint:4,checkpoint_dir:4,checkpoint_prefix:4,chen:10,cheng:30,chiaramont:2,choic:[0,1,2,3,4,6,9,12,13,14,19,23,29,30,32,33,34,35,36],choleski:[5,23,30],choos:[2,3,6,9,10,11,13,14,24,32,33,34,35],chosen:[0,1,2,6,8,9,10,13,16,21,26,29,32,33,34,35],chosen_datapoint:[1,36],christian:28,christoph:[25,28,29],cifar10:3,cifar:3,circ:[1,12,36],circl:[0,8,12,30,35,36],circuit:3,circumfer:9,circumv:[1,5,13,30,34,35],cite:24,ckpt:4,clariti:26,class_nam:[3,9],class_val:9,class_valu:9,classic:[7,9,13,33,34,35,36],classif:[0,3,5,6,7,8,11,12,22,24,28,29,30,31,32,34],classifi:[0,1,4,7,9,10,11,29,36],classificaton:[1,36],classifii:10,clean:[1,36],clear:[1,5,10,12,13,21,34,35,36],clearli:[0,3,5,6,7,8,18,26,30,31,32,33],clever:[1,10,36],clf3:0,clf:[0,6,8,9,10,29,30],clf_lasso:6,clf_ridg:[6,29],clip:[3,26],clone:27,close:[0,1,2,4,6,8,9,11,12,13,14,24,26,28,29,32,33,34,35,36],closer:[3,5,13,30,34,35],closest:[8,11,13,14,34],closur:[22,29],cloud:[22,29],cluster:[0,1,4,6,11,22,29,32,36],cluster_label:14,cm:[1,2,3,6,8,9,13,24,33,34,36],cmap:[0,1,2,3,4,6,8,9,10,24,29,36],cmap_arg:6,cmb:25,cmd:9,cn_:26,cnn:[12,35,36],cnn_kera:3,cntk:[22,29],co:[0,2,3,6,9,13,21,29,32,34,35],code:[3,4,6,7,8,15,16,17,19,22,23,24,26,28],coef0:8,coef:[0,29],coef_:[0,5,6,8,9,13,29,30,31,33,34],coeff:5,coeffici:[0,3,5,6,7,8,9,13,15,16,23,29,30,31,32,33,34,35],coerc:[0,6,29,32],coin:[10,26],coin_toss:10,col:[0,11,29,30],colab:[22,29],cold:9,colinear:0,collabor:24,collaps:8,collect:[0,2,6,10,11,21,22,26,28,29,32,35],collinear:[5,30,31],color:[0,3,4,6,8,9,10,21,24,26,34,35],color_channel:3,color_cod:6,colorbar:[1,6,24],colsample_bytre:10,colsaobject:10,column:[0,1,2,5,6,7,8,9,11,12,17,23,29,30,31,32,33,35,36],columntransform:9,com:[4,6,16,20,21,22,24,28,29,32,33,34,35,36],combin:[1,2,5,6,7,10,26,31,32,33,34,35],come:[0,1,3,4,5,12,13,14,15,29,30,31,32,34,35,36],command:[0,1,29],comment:[0,4,5,6,15,16,24,29,30],commerci:[0,15,22,24,29],commod:[0,29],common:[0,1,3,5,6,7,9,11,13,14,24,26,29,30,32,33,34,35,36],commonli:[0,1,4,6,7,9,13,14,30,32,33,34,35,36],commun:[0,12,24,35,36],commut:3,commutatitav:3,compact:[0,1,3,5,6,7,9,11,12,13,14,29,30,31,32,34,35,36],compair:0,compar:[0,3,4,5,6,11,13,15,16,21,23,24,29,30,31,32,33,34,35],comparison:[2,4,13,34,35],compat:[7,33],compet:0,competit:10,compil:[0,1,3,4,13,15,21,22,23,29,34,35],complet:[0,2,3,4,9,12,29,35,36],completenn:[12,35,36],complex:[1,5,8,9,11,12,13,15,16,19,29,32,34,35,36],complic:[0,1,9,13,29,32,33,36],compoment:30,compon:[0,1,3,4,5,6,7,9,14,16,22,29,30,31,32,33,36],components_:11,compos:[9,12,13,14,21,22,29,34,35,36],compphys:[0,6,16,17,19,20,22,24,25,27,28,29,33,34,35],compress:[0,29,30],compris:[6,33],compromis:[5,30],compulsori:[22,29],comput:[0,1,2,3,4,5,6,7,8,10,11,12,13,15,16,17,21,22,23,24,25,26,28,29,30,31,32,33,36],computation:[0,3,6,9,13,26,29,33,34,35],computationalscienceuio:29,computerlab:24,concaten:[2,4,6,14],concatenate_arg:[],concav:[1,9,13,30,33,34],concentr:[0,10],concept:[0,2,22,29,30],conceptu:[12,13,33,34,35,36],concern:[0,1,4,7,29,33,36],concic:29,conclud:[0,5,13,21,31,32,34,35],conclus:[1,36],cond:2,conda:[0,1,15,22,24,29],condis:30,condit:[0,2,4,5,6,8,9,11,13,26,29,30,35],conduct:22,condwav:2,confid:[0,5,6,7,8,18,24,29,30,31,33],configur:[3,21,35],confirm:[5,12,31,32,35,36],confus:[5,6,7,10,23,30,31,32],confusion_matrix:9,congruenti:26,conjug:[4,8],conjugaci:[13,34],conjunct:3,connect:[0,1,3,4,9,11,12,13,23,29,30,33,34,35,36],consequ:[5,6,8,10,12,13,30,31,32,33,34,35,36],conserv:[5,14,30],consid:[0,1,2,3,5,6,7,8,9,10,12,13,16,19,21,23,24,26,29,30,31,32,33,34,35,36],consider:[0,1,5,13,29,30,31,32,33,34,36],consist:[0,1,2,3,4,6,12,13,19,21,24,26,30,32,33,34,35,36],constant:[0,2,4,5,6,8,12,13,26,29,30,31,32,33,34,35,36],constitu:[0,29],constitut:[2,6,32,33],constrain:[1,3,5,7,11,31,33,36],constraint:[5,6,8,13,30,31,32,34,35],construct:[0,1,2,3,5,6,7,8,9,10,11,23,26,29,30,31,32,33],contact:[0,29],contain:[0,2,3,4,5,6,7,8,9,11,12,13,17,19,21,23,24,26,28,29,30,31,32,33,34,35,36],contemporari:29,content:[1,22,23,29],context:[6,10,13,24,32,33,34,35],contextlib:[0,7,33],contigu:23,continu:[0,1,2,3,4,5,6,7,8,9,10,12,13,17,18,21,23,24,26,29,30,31,32,33,34,36],contour:[9,10,13,34],contourf:[8,9,10],contrast:[1,4,9,10,12,35,36],contribut:[0,3,5,13,21,26,29,30,31,34,35],contributor:[0,24],control:[0,1,3,9,13,15,22,29,34,35,36],conv2d:[3,4],conv2dtranspos:4,conv:[3,4],convei:29,conveni:[0,5,6,12,13,23,24,29,31,32,33,34,35,36],convent:[12,30,36],converg:[1,2,4,5,6,8,9,11,13,14,21,30,31,33,34,35],convergencewarn:[6,8,9,11],convert:[0,1,4,5,9,11,13,23,29,30,34,35],converttomatrix:4,convex:[4,5,7,30],convinc:[13,33,34],convolut:[1,4,22,29],cook:24,cool:[4,9],coolwarm:[6,24],coordin:[5,12,14,30,31,35,36],coorel:0,copi:[0,1,14,30,36],core:[0,2,7,10,29,33],corel:29,coronari:[7,33],corr:[0,5,7,11,30,33],correalt:[11,22],correct:[0,1,2,3,4,5,7,13,23,26,29,30,31,32,34,35,36],correctli:[1,2,6,7,10,24,36],correl:[0,1,3,5,6,7,10,12,13,21,22,26,29,31,32,34,35,36],correlation_matrix:[0,5,7,11,30,33],correspond:[0,3,5,6,8,9,11,12,15,16,17,22,23,24,26,29,30,31,32,35,36],cortex:[12,35,36],cosin:[3,6,32],cost:[0,2,3,5,6,7,8,9,12,13,16,17,19,21,24,29,35],cost_deep_grad:2,cost_funct:2,cost_function_deep:2,cost_function_deep_grad:2,cost_function_grad:2,cost_grad:2,cost_sum:2,costol:[13,21,34,35],could:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,17,23,24,26,29,30,31,32,33,34,35,36],coulomb:[0,29],count:[0,9,25,26,27,29],countor:[13,34],coupl:[4,5,6,31,32],cours:[0,1,3,5,11,24,25,27,30,32],courvil:[21,25,28,29,30,34,35],cov:[5,6,11,23,26,29,30,31,32],cov_xi:[5,11,30],cov_xx:[5,11,30],cov_yi:[5,11,30],covari:[0,7,22,23,29,31,33],covariance_matrix:[5,11,14,30],cover:[0,5,17,22,27,28,30,31],covert:[0,29],covxi:26,covxx:26,covxz:26,covyi:26,covyz:26,covzz:26,cpu:1,cqofi41lfdw:36,craft:3,creat:[1,2,3,4,5,9,10,11,12,22,29,31,33,34,35,36],create_biases_and_weight:[1,36],create_convolutional_neural_network_kera:3,create_neural_network_kera:1,create_x:[5,11,30],credit:[0,7,27,29,33],crim:0,crime:0,criteria:[0,4,9,10,14,26,29],criterion:[9,10,13,33,34],critic:[6,24,30,31],critiqu:24,cross:[0,1,3,7,9,10,13,22,26,29,30,31,34,35,36],cross_entropi:4,cross_val_scor:[6,32,33],cross_valid:[7,10,33],crossvalid:[6,32],crucial:[1,26],cs231:3,cs:[25,27],csr_matrix:[23,29],csv:[0,4,6,7,9,29,32,33],ctnk:1,cubic:0,cumbersom:[5,31,32],cumsum:[10,11,29],cumul:[7,10,26],cumulative_heads_ratio:10,cup:[5,31,32],current:[1,2,3,4,13,14,21,28,33,34,35],curs:[0,30],curv:[6,7,10,12,24,33,35,36],curvatur:[13,33,34,35],custom:[6,14,24],custom_cmap2:[9,10],custom_cmap:[9,10],cutpoint:9,cv:[6,7,10,32,33],cvxbook:[13,33],cvxopt:[5,8,30],cycl:[1,12,35,36],cyclotron:31,d2_g_t:2,d:[1,2,3,4,5,6,7,8,9,10,11,13,14,23,26,27,29,30,31,32,33,34,35,36],d_f:[13,33,34],d_g_t:2,d_net_out:2,da:3,dagger:[5,23,30],dai:[1,9,22,36],damp:3,daniel:27,darget:9,darkr:26,dat:[0,29],dat_id:[0,6,7,9,29,30,32,33],data1:14,data2:14,data3:14,data4:14,data:[2,4,5,8,10,12,13,14,17,18,19,21,23,28,32,34,35],data_id:[0,6,7,9,29,30,32,33],data_indic:[1,36],data_panda:29,data_path:[0,6,7,9,29,30,32,33],databas:[1,36],datafil:[0,6,7,9,24,29,30,32,33],datafram:[0,4,5,7,9,11,29,30,33],datapoint:[1,5,6,7,11,13,30,32,33,34,35,36],dataset:[0,4,6,7,8,9,10,11,13,14,15,16,19,24,29,32,33,34,35],datatyp:4,date:[15,16,17,18,19,20,21,24,29,30,31,32,33,34,35,36],daughter:10,david:[28,29],davison:32,dbh:[1,36],dbo:[1,36],dcomposit:23,ddot:2,dead:1,deadlin:[16,17,18,19,20,21,25],deal:[0,1,3,5,6,8,11,13,14,17,18,23,24,26,29,30,31,33,34,35,36],dealt:0,debt:[7,33],debug:[0,5,6,31,32,33],decad:[0,3,35],decai:[0,13,26,29],decemb:[25,27,29],decent:10,decid:[0,2,3,5,6,9,24,31,32,33],decim:[0,29],decis:[0,1,8,11,22,28,29,36],decision_funct:8,decision_tre:9,decisiontreeclassifi:[9,10],decisiontreeregressor:[0,9,10],decisiontreeregressordecisiontreeregressor:9,declar:[0,4,23,29],decompos:[5,6,23,30],decomposit:[0,6,12,24,29,31,35,36],decompost:[5,30],deconvolut:3,decorrel:[10,13,21,34,35],decreas:[1,2,4,5,6,10,11,13,31,32,33,34,35,36],deduc:[0,29],deep:[3,7,12,13,21,22,25,28,30,34,35,36],deep_neural_network:2,deep_param:2,deep_tree_clf1:9,deep_tree_clf2:9,deep_tree_clf:[9,10],deepen:[5,22,29],deeper:[0,3,4,29],deeplearningbook:[28,29,31],deer:3,def:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,21,24,26,29,30,31,32,33,34,35,36],def_covari:26,default_tim:4,defect:[5,30],defici:[5,30],defin:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,30,31,32,33,34,35],definit:[1,2,5,6,7,8,10,11,12,13,17,23,26,30,31,32,33,34],defint:26,defvjp:2,defvjp_argnum:[],degre:[3,5,6,8,9,10,11,15,16,17,19,24,26,29,31,32,33],deisenroth:30,del:1,delet:6,delimit:4,deliv:[25,29],delta:[0,2,3,6,8,12,13,14,21,29,34,35,36],delta_0:3,delta_1:3,delta_2:3,delta_3:3,delta_4:3,delta_5:3,delta_:[1,23,36],delta_h:[0,1,29,36],delta_j:[3,12,36],delta_k:[12,36],delta_l:[1,3,36],delta_momentum:[13,21,34,35],delta_n:[0,3,29],delug:22,delv:0,demand:[13,33,34],demonstr:[0,3,5,6,7,11,12,22,29,30,31,32,33,36],demystifi:[35,36],den:4,denomin:[1,5,31,32,36],denot:[1,2,6,7,13,26,33,34,35,36],dens:[1,3,4],densiti:[0,2,6,26,29,32],depart:[27,29,30,31,32,33,34,35,36],depend:[0,1,2,4,5,6,7,8,11,12,13,15,21,22,23,24,26,29,30,31,32,33,34,35,36],depict:26,deploy:[0,15,22,24,29],deprec:2,depth:[0,3,9,10,23,32],deriv:[0,1,2,6,7,8,10,11,13,16,17,19,21,22,24,29,35],derivati:[13,34,35],derivative_fn:[13,34],descend:[5,9,11,30,31],descent:[0,1,3,7,8,12,29,30,36],descent_i:[21,35],descent_x:[21,35],describ:[0,2,4,5,6,8,10,11,12,13,18,21,23,24,29,31,32,34,35,36],descript:[0,8,9,29],design:[0,1,3,4,5,6,7,10,11,12,13,15,16,17,18,19,24,29,31,32,33,34,35,36],designmatrix:[0,29],desir:[0,2,4,5,13,14,29,30,33,34],despit:[1,12,35,36],destroi:23,det:[5,23,30],detail:[0,6,11,13,14,23,24,30,33,34],detect:[3,8,12,35,36],determin:[0,2,3,4,5,6,8,9,10,11,12,13,16,23,26,29,30,31,32,33,34,35,36],determinist:[7,13,26,33,34,35],dev:[1,24],develop:[0,3,5,8,10,11,12,21,22,23,24,29,30,31,32,35],deviat:[0,1,2,4,5,6,19,24,26,29,30,31,32],devic:[3,4,14],devis:[12,35,36],df1:29,df:[4,8,11,13,29,34],di:0,diag:[5,8,30,31],diagnost:[1,10],diagon:[0,5,7,13,18,21,23,24,26,29,30,31,33,34,35],diagonaliz:[5,30],diagram:10,diagsvd:6,dice:[6,26,32],dict:[6,8,33],dictionari:0,did:[0,1,5,6,7,10,11,14,24,29,31,32,33,34],die:1,diff1:2,diff2:2,diff:2,diff_ag:2,diffeent:8,differ:[0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,17,21,22,23,24,26,28,29,30,31,32,33,36],differenti:[0,3,16,21,22,23,29,30,33,36],differential_oper:2,difficult:[0,1,6,10,13,21,24,26,29,32,34,35],difficulti:[0,1,13,29,33,34,35],diffonedim:2,digit:[0,1,3,4,6,24,25,27,29,36],dilemma:[13,34,35],dilut:1,dim:[4,11,14,23],dimens:[0,1,2,3,4,5,8,9,11,14,16,17,23,29,30,31,36],dimension:[0,4,5,6,9,11,13,14,19,21,22,23,29,31,32,33,34,35],dimensionless:[0,3,29],diment:23,dimnsion:4,diod:3,direct:[0,1,2,4,7,11,12,13,14,21,29,30,33,34,35,36],directli:[1,4,5,6,26,30,36],directori:[0,7,33],disadvantag:[0,29],disappear:[3,6,32],disc_loss:4,disc_tap:4,discard:[6,11,32,33],disciplin:[0,3,12,35,36],disclaim:26,discord:29,discourag:[13,33,34],discov:[0,29],discover:[5,31],discret:[1,3,5,7,13,31,32,33,34,35],discrimin:[4,7,10,11,33],discriminator_loss:4,discriminator_loss_list:4,discriminator_model:4,discriminator_optim:4,discuss:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,28,29,30,31,32,34,35,36],diseas:[7,33],disguis:[6,30,31],disord:[1,7,33],dispai:[35,36],displai:[0,1,3,4,5,6,7,8,9,10,11,12,14,24,26,29,30,32,33,35,36],displaystyl:[0,5,17,29,30,31],disregard:[0,29],dissimilar:[11,14],dist:14,distanc:[0,8,9,11,14,26],distance_list:9,distinct:[3,7,8,9,10,14,33],distinctli:8,distinguish:[0,4,7,8,26,29,33],distplot:0,distribut:[0,1,4,6,7,10,11,13,14,15,16,18,19,22,23,24,29,30,33,34,36],distrubut:[0,15,22,24,29],dive:[0,8,23,29],diverg:[1,13,33,34,35],divid:[0,1,3,5,6,7,8,9,11,12,26,29,30,31,32,33,35,36],divis:[6,8,9,13,21,23,26,32,33,34,35],dlopen:[3,4,14],dna:[7,33],dnn1:4,dnn2_gru2:4,dnn:[0,1,2,4,12,29,35,36],dnn_kera:1,dnn_model:1,dnn_numpi:[1,36],dnn_scikit:[0,1,29,36],doamin:[31,32],doc:[0,6,16,17,19,20,22,24,25,27,28,29,33,34,35],document:[4,9,11,13,33],doe:[0,1,2,3,4,5,6,8,10,11,12,13,14,16,21,23,24,26,29,32,33,34],doesn:[3,9,12,36],dog:[1,3,4,36],domain:[5,8,13,24,31,32,33,34],domin:[0,29],don:[0,1,3,5,6,7,8,11,13,15,21,22,24,29,30,33,34,35,36],done:[0,2,3,4,5,6,9,10,11,13,17,23,24,29,30,31,32,33,34],dot:[0,2,3,5,6,7,8,9,10,11,12,13,21,23,24,26,29,30,31,32,33,35,36],doubl:[3,4,23,29],doubli:1,doubt:24,down:[0,3,6,9,11,12,13,21,33,34,35,36],download:[0,1,3,5,6,23,24,28,29,36],downsampl:3,dozen:1,dq:[6,32],drag:[13,34,35],dramat:11,drastic:4,draw:[4,6,10,13,32,33,34],drawback:[0,1,3,13,30,33,34,35],drawn:[1,4,6,7,11,26,29,32,33,36],drive:[3,4],driven:3,drop:[0,1,5,6,11,13,21,26,29,30,31,32,34,35],dropna:[0,6,29,32],dropout:4,dt:[2,3,13,26,34,35],dtype:[0,1,2,3,4,14,21,23,29,30,35,36],dual:8,dualiti:6,dub:[0,29],due:[1,2,5,6,8,10,12,13,27,29,30,32,33,34,35,36],dummi:0,dure:[0,1,3,4,8,9,11,17,20,22,24,29,32,34,35],dwell:0,dwh:[1,36],dwo:[1,36],dx:[2,3,8,26],dx_1:26,dx_1p:[6,32],dx_2p:[6,32],dx_mp:[6,32],dx_n:26,dxp:[6,32],dy:[1,8,26],dylib:[3,4,14],dynam:4,dz:8,e:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,19,21,26,27,29,30,31,32,33,34,35,36],e_:[0,2,29],each:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,21,22,23,25,26,27,29,30,31,32,34,35,36],eager:32,eapprox:[0,29],earli:[1,13,21,34,35,36],earlier:[0,5,7,8,9,11,12,13,20,21,29,30,33,34,35,36],earthexplor:[6,24],eas:[6,9,14,32],easi:[0,5,6,7,8,9,10,11,12,13,18,21,22,23,29,30,31,32,33,34,35,36],easier:[5,6,8,9,13,26,29,30,32,34,35],easiest:[13,33,34],easili:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,23,24,29,30,31,32,33,34,36],eastern:[27,29],ebind:[0,29],eblock:9,econometr:29,economi:5,ecosystem:[22,29],ect:25,edg:3,edgecolor:[6,32],edu:[13,33],educ:[0,24,29,33],eff:26,effect:[1,4,10,13,26,34,35,36],effic:[1,36],effici:[0,3,10,13,22,23,26,29,33,34,35],efron:[6,32],egrad:[13,34,35],eig:[5,11,13,21,23,26,29,30,33,34,35],eigen:26,eigenpair:[5,11,30],eigenvalu:[0,5,8,11,13,21,23,29,30,31,33,34,35],eigenvector:[5,11,13,17,30,31,34],eight:[23,29],eigval:[23,26,29],eigvalu:[11,13,21,33,34,35],eigvec:[23,26,29],eigvector:[11,13,21,33,34,35],eispack:[23,29],either:[1,5,6,7,8,9,10,11,13,15,16,24,26,29,30,31,32,33,34,36],elabor:26,elarn:3,electr:[0,3,12,29,35,36],electron:29,eleg:11,element:[1,2,3,4,5,6,7,8,11,12,13,17,18,20,21,22,23,24,25,28,30,31,32,33,36],elementari:[10,13,23,34,35],elementwis:[3,13,34,35],elementwise_grad:[2,13,34,35],elessar:29,elif:[2,14,21,35],elim:23,elimin:[3,8],els:[1,2,3,4,7,9,12,13,14,23,33,34,35,36],elu:1,elus:[0,29],email:[25,27,29],embed:[0,11,30],embodi:[6,19,24,32],emit:26,emner:28,emphas:[0,10,22,29],emphasi:[0,22,28,29],empir:[1,11,26],emploi:[0,1,5,6,11,13,24,26,29,30,31,32,33,34,36],employ:0,empti:[6,10,32],emul:[12,35,36],en:[22,28],enabl:[11,21,35],enbodi:[6,32],encod:[0,3,5,7,9,11,14,17,29,30,31,33],encompass:[0,24,26],encount:[0,1,5,6,7,13,21,26,29,30,32,33,34,35,36],encourag:24,end:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,21,23,24,26,27,29,30,31,32,33,34,35,36],end_box:[],end_nod:2,end_valu:[],endpoint:[3,6],energi:[0,4,6,30,32],enet_coordinate_desc:6,enforc:[12,35,36],eng:28,engin:[0,1,3,4,22,29],english:24,enocurag:24,enoent:[3,4,14],enorm:3,enough:[0,6,13,29,32,33,34],ensembl:[1,9],ensur:[0,1,2,3,5,6,11,13,21,26,30,31,32,33,34,35,36],entail:29,enter:[5,6,17,30,31],enthought:[0,15,22,24,29],entir:[1,3,7,9,22,26,29,33,34,35,36],entiti:[9,12,23,29,36],entri:[0,5,8,11,12,23,29,30,31,32,36],entropi:[1,3,7,10,13,29,34,35,36],enumer:[0,1,2,3,4,6,8,29,30,31,36],env:[0,2,3,4,6,7,8,9,11,14,21,26,29,31,33,35],environ:[2,9,21,22,24,35],eo:[0,6,29,32],eol:[0,29],eosfit:[0,29],epoch:[0,1,3,4,12,13,21,29,34,35,36],epsilon:[0,5,6,7,13,19,24,29,30,31,32,33,34,35],epsilon_0:[0,29],epsilon_1:[0,29],epsilon_2:[0,29],epsilon_:[0,29],epsilon_i:[0,29,30],eq:[3,13,14,23,26,33,34],eqnarrai:[3,5,6,31,32],equal:[0,1,2,3,4,5,6,8,9,11,12,13,14,15,23,24,26,29,30,31,32,33,34,35,36],equat:[1,3,4,5,6,7,8,9,10,11,13,14,16,17,18,19,21,23,24,26,32,35],equilibrium:[2,12,35,36],equiv:[3,13,23,26,33,34],equival:[0,1,5,7,8,11,13,21,22,23,29,30,31,32,34,35,36],erf:26,eriador:29,eridg:29,err:[0,7,10,33],err_:[6,32],err_sqr:2,errat:[13,33,34],errno:[0,3,4,7,14,33],erron:2,error:[1,2,4,5,6,7,9,11,12,13,15,16,17,18,19,21,22,23,24,26,31,33,34,35,36],error_estimate_corr_tim:26,error_hidden:[1,36],error_output:[1,36],escap:[13,33,34,35],especi:[1,3,9,12,13,24,34,35,36],essenti:[0,5,6,9,10,12,14,24,26,30,35,36],establish:[0,6,10,11,15,24,29],estim:[0,1,5,6,7,10,11,13,22,26,29,30,33,34,35,36],estimated_mse_fold:[6,32,33],estimated_mse_kfold:[6,32,33],estimated_mse_sklearn:[6,32,33],et:[0,2,4,15,16,17,24,28,29,30,31,32,33,34,36],eta0:[8,13,33,34],eta:[0,1,3,8,12,13,21,29,33,34,35,36],eta_:[13,21,34,35],eta_t:[13,34,35],eta_v:[0,1,3,29,36],etc:[0,1,3,5,7,8,9,11,12,13,14,15,21,22,23,24,26,30,33,34,35,36],ethic:22,etsim:32,euclidean:[0,14,30],evalu:[0,2,3,4,5,6,9,13,24,26,29,30,31,32,33,34,35],evaluationform:[20,24,34,35],evaluationgrad:[20,24,34,35],evalut:[13,34,35],even:[0,1,3,4,5,6,8,9,10,11,12,13,14,22,23,26,29,30,31,32,33,34,35,36],evenli:4,event:[5,7,10,26,31,32,33],eventu:[0,5,6,11,12,13,24,27,30,31,32,33,34,35,36],everi:[0,1,2,3,4,5,6,9,10,11,12,13,14,22,26,27,29,30,31,32,33,34,35,36],everyth:[4,12,21,36],everywher:[4,13,33,34],evolv:0,exact:[0,5,11,12,13,23,26,29,30,34,36],exactli:[0,3,4,6,12,22,24,30,32,35,36],exam:29,examin:[6,32],exampl:[5,11,12,13,15,16,19,20,22,23,24,26,28],exce:[1,12,13,21,34,35,36],excel:[0,1,4,5,10,29,30],except:[0,3,4,6,7,8,9,23,33],excess:[0,29],excit:0,exclud:[1,6,12,24,30,31,32,33,35,36],exclus:[0,1,3,6,26,29,32,33],execut:[2,5,13,30,34,35],exemplifi:[13,34,35],exercic:[27,29],exercis:[5,22,24,25,27,31,32,33,34,35,36],exercisesweek35:17,exhaust:[6,32,33],exhibit:[0,5,6,8,29,30,32],exist:[0,1,2,3,4,5,6,7,8,9,13,14,18,23,24,29,30,31,32,33,34],exit:[5,23,30],exp:[0,1,2,5,6,7,8,10,11,12,13,15,16,21,24,26,29,30,31,32,33,34,35,36],exp_term:[1,36],expand:[5,7,11,13,30,33,34],expandus:[0,7,33],expans:[0,3,5,8,10,12,13,29,30,33,34,36],expect:[0,1,5,6,7,11,12,13,15,16,19,21,22,24,29,30,33,34,35,36],expectation_value_of_h_wrt_p:26,expens:[6,10,13,33,34,35],experi:[0,1,6,8,13,22,24,29,30,32,33,34,35],experiment:[0,4,6,9,26,29,32],expert:[1,9],explain:[0,6,9,10,11,13,19,24,29,33,34],explained_variance_ratio_:11,explanatori:[0,29],explicit:[0,3,6,13,21,23,24,29,30,31,34,35],explicitli:[0,4,8,21,35],explod:1,exploit:[0,3,12,13,29,34,35,36],explor:[1,4,6,8,13,22,24,33,34,35],expon:[1,36],exponenti:[0,1,5,6,10,13,24,26,29,31,32,33,34,35],export_graphviz:9,export_text:9,exporttext:9,expos:22,express:[0,2,3,5,6,7,10,12,13,16,21,23,24,26,29,31,32,35,36],exptmean:26,exptvari:26,extend:[0,2,7,11,13,17,22,29],extens:[0,12,15,22,29,35,36],extent:[0,1,6,28,32],extern:[3,6,9],extra:[1,3,5,27,29,30,36],extract:[0,3,5,6,7,8,11,13,23,29,30,33,34],extrapol:[0,29],extrem:[0,1,4,5,6,7,8,9,13,16,23,30,31,32,33,34,35],extremum:[13,33,34],extrins:11,ey:[0,5,6,13,14,23,29,31,33,34,35],f11:[0,29],f12:[0,29],f13:[0,29],f1:[13,34,35],f1_grad:[13,34,35],f1d:[13,34],f2:[13,34,35],f2_grad_x1:[13,34,35],f2_grad_x1_analyt:[13,34,35],f2_grad_x2:[13,34,35],f2_grad_x2_analyt:[13,34,35],f3:[13,34,35],f3_grad:[13,34,35],f3_grad_analyt:[13,34,35],f4:[13,34,35],f4_grad:[13,34,35],f4_grad_analyt:[13,34,35],f5:[13,34,35],f5_grad:[13,34,35],f6:[13,34,35],f6_for:[13,34,35],f6_for_grad:[13,34,35],f6_grad_analyt:[13,34,35],f6_while:[13,34,35],f6_while_grad:[13,34,35],f7:[13,34,35],f7_grad:[13,34,35],f7_grad_analyt:[13,34,35],f8:[13,34],f8_grad:[13,34],f9:[0,13,29,34],f9_altern:[13,34],f9_alternative_grad:[13,34],f9_grad:[13,34],f:[0,1,2,3,4,5,6,7,8,10,12,13,14,16,18,19,21,23,26,27,29,30,31,32,33,34,35,36],f_0:[3,10],f_1:[10,13,33,34],f_2:[12,13,33,34,35,36],f_3:[12,35,36],f_:10,f_d:26,f_grad:[13,34,35],f_grad_analyt:[13,34,35],f_i:[0,6,12,16,32,35,36],f_m:[3,10],f_n:3,f_raw:2,f_vec:2,f_wrap:2,face:[13,33,34,35],facecolor:[6,8,26,32],facil:[0,15,22,29,33,34,35],facilit:[12,35,36],fact:[0,1,3,5,9,11,12,13,29,30,31,32,33,34,35,36],factor:[0,1,3,5,6,9,10,11,13,23,26,29,30,31,32,34,35,36],factori:[13,34,35],fade:6,fafab0:[9,10],fahimeh:[27,29],fail:[0,6,8,9,11,13,27,29,32,33,34],fail_on_error:[0,7,33],failur:[7,33],fairli:[1,2,26],faisal:[16,30],fake:4,fake_loss:4,fake_output:4,fall:[8,9,25],fals:[0,1,2,3,4,5,6,7,9,10,14,23,24,29,30,31,32,33,34,35,36],famili:[0,7,8,26,33],familiar:[0,3,5,6,8,15,22,23,24,26,29,31,32],famou:[6,12,36],far:[0,3,4,5,6,8,11,12,13,14,29,30,33,34,35,36],fashion:[0,9,10,29],fast:[1,3,6,10,12,13,22,26,29,32,33,34,36],faster:[1,11,13,34,35],fastest:[13,23,33,34],favor:[7,33],favorit:26,fc:3,fd:[0,7,33],featur:[0,1,3,5,6,7,8,10,11,12,13,18,22,24,26,29,31,32,33,34,35,36],feature_nam:[0,1,7,9,33],feautur:9,fed:[1,36],feed:[0,2,3,11,22,29],feed_forward:[1,36],feed_forward_out:[1,36],feed_forward_train:[1,36],feedback:[4,20,29],feeddorward:4,feedforward:[1,4,12,36],feel:[0,5,6,11,13,15,16,21,22,24,27,29,31,34,35],feet:0,felt:24,fetch:[6,24],few:[1,3,4,5,9,26,29,34,36],fewer:[0,9,11,29],ffnn:[1,12,35,36],field:[0,3,6,12,22,35,36],fifth:[0,6,15,16,24,29],fig:[0,1,2,3,4,6,7,12,13,14,24,29,33,34,35,36],fig_id:[0,6,7,9,29,30,32,33],figaxi:26,figsiz:[0,1,2,3,4,6,7,8,9,10,29,32,33,36],figur:[0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,21,22,24,29,30,31,32,33,34,35,36],figure_id:[0,6,7,9,29,30,32,33],figurefil:[0,6,7,9,29,30,32,33],file:[0,2,3,4,5,6,7,9,14,24,29,30,31,32,33],file_prefix:4,filenam:29,filenotfounderror:[0,7,33],fill:[5,9,30],filter:[0,3,4,7,33],financ:0,find:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,21,22,24,26,29,30,31,33,35,36],fine:[0,14,15,29],finish:2,finit:[3,5,6,12,13,17,26,30,31,32,34,35,36],first:[0,1,2,3,5,6,7,8,9,10,11,13,14,15,16,17,21,23,24,26,27,28,32,35],first_moment:[21,34,35],first_term:[21,34,35],firsteigvector:11,fit:[1,3,4,5,6,7,8,9,11,12,13,15,16,17,21,24,26,30,32,33,34,35,36],fit_beta:[6,30,31],fit_intercept:[0,5,6,30,31,32],fit_mod:9,fit_transform:[0,6,8,9,11,32,33],fiti:[0,29],five:[0,9,17,24,29,30,33],fix:[0,3,4,6,10,11,12,13,21,24,29,32,33,34,35,36],fixedloc:6,flag:4,flat:[3,4,12,13,14,21,33,34,35,36],flatten:[1,3,4,5,23,36],flexibl:[1,6,8,10,12,29,32,35,36],flip:[27,29],float32:[4,9,21,35],float64:[4,21,23,29,30,35,36],floor:[],flop:[5,23,30],flow:[1,4,12,35,36],fluctuat:[5,31],fly:11,fm:[0,29],fmax:3,fmesh:[13,34],fn:7,fname:[0,7,33],focu:[0,3,4,5,6,15,22,28,29,30,31,32],focus:[1,6,7,23,30,31,33,36],fold:[6,9,24],folder:[0,1,3,4,6,14,24,29,32,36],follow:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],font:[0,7,26,29,33],fontdict:26,fontsiz:[1,6,8,9,10,26],fontweight:1,footprint:3,foral:[8,30],forc:[0,5,6,10,11,29,30,31,33],forcast:4,forecast:[4,12,35,36],forest:[0,1,9,22,29],forget:11,form:[0,3,4,5,6,7,8,9,11,12,13,17,21,22,23,24,26,29,30,31,32,33,34,35,36],formal:[3,4,14,26],format:[0,1,2,3,4,6,7,8,9,10,11,22,26,28,30,31,32,33,35,36],format_data:4,formatstrformatt:[6,13,24,33,34],formul:[4,6,11,14],formula:[3,13,26,33,34,35],forth:[4,12,35,36],fortran2003:[22,29],fortran2008:24,fortran90:26,fortran:[0,15,22,23,29],fortun:[0,11,30],forward:[0,3,6,22,23,29,32],foster:29,found:[1,2,3,4,5,6,12,13,14,19,20,24,29,30,31,32,34,35,36],foundat:[22,29],four:[4,5,6,8,12,23,24,25,27,29,31,35,36],fourier:[0,29],fourierdef1:3,fourierdef2:3,fourierseriessign:3,fourth:[12,29,30,36],fp:7,frac:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,19,23,24,26,29,30,31,32,33,34,35,36],fractal:9,fraction:9,frame:[7,33],framework:[1,3,4,8,10,14,26],frank:[5,11,21],frankefunct:[5,6,11,24,30],fredli:[27,29],free:[0,6,11,13,15,16,21,22,23,24,26,27,28,29,34,35],freecodecamp:22,freedom:[5,31],freeli:[0,24],frequenc:[3,6,7,26,32,33],frequent:[0,8,9,13,33,34,35],frequentist:22,fresh:10,fridai:[16,17,18,19,20,21,27,29],friedman:[6,18,24,25,28,29],friendli:4,frodo:29,frog:3,from:[0,1,2,3,4,6,7,8,9,11,13,14,16,17,18,19,22,23,24,26,27,28,29],from_cod:9,from_logit:[3,4],from_tensor_slic:4,fromnumer:2,front:[0,4,5,15,16,29,30,31],fulfil:[2,5,12,30,35,36],full:[0,1,3,5,7,9,10,13,26,29,30,33,34,35],full_matric:[5,30],fulli:[3,6,12,25,26,32,33,35,36],fun:[2,22,29],fun_nam:[],func:2,functionali:11,fundament:[0,6,22,29,32],funtion:2,further:[2,7,9,29],furthermor:[0,3,5,6,7,11,12,13,17,22,24,29,30,31,32,33,34,35,36],futur:[0,4,8,9,29],futurewarn:8,fy:[15,24,25,27,28,29],fys4155:24,fys5419:[28,29],fys5429:[28,29],g0:2,g:[0,1,2,3,4,6,8,9,10,11,13,26,29,31,32,33,34,35,36],g_0:2,g_1:[2,10],g_2:[2,10],g_:[2,9,10],g_analyt:2,g_dnn_ag:2,g_euler:2,g_i:2,g_m:[3,10],g_n:3,g_re:2,g_t:2,g_t_d2t:2,g_t_d2x:2,g_t_dt:2,g_t_hessian:2,g_t_hessian_func:2,g_t_jacobian:2,g_t_jacobian_func:2,g_trial:2,g_trial_deep:2,g_vec:2,gain:[1,5,7,9,10,13,30,31,32,34,35],galleri:[0,29],game:4,gamge:29,gamma1:8,gamma2:8,gamma:[0,2,8,9,10,11,13,21,29,33,34,35],gamma_0:10,gamma_1:10,gamma_1x:10,gamma_:[0,29],gamma_i:[0,8,26,29],gamma_j:[13,34,35],gamma_k:[13,33,34],gamma_m:10,gamma_x:[0,29],gap:[6,8],gate:[4,12],gather:[0,1,12,30,35,36],gaug:[12,35,36],gaussbacksub:23,gaussian:[4,5,6,8,14,26,31,32],gaussian_point:14,gaussian_rbf:8,gave:[13,34,35],gavra:29,gbc:[25,29],gca:[2,6,8,13],gd:[1,33],gd_clf:10,gdclassiffiercgain:10,gdclassiffierconfus:10,gdclassiffierroc:10,gdfit:35,gdm:[13,21,34,35],gdregress:10,ge:[1,5,7,26,30,33],gen:[0,7,33],gen_loss:4,gen_tap:4,gender:[0,29],genener:4,gener:[0,1,2,3,5,6,8,10,11,12,13,14,15,16,17,19,20,21,23,24,26,28,30,31,32,33,34,35,36],generallay:[12,35,36],generate_and_save_imag:4,generate_imag:4,generate_latent_point:4,generate_simple_clustering_dataset:14,generated_imag:4,generator_loss:4,generator_loss_list:4,generator_model:4,generator_optim:4,genom:22,geodes:11,geometr:[0,13,29],geometri:[5,31,32],georg:28,geotif:[6,24],geq:[2,5,8,9,13,30,31,33,34],geron:[0,15,21,25,28,29,34,35],get:[0,1,2,3,4,5,6,7,9,10,11,13,15,20,22,23,24,26,27,29,30,31,32,33,34,36],get_dummi:9,get_paramet:2,get_split:9,get_yaxi:8,get_yticklabel:6,getattr:[],gg:29,gibb:[22,29],gif:4,gini:10,gini_index:9,ginvers:13,git:[0,15,22,29],giter:[13,21,34,35],github:[0,6,9,15,16,17,19,20,21,22,24,25,27,28,29,30,33,34,35],gitlab:[0,15,22,24,29],give:[0,1,2,3,5,6,7,8,9,10,12,13,14,17,22,24,26,29,30,31,32,33,34,35,36],given:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,23,24,26,29,30,31,32,33,34,35,36],global:[6,7,13,24,33,34,35],glorot:1,gnew:13,go:[0,1,3,5,6,8,9,11,12,13,24,29,30,31,32,33,34,36],goal:[0,7,9,29,33],goe:[0,1,2,5,6,13,14,18,23,29,30,31,32,33,34,35,36],golden:[13,34],gone:[5,30,31],gong:[1,36],good:[1,3,4,5,6,9,10,11,13,17,21,22,26,28,30,31,32,33,34,35],goodfellow:[4,25,28,29,30,31,33,34,36],googl:[1,4,21,22,29,35],got:[1,6,13,24,36],gotcha:[21,35],gotten:29,gov:[6,24],gp:28,gpu:[1,13,21,22,29,34,35],grad:[2,13,21,34,35],grad_analyt:[13,34,35],grad_concatenate_arg:[],grade:[24,25],gradient:[0,3,4,7,8,9,12,22,29,30,36],gradient_desc:[21,34,35],gradientboostingclassifi:10,gradientboostingregressor:10,gradients_of_discrimin:4,gradients_of_gener:4,gradienttap:4,gradual:[1,14],grai:[4,6,24],graph:[1,9,11,12,13,33,34,35,36],graph_from_dot_data:9,graphic:[0,1,9,29],grasp:0,gray_r:[1,3,36],grayscal:3,great:[5,13,33,34],greater:[1,7,26,33,36],greatli:[13,34,35],greedi:[9,33],green:[0,3,9,26],grei:4,grid:[1,3,6,7,8,12,26,30,31,32,35,36],gridsearch:33,gridsearchcv:33,grossli:[13,33,34],ground:[0,29],group:[0,6,7,9,14,22,24,25,27,29,32],groupbi:[0,29],grow:[1,3,9,10,36],growth:[0,29],gru:4,guarante:[0,4,13,26,29,30,33,34],guess:[1,4,10,13,14,21,33,34,35,36],guestrin:10,guid:1,guidanc:24,guidelin:[20,34,35],h1:2,h:[0,1,5,6,8,13,16,18,21,24,26,27,28,29,30,33,34,35,36],h_1:[2,13,33,34],h_2:[2,13,33,34],h_:[0,13,29,33,34],h_m:10,ha:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,21,23,24,26,29,30,31,32,33,34,35,36],haa:27,habit:[0,30],had:[0,1,6,7,13,29,32,33,34,36],hadamard:[1,12,13,21,34,35,36],half:[1,8,9],halv:10,hand:[0,1,2,3,5,11,12,13,15,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],handi:[3,24],handl:[0,1,2,5,9,11,22,31],handle_unknown:9,handsid:[12,36],handwrit:[12,35,36],handwritten:[1,5,36],handwrittennot:[33,35],happen:[1,2,3,4,5,6,10,13,26,30,34,35,36],hard:[1,7,8,10,13,33,34,36],hardcopi:[22,29],harder:[0,1,30],harmon:3,hasn:[],hassl:[0,15,22,29],hast:[22,29],hasti:[0,6,15,16,17,18,24,25,28,29,30,32,33],hat:[0,1,5,6,7,9,10,11,12,13,17,18,23,24,30,31,32,34,35,36],have:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23,24,26,27,29,30,31,32,33,34,35,36],haven:[1,36],he:[7,33],head:[0,4,10,26],header:[0,29],heads_proba:10,health:[0,30],hear:[0,13,29,34,35],heart:[0,7,29,33],heatmap:[0,1,3,7,29,33,36],heavili:0,heavisid:[1,36],height:[1,3,6,30,31,36],held:[13,21,34,35],help:[0,1,4,12,13,16,21,24,29,34,35,36],helper:[4,14],henc:[0,5,6,8,9,10,12,13,18,24,29,30,31,32,33,34,35,36],henrik:[27,29],her:[7,33],here:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,26,29,30,31,32,33,34,35,36],hereaft:[0,8,12,29,36],hermitian:23,hessenberg:23,hessian:[0,2,5,13,16,21,31,35],heterogen:[9,10],hi:[7,33],hidden:[1,3,4,12,35,36],hidden_bia:[1,36],hidden_bias_gradi:[1,36],hidden_layer_s:[0,1,29,36],hidden_neuron:4,hidden_weight:[1,36],hidden_weights_gradi:[1,36],hierarch:[5,30,31],high:[0,1,2,3,4,5,6,9,10,11,13,14,21,22,23,24,29,30,32,33,34,35],higher:[0,1,3,5,6,8,13,21,24,29,30,31,32,33,34,35],highest:[1,2,36],highli:[0,3,4,10,18,22,23,28,29,30,31,32],highwai:0,hing:8,hint:[13,16,30,31,33,34],hip:22,hire:0,hist:[4,6,7,26,32,33],histogram:[0,6,7,26,33],histor:[7,11,33],histori:[3,4,12,35,36],hitherto:[5,31],hjorth:[27,29,30,31,32,33,34,35,36],hobbi:26,hoc:[5,30],hoff:28,hold:[1,3,6,13,14,21,32,33,34,35,36],holder:[0,29],holomorphic_grad:2,home:0,homepag:[24,29],homework:[6,13],homogen:[1,3,9,10,13,21,34,35],honchar:2,hopefulli:[0,11,26,29,35],horizont:11,hors:[3,7,33],hot:[1,9,36],hour:[1,22,25,26,27,29,36],how:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,21,22,23,24,26,29,30,31,32,34,35,36],howev:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,22,23,24,26,29,30,31,32,33,34,35,36],hspace:[0,4,8,10,26,29],hstack:1,htf:[25,29],html:[0,9,11,17,19,22,24,25,27,28,29,31,36],http:[0,3,4,6,9,11,13,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,35,36],huang:[0,29],huber:[0,29],huge:[1,3,4,22,36],human:[0,1,3,6,9,12,30,31,35,36],humid:9,hundr:1,hungri:1,huse:29,hvae:35,hybrid:25,hydrogen:[0,29],hyper:21,hyperbol:[1,4,12],hyperparam:8,hyperparamet:[3,4,5,6,9,13,17,29,30,31,33,34,35],hyperplan:11,i0:[0,29],i1:[0,6,8,12,29,30,31,35,36],i2:[0,8,12,29,35,36],i3:[0,12,29,35,36],i5:[0,29],i:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,27,29,30,31,32,33,34,35,36],i_1:[5,6,31,32],i_2:[5,6,31,32],i_:[13,33,34],ian:28,ic:[1,36],id:[7,13,33,34,35],ida:[27,29],idea:[0,1,2,3,4,6,9,10,12,13,23,24,30,31,32,33,34,35,36],ideal:[0,2,6,8,13,26,29,32,35],idem:[6,32],ident:[5,6,12,13,17,23,24,30,34,35,36],identical:[31,32],identifi:[0,1,7,9,11,12,13,14,29,30,33,34,35,36],ieor:26,ifi:28,ifs:[22,29],ignor:[0,1,3,9,30],ii:[23,26],iii:[23,29],ij:[0,1,3,6,8,12,14,16,18,23,24,26,29,30,31,35,36],ik:[0,23,29,30],ilg3ggewq5u:36,illustr:[5,7,10,12,13,14,22,29,32,33,34],ilsvrc:[34,35],im:6,imag:[1,3,4,6,9,11,12,14,28,29,35,36],image_at_epoch_:4,image_batch:4,image_height:3,image_path:[0,6,7,9,29,30,32,33],image_width:3,imageio:[6,24],images_from_seed_imag:4,imagin:1,immedi:[0,3,4,6,15,22,29],implement:[0,2,3,4,5,6,8,9,10,11,12,13,14,17,21,24,26,29,30,31,33,34],impli:[3,5,6,7,13,23,30,31,32,33,34],implicit:3,implicitli:[11,26],importantli:3,impos:[0,6,11,12,29,35,36],imposs:[0,5,29,30],impress:[0,12,29,35,36],improv:[0,4,5,9,10,11,13,21,24,30,35],impur:9,imread:[6,24],imshow:[1,3,4,6,24,36],in1:[],in2:[],in3050:[28,29],in3310:29,in4080:[28,29],in4300:[28,29],in4310:28,in5400:3,in5550:28,in_out_neuron:4,inaccur:[13,33,34],inact:[12,35,36],inadequ:[0,29],inch:[6,30,31],includ:[0,1,2,3,4,5,6,7,11,12,15,16,17,20,22,24,26,27,28,29,30,31,32,36],include_bia:[6,9,32],inclus:[17,35],incom:[12,35,36],incorrect:[1,36],incoveni:8,increas:[0,1,3,4,5,6,8,9,11,12,13,21,24,26,29,30,31,32,34,35,36],increasingli:26,increment:34,ind:6,inde:[0,2,4,5,6,13,29,30],indefinit:4,independ:[0,5,6,7,8,12,13,26,29,30,33,34,35,36],index:[0,1,3,4,10,14,22,23,26,28,29,36],index_col:[0,29],indic:[0,1,3,4,5,6,9,10,11,13,16,21,24,29,30,34,35,36],indispens:[6,32],individu:[1,6,7,10,12,26,29,30,32,33,35,36],indu:0,indx1:2,indx2:2,indx3:2,indx:23,ineffici:[3,13,34,35],inequ:[8,13],inequaltii:[33,34],inertia:[13,21,34,35],inf1000:[22,29],inf1100:[22,29],inf1100l:[22,29],inf1110:[22,29],inf3000:29,infeas:9,infer:[0,1,4,6,28,29,32,36],inferenc:1,infil:[0,6,7,9,29,32,33],infin:[5,6,7,11,18,30,31,32,33],infinit:3,infinitesim:26,influenc:[6,10,32,33],influenti:[1,36],info:29,inform:[0,1,3,4,6,9,11,12,13,14,21,23,24,28,29,32,33,34,35,36],infti:[3,6,13,26,32,33,34],ingeni:[13,33,34,35],ingrad:2,ingredi:[0,9,29],inher:[6,32],inherit:[23,29],initi:[0,1,2,6,10,13,14,23,26,29,32,33,34,35,36],inject:14,inlin:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],inner:[0,13,30,34],inp:4,inplac:13,input:[0,1,3,4,5,6,7,8,12,13,14,21,24,26,29,30,31,32,33,34,35,36],input_dim:1,input_shap:[3,4],inputs:1,inputs_shuffl:[0,1,30,36],insert:[3,5,6,8,10,26,30,31,32],insid:[0,4,7,33],insight:[0,1,5,21,22,29,30,31,32],insist:[6,13,30,31,34],inspect:33,inspir:[0,1,12,29,35,36],instabl:2,instal:[0,1,5,6,9,15],instanc:[0,1,2,4,6,9,11,13,29,30,32,33,34,36],instanti:10,instead:[0,1,2,3,4,5,6,8,9,11,13,14,21,23,24,26,29,30,32,33,34,35,36],institut:[1,36],instruct:[0,1,15,16,29],int32:10,int_0:26,int_:[3,6,26,32],int_a:26,intak:[0,30],integ:[1,2,13,14,23,26,29,34,35,36],integer_vector:[1,36],integr:[3,6,26,29,32],intellig:[0,14,28,29],intend:10,intens:1,intention:14,interact:[0,6,9,12,22,24,29,35,36],intercept:[0,6,8,11,13,16,24,29,31,32,33,34,35],intercept_:[0,6,8,9,13,29,30,31,33,34],interchang:[5,12,23,31,32,35,36],interconnect:1,interest:[0,1,2,3,4,5,6,7,8,9,12,21,22,24,26,29,30,31,32,33,34,35,36],interfac:[0,1,23,30,36],interior:[0,9,29],intermedi:[23,30],intern:[1,2,10,12,35,36],interpol:[1,3,4,6,12,24,35,36],interpr:[5,30,31],interpret:[0,1,6,9,10,12,13,17,19,23,24,26,36],interv:[0,3,5,6,7,13,18,24,26,29,30,31,33,34],intial:[13,33,34],intract:[0,4,30],intrins:[3,11,23,26,29],intro:[22,28,29],introduc:[0,1,5,6,8,10,12,17,23,24,26,29,32,33,36],introduct:[1,2,4,13,17,20,28,30,33,34],introductori:[0,4,23,28,29,30],intuit:[0,5,6,8,12,13,21,24,29,31,32,34,35,36],inv:[0,5,13,21,29,30,31,33,34,35],invalid:[1,8,36],invalu:[0,13,15,22,29,33,34],invari:[1,36],invd:[5,31],inver:[8,35,36],invers:[0,3,6,13,15,16,17,21,24,29,30,33,34,35],inverse_transform:8,invert:[0,5,7,10,13,21,29,31,33,34,35],invh:[13,21,34,35],invok:[0,8],involv:[0,2,6,7,11,12,30,32,33,34,35,36],io:[0,17,19,22,24,25,27,28,29,30],ion:35,ip:[0,8,26,29],ipca:11,ipykernel_12550:[],ipykernel_12588:36,ipykernel_1323:[],ipykernel_1390:[],ipykernel_1539:[],ipykernel_1579:[],ipykernel_58656:[],ipykernel_58739:[],ipykernel_58840:[],ipykernel_58862:[],ipykernel_6316:[],ipykernel_6403:[],ipykernel_6690:[],ipykernel_6729:[],ipykernel_95354:1,ipykernel_95419:6,ipykernel_95519:29,ipykernel_95542:32,ipynb:[22,24,29],ipython:[0,5,7,9,11,14,15,22,24,29,30,33],iq:[6,32],iri:[8,9],irreduc:[6,32],irrelev:[5,30],irrespect:[0,29],isbox:[],iscomplexobj:2,iseffici:[34,35],isn:[5,31,32],isnul:0,isomap:11,isotop:[29,33,34],issu:[1,9,23,31],it_arrai:[13,34],item:[0,13,29,34],items:[23,29],iter:[1,2,4,6,8,9,11,13,14,21,26,32,33,35,36],its:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,18,22,23,24,26,29,31,32,33,34,35,36],itself:[5,6,12,19,24,26,30,31,32,36],j1:23,j:[0,1,2,3,4,5,6,8,9,11,12,13,14,16,17,18,19,23,24,26,28,29,30,31,32,33,34,35,36],j_:6,j_lasso_sk:6,j_ridge_sk:6,j_sk:6,jackknif:[6,22,29,32],jacobian:[2,13,33,34],jacobian_shap:[],jakobsen:27,jason:4,jax:[22,29],jax_descend_i:[21,35],jax_descend_x:[21,35],jax_enable_x64:[21,35],jax_grad:[21,35],jensen:[27,29,30,31,32,33,34,35,36],jerom:[18,24,28],ji:[12,23,36],jit:[13,34],jj:[0,5,6,29,31,32],jk:[0,1,6,12,23,29,35,36],jl:[0,29],jm:23,jnp:[13,21,34,35],job:[2,8,10],johansen:29,join:[0,3,4,6,7,9,14,29,30,32,33],joint:[4,5,31,32],judg:[13,33,34],judgement:[6,24],julia:[22,23,24],jump:[24,26],junk:4,jupit:29,jupyt:[0,9,15,19,22,24,28,29],just:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,22,24,26,29,30,31,32,33,34,35,36],justif:0,justifi:[3,10],k0:[7,33],k1:[7,33],k:[0,1,3,5,6,7,8,9,10,11,12,13,14,22,23,24,26,27,29,30,31,34,35,36],kaggl:[6,24],kappa_d:26,karl:[27,29],karush:8,katrin:[27,29],keep:[0,1,4,5,6,11,13,14,23,24,29,30,31,32,33,34,35],keepdim:[1,2,6,10,23,32,36],kei:[0,1,3,6,12,30,35,36],kept:[4,6,14,32],kera:[0,4,22,24,29],kernel:[0,1,3,4,14,22,29,30],kernel_librari:[3,4,14],kernel_regular:[1,3],kernel_s:4,kernelpca:11,kev:[0,29],kevin:[28,29],keyboardinterrupt:[1,2,36],keyerror:[],keyword:[6,13,23,29],kfold:[6,32,33],kg:[1,36],ki:23,kick:[1,13,34,35],kiener:2,kilomet:[6,30,31],kind:[0,2,3,4,8,12,13,14,29,30,34,35,36],kj:[6,12,23,30,31,36],kjm:[22,29],kkt:8,kl:26,km:[12,29,35,36],kmean:14,kmeanspoint:14,kn_k:14,know:[0,1,2,5,6,8,13,22,29,30,31,33,34,35],knowledg:[0,22,29],known:[1,3,4,5,6,7,8,9,12,23,24,26,28,30,31,32,33,35,36],kondev:[0,29],kp:26,kpca:11,kroneck:14,kuhn:8,kvalsund:[27,29],kwarg:2,kwown:[0,29],l0:[7,33],l1:[0,1,3,7,29,33],l1_l2:[1,3],l1regl:5,l2:[1,3,36],l:[0,1,2,3,5,6,7,8,10,11,12,13,19,23,24,26,29,30,33,34,35],l_1:[7,33],l_2:[7,13,33,34],l_:23,l_j:[12,36],la:[13,34],la_i:[12,36],la_k:[12,36],lab:[20,22,24,29],label:[0,1,2,3,4,5,6,7,8,9,10,12,13,14,21,22,23,24,26,29,30,31,32,33,34,35,36],label_prob:[34,35],labelencod:[7,10,33],labels:[6,8,9],labels_shuffl:[0,1,30,36],laboratori:[25,31],lack:[0,29],lagari:2,lagrang:[8,11],lambda:[0,1,2,3,5,6,7,8,10,12,13,17,18,21,24,26,29,30,31,32,34,35,36],lambda_0:11,lambda_1:[5,8,11,30],lambda_2:[8,11],lambda_:11,lambda_i:[8,11],lambda_iy_i:8,lambda_jy_iy_j:8,lambda_k:8,lambda_n:[5,8,30],lamda:1,land:[0,8],landmark:8,landscap:[13,21,33,34,35],langl:[0,6,11,26,29,30],languag:[0,1,4,8,15,22,23,24,28,29],lapack:[23,29],laplac:[5,31,32],laptop:22,larg:[0,1,2,4,5,6,8,9,10,11,13,15,22,23,24,26,28,29,30,32,33,34,35,36],larger:[0,3,5,6,8,10,11,13,17,26,29,30,31,32,33,34,35],largest:[4,8,11],lasso:[0,7,22,29],lasso_sk:6,last:[0,1,2,3,4,5,6,7,8,10,12,13,14,17,18,23,24,26,27,29,31,32,34,36],latent:4,latent_dim:4,latent_point:4,latent_space_value_rang:4,later:[0,1,4,7,8,12,13,14,15,22,24,29,33,34,35,36],latest:[4,22],latest_checkpoint:4,latex:29,latter:[0,3,6,7,8,11,13,16,23,24,26,29,30,31,32,33,34,35],lattic:[12,35,36],law:0,lax_numpi:[21,35],layer:[0,4,13,21,29,34,35],lbfg:[7,9,10,11,33],lcc:[5,6,31,32],lda:11,ldot:[0,6,11,19,24,29,32,33],le:[5,7,10,13,17,21,26,30,31,33,34,35],lead:[0,1,3,5,6,7,8,9,10,11,12,13,16,17,23,26,29,30,31,32,33,34,35,36],leaf:9,leaki:1,leakyrelu:4,lear:[13,33,34],learn:[3,4,5,6,7,8,9,10,12,18,23,25,27,28],learnabl:3,learner:10,learnig:29,learning_r:[8,10,21,35],learning_rate_init:[0,1,29,36],learning_schedul:[13,21,34,35],learnt:24,least:[0,7,8,10,11,15,16,17,19,21,22,23,26,32,33],leat:[13,21,34,35],leav:[0,1,3,5,6,9,11,29,31,32,33],lectur:[0,1,5,10,11,12,13,15,17,21,22,23,24,25,27,28],lecturenot:[0,17,19,22,24,28,29],left:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,16,17,19,23,24,26,29,30,31,32,33,34,35,36],leftarrow:[8,12,36],legend:[0,2,3,4,5,6,7,8,9,10,13,29,30,31,32,33,34,35],len:[0,1,2,3,4,5,6,8,9,10,11,12,23,29,30,31,32,34,35,36],length:[0,1,2,3,4,8,9,13,16,22,29,30,33,34,35,36],length_of_sequ:4,leq:[0,5,7,8,13,14,26,29,30,31,33,34],less:[0,1,3,4,5,6,8,9,13,22,26,29,30,31,32,33,34,35],lessen:1,let:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,23,26,29,30,31,32,33,34,35,36],letter:[0,16,23,26,29,30],level:[0,1,5,6,9,22,23,24,25,27,29,32],li:[8,11],lib:[0,2,3,4,6,7,8,9,11,14,21,29,31,33,35],liblinear:[8,10],libmetal_plugin:[3,4,14],librari:[0,1,2,3,4,5,6,7,9,10,11,14,15,21,23,24,26,28,30,31,33,36],library_loc:[3,4,14],licens:[0,1,15,22,24,29],lie:[0,6,11,26,29,30,32],life:[0,1,8,12,29,35,36],lifetim:[13,34,35],like:[0,1,2,3,4,5,6,7,9,10,11,12,13,15,16,21,22,23,24,26,29,30,31,32,33,34,35,36],likelihood:[0,1,5,9,29,30,34,35,36],lim_:26,lima:27,limit:[0,5,6,8,9,11,12,21,23,24,29,30,36],lin_clf:8,lin_model:0,lin_reg:9,linalg:[0,2,5,6,8,11,13,21,23,26,29,30,31,33,34,35,36],line1:8,line2:8,line2d:[21,34,35],line3:8,line:[0,1,2,3,4,6,7,8,10,11,13,14,21,24,29,30,31,32,33,34,35,36],linear:[1,3,5,6,7,9,10,11,12,17,18,21,22,24,26,32,34,35,36],linear_model:[0,5,6,7,8,9,10,11,13,29,30,31,32,33,34,35,36],linear_regress:[6,32],linearli:[5,30],linearloc:[6,13,24,33,34],linearregress:[0,6,7,9,29,30,31,32,33],linearsvc:8,lineat:31,liner:[1,3,36],linerar:10,linewidth:[0,2,4,6,8,9,10,24,32],link:[0,4,9,12,22,24,27,29,36],linlag:[5,31],linpack:[23,29],linreg:[0,29],linspac:[0,2,3,4,6,8,9,10,13,15,16,21,23,26,29,30,31,32,34,35],linu:4,linux:[0,1,15,22,24,29],liquid:[0,29],list:[0,1,2,3,4,7,9,22,24,29,30,33,34,35,36],listcomp:[],listedcolormap:[9,10],literatur:[1,7,14,28,32,33],littl:[1,3,9,12,36],live:8,ll:[0,26,29,30],lle:[0,30],lloyd:[4,14],lmb:[0,2,5,6,31,32,33],lmbd:[0,1,3,29,36],lmbd_val:[0,1,3,29,36],lmbda:[13,33,34],ln:[1,13,33,34,36],load:[0,1,3,4,6,7,9,10,14,24,33],load_boston:0,load_breast_canc:[1,7,9,10,11,33],load_data:[3,4],load_digit:[1,3,36],load_iri:[8,9],load_librari:[3,4,14],load_pluggable_device_librari:[3,4,14],loc:[0,3,6,7,8,9,10,29,32,33],local:[0,1,2,3,7,12,13,30,33,34,35,36],locat:[2,3,8],log10:[0,5,6,31,32,33],log:[0,1,2,4,5,6,7,9,10,11,13,23,24,29,30,31,32,33,34,35,36],log_:[0,29],log_clf:10,logaddexp2:[],logaddexp:[],logarithm:[0,5,7,23,29,31,32,33],logbook:24,logic:[0,1,9,29],logist:[0,1,2,8,9,10,11,12,13,21,22,30],logistic_predict:[34,35],logisticregress:[7,9,10,11,33,35,36],logit:[7,33],logreg:[7,9,10,11,33,35,36],logspac:[0,1,3,5,6,29,31,32,33,36],longer:[2,3,8,10,14,23,26,29],loocv:[6,32,33],look:[0,1,2,3,4,5,6,7,8,9,10,11,13,16,18,21,23,24,26,29,30,31,32,33,34,35],loop:[1,4,6,10,12,14,22,23,29,32,36],lose:[1,36],loss:[0,1,3,4,5,6,7,8,10,11,13,23,24,29,31,32,35,36],loss_fil:4,lossfil:4,lost:4,lot:[0,1,4,6,32,34,35],low:[0,6,9,10,11,24,29,30,32],lower:[0,1,3,6,9,10,16,23,30],lowercas:[23,29],lowest:[9,13,26,34,35],lr:[1,3,4,10],lstat:0,lstm:4,lstm_2layer:4,lstsq:[0,29,30],lt:[6,32],lu:[0,5,29,30],lubksb:23,luckili:2,ludcmp:23,lux:23,lvert:[1,36],lw:[0,29],m:[0,1,2,3,5,6,8,9,10,11,12,13,21,23,25,26,27,28,29,30,31,32,33,34,35,36],m_1:14,m_:[9,12,36],m_h:[0,29],m_k:14,m_l:[12,36],m_n:[0,29],m_p:[0,29],m_t:[13,34,35],ma:11,machin:[1,3,4,5,6,7,9,10,11,12,15,21,23,25,28,30,31,32,35,36],machinelearn:[0,6,16,17,19,20,22,24,25,27,28,29,33,34,35],mackai:28,made:[0,1,3,4,5,6,7,9,11,12,18,24,29,30,33,35,36],mae:[0,29],magic:4,magnitud:[1,6,7,13,30,31,33,34,35,36],mai:[0,1,2,3,5,6,7,8,9,11,12,13,18,21,22,23,24,26,29,30,31,32,33,34,35,36],mail:[25,27],main:[0,1,3,4,5,6,7,9,23,24,28,30,33],mainli:[0,5,6,7,9,29,30,31,32,33],maintain:[6,32],major:[1,6,9,10,13,23,29,32,33,34,35,36],make:[1,2,3,4,5,6,7,8,11,12,13,21,22,23,24,26,28,31,32,33,34,35,36],make_axes_locat:6,make_classif:[35,36],make_moon:[8,9,10],make_pipelin:[0,6,10,30,32],make_vjp:2,makedir:[0,6,7,9,29,30,32,33],makeplot:[0,29],malcondit:23,malign:[1,7,9,33],mammographi:[5,31,32],manag:[0,2,3,15,22,24,29],mandatori:[27,29],mani:[0,1,3,4,5,6,7,8,9,11,13,14,21,22,23,24,26,28,29,30,31,32,33,34,35],manifold:11,manner:3,manual:[6,30,31,33],map:[0,1,2,6,7,8,11,12,14,24,26,29,33,35,36],marc:30,margin:[0,5,8],marit:[0,29],mark:29,marker:[0,7,21,23,29,33,35],markov:[22,29],marsaglia:26,mass:[0,1,5,13,30,34,35,36],massag:[0,29],masses2016:[0,29],masses2016ol:[0,29],masses2016tre:0,masseval2016:[0,29],master:[6,16,20,24,25,27,33,34,35],mat1100:[22,29],mat1110:[22,29],mat1120:[22,29],mat:[22,29],match:[1,4,5,13,14,30,33,34,35],match_complex:[],materi:[4,5,7,13,17,23,27,34,35],math:[3,7,12,13,21,23,26,28,29,33,34,35,36],mathbb:[0,4,5,6,7,8,11,12,13,14,17,18,19,23,24,26,29,30,31,32,33,34,35,36],mathbf:[0,5,6,7,8,13,18,19,21,23,24,29,30,31,32,33,34,35],mathcal:[1,5,6,7,13,19,24,31,32,33,34,36],matheemat:3,mathemat:[0,6,11,12,13,17,22,23,26,28,29,31,33],mathemati:29,mathmlbook:16,mathrm:[0,1,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,24,26,29,30,31,32,33,34,35,36],matmul:[1,2,5,31,36],matnat:28,matplotlib:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,21,22,23,24,26,29,30,31,32,33,34,35,36],matric:[0,1,3,4,6,7,8,11,13,16,17,22,30,33,34],matrix:[0,2,3,4,6,7,8,10,13,15,16,17,18,19,21,24,26,32],matshow:1,matter:[2,3,13,30,33,34,35],max:[0,1,2,3,4,9,10,12,13,21,27,29,33,34,35,36],max_depth:[0,9,10],max_diff1:2,max_diff2:2,max_diff:2,max_it:[0,1,8,9,11,13,29,33,34,35,36],max_iter:14,max_leaf_nod:10,max_sampl:10,maxdegre:[0,6,10,30,32],maxdepth:10,maxim:[1,4,5,7,8,11,31,32,33,36],maximum:[0,2,3,5,7,8,9,10,13,14,29,30,34,35],maxpolydegre:[5,6,31,32,33],maxpooling2d:3,mbox:[5,6,18,24,30,31,32],mcculloch:[12,35,36],md:[11,20,24,34,35],mdoel:4,mean:[1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,26,29,32,34,35,36],mean_absolute_error:[0,29],mean_divisor:14,mean_i:26,mean_matrix:14,mean_squared_error:[0,4,6,7,10,29,30,32,33],mean_squared_log_error:[0,29],mean_vector:14,mean_x:26,meaning:[0,4,7,29,33],meansquarederror:[0,29],meant:[2,3,7,10,13,33,34,35],measur:[0,1,2,5,6,9,11,12,14,19,24,26,29,30,31,32,36],mechan:[0,4,26,29],median:[0,29,30],medicin:[12,35,36],medium:[4,8,13,34,35],medv:0,meet:[0,27],mehta:[0,29,30,31],memori:[3,4,11,12,13,21,23,34,35,36],mention:[0,12,13,24,26,29,33,34,35,36],mere:[0,15,29],meshgrid:[2,5,6,8,9,10,11,24,30],messag:[5,13,34,35],messi:2,met:[0,3,8,30],metadata:2,meteorolog:9,meter:[6,30,31],method:[0,1,2,3,4,5,7,8,11,12,14,16,17,18,19,22,23,26,28,30,31,36],metion:[6,24],metric:[0,1,3,6,7,9,10,14,15,16,29,30,32,33,36],metropoli:[22,29],mev:[0,26,29],mgd:[13,34,35],mglearn:[22,29],mgrid:[13,34],mhjensen:[2,3,4,6,8,9,11,14,21,35],mi:10,mia:[27,29],michael:36,michigan:[29,31,33,34,35],microsoft:28,mid:[1,36],midel:4,midnight:[16,17,18,19,20,21],midpoint:9,might:[0,1,2,4,6,9,13,30,31,33,34,35],mild:9,millimet:[6,30,31],million:[0,29,30,34,35],mimic:[12,35,36],min:[0,2,5,8,9],min_:[0,2,5,14,17,29,30,31],min_samples_leaf:9,mind:[0,6,13,24,29,30,31,32,33,34],mindboard:4,mine:[22,29],mini:[1,11,12,13,21,33,36],minibatch:[1,11,13,36],minibathc:[13,34,35],miniforge3:[0,2,3,4,6,7,8,9,11,14,21,29,31,33,35],minim:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,17,18,21,24,30,31,32,34,35,36],minima:[0,1,7,13,29,33,34,35,36],minimum:[0,1,2,6,8,9,11,13,30,32,33,34,35,36],minmaxscal:[0,30],minor:26,minst:1,minu:[7,33],mirjalili:29,mirror:9,misc:[6,24],misclassif:[8,9,10],misclassifi:[8,10],miser:0,mismatch:1,miss:[0,7,10],mistak:4,mit:28,mix:[1,2,29],mixtur:[13,21,34,35],mk:[9,23],mkdir:[0,6,7,9,29,30,32,33],ml:[0,1,10,13,23,24,30,33,34,35],mlab:26,mlbook:29,mle:[5,7,33],mlp:[1,35],mlpclassifi:[1,35,36],mlpregressor:[0,29],mm:23,mml:30,mn:[12,26,35,36],mnist:[1,11,36],mod:26,mode:[25,27,29],model:[2,3,5,7,8,9,10,11,13,14,15,16,18,19,21,22,24,26,28,30,31,32,33,34],model_select:[0,1,3,5,6,7,9,10,11,29,30,31,32,33,36],moder:10,modern:[0,6,7,22,29,32,33],modif:[2,12,13,34,35,36],modifi:[0,1,3,5,7,8,10,12,13,29,30,31,33,34,35,36],modul:[0,9,11,23,29,31],modular:26,modulo:26,moe:[11,30],moment:[5,6,13,21,26,31,32],mondai:29,monitor:[13,21,34,35],monoton:[5,12,26,31,32,35,36],mont:[0,6,22,26,28,29,32],moor:[5,6,31],more:[0,1,2,4,5,7,8,9,10,11,12,13,14,18,22,26,36],moreov:[0,3],morten:[27,29,30,31,32,33,34,35,36],most:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,22,24,26,29,30,31,32,33,34,35,36],mostli:[1,11],motion:[0,13,34,35],motiv:[1,4],move:[0,4,5,6,7,9,12,13,14,21,24,26,30,31,32,33,34,35,36],mpl:[0,7,29,33],mpl_toolkit:[2,6,13,24,33,34],mplot3d:[2,6,13,24,33,34],mplregressor:[1,36],mse:[0,4,5,6,9,10,15,16,17,19,24,29,30,31,32,33],mse_simpletre:10,mselassopredict:[5,31],mselassotrain:[5,31],mseownridgepredict:[6,31],msepredict:[5,31],mseridgepredict:[0,5,6,31,33],msetrain:[5,31],msle:[0,29],mt:[7,12,33,35,36],mu0:26,mu1:26,mu2:26,mu:[0,6,11,13,26,29,32,34,35],mu_1:30,mu_:[6,26,30,31,32],mu_i:[6,30,31],mu_n:11,mu_x:26,much:[0,1,2,3,4,5,6,8,9,10,11,12,13,23,24,26,29,30,31,32,34,35,36],multi:[0,1,3,7,22,29,33],multiclass:[1,7,33,36],multidimension:[11,12,29,35,36],multilay:1,multinomi:[7,33],multipl:[2,4,5,6,7,12,13,26,30,32,33,34,35],multipli:[3,5,6,11,13,23,26,30,31,34],multiplum:8,multivari:[0,2,10,11,22,26,29],multivariate_norm:[11,14],murphi:[11,28,29],must:[1,2,5,6,8,10,12,13,14,26,30,32,33,34,35,36],mutat:[7,33],mutual:[1,3,6,13,32,33,34],mx_:26,myenv:[0,2,3,4,6,7,8,9,11,14,21,29,31,33,35],myriad:[0,15,22,29],mz1:26,mz2:26,n1:23,n2:23,n:[0,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,21,23,24,26,29,30,31,32,33,34,35,36],n_0:[12,26,35,36],n_:[1,2,3,8,12,26,35,36],n_boostrap:[6,10,32],n_bootstrap:[6,32],n_categori:[1,3,36],n_cluster:14,n_compon:11,n_data:35,n_epoch:[13,21,34,35],n_estim:10,n_examples_to_gener:4,n_featur:[1,36],n_filter:3,n_hidden:2,n_hidden_neuron:[0,1,29,36],n_i:26,n_input:[0,1,3,30,36],n_instanc:9,n_iter:[33,34],n_iter_i:[9,11],n_job:10,n_k:14,n_l:[12,26,35,36],n_layer:1,n_m:9,n_neuron:1,n_neurons_connect:3,n_neurons_layer1:1,n_neurons_layer2:1,n_point:14,n_sampl:[6,8,9,10,14,32,35,36],n_split:[6,32,33],n_step:4,n_t:2,n_x:2,nabla:[1,13,33,34,36],nabla_:[2,13,21,33,34,35],nabla_w:[13,34,35],nag:[13,34,35],naimi:[0,29],naiv:[7,33],naive_kmean:14,najafi:[27,29],name:[0,1,3,4,5,6,7,8,9,10,12,13,14,15,22,23,24,26,27,29,30,31,32,33,34,35,36],nameerror:[10,24],namespac:[3,4,14],narrow:[13,34,35],nary_f:2,nary_op_arg:2,nary_op_kwarg:2,nary_oper:2,nation:[1,5,31,32,36],nativ:[22,29],natur:[0,1,4,8,9,12,13,24,26,28,29,33,34,35,36],navier:[12,35,36],nb:26,nb_:23,nbconvert:29,nbviewer:9,nd:14,ndarrai:[2,6],ndim:[],ne:[9,10,23,26,30],nearest:[1,3,6,11,36],nearli:[13,33,34],neat:29,neatli:[],neccesari:[6,32],necess:2,necessari:[0,1,3,4,8,14,29,36],necessarili:[0,4,11,26,29],necesserali:[5,31,32],neck:[7,33],need:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,21,23,26,30,31,32,33,34,35,36],neg:[0,1,3,5,6,7,10,13,23,26,29,31,32,33,34,35,36],neg_mean_squared_error:[6,32,33],neglect:26,neglig:26,neighbor:[3,6,11],neither:[4,13,34,35],neq:[13,14,26,33,34],nervou:[12,35,36],nest:[2,9,12,35,36],nesterov:[13,34,35],net:[2,4,12,35,36],netlib:[23,29],network:[0,9,13,21,22,28,30,34],neural:[0,13,21,22,28,30,33,34],neural_network:[0,1,2,29,35,36],neuralnetwork:[1,36],neuralnetworksanddeeplearn:36,neuron:[1,2,3,4,12],neutral:[0,29],neutron:[0,29],never:[1,4,6,9,26,32,36],new_box:2,new_chang:[13,21,34,35],new_hobbit:29,new_root:[],new_trac:[],newaxi:[0,3,6,9,32,33],newli:[0,29],newton:[1,7,8,13,26,36],next:[0,1,2,3,4,5,6,7,8,9,13,14,21,29,30,31,33,34,35,36],next_guess:[13,34],next_input:4,ng:[1,36],ngini:9,ni:14,nice:[0,1,5,11,29,30,31,32,36],nielsen:36,niter:[13,21,33,34,35],nitric:0,nlambda:[0,5,6,31,32,33],nlp:28,nm:26,nm_n:[0,29],nmse:[6,32],nn:[2,5,6,12,23,31,32,35,36],nn_model:1,nnmin:2,node:[1,2,3,9,10,12,35,36],node_constructor:[],nois:[0,4,5,6,8,9,10,13,15,16,19,24,29,30,31,32,33,34],noise_dimens:4,noisi:[1,6,19,24,32,36],non:[0,1,3,5,6,7,9,10,11,12,13,14,21,23,26,29,30,31,32,33,34,35,36],none:[0,1,2,4,5,9,10,13,26,29,30,31,32,33],nonlinear:[3,6,8,9,11,12,32,35,36],nonneg:[6,9,13,32,33,34],nonparametr:6,nonsens:26,nonsingular:23,nonumb:[3,7,8,13,21,23,33,34,35],nor:[1,4,13,34,35],norm:[0,1,5,6,8,11,13,17,29,30,31,32,33,34,35,36],normal:[3,4,5,6,7,8,9,10,11,12,13,15,16,18,19,21,22,23,24,26,29,30,31,33,34,35,36],normali:[23,29],norwai:[6,24,29,32,35],notat:[0,2,5,6,13,14,21,26,29,30,31,32,34],note:[0,1,2,3,4,5,6,7,8,11,12,13,14,15,16,22,23,26,28,29,32,33,34,36],notebook:[0,1,3,9,15,22,24,29,36],notesseptember16:33,notesseptember30:35,notfounderror:[3,4,14],noth:[1,2,5,8,12,14,26,30,31,35,36],notic:[4,5,12,13,23,26,29,31,34,35,36],notimplementederror:2,notion:3,novel:[3,6,10,33],novemb:[1,25,27,29],now:[0,2,4,5,6,7,8,10,11,12,14,15,16,17,22,23,24,26,29,30,33,36],nowadai:[0,1,3,9,22,29],nox:0,np:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,21,23,24,26,29,30,31,32,33,34,35,36],npr:2,nsampl:[6,9,32,33],nt:2,ntrained_model:[6,31],nu:26,nuclear:[5,30],nuclei:[0,26,29],nucleon:[0,29],nucleu:[0,29],num:4,num_coordin:2,num_featur:35,num_hidden_neuron:2,num_it:2,num_iter:[21,35],num_neuron:2,num_neurons_hidden:2,num_point:2,num_tre:10,num_valu:2,number:[1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,23,24,25,27,29,31,32,33,36],numberid:[7,33],numberparamet:3,numer:[0,5,6,9,10,11,12,13,17,21,22,23,28,29,30,31,32,33,34,35,36],numpi:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,22,24,26,30,31,32,33,36],numpy_box:[],numpy_vjp:2,numpy_wrapp:[],nunmpi:[5,30],nvalu:9,nx:2,nx_test:[6,31],nx_train:[6,31],nx_train_mean:[6,31],ny:26,ny_pr:[6,31],ny_train:[6,31],ny_train_mean:[6,31],o:[0,6,7,8,9,11,15,21,23,27,28,29,33,35],obei:[6,11,13,30,31,34],obj:2,object:[0,1,2,4,6,8,10,23,29,34],obliqu:[5,30],observ:[0,1,3,5,6,7,8,9,10,11,12,13,14,26,31,32,33,34,35,36],obtain:[0,1,5,6,7,8,9,10,12,13,14,17,21,23,24,26,29,30,31,32,33,34,35,36],obviou:[5,6,11,26,30],obviouli:29,obvious:[0,4,5,6,21,23,29,31,32],oc:30,occupi:0,occur:[0,6,8,9,23,26,29],octob:[21,25,27,29,35],od:0,odd:[0,3,7,29,30,33],odenum:2,odesi:2,odin:29,oen:0,off:[1,3,4,5,9,13,19,26,31,32,34,35,36],offer:[6,11,22,23,25,27,29,32],offic:[27,29],offici:[25,29],often:[0,1,3,4,5,6,7,8,9,10,11,12,13,14,16,22,23,24,26,29,30,32,33,34,35,36],ofter:[23,29],ol:[0,13,15,16,17,18,29,30],old:[1,5,10,13,31,32,33,34,36],ols_sk:6,ols_svd:6,olsbeta:[0,5,31],omega:[2,3,6],omega_0:3,omit:[0,5,29,30,31,32],omlmp_kkie0:33,onc:[1,6,9,11,13,32,33,34,35],one:[0,1,3,4,5,6,7,8,9,10,11,13,14,19,21,22,23,24,26,27,29,30,31,32,35],onehot:[1,36],onehot_vector:[1,36],onehotencod:9,ones:[0,2,5,6,8,9,10,11,13,21,23,24,29,30,31,32,33,34],ones_lik:4,ong:30,onl:3,onli:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,19,21,23,24,26,29,30,31,32,33,34,35,36],onlin:[11,25],onto:[5,11,30],open:[0,1,4,6,7,9,15,22,24,25,27,29,32,33],oper:[0,1,3,5,6,10,11,12,13,15,22,26,29,30,31,32,34,35,36],operation:26,oplu:26,opmiz:[13,34,35],opportun:0,oppos:[6,13,34,35],opposit:[1,5,8,30],opt:[1,5,29,31],optim:[0,2,3,4,5,6,7,9,10,11,14,15,16,17,18,19,21,24,31,32],optimis:[1,3],option:[0,1,3,5,6,8,9,11,21,23,24,30,31,32,35,36],optmiz:[1,8,13,21,30,34,35,36],oral:29,orang:0,order:[0,1,2,3,5,6,7,8,9,10,11,12,15,16,23,24,26,29,30,31,32,33,36],ordinari:[0,2,3,7,11,13,15,16,17,19,21,22,32,33,34,35],oreilli:[28,29],org:[0,3,4,9,11,21,22,23,24,28,29,31,34,35],organ:[6,7,10,23,32,33],orient:[1,5,26,30,31],origin:[0,3,5,6,8,11,12,13,23,29,30,32,34,35,36],orthogn:[5,30],orthogon:[0,5,6,8,11,13,17,23,29,30,31,34],orthonorm:[5,30,31],os:[0,1,4,5,6,7,8,9,27,29,30,31,32,33],oscar:1,oscil:[3,13,34,35],oserror:[0,3,4,7,14,33],oslo:[0,15,22,24,25,27,29,30,31,32,33,34,35,36],osx:[0,15,22,24,29],other:[0,1,2,3,5,6,7,8,10,13,14,15,19,22,25,26,27,28,31,32,34],otherwis:[0,1,4,7,13,21,23,29,33,34,35,36],ouput:[5,7,12,31,32,33,36],our:[1,2,3,6,7,8,9,10,12,14,15,16,17,18,19,21,22,23,24,26,31,32,35],ourmodel:0,ourselv:[0,5,6,8,11,13,29,30,31,32,33,34],out1:[],out2:[],out:[0,1,2,4,5,6,7,8,9,10,11,12,13,16,21,22,23,24,26,29,30,31,32,33,34,35,36],out_fil:9,outcom:[0,7,9,10,12,26,30,33,36],outdoor:9,outer:[6,12,13,36],outfil:4,outgrad:2,outlier:[0,8,29,30],outlin:[6,10,11,32],outlook:9,outperform:10,output:[0,1,3,4,5,6,7,8,9,10,12,13,16,23,24,26,29,30,31,32,33,34,35,36],output_bia:[1,36],output_bias_gradi:[1,36],output_shap:4,output_weight:[1,36],output_weights_gradi:[1,36],outputlayer1:[12,35,36],outputlayer2:[12,35,36],outsid:4,over1:[13,34,35],over:[0,1,3,4,5,6,9,10,12,13,21,23,24,29,30,31,32,33,34,35,36],overal:[1,10,36],overcast:9,overcom:[12,13,34,35,36],overdetermin:[0,29],overfit:[0,1,3,6,9,10,13,21,32,34,35,36],overflow:[1,5,31,32,36],overhead:[12,36],overlap:[3,7,8,9,33],overlin:[0,5,6,9,10,11,14,23,29,30,31],overst:0,overtrain:4,overview:[3,33],own:[4,5,6,8,12,13,21,22,23,24,31,34,35,36],owner:0,ownmsepredict:0,ownmsetrain:0,ownridgebeta:[0,6,31],ownypredictridg:0,ownytilderidg:0,oxid:0,p0:2,p1:2,p:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,17,23,26,29,30,31,32,33,34,36],p_:[2,4,8,9],p_hidden:2,p_i:[5,26,31,32],p_j:26,p_n:26,p_output:2,p_x:26,pack:[0,29],packag:[0,1,2,3,4,5,6,7,8,9,11,13,14,15,21,22,24,26,30,31,33,34,35,36],packtpub:29,packtpublish:29,pad:[3,4],page:[0,9,22,29,31,32,33,34],pai:[0,1,9,13,34,35],pair:[0,2,3,9,22,26,29],panda:[0,4,5,6,7,9,11,15,22,24,31,32,33],panel:29,paper:1,paradigm:[0,29],parallel:[10,13,21,22,23,29,34,35],param:2,param_distribut:33,param_grid:33,paramat:2,paramet:[0,1,2,3,4,5,6,7,8,9,10,12,13,16,17,18,19,21,24,26,31,32,36],parameter:[0,6,10,24,29,30],parametr:[0,6,15,16,29,30,32],paramt:[3,5,31,32],parent:2,parent_argnum:[],part:[0,1,3,5,6,10,17,18,21,23,25,26,27,29,31,32,35],partial:[0,1,5,6,7,8,10,11,12,13,16,26,29,30,31,33,34,36],particip:[22,25,27,29],particl:[0,4,13,26,29,34,35],particular:[0,1,2,3,5,6,9,10,11,12,13,16,24,26,28,29,30,31,32,33,34,35,36],particularli:[5,6,8,11,13,21,26,30,32,33,34,35],partit:[1,4,9,36],partli:[6,29,32],pass:[2,3,12,14,33],passkwarg:2,password:24,past:[10,26],patch:[6,26,32],path:[0,3,4,6,7,9,14,15,22,29,30,32,33],pathcollect:[21,35],patient:[7,33],patter:4,pattern:[0,3,4,12,25,28,29,35,36],pauli:[0,29],pc:[11,22],pca:[0,7,22,29,30,33],pd:[0,4,5,6,7,9,11,29,30,31,32,33],pde:2,pdf:[0,3,4,5,6,9,16,20,24,28,29,31,32,33,35],pedagog:[0,29,30],penal:[6,30,31],penalti:[6,13,24,30,31,33,34],penros:[5,6,31],pentagon:[13,33,34],peopl:[0,1,9,13,22,34,35,36],per:[0,1,6,25,27,29,32],percentag:[0,10,11,27],perceptron:[0,1,7,29,33],peregrin:29,perfect:[0,1,13,21,29,34,35,36],perfectli:[4,6,32],perform:[0,2,3,4,5,6,8,10,11,12,13,14,15,16,17,19,21,22,23,24,26,29,30,31,32,33,34,35],performac:4,perhap:[0,5,13,29,30,31,33,34],perimet:[1,9],period:[1,4,26,36],permut:11,persist:[13,34,35],person:[5,6,7,25,27,29,30,31,32,33],perspect:28,pertin:[12,29,36],petal:[8,9],peter:[28,30],phantom:26,phase:[6,12,35,36],phenomena:26,phi:8,phi_k:8,philosophi:[13,34],phone:[27,29],photo:4,phrase:[0,29],physic:[0,1,4,7,12,13,26,27,28,29,30,31,32,33,34,35,36],pi:[2,3,5,6,7,9,12,13,26,31,32,33,34,35,36],pick:[1,9,10,11,13,14,34,35,36],pickl:1,pictur:[0,29],pie:[22,29],piec:[11,14],pillow:[0,15,22,24,29],pinv:[5,6,13,21,30,31,34,35,36],pip3:[0,1,15,24,29],pip:[0,1,15,22,24,29],pipelin:[0,6,8,10,30,32],pippin:29,pit:4,pitfal:[6,30,31],pitt:[12,35,36],pixel:[1,3,4,36],pixel_height:[1,3,36],pixel_width:[1,3,36],place:[0,4,6,8,13,23,24,29,32,33,34],plai:[0,3,4,5,6,8,11,22,29,30,31,32,33],plain:[8,10,12,13,14,21,33,34,36],plan:[6,9,27,28,29],plane:[8,9],plateau:[5,31],platform:[22,29],plausibl:[12,35,36],pleas:[9,11,13,24,27,29,34,35],plenti:1,plethora:[3,12,35,36],pliahhy2ibx9hdharr6b7xevztgzra1p:[35,36],plot:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,21,22,23,24,26,29,30,31,34,35,36],plot_all_sc:[24,31],plot_confusion_matrix:[7,10,33],plot_count:6,plot_cumulative_gain:[7,10,33],plot_data:1,plot_dataset:8,plot_decision_boundari:[9,10],plot_import:10,plot_max:4,plot_min:4,plot_model:4,plot_numb:4,plot_predict:8,plot_regression_predict:9,plot_result:4,plot_roc:[7,10,33],plot_surfac:[2,6,13,24,34],plot_train:9,plot_tre:[9,10],plqvvvaa0qudcjd5baw2dxe6of2tius3v3:[35,36],plt:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],plu:[0,3,5,7,29,30,31,33],pluggabl:[3,4,14],plugin:[3,4,14],pm:[8,32],pmatrix:2,pml:28,pn:3,png:[0,4,6,7,9,29,30,32,33],point:[0,1,2,3,5,6,7,8,9,10,11,13,14,15,16,17,19,21,23,24,26,27,29,30,32,33,34,35,36],point_1:4,point_2:4,poisson:[22,26,29],poli:[6,8,32,33],poly100_kernel_svm_clf:8,poly3:0,poly3_plot:0,poly3dcollect:34,poly_featur:[8,9],poly_features10:9,poly_fit10:9,poly_fit:9,poly_kernel_svm_clf:8,polydegre:[0,5,6,10,30,31,32],polygon:[13,33,34],polym:[12,35,36],polymi:24,polynomi:[0,5,6,7,8,9,10,11,15,16,17,19,21,24,29,30,32,33,35],polynomial_featur:[6,32],polynomial_svm_clf:8,polynomialfeatur:[0,6,8,9,30,32,33],polytrop:[0,6,29,32],pool:3,pool_siz:3,poor:[1,13,21,33,34,35],poorli:[0,30],pop:2,popul:[0,5,29,30,31,32],popular:[0,1,3,6,7,8,9,11,12,15,22,23,24,26,30,33,35,36],popularli:[0,29],portabl:10,portion:[11,13,21,34,35],pose:[0,4,5,6,11,26,29,32],posit:[0,1,2,3,5,7,8,10,11,13,14,23,26,29,30,31,32,33,34,35,36],possibl:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,15,19,21,22,23,24,26,27,29,30,31,32,33,34,35,36],posterior:[5,31,32],postpon:[0,29,30],postscript:24,postul:[5,31,32],potenti:[0,3,5,6,12,13,29,30,31,32,34,35,36],pott:[12,35,36],power:[0,1,5,6,8,9,12,13,29,30,32,34,35,36],pp:[5,6,18,31,32,33],practic:[0,5,6,7,8,24,26,30,31,32,33],practition:[0,1,3,29],pre:29,preced:[1,11,12,26,35,36],preceed:4,preceq:8,precis:[0,2,5,11,13,23,24,26,29,30,31,32,34,35],pred:[6,32,34,35],predicit:0,predict:[0,1,5,6,7,8,9,10,15,16,22,24,28,29,30,31,32,33,35,36],predict_prob:[1,36],predict_proba:[7,10,33,35,36],predictor:[0,5,6,7,9,10,11,29,30,31],prefer:[0,1,6,8,9,11,13,15,22,24,29],prepar:[0,6,23,24,29,30],preprocess:[0,4,6,7,8,9,10,11,24,31,32,33],prerequisit:0,prescript:24,presenc:[13,34,35],present:[0,5,6,7,9,12,13,21,23,24,26,29,30,31,34,35,36],preserv:[3,11,23],press:[13,28,33,34],pretrain:[1,4],pretti:[0,4,8,9,15,22,24,29],prev_centroid:14,prevent:[13,26,34,35],previou:[0,1,2,3,4,5,6,8,10,11,12,13,21,23,24,26,30,33,34,35,36],previous:[2,3,9,10,26],price:[0,4,9,13,34,35],primal:8,primari:[0,7,29,33],prime:26,primit:2,princip:[0,5,7,22,29,30,33],principl:[0,6,7,8,14,29,32,33],print:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,21,23,26,29,30,31,32,33,34,35,36],print_funct:[8,9],printout:[0,29],prior:[0,5,6,29,31,32],privat:0,prob:[1,26],probabilist:[0,28,29,30],probabl:[0,1,3,4,6,7,10,13,22,29,30,33,34,35,36],problem:[0,3,4,5,6,7,8,9,10,11,12,16,17,22,23,24,26,32],probml:28,proce:[0,5,6,7,8,9,10,11,13,23,29,30,31,32,34],procedur:[2,4,5,6,8,10,11,13,21,24,30,31,32,33,34,35],proceed:23,process:[0,2,4,6,9,10,12,13,15,21,22,23,24,26,28,29,32,33,34,35],prod:28,prod_:[1,5,7,31,32,33,36],produc:[0,3,4,5,6,9,10,11,12,13,22,23,24,26,29,30,31,32,34,35,36],product:[0,1,3,5,6,7,8,12,13,16,21,22,23,29,30,31,32,33,35,36],profess:[0,29],program:[0,1,4,5,6,8,12,14,15,16,21,22,23,25,26,27,29,30,35,36],programm:23,progress:[1,4,14,34],prohibit:[6,32],project1:[6,24],project:[0,1,2,3,5,11,13,17,18,19,20,21,22,25,27,30,31,32,34,35,36],project_root_dir:[0,6,7,9,29,30,32,33],projectwrit:24,promin:[12,35,36],promis:8,promot:[27,29],prone:9,pronounc:[13,22,29,34,35],proof:[0,11,12,13,29,32,33,34,36],propag:[2,3,13,34,35],proper:[0,2,6,7,24,32],properli:[1,6,8,10,13,21,24,34,35],properti:[0,1,3,12,13,16,17,23,29,32,34,35,36],proport:[0,1,5,9,11,13,16,26,29,30,34,35,36],propos:[1,4,6,10,24,29],propto:[5,13,31,32,33,34,35],proton:[0,29],prove:[3,13,33,34,35],provid:[0,1,3,4,5,6,8,9,10,12,13,15,21,22,23,24,26,29,30,31,32,33,34,35,36],proxi:[1,13,21,34,35],prune:9,pseudo:[23,26,34],pseudocod:24,pseudoinv:[5,31],pseudoinvers:[5,6,31],pseudorandom:[6,26,32],psycholog:[0,29],pt:[13,34],punish:[0,1,29,36],pure:[3,9,26],purest:9,puriti:9,purpos:[0,3,10,12,14,29,35,36],put:1,py:[0,1,2,3,4,5,6,7,8,9,11,14,21,29,31,32,33,35,36],py_tf:[3,4,14],pycod:29,pydata:22,pydot:9,pyhton2:29,pylab:[0,7,29,33],pypi:22,pyplot:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],pythagora:[5,31,32],python2:[0,15,24,29],python3:[0,2,3,4,6,7,8,9,11,14,15,21,22,24,29,31,33,35],python:[1,2,3,4,5,6,8,11,12,13,14,16,21,24,26,30,31,34,35,36],pytorch:[0,22,24,29],q:[5,6,8,11,26,30,32],qp:8,qquad:[2,11,13,23,34,35],qr:[5,6,23,30],quad:[1,13,23,34,36],quadrat:[0,8,9,13,15,16,29,34],qualit:[4,9,24,26],qualiti:[0,9,15,16,22,29,30],quantifi:1,quantil:10,quantit:[0,6,9,24,29,32],quantiti:[0,2,5,6,7,9,10,11,12,14,16,23,26,29,30,31,32,33,36],quantum:[4,12,28,29,35,36],quartil:[0,30],quench:5,queri:9,question:[0,5,6,9,11,12,13,24,27,29,30,31,32,34,35,36],qugan:4,quick:[4,26],quickli:[1,3,9,11,13,33,34],quit:[1,5,6,9,10,12,30,32,35,36],quot:4,r2:[0,5,6,29,30,31,33],r2_score:[0,29],r2score:[0,29],r:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,21,22,23,24,26,30,31,32,33,34,35,36],r_1:9,r_2:9,r_j:9,r_m:9,rad:0,radial:[0,8,12,35,36],radioact:26,radiu:[0,1,9,30],rag:2,rain:9,rais:[0,2,3,4,7,14,31,33],ramp:1,ran0:26,ran1:26,ran2:26,ran3:26,rand:[0,4,5,6,9,10,13,15,16,21,23,29,30,31,32,33,34,35],randint:[6,9,13,21,32,34,35],randn:[0,1,2,5,6,9,11,13,15,16,21,29,30,31,32,33,34,35,36],random:[0,1,2,3,4,5,6,8,9,13,14,15,16,21,22,23,24,29,30,31,32,34,35,36],random_forest_model:10,random_index:[13,21,34,35],random_indic:[1,3,36],random_st:[0,7,8,9,10,11,33,35,36],randomforestclassifi:10,randomizedsearchcv:33,randomli:[1,6,9,13,14,21,32,33,34,35,36],randuniform:33,rang:[0,1,2,3,4,5,6,7,9,10,11,12,13,14,21,23,26,29,30,31,32,33,34,35,36],rangl:[0,6,11,26,29,30],rangle_x:26,rank:[5,30],rankdir:4,raphson:[1,8,13,36],rapidli:0,rare:[1,13,29,33,34,35],raschka:[29,30,31,32,33,34,35],rasckha:29,rashcka:36,rate:[0,1,2,3,4,8,9,10,12,13,33,36],rather:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,23,26,29,30,31,32,33,34,35,36],ratio:[4,7,9,10,11,33],rational:[0,29],ravel:[5,6,7,8,9,10,11,13,23,30,32,33,34],raw:3,rbf:[8,11,12,35,36],rbf_kernel_svm_clf:8,rbf_pca:11,rc:[0,26],rc_temp:[0,7,33],rcond:[0,29,30],rcparam:[0,1,3,7,8,9,10,26,29,33,36],re:[2,4,13,33,34],reach:[1,4,5,6,9,10,11,12,13,14,31,32,33,34,35,36],read:[0,2,3,4,5,6,7,8,11,12,16,21,23,24,25,26,28,31,34,36],read_csv:[0,6,7,9,29,32,33],read_fwf:[0,29],reader:[0,6,23,26,29,30,31],readi:[0,1,5,6,8,10,11,12,23,24,29,31,32,36],readili:[1,36],readthedoc:22,real:[0,1,2,4,7,10,11,12,23,30,32,33,35,36],real_loss:4,real_output:4,realist:8,realiti:26,realiz:[1,12,35,36],realli:[0,1,29],rearrang:[13,34,35],reason:[0,1,3,4,10,13,28,29,33,34,35],reassign:1,recal:[5,6,9,10,11,12,23,26,29,30,31,32,33,34,36],recast:3,receiv:[1,3,10,12,26,35,36],recent:[0,1,2,3,4,6,7,10,13,14,21,24,28,29,31,32,33,34,35,36],recept:[3,12,35,36],receptive_field:3,recip:[0,6,7,23,24,29,30,33],reciproc:[5,31],recogn:[0,4,5,10,29,31,32],recognit:[0,1,3,12,25,28,29,35,36],recommen:29,recommend:[0,2,3,4,5,6,8,13,15,18,21,22,23,24,28,31,32,34,35,36],reconsid:9,reconstruct:11,record:[10,24,25,27,29,34,35],rectangl:[9,13,33,34],rectangular:[5,30],rectifi:[1,3,12,35,36],recur:[0,22,29],recurr:[0,1,22,29],recurs:[9,22,23,29],red:[0,3,4,6,8,9,21,32,34,35],redefin:[0,10,29,30],redefinit:31,reduc:[1,2,3,5,6,9,10,11,13,21,29,31,32,33,34,35,36],reduct:[0,2,10,11,22,26,29,30],refer:[0,1,2,3,5,6,9,11,12,13,14,20,23,28,29,30,32,33,34,35,36],referenc:2,refin:[12,35,36],refit:[6,32],reflect:[0,1,4,5,24,26,29],refresh:[22,29],refreshprogrammingskil:29,reg:[10,11],regard:[1,9,13,34],regardless:[12,35,36],region:[3,4,6,9,12,24,35,36],regist:[6,24,26],reglasso:[5,31],regr_1:[0,9],regr_2:[0,9],regr_3:[0,9],regress:[1,8,11,12,15,16,21,22,23],regressor:[0,7,10,29,33],regridg:[0,5,6,31,33],regular:[0,3,4,5,6,7,9,13,17,27,29,30,31,32,34,35],regularis:6,reilli:[0,15,28,29],reinforc:[0,8,22,29],reiter:1,reject:7,rel:[0,4,6,7,9,12,13,26,29,30,32,33,34,35,36],relat:[0,1,3,4,5,11,13,14,23,26,29,31,32,34,35],relationship:[0,4,9,29],relativeerror:[0,29,30],releas:[1,22,29],relev:[0,1,5,7,11,15,21,22,24,26,29,31],reli:[0,6,8],reliabilti:24,reliabl:[7,26,33],relu:[3,4,29,36],remain:[1,2,4,6,12,23,26,30,31,32,33,35,36],remaind:26,reman:2,remark:1,rememb:[0,8,13,23,24,29,34,35],remind:[0,5,11,13,23,26,30,31,32],remov:[0,4,5,6,30,31],render:[0,9,29,30],reorder:[5,7,30,31,33],reorgan:[0,29],repeat:[0,1,3,4,5,6,9,10,11,13,14,21,23,24,26,29,31,32,33,34,35,36],repeated:29,repeatedli:[0,6,10,13,32,34,35],repet:3,repetit:[6,29,30,32,33,34],rephras:[13,33,34],replac:[0,1,3,4,5,6,10,12,14,15,16,21,22,24,29,30,31,32,33,36],replica:[6,32],repo:24,report:[20,29,34,35],reportexampl:[20,24],reportsampl:20,repositori:[0,4,24,29],repres:[0,1,2,3,4,5,6,7,8,9,10,12,13,26,29,30,31,32,33,34,35],represent:[0,1,3,6,9,26,29,32,33,36],representd:3,reproduc:[0,5,6,9,12,15,16,22,24,26,29,30,36],repuls:[0,29],request:[0,13,21,34,35],requir:[0,1,3,4,5,6,8,9,11,12,13,17,23,29,30,31,32,33,34,35,36],rerun:9,res1:2,res2:2,res3:2,res_analyt:2,res_analytical1:2,res_analytical2:2,res_analytical3:2,resaml:[6,24],resampl:[0,7,10,19,22,29,30,33,34],rescal:[0,11,12,30,35,36],rescu:[5,31,32],reseach:[6,24],research:[0,4,13,21,22,28,29,34,35],resembl:[6,26,32],reserv:[1,5,6,26,31,32,36],reshap:[0,1,2,3,4,6,8,9,10,15,16,23,29,30,32,36],residenti:0,residu:[0,5,13,29,34],resiz:[5,30],resourc:29,respect:[0,1,2,3,5,6,7,8,10,11,12,13,14,16,17,21,24,26,29,30,31,32,33,34,35,36],respond:[12,35,36],respons:[0,7,9,12,29,30,33,35,36],rest:[0,5,30],restat:[0,12,29,36],restor:4,restored_discrimin:4,restored_gener:4,restrict:[0,3,9,12,29,35,36],result:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,21,22,23,24,26,29,32,33,34,35,36],retail:0,retain:[5,6,30,32,33],rethink:32,retriev:29,return_data:14,return_sequ:4,return_x_i:9,reus:[1,3,6,18,19,20,24],reveal:[0,12,29,35,36],revers:[1,23],review:[22,23],revisit:[14,36],revolut:29,reward:[0,4,29],rewrit:[0,3,5,6,7,8,10,11,12,13,19,23,24,26,31,33,34,35,36],rewritten:[2,6,8,10,26,32],rewrot:[13,33,34],rf:10,rgb:3,rgoj5yh7evk:22,rh:[6,32],rho:[0,10,13,21,29,34,35],rho_1:10,rho_2:10,rho_m:10,rich:[0,29],ride:9,rideclass:9,ridedata:9,ridg:[7,11,13,21,22,29],ridge_sk:6,ridgebeta:[5,31],ridgecv:33,right:[0,1,2,3,5,6,7,8,9,10,12,13,14,16,17,19,23,24,26,29,30,31,32,33,34,35,36],right_sid:2,rightarrow:[0,1,5,6,8,11,12,13,26,29,30,32,33,34,35,36],rigor:[0,29],ring:6,rise:[0,29],risk:[0,13,15,16,29,33,34,35],rival:4,river:0,rlm:29,rm:[0,26],rmse:0,rmsporp:[13,21,34,35],rmsprop:[1,3,4,13],rnd_clf:10,rng:26,rnn1:4,rnn2:4,rnn:[4,12,35,36],rnn_2layer:4,rnn_input:4,rnn_output:4,rnn_train:4,rntrick1:26,rntrick2:26,rntrick3:26,rntrick4:26,ro:[0,13,21,29,33,34,35],robert:[18,24,28],robust:[0,29],robustscal:[0,30],roc:[7,10],role:[0,2,5,6,8,22,29,30,31,32,33],roll:6,room:[0,27,29],root:[0,5,9,13,26,30,31,33,34,35],rot:29,rotat:[1,8,9,10],rotation_matrix:9,roughli:[1,3],round:[0,7,9,13,33,34,35],routin:[13,23,29,33,34],row:[0,1,2,5,6,9,11,23,29,30,31,32,36],row_stack:[],rr:[5,30],rrr:[5,30],rug:[13,33,34,35],rule:[0,1,5,6,13,24,29,30,31,32,34,35],run:[0,1,2,4,5,6,8,9,11,13,15,21,22,24,29,30,31,32,33,34,35],runtim:[1,6,14],runtimewarn:[1,6,32,36],rust:[0,15,22,23,29],rvert:[1,36],rvert_2:[1,36],s:[0,1,2,3,4,5,6,7,9,11,12,13,16,17,18,22,23,24,26,29,30,31,36],s_1:6,s_:[3,6],s_i:[6,7,33],s_j:6,s_k:6,saddl:[13,33,34,35],sai:[0,1,2,3,4,5,6,7,8,9,10,11,12,23,24,26,29,30,31,32,33,36],said:[6,9,13,33,34],sake:[0,5,7,11,29,30,31,33],sale:[0,29],sam:29,same:[0,1,2,3,4,5,6,8,9,11,12,14,17,23,24,26,29,30,31,33,36],samm:10,sampl:[0,1,2,3,4,5,6,7,8,9,10,13,14,15,16,19,21,22,23,24,26,29,30,31,32,33,34,35,36],sample_vari:14,sampleexptvari:26,samwis:29,sastri:11,satisfactori:[0,29],satisfi:[1,2,3,6,8,13,23,26,32,33,34,36],satur:[1,6,32],save:[0,4,6,7,9,13,21,29,30,32,33,34,35],save_fig:[0,6,7,9,10,29,30,32,33],savefig:[0,4,6,7,9,26,29,30,32,33],savetxt:4,saw:[5,30],scalabl:10,scalar:[2,5,6,10,30,31,32],scale:[0,1,3,5,6,7,8,9,10,11,12,13,15,16,17,21,22,23,24,27,29,31,33,34,35,36],scale_mean:4,scale_std:4,scaler:[0,7,8,9,10,11,24,30,31],scan:[5,7,31,32,33],scari:[5,31,32],scatter:[0,1,6,7,8,9,14,21,29,30,31,32,33,35],scenario:[6,13,33,34,35],schedul:[13,27,34,35],scheme:[1,13,33,34,35],schrage:26,scienc:[0,1,10,12,13,22,25,26,27,28,33,34,35,36],scientif:[0,15,22,24,29,34,35],scientist:[0,29],scikit:[3,5,6,8,9,10,13,21,22,23,24,25,28,35],scikit_learn:[0,16],scikitlearn:29,scikitplot:[7,10,33],scipi:[0,3,5,6,13,15,22,23,24,29,30,31,32,33,34],scl:6,score:[0,1,3,6,7,9,10,11,15,16,24,27,29,30,32,33,34,35,36],scores_kfold:[6,32,33],scratch:[1,13,35,36],sdg:[13,21,34,35],sdv4f4s2sb8:35,seaborn:[0,1,3,6,7,21,29,33,36],seamless:[0,15,22,24,29],search:[0,1,3,5,9,13,29,31,34,35,36],sebastian:29,sebastianraschka:29,sec:6,second:[0,2,3,4,5,6,7,8,9,11,12,14,15,16,22,23,24,26,27,29,30,32,33,36],second_mo:[21,34,35],second_term:[21,34,35],secondeigvector:11,secondli:[12,36],section:[4,11,16,17,23,24,26,30,31,33,34,35],sector:0,see:[0,1,2,3,4,5,6,7,8,10,11,12,13,15,16,17,18,21,22,23,24,26,29,30,31,32,33,34,35,36],seed:[0,1,2,3,4,5,6,8,9,11,13,14,15,16,21,24,26,29,30,31,32,33,34,35,36],seed_imag:4,seek:[1,2,8],seem:[1,3,4,34,35,36],seemingli:[0,29],seen:[0,1,3,5,10,12,17,26,29,36],segment:[13,33,34],seismic:6,seldomli:[0,29],select:[1,5,6,8,9,10,11,17,24,25,26,27,28,29,30,31,32,36],self:[0,1,5,7,21,29,30,31,33,35,36],sell:4,semest:[7,25,33],semi:[8,13,33,34],semilogx:6,send:[5,12,13,27,29,34,35,36],senior:[25,27],sens:[0,4,6,8,24,29,32],sensibl:3,sensit:[0,5,6,9,13,29,30,31,32,35],sent:2,sentdex:[35,36],sentenc:[4,12,35,36],separ:[0,1,2,4,6,8,9,12,14,15,22,24,26,29,32,35,36],septemb:[17,18,19,20,24,29],sequenc:[2,3,4,7,9,10,12,13,22,23,26,29,33,34,35,36],sequenti:[1,3,4,10,12,26,35,36],seri:[0,1,2,3,4,5,6,10,11,12,13,23,29,30,31,32,33,34,35,36],serif:[0,7,26,29,33],serv:[0,1,2,3,5,7,13,21,24,28,29,30,31,32,33,34,35],servic:24,session:[1,20,24,25,27,29],set:[1,4,5,6,7,8,10,11,13,14,16,17,21,22,23,24,26,27,31,32,34,35],set_major_formatt:[6,24],set_major_loc:[6,24],set_tick:[1,6,8],set_ticklabel:[1,6],set_titl:[0,1,2,3,7,12,14,29,33,35,36],set_xlabel:[0,1,2,3,7,12,29,33,35,36],set_xlim:[7,12,33,35,36],set_xticklabel:1,set_ylabel:[0,1,2,3,7,29,33,36],set_ylim:[7,12,33,35,36],set_ytick:[7,33],set_yticklabel:[1,6],set_zlim:[6,24],seth:4,setminu:[6,33],setosa:[8,9],setosa_or_versicolor:8,setp:[6,32],setup:[1,4,6,8,21,22,29,30,36],sever:[0,3,5,6,7,8,9,11,12,13,21,22,23,26,29,30,31,32,33,34,35,36],sgd:[1,3,21,33],sgd_clf:8,sgdclassifi:8,sgdreg:[13,33,34],sgdregressor:[13,33,34],sgn:[5,30,31],shallow:[13,34,35],shape:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,23,29,30,31,32,33,34,35,36],shape_bas:[],share:[1,3,29],she:[7,33],shell:[21,35],shift:[1,6,12,26,31,35,36],ship:3,shire:29,shortcom:[13,33,34,35],shorten:4,shorter:26,shorthand:[29,32],shortli:[23,29],should:[0,2,3,5,6,8,9,11,12,15,16,21,23,24,26,29,30,31,32,36],show:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,21,23,24,26,29,30,31,32,33,34,35,36],show_shap:4,shown:[0,4,5,8,9,11,12,13,21,23,30,33,34,35,36],shrink:[3,5,6,8,11,24,30,31],shrinkag:[5,6,30,31],shrunk:11,shuffl:[0,1,4,6,13,21,30,32,33,34,35,36],side:[0,2,5,8,12,13,23,29,31,32,33,34,35,36],sigh:[22,29],sigma0:26,sigma1:26,sigma2:26,sigma:[0,1,5,6,7,10,11,12,13,17,18,19,23,24,26,29,30,31,32,33,34,35,36],sigma_0:[5,30,31],sigma_1:[5,30,31],sigma_2:[5,30,31],sigma_:[5,23,29,30,31,32],sigma_fn:[7,12,33,35,36],sigma_i:[0,5,29,30,31],sigma_j:[5,17,30,31],sigma_m:[6,26,32],sigma_n:[11,26],sigma_t:[13,34,35],sigma_x:26,sigmoid:[1,2,4,7,8,10,12,33,34,35,36],sigmundson:[6,30,31],sign:[1,2,7,8,10,26,27,33,35,36],signal:[1,3,10,12,35,36],signifi:4,signific:1,significantli:[1,13,21,26,33,34,35,36],sigurd:29,sim:[4,5,6,13,18,24,26,31,32,34,35],similar:[0,1,2,3,4,5,6,7,8,9,10,11,14,17,22,23,24,29,31,32,33],similarli:[0,1,3,5,8,10,13,20,26,29,30,31],simpl:[1,2,3,5,6,7,8,10,11,12,14,15,16,17,19,21,22,23,24,26,32,36],simplepredict:10,simpler:[0,1,5,6,7,13,16,19,21,22,24,29,31,34,35],simplernn:4,simplest:[0,1,3,4,9,10,12,14,29,35,36],simpletre:10,simpli:[0,1,2,4,5,6,8,9,10,11,12,15,22,23,24,26,29,30,31,32,35,36],simplic:[2,5,6,7,8,9,10,11,12,14,30,31,33,35,36],simplicti:[5,30],simplifi:[0,6,9,15,22,24,29,30,31,32],simplist:[3,6,26,32],simul:[6,32],simultan:[6,32],sin:[0,1,2,3,4,9,12,13,21,23,29,34,35,36],sinc:[0,1,2,3,5,6,7,8,9,10,11,13,21,23,26,28,29,30,31,32,33,34,35,36],sine:[3,12,35,36],singl:[0,1,2,3,5,6,7,8,9,12,13,23,26,29,30,31,32,33,34],singular:[0,6,13,23,24,29,31,32,33,34],sinusoid:3,site:[0,2,3,4,6,7,8,9,11,14,21,24,25,29,31,33,35],situat:[0,4,5,7,13,21,26,29,30,33,34,35],six:[3,26],size:[0,1,2,3,4,5,6,8,9,10,11,13,21,23,24,26,29,31,32,33,34,35,36],sketch:10,ski:9,skill:0,skip:11,skl:[0,6,29,30,31],sklearn:[0,1,3,5,6,7,8,9,10,11,13,14,29,30,31,32,33,34,35,36],skplt:[7,10,33],sl:[6,31,33],slack:8,slice:[2,23,29],slide:[0,3,15,16,24,26,29,30,32,34,36],slight:[6,13,32,34,35],slightli:[1,2,3,5,6,7,10,26,30,31,32,33],slope:[8,11,12,35,36],slow:[0,2,8,13,30,33,34,35],slower:[5,23,29,30,31],slowest:23,slowli:[12,36],slp:[1,36],small:[0,1,2,3,5,6,8,9,10,11,12,13,21,22,23,24,26,29,30,31,32,33,34,35,36],smaller:[0,1,2,5,6,8,9,11,13,26,29,30,31,32,33,34,35],smallest:[0,4,14,15,16,29,33],smallest_row_index:14,smooth:[0,3,6,9,13,24,29,33,34],sn:[0,1,3,6,7,29,33,36],sne:11,sneak:29,so:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,19,21,22,23,24,26,27,29,30,31,32,33,34,35,36],soar:6,social:0,soft:[1,7,10,12,33,35,36],soften:8,softmax:[3,7,33],softwar:[0,8,15,22,23],sol:8,sole:[0,6,29],solid:[0,7,33],solut:[0,1,2,3,5,6,8,10,11,13,17,18,23,24,26,29,30,31,32,33,34,35],solution_ev:34,soluton:2,solv:[0,1,3,5,6,8,10,11,12,13,23,24,29,30,35,36],solve_expdec:2,solve_ode_deep_neural_network:2,solve_ode_neural_network:2,solve_pde_deep_neural_network:2,solveod:2,solveode_popul:2,solver:[2,7,8,9,10,11,21,23,29,33,35],some:[0,1,2,3,4,5,6,7,8,9,10,11,12,14,24,26,29,31,32,35,36],some_model:[6,30,31],somehow:4,someth:[0,1,3,4,7,9,11,24,26,29,30,33,36],sometim:[0,1,11,12,13,14,29,30,34,35,36],somewhat:[35,36],soon:[23,27,30],sophist:[0,29],sopt:[13,34],sort:[5,6,9,11,26,30,32],sound:[3,5,31,32],sourc:[0,1,3,6,15,22,23,24,26,29,32],space:[0,1,4,5,8,9,11,12,13,14,21,26,30,31,32,33,34,35,36],span:[0,3,5,9,11,23,29,30],spare:1,spars:[3,6,23,29],sparse_mtx:[23,29],sparsecategoricalcrossentropi:3,sparsiti:10,spatial:[1,2,3,12,35,36],speak:26,special:[6,7,10,12,13,23,26,29,30,31,33,34,36],specif:[0,1,2,3,4,5,6,7,8,9,11,12,16,22,23,24,26,28,29,30,31,32,33,35,36],specifi:[0,3,5,6,7,9,11,13,14,21,24,26,29,31,32,33,34,35],specifici:[0,10,29],spectacular:3,spectral:1,speech:[0,1,3,4,12,35,36],speed:[1,2,4,13,34,35,36],spend:26,spent:24,sphere:[0,30],spin:6,spite:0,spline:8,split:[1,3,4,5,6,8,9,10,11,14,17,24,26,31,32,33],splite:0,splitter:[1,10],spontan:26,spot:3,spread:[0,11,26,29,30],springer:[18,24,28,29,32],spuriou:[13,21,34,35],sqquar:31,sqrsignal:3,sqrt:[0,3,4,5,6,8,10,11,13,17,21,26,30,31,32,34,35],squar:[1,2,3,4,7,8,9,11,13,14,15,16,17,19,21,22,23,26,32,33,34,35,36],squarederror:10,squaredeuclidean:14,squash:[12,35,36],srtm:[6,24],srtm_data_norway_1:[6,24],stabil:[5,24],stabl:[0,4,5,6,9,11,22,24,29,30,31],stack:[3,4],stage:[5,13,21,24,34,35],stai:[0,2,4,5,11,17,29,30],stand:[0,5,9,12,29,30,31,35,36],standadscal:30,standard:[0,1,4,5,6,7,8,10,12,15,16,17,19,21,23,24,26,29,31,33,35,36],standard_basi:[],standardscal:[0,6,7,8,9,10,11,30,31],stanford:[13,33],start:[0,1,2,3,4,5,6,8,9,10,11,12,13,14,20,23,26,27,29,30,32,33,34,36],start_box:[],start_nod:[],start_tim:14,starting_point:[21,35],stat:[6,32,33],state:[1,2,4,5,6,7,8,10,11,12,13,22,26,30,31,32,33,34,35,36],statement:[0,7,23,29,33],stationari:[33,34],statist:[0,1,3,4,7,9,10,11,12,13,14,18,23,24,25,28,30,33,34,35,36],statu:[0,7,9,11,29,33],stavang:[6,24],std:[0,4,6,29,30,32],steep:[13,21,33,34,35],steepest:35,step:[0,1,2,4,6,7,9,10,11,12,13,14,21,23,24,29,36],step_fn:[7,12,33,35,36],step_length:[13,34,35],step_siz:34,steps_list:9,stereo:3,still:[0,2,3,5,6,11,13,17,26,32,33,34,35],stimuli:[12,35,36],stk2100:[28,29],stk3155:[15,24,25,27],stk4021:[28,29],stk4051:[28,29],stk4155:[25,27],stk5000:28,stk:[28,29],stochast:[0,1,5,6,8,11,12,15,16,24,29,31,32,33,36],stock:4,stoke:[12,35,36],stone:[0,7,24,33],stop:[1,4,9,11,13,14,21,33,36],stopiter:[0,7,33],storag:[5,30],store:[0,1,2,3,6,11,13,24,26,29,34,35,36],storehaug:[27,29],str:[1,3,4,36],straight:[0,6,8,13,29,32,33,34],straightforward:[0,2,3,5,6,8,9,10,13,23,29,30,31,32,33,34],strategi:[0,1,9,29,36],stratifi:[6,32],strength:[0,5,14,30],stretch:11,strict:[8,13,33,34],strictli:[8,13,33,34],stride:[4,23],strike:6,string:[1,36],stroke:[7,33],strong:[3,6,9,10,12,23,26,32,35,36],strongli:[0,8,22,23],stronli:0,structur:[0,1,2,3,6,9,10,12,22,29,32,33,34,35,36],stuck:[1,13,33,34,35,36],student:[0,24,25,27,28,29],studi:[0,3,4,5,6,7,8,11,12,13,17,19,21,22,24,28,29,30,31,34,35,36],studier:28,style:[0,7,9,23,29,33],sub:[9,12,35,36],subarg:[],subdivid:[0,23,29],subfield:0,subject:[6,8,26],submit:29,subplot:[0,1,3,4,6,7,8,9,10,14,29,32,33,36],subplots_adjust:[8,26],subprogram:[23,29],subract:[0,30],subroutin:[0,29],subscript:[1,36],subsequ:[1,4,5,6,12,23,26,30,32,35,36],subset:[1,6,9,12,13,22,29,32,33,34,35,36],subspac:[0,8,11,30],substanti:[9,10],substep:11,substitut:[3,6,12,23,32,35,36],subsubset:9,subtask:6,subtl:1,subtract:[0,4,5,6,11,13,17,21,23,24,26,31,32,34,35],subtre:9,subval:[],succeed:[0,4,29],success:[3,7,9,13,26,33,34],successfulli:[4,9],sudo:[0,15,22,24,29],suffer:[0,1,2,5,10,29,30,31],suffici:[1,6,8,11,13,32,33,34,36],suggest:[1,13,24,28,34],suit:[8,12,35,36],suitabl:[0,26,30],sum:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,33,34,35,36],sum_:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,23,24,26,29,30,31,32,33,34,35,36],sum_i:[0,2,5,6,8,13,17,19,24,30,31,32,34,35],sum_j:6,sum_ja_:0,sum_k:[6,8,12,23,36],sum_logist:[13,34],sum_m:3,sum_n:3,sum_nx_:3,summar:[5,6,9,31,32,33,35,36],summari:[1,3,4,10,21,25,31,36],summat:[0,3,16,30],sunni:9,superconduct:31,superfici:3,superscript:[1,12,35,36],supervis:[0,5,6,7,9,12,22,29,30,32,33,35,36],supplement:[7,24,33],support:[0,1,9,10,11,13,22,29,30,34],suppos:[0,5,6,7,8,10,11,12,13,23,29,30,31,32,33,34,35,36],suppress:[5,8,13,31,34,35],sure:[0,1,4,6,24],surf:[6,24],surfac:[0,6,24,29],surpass:6,surpris:[0,29],surround:[3,22],survei:[0,5,6,29,30,31,32],svc:[8,9,10],svd:[0,6,11,17,29,32],svdinv:[5,31],svm:[8,9,10,11],svm_clf:[8,10],swath:[5,30],sy:[13,33,34],symbol:[1,3,4,5,11,13,14,22,26,29,30,31,34,35,36],symmeteri:1,symmetr:[0,5,8,11,12,13,23,29,30,34,35,36],symmetri:[6,9],sympi:[0,15,22,24,29],synonim:26,syntax:13,syntaxerror:8,system:[0,1,3,4,6,7,9,10,12,13,15,22,23,24,29,33,34,35,36],systemat:[4,6,32],t0:[3,6,13,21,34,35],t1:[2,13,21,34,35],t2:2,t3:2,t:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23,24,26,27,29,32,33,34,35,36],t_0:[2,9,13,34,35],t_1:[13,34,35],t_:2,t_b:10,t_i:[1,2,5,12,30,36],t_j:[12,36],t_k:9,tabl:[9,24,26,27,29,35,36],tabul:[0,29],tabular:29,tackl:4,tag:[2,3,4,5,6,7,12,13,14,21,23,26,30,33,34,35,36],taht:[0,29],tail:26,tailor:[2,8,11,29],taiwan:[0,29],take:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,16,21,22,23,26,29,30,31,32,33,34,35,36],taken:[0,1,3,6,10,13,23,29,32,34,36],tan:3,tangent:[1,4,12,13,33,34,35,36],tanh:[1,4,7,8,12,33,34,35,36],target:[0,1,2,3,4,5,6,7,8,9,10,11,12,29,30,31,32,33,34,35,36],target_iscomplex:2,target_meta:2,target_nam:9,target_ndim:[],target_shap:2,task:[0,1,3,6,9,11,12,14,20,24,29,32,35,36],tau:[3,5,26,31,32],taught:29,tax:0,taylor:[2,13,33,34],taylornr:[13,33,34],tba:[],tc:8,td:[1,6,29,32,36],teach:29,team:1,teaser:0,technic:[0,5,6,13,15,24,29,30,34,35],techniqu:[0,1,8,10,13,22,26,28,29,30,32,33,34,35],technolog:[0,1,36],tell:[0,4,6,10,11,13,26,32,34,35],temp1:1,temp2:1,temp:1,temperatur:[0,9,29],temporarili:1,ten:[3,17,29],tend:[3,5,6,8,9,10,12,13,14,21,30,31,32,34,35,36],tendenc:[0,29],tension:[6,32],tensor:3,tensordot:[],tensordot_adjoint_0:[],tensordot_adjoint_1:[],tensorflow:[0,2,4,8,14,15,22,23,24,25,28,29,30],term1:[5,6,11,24,30],term2:[5,6,11,24,30],term3:[5,6,11,24,30],term4:[5,6,11,24,30],term:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,24,26,29,30,31,33,34,35],termin:[0,4,5,9,10,13,15,21,29,30,34,35],terrain1:[6,24],terrain:[6,21,24],test:[3,4,5,6,7,8,9,10,13,17,19,21,23,24,26,32,33,34,35],test_acc:3,test_accuraci:[1,3,36],test_error:6,test_imag:[3,4],test_ind:[6,32,33],test_input:4,test_label:[3,4],test_loss:3,test_pr:[1,36],test_predict:[1,36],test_rnn:4,test_scor:[7,10,33],test_siz:[0,1,3,5,6,10,29,30,31,32,33,36],test_split:9,tester:31,testerror:[0,6,30,32],testi:4,testpredict:4,testx:4,text:[0,1,2,4,5,8,9,11,13,15,21,23,26,28,30,32,33,34,35,36],textbook:[16,17,21,24,30,32],textual:9,textur:[1,9],tf:[1,3,4,13,14,33,34],tf_loadlibrari:[3,4,14],th:[0,1,2,5,6,7,9,12,13,14,15,16,23,24,26,29,30,31,32,33,34,35,36],than:[0,1,2,3,4,5,6,7,9,10,11,12,13,17,22,26,29,30,31,32,35,36],thank:[4,6,30,31],theano:[1,22,29],thei:[0,1,2,3,4,5,6,7,8,9,11,12,13,23,24,26,29,30,31,32,33,34,35,36],them:[0,1,3,4,6,8,9,10,11,12,13,23,24,29,30,31,34,35,36],theme:[0,29,34],themselv:[0,26,29],thenc:[6,32],theorem:[2,6,7,30,33,35],theoret:[0,4,10,29],theori:[0,1,3,8,9,12,13,18,22,24,28,29,31,34,35,36],thereaft:[0,5,6,11,12,15,16,17,23,24,29,32,36],therebi:[0,5,7,11,29,30,31,33],therefor:[0,1,2,3,4,6,7,8,11,13,26,29,30,32,33,34,35,36],therein:11,thereof:[0,6,13,29,32,34,35],theta:[1,4,13,21,26,34,35,36],theta_:[1,13,34,35,36],theta_i:[1,36],theta_linreg:[13,21,34,35],theta_t:[13,34,35],thetaand:[35,36],thetaor:[35,36],thetaxor:[35,36],thi:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,22,23,24,25,26,28,30,31,32,33,34,35,36],thing:[0,1,2,4,5,7,9,26,29,31,32,33],think:[0,1,3,4,6,9,12,13,14,26,29,32,33,34,35,36],third:[0,3,6,13,21,27,29,33,34,35],thirti:[7,33],thorughout:29,those:[0,3,5,6,8,9,10,11,21,23,24,25,29,30,32],though:[1,2,3,4,13,23,26,34,35,36],thought:[6,14,24,26,32],thousand:[0,1,24,30,34,35],three:[0,1,3,5,6,8,9,12,15,23,24,25,26,27,29,30,31,32,33,35,36],threshold:[1,3,9,10,11,12,13,34,35,36],through:[0,1,2,3,4,5,6,8,11,12,13,14,22,23,26,29,30,31,32,33,34,35,36],throughout:[0,4,5,14,22,23,26,29],thu:[0,1,2,5,6,7,8,10,11,12,13,21,24,27,29,30,31,32,33,34,35,36],thumb:[0,6,24,29,30],thursdai:[27,30],tibshirani:[6,18,24,25,28,29,32],tick:6,tick_param:6,ticker:[6,13,24,26,33,34],tif:[6,24],tight_layout:[1,7,33],tightli:11,tild:[0,5,6,7,11,15,16,17,18,19,24,26,29,30,31,32,36],till:[0,4,7,8,9,10,12,23,29,30,31,33,36],time:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,21,22,23,24,26,29,30,31,32,33,36],timeit:4,timer:4,tini:1,tip:3,titl:[0,1,2,3,4,6,7,8,9,10,13,21,24,26,29,32,33,34,35,36],tmp:[13,34,35],tn:[2,3,7],to_categor:[1,3,4,36],to_categorical_numpi:[1,36],to_numer:[0,6,29,32],todai:3,togeth:[0,3,6,8,11,13,21,22,29,34,35],toi:[14,34,35],told:[13,34],toler:[2,6,14],tolist:4,tomographi:[12,35,36],too:[0,2,4,5,6,9,11,13,15,26,28,29,30,32,33,34,35],took:[8,29],tool:[0,1,3,6,13,22,30,32,34,35],toolbox:8,top:[0,3,5,6,9,10,18,22,29,31,32],topic:[0,5,6,7,8,22,24,30,31,33],topograph:24,topolog:[1,3,12,35,36],toposort:2,torkjellsdatt:[27,29],toss:[10,26],total:[0,1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,23,26,27,29,30,32,33,34,36],total_loss:4,totalclustervari:14,totalscatt:14,toward:[1,2,7,12,13,24,33,34,36],towardsdatasci:[34,35],town:0,tp:[4,7],tpng:9,tpu:[13,21,22,29,34,35],tqdm:6,tr:30,trace:2,trace_stack:[],traceback:[0,1,2,3,4,6,7,10,13,14,24,29,31,33,36],tracer:2,track:[3,13,14,23,30,33,34,35],tract:0,tractabl:[0,29,30],trade:[5,9,19,31,32],tradeoff:[0,5,19,24,29,30,31,33],tradit:[0,1,4,6,29,32,36],train:[2,3,5,6,8,9,10,11,12,13,17,19,21,24,31,32,33,34,35],train_accuraci:[0,1,3,29,36],train_dataset:4,train_end:[0,1,30,36],train_error:6,train_imag:[3,4],train_ind:[6,32,33],train_label:[3,4],train_pr:[1,36],train_siz:[0,1,3,30,36],train_step:4,train_test_split:[0,1,3,5,6,7,9,10,11,29,30,31,32,33,36],train_test_split_numpi:[0,1,30,36],trainable_vari:4,trained_model:[6,30,31],trainerror:[0,30],traini:4,training_checkpoint:4,training_dataset:4,training_gradi:[13,21,34,35],training_gradient_fun:[34,35],training_loss:[34,35],trainingerror:[6,32],trainpredict:4,trainscor:4,trainx:4,trait:[0,29],trajectori:4,trajectory_i:[21,35],trajectory_x:[21,35],transfer:9,transform:[0,5,6,7,8,9,10,11,12,13,21,22,23,29,30,31,32,33,34,35,36],transit:[6,12,35,36],translat:[1,4,6,10,29,30,31,36],transpos:[1,5,11,23,30,31,36],travers:[0,5],treat:[0,1,3,6,12,13,26,29,30,31,32,33,34,35,36],tree:[0,1,6,22,24,29,36],tree_clf:[9,10],tree_clf_:9,tree_clf_sr:9,tree_reg1:9,tree_reg2:9,tree_reg:9,trend:26,treue:7,trevor:[18,24,28],tri:[2,3,4,9,13,33,34],triain:0,trial:[0,2,4,6,13,26,29,32,33,34],triangl:[13,33,34],triangular:23,trick:[3,4,8,11,13,21,26,34,35],trickier:26,tridiagon:23,trigger:[0,7,33],trillion:22,trivial:[0,1,5,11,26,29,31],troubl:[0,8,12,30,36],truck:3,true_beta:[6,30,31],true_divid:[1,36],true_fun:[6,32],truncat:[21,35],trust:9,tucker:8,tuesdai:[27,29,32,33,34],tumor:[7,9,33],tumour:[7,33],tunabl:[1,21],tune:[4,9,13,21,23,29,33,34,35],tup:[],tupl:2,turn:[0,1,5,6,7,8,9,10,11,12,13,19,23,24,26,29,30,32,33,34,35,36],tutori:[1,4],tv:2,tveito:2,tvw1zdmznwm:35,tweak:[1,4,10,26],twice:[13,33,34],twist:11,two:[0,1,2,4,5,6,7,9,10,11,12,13,15,16,23,25,26,28,29,31,32,34,35,36],tx:[13,33,34,35,36],tx_1:[13,33,34],txt:4,ty:[13,33,34],type:[0,1,3,6,8,10,13,16,23,24,26,30,31,32,33,34],typeerror:[2,6,13],typic:[0,1,2,3,4,5,7,9,10,12,13,21,26,29,30,31,32,33,34,35,36],typo:24,u:[0,2,5,6,8,10,11,12,17,23,29,30,31,35,36],u_:23,u_i:[12,35,36],u_m:10,ua:[0,29],ubuntu:[0,15,22,24,29],uci:0,ufunc:2,uio:[24,27,28],un:14,unabl:9,unari:[23,29],unary_f:2,unary_oper:2,unary_to_nari:2,unbalanc:[6,9,32,33],unbias:[0,5,6,29,31,32],unbroadcast:2,unbroadcast_f:2,uncent:[6,31],uncertainti:[0,5,29,31,32],uncertitud:26,unchang:[1,3],uncorrel:[10,26],undefin:[5,30],under:[0,1,5,6,10,13,15,16,22,24,29,30,31,32,33,34],underdetermin:[0,29],underfit:[1,6,32],underflowproblem:[5,31,32],undergo:[5,31,32],undergradu:[25,27],underli:[0,1,9,13,26,29,34,35],underset:[4,14],understand:[0,1,3,5,6,10,13,14,21,22,29,30,31,33,34,35],understood:[8,13,34,35],undesir:8,undetermin:[5,8,31,32],undo:4,unexpect:[6,13,32],unexpected:26,unfair:[6,30,31],unfortun:[1,8,9,10],unicode_liter:[8,9],uniform:[0,1,5,6,11,13,15,16,24,26,29,30,33,34,36],uniformli:[13,26,33,34,35],unifrompdf:26,unimport:[13,33,34],union:[5,6,31,32,33],uniqu:[0,2,6,13,14,23,29,32,33,34],unique_cluster_label:14,unit:[0,1,3,4,5,10,12,26,29,30,31,35,36],unitari:[5,6,23,30],unitarili:[23,29],uniti:26,univari:26,univers:[0,1,2,13,15,22,24,25,27,29,30,31,32,33,34,35],unix:1,unknow:[0,23,29],unknown:[0,1,3,4,5,6,8,10,13,16,21,23,29,30,31,32,34,35,36],unknowwn:[12,36],unlabel:1,unless:[0,3,6,11,13,24,29,32,33,34],unlik:[1,3,8,13,33,34,35],unnecessarili:9,unord:3,unravel:[1,36],unrol:[3,11],unseen:[0,7,9,33],unstabl:1,unsupervis:[0,1,4,12,22,29,35,36],unsymmetr:[23,29],until:[1,2,4,9,12,13,14,33,34,35,36],untouch:0,unusu:[12,35,36],up:[1,3,4,5,6,8,10,11,13,14,16,18,22,23,24,26,27,31,34],updat:[1,2,10,12,13,14,21,34,35,36],uploa:29,upload:[22,24,28],upon:[0,1,6,7,11,23,24],upper:[0,8,9,16,23,30],uppercas:[23,29],upsampl:4,upscal:4,url:[0,7,29,30,33,35],us:[4,5,6,8,9,10,11,12,14,15,16,17,18,19,23,25,26,28,31,32],usa:[29,35],usag:[0,8,22,29,30,35],usd10000:0,usd:0,use_bia:4,usecol:[0,29],useless:[1,36],user:[0,1,2,3,4,6,7,8,9,11,14,15,21,22,23,24,29,30,31,33,35],usernam:24,userwarn:[6,21,35],usetex:26,usg:[6,24],usr:26,usual:[0,3,4,7,12,13,14,29,33,34,35,36],ut:[5,31],utf:[0,7,33],util:[1,3,4,6,7,10,14,29,32,33],ux:23,v0:26,v1:26,v2:26,v8xr:[35,36],v:[2,4,5,6,11,13,17,21,22,30,31,34,35,36],v_0:11,va:1,vahid:29,val:[13,34,35],val_accuraci:3,val_loss:4,vale:2,valid:[0,1,4,7,9,10,13,21,22,26,29,30,34,35],validation_data:3,validation_split:4,valu:[0,1,2,3,4,6,7,8,9,10,12,13,14,15,16,19,21,22,23,24,29,34,35,36],valuat:9,valueerror:[],valy:4,van:[0,18,24,29,30,31,32],vandenbergh:[8,13,33,34],vandermond:[0,29],vanilla:[0,6,11,14,30,31],vanish:[1,4,13,26,33,34],var_x:26,varabl:8,varepsilon:[5,6,18,24,31,32],varepsilon_:[5,6,31,32],varepsilon_i:[5,6,31,32],vari:[0,1,3,5,6,10,15,16,29,32,36],variabl:[0,1,2,5,6,7,8,10,11,12,13,14,21,23,29,30,31,32,35,36],varianc:[0,1,5,7,9,10,11,13,14,18,19,21,22,23,26,29,30,33,34,35],variance_i:[5,11,30],variance_x:[5,11,30],variant:[0,1,6,8,12,13,29,30,33,34,35,36],variat:[3,4,11,29],varieti:[0,3,12,15,22,24,29,35,36],variou:[1,3,5,6,7,8,9,11,12,13,16,18,21,22,23,24,26,30,31,34,35,36],varydimens:4,vastli:3,vaue:1,vault:0,vdot:[2,13,33,34],ve:24,vec:[6,32],vector:[0,1,2,3,4,5,6,7,9,10,11,13,14,16,17,21,22,31,32,33,34],vector_mean:14,ventur:[0,8,15,22,29],verbos:[1,3,4],veri:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,24,26,28,29,30,31,32,33,34,35,36],verifi:[3,11,23,29],versatil:[8,29],versicolor:[8,9],version:[0,3,10,13,14,15,22,23,24,26,29,34],versu:1,vert:[0,1,5,6,7,8,9,11,13,17,29,30,31,32,33,34,36],vert_1:[5,6,30,31,32],vert_2:[5,6,11,17,30,31,32],via:[0,5,6,7,8,9,10,11,12,15,19,22,23,24,25,26,27,29,30,31,32,33,35,36],vidal:11,video:[0,1,12,22,25,27,29,30,31,32,36],view:[1,3,5,6,12,13,21,26,28,29,31,32,34,35,36],violat:8,virginica:9,viridi:[0,1,2,3,29,36],virtual:1,viscos:[13,34,35],viscou:[13,34,35],visibledeprecationwarn:2,vision:[0,3],visual:[0,3,11,12,15,22,29,30,35],visualis:1,viz:[6,8,26],vjp:2,vjp_argnum:2,vjpfun:2,vjpmaker:[],vjpnode:[],vmap:[13,34],vmax:[1,6],vmh0zpt0tli:35,vmin:[1,6],voic:3,volum:[0,3,29],vote:10,voting_clf:10,votingclassifi:10,votingsimpl:10,vs:[0,4,6,34],vspace:2,vstack:[5,11,23,26,29,30],vt:[5,30,31],w1:8,w2:[8,11],w3:8,w:[0,1,2,3,4,5,6,7,8,10,11,12,13,14,23,26,29,30,32,33,34,35,36],w_1:[8,23],w_1x_1:8,w_1x_:8,w_2:[8,23],w_2x_2:8,w_2x_:8,w_3:23,w_4:23,w_:[1,12,35,36],w_hidden:2,w_i:[1,2,10,36],w_ix_i:[12,35,36],w_j:23,w_m:23,w_output:2,w_px_:8,w_px_p:8,wa:[0,1,3,4,5,6,7,10,11,12,14,17,23,24,29,30,31,32,33,35,36],wai:[0,1,2,3,4,5,6,7,8,10,11,12,13,14,17,23,26,29,30,31,33,34,36],walk:9,walker:26,wang:[0,29],want:[0,1,2,3,4,5,6,8,9,10,11,12,13,14,15,16,17,22,24,26,29,30,31,32,33,34,35,36],warn:[4,8],warrant:[6,32,33],wast:[3,34,35],watch:[22,35,36],wave:3,wavelet:8,we:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,30,31,32,33,36],weak:[9,10,14],weather:[1,12,35,36],web:[22,25,27,29],webpag:29,websit:[6,23,24,25,29],wedg:[8,26],wednesdai:[27,29,32,33,34],wee:11,week:[0,5,6,7,24,25,27],weekli:[16,22,24,27,28,29,35],weight:[0,1,2,3,6,7,9,10,12,13,24,26,33,34,35],weigth:2,welchlab:[35,36],welcom:[8,22],well:[0,1,2,3,4,5,6,7,8,9,10,12,13,15,16,19,20,21,22,23,24,26,28,29,30,31,32,33,34,35,36],went:8,were:[0,1,3,4,5,6,7,8,10,11,12,14,26,29,30,32,33,35,36],wessel:[0,18,24,29,30,31,32],what:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,19,22,23,24,26,33,34,35,36],whatev:3,when:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,21,23,24,26,29,30,31,32,33,36],whenev:[13,21,26,34,35],where:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23,24,26,27,29,30,31,32,33,34,35,36],wherea:[6,26,32],wherefrom:24,wherein:[1,12,35,36],whether:[0,3,5,7,9,24,26,29,31,33],which:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,29,30,31,32,33,36],whichev:[1,3],white:9,whiteboard:[31,32,33,34,35],who:[0,25],whole:[1,3,4,5,9,11,13,31,32,34,35,36],whose:[0,6,10,26,30,32],whow:[11,30],why:[0,1,3,6,13,21,24,31,33,34],wide:[0,1,3,6,7,12,15,22,23,24,29,32,33,35,36],widehat:[6,32],width:[0,3,8,9,29],wieringen:[0,18,24,29,30,31,32],win:10,wind:9,wing:[27,29],winther:2,wiothout:[6,30],wiscons:[7,33],wisconsin:10,wisdom:[6,31],wise:[0,1,5,12,13,30,34,35,36],wish:[0,2,5,7,8,11,13,14,23,24,29,30,33,34],with_std:[0,30],wither:6,within:[0,2,3,4,7,9,12,13,14,26,28,29,33,34,36],withinclust:14,without:[0,1,5,6,8,9,11,12,13,21,29,30,31,32,34,35,36],wo5dmep_bbi:[35,36],won:[0,29],wonder:8,word:[0,1,3,4,5,6,7,14,26,29,30,31,32],work:[0,1,4,6,7,8,9,13,15,21,22,24,25,26,27,29,30,32,33,34,35,36],workshop:29,world:[0,8,30],worldwid:[0,29],wors:[0,1,3,4,6,29,32],worst:9,worth:9,worthi:24,would:[0,1,3,5,6,7,8,9,10,11,12,13,23,24,26,29,30,31,32,33,34,35,36],wrap:[6,23,29],wrap_util:2,write:[0,1,2,3,5,6,7,8,12,13,15,16,17,20,21,23,29,30,32,33,34,35,36],written:[0,2,3,5,11,12,13,16,22,23,24,26,29,30,31,32,33,34,35,36],wrong:[1,8,36],wrongli:10,wrote:[5,11,30],wrt:[2,10,13,21,34,35],wth:[10,13,21,34,35],www:[22,23,24,28,29,31,35,36],wx_1:8,x0:8,x1:[4,8,9,10,13,34,35],x1_exampl:8,x1d:8,x2:[8,9,10,13,34,35],x2d:[8,11],x2d_train:11,x2dsl:11,x3:[8,9],x4:9,x:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,29,32,33,34,35,36],x_0:[0,5,11,23,29,30,31,32],x_1:[0,2,5,6,7,8,9,10,11,13,23,26,29,30,31,32,33,34,35,36],x_2:[0,2,5,6,7,8,9,10,11,13,23,26,29,30,32,33,34,35,36],x_3:[8,23,26],x_4:23,x_:[0,2,3,5,6,8,10,11,13,14,18,23,24,26,29,30,31,32,33,34],x_center:11,x_data:[1,36],x_data_ful:[1,36],x_hidden:2,x_i:[0,1,2,5,6,7,8,9,10,11,12,13,14,17,23,26,29,30,31,32,33,34,35,36],x_input:2,x_ix_:[0,29],x_iy_i:8,x_j:[0,2,8,9,12,16,26,30,35,36],x_jy_j:8,x_k:[12,14,23,26,30,35,36],x_l:26,x_m:[6,12,23,26,32,35,36],x_n:[0,2,3,6,8,11,12,13,23,26,29,32,33,34,35,36],x_new:[9,10],x_offset:[6,30,31],x_output:2,x_p:[3,7,9,33],x_poli:9,x_poly10:9,x_pred:4,x_prev:2,x_reduc:11,x_scale:8,x_small:[13,34],x_test:[0,1,3,5,6,7,9,10,11,29,30,31,32,33,36],x_test_own:6,x_test_scal:[0,6,7,9,10,11,30,31],x_tot:4,x_train:[0,1,3,4,5,6,7,9,10,11,29,30,31,32,33,36],x_train_mean:[6,30,31],x_train_own:6,x_train_scal:[0,6,7,9,10,11,30,31],x_val:1,xarrai:[22,29],xavier:1,xbkjd4ccgq:29,xbnew:[13,33,34],xcode:[0,15,22,24,29],xdclassiffierconfus:10,xdclassiffierroc:10,xg_clf:10,xgb:10,xgbclassifi:10,xgboost:9,xgboot:10,xgbregressor:10,xgparam:10,xgtree:10,xi:[8,13,21,34,35],xi_1:8,xi_:8,xi_i:8,xinv:[31,35,36],xk:8,xla:[13,21,22,29,34,35],xlabel:[0,1,2,3,4,5,6,7,8,9,10,13,21,24,26,29,31,32,33,34,35],xlim:[6,10,32],xm:9,xmesh:[13,34],xnew:[0,13,21,29,33,34,35],xp:26,xpanda:[0,30],xpd:[5,11,30],xplot:0,xs:9,xscale:[0,30],xsr:9,xt_x:[13,21,33,34,35],xtest:[6,32,33],xtick:[3,6,8,9,32],xtrain:[6,32,33],xu:[0,29],xx:[0,23,29],xy:[0,6,8,23,24,29],xytext:8,xz:[23,29],y1:4,y2:4,y3:4,y:[0,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,29,30,31,32,33,34,35,36],y_0:[0,5,11,23,29,30,31,32],y_1:[0,5,8,9,11,13,23,29,30,31,32,33,34],y_1y_1:8,y_1y_1k:8,y_1y_2:8,y_1y_2k:8,y_1y_n:8,y_1y_nk:8,y_2:[0,5,8,9,11,23,29,30],y_2y_1:8,y_2y_1k:8,y_2y_2:8,y_2y_2k:8,y_3:[0,9,23],y_4:23,y_:[0,1,5,6,10,11,23,29,30,31,32,36],y_data:[0,1,5,6,29,30,31,33,36],y_data_ful:[1,36],y_decis:8,y_fit:[0,30],y_i:[0,1,5,6,7,8,9,10,11,12,13,15,16,17,18,19,23,24,29,30,31,32,33,34,35,36],y_if_:10,y_ix_:[0,29],y_ix_i:[7,8,13,30,33,34],y_iy_jk:8,y_j:[6,8,12,19,24,32,35,36],y_k:[12,35,36],y_m:23,y_model:[0,4,5,6,29,30,31,33],y_n:[8,13,33,34],y_ny_1:8,y_ny_1k:8,y_ny_2:8,y_ny_2k:8,y_ny_n:8,y_ny_nk:8,y_offset:[6,30,31],y_plot:9,y_pred1:9,y_pred2:9,y_pred:[0,1,4,6,7,8,9,10,30,31,32,33,36],y_pred_rf:10,y_pred_tre:10,y_predict:35,y_proba:[7,10,33],y_scaler:[6,31],y_test:[0,1,3,4,5,6,7,9,10,11,29,30,31,32,33,36],y_test_onehot:[1,36],y_test_predict:0,y_tot:4,y_train:[0,1,3,4,5,6,7,9,10,11,29,30,31,32,33,36],y_train_mean:[6,30,31],y_train_onehot:[1,36],y_train_predict:0,y_train_scal:[6,31],y_val:1,yand:[35,36],ye:[3,6,7,32,33],year:[0,22,29],yet:[0,1,6,8,11,13,29,33,34,36],yi:[13,21,34,35],yield:[0,2,5,6,7,8,10,12,13,14,23,26,29,31,32,33,34,35,36],yk:8,ylabel:[0,1,2,3,4,5,6,7,8,9,10,13,21,24,26,29,31,32,33,34,35],ylim:[3,6,32],ym:9,ymesh:[13,34],yn:0,yo:[8,9,10],yor:[35,36],yoshua:[1,28],you:[0,1,2,3,4,5,6,8,9,10,11,13,15,16,17,19,20,21,22,23,24,26,27,28,29,30,31,32,33,34,35,36],young:0,your:[1,2,4,5,6,8,11,13,17,19,20,21,22,23,24,31,32,33,34,35,36],yourself:[11,13,29,34],youtu:[33,35],youtub:[22,35,36],ypred:[6,32,33],ypredict2:[13,21,33,34,35],ypredict:[0,13,21,29,30,33,34,35],ypredictlasso:[5,31],ypredictol:[0,5,31],ypredictown:[6,30,31],ypredictownridg:[6,31],ypredictridg:[0,5,6,31,33],ypredictskl:[6,30,31],yridg:29,ys:9,ytest:[6,32,33],ytick:[3,6,8,9,32],ytild:[0,6,29,30,32],ytildelasso:[5,31],ytildenp:[0,29,30],ytildeol:[0,5,31],ytildeownridg:[6,31],ytilderidg:[5,6,31],ytrain:[6,32,33],yuxi:29,yx:[23,29],yxor:[35,36],yy:[23,29],yz:[23,29],z:[0,1,2,3,4,5,6,7,8,9,11,12,13,23,24,26,29,30,32,33,34,35,36],z_0:[23,29],z_1:[23,29],z_2:[23,29],z_:[1,2,12,23,29,36],z_c:[1,36],z_h:[1,36],z_hidden:2,z_i:[1,12,35,36],z_j:[1,12],z_k:[12,30,36],z_m:[1,36],z_mod:9,z_o:[1,36],z_output:2,zaman:26,zaxi:[6,24],zero:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,21,23,24,26,29,30,31,32,33,34,35,36],zeros_lik:4,zeroth:30,zfill:4,zip:[2,4,6],zm_h:[0,29],zn:0,zone:0,zoom:29,zx:[23,29],zy:[23,29],zz:[23,29]},titles:["3. Linear Regression","14. Building a Feed Forward Neural Network","15. Solving Differential Equations with Deep Learning","16. Convolutional Neural Networks","17. Recurrent neural networks: Overarching view","4. Ridge and Lasso Regression","5. Resampling Methods","6. Logistic Regression","8. Support Vector Machines, overarching aims","9. Decision trees, overarching aims","10. Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods","11. Basic ideas of the Principal Component Analysis (PCA)","13. Neural networks","7. Optimization, the central part of any Machine Learning algortithm","12. Clustering and Unsupervised Learning","Exercises week 34","Exercises week 35","Exercises week 36","Exercises week 37","Exercises week 38","Exercises week 39","Exercises week 41","Applied Data Analysis and Machine Learning","2. Linear Algebra, Handling of Arrays and more Python Features","Project 1 on Machine Learning, deadline October 7 (midnight), 2024","Teaching schedule with links to material","1. Elements of Probability Theory and Statistical Data Analysis","Teachers and Grading","Textbooks","Week 34: Introduction to the course, Logistics and Practicalities","Week 35: From Ordinary Linear Regression to Ridge and Lasso Regression","Week 36: Linear Regression and Statistical interpretations","Week 37: Statistical interpretations and Resampling Methods","Week 38: Logistic Regression and Optimization","Week 39: Optimization and Gradient Methods","Week 40: Gradient descent methods (continued) and start Neural networks","Week 41 Neural networks and constructing a neural network code"],titleterms:{"1":[0,15,16,17,18,24,29,30],"11":36,"16":33,"2":[0,15,16,17,18,29,30,31],"2023":27,"2024":[24,34,35,36],"21":[],"23":34,"26":30,"27":34,"3":[0,15,16,29,30],"30":35,"34":[15,29],"35":[16,30],"36":[17,31],"37":[18,32],"38":[19,33],"39":[20,21,34],"4":[0,30],"40":[21,35],"41":[21,36],"5":0,"7":[24,36],"9":32,"case":[8,10,26,30,31,33,34],"class":33,"do":[1,31,32,34,35,36],"final":[12,21,30,31,34,35,36],"function":[0,1,6,7,8,10,11,12,13,21,24,26,29,30,31,32,33,34,35,36],"import":[5,21,23,29,30,31,35],"new":[4,31,32],A:[0,1,4,8,9,21,29,31,32,33,35],AND:[35,36],And:[21,29,30,31,33,34,35],But:[21,34,35],For:30,In:27,Ising:6,OR:[35,36],The:[0,1,2,3,5,6,7,8,9,11,12,17,22,29,30,31,32,33,34,35,36],To:[29,30],With:[4,31],about:[29,30],abov:31,activ:[1,12,31,35,36],ad:[0,6,17,24,29,30,35,36],adaboost:10,adagrad:[13,21,34,35],adam:[13,21,34,35],adapt:[10,21,34,35],adjust:[1,36],advanc:[21,35],adversari:4,again:[3,9,33],ai:[24,29],aim:[8,9,17,18,19,20,21,29],aka:[29,30],al:[21,35],algebra:[23,29],algorithm:[9,10,11,12,21,30,34,35,36],algortithm:[13,33,34],all:8,an:[0,4,10,29],analys:[5,30],analysi:[0,5,6,11,22,24,26,29,30,31,32],analyt:[0,16,17,21],ani:[13,33,34],anoth:[9,31,32],appli:22,approach:[0,8,14,29,32,34,35],approxim:[12,36],architectur:[1,36],argument:[34,35],arrai:[23,29],artifici:[35,36],assist:27,assumpt:[31,32],august:30,autocorrel:26,autograd:[2,13,21,34,35],automat:[13,21,34,35],avoid:[],b:[17,24,34],back:[1,11,12,36],background:[22,24,32],bag:10,base:[13,21,32,34,35],basic:[0,5,7,9,10,11,23,30,31,32,33],batch:[1,34,35],bay:[5,31,32],befor:11,beta:[31,32],better:[8,35,36],bia:[6,24,32],bias:36,binari:[1,36],bind:29,bird:10,boldsymbol:[30,31,32],boost:10,bootstrap:[6,10,32],boston:0,breast:1,brief:[29,32,33,34],bring:[12,36],build:[1,3,9],c:[24,29],calcul:30,can:[21,29,32,34,35],cancer:[1,7,9,11,33],cart:9,center:30,central:[13,22,26,32,33,34],chain:[12,36],challeng:33,chang:10,channel:29,chi:[0,29],choos:[1,36],cifar01:3,classic:11,classif:[1,9,10,33,36],classifi:[8,33],clip:1,cluster:14,cnn:3,code:[0,1,2,5,9,11,12,13,14,21,29,30,31,32,33,34,35,36],collect:[1,3,36],come:33,commun:29,compact:33,compar:[2,10],comparison:31,compet:[21,34,35],complet:30,complex:[0,6,24,30],complic:[6,34,35],compon:11,comput:[9,34,35],computation:32,computerlab:29,con:9,concept:26,condit:[31,32,33,34],confid:32,conjug:[13,34],construct:36,continu:35,contn:29,convex:[8,13,33,34],convolut:[3,12,35,36],correctli:[31,32],correl:[11,30,33],correspond:[33,34],cost:[1,10,30,31,32,33,34,36],cours:[22,28,29],covari:[5,11,26,30],cover:29,cross:[6,24,32,33],cython:29,d:24,data:[0,1,3,6,7,9,11,15,16,22,24,26,29,30,31,33,36],dataset:[1,3,36],deadlin:[24,29],decai:[2,34,35],decis:[9,10],decomposit:[5,11,17,23,30],deep:[1,2,29,33],defin:[1,29,36],definit:36,degre:[0,30],deliveri:24,delta:32,dens:[0,29],deriv:[5,12,30,31,32,33,34,36],descent:[2,10,13,21,33,34,35],descript:24,design:30,detail:[3,29],develop:[1,36],diagon:11,differ:[8,34,35],different:21,differenti:[2,13,34,35],diffus:2,dimension:[2,3,8,24,30],directli:[34,35],disadvantag:9,discret:26,discuss:33,distribut:[5,26,31,32],distrubut:32,doe:[30,31,35,36],domain:26,dot:34,down:1,dropout:1,e:24,each:33,economi:30,electron:24,element:[0,26,29,34,35],elimin:23,energi:29,ensembl:10,entropi:[9,33],environ:[0,15,29],equat:[0,2,12,29,30,31,33,34,36],error:[0,10,29,30,32],essenti:29,estim:[31,32],et:[21,35],etc:29,euler:2,evalu:[1,36],exampl:[0,1,2,3,4,6,7,8,9,10,21,29,30,31,32,33,34,35,36],exercis:[0,6,15,16,17,18,19,20,21,29,30],expect:[18,26,31,32],expens:32,experi:26,explor:[0,15,16,29],exponenti:2,express:[17,18,30,33,34],extend:[33,34],extrapol:4,extrem:[10,29],ey:10,f:24,fall:27,famili:[1,29,30],famou:23,fantast:30,featur:[9,23,30],feed:[1,12,35,36],find:[32,34],fine:1,first:[4,12,29,30,31,33,34,36],fit:[0,10,29,31],fix:30,fold:[32,33],forc:3,forest:10,format:[24,29],forward:[1,2,12,35,36],fourier:3,frank:[6,24,30],freedom:[0,30],frequent:30,frequentist:[0,29],fridai:[],from:[5,10,12,21,30,31,32,33,34,35,36],full:[2,36],further:[3,5,30],g:24,gan:4,gate:[35,36],gaussian:23,gd:[13,21,34,35],gener:[4,9,29],geometr:[11,33,34],get:[21,35],gini:9,good:[0,29],goodfellow:[21,35],grade:[27,29],gradient:[1,2,10,13,21,33,34,35],grid:33,group:33,growth:2,ha:22,handl:[23,29,30],happen:[31,32],hessian:[30,33,34],hidden:2,histogram:32,homework:[33,34],hous:0,how:33,hyperbol:[35,36],hyperparamet:[1,36],hyperplan:8,i:1,id3:9,idea:11,ideal:[33,34],ident:[31,32],identifi:32,ii:29,iid:[31,32],illustr:[31,35,36],implement:[1,35,36],implic:[5,30],improv:[1,34,36],includ:[13,21,33,34,35],increment:11,independ:[31,32],index:9,inform:27,input:2,instal:[22,24,29],instructor:27,intercept:30,interpret:[5,11,29,30,31,32,33,34],interv:32,introduc:[11,13,21,30,34,35],introduct:[0,6,22,23,24,29,35,36],invers:[5,23,31],invert:30,iter:[10,34],its:30,jacobian:30,jax:[13,21,34,35],job:[35,36],julia:29,jungl:10,k:[32,33],kera:[1,3],kernel:[8,11],l:36,lab:[32,33,34,35],lagrangian:8,lambda:33,lasso:[5,6,24,30,31,32,33,35],last:[30,33,35],later:[5,30],layer:[1,2,3,12,36],learn:[0,1,2,11,13,14,15,16,21,22,24,29,30,31,32,33,34,35,36],least:[5,6,18,24,29,30,31],lectur:[29,30,31,32,33,34,35,36],level:10,librari:[22,29],likelihood:[7,31,32,33],limit:[1,13,26,32,33,34,35],linear:[0,8,13,23,29,30,31,33],link:[5,11,25,28,30,31,32],literatur:24,logist:[7,29,33,34,35,36],loop:[34,35],loss:[30,33,34],lu:23,machin:[0,8,13,22,24,29,33,34],made:[31,32],main:[26,29],make:[0,9,10,15,16,29,30],mani:[10,12,36],manipul:30,margin:[31,32],mass:29,materi:[24,25,29,30,31,32,33,36],math:[5,30],mathemat:[3,5,8,30,34,35,36],matric:[5,23,29,31],matrix:[1,5,11,12,23,29,30,31,33,34,35,36],matter:[0,29],max:30,maximum:[31,32,33],mean:[0,30,31,33],measur:33,meet:[5,10,26,29,30],mercer:8,method:[6,9,10,13,21,24,29,32,33,34,35],midnight:24,min:30,mini:[34,35],minibatch:[21,34,35],minim:[29,33],ml:29,mle:[31,32],mlp:[12,36],mnist:[3,4],model:[0,1,4,6,12,29,35,36],moment:[34,35],momentum:[13,21,34,35],mondai:[30,31,32,33,34,35,36],moon:[8,9],more:[3,6,21,23,24,29,30,31,32,33,34,35],multi:[35,36],multilay:[12,35,36],multipl:[1,3,36],multipli:8,need:[24,29],network:[1,2,3,4,7,12,29,33,35,36],neural:[1,2,3,4,7,12,29,35,36],neuron:[35,36],newton:[21,33,34,35],noen:21,non:8,none:[34,35],normal:[0,1,32],notat:[12,35,36],note:[21,24,30,31,35],now:[1,9,13,21,31,32,34,35],nuclear:[0,29],nueral:33,numba:29,number:[0,2,21,26,30,34,35],numer:[2,24,26],numpi:[21,23,29,34,35],object:[3,36],obtain:11,octob:[24,36],od:2,off:[6,24],ol:[5,6,21,24,31,32,34,35],one:[2,12,33,34,36],ones:[35,36],oper:23,optim:[1,8,13,22,29,30,33,34,35,36],order:[13,21,34,35],ordinari:[5,6,18,24,29,30,31],organ:[0,29],orient:36,oslo:28,other:[4,9,11,12,23,24,29,30,33,35,36],our:[0,4,5,11,13,29,30,33,34,36],outcom:[22,29],output:2,overarch:[0,4,8,9,17,18,19,20,21,29,30],overview:[10,29,34,35],own:[0,10,11,15,16,29,30],packag:[23,29],panda:[29,30],paper:24,paramet:[29,30,33,34,35],part:[13,22,24,30,33,34],partial:2,pass:[1,36],pca:11,pdf:26,pencil:24,perceptron:[12,35,36],perform:[1,9,36],period:3,perspect:1,plan:[30,31,32,33,34,35,36],plot:[32,33],point:4,poisson:2,polynomi:[3,31],popul:2,popular:29,practic:[13,21,27,29,34,35],pre:[1,3,36],preambl:24,predict:4,predictor:33,preprocess:30,prerequisit:[3,22,29],princip:11,principl:3,pro:9,probabl:[5,26,31,32],problem:[1,2,13,21,29,30,31,33,34,35,36],procedur:[9,29],process:[1,3,36],product:34,program:[2,13,24,33,34],project:[6,24,29,33],prop:[13,34,35],propag:[1,12,36],properti:[5,26,30,33],python:[0,9,15,22,23,29],quick:8,r:29,random:[10,11,26,33],raphson:[33,34],rate:[21,34,35],read:[9,29,30,32,33,35],real:[6,24,29],recommend:[29,30],rectangular:31,recurr:[4,12,35,36],recurs:[34,35],reduc:[0,30],reduct:3,refer:24,reformul:2,regress:[0,5,6,7,9,10,13,17,18,24,29,30,31,32,33,34,35,36],regular:[1,33,36],relat:30,relev:[28,30,33,35,36],relu:1,remark:3,remind:[6,8,29,33,34],repeat:30,replac:[13,34,35],report:24,repositori:32,repres:36,requir:[2,22],resampl:[6,24,32],rescal:[6,31],residu:30,resourc:2,result:[30,31],revisit:[13,33,34],rewrit:[29,30,32],rewritten:33,ridg:[0,5,6,17,18,24,30,31,32,33,34,35],rm:[13,34,35],rmsprop:[21,34,35],rule:[12,36],s:[8,10,21,32,33,34,35],same:[13,21,32,34,35],sampl:11,scale:30,schedul:[25,29],schemat:9,scheme:2,scienc:29,scikit:[0,1,11,15,16,29,30,31,32,33,34,36],search:33,second:[13,21,34,35],select:33,semest:27,sensit:[33,34],septemb:[31,32,33,34,35],session:[30,31,32,33,34,35,36],set:[0,2,3,9,12,15,29,30,33,36],sgd:[13,34,35],should:1,similar:[13,21,34,35],simpl:[0,4,9,13,29,30,31,33,34,35],singl:[10,35,36],singular:[5,11,17,30],size:30,slightli:[34,35],soft:8,softmax:[1,36],softwar:[24,29],solv:[2,31,33,34],solver:13,some:[13,23,30,33,34],specifi:2,split:[0,15,16,29,30],squar:[0,5,6,10,18,24,29,30,31],standard:[13,30,32,34],start:[21,35],state:[0,29],statist:[5,6,22,26,29,31,32],steepest:[10,13,33,34],step:[32,33,34,35],still:30,stochast:[13,21,26,34,35],stop:[34,35],strongli:29,studi:33,subtract:30,suggest:[29,33,35],sum:32,summari:[27,29,35],superposit:3,supervis:1,support:8,svd:[5,30,31],syntax:34,systemat:3,t:[30,31],taken:[21,35],teach:[25,27],teacher:[27,29],technic:31,techniqu:[6,11,24],technolog:22,tensorflow:[1,3],tent:29,term:[32,36],test:[0,1,15,16,29,30,31,36],text:29,textbook:[28,29],than:[33,34],theorem:[5,8,11,12,26,31,32,36],theori:26,thi:[17,18,19,20,21,29],think:30,thursdai:[],time:[34,35],tip:[13,21,34,35],togeth:[12,36],tool:[24,29],top:1,topic:29,toward:11,trade:[6,24],tradeoff:[6,32],train:[0,1,4,15,16,29,30,36],transform:3,tree:[9,10],tuesdai:[31,35,36],tune:1,two:[3,8,22,24,30,33],type:[2,4,12,29,35,36],uio:29,understand:32,univers:[12,28,36],unsupervis:14,unsupport:34,up:[0,2,9,12,15,21,29,30,32,33,35,36],us:[0,1,2,3,7,13,21,22,24,29,30,33,34,35,36],usag:[31,32],valid:[6,24,32,33],valu:[5,11,17,18,26,30,31,32,33],vari:[21,34,35],variabl:[26,33,34],varianc:[6,24,31,32],variou:[0,15,29,32,33],vector:[8,12,23,29,30,35,36],video:[33,34,35],view:[0,4,10,30],visual:[1,9,36],vs:3,wai:[9,21,32,35],warm:[21,35],wave:2,we:[21,29,34,35],wednesdai:[31,35,36],week:[15,16,17,18,19,20,21,29,30,31,32,33,34,35,36],weekend:33,weekli:25,weight:36,what:[0,29,30,31,32],when:[34,35],which:[1,21,34,35],why:[29,30,32,35,36],wisconsin:[7,33],wrap:[30,32],write:[4,11,24,31],x:[30,31],xgboost:10,xor:[35,36],yet:31,your:[0,10,15,16,29,30],yourself:33,z_j:36}}) \ No newline at end of file +Search.setIndex({docnames:["chapter1","chapter10","chapter11","chapter12","chapter13","chapter2","chapter3","chapter4","chapter5","chapter6","chapter7","chapter8","chapter9","chapteroptimization","clustering","exercisesweek34","exercisesweek35","exercisesweek36","exercisesweek37","exercisesweek38","exercisesweek39","exercisesweek41","intro","linalg","project1","schedule","statistics","teachers","textbooks","week34","week35","week36","week37","week38","week39","week40","week41"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":4,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":3,"sphinx.domains.rst":2,"sphinx.domains.std":2,"sphinx.ext.intersphinx":1,sphinx:56},filenames:["chapter1.ipynb","chapter10.ipynb","chapter11.ipynb","chapter12.ipynb","chapter13.ipynb","chapter2.ipynb","chapter3.ipynb","chapter4.ipynb","chapter5.ipynb","chapter6.ipynb","chapter7.ipynb","chapter8.ipynb","chapter9.ipynb","chapteroptimization.ipynb","clustering.ipynb","exercisesweek34.ipynb","exercisesweek35.ipynb","exercisesweek36.ipynb","exercisesweek37.ipynb","exercisesweek38.ipynb","exercisesweek39.ipynb","exercisesweek41.ipynb","intro.md","linalg.ipynb","project1.ipynb","schedule.md","statistics.ipynb","teachers.md","textbooks.md","week34.ipynb","week35.ipynb","week36.ipynb","week37.ipynb","week38.ipynb","week39.ipynb","week40.ipynb","week41.ipynb"],objects:{},objnames:{},objtypes:{},terms:{"0":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,27,29,30,31,32,33,34,35,36],"00":[0,1,5,6,9,11,29,30,31,35,36],"000":[1,3,9],"0000":[5,9],"00000":[9,34],"000000":[5,11,30],"00000000e":[5,30,35,36],"00001":34,"00001572":[],"00001716":35,"00002":34,"00002585e":30,"00003":34,"00003828":35,"00005":34,"00007":34,"00007706":35,"00007738":[],"00009":34,"0001":[1,17],"00010067":34,"00010366":[],"00011577":21,"00012":34,"000137":26,"00013938":36,"00013955":21,"00014166":21,"00016062":21,"00016449":21,"00016535":[],"00016719":34,"00017733":[],"00018":34,"00018053":[],"00018212":21,"00018651":21,"00019258":35,"00019998":5,"0002065":21,"00021147":21,"00021270681344726395":[],"00021771":36,"000225":34,"00022969":[],"00023":34,"00023414":21,"00023813":[],"00023978":21,"00024087":5,"00024929":34,"00025662":34,"00026549":21,"00027188":21,"0002762":34,"00027746":34,"00028":34,"00028167":34,"00029012":5,"0002926":[],"00030102":21,"00030601":34,"00030827":21,"00031208":34,"00031535148309577417":[6,31],"0003153514830958095":[6,31],"00033904":34,"00034006":36,"00034132":21,"00034576":34,"00034688149480437765":[],"00034944":5,"00034953":21,"0003701342170783489":9,"00037564":34,"00037737":21,"00038309":34,"000387":21,"00039632":21,"00041619":34,"000417932":2,"00042089":5,"00042093":34,"00042444":34,"00042721":[],"0004388":21,"00044":34,"00044937":21,"00046006":34,"00046111":34,"000464088":2,"00046631":[],"00047025":34,"00048158":21,"00049754":21,"00050694":5,"00050952":21,"00051088":34,"00051916":[],"00052102":34,"00053001":[],"00053118":36,"00053122":[],"00056414":21,"00056603":34,"00057726":34,"00057772":21,"00058016":[6,31],"00060":34,"00060704":6,"00061058":5,"00062592":6,"00062668":[],"000626681519836":[],"00062713":34,"00063362":32,"00063866":32,"00063957":34,"00063965":21,"00065505":21,"00066668":[6,31],"00067008":34,"00068091":32,"00068734":[6,31],"00069":34,"00069123":6,"00069482":34,"0007086":34,"00072527":21,"00073541":5,"00074274":21,"00075590":32,"00076202":34,"00076495":[6,31],"00076908":6,"00076983":34,"0007698473260556325":[6,31],"0007698473260556343":[6,31],"000783":[],"00078324":[],"00078509":34,"00079125":6,"00079904":32,"00079968":5,"00080497":[],"00082235":21,"0008297":36,"0008297120772365539":[],"00083355":32,"00084215":21,"00084707":6,"00085292":34,"00085892":6,"00086984":34,"00087697":[6,31],"00088573":5,"00089193":32,"00092678":6,"00092898":32,"00093243":21,"00094499":34,"00095488":21,"00095624":[],"00096314":5,"00096373":34,"00099778":[],"001":[1,2,8,13,17,31,33,34],"00100081":[],"00100519":[6,31],"00100913":[],"001047":34,"0010479245693919886":[6,32],"00105081":[6,31],"00105724":21,"00106677":5,"00106776":34,"00107405":[6,31],"00108":34,"0010827":21,"00108471":[],"00109354":[],"00111756":[6,31],"00114401":[],"00114451":[],"00114855":[],"0011526":[6,31],"00115631":34,"00115999":5,"00116001":34,"00118302":34,"00118584":6,"00119688":32,"00119876":21,"00122762":21,"00125057":[],"00126053":34,"00128479":5,"00128523":34,"00129599":36,"00130885":[],"00131072":34,"001323":[6,31],"00133638":[],"00134424":35,"00135922":21,"00136125":[],"00137814":6,"00139195":21,"00139705":5,"00140846":32,"00141727":34,"00142396":34,"00143013":[],"00144539":34,"0014522":34,"001468":[],"00146807":[],"00149311":[6,31],"00149679":[],"00149956":[6,31],"00151416":[],"00151426":35,"00152117":[6,31],"00154115":21,"00154733":5,"00154853":32,"00156374":6,"00157766":34,"00157826":21,"00158":34,"00160895":34,"00161463":35,"00162921":[],"00163548":[],"00167329":34,"00168251":5,"00168745":[],"00169":34,"00170579":35,"00170809":[],"00171171":[],"00172865":[],"00174276":[6,31],"00174738":[],"00174743":21,"00174795":34,"00175331":[6,31],"00178263":34,"00178952":21,"001795":[],"00180673":34,"00181885":35,"0018310257999764163":[],"00186347":5,"00187032":[],"0018798":[],"001880":5,"00191076":[],"00192154":35,"00193661":34,"0019575":[],"00197505":34,"00198129":21,"00200":8,"00202433":36,"00202624":5,"00202756":[6,31],"00202904":21,"0020489":35,"00206234":[],"00208188":34,"00209403":[],"00211418":[],"00211924":21,"00212766":[],"00213888":[],"00214559":34,"00216458":35,"00217499":[6,31],"00217968":[],"00218823":34,"00219195":32,"00220013":[],"00223857":[],"00224413":5,"00224638":21,"00225842":34,"0022626":[],"00228740":6,"00229111":[],"00230059":21,"00230805":35,"0023548":[6,31],"00236918":[],"00237699":34,"002381316302584885":[6,31],"0023813163025848865":[6,31],"00242441":34,"0024271":[],"00242954":32,"00242999":6,"00243186":[6,31],"00243835":35,"0024401":5,"002446":[],"00248232":[],"00249435":[6,31],"00250787":[],"00251359":[],"00254671":21,"00254973":[],"00256001":[],"00256622":[],"00259997":35,"00260839":21,"00263296":34,"00263755":[],"00263812":[],"00264":34,"00266858":2,"00268602":34,"00270244":5,"00270262":[],"00272337":[],"00274676":35,"00274989":[6,31],"00275768":[],"00279722":[],"00282226":[],"00282302":34,"00288656":21,"00289724":[6,31],"00290613":[],"00291535":34,"0029276":[],"00292882":35,"00293758":[],"00293838":5,"00295713":21,"00297571":34,"00298783":[],"0030094":[],"00302547":[],"00309418":35,"00310113":2,"00312361":[6,31],"00315593":6,"003162":36,"00319887":[],"0032153180657605116":[6,32],"00322456":34,"00323332":[6,31],"0032542":5,"00325450":32,"00326986":21,"00327104":[],"00327797":[],"00329616":34,"00329927":35,"00330046":[],"003301":[6,31],"00331927":[],"00334047":[],"00334797":[],"00335101":[],"00335174":21,"0033955154592040936":[6,32],"0034318":34,"00348246":[],"00348553":35,"00352878":34,"00353823":5,"00353938":[],"00355614":34,"00359628":[],"0036237":[6,31],"0036367":[6,31],"00363823":35,"00364159":[],"00364235":[],"00364967":34,"00365819":[],"00369758":[6,31],"00369852":21,"00371656":35,"0037314":[],"00379682":21,"0038287":[],"0038335":[6,31],"00389038":34,"003909404072811226":[6,32],"00391839":5,"0039259":[],"00392639":35,"0039455":[],"00399521":[],"0039987":[6,31],"00399972":[],"004":[5,31,32],"00403677":34,"00405581":[],"0040792":[],"00408":34,"004091940707753939":[6,32],"00410387":[6,31],"00410478":6,"004113634617443131":[6,30,31],"00411363461744314":[6,30,31],"004113634617443147":[6,30,31],"0041148":[],"00412":34,"00415497":[],"00415598634586135":[6,32],"00416103":34,"00416704":21,"00418347":[],"00418664":35,"00420072":32,"00424909":2,"00424967":[6,31],"00426027":5,"00429456":21,"0042992":34,"00432864":[],"00433417":11,"00434043":[],"0043587":[],"00437846":[],"00438318":[],"00440346":[6,31],"00441097":34,"004423":35,"00443743":[6,31],"0044505":34,"00445186":34,"00445655":11,"0045162":[],"00455966":[],"004579219539673834":[6,32],"00458631":[],"00458878":[6,31],"004610275230656212":[6,32],"00462287":[6,31],"00462662":[],"00464677":21,"00465099":32,"0046544":[],"00468914":26,"00471617":35,"00471782":5,"00472199":6,"00472276":[],"00472512":[6,31],"00474898":[],"00476012":34,"00478417":[],"00480881":[],"00483858":21,"00487029":34,"00493903":36,"0049544":[6,31],"00497837":31,"00498243":35,"004999999999999991":[],"005":0,"005000000000000001":[],"00500716":[],"00502886":[],"00503932":21,"00507531":[],"00509128":34,"00512599":[],"00512927":5,"00513051":[],"00515181":[],"00515889":21,"00517114":[6,31],"00519717":[],"00520911":34,"00521014":[],"00522055":[],"00526348":[6,31],"00527578":[],"0053018":[6,31],"00531268":35,"00537955":[],"00539563":21,"00544547":34,"00546503":21,"00547113":[],"00551372":34,"00552462":[],"00554202":[],"00554552":[6,31],"00556826":[6,31],"00556946":[],"0055715":34,"00557893":[],"0055997":[],"00560098":[],"00561262":35,"005643":[],"00564344":[],"00564365":34,"00566707":[],"0056799":5,"00569512":[],"00570321":[],"0057065":[],"00571608":[],"00572613":[],"00573661":[],"00573727":[],"00574735":[],"00578809":[],"00579953":[6,31],"0058243":34,"00585143":21,"00586355":[],"00588657":[6,31],"0059267":21,"00593362":[],"0059591":34,"00597698":[],"00598464":35,"00606382":[],"00607783":6,"006162":[6,31],"00617221":[],"00617499":5,"0062202":[],"00622949":34,"00623535":[],"00625051":[],"00625672":[],"00627115":[],"00630331":[6,31],"00632251":35,"00633289":[],"00634299":[],"00634575":21,"00635016":[],"00637188":[],"00637367":34,"0063878":[],"00641423":[],"00642221":[6,31],"00642737":21,"00644":34,"0064472":31,"00647029":[],"00654835":[],"00659604":[],"00660427":[6,31],"00666287":34,"00667611":[],"00672607":[6,31],"00673407":[6,31],"00674158":35,"00676256":23,"00676387":[6,31],"00679013":[],"0068011":[6,31],"00681708":34,"00683748":5,"00683875021199284":[],"00683964":[6,31],"00685287":[],"00687309":[],"00688012":[],"00688182":21,"00689214":34,"00691012":[],"00694315":[],"0069668":[],"00697033":21,"007024126888938232":[6,32],"00702721":[],"0071129":[],"00712219":35,"0071264":34,"00715512":[],"00719176":[6,31],"00727646693":[0,29],"00729134":34,"00731392e":30,"007315":30,"00732665":[],"0074331":5,"00746317":21,"00747773":[],"00748862":[],"00754823":[],"00755917":21,"00759119":6,"00759427":35,"00762217":34,"00764333":[],"007658477904313023":[],"0076989":[],"00771475":36,"0077313":[],"00779859":34,"00781918":32,"00784393":[6,31],"00789262":[],"00791263":[],"00792032":[],"00798909":[],"00802302":35,"00803064":[6,31],"008043811612683473":[],"00805074":32,"00809364":21,"00812487":[],"00813803":6,"00815244":34,"00816675":[],"00817631":[6,31],"00818251":[],"00819774":21,"00823002":5,"00827728":[6,31],"00828121":[],"00831018":[6,31],"00834112":34,"00834567":[6,31],"00838555":[],"00848904":[6,31],"0085548":35,"008560581831215528":[],"0085639":[],"00859693":[],"00860892":[],"00861518":34,"0086649156":[0,29],"008675369724975977":5,"00871959":34,"008753288788081405":30,"00877737":21,"00881939":[],"00885858":35,"00889027":21,"00889475":[],"00891702":[],"0089214":34,"00894639":5,"00903778":35,"00905423":[6,31],"00908537":[],"009163470508352218":5,"009164545680330616":[6,32],"00917248":[6,31],"00919984":[],"009211602191395454":30,"00925406":34,"00930146":[],"0093262":34,"009338082195270294":[],"00934327e":30,"00934499":[6,31],"00935742":[],"00939407":[],"009396472959497925":[],"00940611":[],"00942574":[],"00943959":[],"00951885":21,"00954206":34,"00955125":[],"00956827":[],"00958615":[],"0096208":[6,31],"00963683":35,"00964129":21,"00974758":[],"00979357":[],"00982052":[],"00989834e":[],"00990475":5,"00992331":[6,31],"00996754":[6,31],"00996762":[],"00997502":34,"01":[0,1,2,5,6,9,11,13,17,21,28,29,30,31,34,35,36],"010018312644137363":[6,32],"01003519":[],"01006":34,"01006984":[],"0100706":[6,31],"01009321":[],"01013849":[],"01014331":[],"01018089":35,"01020588":34,"01024875":[],"01031":34,"01032298":21,"01032533":[],"010331721306655127":[6,32],"010348289064969316":[],"01035006":[],"01039879":[],"01044475":[],"01045576":21,"010516485576645508":[6,32],"01060492":[],"010612904886352397":[],"01066519":[6,31],"01066897":34,"01067432":[],"01070103":[],"01075018":[],"01076611":5,"01076897":34,"01080465e":[],"01084359":[],"01085571":35,"01091589":34,"01093529":[],"01093553":[],"01098247":[],"0110":26,"01107333":[],"011076219011379514":[6,32],"011156605304609659":[],"01119504":21,"01119738":[],"01119981":[],"011208613520466846":[],"011225":2,"01123792e":30,"01129731":35,"0113104":[6,31],"01131771":[],"01133903":21,"01141119":34,"01146857":35,"01161645":[],"0116753":34,"01178857":[],"01179128":[],"01179415":[],"01179792":[6,31],"011818646101922625":30,"011886":[],"01191824":5,"01199741":[],"01205039":36,"01206221":[],"012073649446193166":[6,32],"0121289":[],"01214076":21,"01214862":[],"0121766":[],"01219292":[6,31],"01220505":34,"01222822":30,"01222875":35,"01223198":[6,31],"01223754":[],"01229102":21,"01229692":21,"01231917":[6,31],"01234":[],"01234261":[],"01241284":[],"01244297":[],"01247909":[],"01248754":34,"01249445":35,"01250964":[],"01261048":[],"01265755":30,"012658":30,"01266999":[],"01267007":31,"0126711":[],"01268737":[],"01280793":[],"01288787":[],"01290947":[6,31],"0129191":35,"01295356":5,"01305415":34,"013121574015585152":[6,32],"013121574015585155":[6,32],"01315875":[],"01316233":[],"01316638":21,"01318643":[6,31],"01323523":[],"01327148e":[],"01329403":[],"01332832":[],"01333573":21,"01335628":34,"0134113":[],"01346122":34,"01347916":[6,31],"01348565":[6,31],"01349244":[],"01353638":[],"01355882":[],"01367553":[6,31],"0137297":34,"01373484":[],"01376216":[],"01377545":35,"01393496":[],"01396231":34,"01397146":[6,31],"01399457":[],"01405935":[6,31],"01406777":[],"01409478":[],"01416528":[6,31],"01427864":21,"01428546":34,"01433809":5,"014436800088904942":[6,32],"01444013":[],"0144623":21,"01449782":[6,31],"01455304":35,"01458337":[6,31],"014586":30,"01458611":30,"0146081":[6,31],"01462254":[],"01463049":[6,31],"01464686":[],"01473759":[],"01480256":[],"01493365":34,"014934":34,"01499192":[],"01506354":[],"01507238889517706":[6,31],"01507238889517717":[6,31],"01509793":[],"01511937":34,"01522108":21,"01527928":34,"01530321":[],"01531845":[6,31],"01532738":[],"01543076":[],"01548486":21,"01549377":[6,31],"01551724":[],"01551775":35,"015518":[],"01551815":[],"01552874":[],"01558197":5,"01568403":21,"01572":34,"01573062":[],"01573768":[],"01584129":[],"01594452":32,"01597256":34,"01600363":[],"01604235":[],"01620955":[],"01624447":[],"01625794":[],"01628578269596628":[6,32],"01633913":[6,31],"01634224":34,"01639344":35,"01640891":6,"01641044":[],"01643795":[],"0164974":[],"01654574":[],"01655318":[6,31],"01655384":[],"016587414993043573":[6,32],"01674956":[],"01679297":21,"01681173":[],"01681612":[],"01682652":34,"01691985":[6,31],"0169643":5,"01700897":21,"01706166":[],"01708375":34,"01708781":[6,31],"01708852":[6,31],"01713366":[6,31],"01717549":[],"01724499":5,"017355848195593347":[6,32],"01735584819559336":[6,32],"01737634":[],"01747915":34,"01748034":35,"01756114":[],"01759442":[],"01759974":[],"01760144":[],"017665":5,"01772779":[],"01779091e":[],"01783096":[],"01783414e":30,"0178462":[],"01793261":[],"0179826":[],"01811279":[],"01817048":[],"0182116":21,"018232":30,"01826811e":[],"01827225":34,"01827302":[],"01830039":[],"01831050e":[6,31],"01831190e":[6,31],"01844584":21,"01844822":[],"01846605":35,"01863203":[],"01866537":[6,31],"01869515":34,"01872002":[],"01873344":11,"01873869":5,"01881237":[],"01882264":36,"01897462":[],"01898855":[6,31],"01905384":[],"01905883":[6,31],"01908936":[6,31],"01915337":[],"01922269":[],"0193075":[],"0195302":[],"01954342":34,"01963611":[6,31],"01969093":35,"01969145":[6,31],"01975006":21,"01975416527185249":[6,32],"01975848":[6,31],"01979808":[],"01999575":34,"02":[0,4,6,7,12,29,30,31,33,35,36],"0200041":21,"02014577":[],"02016185":[],"02024962":[6,31],"02026756":[],"02031987":[],"02032056":[],"02034655":[],"02054837e":[6,31],"0206033":[],"02068067":[6,31],"02073509":5,"02077431":31,"02079913":35,"02084474":[],"02087411":[],"02090304":34,"02091662":[],"02092464":[],"02098261":[6,31],"02102403":[],"02103315":34,"0211429":[],"02117843":[],"02123176":[6,31],"02126205":[],"02137508":23,"02138683":34,"02141849":21,"02148021":34,"02151521":[],"021544346900318832":31,"02156196":[],"02156565":[],"021592704588025022":[6,32],"021592704588025025":[6,32],"02164667":[],"02169399":21,"02175561":23,"02183817":[],"02189606":35,"02189863":[],"02189994":[],"02198702e":[6,31],"02198703e":[6,31],"022":[],"02207054":[],"02208512":[6,31],"02214409916811925":26,"02218045":35,"02218076":[],"02228115":[6,31],"02229529":[6,31],"02235723":34,"02252765":5,"02265404":[],"02281004":[],"02286267":[],"02287468":34,"02296298":34,"022999498260366312":[6,32],"0231353":[],"0232":[],"0232101":[],"02322297":[],"02322594":[],"02322786":21,"023295599127611474":[],"02330799":[],"02334754":[],"02338085":[],"02342235":35,"02345858":[],"02348765":[6,31],"02352663":21,"02354386":23,"02355756":[],"02358547":[],"02361665":[],"02365049":[6,31],"02374496":[],"02386932":[],"0239126":34,"02391906":[],"024":[],"024011020121022356":[],"02404706":[],"0241039":[],"02413786":21,"02424794":32,"02432309":[],"02441422":[],"02446604":34,"02447063e":[],"0245528":[6,31],"02456":34,"02459084":34,"02472936":[],"02474828":[],"024792624800382218":5,"02492265":5,"02496085":34,"02498282":35,"02498832":[6,31],"02500488":[],"02502325":[],"02503392":[],"02503753":[6,31],"02511518":6,"02519009":21,"02521917":[],"02522069":6,"02527621":[],"0253208":[],"02540212":[],"02544154":[],"02545":34,"02546675":32,"0255141":21,"02552966":23,"02557617":34,"02564828":[],"02566356":[],"025709":[11,30],"02572685":[],"02576358":[],"02576685":[],"02584233":[],"02586427":[6,31],"02594314":[],"02601643":[],"0260906":[6,31],"02612988e":30,"02616812":34,"02622039":[],"0262517":[],"02625193":8,"02629144":34,"0263106":[],"02631942":[],"02632742":[],"02636268":35,"02649469":[],"026495":[],"02651857":[],"02654585":[],"02660572763718093":[6,32],"026605727637180936":[6,32],"02664408":[],"02693015":[],"02693858":31,"02707227":5,"02723445":[6,31],"02731808":21,"02732402":[],"02735547":34,"02754248":[],"027609773491022525":[6,32],"02760977349102253":[6,32],"02766946":21,"02769274":[],"02780107":[],"02784266":[],"02787184":[],"02797154":[],"0279886":34,"02806268":[],"02808229":[],"02809972":[],"02813369":35,"02850506e":30,"02857":4,"02859759":[],"028638258927275215":[],"02876848":[],"02895918":31,"02900153e":34,"029003":[],"02901273e":30,"02909574":[],"02920675":[],"02923006":[],"0292555":21,"02925855":34,"02928194":[],"02930753":21,"02940083":36,"02944152":[],"02946852":[],"029483":5,"02962583":21,"02963147":35,"02965159":[],"02970225":21,"029733":30,"02973733":[],"02976145":[6,31],"02980537":[],"02993573":34,"02994311":5,"02f":[6,24],"03":[1,6,30,31],"03000689":21,"03015288036252618":[],"03016341":[],"03032441e":[6,31],"03033791":[],"0303586629618948":[],"03057995":[],"030645975175292262":[],"03076019":[],"03077640549":4,"03099776":5,"031":[5,31,32],"03115122":[],"0311613":[],"03119062":[],"03158013":[],"0316146":[],"03166546":35,"0317606":[],"03177331":23,"03196357":[6,31],"03201179e":[],"03201217":[],"03201832":34,"03205795":[],"03206757":[],"03207075e":36,"03212854":21,"032142":[],"03214247":[],"03214829":[],"0321956":11,"032196":11,"03239393":[],"03244944":[],"03247316":[],"03251863":5,"03254179":21,"03256632e":1,"03261373":[],"03267527":[6,31],"03274273":[],"03279636":[6,31],"03285784":[],"0328643":34,"0330308045183194":[6,31],"0330308045187757":[6,31],"03306538":34,"03308408":5,"03309191e":30,"03311432":[],"03313259e":30,"03317599":[],"03318519":35,"0332335":26,"033233504714921":26,"03358833":[],"03361037":[],"03365012":[],"033657685071527665":[6,32],"0337609":[],"03382942":29,"03396658":[],"034":[],"03400724e":30,"03404758":[],"034048":[],"03409194":[],"0342028":[],"0342458":34,"03447512":[6,31],"034476":11,"03447649":11,"034557":30,"03455885":[],"03476611e":30,"03479236":[],"03484266":21,"03511387":[],"03529083":21,"03529801":[],"03538463":[],"03538673e":30,"03558034":[],"03559176":35,"03562355":[6,31],"03568439":[6,31],"03573214":[],"03578526":[],"0359565":5,"03596557":[],"03624411":[],"0362483569261072":[],"03630548":[6,31],"03642173":[],"03648711":[],"036527092051294":[],"03662823":34,"03664879":[],"03680811":35,"03681479262838276":[],"0369544130635358":[],"03701105":[],"03703391":[],"03707133":11,"03778607":21,"037813671417389005":[6,32],"03781367141738902":[6,32],"03796359":[],"03796582":[],"03798785":[],"03814292":[6,31],"03815288":[6,31],"0382721":21,"038300":[11,30],"03837":34,"03844073":[],"03846169":31,"03853213":[],"03853268":[],"03853313":[],"03868372":[],"03872795610436844":[],"03873507":[],"03887801":[],"039039":5,"03916813":[],"0394226":[],"03948301":[],"03960002":[],"03973359":[],"039764":35,"03976851":34,"03979291":[],"0398603":35,"039967668952797":[6,31],"0399676689527975":[6,31],"04":[1,6,11,30,31],"04000457":21,"040102":5,"04010697":[6,31],"04018043":35,"04018985":[],"04033524":21,"04038595":[],"04046513":[],"04061345":[],"04063602":[6,31],"040684":[],"04072235":[],"04073097":[],"0408223":[],"0409646":[],"04097813":21,"041":[6,9],"04101344":[],"04108038":34,"04110474":[],"0411487294305088":[6,31],"0411487294305226":[6,31],"04150522":21,"04158557":[],"04161572":[],"0417409":36,"04191323":[],"04193203":30,"042060":[],"04206048":[],"042136":[],"04216532":[],"0422":[],"04220758":[6,31],"04224929":[],"04238763":[],"04262217":[],"04293545":[],"04295726":35,"04295757":32,"043":9,"043072":[],"04307275":26,"04315108":5,"04315855":[],"04323936e":[],"04330558":[],"04330907":[],"04346721":5,"04353549":[],"04355062":[],"04355837":[6,31],"04362":9,"043637":[],"04369752":[],"0437499":2,"043839":[],"04389027":[6,31],"044014":[],"04401421":[],"04413243":[],"04421197":35,"04423486":[6,31],"04426744e":30,"044334":30,"04443985":21,"044613":[6,31],"04487298":[],"0449":[],"04495752":[],"04501146":21,"04504728e":30,"045161":[],"045258":[],"04532405":[],"04537385":[6,31],"04543942":[6,31],"045630":[],"04564589":[],"04566964":[6,31],"0458":9,"04588592":[],"04592382":36,"045963":[],"0462999":[],"04640695":35,"04641529":[],"04646338":[],"04648335":5,"04652794":[],"04657426":[],"04664255":6,"046663":[],"046678":[],"046764":[],"04683565":5,"04688012":[],"04719868":[],"047299":[],"0473916":[],"047447724189861":[],"0474753":34,"047489":[],"04757138":23,"047760":[],"04776242":35,"04784395":[6,31],"04794409":[],"048020":[],"04808723":[],"0481872773043029":[6,32],"048194":21,"04832356":[],"04838148":[],"04852743":[],"04877931":[],"048781":[],"0488139":21,"04892055":[6,31],"04899367":[],"049060":[],"04909093":[6,31],"04912436":6,"049196":[],"04922273":[],"04926746":32,"049276":[],"04933083":[],"049380":[],"04939861":[],"049479":[],"049481":[],"049556996627824":[6,31],"0495569966278269":[6,31],"04955942":[],"04963309":[],"049677":[],"04984743":[],"05":[1,4,6,24,30,31,34,35,36],"050015":[],"05002471":[],"05005634426334421":[],"05006037":[],"05009826":[6,31],"05013368":35,"05029018":[],"05029453":[],"050315327923114654":29,"05034088e":30,"05040878":[],"05045":[],"05054319":30,"05060379":[],"05068486":[],"050796":[],"05087018":[],"05098714":[],"05100875":[6,31],"051021":[],"051042":[],"05135047":34,"051368":[],"05141614":[],"051418":5,"05144177":[],"051554":[],"05159088":[],"051598":35,"051645":[],"051649":[11,30],"0517473":5,"05176711":[],"051787":[],"052010":11,"05201041":11,"05224117":[],"0522653":21,"052279218012056844":[6,32],"05227921801205686":[6,32],"052305":30,"05233008":[],"052370":[],"05240397":[],"052427":[],"0524497":30,"0525733":[],"05263":9,"052692":[],"052738":[],"052856":[],"05293756":21,"05296475":23,"05302":9,"053036":[],"05336637":[],"053387":[],"053417":30,"053462":[],"05347795":[],"053599":[],"05364854":8,"053787":[],"05383795":[6,31],"05383947":[],"053849":5,"053854":[],"05395761":[],"05401912":[],"05415968":35,"054197":[],"054286":[],"054434":[],"05447415":[6,31],"054609":[],"054617":30,"054655":30,"05484773":[],"054932":[],"055000":[],"05505310046363":2,"055091049054481":[],"05509105":[],"05519999":31,"05533":9,"055477":[],"05549529":[],"05563358":[],"055653":[],"055676":30,"055734":30,"055737":[],"05574159":35,"05577845931438246":[],"055876":[],"055910":30,"055987":30,"056026":[],"056041":[],"0560663":[],"05614483":5,"0562":32,"05623":9,"056287":[],"056328":[],"05641352":[],"056414":[],"05648":9,"05651951":[6,31],"05665429e":30,"05667":9,"05668052":21,"056683":30,"056717":[],"056826":[],"056856":[],"05716368155342608":[6,32],"057216":[],"057287":[],"057300":30,"057316":[],"05737289":[],"057387":[],"057393":30,"057418":30,"057420":[],"057457":30,"05747369":[],"057514":[],"057607":[],"057609":[],"05767":36,"057722":30,"057835":30,"05785343":[6,31],"05788748":[],"05789007":[6,31],"057913350391706":[],"057929":[],"05792927":[],"057951":[],"057961":[],"05796251":[6,31],"057964":[],"05804539":[],"05804744e":34,"05807125":[6,31],"058133":[],"058152":[],"058234":[],"058245":[],"058254":[],"05831017":[],"058361":[],"058422":[],"058427":[],"05850899":35,"058552":30,"058582":[],"058593":[],"058641":[],"058645":30,"0586484":34,"05867956":[],"058721":[],"058770":[],"05883":9,"05884":9,"058854":30,"05888195":[],"058952":30,"058967":[],"058970":[],"058996":30,"058997":[],"059031":30,"05914563":[],"059181":21,"059201":[],"059243":[],"059340":[],"05941988e":35,"059624":[],"059669":[],"059761":11,"05978512":[],"059807":30,"059876":[],"059951":30,"059956":11,"05996":34,"059977":[],"05999":9,"059992":[],"059993":30,"06":[6,30,31,34,35,36],"060071":[],"060083":30,"060085":[],"060087":[],"060171":[],"06020264":[],"06020587":[6,31],"06021793":35,"060251":[],"060254":30,"060275":11,"060288":[],"060312":[],"06043581":[6,31],"060453":[],"060470":[],"060471":[],"060475":[],"0604888":[],"060490":[],"060547":[],"060629":[],"060631":[],"060652":[],"0606958":[],"060716":30,"06072":34,"060726":11,"060734":[],"060735":[],"060756":30,"060870":[],"060872":30,"060898":[],"060994":[],"061025":[],"06110658":[],"061154":[],"061163":30,"061284":[],"061319":11,"061359":30,"061386":[],"061443":30,"061452":30,"06146873":21,"06155151":[],"061588":[],"061614":30,"061637":[],"061656":[],"061706":[],"061724":[],"061848":[],"061862":[],"061898":11,"061921":[],"06199119":[],"06200174":5,"062016":30,"062053":[],"062058":[],"06208238634231949":[6,32],"06210358":[],"062161":[],"06216141":[],"062173":[],"062199":[],"062216":5,"062231":[],"062260":[],"062263":[],"062282":[],"062292565":4,"062300":[],"062337":30,"062356":[],"062429":[],"062520":11,"062599":30,"06260611":[],"062616":[],"062624":30,"06263176":[],"062637":[],"062691":[],"062700":[],"06277313":[],"062797":[],"062853":[],"062874":30,"06287939":[],"062932":[],"063017":[],"063019":30,"063048":[],"063061":30,"063064":[],"063080":30,"063130":11,"063133":[],"063161":11,"063163":[],"063197":11,"063206":11,"06320757":35,"063260":30,"063294":11,"063332":11,"063354":[],"063395":11,"063518":[],"063525":[],"063526":[],"063536":5,"063545":[],"063549":[],"063560":[],"063637":[],"063653":30,"063673":[],"0637712":[],"063781":[],"063786":5,"063791":[],"063802":[],"0638484":34,"063862":[],"063894":30,"06392846":[],"063933":11,"063954":[],"06395476":[],"063959":[],"063977":[],"063995":[],"064000":[],"064074":30,"064077":[],"06410638":[],"064107":[],"06416459":[],"064166":[],"06418809":34,"064189":11,"064202":[],"064218":[],"064294":[],"06430789":[],"06432267":[],"064382":[],"064427":[],"064428":[],"06444":9,"06444224":[],"064501":30,"064505":[],"064507":[],"06453579006728324":[6,32],"064547":[],"064573":[],"064604":[],"064606":[5,30],"064609":30,"064615":[],"064668":[],"064690":[],"064695":[],"064699":30,"064728":11,"064739":[],"064793":30,"064820":[],"064834":[],"064873":[],"064878":[],"06491736":[6,31],"064978":[],"065001":[],"065007":[],"065028":[],"06505375":35,"065062":[],"065077":30,"065096":11,"065108":[],"065121":5,"065149":[],"065212":[],"065217":11,"065352":[],"065358":[],"06536971":[],"065378":30,"065390":30,"065410":30,"06547790180152355":[6,32],"06547790180152359":[6,32],"065482":[],"065556":[],"065616":[],"065619":5,"065654":5,"065679":[],"065788":[],"065818":[],"065821":5,"065830":[],"06590458":[],"065949":[],"065963":[],"06603447":[],"066054":11,"066059":5,"066066":30,"066127":5,"066145":5,"066153":[],"066199":5,"066205":5,"06622369":[],"066256":[],"066286":11,"066358":5,"0663596":[],"06637":9,"066425":5,"066458":[],"066474":30,"066500":30,"06659997":[],"066612":30,"06662069e":[],"06662675":[],"066633":[],"066647":30,"066653":[],"0666807":2,"066686":11,"06674611e":[],"066763":[],"066766":5,"06677444e":[],"066778":5,"066787":30,"066824":[],"066837":[11,30],"066838":[],"06684886":[],"06685171":[],"066854":30,"066855":[],"066865":[],"06690071":[],"066912":5,"066948":5,"066988":11,"066997":[],"066999":30,"067000":5,"067003":[],"067074":[],"067141":[],"067164":[],"067168":[],"06724062":5,"067270675787016":[34,35],"067367":[],"067374":11,"067380":[],"067400":11,"067431":11,"067511":11,"067515":5,"067539":5,"067637":30,"067671":[],"067707":30,"067764":[],"06777772":[],"067793":[],"067809":[],"067843":11,"067922":11,"067948":[],"067967":[],"067974":11,"06804775":[],"06808421":23,"068116":[],"068206":[],"068215":11,"068264":30,"068268":[],"06828347":35,"068307":30,"068353":5,"068360":[],"068369":[],"068394":11,"068408":[],"068441":30,"06844519414009445":[6,32],"06844519414009446":[6,32],"068446":[],"06849372":[],"068494":[],"068504":[],"068512":5,"068533":[],"068539":11,"068587":11,"068592":[],"068607":[],"068629":30,"068680":[],"068684":[],"068727":30,"068758":[],"068775":11,"068827":11,"068843":11,"068897":[],"068903":[],"068906":30,"068912":[],"068924":11,"068967":[],"068977":11,"068985":11,"06901081":[],"069028":30,"069045":11,"069129":11,"069179":[],"069203":5,"06926192":29,"069270":11,"069293":5,"069317":[],"069320":11,"069322":[],"069399":[],"06942115e":[],"0694226":[],"069427":[],"069439":[],"069452":30,"069484":[],"069486":[],"069584":30,"06970419":[],"069802":[],"069811":11,"06984502":[],"069866":5,"069873":[],"069885":[],"069907":5,"0699274":26,"069978":[],"069979":[],"07":[6,30,31,34,36],"070024":11,"070027":11,"070043":30,"07006502":[],"070095":[],"070098":11,"070135":5,"070146":30,"070150":[],"07016":9,"07017":9,"070183":11,"070213":30,"070274":11,"070275":11,"07027791":35,"07039":9,"070432":[],"070441":[],"070457":30,"070462":[],"070514":[],"070531":5,"070547":11,"070552":5,"070556":[],"070558":[],"070582":30,"070600":[],"070605":5,"070622":5,"07062318":[6,31],"070630":[],"070655":5,"070696":11,"070712":5,"070737":30,"070772":11,"070780":5,"070805":5,"07084394":[],"070855":5,"070859":[],"070886":[],"070889":[11,30],"070891":[],"070898":[],"070916":11,"070918":11,"070950":[],"070980":[],"070986":30,"071049":5,"071055":11,"07106891":[],"071103":[],"07115":9,"071173":5,"071186":11,"071191":11,"071208":[],"07123177":[],"071252":[],"071279":[],"071291":[],"071294":5,"0713":[0,29],"071314":[],"071356":[],"071379":11,"071433":[],"071436":5,"071437":5,"071449":[],"07145103":11,"07147935":[],"071530":[],"071560":5,"071572":[],"071578":[],"071580":11,"07160048164233102":[6,32],"07160048164233104":[6,32],"071608":[],"071638":5,"071643":11,"071655":[],"071656":11,"071680":5,"07173249":36,"071758":[],"071803":[],"071831":[],"0718316":34,"071868":[],"071921":[],"071935":[],"071937":[],"072000":30,"072015":5,"072031":5,"072037":5,"072092":[],"072111":30,"072132":[11,30],"072147":[],"07218473624441492":23,"072200":11,"072209":[],"072286":[],"072290639572326":26,"07229064":26,"072304":[],"072344":[],"072380":5,"07241855":[],"072476":30,"072500":[],"0725872":[],"072590":[],"072591":5,"072621":30,"072638":[],"072684":[],"072689":[],"072697":[],"072728":[],"072752":[],"072817":[],"072824":11,"072826":5,"072843":[],"072849":5,"07285":3,"072863":[],"072947":11,"072961":5,"072997":5,"073048":[],"073102":[],"073109":[],"073253":[],"073258":11,"073262":11,"073288":[],"07332248":[],"073339":[],"073405":[],"073408":[],"073415":[],"073422":[],"073499":[],"073514":5,"073528":11,"073576975500551":26,"073598":[11,30],"073612":5,"073644":30,"073647":11,"073672":[],"073685":[],"07373479":[],"07376699":35,"07378525":[],"073791":[],"073800":5,"073858":[],"073866":[],"073882":11,"073911":5,"073923":[],"07405556":[],"074067":[11,30],"074084":30,"074112":[],"074114":[],"074115":11,"074130":[],"074210":30,"07421084":5,"074221":[],"07429886e":[],"074323":30,"074368":[],"074374":5,"074417":[],"074454":5,"0744881":[],"074531":[],"074561":11,"07456491":5,"07469645":[],"074807":[],"074824":[],"074859":[],"074892":[],"07490892":[6,31],"074971":[],"07517385":35,"075176":[],"075177":[],"075198":[],"075239":5,"075289":5,"075298":[],"075302":11,"07531349":[],"075356":[],"075385":[],"075392":[],"075463":[],"075513":11,"075522":[],"07555537":[],"075557":[],"075602":[],"075615":[],"075771":[],"075794":[],"075816":30,"075822":[],"075842":5,"075876":5,"075885":26,"075889":30,"075909":[],"0759216":35,"075956":[],"07597049":[],"075978":5,"07600369":[],"076066":5,"076071":5,"076091":[],"076138":[],"076150":30,"076161":[],"076167":[],"076232":5,"076244":[],"076259":[],"076321":5,"076333":[],"076351":[],"076389":[],"076393":[],"076396":[],"076418":[],"07641937":32,"076434":11,"076435":[],"076436":[],"076448":5,"076459":[],"076479":11,"0764924":[6,31],"076508":11,"076542":[],"076618":[],"076638":[],"076648":11,"076679":11,"07668538":[],"076693":[],"076776262573027":[],"07678":9,"076833":[],"076857":[],"076859":[],"0768805855280187":[],"07692307692307693":9,"076934":[],"076938":[11,30],"076947":11,"076968":[],"077035":5,"07712197e":[],"077141":[],"077168":30,"077226":[],"077248":[],"077280":5,"077301":[],"077304":[],"077329":[],"077341":[],"077382":[],"077391":5,"07740964":26,"077411":[],"07745579":23,"077460":30,"077485":11,"077486":[],"077516":[],"077529":[],"077539":[],"077553":[],"077567":[],"077601":11,"077613":[],"077653":[],"0776532":[],"077683":[],"077736":[],"077745":11,"07776381":11,"077764":11,"07777777777777778":1,"077813":11,"077839":11,"077906":[],"077941":[],"077965":[],"078035":[],"078044":11,"078071":[],"07808426989543932":[],"078110":30,"078118":[],"078123":11,"078146":11,"07820":9,"078210":[],"078238":[],"078268":11,"078282":[],"078284":[],"078313":[],"078324":[],"078336":30,"078359":5,"078363":[],"078386":[],"078447":[],"078540":30,"078541":11,"078544":[],"078557":[],"078573":11,"078588":[],"078636":[],"07864":9,"078684":[],"078688":11,"07871":9,"078731":[],"07890044":[],"078945":5,"078974":30,"078981":[],"078986":30,"079002":5,"079027":[],"079030":5,"079074":[],"079089":[],"079107":11,"07911268":[],"079174":11,"07919041":[],"079202":11,"079240":5,"079334":[],"079347":[],"079391":[],"079420":[],"07944154":[23,29],"079444":[],"07950356694388497":[],"079510":[],"079670":5,"0796891867672603":[6,32],"07969087":35,"079739":[],"079747":11,"07974741":[],"07978850553011713":[],"079887":[],"079903":[],"079946":30,"079947":[],"079953":[],"079959":[],"079976":5,"079977":[],"07998756":[],"079989":[],"079998":[],"08":[9,26,30,34,35,36],"080082":[],"080094":5,"080171":[],"080205":[],"080222":[],"08023512":34,"080316":[],"08032505":[],"080345":11,"08043851":5,"080453":[],"080549":5,"080555":[],"080616":30,"080630":[],"080657":[],"080702":[],"080706":5,"080747":[],"080764":30,"080832":[],"080903":[],"080947":[],"080987":[],"081038":[],"081103":[],"081195":[],"081217":5,"081221":[],"081235":[],"081252":[],"081276":30,"08131003":6,"0813156":[],"081431":[],"081457":[],"081494":[],"081527":5,"08153923":[],"081544":[],"08156108":[6,31],"08165104":30,"081655":30,"081686":5,"081728":[],"08179906":[],"081835":[],"081871":[],"081955":[],"081978":[],"0820185":35,"082115":[],"082126":[],"082170":[],"082173":[],"082174":[],"08227057":[],"08227668":[],"082303":[],"08233627":[],"082464":[],"082482":[],"08251519":[6,31],"082518":[],"082519":[],"082533":5,"082653":30,"08266769":29,"082742":5,"082764":[],"082784":11,"082785":[],"08280012":[],"082803":[],"082857":[],"082971":[],"08299273e":[6,31],"083016":11,"083119":[],"0831367":[],"083179":5,"083182":[],"08318298e":1,"083248":[],"083259":[],"083260":11,"083268":5,"083288":[],"08333333333333333":9,"083342":11,"08336233266":4,"083446":[],"083465":[],"083471":[],"083479":[],"083499":[],"083501":[],"083527":30,"083547":11,"083548":5,"083564":[],"083734":[],"083765":[],"08376632":[6,30,31],"083766322923899":[6,30,31],"0837663229239043":[6,30,31],"083793":[],"083864":[],"083900":[],"08398399377155011":9,"084018":[],"084042":[],"084076":30,"084091":[],"084122":[],"08418956":[],"084218":11,"08421808":11,"084255":[],"08426840630693411":[6,32],"08426840630693413":[6,32],"084312":11,"084319":[],"084358":[],"084376":[],"084406":[],"084434":[],"084514":[],"08455":9,"08458591":29,"084619":[],"084637":[],"084695":[],"084702":[],"084712":[],"08474":9,"084809":30,"084910":[],"084915":[],"084963":5,"084967":[],"084996":[],"085079":[],"085120":[],"085139":[],"085145":5,"085222":[],"085294":[],"085353":[],"08536248571780691":5,"085390":[],"08539155":34,"085392":[],"08539583":[],"085436":[],"085455":[],"08551306":[6,31],"085518":[],"085548":[],"085592":[],"08576932":6,"085853":5,"08587209":35,"085918":[],"08593216":[6,31],"085973":[],"085996":[],"086026":[],"086068":5,"08609047":35,"086095":[],"086096":[],"08611111111111111":1,"086125":[],"086212":[],"08622478":[],"086230":[],"086239":5,"08624193":[],"086250":[],"086286":[],"086318":[],"086346":[],"086364":[],"086428":[],"086483":5,"08660891":[],"08667591":[],"086694":[],"086712":[],"086730":[],"086799":[],"086808":[],"086809":[],"08687303":34,"08690":9,"08690184845323":11,"086913":[],"086970":[],"08699295e":[],"08702578":[],"087210":[],"087424":[],"087429":5,"08747795":[],"0875061":[],"08758":9,"08758013":[],"087864":[],"087871":5,"08793554992813543":[],"087988":[],"088023":[],"088029":[],"088030":[],"088038":[],"088102":[],"088127":[],"0881981":5,"088199":[],"08824304e":[],"08826182458028335":[],"08826256":[],"088375":[],"08839544":[],"088574":[],"08860502":35,"088651":[],"08871404":5,"08881497884574564":30,"08888888888888889":1,"088970":[],"08902":9,"08931169286872433":[],"08935132374099551":[],"089376":[],"0894015":[],"089404":[],"08946029":[],"0895043":[],"0895387":30,"089539":30,"089548":[],"089578":[],"089600":[],"089619":[],"089626":5,"089718":[],"08996":9,"089996":5,"09":[1,30],"090033":[],"090038":[],"09007789":[],"09024373":[],"09028702":[],"090439":[],"090440":[],"090468":[],"09048717285916912":23,"090624":[],"09070064":23,"09078672":[],"0907958":[],"090985":[],"091015":[],"091068":[],"091159":[],"09135059e":[],"091362":5,"091365":[],"091388":[],"09156055":[],"09163947":6,"09166666666666666":1,"0917":9,"09171886":[],"091731":[],"092252":[],"092347":[],"092401":[],"09246293455466892":29,"092486":[],"09251":9,"092607":[],"092608577084595":[],"09291556244521161":[],"09291806":[],"092956":5,"092982":[],"09300398":35,"0930438":[],"093094":[],"09346106":[],"093554":[],"09360113":[],"09368":34,"0938492":[],"09397626":[],"09398153":[],"094044":[],"0940821989627646e":[6,31],"0940821989652176e":[6,31],"094099":[],"094254":[],"094362":[],"094439":[],"09444444444444444":[],"09469095":[],"09487358":23,"09515455":[],"09529067":[],"095465":[],"09572047":35,"095805":[],"09590269e":30,"09604976":[],"09609807":5,"09610694":26,"096270":[],"096365":[],"096511363983559":[],"09651792":[],"0973900819831327":26,"09740532e":[],"0974119":23,"09744":9,"09755017":[],"09780":9,"09790216282081063":[],"09791":9,"09808622":[],"09829902":26,"0983565":[],"098414":[],"09846933":[],"09861229":[23,29],"09903804":8,"09913654":[],"09919198949275869":[6,32],"09928714":23,"09951287404314545":1,"0n":[0,29],"0x0006":[3,4,14],"0x1174af160":[],"0x11753f700":35,"0x117715eb0":[],"0x117893340":[],"0x117c17be0":[],"0x11975e550":[],"0x11b160a60":[],"0x11bc3a1f0":35,"0x11f13fb20":34,"0x120cc1b20":[],"0x121cf68e0":[],"0x124b30190":21,"0x124b96d60":21,"0x1273ffac0":[],"0x1279bd460":[],"0x12e13a850":34,"1":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,21,23,25,26,27,28,31,32,33,34,35],"10":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,21,23,24,25,26,27,29,30,31,32,33,34,35,36],"100":[0,1,2,3,4,5,6,8,9,10,11,13,14,15,16,17,21,23,26,27,29,30,31,32,33,34,35,36],"1000":[0,1,2,4,5,8,11,13,14,21,22,26,29,30,33,34,35],"10000":[2,5,6,10,11,13,26,31,32],"100000":8,"10001":10,"100083":[],"10008326":[],"1000911":[],"1001":[9,26],"1002":26,"10029389":34,"1003":26,"10030":9,"10036694":[],"10041812":31,"1004727":35,"1005":26,"10068448":[],"1007":32,"1007711427354898":[6,32],"1009":26,"10107914":26,"1011":26,"101150":5,"10115017":5,"10116149":[],"101263":[],"1013":26,"1013904243":26,"10141413e":[6,31],"1015":26,"1015491":34,"10158754":[],"1015am":29,"1023":26,"10230":9,"1024":3,"10242458":[],"1026":26,"10261093":[],"1027":26,"10276112":[],"103":1,"1030":26,"1033455":[],"10340":9,"10340733":35,"1037":26,"10378326e":1,"1038":26,"10391807":[6,31],"10398646080125032":[6,32],"10398646080125035":[6,32],"1040":26,"10405456":11,"10426556":35,"10430":9,"104411":30,"1047":26,"10499357":34,"105":31,"10520":9,"10539984":[],"105400":[],"10541723644166373":[],"10555555555555556":1,"10572":32,"10587277":[],"10589577":5,"10595991":[],"10598715e":36,"10604579e":30,"106095":[11,30],"1064601390492845":26,"10646014":26,"10719554":[],"10719859":[],"10747579":5,"107476":5,"1074792":[],"10754764":[],"1079":32,"10790125813226321":30,"108":[6,9],"1080176":[],"10837392":23,"10854118":35,"10888197":[],"10898643":[],"10908858":[],"10913":6,"10931453":[6,31],"10960":9,"10994958":[],"10995472e":36,"10th":9,"10x":[0,29],"11":[0,1,2,5,6,7,8,9,10,11,12,13,15,16,21,23,24,25,26,27,28,29,30,31,32,33,34,35],"1100":26,"1101":26,"11022302e":[5,35,36],"11042239":[],"11081083":[],"1108407":[],"111":[1,7,12,33,35,36],"11100":9,"11113486":11,"111135":11,"11131389":21,"11163239":[],"11171148":35,"1118933":23,"11202337":32,"11204514":36,"112383":[11,30],"1124":9,"112619":[],"11261935":[],"11265643e":30,"11277166":5,"112772":5,"11382896":31,"11388888888888889":[],"11390":9,"11433693":[],"114384":11,"11438414":11,"11439407":[],"114550":32,"11462415":5,"11482289e":[6,31],"1148541":[],"11507992e":1,"115356":[],"11535632":[],"11547777218872497":[6,32],"11548661":[],"11571507":[],"115822":6,"1158848":[],"11590":9,"11596834":[],"11597515":[],"11620886":21,"11660":9,"11666666666666667":1,"11683558":[],"1169242":[],"11694":24,"117":8,"11715109e":30,"11725761":35,"11744554e":[6,31],"11747908":23,"11780":9,"118":[0,2,7,33],"11822173":[],"11830757":31,"118318":30,"1184":32,"11840":9,"11844773":[],"11868033":[],"11890":9,"11891833e":21,"119":[0,2,7,33],"11922031":[],"11930916":29,"11992194":11,"119922":11,"119936":2,"12":[0,1,2,3,4,5,6,7,8,9,11,12,21,23,26,28,29,30,32,33,34,35],"120":[0,2,3,7,33],"1203":9,"1203284":8,"120435":5,"12043521":5,"12044974":30,"120450":30,"12068251":35,"12081773":34,"121":[8,9,10],"12123488":35,"121292":[],"12155483":[],"1215pm":[27,29],"12166797":[],"12182967":[6,31],"122":[2,8,9,10],"12206013":[],"12220276":[],"12222222222222222":1,"12235593":[],"123":2,"12318726e":[6,31],"12329646":[],"12330033":30,"12333649":[6,31],"12363332":23,"123711":6,"12380":9,"12382443":[],"124":[0,29],"12400":9,"1242":8,"124228866018077":[],"124325":[],"12466453":34,"12498355":[],"1251681":36,"12536737":34,"12544009":[],"12552073e":[6,31],"12591227":30,"126":9,"12600095":[],"1261":9,"12618549":5,"1265":9,"12667402":35,"127":4,"1271":6,"12733892":[],"12777777777777777":[],"12790":9,"128":[3,4,13,34,35],"12829994e":30,"12846660e":30,"12871842":30,"129012":6,"12922837":[],"12952339":31,"12957454":26,"1297":9,"1298":9,"129963":32,"12it":[],"12pm":[27,29],"13":[0,1,2,5,6,7,9,11,12,18,21,23,26,29,30,32,33,34,35],"130":9,"13003291":[6,31],"13024288":[],"13035147135400782":11,"13037395":35,"13040489":26,"13055555555555556":[],"13055762":[],"130694":30,"13069442":30,"131":9,"13107995":[],"13134148011170077":[],"13137881":[],"131379":[],"13152828":[],"13164176":29,"132":9,"13220608e":[6,31],"1325":6,"1326":9,"13260573":[],"1326197715":29,"13280":9,"133":[7,33],"1332":32,"13337992":[],"134":31,"13457622":[],"135":9,"1350":32,"13535942":[6,31],"13564988":29,"136":[0,7,33],"13600596":[],"13607502":[],"13646574":5,"13659941":[],"13661243e":[6,31],"13663125":29,"13675593":[],"136756":[],"13679863":[6,31],"13684661":35,"13699574":[],"136996":[],"137":[0,7,33],"13729154":29,"13738633":[],"13740":9,"137652":[11,30],"138":[0,7,33],"13819592e":30,"13820":34,"13825388":[],"13847167":[],"1385":6,"1385510301651882":[],"13865173":5,"138775":[11,30],"13878649":[],"1388888888888889":[],"13890":9,"13896095":29,"139":[0,7,33],"13911934":26,"13913033":[],"139224":[],"1392559585020426e":[6,31],"139255958997547e":[6,31],"1393548":[],"13956654":[],"13it":[],"14":[0,2,4,5,6,7,8,9,10,11,12,21,23,26,28,30,32,33,34,35],"140":[0,2,7,9,33],"14021063":[6,31],"14046224e":[],"14084366":35,"141":[0,2,7,33],"14100":9,"14104212":26,"1412":[21,34,35],"14122256":[],"1416398":[6,31],"14174745":[6,31],"1418":9,"14187173":[],"142":[0,7,9,33],"14213876":[],"1424112":21,"14250":9,"14260706":[],"14277718e":30,"143":[0,2,7,9,33],"14309433":[],"14369927":[],"1437":1,"14373934e":36,"144":[0,7,33],"14400":9,"1440501043841336":1,"1441031":[],"14437776":[],"14440":9,"14452678":[],"1446729567":4,"145":2,"14523337e":[],"14550854":11,"145509":11,"14568914":31,"14599499":[],"146":2,"14605929":[],"14629156":32,"14638":34,"14643345e":[],"14708":[],"14710":9,"14716":6,"14721582":35,"14722222222222223":1,"147400":[11,30],"147420":[11,30],"147545":6,"1477190177681485":[],"147836":[],"14783612":35,"1479":9,"148":[3,4,14],"14812206":6,"14815202":[],"14824254":[],"14825560e":30,"14828178":23,"14829228":[],"14841322":29,"14880915":34,"1488598":[],"149063":[],"149266":6,"14934258650797513":[],"149353":32,"149388":[],"149433":[],"149466":[],"149483":[],"149904":[],"149921":[],"14g":[6,32],"14it":[],"15":[0,1,2,4,6,7,8,9,12,13,15,16,17,21,26,29,32,33,34,35,36],"150":[3,4,8,9,14],"15005476":5,"1502":36,"150527":[],"15079545":[],"15098090e":[6,31],"151":[3,4,14],"15126318":[],"15130074e":[6,31],"151522":[],"15173932":[],"152":9,"15200":9,"15202654":[],"15215415":35,"152494":6,"1527777777777778":[],"15283463":[],"153":[3,4,14],"153036":30,"15313054":32,"15351626":[],"15361856":[],"15384615384615385":9,"154":[3,4,14],"1547556":[],"15489318":[],"155":[3,4,9,14],"15527976":[],"15546887":[],"15593478":[],"156":[3,4,14],"15605625":[],"15670921":34,"1567286":34,"156956":5,"157":[3,4,14],"15709522":[],"157128":[],"1571284":[],"1575":9,"1575046":[],"15751952":[],"158":9,"15830902":34,"15833751":[],"15847501":21,"1587":9,"1590":9,"15924557e":30,"15951871":34,"15970814":35,"1598058":[],"15990":9,"15991124e":[],"15am":29,"15g":[6,32],"15it":[],"16":[1,2,3,4,5,6,8,9,10,19,21,26,29,30,31,32,34,35,36],"1603":3,"16063661":[],"16111111111111112":1,"16118615":[],"16158074":[],"161581":[],"16172219e":[],"16180248":35,"16188604":[],"16201555":[],"16209264e":[],"16211139":5,"16220":9,"162246":5,"16231451":4,"1625":9,"16257872":35,"1628":9,"16292908":23,"16304863":30,"163049":30,"1630775253":1,"16312434e":[],"16342407":5,"16343471":[6,31],"1636508":[],"16384":3,"16407038":29,"16411163":[],"164112":[],"16413938":21,"16431956":[],"16437294":35,"16445858":[],"16469725":[],"16486151":[],"16500":9,"165272":[],"16532977":[],"16535252":29,"16567361":[],"166":9,"16617445":[],"1664372":[],"166540":[],"16654048":[],"16710567":29,"16744759":[],"16777789":23,"167787":5,"16791183":23,"168":9,"16805821e":[6,31],"16879134":[],"17":[1,2,5,6,7,8,9,13,21,23,26,30,32,33,34,35,36],"17021424":26,"1709":9,"171":31,"171525":30,"1715252":30,"17168028":[],"17174962e":1,"17214545":23,"17222222222222222":[],"17253354":35,"1726":9,"17260271":[],"17272182":26,"173":[21,35],"17300":9,"1731":9,"1732863504708044":[],"17359583e":[],"17367225":[],"17377547":[],"17405911e":[],"17446471":6,"17483760":32,"175":32,"17501258":36,"1752":9,"175300":30,"17547294e":[],"17563274":[],"17567503":[],"17641709":[6,31],"17643975e":30,"17669259":[],"176762":[],"17676247":[],"1767857":29,"17739525":29,"17748881e":34,"17757295":35,"17777777777777778":1,"17801022":5,"17801827":[],"17827738":[],"17834506e":[],"17856374":[],"17861098":6,"17861414":[],"17869861e":30,"179":[],"17913653":[],"17917768":5,"1793417":[],"17934801":[],"17949575":5,"17953942":11,"17968231":[],"1797":[1,3],"18":[2,6,7,8,9,10,13,21,26,32,33,34,35],"180":2,"1801709":31,"18019623e":[],"18029127":5,"18043393":26,"1807":4,"1808228":34,"18085537":[],"1809":9,"18093549":34,"18094575":[],"181":9,"1810415856976313":[],"18118338":[],"1812":9,"18120973":[],"181210":[],"18147009":[],"181766185664273":[],"182086698929565":[],"1821":9,"18234308":[],"18277213":[],"18285689e":[],"18307821":31,"18333333333333332":[],"18383522":30,"18388":6,"184":9,"1840":32,"18409254":[],"18418938":[],"184519":30,"18485685":[],"184866696796263":[],"18497496":11,"184975":11,"185":31,"18501900e":30,"18510775":[],"1860":9,"18611111111111112":[],"18613217e":[6,31],"1863889":35,"18660":9,"18670072e":30,"18673098":11,"18702469":23,"18711407":[],"18742521":[],"18816387":[],"18824338":[],"18840034e":[],"18925625":[],"189496":30,"18956157":[],"189622":30,"19":[2,6,9,15,21,26,29,32,34,35],"19009085621304586":[],"190529":[],"19052935":[],"19069576e":34,"19126179":[],"19166666666666668":1,"191833":35,"192":32,"19207979":5,"19220":9,"19299283":[],"19371605e":36,"1940":0,"194042826649355e":[6,31],"194042826815211e":[6,31],"1943":[12,35,36],"19433318":[],"1944":6,"19547923":[],"19559737e":30,"1956":9,"19569961":[6,30,31],"19583547":[],"19588651":34,"19661197":34,"19677112":[],"1970":[23,29],"1973":9,"197370":[11,30],"19740":9,"1979":[6,32],"19791352":[],"197914":[],"19800":9,"19849513":29,"19852045":[],"1989":36,"1991":36,"1_1":[12,35],"1_2":[12,35],"1_3":[12,35],"1cm":[0,8,10,26,29,36],"1d":[1,2,3],"1e":[1,2,4,13,14,21,34,35],"1e10":14,"1e4":6,"1f":1,"1k":23,"1n":[0,29],"1x":[0,29],"2":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,21,22,23,24,25,26,28,32,33,34,35],"20":[0,1,2,6,7,8,9,13,19,21,26,27,29,31,32,33,34,35,36],"200":[0,2,3,4,8,9,10],"2000":[0,30],"20015436":6,"20020163":36,"2004":[13,33],"20051449":[],"2006":28,"2008":29,"2010":[1,36],"2011":1,"20135691":35,"2014":4,"2015":1,"20158083":5,"201581":5,"2016":[0,29],"2018":[0,6,30,32],"2019":[8,9],"2021":[6,14,30,31,33],"20218457":[],"2022":[29,36],"20228273":[],"2023":24,"2024":[15,16,17,18,19,20,21,29,30,31,32,33],"202698":[],"2026985":[],"2027":9,"20277777777777778":1,"20288581":[],"20336784":[],"20347912":[],"20357736":[],"20367355":23,"20375464":[],"20393534":[],"204049":11,"20404927":11,"20480187":[],"204802":[],"20500":9,"20519189":[],"2060":9,"20601797e":30,"20608548e":30,"20651434":[],"206664":5,"20666447":5,"2069":9,"2072382":35,"20728198":[],"207545":[11,30],"20755569":[],"2077068":[],"20775115":[],"20833333333333334":1,"20834188":[],"20867052175034223":[6,32],"20912557":[],"20916295":30,"20980":9,"21":[0,1,2,5,6,7,9,12,13,21,23,29,30,32,33,34,35,36],"210340":[11,30],"21058097":5,"21070843":29,"21093775":6,"211":[],"21130":9,"2116753732":4,"21169159e":[6,31],"21192602e":[],"212":[],"21277816e":30,"213":[],"213103":[11,30],"2131067":23,"21332621":0,"21333766":29,"21344077":[],"213743":[11,30],"21390371e":[],"21392756":21,"21430643e":34,"21444055":26,"21517262":6,"21531156":[],"21565007e":30,"21596432":6,"2160073466353432":[],"216290":[11,30],"21631786":29,"21655059e":30,"216683":[11,30],"21680864":[],"21699817":[],"21752693":35,"21805426":[],"21813899e":[],"21817966":[],"21998973":[],"22":[0,1,2,5,6,9,12,13,21,23,29,30,32,34,35],"22013655":[],"22044605e":[5,30,35,36],"221":8,"221180":30,"2212296":35,"22128142":[],"2216":9,"221666864828611":[],"22169087":[],"2218":9,"221805":2,"221921":5,"22217237e":30,"22226881":[],"222400":30,"22388052":35,"22467274":32,"225":4,"22528536":[],"2257449":[],"22592946e":[],"226014":[],"22601408":[],"22623421":[],"22667819":[],"22688898":[],"22690428":5,"22755839e":[],"22810365":[],"228104":[],"22842468702219465":[6,32],"2284246870221947":[6,32],"22847924":5,"22849742":[],"22871":34,"22897303":[],"22919456":[],"2293":2,"2294":2,"2296":2,"2297":2,"22977659964799":[],"2297766":[],"22it":6,"23":[1,2,6,9,12,15,20,21,23,29,32,35,36],"23002365e":[6,31],"23007231e":36,"23076923076923078":9,"23093598e":[],"23139242":[],"23164401":[],"23167717":5,"232435":30,"23262877":[],"23303727":23,"23333333333333334":[],"23344210e":30,"2338675":30,"233868":30,"234":6,"23407025":[],"23423987":[],"234496":5,"23449607":5,"23472994":[],"23481471":29,"23499549":35,"2351":6,"23526911":[],"23528337":32,"235969":[],"23596934":[],"23616967":[],"2364":9,"23663482":23,"2373286546935638":[],"23794815":26,"23847441":[],"239":32,"23950884":[],"2397":9,"23971032":30,"23994188e":[],"24":[0,1,6,9,21,23,29,32,34,35],"2401":24,"24032019":[],"24071032":[],"24106503":34,"24140":9,"24159785":30,"2416":9,"24175744e":[6,31],"24185931":35,"2419":9,"24224776e":[],"24225043":[],"24254071":[],"24284399":[],"2430":9,"24344979e":35,"24346138":26,"24369936":[],"24377554":[],"243776":[],"24390":9,"24398826":[],"24433117":[],"24444444444444444":[],"24454968":[],"24485814":34,"24493666":32,"246":2,"24602146":34,"24613581":29,"24640494":34,"24688853":[],"24692014":[],"2475908482537097":[],"24759085":[],"24768421e":34,"24780663":23,"24829908":5,"24856992e":[],"24906604e":[6,31],"24999088":21,"24it":[],"25":[2,3,4,5,6,8,9,11,21,23,24,30,32,34,35,36],"250":[2,4,7,9,33],"25000":0,"25018094":21,"25111821":[],"25185716":31,"251879":30,"252008":5,"25200841":5,"25233253":[],"252333":[],"252436":30,"25337053":[],"25343155":32,"25354173":[],"25386687":35,"253891":[],"25389111":[],"25458506e":[],"2546186":[],"254619":[],"2546817701709956":[],"255":3,"255001":30,"25512598":[],"25555619":[],"256":[2,4],"25617655e":[6,31],"25617658e":[6,31],"25673276":[],"256733":[],"25695398":32,"25705685":[],"2572":9,"25729558":[],"2575":9,"25849623":[],"25879315330607":11,"259153":[11,30],"2597":9,"25970297":[],"25986026":[],"25989189":[],"26":[6,9,16,21,26,32,34,35],"26001134":26,"26048873":[],"26083712":[],"26113912":[],"26124692":6,"26128189":35,"26152075":29,"26254957e":30,"262648":[],"26264849":[],"26281735":34,"26292364":32,"26297455":30,"26301436":5,"26307235":[],"2630723514841553":[],"26321660e":30,"26378176e":[],"26402837":[],"26409315307910025":[6,31],"2640931530791004":[6,31],"26464303e":[],"26479234":[],"2650":9,"265109911":4,"26527089":23,"26536626e":21,"2654":9,"265868":[],"26586817":[],"2662452":[],"26646852":35,"2666905":29,"26680052":[],"266801":[],"26710969":5,"26715191":[],"26775644":[],"26780278":5,"2679757":[],"268":9,"26814548":6,"26817703":[],"26821199":[],"2694078":[],"26995402":30,"27":[0,1,6,20,21,32,35],"27065633":31,"27124938":[],"271260217275557":26,"27126022":26,"27182417":[],"27231287":29,"27336592":36,"27352535e":[],"27425372":35,"27470622":34,"27482829e":30,"2750":9,"2751616":[],"27597777e":[],"27600259":[],"27602210e":[],"27623637":[],"276263":[11,30],"27633474":[],"27693602e":[35,36],"27698328":35,"27700":9,"27760":9,"2781456":[],"27861634e":[],"27924636":5,"27933134":23,"27it":[],"27n_":26,"28":[1,3,4,6,9,21,32,34,35],"28000355":[],"280004":[],"28021598":29,"280464e":[],"280573":5,"280647":[11,30],"28109198":[],"2813829":[],"28164443e":[],"28183460e":[],"28205578e":30,"28225179":21,"2822642":35,"28253033":23,"282727":[11,30],"28276275":[],"28306304e":[],"2830637392":4,"28316949":[],"28336218e":[6,31],"28364423":21,"28390":9,"28391978":30,"28399125":[],"28415767":[],"28443039":32,"28457291":[],"28475098":8,"28496213":29,"28542801":[],"2861":26,"28709718":[],"2871":9,"2873":9,"2876045":[],"28776411":[],"28793787":[],"2882":26,"2885519":[],"2886":26,"2890":[0,29],"28902948":[],"2892":26,"28923":[],"28956161":[],"2895786617507":11,"28it":[],"29":[2,6,9,21,32,34,35],"29015871":[],"29033075e":[],"29100624e":[],"291056":[],"2915":26,"29162184":[],"29167186":5,"29223521":[],"29238145":[],"29253213e":[],"29306584e":30,"2931":29,"29350":34,"29390668":[],"29398019":[],"29491144e":30,"29541992e":[],"29620357":[],"29627774":35,"29633608":[],"29653038":34,"2965315":21,"2968":29,"297648":5,"29764815":5,"2976637":[],"2980":29,"298037":[],"29803738":[],"29822833":[6,31],"29860173":34,"2986082":[],"29861395":[],"29881308":[],"2990":29,"29902518":34,"299748":30,"2_":[12,35],"2_1":[12,35],"2_2":[12,35],"2_3":[12,35],"2_i":[12,35],"2_m":[6,26,32],"2_t":[13,34,35],"2_x":26,"2b":26,"2c8f433990d1":[34,35],"2cm":8,"2d":[1,3,11,12,22,29,35,36],"2e":[6,32],"2f":[0,7,9,10,11,12,29,30,33,35,36],"2g":2,"2g_i":2,"2k":3,"2m":[6,32],"2n":[0,2,3,29,30],"2nd":[9,35],"2p":[26,36],"2pm":27,"2pt":4,"2x":[0,3,8,13,29,34,35,36],"2x_ix_jy_iy_j":8,"2x_j":8,"2xb":36,"2y_i":10,"2y_j":8,"3":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,21,22,23,24,25,26,27,31,32,33,34,35],"30":[0,1,2,4,6,7,9,10,13,16,21,27,30,32,33,34],"300":[21,35,36],"30000":[0,29],"30000613":[],"30005983":[],"30010":9,"300231":5,"30023144":5,"30117681":[],"30119421":8,"30124108":[],"30134885":[],"30141906":[],"30190897":11,"301909":11,"302":32,"30258509":[23,29],"30269539":23,"30283188":31,"303":6,"30306759":34,"30334592e":[],"30387411e":[],"30400113":[],"30442964":30,"30466214e":[6,31],"30493151":35,"30506075e":[],"30607268":34,"30637636":[],"3072":3,"3076923076923077":9,"30787294":6,"30915293":[],"309153":[],"30916402":35,"30916988":[],"309170":[],"30917499e":[],"30940":9,"3096154":[],"30982436":[],"3099":32,"30it":[],"31":[2,12,23,26,35],"31008026":[],"310579":30,"3105791":30,"310957":[],"31095745":[],"31160886":[],"31162122":[],"312":31,"31227657e":[],"3123314713548606":[6,32],"31248425":34,"31276579e":[6,31],"31286143":[],"313":31,"313155":11,"31315504":11,"31318084":5,"31363366":[],"31367041":35,"31453949":[],"31457796":5,"314869":[],"31486917":[],"315":[6,31],"31541884":35,"3155":[0,5,6,31,32,33],"31555734196707536":[],"31571995":[],"316":31,"31601423":[],"31664443e":34,"31702609":[],"31718909":11,"31727523":[],"317367":11,"31758645":21,"31812561":21,"31849289":29,"31876431e":[],"31896852":8,"31936237":[],"3194467":[],"31it":[],"32":[2,3,4,6,8,12,13,23,26,34,35],"3200":1,"32003025":[],"32007041":35,"320656":[],"32065614":[],"32068736":29,"3207":32,"32084559e":30,"32149601703519115":[6,32],"3214960170351912":[6,32],"3215":9,"323059":5,"32305911":5,"323184775146844":[],"32318478":[],"32393078":[],"324":2,"32419549":[],"3241988":[],"32422234e":[],"3245":2,"32450054":30,"3250":1,"325228546249804":[],"32522855":[],"3260513":[],"32606139":[],"3262":6,"326238":30,"32641434":29,"32651488":[],"32684035":[],"32733949":[],"32799141":35,"3280928":[],"328093":[],"32825214":[],"32906581":[],"32932635":[],"32941912":35,"32it":6,"33":[9,12,23,27,35],"33000573":29,"33006628":34,"33025801":[],"33049619":26,"33062878":[],"330629":[],"33066907e":[5,30],"33096549":23,"33107417":[],"331075":21,"33145794":[],"33149531":[],"33166055e":5,"331939":30,"33212971":[],"33217312":26,"33220123":[],"33235647":[],"33266422":[],"333":[7,33],"33477019":35,"33528448":35,"33532886":29,"33596404":[],"33615742":[],"33675308":[],"33734605":23,"33742926":29,"33826500e":[],"3388112":[],"33978889":34,"33it":[],"34":[9,23],"340071371496255":30,"34026086":[],"3403":9,"340782":[11,30],"34114547":5,"34139775e":36,"34182884":[],"34225662":23,"342680":30,"34271514":[],"34332677":[],"34346829":[],"3436":[0,29],"34367970":6,"3437":[0,29],"34412923":30,"344176915013831":[],"34427423":[],"34483937":[],"34483955":29,"34568909":[],"34569596":5,"34569632":[],"34577375":35,"34598722":23,"34599467e":21,"34599598":[],"346000154268618":23,"34620097":[],"34654596":[],"346546":[],"34661376":[],"346614":[],"34759233":[],"3480527":26,"34871778":[],"34904819":[],"35":[0,6,17,24,27,29,35],"35018806":[],"35098705":[],"35140":9,"3514835":[],"351636":[11,30],"35182854":5,"35196964":[],"35243372":[],"35275513":[],"35320952":[],"35354073":[],"35432563":[],"3544313922":6,"35470445e":[5,30],"35506347e":30,"35520169":[],"35533773":6,"35537114e":[],"35587321":35,"35613536e":30,"356399":30,"356673":[],"35667342":[],"35689303":[],"35714377":[],"35731585":29,"35736":34,"357508":30,"3577615":[],"3581341341":4,"35823372e":35,"35870701":26,"359":[5,31],"35957915":[],"35966688":[],"35980374":29,"35986305":[],"35it":6,"36":[0,5,6,24,26,36],"360":1,"36091273":[],"3613":9,"361541":5,"36154104":5,"361556":30,"36185989":[],"3621311":5,"36235052e":[],"36303682e":30,"3632959111950474e":[6,31],"363295916366933e":[6,31],"36339156":[],"36353321":29,"36401981":[],"36482524":[],"36545697e":[],"3655222":5,"366375489616074":[],"367":[2,9],"36754671":[],"36880327":23,"36895644":32,"369139":[11,30],"36it":6,"37":[9,24,33,34],"37013105":23,"37055062":[],"37057274":21,"370782966":4,"37093787":[],"37135473":[],"37153115":29,"37175575":34,"37239927e":30,"37255873":[],"3727791":29,"37354121":35,"37396662":[6,31],"37415625e":30,"37449168":23,"37454707":23,"374675":[],"37467515":[],"37507799e":[],"37532078":[],"37582891":[],"375829":[],"37600869":29,"37685349":[],"37700967e":30,"377372":30,"37737221":30,"3777801602":6,"378271":[],"37827145":[],"37837864":[],"37900111":[6,31],"37919989":29,"38":[0,9,24,26],"380":9,"38102552":[],"38135733e":[6,31],"3817475779":[6,32],"38198866":29,"38203725":[],"38259084":34,"38298234e":30,"38337498":[],"38381781":[],"38399622":[],"38440469":[],"38445171":35,"38460453":23,"38461538461538464":9,"38461539":34,"38592549":26,"386":9,"38612299e":30,"386161":[],"38616125":[],"38618024":[],"38629436":[23,29],"387":32,"387620":11,"38762019":11,"3882273":[],"38827994":6,"38865681e":[],"38916861e":[6,31],"3892":32,"38934047":29,"38962192e":[6,31],"38992371":[],"39":[0,9,27,29,35,36],"390334838933238":26,"39033484":26,"39039235":23,"3908470004999506":[],"39090680e":[],"3910042":29,"39197698":30,"391977":30,"39214397":30,"392144":30,"39223923":[],"39279291":29,"3939184e":[],"39398622":[],"394":9,"39517073":[],"39525059":[],"39540235":[],"39579407":5,"395980256477532":[],"39598026":[],"39614949":[],"39621036e":[],"39692815":[],"39706038":5,"397700":[11,30],"39789527":[23,29],"3983":6,"39855569":[],"39865452":[],"39922082":[],"39929428":[],"39931051e":30,"39952356":[],"399836":30,"3d":[2,3,4,6,13,24,32,34],"3f":[1,3,9],"3n":23,"3x":[2,8],"3x_0x_1":36,"3x_i":2,"3y":8,"3yk470mj5p931p9dtkk0y6jw0000gn":[1,6,29,32],"4":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,21,23,24,26,29,31,32,33,34,35,36],"40":[1,6,9,24,27,29,32,36],"400":4,"4000":[9,29],"40037367e":[],"40072098":[],"40093324":[],"40140374":[],"401842":[11,30],"40184681":23,"40266454":[],"40354798e":30,"40415979e":[],"40418675":[],"404783":[],"40478305":[],"405":9,"4050":[28,29],"40558184":[],"405890":[11,30],"405964":[],"40596423":[],"40605118":[],"40620066":30,"406201":30,"40632663":[],"4069157":[],"407":9,"408":9,"40800396":35,"40833375":[],"4087":9,"4087793":5,"40927184e":[6,31],"40it":6,"41":[2,9,23],"4107":9,"41146753":29,"4121966338442804":[],"41229845":35,"41310208":[],"41366128e":[],"41408221":[],"41433969":5,"41487642":29,"41511965e":1,"41532521":35,"4155":[2,15],"4162706317":6,"41636775":[],"41664613":26,"4166666666666667":9,"41675053":[],"41744203":[],"41764479":[],"417644792969273":[],"41820116":23,"41842093e":30,"418506":[11,30],"41869784":29,"41882037e":[6,31],"41925189":[],"41987877":[],"4198932":29,"42":[1,4,8,9,10,23],"42083463e":[],"42095725":29,"42124182":[],"4215795":23,"42197297e":[],"42305151":[],"4230769230769231":9,"42310878":26,"423646":[],"42364634":[],"42392359":[],"424274":[],"4242743":[],"42441033":5,"42450":9,"42497724":[],"42553096":[],"42575338":23,"426":[6,9],"42644801":21,"42699034":36,"42774546":[],"42793344e":[],"42873361":29,"429":32,"42945319":[],"43":[0,1,7,9,23,33],"43054282":5,"4310":29,"433":32,"43330971e":[6,31],"43373107":[],"435163":30,"43563433":23,"43579948e":[6,31],"43639284e":30,"436462435":4,"43703545":[],"43727575":[],"43766686":11,"43779698e":[],"438060758":6,"438136":30,"439230":6,"43962226":[],"43976975777097144":[],"43984553e":[],"43it":6,"44":[0,1,23],"44089210e":[5,30],"441":[3,4,14],"442":[3,4,14],"44255455":[],"442600":[11,30],"44286735":[],"443":[3,4,14],"443217":30,"44395301":31,"444":[3,4,9,14],"44418124":34,"44454123":29,"445":[3,4,14],"44536331":29,"44563226":[],"446033":32,"44624525e":30,"44658658e":30,"44767398":21,"4477214":5,"44830934":[],"44838546":[],"44867801":35,"44970586e":1,"44995924":23,"45":[9,27,29],"450":9,"450257":[11,30],"4504":9,"45053025":29,"45193407":[],"45430236":[],"455173":32,"45560415":[],"4557763":11,"455947":30,"456":9,"45620975":[],"457":2,"457311":[],"45731144":[],"45731379":23,"4576811":29,"45781905e":34,"458027":30,"458078":[11,30],"4580854":[],"4591127":23,"45915671e":30,"45960079":5,"45it":6,"46":[2,9,27,29],"460":[9,11],"4601":9,"46065811":23,"46086448":23,"46107913":[],"46134248e":[],"46153846153846156":9,"46170878e":34,"4619526":23,"462":[7,33],"46318204":[],"46342934":[],"4635149":[],"46383925e":[6,31],"46383926e":[6,31],"46387965":[],"46415522":[],"46415888336127775":31,"46544987":[],"46593404":[],"46660941e":[],"46713267":31,"46736215":32,"4676059":30,"467606":30,"46891823":[],"46911594e":[],"46954702e":[],"46963249":[],"46984559":[],"46984697e":[6,31],"47":[2,9,27,29],"47042744":5,"47051432":32,"47052809":[],"470714":30,"47075725":6,"47116868e":[6,31],"47125748":5,"47132891":5,"4725246793626128":[],"4729218":[],"47297587e":[],"47313680":32,"47334547e":[],"4735968":35,"47433659":[],"4745474":[],"47478922e":[],"47610036":6,"4761747":[],"47729832":[],"47757553":[],"47815203":11,"47823856":34,"47892661":[],"47910545":[],"479465113":4,"47989224":[],"47991892":[],"47it":6,"48":[2,9,32],"48004784":29,"48062913":[],"48151166":23,"48170743":[],"481979":6,"48200792":[],"48233952":[],"48257387":[27,29],"48268005e":[],"48306473":[],"48307405":[],"4831139":[],"48326853":[],"48399942":[],"48420061":[],"4843772":29,"48476997":11,"484905":5,"48490503":5,"48494803":31,"48521055":30,"48697869":[],"486979":[],"4870934":[],"48786826e":35,"48826894e":30,"48827791":[],"48843174e":[],"48867802":[],"48900413":[],"48931464":[],"489315":[],"48994188":5,"48it":[],"49":[5,6,9,11,24,30,34,35],"49074536":[],"49123502e":[],"49152":3,"49156266e":[],"49211524":[],"49224801":[],"49285045e":35,"4937346":23,"49381549":[],"49392067e":30,"4940954":[0,29],"49470005":[],"49513019":26,"4951301940723654":26,"49584063e":30,"4959161509357395e":[6,31],"4959161509366685e":[6,31],"49608088":35,"49611541":[],"49897504e":36,"4990":26,"49910481e":[],"4992":26,"49939493":[],"499394932852416":[],"4997":26,"49it":6,"4c4c7f":[9,10],"4d":3,"4f":6,"4pm":[27,29],"4y":8,"4y_i":10,"5":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,21,23,24,26,29,30,31,32,33,34,35,36],"50":[1,2,3,4,6,7,8,9,10,13,21,29,30,32,33,34,35,36],"500":[1,3,4,6,9,10,13,32,33,34,35],"50000000e":[35,36],"50000455":5,"50000553":5,"50000718":5,"50000855":5,"50000969":5,"50001063":5,"50001142":5,"50001207":5,"50001261":5,"50001306":5,"50001343":5,"50001374":5,"500014":5,"50001414":5,"50001422":5,"50001439":5,"50001454":5,"50001466":5,"50001476":5,"50001485":5,"50001492":5,"50001498":5,"50001502":5,"50001506":5,"5000151":5,"50001512":5,"50001515":5,"50001517":5,"50001518":5,"50001519":5,"50001521":5,"50001522":5,"50001523":5,"50001524":5,"50001525":5,"5018":26,"5020612":26,"50227564e":[6,31],"50258788e":21,"502698":[],"50269821":[],"50306335":[],"50321091":5,"50327198":23,"50427787":32,"50482139":[],"50530832":32,"506":0,"50600514e":[],"50610071e":34,"506553":30,"50655336":30,"50667812":[],"50714096e":[],"5076963":23,"507d50":[9,10],"50846111e":[6,31],"50846112e":[6,31],"50850373":[],"50887105":[],"50911289":[],"50it":[],"50j":[13,34],"50x10":1,"51":10,"510":1,"5105332296929628":9,"51069279":23,"51104913":[],"51136852":[],"51154388":[],"5116375":[],"511888":5,"51317506":[],"51364117":23,"51374050":32,"514219":30,"5142856":[],"51437058e":30,"51447004":29,"51512235":[],"51546825":29,"51564682":23,"51611732":35,"51643579":[],"51659846":34,"51709529":[],"51728978":[],"5177783846":4,"51808934e":36,"51858116":[],"51914183e":[],"51928402":23,"51937727":23,"52":[33,34,35],"52031552e":30,"52087499":[],"521422502348998":11,"521558":[],"52155823":[],"52173381":[],"5222222222222223":1,"52284329e":30,"52301447e":30,"52317963":[],"52362157e":30,"52397611":[],"52446101":26,"5257011":[],"52573336":11,"52635761":23,"52654886":[],"52657934":23,"526744":[11,30],"52698542":[],"52706754":11,"527068":11,"52732966":[],"52780600":32,"52874252":5,"52876551":[],"52888979":[],"52989287e":[],"52it":[],"53":[9,33,34],"5303329":11,"53052247":[],"5305555555555556":1,"53105728":[],"53125507":23,"531280":30,"53149078":[],"532":[],"5321613":[],"53269627e":[],"53285379":[],"532854":[],"533":[],"53312817":29,"534":[],"535":[],"53512750e":[],"53534008":26,"53585173":[],"535852":[],"53629564":23,"53640693":[],"537":[],"53703498":6,"53723188":[],"53729411e":30,"53732988":[],"53738247":32,"5378811":11,"538":[],"5384615384615384":9,"539":[],"539261":[11,30],"53942728":[],"53996947":[],"5399913":[],"53it":6,"54":[6,9,26],"540":9,"54011398":[],"54039921":5,"54041041e":5,"54057582":[],"54150298":36,"541605":30,"54175461":34,"5426270409877345":[],"543939":30,"54393936":30,"5443909":[],"544439":30,"54490887":[],"54637219":32,"54725976":[],"54760497":35,"54811237":26,"548263635652985":[],"54843215":[],"548432150659993":[],"54856099":[],"54873252":[],"54880148":[],"54921401":[],"54928947e":36,"54935794":29,"54it":6,"55":[1,9],"55020405":[],"55020649":[],"55042779":[],"551023":5,"55102329":5,"55179339":[],"55196383":[],"55386681":29,"55460327e":[],"55542568":[],"5555555555555556":1,"55582742":29,"5567":6,"55688514":26,"557795":[11,30],"55838":34,"55854694":11,"559791959661649":26,"55996153":[],"55it":[],"56":[1,9],"56033697":5,"56042437":[],"56072658":[],"561410":[],"56141009":[],"56198284":5,"56342158":[],"564":9,"56423957":[],"56423957069263":[],"564374":[11,30],"56453869":[],"564759":[],"56475921":[],"56476512e":[],"565":9,"5653087":35,"56536":[0,29],"56541622e":[],"56589683":32,"566":9,"56636616e":[6,31],"567":9,"56763673":[],"56783103":23,"56790195e":30,"568":[9,32],"56804783":[],"56832496e":[],"56857739e":[],"569":[1,9],"56912044e":[6,31],"56922102":29,"56939714":5,"56947078":[],"56965674":32,"56967917":[],"56977352":[],"56it":[],"57":[0,8,9,27,29],"570":9,"571":[5,31],"571105947979344e":[6,31],"571105947979412e":[6,31],"57192197":[],"57201944e":[6,31],"57252451e":30,"57261202":[],"574465":[11,30],"57468142":29,"57492326":[],"57521514":[],"57584612":[],"575870409023631":[],"576":32,"5769230769230769":9,"57803254":29,"57819238e":[],"57847325":[],"57881465":[],"57886743":[],"57914918":[],"57933547":26,"58":[9,10,27,29],"58013829":[],"58084123":[],"5833333333333334":9,"583595":30,"58379362":[],"5847256":[],"58492636e":30,"58493493":[],"58493681":[],"58583003":[],"58589719":29,"58735893":[],"58827236":6,"5888888888888889":1,"58890784":[],"58914105":[],"589841":[],"59":9,"59009792":11,"59078383":[],"590784":[],"591317992":4,"59184268":[],"59215613":[],"59244881":[],"59348521":[],"59354079":6,"59355752e":30,"59372982":23,"594241":[],"59424119":[],"5944444444444444":1,"59465457e":[],"59491404e":[],"59630232e":[],"5965161e":36,"59683811":[],"59698459":26,"59730078":[],"59779819":34,"59875207":[],"59884169":29,"59908884":[],"59963873":[],"59971727":[],"5cm":26,"5f":[8,34],"5x":8,"5y":8,"6":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,21,23,26,27,29,30,31,32,33,34,35,36],"60":[1,3,6,9],"60000":4,"60026673":[],"60041459e":[],"600529":[],"60052901":[],"60160003e":30,"6019067271":4,"6029291":[],"60293962":5,"60342978":32,"60375434":23,"6038642":[],"60418171":[],"60420593":5,"60451189e":[],"60543038":30,"60552651":[],"60570744":[],"60588173":29,"60605083e":[],"606251":[],"60625144":[],"60664448":[],"60673226":11,"606760":5,"60737006e":36,"60762863":[],"60921896":[],"60929685":32,"60940356":[],"60943791":[23,29],"60999067":[],"61":1,"61069681":23,"61083596e":[],"61106937e":[],"6111111111111112":1,"61113781":[],"61192203":[],"61192712":23,"61209378e":36,"612939":30,"61321722e":[],"61325173":[],"613579":30,"61382924":[],"613893902124586":26,"61395701":[],"61414743":23,"61468323":26,"614808":[11,30],"6153846153846154":9,"61564092":[],"6156409232714415":[],"61602014e":[],"61621902":[],"61774362":[],"61775176":32,"618746":[],"61883807":[],"618982":30,"61979664e":[],"62":1,"6200":29,"6201":29,"6202":29,"6203":29,"6204":29,"62113349e":30,"621584":[],"62158409":[],"62242138e":[],"62275788":34,"62286539":[],"62323175":36,"62351789":[],"62373464":11,"625":[7,33],"62551462":26,"62573269":29,"62617788":23,"62620041e":[],"626635268":[6,32],"626678":[],"6266783":[],"6267112":[],"62671667":[],"62714703":36,"62716271":35,"62725226":31,"628":6,"62863106e":30,"62886648":[],"62894215":5,"62905281e":[],"62908496":23,"62918713":21,"62954328e":21,"63":[0,1,6,9,32],"63025821e":[6,31],"63030526":[],"63031478":[],"630315":[],"63037846":6,"63042739":21,"63046054":[],"63071772":[],"63142399":29,"63142731":[],"63162342":30,"63207408":[],"63209435":29,"63249532e":[6,31],"63309898":[],"6333349473431832":26,"63347711":21,"63490568":26,"63498144":5,"63546236":[],"63555267e":[],"63619709":30,"6380763200092493":[],"63833441e":[],"6383903":29,"63896182":[],"638962":[],"6389681":[],"63898112e":30,"63919355":5,"639194":5,"64":[1,2,3,4,13,23,29,34,35],"64009263":[],"64012627":5,"6401576":[],"6407249":[],"640x480":[6,13],"64316192":32,"64322974":[],"64361375":29,"64362404":[],"64373221":[],"64373635e":34,"64399916":[],"64411666":[],"64412879":[],"6441397":[],"64425744":[],"64516328":35,"64564368e":[],"646283":[11,30],"64713979":[],"64742912e":[6,31],"647473":[11,30],"64796751":29,"64857542":[],"64885265":23,"649":[],"64909048":[],"649382":[11,30],"64976691":[],"64x50":1,"65":[1,2,8,9],"650":[],"65082441":[],"651":2,"65183066":[],"651831":[],"652":2,"65293772":[],"653":2,"6533977":[],"653398":[],"6536392":30,"654":2,"65442354":30,"654424":30,"65475653":[],"655":2,"65543115":[],"65554958":[],"65571174e":30,"65591748":[],"65593984":[],"65599456":30,"656":[],"65641173":[],"6568154596723088":[],"6568686180915178":[],"65686862":[],"65720152e":30,"6572612e":36,"65738717e":30,"65743689":30,"65759901":[],"658":2,"65833132":30,"65885453":5,"65889641e":[],"65891389":30,"658914":30,"659":2,"65900052e":[],"65917558":23,"65944342":34,"65it":[],"66":2,"660":2,"66018725e":30,"66063786":[],"66064822":30,"66080313":30,"66204648":6,"662836197064178":[],"66289235":[],"66294408":30,"6629598":[],"662960":[],"66365453e":[],"6638":9,"664314":5,"66431407":5,"66456459":[],"66487438":[],"66498292":[],"6652177":30,"66560":9,"6663569":[],"66694492":36,"667":9,"6671767":[],"66729685":[],"66757105e":[],"66809369":[],"668172":30,"6690108":[],"66951679":[],"67":[1,2,9],"67015946e":[],"6702":[],"67047975e":[6,31],"67088558":[],"67100236":[],"67231298":[],"67238764e":[],"672721":30,"672759":[],"67275915":[],"67313212":[],"67314874e":5,"67374815":23,"674":32,"67435043":26,"67464946":[],"67490857":34,"67495943":[],"67524588":23,"67561021":29,"67819487e":[],"67834752":[],"67875366":[],"678754":[],"67it":[],"68":2,"6801":[],"68072161":23,"6809195":[],"680920":[],"68092237e":[],"68110474":35,"6816947":[],"68192193":5,"68257097":[],"68286725":30,"6831505":[],"68352799":[],"68402334":36,"68534263e":[6,31],"68542204":5,"68591105":[],"68637642":[],"68655456":23,"6869":9,"68735473":29,"68822559":[],"688226":[],"68826552":29,"68857788":[],"6887363571":4,"68879472":[],"68929213e":[6,31],"689519":[11,30],"69":[2,9,26],"690":9,"690617":30,"69069n_":26,"69089532":23,"691":[],"691364":[],"69136414":[],"69182892e":30,"69227923":[],"69230769":34,"6923076923076923":9,"69247718":23,"6927554":23,"69303453":[],"693035":[],"69391797":[],"69417174":[],"69435454":[],"69438869":[],"69465386":23,"69484813e":5,"69504801":6,"69515531":[],"69566966":29,"69634577e":[6,31],"69695259":5,"697346":[],"69734609":[],"69756791":[],"69768266":11,"6980":[21,34,35],"6988905":29,"69903406":[],"69983227":[],"6999536":11,"69it":[],"6n_":26,"6pm":29,"7":[0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,21,23,25,26,28,29,30,31,32,33,34,35],"70":[1,6,7,9,33],"7002164":26,"70037324e":30,"70039784":[],"701370":5,"70241548":[],"7026722043092946":[],"7029975":[],"70301068":[],"70362677":[],"70469324":29,"70474145":[],"70499955":29,"70514808":[],"70587399":[],"705946":[],"70594608":[],"70630967":[],"70653767":4,"70665448":[],"70704566":[],"7070883":29,"70710678":[5,30],"70711022":[],"7074705":[],"70811405e":36,"70832814":5,"70857635":[],"7086067479626619":30,"70928399":11,"709284":11,"71":1,"71142161":30,"711422":30,"7119":9,"712018":[11,30],"71261809":[],"71263851e":36,"7127128":29,"71332117":[],"713763":[],"71376303":[],"71384267e":34,"71441086":[],"71469351":[],"7150195":29,"71505132e":35,"71507714e":[],"71524686":[],"71582784":[],"71737253":30,"71761101":30,"718165":5,"71838601":23,"71860732":[],"7198234":[],"720889407643293":[],"72174172":11,"72236654":[],"72271878e":[6,31],"7228852":[],"72288611":[],"72309979e":[],"7236674":5,"724":3,"72427854":[],"7249499":[],"725256":[],"7252563":[],"726017":[],"72601722":[],"72602818":[],"72710494":29,"72744372":[],"72770687":5,"727707":5,"72771857":[],"72848736":[],"72859758":5,"72952595":[],"72962885":23,"72964493e":[],"72981762":8,"72992196":[],"73":[6,9,32],"73018893":[],"73031999":[],"73062648":[],"73063053":[],"73068535":[],"73071831":26,"731000":30,"73122034":[],"73176319":23,"73203674":[],"73252708":34,"73265885":34,"73305640e":[],"733096":30,"73337355":[],"73374853e":36,"73578772":[],"73595198":[],"73646130e":[],"73690387":34,"737184":[],"73718419":[],"73741131e":[],"73785069":[],"737851":[],"73853838":[],"73958682":[],"73986200e":30,"73994248":[],"74":[6,32,34,35],"740":9,"74028787e":[],"7403629637766833":11,"74038232":[],"74075864":26,"74081822":8,"74171049":[],"74259663":[],"742597":[],"74272285e":[],"74291603e":30,"74384949":30,"74607851":30,"74613334":[],"74724414e":30,"74724774":34,"74829661":30,"74840212":5,"7487814387207385":[],"74878144":[],"74883972":[],"74900488":5,"74957448":[],"749765":30,"75":[5,6,8,9,11,24,30,32,35,36],"75018686":[],"750187":[],"75025744":[],"750445":30,"75050135":30,"75080943":[],"7509571":[],"7510197":[],"7511273":[],"75131415":[],"75138064":23,"751699":[11,30],"75170092":5,"75216828e":34,"75269037":30,"75300068":[],"7539148284817965":29,"75406226e":[],"75424998":35,"75433448":[],"7546682196464342":[],"75532041":[],"75576555":30,"75600095":[],"756352":30,"75654448":[],"75677341":[],"756828":[],"75682834":[],"75760403":[],"7577":32,"75770568":30,"7577113351177733":[],"75956617":23,"76":[9,27,29,33,34],"76120718":[],"761574":[],"76157429":[],"76190591":31,"76262775":[],"76277254":[],"76329289":21,"7642448":[],"764245":[],"765":[7,33],"76527062":[],"76533281":5,"765333":5,"7658599":[],"76612827":[],"766163196245293":[],"76686148":[],"76690383":32,"76692036e":30,"767367275553824":[],"76790092":[],"76807288":[],"76855921":23,"76887316e":30,"7692307692307693":9,"76936315":5,"76940759":26,"76942272":[],"7694444444444445":1,"76996262e":[],"77":[9,27,29,34,35],"77030637":23,"77106886":35,"771128":[],"77152076":5,"77152924":[],"7718":9,"77199379e":[],"772588722239781":[34,35],"77352152e":[],"77354301":[],"774498":[],"77449804":[],"77465911":[],"77482712":[],"77507653":[],"77559615":[],"77635684e":[],"77636e":[34,35],"77652198e":30,"77659961":26,"7766443":[],"77714169":8,"77725472":[],"777255":[],"77803692":[],"7782028952":4,"77845284":[],"77873845e":[],"77959897":[],"78":[],"78009660e":30,"78010668":35,"78156479e":5,"78184120e":[6,31],"78186404":23,"78254537":[],"78278086":[],"78326199e":[],"78459458":35,"78671736":[],"78745927":[],"78758569":[],"78876155e":[],"78892891":[],"78941903":5,"79":[],"79111643":5,"79135536e":30,"79171202":23,"79247398":[],"79280475":[],"793167":30,"794282":[11,30],"79469098":[],"79503363":21,"7953443":31,"79622905":[],"79623487":5,"796235":5,"79633065":32,"79718864":29,"79778008":6,"79787194":11,"797872":11,"797e":6,"79849321":[],"79866484":[],"79870689e":30,"7989356":29,"79898903":23,"7d7d58":[9,10],"8":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,21,23,24,26,29,30,31,32,33,34,35,36],"80":[0,1,5,6,8,9,30,31,32],"800":[4,7,33],"80011603e":[],"80056922":[],"801356":[],"8030191":[],"80354994":6,"80410179":[],"80413696":[],"80460179":32,"80469739":5,"8055555555555556":1,"80576215":35,"80609615e":[6,31],"80609616e":[6,31],"80637385":[],"80740939":29,"80847477e":[6,31],"8084934":23,"80855691":[],"808557":[],"80907609":34,"80979265":[],"81":1,"81007381":29,"81035098":[],"81042619e":30,"81048318e":[6,31],"81160425":5,"81218742e":30,"81246697":26,"81283649":[],"81318307":[],"8133":6,"81333808":6,"81425129e":30,"81479491":[],"81506255":[],"81559586":[],"815am":[27,29],"81622636":[],"81633628":11,"816454":30,"816847":30,"81839897":[],"81889188":35,"81919129":[],"819253":[],"81925302":[],"81931348":35,"81947005":23,"81979166":26,"82":[],"82060913e":30,"8207274870895702":5,"82079885":[],"82121282":[],"82146046":35,"82161167":29,"82198978":5,"82242798":[],"8227":[],"8232102961414203":[],"823417":[],"82341746":[],"82376174e":30,"82418008":[],"82418352":[],"8244":[],"8250103":35,"82533209":11,"82551764":23,"82559478":[],"82623709e":[],"8265786":5,"82688363":[],"82802004":[],"82832579":[],"82914126":[],"829252":[],"82925222":[],"83":2,"83020679":[],"8305555555555556":[],"83146596":32,"83363025":[],"83369175":[],"83463634e":30,"83466807":[],"83512277":5,"83641435":34,"83655756":29,"83718206":[],"83816147":[],"83823317e":30,"83870189":6,"8387133":[],"83884553e":[],"839957":[],"83995705":[],"84":2,"84159992":[],"842":[0,7,33],"8423144":23,"842436":30,"84254917":[],"843":[0,7,33],"84351715":[],"84355903e":1,"844":[0,7,33],"84401886":5,"84443254e":1,"84478178":34,"84605507":[],"8461538461538461":9,"84661230e":[],"84707251e":30,"84711297":[],"84726382":[],"84767088":[],"8476874":[],"84780262":6,"84789579e":[],"8485":32,"84858":32,"84862355":29,"8488":32,"84923989e":[6,31],"84972787":[],"84994524":5,"85":[1,9],"85005989":[],"85014487":[],"850164":5,"8505072899794293":[],"85064942":11,"85079059":[],"85108001":[],"85112594":23,"8517571":[],"85222243":[],"85259666e":[],"85263220":6,"85276538":23,"85278920e":5,"85293303e":30,"85378708":[],"85408468e":34,"85422602":[],"85437905":35,"85551266e":30,"85601992":5,"85625134":29,"85703369":[],"85711016":29,"85777073":[],"857771":[],"858":9,"8583333333333333":[],"85866294e":21,"85871255":[],"85945208e":30,"86":2,"86009093":[],"86016288":[],"86062977":6,"86066395":[],"86067818":[],"86117291":5,"86123808e":[],"86134827":5,"86143379":[],"86145244":11,"86174943":[],"86192682e":30,"86197958":[],"86240935":[],"86247117":[],"86267497":[],"862675":[],"86273371":31,"8638888888888889":1,"86416941":[],"86445334":[],"86458368e":36,"86459987":29,"865":[0,7,33],"86519139":23,"866":[0,7,33],"86602331":[],"86629161":26,"86630":9,"86639832e":35,"86643649":[],"8666666666666667":1,"867":[0,7,33],"86737671":[],"86810":9,"86867512":11,"86891741":[],"8691787":29,"86943859":[],"86978877":[],"87":9,"87020155":[],"8702784034":4,"870337":[],"87068171":31,"87070464":[],"870704644539707":[],"87072815e":30,"87093752":[],"87148597":[],"87169607e":30,"87186187":26,"8720648":26,"8722222222222222":[],"87238538":[],"87340054":[],"87381451":5,"87399194":[],"87473452":[],"87494456e":30,"875":1,"87584434":[],"8759":[34,35],"87627342":32,"87696461":[],"877":6,"87732748":[],"87740526":29,"87788573":[],"87818331":[],"87878356":26,"87884833":[],"87981676":[],"88":[29,34,35],"88046261":5,"8805555555555555":[],"88064505":[],"88135577e":[],"88157423":29,"88168312e":[6,31],"8817842e":[],"88182591":30,"88236598e":[],"8825782":[],"88289263":29,"88323026":30,"88336879":5,"8834":[],"88377332":[],"884669":30,"88501323":[],"88529063e":[6,31],"88551766e":30,"88594444":21,"88613493":30,"88614317":[],"88639567":29,"88653291":29,"88738394e":[],"88809826":29,"88860399":26,"8888888888888888":[],"88960947":[],"8896094720230128":[],"89":9,"890033":11,"89003324":11,"89017198e":30,"89044267":21,"89058005":29,"8905826":[],"89069029":21,"89126914e":30,"8917148":[],"891715":23,"89184351":[],"89288636":11,"8931686":34,"89408972":[],"89410423":5,"8944444444444445":[],"89457785":[],"89463761e":[],"89533642":29,"89540936":[],"89563074":36,"8962":[],"89654756":[],"89710385e":[],"89724282":[],"89766337e":[],"8978":[],"89845198":26,"8f":[6,32],"8g":[6,32],"8n":23,"8x8":1,"9":[0,1,2,3,4,5,6,7,8,9,11,12,13,14,18,21,23,24,25,26,27,29,30,31,33,34,35,36],"90":[0,1,6,9],"90075537":5,"9011":6,"90114639":29,"90135464e":30,"90220243":5,"90266948":5,"9027777777777778":[],"90300219":[],"90304177e":30,"9040":9,"90475506e":[6,31],"9054":32,"9055555555555556":[],"906589":[],"9065894":[],"906747":5,"90717653":11,"907177":11,"90842732":23,"90860768":23,"90894281":29,"91":[27,29],"910":9,"91099021":[],"91100141e":34,"9111111111111111":[],"91114704":[],"91128596":5,"91247848e":36,"91270333":[],"91312563":[],"91365263":[],"91410559e":[],"91416944e":[],"91434750e":[],"91492986e":[6,31],"91546928":[],"91648657":[],"9166666666666666":9,"91669165":[],"916692":[],"91672129":29,"91722512e":[],"91744988":[],"91752854":[],"91760278":5,"91811422":[],"91812702":5,"91854134":[],"918785":29,"918992":30,"91933003":23,"919503":11,"9195033":11,"91961463":[],"92":[6,9,27,29],"92003207":[],"92192012":[],"9225384545636204":5,"9230769230769231":9,"92308867":[],"92313548e":36,"92319842":[],"92326255":[],"92341148":23,"92370959":[],"92376655":[],"924e":6,"925":1,"92507116e":1,"92512799":[],"92527681e":[],"92578916":5,"92599642":[],"92604454":[],"92622842":0,"92661467e":34,"9271707090281667":[],"92756256":31,"9277777777777778":1,"9288904":23,"92921498":26,"9305555555555556":1,"93074023":[],"931":[0,29],"93155188":5,"93158979":5,"93237862":[],"932382":[],"93289669":[],"93293067":26,"933":[5,31],"93325371e":36,"93366198":[],"933662":[],"93397254e":[],"93492130e":[6,31],"93597168":[],"935972":[],"93601008e":30,"93619369":23,"93668828":[],"936877889972962":[],"937":26,"937057":11,"937082":30,"93787605":[],"93799826":5,"938":26,"9387":9,"93891335e":[],"939":[0,26,29],"93900569e":30,"93909866":[],"93937564":[],"93942872":35,"93968601":[],"93970238":26,"93989887":[],"94":[9,26],"94092702":[],"94099173":[],"94141801":[],"94221383":23,"94226022e":[6,31],"94255277":26,"94273542":30,"94284104":5,"94285762":29,"94291287":[],"94320205":5,"9434":5,"94388948":34,"94419718":[],"9444444444444444":1,"94484047e":[35,36],"94499279":34,"9450635":29,"94591015":[23,29],"946167":[],"94616709":[],"94623184":5,"94625725":[],"946276":[],"94627617":[],"946372":[],"94637206":[],"94639099":11,"946957":5,"94704941e":[],"9472222222222222":1,"947607":[],"94766419e":30,"94781064":31,"9482527":5,"9485531":[],"9495484":[],"94973606":[],"95":[1,9,11,32],"95008046":6,"95033155e":[],"950423":[],"95053694e":[],"95115528":[],"95166920e":30,"95226607":[],"95231424":5,"952387":30,"9527777777777777":[],"95284275":5,"953065564":1,"95338273":30,"95343966":23,"95351665":5,"95354276":26,"95395895":[],"953959":[],"954":26,"95400323":29,"95511792":30,"955118":30,"95518112":[],"9555555555555556":1,"95563211":[],"955820c21e8b":4,"95611042":34,"95647867":[],"956563":[11,30],"95684892":5,"95703":[34,35],"95715036":[],"95743466e":[],"95793988e":[],"958228616652075":5,"95845431":21,"95872127":[],"95890587":29,"95906059":34,"959076":[],"95935439":[],"96":[1,6,9,11,32],"960":26,"9601304850035702e":[6,31],"9601304850073734e":[6,31],"96015381":23,"96024953":5,"96075051":34,"96080358":26,"96084663":5,"961":26,"962":26,"96231225":[],"96251859":[],"96301764":35,"96305058":[],"963187":[],"9637117593816477":[6,31],"96379806e":[],"96391888":[],"9640435":5,"96432396":[],"96461948":23,"9647801":29,"9649652536":4,"965548":30,"96585824":[],"96631321":30,"96688672":5,"967":6,"9674916":5,"967809":[11,30],"96826039":[],"96850191":[],"96853248":23,"968650":[],"96865004":[],"96866031":[],"968704":11,"96870431":11,"96894842":[],"96916206":[],"969190":[],"96919021":[],"96919836":[],"9692":[],"96963458":36,"96991192":[],"97005689":5,"97065359":32,"970827":[],"97082748":[],"97108e":[34,35],"97120565":[],"9712983":[],"97206657":5,"972067":5,"972149":[],"9722222222222222":[],"97228653":[],"9722865317690382":[],"97243128":5,"97243946":[],"972533":[],"97253307":[],"97272223":[],"97300836":5,"97435908":[],"97480604":[],"97482498":11,"974825":11,"97486336":29,"97497404e":[6,31],"97498674":29,"975":[],"97507735":5,"97512176":29,"975484":[],"97548406":[],"97570392":29,"97626519":[],"97630233":32,"9767506308987675":[],"977":6,"97705827":5,"97716508":[],"97758848":5,"9777777777777777":[],"978":32,"9780387310732":28,"9780387848570":28,"9781098134174":29,"9781492032632":28,"9781801819312":29,"97836358":[],"978553":5,"97898392":[6,30,31],"97906022e":30,"9792":[],"97926491":5,"97935648":[],"97979891":6,"98":[0,1,9,36],"980":9,"9805555555555555":[],"98091621":5,"981321":30,"98139097":5,"98140006e":[],"98190064":[],"98232596":21,"98246764":35,"98271562":26,"98275501":5,"98281205":34,"983310":30,"98338288":[],"983383":[],"983450":[],"9834505":[],"9838929":[],"98413059":5,"98413606":[],"9841870203276504":[],"98454786":5,"98473694":[],"985":26,"98566191":5,"986":26,"9861111111111112":[],"98619989":[],"98636199":[],"986362":[],"98654811":[],"986699":5,"98680716":5,"98716878":5,"98723376":[],"98740373":23,"98770503":29,"98808176":5,"98822371":6,"9888888888888889":[],"989":26,"9890348":5,"9893447":5,"98947674e":30,"98947894":30,"9898ff":[9,10],"99":[1,6,9,11,13,21,32,34,35],"990":9,"99003341":[],"99009525":5,"9904314810719695":[],"99072374":[],"99088801":5,"991":26,"991047":[],"99104747":[],"99114739e":[],"99115119":5,"99176998":5,"99194201":[],"992":26,"99201684e":[],"99242921":5,"99265097":5,"99294056":[],"993":26,"9930742":23,"99316252":5,"99318183":[],"99360578e":35,"99368326":[],"99370678":23,"99371056":5,"99389612":5,"99415296":[],"99427512":23,"9943201":5,"99434472":[],"994345":[],"994474":[],"99447418":[],"99456598":34,"99475306":34,"9947756":5,"9948998579029953":[],"99492986":5,"99498272":[],"9951059931014423":[],"99512017":23,"9952183728736417":[],"9952505213910134":30,"9952537939995855":[],"99528218":5,"99539415":5,"9955318336036834":30,"99562995":35,"99566069":5,"99578809":5,"9958589197366403":[],"9958983289118531":[],"9959308805732706":30,"996":[5,31,32],"99608161":5,"99619572":21,"9963961":5,"99647992e":[],"99650061":5,"996626":[],"99662602":[],"9967458":5,"9969461173312454":[],"9969513794144311":[],"99700706":5,"99709215":5,"99723951":[],"997252717901263":[],"99729756":5,"99751458":5,"99753321e":30,"99758326":5,"99762142":31,"997746":11,"99774602":11,"99775587":5,"99793613":5,"99799099":5,"99802696":34,"99812668e":[],"99813653":5,"99828624":5,"9983295":5,"99835783":34,"99845267":5,"99848215":[],"99848815":34,"99854557":30,"998577":5,"99861053":5,"99862019":30,"99869482":30,"99871521":5,"99876945":30,"99881845":5,"99883628":30,"99884384":5,"99884409":30,"99884986":31,"99887767":[],"99891093":30,"99891873":30,"99893323":5,"99898558":30,"999":[9,21,26,34,35],"99901896":5,"99903755":5,"99906023":30,"9990927157696581":31,"99911427":5,"99912709":30,"99913489":30,"99916114":34,"99918546":5,"99919837":5,"99920175":30,"99926459":5,"99927642":30,"9993237":5,"99933188":5,"9993511":30,"99938942":5,"99941797":30,"99942911":21,"9994385":5,"99944272":5,"9994574":[],"99949266":30,"99949306":5,"99953381":5,"99953475":5,"99954278":[],"99954434":[],"99954925":34,"99956033":[],"99956181":21,"99956735":30,"99957911":5,"99961294":5,"99965056":5,"99967865":5,"99968451":[],"99970894":30,"99970988":5,"9997332":5,"99975913":5,"99977375":[],"99977849":5,"99978365":30,"99979896":35,"99980002":5,"9998161":5,"99984732":5,"99987324":5,"99989103":34,"99989296":21,"99989476":5,"99990413":[],"99990706":[],"99991245":[],"99991263":5,"99991295":[],"99992107":35,"99992746":5,"99993978":5,"99995":5,"999955585168597":[6,31],"99996755":[],"99997644":21,"99998727":[],"9x":[6,24],"9y":[6,24],"\u00f8yvind":[6,30,31],"abstract":[1,20,34],"boolean":4,"break":[0,4,6,11,14,29],"byte":[23,29],"case":[0,1,2,3,4,5,6,7,11,12,13,14,16,21,22,23,24,29,32,35,36],"catch":0,"class":[0,1,3,4,6,7,8,9,11,12,13,26,29,32,34,35],"default":[0,1,2,4,6,7,8,16,23,24,29,30,31,33,36],"do":[0,2,3,4,5,6,8,9,10,11,12,13,14,15,16,21,23,24,29,30,33],"ekstr\u00f8m":4,"export":9,"f\u00f8470":[27,29],"final":[0,1,2,3,4,5,6,7,8,9,10,11,13,14,16,18,19,20,24,25,26,27,29,32,33],"float":[0,3,4,5,9,11,13,14,23,29,30,34,35],"function":[2,3,4,5,9,14,15,16,17,18,19,22,23],"import":[0,1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,17,24,26,32,33,34],"int":[0,1,2,3,4,5,6,11,13,14,21,23,26,30,32,34,35],"long":[0,1,3,4,12,13,29,33,34,35,36],"m\u00f8svatn":[6,24],"new":[0,1,2,3,5,6,7,8,9,10,11,13,14,17,21,23,29,30,33,34,35],"public":[0,22,29],"return":[0,1,2,3,4,5,6,7,8,9,11,13,14,21,23,24,26,29,30,31,32,33,34,35,36],"sch\u00f8yen":[6,30,31],"short":[4,5,20,24,31,32],"super":[5,30,31],"switch":0,"throw":[3,6,26,32],"true":[0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,19,23,24,26,29,30,31,32,33,34,35,36],"try":[0,1,2,4,5,6,7,8,9,10,11,13,14,15,16,22,23,24,26,29,30,31,32,33,34,35,36],"var":[1,5,6,10,11,18,19,24,26,29,30,31,32],"while":[0,1,3,4,5,6,7,8,9,11,12,13,26,29,30,31,32,33,34,35,36],A:[2,3,5,6,7,10,11,12,13,16,18,20,22,23,24,25,26,27,28,30,34],AND:2,And:[0,3,4,5,6,9,13,20,22,24,26],As:[0,1,2,3,4,5,6,8,10,12,13,16,23,24,26,29,30,31,32,33,34,35,36],At:[0,4,6,13,24,29,34],BE:[0,29],Be:[2,22,29],Being:[13,34],But:[0,1,2,3,5,6,9,10,26,30,31,32,36],By:[0,3,5,6,12,13,17,23,29,30,31,32,33,34,35],For:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23,24,25,26,28,29,31,32,33,34,35,36],IF:[6,31],IN:28,If:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,15,16,21,22,23,24,26,29,30,31,32,33,34,35,36],In:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,22,23,24,26,28,29,30,31,32,33,34,35],Is:11,Ising:[5,12,30,35,36],It:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,22,23,24,26,29,30,31,32,33,34,35,36],Its:[1,2,4,11],NO:[9,11],No:[0,6,7,9,29,31,33,35],Not:[0,1,5,6,30,31,32,35,36],OR:26,Of:26,On:[0,3,9,15,24,25,26,27,28,29],One:[0,1,3,4,5,6,7,8,11,12,13,17,21,24,26,30,32,33,34,35,36],Or:[0,1,6,24,29,33,36],Such:[0,6,12,16,26,32,33,34,35,36],That:[0,5,7,10,11,12,14,19,24,26,29,31,32,33,36],The:[4,10,13,14,15,16,18,19,20,21,23,24,25,26,27,28],Their:[],Then:[0,1,6,8,9,10,11,12,13,14,23,24,29,32,33,34,35,36],There:[0,3,4,5,6,8,9,11,12,14,23,24,25,26,27,29,30,31,33,34,35,36],These:[0,3,4,5,8,9,10,11,12,13,14,15,16,23,24,26,27,29,30,31,34,35,36],To:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,21,23,26,31,32,33,34,35,36],With:[0,5,6,8,9,10,11,12,14,18,23,24,26,29,30,32,35,36],_0:[5,8,10,11,13,30,33,34],_1:[2,5,6,8,10,11,12,13,14,23,30,31,33,34,35,36],_2:[2,5,8,11,12,13,23,30,34,35],_3:23,_4:23,_9:[13,34,35],_:[0,1,2,4,5,6,7,8,9,10,11,12,13,17,18,19,21,23,24,29,30,31,32,33,34,35],__array_function__:2,__class__:10,__doc__:[6,32],__enter__:[0,7,33],__future__:[8,9,36],__getattr__:31,__getattribute__:29,__getitem__:[0,7,33],__init__:[0,1,3,4,7,14,31,33,35],__main__:[2,35],__name__:[2,10,31,35],__rtruediv__:[],_accessor:29,_auto10:[6,12,35],_auto11:[6,35],_auto12:[6,35],_auto1:[2,3,4,5,6,7,12,13,21,23,26,30,33,34,35,36],_auto2:[2,3,4,5,6,12,13,23,26,34,35,36],_auto3:[3,4,5,6,12,13,23,34,35,36],_auto4:[4,6,12,13,23,34,35],_auto5:[4,6,12,13,23,34,35],_auto6:[4,6,12,23,35],_auto7:[4,6,12,23,35],_auto8:[6,12,35],_auto9:[6,12,35],_base:8,_build:[0,17,19,22,24,28,29],_c:1,_can_hold_identifiers_and_holds_nam:29,_check_optimize_result:[9,11],_class:8,_compon:11,_coordinate_desc:6,_depth:9,_fraction:9,_generatorcontextmanag:[0,7,33],_i:[0,1,2,5,6,7,8,11,12,13,15,16,17,19,24,29,30,31,32,33,34,35,36],_info_axi:29,_j:[0,1,2,3,5,6,8,13,17,19,24,30,31,32,34],_k:[13,33,34,35],_l:[12,35,36],_lambda:[6,29],_leaf:9,_ll:[3,4,14],_logist:[9,11],_m:10,_make_vjp:[],_multilayer_perceptron:[],_n:[2,5,8,11,13,30,33,34],_node:9,_np:[],_o:[3,4,14],_open_file_or_url:[0,7,33],_p:[5,8,30],_plugin_dir:[3,4,14],_ratio:11,_rc_params_in_fil:[0,7,33],_s:[3,4,14],_sampl:9,_split:[6,9,24],_src:[21,35],_t:[13,21,34,35],_test:[6,24],_tf_getinputpropertieslist:[3,4,14],_trace:[],_valu:[],_varianc:11,_weight:9,_wrapreduct:2,a0:3,a0faa0:[9,10],a1:[0,29],a2:[0,29],a3:[0,29],a4:[0,29],a_0:[0,21,29,36],a_1:36,a_1a:[0,29],a_1x:21,a_2:36,a_2a:[0,29],a_2x:21,a_3:[0,29],a_3a:[0,29],a_4:[0,29],a_4a:[0,29],a_:[0,1,16,23,29,30,36],a_h:1,a_i:[0,1,2,12,29,36],a_j:[1,12,36],a_k:[0,1,12,36],aaron:28,ab:[0,2,5,13,14,21,24,29,30,31,34,35,36],ab_channel:[22,35,36],abandon:[1,36],abbrevi:25,abid:26,abil:[0,10],abl:[0,1,4,5,6,7,10,12,13,16,24,30,33,34,35,36],about:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,22,23,24,27,31,32,33,34,35,36],abov:[0,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,23,24,26,28,29,30,32,33,34,35],abovement:[6,29,32],abscissa:[13,33,34],absolut:[0,2,5,6,13,29,30,31,32,34,35],absorb:[30,31],acceler:[13,21,34,35],accept:[0,3,6,9,24,29,30],access:[0,3,11,26,29],accid:[4,6,32,33],accompani:[0,29,30],accomplish:[8,9,13,34,35],accord:[0,1,2,5,6,9,12,13,14,15,16,26,29,31,32,33,34,35,36],accordingli:11,account:[0,3,5,13,15,26,29,31,32,34,35],accumul:[12,13,21,26,34,35,36],accur:[0,3,4,6,10,13,32,34,35],accuraci:[0,1,3,4,5,6,7,9,10,11,12,29,30,33,35,36],accuracy_scor:[0,1,10,29],accuracy_score_numpi:1,achiev:[0,1,5,6,8,12,23,29,31,32,35,36],aco:26,acquaint:22,acquir:[1,22,29,36],acr:0,across:[1,3,6,9,22,29,32],act:[1,3,23],action:26,activ:[0,2,3,4,9,25,27,29,33,34],actual:[0,1,4,5,6,8,11,16,23,26,29,30,31,32,36],ad:[1,3,4,5,8,13,15,16,23,31,32,33,34],ada_clf:10,adaboostclassifi:10,adadelta:[13,34,35],adagrad:36,adam:[1,3,4,27,29,36],adap:36,adapt:[4,6,13,28,32,33,36],add:[0,1,2,3,4,5,6,8,10,11,12,15,16,17,21,24,26,29,30,31,32,34,36],add_outgrad:2,add_subplot:[1,7,12,14,24,33,34,35,36],addendum:5,addit:[0,2,3,5,6,7,8,9,10,12,13,15,17,21,22,23,24,26,27,28,29,30,31,32,33,34,35,36],addition:[12,13,33,34,35,36],address:[1,9,11,13,29,34,35,36],adjac:[3,12,35,36],adjoint:[5,30,31],adjust:[0,5,12,13,33,34,35],admir:[0,29],advanc:[4,6,12,28,29,32,36],advantag:[1,3,5,6,10,13,23,31,32,33,34,35],adversari:29,afecionado:29,affect:3,affin:[0,3,8,11,30,36],afford:3,aficionado:29,aforement:14,african:0,after:[0,1,2,4,5,6,9,11,12,13,15,21,22,23,24,26,29,30,31,32,34,35,36],afterward:[0,29],ag:[0,7,25,29,30,33],ag_0:2,again:[0,1,4,5,6,7,8,10,11,12,13,15,16,21,24,26,29,30,31,32,34,35,36],against:[1,4,7,10,21,33],agegroup:[7,33],agegroupmean:[7,33],aggreg:[9,10],agorithm:10,agre:[5,6,26,31,32],agreement:[13,21,34,35],ahead:9,ai:[0,28],aid:[11,20],aim:[0,1,4,6,7,11,14,15,16,22,23,24,30,32,33,36],ainv:5,airplan:3,aka:[5,31,32],al:[0,2,4,15,16,17,24,28,29,30,31,32,33,34,36],alarm:[5,7,31,32],aldo:30,algebra:[0,3,5,13,21,22,30,31,32,34,35],algorithm:[0,1,2,4,5,6,7,8,13,14,22,23,24,26,28,29,31,32,33],align:[0,2,5,6,7,8,13,24,26,29,30,31,32,33,34],all:[0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],allevi:[1,13,33,34,36],alloc:[3,23],allow:[0,1,2,3,5,6,8,10,13,15,16,22,23,24,29,30,31,32,33,34,35,36],almost:[0,1,6,8,11,13,21,26,32,33,34,35,36],alon:[2,9],along:[2,3,4,5,6,9,10,11,22,23,29,30,31,32,33],alpha:[0,1,2,3,4,6,7,8,9,10,13,14,26,29,30,32,33,34,36],alpha_0:3,alpha_1:3,alpha_2:3,alpha_:10,alpha_i:[3,13,34],alpha_k:[13,34],alpha_m:10,alpha_n:3,alpha_opt:[13,34],alreadi:[2,3,4,5,6,10,12,22,23,26,29,30,31,32,35,36],also:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,29,30,31,32,33,34,35,36],alter:1,altern:[0,1,4,5,6,8,9,11,13,23,24,29,30,31,32,33,34],although:[0,1,5,6,8,10,13,16,21,29,31,32,34,35,36],alwai:[0,3,5,6,12,13,16,21,24,26,29,30,31,32,33,34,35,36],am:4,ambit:36,ame2016:[0,29],american:0,among:[0,3,5,9,10,12,23,29,30,31,35,36],amongst:[5,31,32],amount:[0,1,3,4,6,8,10,14,22,32,36],amp:[35,36],an:[1,2,3,5,6,7,8,9,11,12,13,14,15,16,17,19,20,21,22,23,24,26,27,28,30,31,32,33,34,35],an_:26,anaconda:[0,1,15,22,24,29],analog:[13,34,35],analys:[6,31,32],analysi:[1,3,4,7,14,15,16,17,19,21,23,28,33],analyt:[2,3,5,6,7,12,13,15,22,24,29,30,31,32,33,34,35,36],analytical_gradi:[21,35],analyz:[0,1,3,4,5,6,16,17,24,26,30,31],andrew:[1,36],angl:[0,3,9,30],anharmon:3,ani:[0,1,2,3,4,5,6,7,8,9,10,12,14,18,26,29,30,31,32,35,36],anim:[4,12,35,36],ann:[12,35,36],annot:[0,1,3,7,8,29,33],announc:29,anoth:[0,1,3,4,5,6,7,8,10,11,12,13,23,24,26,29,30,33,34,35,36],anp:2,ans_vspac:[],ansatz:[0,29],answer:[0,1,3,5,6,23,24,27,29,31,32],antialias:[2,6,24],anticip:4,anymor:[1,8,36],anyon:[4,8],anyth:[1,26,36],anytim:[27,29],apach:1,apart:[11,13,33,34],api:[1,22,29],appar:2,appear:[0,1,3,13,16,23,26,34,35,36],append:[1,3,4,8,9,13,21,29,34,35],appendix:24,appli:[0,1,2,3,4,6,7,8,9,10,11,12,13,15,16,24,26,28,29,30,31,32,33,34,35,36],applic:[0,1,3,4,5,6,7,9,12,13,21,23,24,26,28,29,30,32,33,34,35,36],apply_gradi:4,approach:[1,2,4,5,6,9,10,11,12,13,17,21,22,26,28,30,33,36],appropri:[2,6,9,12,13,22,26,32,34,35],approv:29,approx:[0,2,3,6,10,11,13,26,29,32,33,34,35],approxim:[0,1,2,3,4,5,6,7,10,11,13,18,19,24,26,29,30,31,32,33,34,35],apt:[0,15,22,24,29],aq:26,ar:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],aragorn:29,arang:[1,3,4,6,7,9,10,12,13,24,29,33,34,35,36],arbitrari:[1,4,6,8,12,13,26,32,33,34,35,36],arbitrarili:[0,1,11,29],arc:[6,24],architectur:[3,4,12,36],area:[0,3,6,9,24,28,29],arg:2,argmax:[1,11],argmin:[4,10,14],argnum:2,argnum_0:2,argnum_1:2,argsort:11,argu:[1,13,34,35,36],argument:[0,2,3,5,6,11,12,13,21,29,30,31,32,36],argval:[],aris:[0,6,12,13,26,29,32,33,34],arithmet:[0,13,23,29,34,35],arm:[6,31],armadillo:23,arnulf:36,around:[0,1,4,5,6,11,26,29,31,32,36],arr:[],arr_list:[],arrai:[0,1,2,3,4,5,6,7,8,9,11,12,13,14,21,22,24,26,30,31,32,33,34,35,36],arrang:[3,29],arraybox:[13,34],arriv:[0,6,9,11,23,26,29,32],arrow:[12,35,36],arrowprop:8,art3d:34,art:[0,1,15,22,29,36],articl:[0,3,4,6,10,18,24,29,30,31,32],artifici:[0,2,7,12,28,29,33],artificialneuron:[12,35,36],arug:[13,34,35],arxiv:[3,4,21,24,34,35,36],asarrai:[0,2,6,9,21,30,31,34,35],asid:30,ask:[5,6,11,12,24,31,32,36],aspect:[0,6,22,24,29,30,31,36],assembl:[0,3,29],assert:4,assess:[0,6,24,29,30,31,32],assici:4,assign:[0,7,8,9,12,13,14,25,27,28,29,33,34,35,36],associ:[0,6,9,12,14,26,29,32,35,36],assum:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,19,23,24,26,29,30,31,32,33,34,35,36],assumpt:[0,3,5,6,9,11,18,24,26,29,30],ast:[0,5,6,18,24,29,31,32,33],astronomi:[29,31,33,34,35],astyp:[4,9,10],asymmetri:[0,29],asymptot:[4,6,32],atleast_2d:[],atom:[0,29],attempt:[0,4,6,7,8,10,29,31,33,36],attend:25,attent:[0,23,29],attr:31,attract:[0,10,29],attribut:[0,9,29,31],attributeerror:[29,31],audi:[0,29],audio:[3,4],august:[15,16,29],aurelien:[0,15,25,28,29],austfjel:[6,24],author:[0,1,10,26,36],authour:29,auto:[8,9,10,26],auto_exampl:[24,31],autocor:26,autocorrelation_tim:26,autocorrelform:26,autocovari:26,autoencod:[4,22,29],autoencond:22,autograd:[22,29,36],autom:[0,22,28,29],automac:23,automag:29,automat:[0,1,2,3,4,11,16,22,23,29],automobil:3,autonom:4,avail:[0,1,4,6,7,10,11,15,20,21,22,23,24,25,27,28,29,32,33,35],averag:[0,1,3,6,9,10,13,14,21,26,27,29,30,31,32,33,34,35],avoid:[0,4,5,6,9,11,13,21,23,29,30,32,33,34,35],awai:[2,3,6,30,31,36],awar:[2,10],award:[27,29],ax:[0,1,2,3,4,6,7,8,9,10,11,12,13,14,23,24,29,32,33,34,35,36],axes3d:[2,6,13,24,33,34],axes_grid1:6,axhlin:8,axi:[0,1,2,3,4,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],axiom:[5,31,32],axis_arg:[],axlabel:[0,29],axvlin:[4,8],axvspan:4,b1:8,b2:8,b3:8,b:[0,1,3,4,5,6,8,9,10,12,13,14,15,16,21,26,27,29,30,31,32,33,35,36],b_0:[0,36],b_1:[0,2,12,13,34,35,36],b_2:[0,13,34,36],b_5:[13,34,35],b_:[0,1,23,36],b_group:9,b_i:[0,1,2,12,29,35,36],b_ia_:[0,29],b_ia_i:0,b_index:9,b_j:[1,12,35,36],b_k:[0,1,12,13,34,35,36],b_m:[12,35],b_score:9,b_valu:9,babcock:29,bachelor:[25,27],back:[0,3,4,5,6,8,9,10,15,23,26,29,30,31,33,34,35],backbon:23,backend:[0,1,4,7,21,33,35],background:[28,29,30,36],backpropag:[1,36],backtrack:9,backup:23,backward:[1,2,4,12,23,36],backward_pass:2,bad:[6,30,31],badli:26,bag:[9,22,29],bag_clf:10,baggin:29,baggingboot:10,baggingclassifi:10,baggingtre:10,balanc:[6,32,33],band:23,bandwidth:23,bar:[0,6,11,15,16,24,29],barber:28,bare:[4,10],base:[0,1,3,4,5,7,8,9,10,14,22,26,27,28,29,30,31,33,36],basi:[5,7,8,10,11,12,13,23,30,31,33,34,35,36],basic:[6,8,12,13,14,22,24,26,29,34,35],batch:[3,4,11,12,13,21,33],batch_shap:4,batch_siz:[1,3,4],batchnorm:4,bay:[7,33],baydin:36,bayesian:[5,22,28,29,31,32],beam:[29,33,34,35],becattini:27,becaus:[0,1,2,3,4,5,6,8,9,12,13,14,29,31,32,33,34,35,36],becom:[0,1,2,5,6,7,9,12,13,21,26,29,30,31,32,33,34,35,36],been:[0,1,2,3,4,5,6,11,12,13,22,23,24,29,30,31,32,34,35,36],befor:[0,1,2,3,4,5,6,7,8,12,13,14,20,23,24,26,29,30,31,32,33,34,35,36],beforehand:[0,26,29],begin:[0,1,2,3,4,5,6,7,8,9,11,12,13,14,21,23,24,26,27,29,30,31,32,33,34,35,36],behav:[1,6,13,32,33,34,36],behavior:[0,1,13,29,33,34,35,36],behaviour:[12,35,36],behind:[0,1,6,8,13,29,33,34],being:[0,1,2,3,4,5,7,8,10,11,12,13,17,26,29,30,31,32,33,34,35,36],believ:[9,23],belong:[7,8,9,13,14,33,34],below:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,23,24,26,29,30,31,32,33,34,35,36],benchmark:10,benefici:[1,13,34,35],benefit:[0,1,4,11,13,15,22,29,33,34,35],bengio:[1,21,25,28,29,30,34,35],benign:[1,7,9,33],benno:36,berner:36,besid:[4,5,31],bessel:[5,30,31,32],best:[0,1,2,3,4,5,6,7,8,9,10,12,13,24,27,29,30,32,33,34,36],best_estimator_:33,beta1:[21,34,35],beta2:[21,34,35],beta:[0,1,3,5,6,7,10,11,13,16,17,18,19,21,24,29,30,33,34,35],beta_0:[0,1,3,5,6,7,13,29,30,31,33,34],beta_0x_:[0,29,30],beta_1:[0,1,3,5,6,7,10,13,29,30,31,33,34,35],beta_1x_0:[0,29],beta_1x_1:[0,7,29,33],beta_1x_2:[0,29],beta_1x_:[0,29,30],beta_1x_i:[7,13,30,33,34],beta_2:[0,3,13,29,30,34,35],beta_2x_0:[0,29],beta_2x_1:[0,29],beta_2x_2:[0,7,29,33],beta_2x_:[0,29,30],beta_2x_i:30,beta_3:3,beta_3x_i:30,beta_4x_i:30,beta_:[0,3,6,7,13,29,30,31,33,34,35],beta_i:[0,3,5,29,30,31],beta_j:[0,5,6,13,18,24,29,30,31,32,34,35],beta_k:[13,33,34],beta_lasso:35,beta_linreg:[13,21,33,34,35],beta_logreg:35,beta_m:10,beta_mg_m:10,beta_n:3,beta_ol:35,beta_p:[7,33],beta_px_p:[7,33],beta_ridg:35,betavalu:5,better:[0,1,2,3,4,6,9,10,11,12,13,21,29,30,31,32,34],between:[0,1,2,3,4,5,6,7,8,9,11,12,13,14,17,21,24,26,29,30,31,32,33,34,35,36],beyond:[0,1,5,6,8,13,21,24,29,30,33,34,35,36],bf:[13,14,23,26,33,34],bg:29,bgd:[13,34,35],bia:[0,1,2,3,5,8,9,10,12,13,19,29,30,31,33,34,35,36],bias:[1,2,3,5,6,9,12,31,35],bibliographi:24,big:[0,1,2,5,6,14,18,31,32],bigger:[1,6,30,31,36],bigr:[12,35],bike:9,bilbo:29,billion:[3,12,22,35,36],bin:[0,7,26,33],binari:[0,3,5,7,9,10,12,29,31,32,33],binarycrossentropi:4,bind:[0,30],binomi:[22,26,29],binsboot:[6,32],bioinformat:0,biolog:[1,12,35,36],bios1100:[22,29],bird:[0,3],birth:29,bishop:[25,28,29],bit:[1,4,23,26,29,36],bitwis:26,bivari:2,bk:[0,13,34,35],bla:[23,29],black:[8,9,14,21,35],blob:[16,20,24,33,34,35],block:[6,10,22,23,26,29,32],blog:29,blogpost:4,blue:[0,3],bmatrix:[0,1,3,5,7,8,11,13,23,29,30,31,33,34,36],bmi:1,bn:[],bodi:[0,1,4,12,29,35,36],bold:1,boldfac:[0,5,16,30,31],boldsymbol:[0,1,2,3,5,6,7,8,10,11,13,14,15,16,17,18,19,21,24,29,33,34,35,36],boltzmann:[12,22,29,35,36],book1:28,book:[19,24,28,29,30,32],boost:[1,9,22,29,36],boostrap:10,bootstrap:[1,13,19,22,24,29,33,34,35,36],borrow:29,boston_dataset:0,bot:8,both:[0,1,4,5,6,8,9,10,13,14,15,16,22,23,24,26,27,29,30,31,32,33,34,35,36],bottl:[7,33],bound:[0,8,12,34,35,36],boundari:[2,4,8,11,12],box:[4,9],boxed_arg:[],boyd:[8,13,33,34],bracket:[4,26],brain:[1,7,12,33,35,36],branch:9,breast:[5,7,11,31,32,33],breviti:[13,21,34,35],brew:[0,15,22,24,29],brg:8,brief:[24,30],briefli:[0,29],bring:[0,5,6,10,30,31],broad:0,broadcast_idx:2,brought:[13,21,22,29,34,35],brownle:4,browser:29,brute:[3,5,11,30,31,33,36],bs:[8,9,10],buffer_s:4,bui:4,build:[0,4,5,6,10,23,26,29,31,32,33,34,35,36],built:[0,1,3,4,6,32],bunch:11,busi:0,bxe2t:[35,36],c1:[8,11],c2:[8,11],c:[0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,19,22,23,26,27,28,30,31,32,33,34,35,36],c_0:26,c_1:[12,35],c_2:[12,35],c_3:[12,35],c_4:[12,35],c_:[0,8,9,10,13,21,26,33,34,35],c_i:[12,13,34,35],c_k:26,ca:[1,29,36],cach:10,cal:[0,8,10,12,13,15,16,29,33,34,36],calcul:[0,1,2,4,5,6,8,9,10,11,12,13,14,15,16,18,21,23,26,29,31,32,33,34,35,36],call:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,19,21,22,23,24,26,27,29,30,31,32,33,34,35,36],calor:[0,30],cambridg:[13,28,33,34,36],can:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,26,27,28,30,31,33],cancel:[0,13,29,30,34,35],cancer:[5,10,31,32],cancerpd:[7,33],candid:[8,9,10,34],cannot:[0,1,4,5,6,7,8,9,25,26,30,31,33],canopi:[0,15,22,24,29],canva:[24,29],cap:[5,31,32],capabl:[0,1,8,13,22,29,34,35],capac:[2,27],capita:0,caption:24,captur:[4,11,12,35,36],car:[3,4],card:[0,7,29,33],cardin:[1,36],care:[11,33],carefulli:[13,34],carlo:[0,6,22,26,28,29,32],carri:[2,6,7,24,32,33],cart:10,casella:28,cast:[1,36],cat:[3,4],categor:[0,1,3,9,11,29],categori:[0,1,3,7,10,12,14,29,33,35,36],categorical_crossentropi:[1,3],caus:[0,5,6,7,26,29,30,31,32,33],causal:0,causat:[0,29],cax:1,cb:[6,29],cbar:1,cc:[0,1,5,13,29,30,31,33,34,36],ccc:[5,12,31,35],cd_fast:6,cdf:26,cdot:[0,2,6,12,13,14,23,26,29,32,33,34,35],celebr:[13,33,34],cell:[0,1,2,3,4,6,7,8,9,10,13,14,24,31,33],center:[0,1,6,7,8,9,11,14,24,26,29,31,32,33,36],central:[0,3,5,6,8,16,23,29,30,31,36],centroid:[14,26],centroid_differ:14,centuri:3,certain:[0,3,6,7,9,26,29,30,32,33],certainti:32,cg:[13,34],cha:0,chain:[0,1,13,22,26,29,34,35],challeng:[34,35,36],chanc:[1,5,13,26,31,32,34,35],chang:[0,1,2,3,4,5,6,8,9,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],channel:3,chap4:36,chapter3:[0,19,24],chapter:[0,6,10,11,16,18,21,23,24,28,29,30,31,32,33,34,35,36],charact:[0,3,5,8,29,30],character:[8,9,10,12,26,35,36],characterist:[0,1,3,10,13,21,29,34,35],charg:[0,29],charl:0,chase:4,chatgpt:24,chd:[7,33],chddata:[7,33],cheap:[5,30],cheaper:[1,13,34,35,36],check:[0,1,3,4,5,6,11,13,23,29,34,35,36],checkmark:3,checkpoint:4,checkpoint_dir:4,checkpoint_prefix:4,chen:10,cheng:30,chiaramont:2,choic:[0,1,2,3,4,6,9,12,13,14,19,23,29,30,32,33,34,35],choleski:[5,23,30],choos:[2,3,6,9,10,11,13,14,24,32,33,34,35],chosen:[0,1,2,6,8,9,10,13,16,21,26,29,32,33,34,35,36],chosen_datapoint:1,christian:28,christoph:[25,28,29],cifar10:3,cifar:3,circ:[1,12,36],circl:[0,8,12,30,35,36],circuit:3,circumfer:9,circumv:[1,5,13,30,34,35,36],cite:24,ckpt:4,clariti:26,class_nam:[3,9],class_val:9,class_valu:9,classic:[7,9,13,33,34,35,36],classif:[0,3,5,6,7,8,11,12,22,24,28,29,30,31,32,34,36],classifi:[0,1,4,7,9,10,11,29],classificaton:1,classifii:10,clean:1,clear:[1,5,10,12,13,21,34,35],clearli:[0,3,5,6,7,8,18,26,30,31,32,33],clever:[1,10],clf3:0,clf:[0,6,8,9,10,29,30],clf_lasso:6,clf_ridg:[6,29],clip:[3,26],clone:27,close:[0,1,2,4,6,8,9,11,12,13,14,24,26,28,29,32,33,34,35,36],closer:[3,5,13,30,34,35],closest:[8,11,13,14,34],closur:[22,29],cloud:[22,29],cluster:[0,1,4,6,11,22,29,32],cluster_label:14,cm:[1,2,3,6,8,9,13,24,33,34],cmap:[0,1,2,3,4,6,8,9,10,24,29],cmap_arg:6,cmb:25,cmd:9,cn_:26,cnn:[12,35,36],cnn_kera:3,cntk:[22,29],co:[0,2,3,6,9,13,21,29,32,34,35],code:[3,4,6,7,8,15,16,17,19,22,23,24,26,28],coef0:8,coef:[0,29],coef_:[0,5,6,8,9,13,29,30,31,33,34],coeff:5,coeffici:[0,3,5,6,7,8,9,13,15,16,23,29,30,31,32,33,34,35],coerc:[0,6,29,32],coin:[10,26],coin_toss:10,col:[0,11,29,30],colab:[22,29],cold:9,colinear:0,collabor:24,collaps:8,collect:[0,2,6,10,11,21,22,26,28,29,32,35,36],collinear:[5,30,31],color:[0,3,4,6,8,9,10,21,24,26,34,35],color_channel:3,color_cod:6,colorbar:[1,6,24],colsample_bytre:10,colsaobject:10,column:[0,1,2,5,6,7,8,9,11,12,17,23,29,30,31,32,33,35,36],columntransform:9,com:[4,6,16,20,21,22,24,28,29,32,33,34,35,36],combin:[1,2,5,6,7,10,26,31,32,33,34,35,36],come:[0,1,3,4,5,12,13,14,15,29,30,31,32,34,35,36],command:[0,1,29],comment:[0,4,5,6,15,16,24,29,30],commerci:[0,15,22,24,29],commod:[0,29],common:[0,1,3,5,6,7,9,11,13,14,24,26,29,30,32,33,34,35,36],commonli:[0,1,4,6,7,9,13,14,30,32,33,34,35],commun:[0,12,24,35,36],commut:3,commutatitav:3,compact:[0,1,3,5,6,7,9,11,12,13,14,29,30,31,32,34,35],compair:0,compar:[0,3,4,5,6,11,13,15,16,21,23,24,29,30,31,32,33,34,35,36],comparison:[2,4,13,34,35],compat:[7,33],compet:0,competit:10,compil:[0,1,3,4,13,15,21,22,23,29,34,35],complet:[0,2,3,4,9,12,29,35],completenn:[12,35],complex:[1,5,8,9,11,12,13,15,16,19,29,32,34,35,36],complic:[0,1,9,13,29,32,33],compoment:30,compon:[0,1,3,4,5,6,7,9,14,16,22,29,30,31,32,33,36],components_:11,compos:[9,12,13,14,21,22,29,34,35,36],compphys:[0,6,16,17,19,20,22,24,25,27,28,29,33,34,35],compress:[0,29,30],compris:[6,33],compromis:[5,30],compulsori:[22,29],comput:[0,1,2,3,4,5,6,7,8,10,11,12,13,15,16,17,21,22,23,24,25,26,28,29,30,31,32,33,36],computation:[0,3,6,9,13,26,29,33,34,35,36],computationalscienceuio:29,computerlab:24,concaten:[2,4,6,14],concatenate_arg:[],concav:[1,9,13,30,33,34],concentr:[0,10],concept:[0,2,22,29,30],conceptu:[12,13,33,34,35,36],concern:[0,1,4,7,29,33],concic:29,conclud:[0,5,13,21,31,32,34,35],conclus:1,cond:2,conda:[0,1,15,22,24,29],condis:30,condit:[0,2,4,5,6,8,9,11,13,26,29,30,35],conduct:22,condwav:2,confid:[0,5,6,7,8,18,24,29,30,31,33],configur:[3,21,35],confirm:[5,12,31,32,35],confus:[5,6,7,10,23,30,31,32],confusion_matrix:9,congruenti:26,conjug:[4,8],conjugaci:[13,34],conjunct:3,connect:[0,1,3,4,9,11,12,13,23,29,30,33,34,35,36],consequ:[5,6,8,10,12,13,30,31,32,33,34,35],conserv:[5,14,30],consid:[0,1,2,3,5,6,7,8,9,10,12,13,16,19,21,23,24,26,29,30,31,32,33,34,35,36],consider:[0,1,5,13,29,30,31,32,33,34],consist:[0,1,2,3,4,6,12,13,19,21,24,26,30,32,33,34,35,36],constant:[0,2,4,5,6,8,12,13,26,29,30,31,32,33,34,35,36],constitu:[0,29],constitut:[2,6,32,33],constrain:[1,3,5,7,11,31,33],constraint:[5,6,8,13,30,31,32,34,35],construct:[0,1,2,3,5,6,7,8,9,10,11,23,26,29,30,31,32,33],contact:[0,29],contain:[0,2,3,4,5,6,7,8,9,11,12,13,17,19,21,23,24,26,28,29,30,31,32,33,34,35,36],contemporari:29,content:[1,22,23,29],context:[6,10,13,24,32,33,34,35,36],contextlib:[0,7,33],contigu:23,continu:[0,1,2,3,4,5,6,7,8,9,10,12,13,17,18,21,23,24,26,29,30,31,32,33,34,36],contour:[9,10,13,34],contourf:[8,9,10],contrast:[1,4,9,10,12,35,36],contribut:[0,3,5,13,21,26,29,30,31,34,35],contributor:[0,24],control:[0,1,3,9,13,15,22,29,34,35],conv2d:[3,4],conv2dtranspos:4,conv:[3,4],convei:29,conveni:[0,5,6,12,13,23,24,29,31,32,33,34,35],convent:[12,30],converg:[1,2,4,5,6,8,9,11,13,14,21,30,31,33,34,35,36],convergencewarn:[6,8,9,11],convert:[0,1,4,5,9,11,13,23,29,30,34,35],converttomatrix:4,convex:[4,5,7,30],convinc:[13,33,34],convolut:[1,4,22,29],cook:24,cool:[4,9],coolwarm:[6,24],coordin:[5,12,14,30,31,35],coorel:0,copi:[0,1,14,30],core:[0,2,7,10,29,33],corel:29,coronari:[7,33],corr:[0,5,7,11,30,33],correalt:[11,22],correct:[0,1,2,3,4,5,7,13,23,26,29,30,31,32,34,35],correctli:[1,2,6,7,10,24],correl:[0,1,3,5,6,7,10,12,13,21,22,26,29,31,32,34,35,36],correlation_matrix:[0,5,7,11,30,33],correspond:[0,3,5,6,8,9,11,12,15,16,17,22,23,24,26,29,30,31,32,35,36],cortex:[12,35,36],cosin:[3,6,32],cost:[0,2,3,5,6,7,8,9,12,13,16,17,19,21,24,29,35],cost_deep_grad:2,cost_funct:2,cost_function_deep:2,cost_function_deep_grad:2,cost_function_grad:2,cost_grad:2,cost_sum:2,costol:[13,21,34,35],could:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,17,23,24,26,29,30,31,32,33,34,35,36],coulomb:[0,29],count:[0,9,25,26,27,29],countor:[13,34],coupl:[4,5,6,31,32],cours:[0,1,3,5,11,24,25,27,30,32],courvil:[21,25,28,29,30,34,35],cov:[5,6,11,23,26,29,30,31,32],cov_xi:[5,11,30],cov_xx:[5,11,30],cov_yi:[5,11,30],covari:[0,7,22,23,29,31,33],covariance_matrix:[5,11,14,30],cover:[0,5,17,22,27,28,30,31],covert:[0,29],covxi:26,covxx:26,covxz:26,covyi:26,covyz:26,covzz:26,cpu:1,cqofi41lfdw:36,craft:3,creat:[1,2,3,4,5,9,10,11,12,22,29,31,33,34,35,36],create_biases_and_weight:1,create_convolutional_neural_network_kera:3,create_neural_network_kera:1,create_x:[5,11,30],credit:[0,7,27,29,33],crim:0,crime:0,criteria:[0,4,9,10,14,26,29],criterion:[9,10,13,33,34,36],critic:[6,24,30,31],critiqu:24,cross:[0,1,3,7,9,10,13,22,26,29,30,31,34,35,36],cross_entropi:4,cross_val_scor:[6,32,33],cross_valid:[7,10,33],crossvalid:[6,32],crucial:[1,26,36],cs231:3,cs:[25,27],csr_matrix:[23,29],csv:[0,4,6,7,9,29,32,33],ctnk:1,cube:36,cubic:0,cumbersom:[5,31,32],cumsum:[10,11,29],cumul:[7,10,26],cumulative_heads_ratio:10,cup:[5,31,32],current:[1,2,3,4,13,14,21,28,33,34,35,36],curs:[0,30],curv:[6,7,10,12,24,33,35,36],curvatur:[13,33,34,35],custom:[6,14,24],custom_cmap2:[9,10],custom_cmap:[9,10],cutpoint:9,cv:[6,7,10,32,33],cvxbook:[13,33],cvxopt:[5,8,30],cybenko:36,cycl:[1,12,35,36],cyclotron:31,d2_g_t:2,d:[1,2,3,4,5,6,7,8,9,10,11,13,14,23,26,27,29,30,31,32,33,34,35,36],d_f:[13,33,34],d_g_t:2,d_net_out:2,da:[3,36],dagger:[5,23,30],dai:[1,9,22],damp:3,daniel:27,darget:9,darkr:26,dat:[0,29],dat_id:[0,6,7,9,29,30,32,33],data1:14,data2:14,data3:14,data4:14,data:[2,4,5,8,10,12,13,14,17,18,19,21,23,28,32,34,35],data_id:[0,6,7,9,29,30,32,33],data_indic:1,data_panda:29,data_path:[0,6,7,9,29,30,32,33],databas:1,datafil:[0,6,7,9,24,29,30,32,33],datafram:[0,4,5,7,9,11,29,30,33],datapoint:[1,5,6,7,11,13,30,32,33,34,35],dataset:[0,4,6,7,8,9,10,11,13,14,15,16,19,24,29,32,33,34,35,36],datatyp:4,date:[15,16,17,18,19,20,21,24,29,30,31,32,33,34,35,36],daughter:10,david:[28,29],davison:32,db:36,dbh:1,dbo:1,dcomposit:23,ddot:2,dead:[1,36],deadlin:[16,17,18,19,20,21,25],deal:[0,1,3,5,6,8,11,13,14,17,18,23,24,26,29,30,31,33,34,35,36],dealt:0,debt:[7,33],debug:[0,5,6,31,32,33],decad:[0,3,35],decai:[0,13,26,29],decemb:[25,27,29],decent:10,decid:[0,2,3,5,6,9,24,31,32,33],decim:[0,29],decis:[0,1,8,11,22,28,29],decision_funct:8,decision_tre:9,decisiontreeclassifi:[9,10],decisiontreeregressor:[0,9,10],decisiontreeregressordecisiontreeregressor:9,declar:[0,4,23,29],decompos:[5,6,23,30,36],decomposit:[0,6,12,24,29,31,35,36],decompost:[5,30],deconvolut:3,decorrel:[10,13,21,34,35],decreas:[1,2,4,5,6,10,11,13,31,32,33,34,35],deduc:[0,29],deep:[3,7,12,13,21,22,25,28,30,34,35],deep_neural_network:2,deep_param:2,deep_tree_clf1:9,deep_tree_clf2:9,deep_tree_clf:[9,10],deepen:[5,22,29],deeper:[0,3,4,29],deeplearningbook:[28,29,31],deer:3,def:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,21,24,26,29,30,31,32,33,34,35,36],def_covari:26,default_tim:4,defect:[5,30],defici:[5,30],defin:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,30,31,32,33,34,35],definit:[1,2,5,6,7,8,10,11,12,13,17,23,26,30,31,32,33,34],defint:26,defvjp:2,defvjp_argnum:[],degre:[3,5,6,8,9,10,11,15,16,17,19,24,26,29,31,32,33],deisenroth:30,del:1,delet:6,delimit:4,deliv:[25,29],delta:[0,2,3,6,8,12,13,14,21,29,34,35,36],delta_0:[3,36],delta_1:[3,36],delta_2:[3,36],delta_2a_1:36,delta_3:3,delta_4:3,delta_5:3,delta_:[1,23,36],delta_h:[0,1,29],delta_i:36,delta_j:[3,12,36],delta_k:[12,36],delta_l:[1,3],delta_momentum:[13,21,34,35],delta_n:[0,3,29],delug:22,delv:0,demand:[13,33,34],demonstr:[0,3,5,6,7,11,12,22,29,30,31,32,33],demystifi:[35,36],den:4,denomin:[1,5,31,32],denot:[1,2,6,7,13,26,33,34,35],dens:[1,3,4],densiti:[0,2,6,26,29,32],depart:[27,29,30,31,32,33,34,35,36],depend:[0,1,2,4,5,6,7,8,11,12,13,15,21,22,23,24,26,29,30,31,32,33,34,35,36],depict:26,deploy:[0,15,22,24,29],deprec:2,depth:[0,3,9,10,23,32],deriv:[0,1,2,6,7,8,10,11,13,16,17,19,21,22,24,29,35],derivati:[13,34,35],derivative_fn:[13,34],derivb1:36,derivb2:36,derivw1:36,derivw2:36,descend:[5,9,11,30,31],descent:[0,1,3,7,8,12,29,30,36],descent_i:[21,35],descent_x:[21,35],describ:[0,2,4,5,6,8,10,11,12,13,18,21,23,24,29,31,32,34,35,36],descript:[0,8,9,29],design:[0,1,3,4,5,6,7,10,11,12,13,15,16,17,18,19,24,29,31,32,33,34,35,36],designmatrix:[0,29],desir:[0,2,4,5,13,14,29,30,33,34],despit:[1,12,35,36],destroi:23,det:[5,23,30],detail:[0,6,11,13,14,23,24,30,33,34],detect:[3,8,12,35,36],determin:[0,2,3,4,5,6,8,9,10,11,12,13,16,23,26,29,30,31,32,33,34,35,36],determinist:[7,13,26,33,34,35,36],deternin:36,dev:[1,24,36],develop:[0,3,5,8,10,11,12,21,22,23,24,29,30,31,32,35,36],deviat:[0,1,2,4,5,6,19,24,26,29,30,31,32,36],devic:[3,4,14],devis:[12,35,36],df1:29,df:[4,8,11,13,29,34,36],di:0,diag:[5,8,30,31],diagnost:[1,10,36],diagon:[0,5,7,13,18,21,23,24,26,29,30,31,33,34,35],diagonaliz:[5,30],diagram:10,diagsvd:6,dice:[6,26,32],dict:[6,8,33],dictionari:0,did:[0,1,5,6,7,10,11,14,24,29,31,32,33,34],die:[1,36],diff1:2,diff2:2,diff:[2,36],diff_ag:2,diffeent:8,differ:[0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,17,21,22,23,24,26,28,29,30,31,32,33,36],different:36,differenti:[0,3,16,21,22,23,29,30,33],differential_oper:2,difficult:[0,1,6,10,13,21,24,26,29,32,34,35,36],difficulti:[0,1,13,29,33,34,35,36],diffonedim:2,digit:[0,1,3,4,6,24,25,27,29],digress:36,dilemma:[13,34,35],dilut:[1,36],dim:[4,11,14,23],dimens:[0,1,2,3,4,5,8,9,11,14,16,17,23,29,30,31,36],dimension:[0,4,5,6,9,11,13,14,19,21,22,23,29,31,32,33,34,35],dimensionless:[0,3,29],diment:23,dimnsion:4,diod:3,direct:[0,1,2,4,7,11,12,13,14,21,29,30,33,34,35,36],directli:[1,4,5,6,26,30],directori:[0,7,33],disadvantag:[0,29],disappear:[3,6,32],disc_loss:4,disc_tap:4,discard:[6,11,32,33],disciplin:[0,3,12,35,36],disclaim:26,discontinu:36,discord:29,discourag:[13,33,34],discov:[0,29],discover:[5,31],discret:[1,3,5,7,13,31,32,33,34,35,36],discrimin:[4,7,10,11,33],discriminator_loss:4,discriminator_loss_list:4,discriminator_model:4,discriminator_optim:4,discuss:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,28,29,30,31,32,34,35,36],diseas:[7,33],disguis:[6,30,31],disord:[1,7,33],dispai:[35,36],displai:[0,1,3,4,5,6,7,8,9,10,11,12,14,24,26,29,30,32,33,35,36],displaystyl:[0,5,17,29,30,31],disregard:[0,29],dissimilar:[11,14],dist:14,distanc:[0,8,9,11,14,26],distance_list:9,distinct:[3,7,8,9,10,14,33],distinctli:8,distinguish:[0,4,7,8,26,29,33],distplot:0,distribut:[0,1,4,6,7,10,11,13,14,15,16,18,19,22,23,24,29,30,33,34,36],distrubut:[0,15,22,24,29],dive:[0,8,23,29],diverg:[1,13,33,34,35,36],divid:[0,1,3,5,6,7,8,9,11,12,26,29,30,31,32,33,35,36],divis:[6,8,9,13,21,23,26,32,33,34,35,36],dlopen:[3,4,14],dna:[7,33],dnn1:4,dnn2_gru2:4,dnn:[0,1,2,4,12,29,35,36],dnn_kera:1,dnn_model:1,dnn_numpi:1,dnn_scikit:[0,1,29],doamin:[31,32],doc:[0,6,16,17,19,20,22,24,25,27,28,29,33,34,35],document:[4,9,11,13,33],doe:[0,1,2,3,4,5,6,8,10,11,12,13,14,16,21,23,24,26,29,32,33,34],doesn:[3,9,12,36],dog:[1,3,4],domain:[5,8,13,24,31,32,33,34],domin:[0,29],don:[0,1,3,5,6,7,8,11,13,15,21,22,24,29,30,33,34,35,36],done:[0,2,3,4,5,6,9,10,11,13,17,23,24,29,30,31,32,33,34,36],dot:[0,2,3,5,6,7,8,9,10,11,12,13,21,23,24,26,29,30,31,32,33,35,36],doubl:[3,4,23,29],doubli:[1,36],doubt:24,down:[0,3,6,9,11,12,13,21,33,34,35],download:[0,1,3,5,6,23,24,28,29],downsampl:3,dozen:[1,36],dq:[6,32],drag:[13,34,35],dramat:11,drastic:4,draw:[4,6,10,13,32,33,34],drawback:[0,1,3,13,30,33,34,35,36],drawn:[1,4,6,7,11,26,29,32,33,36],drive:[3,4],driven:3,drop:[0,1,5,6,11,13,21,26,29,30,31,32,34,35,36],dropna:[0,6,29,32],dropout:4,dt:[2,3,13,26,34,35,36],dtype:[0,1,2,3,4,14,21,23,29,30,35,36],dual:8,dualiti:6,dub:[0,29],due:[1,2,5,6,8,10,12,13,27,29,30,32,33,34,35,36],dummi:0,dure:[0,1,3,4,8,9,11,17,20,22,24,29,32,34,35,36],dwell:0,dwh:1,dwo:1,dx:[2,3,8,26,36],dx_1:26,dx_1p:[6,32],dx_2p:[6,32],dx_mp:[6,32],dx_n:26,dxp:[6,32],dy:[1,8,26,36],dylib:[3,4,14],dynam:4,dz:8,e:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,18,19,21,26,27,29,30,31,32,33,34,35,36],e_:[0,2,29],each:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,21,22,23,25,26,27,29,30,31,32,34,35,36],eager:32,eapprox:[0,29],earli:[1,13,21,34,35],earlier:[0,5,7,8,9,11,12,13,20,21,29,30,33,34,35,36],earthexplor:[6,24],eas:[6,9,14,32],easi:[0,5,6,7,8,9,10,11,12,13,18,21,22,23,29,30,31,32,33,34,35,36],easier:[5,6,8,9,13,26,29,30,32,34,35],easiest:[13,33,34],easili:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,23,24,29,30,31,32,33,34,36],eastern:[27,29],ebind:[0,29],eblock:9,econometr:29,economi:5,ecosystem:[22,29],ect:25,edg:3,edgecolor:[6,32],edu:[13,33],educ:[0,24,29,33],eff:26,effect:[1,4,10,13,26,34,35,36],effic:1,effici:[0,3,10,13,22,23,26,29,33,34,35,36],efron:[6,32],egrad:[13,34,35],eig:[5,11,13,21,23,26,29,30,33,34,35],eigen:26,eigenpair:[5,11,30],eigenvalu:[0,5,8,11,13,21,23,29,30,31,33,34,35],eigenvector:[5,11,13,17,30,31,34],eight:[23,29],eigval:[23,26,29],eigvalu:[11,13,21,33,34,35],eigvec:[23,26,29],eigvector:[11,13,21,33,34,35],eispack:[23,29],either:[1,5,6,7,8,9,10,11,13,15,16,24,26,29,30,31,32,33,34,36],elabor:26,elarn:3,electr:[0,3,12,29,35,36],electron:29,eleg:11,element:[1,2,3,4,5,6,7,8,11,12,13,17,18,20,21,22,23,24,25,28,30,31,32,33,36],elementari:[10,13,23,34,35,36],elementwis:[3,13,34,35],elementwise_grad:[2,13,34,35],elessar:29,elif:[2,14,21,35],elim:23,elimin:[3,8],els:[1,2,3,4,7,9,12,13,14,23,33,34,35,36],elu:1,elus:[0,29],email:[25,27,29],embark:36,embed:[0,11,30],embodi:[6,19,24,32],emit:26,emner:28,emphas:[0,10,22,29],emphasi:[0,22,28,29],empir:[1,11,26,36],emploi:[0,1,5,6,11,13,24,26,29,30,31,32,33,34],employ:0,empti:[6,10,32],emul:[12,35,36],en:[22,28],enabl:[11,21,35],enbodi:[6,32],encod:[0,3,5,7,9,11,14,17,29,30,31,33],encompass:[0,24,26],encount:[0,1,5,6,7,13,21,26,29,30,32,33,34,35,36],encourag:24,end:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,21,23,24,26,27,29,30,31,32,33,34,35,36],end_box:[],end_nod:2,end_valu:[],endpoint:[3,6],energi:[0,4,6,30,32],enet_coordinate_desc:6,enforc:[12,35,36],eng:28,engin:[0,1,3,4,22,29,36],english:24,enocurag:24,enoent:[3,4,14],enorm:3,enough:[0,6,13,29,32,33,34],ensembl:[1,9,36],ensur:[0,1,2,3,5,6,11,13,21,26,30,31,32,33,34,35,36],entail:29,enter:[5,6,17,30,31],enthought:[0,15,22,24,29],entir:[1,3,7,9,22,26,29,33,34,35,36],entiti:[9,12,23,29],entri:[0,5,8,11,12,23,29,30,31,32],entropi:[1,3,7,10,13,29,34,35],enumer:[0,1,2,3,4,6,8,29,30,31],env:[0,2,3,4,6,7,8,9,11,14,21,26,29,31,33,35],environ:[2,9,21,22,24,35],eo:[0,6,29,32],eol:[0,29],eosfit:[0,29],epoch:[0,1,3,4,12,13,21,29,34,35],epsilon:[0,5,6,7,13,19,24,29,30,31,32,33,34,35,36],epsilon_0:[0,29],epsilon_1:[0,29],epsilon_2:[0,29],epsilon_:[0,29],epsilon_i:[0,29,30],eq:[3,13,14,23,26,33,34],eqnarrai:[3,5,6,31,32],equal:[0,1,2,3,4,5,6,8,9,11,12,13,14,15,23,24,26,29,30,31,32,33,34,35,36],equat:[1,3,4,5,6,7,8,9,10,11,13,14,16,17,18,19,21,23,24,26,32,35],equilibrium:[2,12,35,36],equiv:[3,13,23,26,33,34],equival:[0,1,5,7,8,11,13,21,22,23,29,30,31,32,34,35],erf:26,eriador:29,eridg:29,err:[0,7,10,33],err_:[6,32],err_sqr:2,errat:[13,33,34],errno:[0,3,4,7,14,33],erron:2,error:[1,2,4,5,6,7,9,11,12,13,15,16,17,18,19,21,22,23,24,26,31,33,34,35,36],error_estimate_corr_tim:26,error_hidden:1,error_output:1,escap:[13,33,34,35],especi:[1,3,9,12,13,24,34,35,36],essenti:[0,5,6,9,10,12,14,24,26,30,35,36],establish:[0,6,10,11,15,24,29],estim:[0,1,5,6,7,10,11,13,22,26,29,30,33,34,35,36],estimated_mse_fold:[6,32,33],estimated_mse_kfold:[6,32,33],estimated_mse_sklearn:[6,32,33],et:[0,2,4,15,16,17,24,28,29,30,31,32,33,34,36],eta0:[8,13,33,34],eta:[0,1,3,8,12,13,21,29,33,34,35,36],eta_:[13,21,34,35],eta_t:[13,34,35],eta_v:[0,1,3,29],etc:[0,1,3,5,7,8,9,11,12,13,14,15,21,22,23,24,26,30,33,34,35],ethic:22,etsim:32,euclidean:[0,14,30],evalu:[0,2,3,4,5,6,9,13,24,26,29,30,31,32,33,34,35],evaluationform:[20,24,34,35],evaluationgrad:[20,24,34,35],evalut:[13,34,35],even:[0,1,3,4,5,6,8,9,10,11,12,13,14,22,23,26,29,30,31,32,33,34,35,36],evenli:4,event:[5,7,10,26,31,32,33],eventu:[0,5,6,11,12,13,24,27,30,31,32,33,34,35,36],everi:[0,1,2,3,4,5,6,9,10,11,12,13,14,22,26,27,29,30,31,32,33,34,35,36],everyth:[4,12,21,36],everywher:[4,13,33,34],evolv:0,exact:[0,5,11,12,13,23,26,29,30,34,36],exactli:[0,3,4,6,12,22,24,30,32,35,36],exam:29,examin:[6,32],exampl:[5,11,12,13,15,16,19,20,22,23,24,26,28],exce:[1,12,13,21,34,35,36],excel:[0,1,4,5,10,29,30,36],except:[0,3,4,6,7,8,9,23,33],excess:[0,29],excit:0,exclud:[1,6,12,24,30,31,32,33,35,36],exclus:[0,1,3,6,26,29,32,33,36],execut:[2,5,13,30,34,35],exemplifi:[13,34,35],exercic:[27,29],exercis:[5,22,24,25,27,31,32,33,34,35],exercisesweek35:17,exhaust:[6,32,33],exhibit:[0,5,6,8,29,30,32],exist:[0,1,2,3,4,5,6,7,8,9,13,14,18,23,24,29,30,31,32,33,34,36],exit:[5,23,30],exp:[0,1,2,5,6,7,8,10,11,12,13,15,16,21,24,26,29,30,31,32,33,34,35,36],exp_term:1,expand:[5,7,11,13,30,33,34],expandus:[0,7,33],expans:[0,3,5,8,10,12,13,29,30,33,34,36],expect:[0,1,5,6,7,11,12,13,15,16,19,21,22,24,29,30,33,34,35,36],expectation_value_of_h_wrt_p:26,expens:[6,10,13,33,34,35],experi:[0,1,6,8,13,22,24,29,30,32,33,34,35],experiment:[0,4,6,9,26,29,32],expert:[1,9,36],explain:[0,6,9,10,11,13,19,24,29,33,34],explained_variance_ratio_:11,explanatori:[0,29],explicit:[0,3,6,13,21,23,24,29,30,31,34,35],explicitli:[0,4,8,21,35],explod:1,exploit:[0,3,12,13,29,34,35,36],explor:[1,4,6,8,13,22,24,33,34,35,36],expon:1,exponenti:[0,1,5,6,10,13,24,26,29,31,32,33,34,35,36],export_graphviz:9,export_text:9,exporttext:9,expos:22,expr:36,express:[0,2,3,5,6,7,10,12,13,16,21,23,24,26,29,31,32,35],exptmean:26,exptvari:26,extend:[0,2,7,11,13,17,22,29],extens:[0,12,15,22,29,35,36],extent:[0,1,6,28,32],extern:[3,6,9],extra:[1,3,5,27,29,30],extract:[0,3,5,6,7,8,11,13,23,29,30,33,34,36],extrapol:[0,29],extrem:[0,1,4,5,6,7,8,9,13,16,23,30,31,32,33,34,35,36],extremum:[13,33,34],extrins:11,ey:[0,5,6,13,14,23,29,31,33,34,35],f11:[0,29],f12:[0,29],f13:[0,29],f1:[13,34,35],f1_grad:[13,34,35],f1d:[13,34],f2:[13,34,35],f2_grad_x1:[13,34,35],f2_grad_x1_analyt:[13,34,35],f2_grad_x2:[13,34,35],f2_grad_x2_analyt:[13,34,35],f3:[13,34,35],f3_grad:[13,34,35],f3_grad_analyt:[13,34,35],f4:[13,34,35],f4_grad:[13,34,35],f4_grad_analyt:[13,34,35],f5:[13,34,35],f5_grad:[13,34,35],f6:[13,34,35],f6_for:[13,34,35],f6_for_grad:[13,34,35],f6_grad_analyt:[13,34,35],f6_while:[13,34,35],f6_while_grad:[13,34,35],f7:[13,34,35],f7_grad:[13,34,35],f7_grad_analyt:[13,34,35],f8:[13,34],f8_grad:[13,34],f9:[0,13,29,34],f9_altern:[13,34],f9_alternative_grad:[13,34],f9_grad:[13,34],f:[0,1,2,3,4,5,6,7,8,10,12,13,14,16,18,19,21,23,26,27,29,30,31,32,33,34,35,36],f_0:[3,10],f_1:[10,13,33,34],f_2:[12,13,33,34,35],f_3:[12,35],f_:10,f_d:26,f_grad:[13,34,35],f_grad_analyt:[13,34,35],f_i:[0,6,12,16,32,35],f_m:[3,10],f_n:3,f_raw:2,f_vec:2,f_wrap:2,face:[13,33,34,35],facecolor:[6,8,26,32],facil:[0,15,22,29,33,34,35],facilit:[12,35,36],fact:[0,1,3,5,9,11,12,13,29,30,31,32,33,34,35,36],factor:[0,1,3,5,6,9,10,11,13,23,26,29,30,31,32,34,35],factori:[13,34,35],fade:6,fafab0:[9,10],fahimeh:[27,29],fail:[0,6,8,9,11,13,27,29,32,33,34,36],fail_on_error:[0,7,33],failur:[7,33],fairli:[1,2,26,36],faisal:[16,30],fake:4,fake_loss:4,fake_output:4,fall:[8,9,25],fals:[0,1,2,3,4,5,6,7,9,10,14,23,24,29,30,31,32,33,34,35],famili:[0,7,8,26,33],familiar:[0,3,5,6,8,15,22,23,24,26,29,31,32,36],famou:[6,12],far:[0,3,4,5,6,8,11,12,13,14,29,30,33,34,35,36],fashion:[0,9,10,29],fast:[1,3,6,10,12,13,22,26,29,32,33,34,36],faster:[1,11,13,34,35,36],fastest:[13,23,33,34],favor:[7,33],favorit:26,fc:3,fd:[0,7,33],featur:[0,1,3,5,6,7,8,10,11,12,13,18,22,24,26,29,31,32,33,34,35,36],feature_nam:[0,1,7,9,33],feautur:9,fed:[1,36],feed:[0,2,3,11,22,29],feed_forward:1,feed_forward_out:1,feed_forward_train:1,feedback:[4,20,29],feeddorward:4,feedforward:[1,4,12,36],feel:[0,5,6,11,13,15,16,21,22,24,27,29,31,34,35,36],feet:0,felt:24,fetch:[6,24],few:[1,3,4,5,9,26,29,34,36],fewer:[0,9,11,29],ffnn:[1,12,35,36],field:[0,3,6,12,22,35,36],fifteen:36,fifth:[0,6,15,16,24,29],fig:[0,1,2,3,4,6,7,12,13,14,24,29,33,34,35,36],fig_id:[0,6,7,9,29,30,32,33],figaxi:26,figsiz:[0,1,2,3,4,6,7,8,9,10,29,32,33],figur:[0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,21,22,24,29,30,31,32,33,34,35,36],figure_id:[0,6,7,9,29,30,32,33],figurefil:[0,6,7,9,29,30,32,33],file:[0,2,3,4,5,6,7,9,14,24,29,30,31,32,33],file_prefix:4,filenam:29,filenotfounderror:[0,7,33],fill:[5,9,30],filter:[0,3,4,7,33],financ:0,find:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,21,22,24,26,29,30,31,33,35,36],fine:[0,14,15,29],finish:2,finit:[3,5,6,12,13,17,26,30,31,32,34,35,36],first:[0,1,2,3,5,6,7,8,9,10,11,13,14,15,16,17,21,23,24,26,27,28,32,35],first_moment:[21,34,35],first_term:[21,34,35],firsteigvector:11,fit:[1,3,4,5,6,7,8,9,11,12,13,15,16,17,21,24,26,30,32,33,34,35,36],fit_beta:[6,30,31],fit_intercept:[0,5,6,30,31,32],fit_mod:9,fit_transform:[0,6,8,9,11,32,33],fiti:[0,29],five:[0,9,17,24,29,30,33,36],fix:[0,3,4,6,10,11,12,13,21,24,29,32,33,34,35],fixedloc:6,flag:4,flat:[3,4,12,13,14,21,33,34,35],flatten:[1,3,4,5,23],flexibl:[1,6,8,10,12,29,32,35,36],flip:[27,29],float32:[4,9,21,35],float64:[4,21,23,29,30,35,36],floor:[],flop:[5,23,30],flow:[1,4,12,35,36],fluctuat:[5,31],fly:11,fm:[0,29],fmax:3,fmesh:[13,34],fn:7,fname:[0,7,33],focu:[0,3,4,5,6,15,22,28,29,30,31,32],focus:[1,6,7,23,30,31,33],fold:[6,9,24],folder:[0,1,3,4,6,14,24,29,32],follow:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],font:[0,7,26,29,33],fontdict:26,fontsiz:[1,6,8,9,10,26],fontweight:1,footprint:3,foral:[8,30,36],forc:[0,5,6,10,11,29,30,31,33,36],forcast:4,forecast:[4,12,35,36],forest:[0,1,9,22,29,36],forget:11,form:[0,3,4,5,6,7,8,9,11,12,13,17,21,22,23,24,26,29,30,31,32,33,34,35,36],formal:[3,4,14,26,36],format:[0,1,2,3,4,6,7,8,9,10,11,22,26,28,30,31,32,33,35,36],format_data:4,formatstrformatt:[6,13,24,33,34],formul:[4,6,11,14],formula:[3,13,26,33,34,35,36],forth:[4,12,35],fortran2003:[22,29],fortran2008:24,fortran90:26,fortran:[0,15,22,23,29],fortun:[0,11,30],forward:[0,3,6,22,23,29,32],forwardpropag:36,foster:29,found:[1,2,3,4,5,6,12,13,14,19,20,24,29,30,31,32,34,35,36],foundat:[22,29],four:[4,5,6,8,12,23,24,25,27,29,31,35,36],fourier:[0,29,36],fourierdef1:3,fourierdef2:3,fourierseriessign:3,fourth:[12,29,30],fp:7,frac:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,19,23,24,26,29,30,31,32,33,34,35,36],fractal:9,fraction:9,frame:[7,33],framework:[1,3,4,8,10,14,26],frank:[5,11,21],frankefunct:[5,6,11,24,30],fredli:[27,29],free:[0,6,11,13,15,16,21,22,23,24,26,27,28,29,34,35,36],freecodecamp:22,freedom:[5,31],freeli:[0,24],frequenc:[3,6,7,26,32,33],frequent:[0,8,9,13,33,34,35],frequentist:22,fresh:10,fridai:[16,17,18,19,20,21,27,29],friedman:[6,18,24,25,28,29],friendli:4,frodo:29,frog:3,from:[0,1,2,3,4,6,7,8,9,11,13,14,16,17,18,19,22,23,24,26,27,28,29],from_cod:9,from_logit:[3,4],from_tensor_slic:4,fromnumer:2,front:[0,4,5,15,16,29,30,31],fulfil:[2,5,12,30,35,36],full:[0,1,3,5,7,9,10,13,26,29,30,33,34,35],full_matric:[5,30],fulli:[3,6,12,25,26,32,33,35,36],fun:[2,22,29],fun_nam:[],func:2,functionali:11,fundament:[0,6,22,29,32],funtion:2,furthemor:36,further:[2,7,9,29,36],furthermor:[0,3,5,6,7,11,12,13,17,22,24,29,30,31,32,33,34,35,36],futur:[0,4,8,9,29],futurewarn:8,fy:[15,24,25,27,28,29],fys4155:24,fys5419:[28,29],fys5429:[28,29],g0:2,g:[0,1,2,3,4,6,8,9,10,11,13,26,29,31,32,33,34,35,36],g_0:2,g_1:[2,10],g_2:[2,10],g_3:36,g_:[2,9,10],g_analyt:2,g_dnn_ag:2,g_euler:2,g_i:[2,36],g_j:36,g_m:[3,10],g_n:3,g_re:2,g_t:2,g_t_d2t:2,g_t_d2x:2,g_t_dt:2,g_t_hessian:2,g_t_hessian_func:2,g_t_jacobian:2,g_t_jacobian_func:2,g_trial:2,g_trial_deep:2,g_vec:2,gain:[1,5,7,9,10,13,30,31,32,34,35],galleri:[0,29],game:4,gamge:29,gamma1:8,gamma2:8,gamma:[0,2,8,9,10,11,13,21,29,33,34,35],gamma_0:10,gamma_1:10,gamma_1x:10,gamma_:[0,29],gamma_i:[0,8,26,29],gamma_j:[13,34,35],gamma_k:[13,33,34],gamma_m:10,gamma_x:[0,29],gap:[6,8],gate:[4,12],gather:[0,1,12,30,35,36],gaug:[12,35,36],gaussbacksub:23,gaussian:[4,5,6,8,14,26,31,32],gaussian_point:14,gaussian_rbf:8,gave:[13,34,35],gavra:29,gbc:[25,29],gca:[2,6,8,13],gd:[1,33,36],gd_clf:10,gdclassiffiercgain:10,gdclassiffierconfus:10,gdclassiffierroc:10,gdfit:35,gdm:[13,21,34,35],gdregress:10,ge:[1,5,7,26,30,33,36],gen:[0,7,33],gen_loss:4,gen_tap:4,gender:[0,29],genener:4,gener:[0,1,2,3,5,6,8,10,11,12,13,14,15,16,17,19,20,21,23,24,26,28,30,31,32,33,34,35],generallay:[12,35],generate_and_save_imag:4,generate_imag:4,generate_latent_point:4,generate_simple_clustering_dataset:14,generated_imag:4,generator_loss:4,generator_loss_list:4,generator_model:4,generator_optim:4,genom:22,geodes:11,geometr:[0,13,29],geometri:[5,31,32],georg:28,geotif:[6,24],geq:[2,5,8,9,13,30,31,33,34],geron:[0,15,21,25,28,29,34,35],get:[0,1,2,3,4,5,6,7,9,10,11,13,15,20,22,23,24,26,27,29,30,31,32,33,34],get_dummi:9,get_paramet:2,get_split:9,get_yaxi:8,get_yticklabel:6,getattr:[],gg:29,gibb:[22,29],gif:4,gini:10,gini_index:9,ginvers:13,git:[0,15,22,29],giter:[13,21,34,35],github:[0,6,9,15,16,17,19,20,21,22,24,25,27,28,29,30,33,34,35,36],gitlab:[0,15,22,24,29],gitta:36,give:[0,1,2,3,5,6,7,8,9,10,12,13,14,17,22,24,26,29,30,31,32,33,34,35,36],given:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,23,24,26,29,30,31,32,33,34,35,36],global:[6,7,13,24,33,34,35],glorot:1,gnew:13,go:[0,1,3,5,6,8,9,11,12,13,24,29,30,31,32,33,34,36],goal:[0,7,9,29,33],goe:[0,1,2,5,6,13,14,18,23,29,30,31,32,33,34,35],golden:[13,34],gone:[5,30,31],gong:1,good:[1,3,4,5,6,9,10,11,13,17,21,22,26,28,30,31,32,33,34,35,36],goodfellow:[4,25,28,29,30,31,33,34,36],googl:[1,4,21,22,29,35],got:[1,6,13,24],gotcha:[21,35],gotten:29,gov:[6,24],gp:28,gpu:[1,13,21,22,29,34,35],grad:[2,13,21,34,35],grad_analyt:[13,34,35],grad_concatenate_arg:[],grade:[24,25],gradient:[0,3,4,7,8,9,12,22,29,30],gradient_desc:[21,34,35],gradientboostingclassifi:10,gradientboostingregressor:10,gradients_of_discrimin:4,gradients_of_gener:4,gradienttap:4,gradual:[1,14,36],grai:[4,6,24],graph:[1,9,11,12,13,33,34,35,36],graph_from_dot_data:9,graphic:[0,1,9,29],grasp:0,gray_r:[1,3],grayscal:3,great:[5,13,33,34,36],greater:[1,7,26,33,36],greatli:[13,34,35],greedi:[9,33],green:[0,3,9,26],grei:4,grid:[1,3,6,7,8,12,26,30,31,32,35,36],gridsearch:33,gridsearchcv:33,groh:36,grossli:[13,33,34],ground:[0,29],group:[0,6,7,9,14,22,24,25,27,29,32],groupbi:[0,29],grow:[1,3,9,10,36],growth:[0,29],gru:4,guarante:[0,4,13,26,29,30,33,34],guess:[1,4,10,13,14,21,33,34,35],guestrin:10,guid:1,guidanc:24,guidelin:[20,34,35],h1:2,h:[0,1,5,6,8,13,16,18,21,24,26,27,28,29,30,33,34,35],h_1:[2,13,33,34],h_2:[2,13,33,34],h_:[0,13,29,33,34],h_m:10,ha:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,21,23,24,26,29,30,31,32,33,34,35,36],haa:27,habit:[0,30],had:[0,1,6,7,13,29,32,33,34,36],hadamard:[1,12,13,21,34,35,36],half:[1,8,9,36],halv:10,hand:[0,1,2,3,5,11,12,13,15,22,23,24,25,26,27,28,29,30,31,32,33,34,35],handi:[3,24],handl:[0,1,2,5,9,11,22,31,36],handle_unknown:9,handsid:[12,36],handwrit:[12,35,36],handwritten:[1,5],handwrittennot:[33,35],happen:[1,2,3,4,5,6,10,13,26,30,34,35,36],hard:[1,7,8,10,13,33,34,36],hardcopi:[22,29],harder:[0,1,30,36],harmon:3,hasn:[],hassl:[0,15,22,29],hast:[22,29],hasti:[0,6,15,16,17,18,24,25,28,29,30,32,33],hat:[0,1,5,6,7,9,10,11,12,13,17,18,23,24,30,31,32,34,35,36],have:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23,24,26,27,29,30,31,32,33,34,35,36],haven:1,he:[7,33],head:[0,4,10,26],header:[0,29],heads_proba:10,health:[0,30],hear:[0,13,29,34,35],heart:[0,7,29,33],heatmap:[0,1,3,7,29,33],heavili:0,heavisid:1,height:[1,3,6,30,31],held:[13,21,34,35],help:[0,1,4,12,13,16,21,24,29,34,35,36],helper:[4,14],henc:[0,5,6,8,9,10,12,13,18,24,29,30,31,32,33,34,35],henrik:[27,29],her:[7,33],here:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,26,29,30,31,32,33,34,35,36],hereaft:[0,8,12,29],hermitian:23,hessenberg:23,hessian:[0,2,5,13,16,21,31,35],heterogen:[9,10],hi:[7,33],hidden:[1,3,4,12,35],hidden_bia:1,hidden_bias_gradi:[1,36],hidden_layer_s:[0,1,29],hidden_neuron:4,hidden_weight:1,hidden_weights_gradi:[1,36],hierarch:[5,30,31],high:[0,1,2,3,4,5,6,9,10,11,13,14,21,22,23,24,29,30,32,33,34,35,36],higher:[0,1,3,5,6,8,13,21,24,29,30,31,32,33,34,35],highest:[1,2],highli:[0,3,4,10,18,22,23,28,29,30,31,32],highwai:0,hing:8,hint:[13,16,30,31,33,34],hip:22,hire:0,hist:[4,6,7,26,32,33],histogram:[0,6,7,26,33],histor:[7,11,33],histori:[3,4,12,35,36],hitherto:[5,31],hjorth:[27,29,30,31,32,33,34,35,36],hobbi:26,hoc:[5,30],hoff:28,hold:[1,3,6,13,14,21,32,33,34,35],holder:[0,29],holomorphic_grad:2,home:0,homepag:[24,29],homework:[6,13],homogen:[1,3,9,10,13,21,34,35],honchar:2,hopefulli:[0,11,26,29,35],horizont:11,hornik:36,hors:[3,7,33],hot:[1,9],hour:[1,22,25,26,27,29],how:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,21,22,23,24,26,29,30,31,32,34,35,36],howev:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,22,23,24,26,29,30,31,32,33,34,35,36],hspace:[0,4,8,10,26,29,36],hstack:1,htf:[25,29],html:[0,9,11,17,19,22,24,25,27,28,29,31,36],http:[0,3,4,6,9,11,13,16,17,19,20,21,22,23,24,25,27,28,29,30,31,32,33,34,35,36],huang:[0,29],huber:[0,29],huge:[1,3,4,22,36],human:[0,1,3,6,9,12,30,31,35,36],humid:9,hundr:[1,36],hungri:[1,36],huse:29,hvae:35,hybrid:25,hydrogen:[0,29],hyper:21,hyperbol:[1,4,12],hyperparam:8,hyperparamat:36,hyperparamet:[3,4,5,6,9,13,17,29,30,31,33,34,35],hyperplan:11,i0:[0,29],i1:[0,6,8,12,29,30,31,35],i2:[0,8,12,29,35],i3:[0,12,29,35],i5:[0,29],i:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,27,29,30,31,32,33,34,35,36],i_1:[5,6,31,32],i_2:[5,6,31,32],i_:[13,33,34],ian:28,ic:1,id:[7,13,33,34,35],ida:[27,29],idea:[0,1,2,3,4,6,9,10,12,13,23,24,30,31,32,33,34,35,36],ideal:[0,2,6,8,13,26,29,32,35],idem:[6,32],ident:[5,6,12,13,17,23,24,30,34,35],identical:[31,32],identifi:[0,1,7,9,11,12,13,14,29,30,33,34,35],ieor:26,ifi:28,ifs:[22,29],ignor:[0,1,3,9,30,36],ii:[23,26],iii:[23,29],ij:[0,1,3,6,8,12,14,16,18,23,24,26,29,30,31,35,36],ik:[0,23,29,30],ilg3ggewq5u:36,illustr:[5,7,10,12,13,14,22,29,32,33,34],ilsvrc:[34,35],im:6,imag:[1,3,4,6,9,11,12,14,28,29,35,36],image_at_epoch_:4,image_batch:4,image_height:3,image_path:[0,6,7,9,29,30,32,33],image_width:3,imageio:[6,24],images_from_seed_imag:4,imagin:[1,36],immedi:[0,3,4,6,15,22,29],implement:[0,2,3,4,5,6,8,9,10,11,12,13,14,17,21,24,26,29,30,31,33,34,36],impli:[3,5,6,7,13,23,30,31,32,33,34],implicit:3,implicitli:[11,26],importantli:3,impos:[0,6,11,12,29,35,36],imposs:[0,5,29,30],impress:[0,12,29,35,36],improv:[0,4,5,9,10,11,13,21,24,30,35],impur:9,imread:[6,24],imshow:[1,3,4,6,24],in1:[],in2:[],in3050:[28,29],in3310:29,in4080:[28,29],in4300:[28,29],in4310:28,in5400:3,in5550:28,in_out_neuron:4,inaccur:[13,33,34],inact:[12,35,36],inadequ:[0,29],inch:[6,30,31],includ:[0,1,2,3,4,5,6,7,11,12,15,16,17,20,22,24,26,27,28,29,30,31,32],include_bia:[6,9,32],inclus:[17,35],incom:[12,35,36],incorrect:1,incoveni:8,increas:[0,1,3,4,5,6,8,9,11,12,13,21,24,26,29,30,31,32,34,35,36],increasingli:26,increment:34,ind:6,inde:[0,2,4,5,6,13,29,30,36],indefinit:4,independ:[0,5,6,7,8,12,13,26,29,30,33,34,35],index:[0,1,3,4,10,14,22,23,26,28,29],index_col:[0,29],indic:[0,1,3,4,5,6,9,10,11,13,16,21,24,29,30,34,35,36],indispens:[6,32],individu:[1,6,7,10,12,26,29,30,32,33,35,36],indu:0,indx1:2,indx2:2,indx3:2,indx:23,ineffici:[3,13,34,35],inequ:[8,13],inequaltii:[33,34],inertia:[13,21,34,35],inf1000:[22,29],inf1100:[22,29],inf1100l:[22,29],inf1110:[22,29],inf3000:29,infeas:9,infer:[0,1,4,6,28,29,32],inferenc:1,infil:[0,6,7,9,29,32,33],infin:[5,6,7,11,18,30,31,32,33,36],infinit:3,infinitesim:26,influenc:[6,10,32,33],influenti:1,info:29,inform:[0,1,3,4,6,9,11,12,13,14,21,23,24,28,29,32,33,34,35,36],infti:[3,6,13,26,32,33,34,36],ingeni:[13,33,34,35],ingrad:2,ingredi:[0,9,29],inher:[6,32],inherit:[23,29],initi:[0,1,2,6,10,13,14,23,26,29,32,33,34,35,36],inject:14,inlin:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],inner:[0,13,30,34],inp:4,inplac:13,inpput:36,input:[0,1,3,4,5,6,7,8,12,13,14,21,24,26,29,30,31,32,33,34,35],input_dim:1,input_shap:[3,4],inputs:1,inputs_shuffl:[0,1,30],insert:[3,5,6,8,10,26,30,31,32],insid:[0,4,7,33],insight:[0,1,5,21,22,29,30,31,32],insist:[6,13,30,31,34],inspect:33,inspir:[0,1,12,29,35,36],instabl:2,instal:[0,1,5,6,9,15],instanc:[0,1,2,4,6,9,11,13,29,30,32,33,34],instanti:10,instead:[0,1,2,3,4,5,6,8,9,11,13,14,21,23,24,26,29,30,32,33,34,35],institut:1,instruct:[0,1,15,16,29],int32:10,int_0:26,int_:[3,6,26,32,36],int_a:26,intak:[0,30],integ:[1,2,13,14,23,26,29,34,35],integer_vector:1,integr:[3,6,26,29,32],intellig:[0,14,28,29],intend:10,intens:[1,36],intention:14,interact:[0,6,9,12,22,24,29,35,36],intercept:[0,6,8,11,13,16,24,29,31,32,33,34,35],intercept_:[0,6,8,9,13,29,30,31,33,34],interchang:[5,12,23,31,32,35,36],interconnect:[1,36],interest:[0,1,2,3,4,5,6,7,8,9,12,21,22,24,26,29,30,31,32,33,34,35,36],interfac:[0,1,23,30],interior:[0,9,29],intermedi:[23,30],intern:[1,2,10,12,35,36],interpol:[1,3,4,6,12,24,35,36],interpr:[5,30,31],interpret:[0,1,6,9,10,12,13,17,19,23,24,26,36],interv:[0,3,5,6,7,13,18,24,26,29,30,31,33,34],intial:[13,33,34],intract:[0,4,30],intrins:[3,11,23,26,29],intro:[22,28,29],introduc:[0,1,5,6,8,10,12,17,23,24,26,29,32,33,36],introduct:[1,2,4,13,17,20,28,30,33,34],introductori:[0,4,23,28,29,30],intuit:[0,5,6,8,12,13,21,24,29,31,32,34,35,36],inv:[0,5,13,21,29,30,31,33,34,35],invalid:[1,8],invalu:[0,13,15,22,29,33,34],invari:1,invd:[5,31],inver:[8,35,36],invers:[0,3,6,13,15,16,17,21,24,29,30,33,34,35],inverse_transform:8,invert:[0,5,7,10,13,21,29,31,33,34,35],invh:[13,21,34,35],invok:[0,8],involv:[0,2,6,7,11,12,30,32,33,34,35,36],io:[0,17,19,22,24,25,27,28,29,30],ion:35,ip:[0,8,26,29],ipca:11,ipykernel_12550:[],ipykernel_12588:[],ipykernel_1323:[],ipykernel_1390:[],ipykernel_1539:[],ipykernel_1579:[],ipykernel_58656:[],ipykernel_58739:[],ipykernel_58840:[],ipykernel_58862:[],ipykernel_6316:[],ipykernel_6403:[],ipykernel_6690:[],ipykernel_6729:[],ipykernel_95354:1,ipykernel_95419:6,ipykernel_95519:29,ipykernel_95542:32,ipynb:[22,24,29],ipython:[0,5,7,9,11,14,15,22,24,29,30,33],iq:[6,32],iri:[8,9],irreduc:[6,32],irrelev:[5,30],irrespect:[0,29],isbox:[],iscomplexobj:2,iseffici:[34,35],isn:[5,31,32],isnul:0,isomap:11,isotop:[29,33,34],issu:[1,9,23,31,36],it_arrai:[13,34],item:[0,13,29,34],items:[23,29],iter:[1,2,4,6,8,9,11,13,14,21,26,32,33,35,36],its:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,18,22,23,24,26,29,31,32,33,34,35,36],itself:[5,6,12,19,24,26,30,31,32,36],j1:23,j:[0,1,2,3,4,5,6,8,9,11,12,13,14,16,17,18,19,23,24,26,28,29,30,31,32,33,34,35,36],j_:6,j_lasso_sk:6,j_ridge_sk:6,j_sk:6,jackknif:[6,22,29,32],jacobian:[2,13,33,34],jacobian_shap:[],jakobsen:27,jason:4,jax:[22,29,36],jax_descend_i:[21,35],jax_descend_x:[21,35],jax_enable_x64:[21,35],jax_grad:[21,35],jensen:[27,29,30,31,32,33,34,35,36],jentzen:36,jerom:[18,24,28],ji:[12,23,36],jit:[13,34],jj:[0,5,6,29,31,32],jk:[0,1,6,12,23,29,35,36],jl:[0,29],jm:23,jnp:[13,21,34,35],job:[2,8,10],johansen:29,join:[0,3,4,6,7,9,14,29,30,32,33],joint:[4,5,31,32],judg:[13,33,34],judgement:[6,24],julia:[22,23,24],juliu:36,jump:[24,26],junk:4,jupit:29,jupyt:[0,9,15,19,22,24,28,29,36],just:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,22,24,26,29,30,31,32,33,34,35,36],justif:0,justifi:[3,10],k0:[7,33],k1:[7,33],k:[0,1,3,5,6,7,8,9,10,11,12,13,14,22,23,24,26,27,29,30,31,34,35],kaggl:[6,24],kappa_d:26,karl:[27,29],karush:8,katrin:[27,29],keep:[0,1,4,5,6,11,13,14,23,24,29,30,31,32,33,34,35,36],keepdim:[1,2,6,10,23,32],kei:[0,1,3,6,12,30,35],kept:[4,6,14,32],kera:[0,4,22,24,29],kernel:[0,1,3,4,14,22,29,30],kernel_librari:[3,4,14],kernel_regular:[1,3],kernel_s:4,kernelpca:11,kev:[0,29],kevin:[28,29],keyboardinterrupt:[1,2],keyerror:[],keyword:[6,13,23,29],kfold:[6,32,33],kg:1,ki:23,kick:[1,13,34,35,36],kiener:2,kilomet:[6,30,31],kind:[0,2,3,4,8,12,13,14,29,30,34,35,36],kj:[6,12,23,30,31,36],kjm:[22,29],kkt:8,kl:26,km:[12,29,35],kmean:14,kmeanspoint:14,kn_k:14,know:[0,1,2,5,6,8,13,22,29,30,31,33,34,35,36],knowledg:[0,22,29],known:[1,3,4,5,6,7,8,9,12,23,24,26,28,30,31,32,33,35,36],kondev:[0,29],kp:26,kpca:11,kroneck:14,kuckuck:36,kuhn:8,kutyniok:36,kvalsund:[27,29],kwarg:2,kwown:[0,29],l0:[7,33],l1:[0,1,3,7,29,33],l1_l2:[1,3],l1regl:5,l2:[1,3],l:[0,1,2,3,5,6,7,8,10,11,12,13,19,23,24,26,29,30,33,34,35],l_1:[7,33,36],l_2:[7,13,33,34,36],l_:23,l_j:[12,36],la:[13,34],la_i:[12,36],la_k:[12,36],lab:[20,22,24,29],label:[0,1,2,3,4,5,6,7,8,9,10,12,13,14,21,22,23,24,26,29,30,31,32,33,34,35,36],label_prob:[34,35],labelencod:[7,10,33],labels:[6,8,9],labels_shuffl:[0,1,30],laboratori:[25,31],lack:[0,29],lagari:2,lagrang:[8,11],lambda:[0,1,2,3,5,6,7,8,10,12,13,17,18,21,24,26,29,30,31,32,34,35,36],lambda_0:11,lambda_1:[5,8,11,30],lambda_2:[8,11],lambda_:11,lambda_i:[8,11],lambda_iy_i:8,lambda_jy_iy_j:8,lambda_k:8,lambda_n:[5,8,30],lamda:1,land:[0,8],landmark:8,landscap:[13,21,33,34,35],langl:[0,6,11,26,29,30],languag:[0,1,4,8,15,22,23,24,28,29,36],lapack:[23,29],laplac:[5,31,32],laptop:22,larg:[0,1,2,4,5,6,8,9,10,11,13,15,22,23,24,26,28,29,30,32,33,34,35,36],larger:[0,3,5,6,8,10,11,13,17,26,29,30,31,32,33,34,35],largest:[4,8,11],lasso:[0,7,22,29],lasso_sk:6,last:[0,1,2,3,4,5,6,7,8,10,12,13,14,17,18,23,24,26,27,29,31,32,34],latent:4,latent_dim:4,latent_point:4,latent_space_value_rang:4,later:[0,1,4,7,8,12,13,14,15,22,24,29,33,34,35,36],latest:[4,22],latest_checkpoint:4,latex:29,latter:[0,3,6,7,8,11,13,16,23,24,26,29,30,31,32,33,34,35,36],lattic:[12,35,36],law:0,lax_numpi:[21,35],layer:[0,4,13,21,29,34,35],lbfg:[7,9,10,11,33],lcc:[5,6,31,32],lda:11,ldot:[0,6,11,19,24,29,32,33],le:[5,7,10,13,17,21,26,30,31,33,34,35],lead:[0,1,3,5,6,7,8,9,10,11,12,13,16,17,23,26,29,30,31,32,33,34,35,36],leaf:9,leaki:[1,36],leakyrelu:4,lear:[13,33,34],learn:[3,4,5,6,7,8,9,10,12,18,23,25,27,28],learnabl:3,learner:10,learnig:29,learning_r:[8,10,21,35],learning_rate_init:[0,1,29],learning_schedul:[13,21,34,35],learnt:24,least:[0,7,8,10,11,15,16,17,19,21,22,23,26,32,33],leat:[13,21,34,35],leav:[0,1,3,5,6,9,11,29,31,32,33,36],lectur:[0,1,5,10,11,12,13,15,17,21,22,23,24,25,27,28],lecturenot:[0,17,19,22,24,28,29],left:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,16,17,19,23,24,26,29,30,31,32,33,34,35,36],leftarrow:[8,12,36],legend:[0,2,3,4,5,6,7,8,9,10,13,29,30,31,32,33,34,35],len:[0,1,2,3,4,5,6,8,9,10,11,12,23,29,30,31,32,34,35,36],length:[0,1,2,3,4,8,9,13,16,22,29,30,33,34,35],length_of_sequ:4,leq:[0,5,7,8,13,14,26,29,30,31,33,34],less:[0,1,3,4,5,6,8,9,13,22,26,29,30,31,32,33,34,35],lessen:[1,36],let:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,23,26,29,30,31,32,33,34,35,36],letter:[0,16,23,26,29,30],level:[0,1,5,6,9,22,23,24,25,27,29,32,36],li:[8,11],lib:[0,2,3,4,6,7,8,9,11,14,21,29,31,33,35],liblinear:[8,10],libmetal_plugin:[3,4,14],librari:[0,1,2,3,4,5,6,7,9,10,11,14,15,21,23,24,26,28,30,31,33],library_loc:[3,4,14],licens:[0,1,15,22,24,29],lie:[0,6,11,26,29,30,32],life:[0,1,8,12,29,35,36],lifetim:[13,34,35],like:[0,1,2,3,4,5,6,7,9,10,11,12,13,15,16,21,22,23,24,26,29,30,31,32,33,34,35,36],likelihood:[0,1,5,9,29,30,34,35],lim_:26,lima:27,limit:[0,5,6,8,9,11,12,21,23,24,29,30],lin_clf:8,lin_model:0,lin_reg:9,linalg:[0,2,5,6,8,11,13,21,23,26,29,30,31,33,34,35,36],line1:8,line2:8,line2d:[21,34,35],line3:8,line:[0,1,2,3,4,6,7,8,10,11,13,14,21,24,29,30,31,32,33,34,35,36],linear:[1,3,5,6,7,9,10,11,12,17,18,21,22,24,26,32,34,35,36],linear_model:[0,5,6,7,8,9,10,11,13,29,30,31,32,33,34,35,36],linear_regress:[6,32],linearli:[5,30],linearloc:[6,13,24,33,34],linearregress:[0,6,7,9,29,30,31,32,33],linearsvc:8,lineat:31,liner:[1,3],linerar:10,linewidth:[0,2,4,6,8,9,10,24,32],link:[0,4,9,12,22,24,27,29,36],linlag:[5,31],linpack:[23,29],linreg:[0,29],linspac:[0,2,3,4,6,8,9,10,13,15,16,21,23,26,29,30,31,32,34,35],linu:4,linux:[0,1,15,22,24,29],liquid:[0,29],list:[0,1,2,3,4,7,9,22,24,29,30,33,34,35],listcomp:[],listedcolormap:[9,10],literatur:[1,7,14,28,32,33,36],littl:[1,3,9,12,36],live:8,ll:[0,26,29,30],lle:[0,30],lloyd:[4,14],lmb:[0,2,5,6,31,32,33],lmbd:[0,1,3,29],lmbd_val:[0,1,3,29],lmbda:[13,33,34],ln:[1,13,33,34],load:[0,1,3,4,6,7,9,10,14,24,33],load_boston:0,load_breast_canc:[1,7,9,10,11,33],load_data:[3,4],load_digit:[1,3],load_iri:[8,9],load_librari:[3,4,14],load_pluggable_device_librari:[3,4,14],loc:[0,3,6,7,8,9,10,29,32,33],local:[0,1,2,3,7,12,13,30,33,34,35,36],locat:[2,3,8],log10:[0,5,6,31,32,33],log:[0,1,2,4,5,6,7,9,10,11,13,23,24,29,30,31,32,33,34,35],log_:[0,29],log_clf:10,logaddexp2:[],logaddexp:[],logarithm:[0,5,7,23,29,31,32,33],logbook:24,logic:[0,1,9,29,36],logist:[0,1,2,8,9,10,11,12,13,21,22,30],logistic_predict:[34,35],logisticregress:[7,9,10,11,33,35,36],logit:[7,33],logreg:[7,9,10,11,33,35,36],logspac:[0,1,3,5,6,29,31,32,33],longer:[2,3,8,10,14,23,26,29],loocv:[6,32,33],look:[0,1,2,3,4,5,6,7,8,9,10,11,13,16,18,21,23,24,26,29,30,31,32,33,34,35,36],loop:[1,4,6,10,12,14,22,23,29,32],lose:1,loss:[0,1,3,4,5,6,7,8,10,11,13,23,24,29,31,32,35,36],loss_fil:4,lossfil:4,lost:4,lot:[0,1,4,6,32,34,35,36],low:[0,6,9,10,11,24,29,30,32],lower:[0,1,3,6,9,10,16,23,30,36],lowercas:[23,29],lowest:[9,13,26,34,35],lr:[1,3,4,10],lstat:0,lstm:4,lstm_2layer:4,lstsq:[0,29,30],lt:[6,32],lu:[0,5,29,30],lubksb:23,luckili:2,ludcmp:23,lux:23,lvert:1,lw:[0,29],m:[0,1,2,3,5,6,8,9,10,11,12,13,21,23,25,26,27,28,29,30,31,32,33,34,35,36],m_1:14,m_:[9,12,36],m_h:[0,29],m_k:14,m_l:[12,36],m_n:[0,29],m_p:[0,29],m_t:[13,34,35],ma:11,machin:[1,3,4,5,6,7,9,10,11,12,15,21,23,25,28,30,31,32,35,36],machinelearn:[0,6,16,17,19,20,22,24,25,27,28,29,33,34,35],mackai:28,made:[0,1,3,4,5,6,7,9,11,12,18,24,29,30,33,35,36],mae:[0,29],magic:4,magnitud:[1,6,7,13,30,31,33,34,35,36],mai:[0,1,2,3,5,6,7,8,9,11,12,13,18,21,22,23,24,26,29,30,31,32,33,34,35,36],mail:[25,27],main:[0,1,3,4,5,6,7,9,23,24,28,30,33,36],mainli:[0,5,6,7,9,29,30,31,32,33],maintain:[6,32],major:[1,6,9,10,13,23,29,32,33,34,35],make:[1,2,3,4,5,6,7,8,11,12,13,21,22,23,24,26,28,31,32,33,34,35,36],make_axes_locat:6,make_classif:[35,36],make_moon:[8,9,10],make_pipelin:[0,6,10,30,32],make_vjp:2,makedir:[0,6,7,9,29,30,32,33],makeplot:[0,29],malcondit:23,malign:[1,7,9,33],mammographi:[5,31,32],manag:[0,2,3,15,22,24,29],mandatori:[27,29],mani:[0,1,3,4,5,6,7,8,9,11,13,14,21,22,23,24,26,28,29,30,31,32,33,34,35,36],manifold:11,manner:3,manual:[6,30,31,33],map:[0,1,2,6,7,8,11,12,14,24,26,29,33,35],marc:30,margin:[0,5,8],marit:[0,29],mark:29,marker:[0,7,21,23,29,33,35],markov:[22,29],marsaglia:26,mass:[0,1,5,13,30,34,35],massag:[0,29],masses2016:[0,29],masses2016ol:[0,29],masses2016tre:0,masseval2016:[0,29],master:[6,16,20,24,25,27,33,34,35],mat1100:[22,29],mat1110:[22,29],mat1120:[22,29],mat:[22,29],match:[1,4,5,13,14,30,33,34,35,36],match_complex:[],materi:[4,5,7,13,17,23,27,34,35],math:[3,7,12,13,21,23,26,28,29,33,34,35,36],mathbb:[0,4,5,6,7,8,11,12,13,14,17,18,19,23,24,26,29,30,31,32,33,34,35,36],mathbf:[0,5,6,7,8,13,18,19,21,23,24,29,30,31,32,33,34,35,36],mathcal:[1,5,6,7,13,19,24,31,32,33,34],matheemat:3,mathemat:[0,6,11,12,13,17,22,23,26,28,29,31,33],mathemati:29,mathmlbook:16,mathrm:[0,1,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,24,26,29,30,31,32,33,34,35,36],matmul:[1,2,5,31,36],matnat:28,matplotlib:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,21,22,23,24,26,29,30,31,32,33,34,35,36],matric:[0,1,3,4,6,7,8,11,13,16,17,22,30,33,34,36],matrix:[0,2,3,4,6,7,8,10,13,15,16,17,18,19,21,24,26,32,36],matshow:1,matter:[2,3,13,30,33,34,35,36],max:[0,1,2,3,4,9,10,12,13,21,27,29,33,34,35,36],max_depth:[0,9,10],max_diff1:2,max_diff2:2,max_diff:2,max_it:[0,1,8,9,11,13,29,33,34,35,36],max_iter:14,max_leaf_nod:10,max_sampl:10,maxdegre:[0,6,10,30,32],maxdepth:10,maxim:[1,4,5,7,8,11,31,32,33],maximum:[0,2,3,5,7,8,9,10,13,14,29,30,34,35],maxpolydegre:[5,6,31,32,33],maxpooling2d:3,mbox:[5,6,18,24,30,31,32],mcculloch:[12,35,36],md:[11,20,24,34,35],mdoel:4,mean:[1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,26,29,32,34,35,36],mean_absolute_error:[0,29],mean_divisor:14,mean_i:26,mean_matrix:14,mean_squared_error:[0,4,6,7,10,29,30,32,33],mean_squared_log_error:[0,29],mean_vector:14,mean_x:26,meaning:[0,4,7,29,33],meansquarederror:[0,29],meant:[2,3,7,10,13,33,34,35,36],measur:[0,1,2,5,6,9,11,12,14,19,24,26,29,30,31,32,36],mechan:[0,4,26,29],median:[0,29,30],medicin:[12,35,36],medium:[4,8,13,34,35],medv:0,meet:[0,27],mehta:[0,29,30,31],memori:[3,4,11,12,13,21,23,34,35,36],mention:[0,12,13,24,26,29,33,34,35,36],mere:[0,15,29],meshgrid:[2,5,6,8,9,10,11,24,30],messag:[5,13,34,35],messi:2,met:[0,3,8,30],metadata:2,meteorolog:9,meter:[6,30,31],method:[0,1,2,3,4,5,7,8,11,12,14,16,17,18,19,22,23,26,28,30,31,36],metion:[6,24],metric:[0,1,3,6,7,9,10,14,15,16,29,30,32,33],metropoli:[22,29],mev:[0,26,29],mgd:[13,34,35],mglearn:[22,29],mgrid:[13,34],mhjensen:[2,3,4,6,8,9,11,14,21,35],mi:10,mia:[27,29],michael:36,michigan:[29,31,33,34,35],microsoft:28,mid:1,midel:4,midnight:[16,17,18,19,20,21],midpoint:9,might:[0,1,2,4,6,9,13,30,31,33,34,35,36],mild:9,millimet:[6,30,31],million:[0,29,30,34,35],mimic:[12,35,36],min:[0,2,5,8,9],min_:[0,2,5,14,17,29,30,31],min_samples_leaf:9,mind:[0,6,13,24,29,30,31,32,33,34],mindboard:4,mine:[22,29],mini:[1,11,12,13,21,33,36],minibatch:[1,11,13],minibathc:[13,34,35],miniforge3:[0,2,3,4,6,7,8,9,11,14,21,29,31,33,35],minim:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,17,18,21,24,30,31,32,34,35,36],minima:[0,1,7,13,29,33,34,35],minimum:[0,1,2,6,8,9,11,13,30,32,33,34,35],minmaxscal:[0,30],minor:26,minst:1,minu:[7,33],mirjalili:29,mirror:9,misc:[6,24],misclassif:[8,9,10],misclassifi:[8,10],miser:0,mismatch:[1,36],miss:[0,7,10],mistak:4,mit:28,mix:[1,2,29,36],mixtur:[13,21,34,35],mk:[9,23],mkdir:[0,6,7,9,29,30,32,33],ml:[0,1,10,13,23,24,30,33,34,35,36],mlab:26,mlbook:29,mle:[5,7,33],mlp:[1,35,36],mlpclassifi:[1,35,36],mlpregressor:[0,29],mm:23,mml:30,mn:[12,26,35],mnist:[1,11,36],mod:26,mode:[25,27,29],model:[2,3,5,7,8,9,10,11,13,14,15,16,18,19,21,22,24,26,28,30,31,32,33,34],model_select:[0,1,3,5,6,7,9,10,11,29,30,31,32,33],moder:10,modern:[0,6,7,22,29,32,33,36],modif:[2,12,13,34,35],modifi:[0,1,3,5,7,8,10,12,13,29,30,31,33,34,35,36],modul:[0,9,11,23,29,31],modular:26,modulo:26,moe:[11,30],moment:[5,6,13,21,26,31,32],momentum:36,mondai:29,monitor:[13,21,34,35],monoton:[5,12,26,31,32,35,36],mont:[0,6,22,26,28,29,32],moor:[5,6,31],more:[0,1,2,4,5,7,8,9,10,11,12,13,14,18,22,26],moreov:[0,3],morten:[27,29,30,31,32,33,34,35,36],most:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,22,24,26,29,30,31,32,33,34,35,36],mostli:[1,11,36],motion:[0,13,34,35],motiv:[1,4,36],move:[0,4,5,6,7,9,12,13,14,21,24,26,30,31,32,33,34,35,36],mpl:[0,7,29,33],mpl_toolkit:[2,6,13,24,33,34],mplot3d:[2,6,13,24,33,34],mplregressor:1,mse:[0,4,5,6,9,10,15,16,17,19,24,29,30,31,32,33],mse_simpletre:10,mselassopredict:[5,31],mselassotrain:[5,31],mseownridgepredict:[6,31],msepredict:[5,31],mseridgepredict:[0,5,6,31,33],msetrain:[5,31],msle:[0,29],mt:[7,12,33,35,36],mu0:26,mu1:26,mu2:26,mu:[0,6,11,13,26,29,32,34,35],mu_1:30,mu_:[6,26,30,31,32],mu_i:[6,30,31],mu_n:11,mu_x:26,much:[0,1,2,3,4,5,6,8,9,10,11,12,13,23,24,26,29,30,31,32,34,35,36],multi:[0,1,3,7,22,29,33],multiclass:[1,7,33],multidimension:[11,12,29,35,36],multilay:1,multinomi:[7,33],multipl:[2,4,5,6,7,12,13,26,30,32,33,34,35,36],multipli:[3,5,6,11,13,23,26,30,31,34],multiplum:8,multivari:[0,2,10,11,22,26,29],multivariate_norm:[11,14],murphi:[11,28,29],must:[1,2,5,6,8,10,12,13,14,26,30,32,33,34,35,36],mutat:[7,33],mutual:[1,3,6,13,32,33,34,36],mx_:26,myenv:[0,2,3,4,6,7,8,9,11,14,21,29,31,33,35],myriad:[0,15,22,29],mz1:26,mz2:26,n1:23,n2:23,n:[0,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,21,23,24,26,29,30,31,32,33,34,35,36],n_0:[12,26,35],n_:[1,2,3,8,12,26,35],n_boostrap:[6,10,32],n_bootstrap:[6,32],n_categori:[1,3],n_cluster:14,n_compon:11,n_data:35,n_epoch:[13,21,34,35],n_estim:10,n_examples_to_gener:4,n_featur:[1,36],n_filter:3,n_hidden:2,n_hidden_neuron:[0,1,29,36],n_i:26,n_input:[0,1,3,30,36],n_instanc:9,n_iter:[33,34],n_iter_i:[9,11],n_job:10,n_k:14,n_l:[12,26,35],n_layer:1,n_m:9,n_neuron:1,n_neurons_connect:3,n_neurons_layer1:1,n_neurons_layer2:1,n_output:36,n_point:14,n_sampl:[6,8,9,10,14,32,35,36],n_split:[6,32,33],n_step:4,n_t:2,n_x:2,nabla:[1,13,33,34],nabla_:[2,13,21,33,34,35],nabla_w:[13,34,35],nag:[13,34,35],naimi:[0,29],naiv:[7,33],naive_kmean:14,najafi:[27,29],name:[0,1,3,4,5,6,7,8,9,10,12,13,14,15,22,23,24,26,27,29,30,31,32,33,34,35,36],nameerror:[10,24],namespac:[3,4,14],narrow:[13,34,35],nary_f:2,nary_op_arg:2,nary_op_kwarg:2,nary_oper:2,nation:[1,5,31,32],nativ:[22,29],natur:[0,1,4,8,9,12,13,24,26,28,29,33,34,35,36],navier:[12,35,36],nb:26,nb_:23,nbconvert:29,nbviewer:9,nd:14,ndarrai:[2,6],ndim:[],ne:[9,10,23,26,30],nearest:[1,3,6,11],nearli:[13,33,34],neat:29,neatli:[],neccesari:[6,32],necess:2,necessari:[0,1,3,4,8,14,29,36],necessarili:[0,4,11,26,29],necesserali:[5,31,32],neck:[7,33],need:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,21,23,26,30,31,32,33,34,35,36],neg:[0,1,3,5,6,7,10,13,23,26,29,31,32,33,34,35,36],neg_mean_squared_error:[6,32,33],neglect:26,neglig:26,neighbor:[3,6,11],neither:[4,13,34,35],neq:[13,14,26,33,34],nervou:[12,35,36],nest:[2,9,12,35],nesterov:[13,34,35],net:[2,4,12,35,36],netlib:[23,29],network:[0,9,13,21,22,28,30,34],neural:[0,13,21,22,28,30,33,34],neural_network:[0,1,2,29,35,36],neuralnetwork:1,neuralnetworksanddeeplearn:36,neuron:[1,2,3,4,12],neutral:[0,29],neutron:[0,29],never:[1,4,6,9,26,32,36],new_box:2,new_chang:[13,21,34,35],new_hobbit:29,new_root:[],new_trac:[],newaxi:[0,3,6,9,32,33],newli:[0,29],newton:[1,7,8,13,26,36],next:[0,1,2,3,4,5,6,7,8,9,13,14,21,29,30,31,33,34,35,36],next_guess:[13,34],next_input:4,ng:[1,36],ngini:9,ni:14,nice:[0,1,5,11,29,30,31,32],nielsen:36,nine:36,niter:[13,21,33,34,35],nitric:0,nlambda:[0,5,6,31,32,33],nlp:28,nm:26,nm_n:[0,29],nmse:[6,32],nn:[2,5,6,12,23,31,32,35],nn_model:1,nnmin:2,node:[1,2,3,9,10,12,35],node_constructor:[],nois:[0,4,5,6,8,9,10,13,15,16,19,24,29,30,31,32,33,34],noise_dimens:4,noisi:[1,6,19,24,32],non:[0,1,3,5,6,7,9,10,11,12,13,14,21,23,26,29,30,31,32,33,34,35,36],none:[0,1,2,4,5,9,10,13,26,29,30,31,32,33,36],nonlinear:[3,6,8,9,11,12,32,35,36],nonneg:[6,9,13,32,33,34],nonparametr:6,nonsens:26,nonsingular:23,nonumb:[3,7,8,13,21,23,33,34,35],nor:[1,4,13,34,35,36],norm:[0,1,5,6,8,11,13,17,29,30,31,32,33,34,35,36],normal:[3,4,5,6,7,8,9,10,11,12,13,15,16,18,19,21,22,23,24,26,29,30,31,33,34,35],normali:[23,29],norwai:[6,24,29,32,35],notat:[0,2,5,6,13,14,21,26,29,30,31,32,34,36],note:[0,1,2,3,4,5,6,7,8,11,12,13,14,15,16,22,23,26,28,29,32,33,34,36],notebook:[0,1,3,9,15,22,24,29,36],notesseptember16:33,notesseptember30:35,notfounderror:[3,4,14],noth:[1,2,5,8,12,14,26,30,31,35,36],notic:[4,5,12,13,23,26,29,31,34,35,36],notimplementederror:2,notion:3,novel:[3,6,10,33],novemb:[1,25,27,29],now:[0,2,4,5,6,7,8,10,11,12,14,15,16,17,22,23,24,26,29,30,33,36],nowadai:[0,1,3,9,22,29,36],nox:0,np:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,21,23,24,26,29,30,31,32,33,34,35,36],npr:2,nsampl:[6,9,32,33],nt:2,ntrained_model:[6,31],nu:26,nuclear:[5,30],nuclei:[0,26,29],nucleon:[0,29],nucleu:[0,29],num:4,num_coordin:2,num_featur:35,num_hidden_neuron:2,num_it:2,num_iter:[21,35],num_neuron:2,num_neurons_hidden:2,num_point:2,num_tre:10,num_valu:2,number:[1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,23,24,25,27,29,31,32,33],numberid:[7,33],numberparamet:3,numer:[0,5,6,9,10,11,12,13,17,21,22,23,28,29,30,31,32,33,34,35,36],numpi:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,22,24,26,30,31,32,33,36],numpy_box:[],numpy_vjp:2,numpy_wrapp:[],nunmpi:[5,30],nvalu:9,nx:2,nx_test:[6,31],nx_train:[6,31],nx_train_mean:[6,31],ny:26,ny_pr:[6,31],ny_train:[6,31],ny_train_mean:[6,31],o:[0,6,7,8,9,11,15,21,23,27,28,29,33,35],obei:[6,11,13,30,31,34],obj:2,object:[0,1,2,4,6,8,10,23,29,34,36],obliqu:[5,30],observ:[0,1,3,5,6,7,8,9,10,11,12,13,14,26,31,32,33,34,35],obtain:[0,1,5,6,7,8,9,10,12,13,14,17,21,23,24,26,29,30,31,32,33,34,35,36],obviou:[5,6,11,26,30],obviouli:29,obvious:[0,4,5,6,21,23,29,31,32],oc:30,occupi:0,occur:[0,6,8,9,23,26,29],octob:[21,25,27,29,35],od:0,odd:[0,3,7,29,30,33],odenum:2,odesi:2,odin:29,oen:0,off:[1,3,4,5,9,13,19,26,31,32,34,35],offer:[6,11,22,23,25,27,29,32],offic:[27,29],offici:[25,29],often:[0,1,3,4,5,6,7,8,9,10,11,12,13,14,16,22,23,24,26,29,30,32,33,34,35,36],ofter:[23,29],ol:[0,13,15,16,17,18,29,30],old:[1,5,10,13,31,32,33,34],ols_sk:6,ols_svd:6,olsbeta:[0,5,31],omega:[2,3,6],omega_0:3,omit:[0,5,29,30,31,32],omlmp_kkie0:33,onc:[1,6,9,11,13,32,33,34,35,36],one:[0,1,3,4,5,6,7,8,9,10,11,13,14,19,21,22,23,24,26,27,29,30,31,32,35],onehot:1,onehot_vector:1,onehotencod:9,ones:[0,2,5,6,8,9,10,11,13,21,23,24,29,30,31,32,33,34],ones_lik:4,ong:30,onl:3,onli:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,19,21,23,24,26,29,30,31,32,33,34,35,36],onlin:[11,25,36],onto:[5,11,30],open:[0,1,4,6,7,9,15,22,24,25,27,29,32,33],oper:[0,1,3,5,6,10,11,12,13,15,22,26,29,30,31,32,34,35],operation:26,oplu:26,opmiz:[13,34,35],opportun:0,oppos:[6,13,34,35],opposit:[1,5,8,30,36],opt:[1,5,29,31,36],optim:[0,2,3,4,5,6,7,9,10,11,14,15,16,17,18,19,21,24,31,32],optimis:[1,3],option:[0,1,3,5,6,8,9,11,21,23,24,30,31,32,35],optmiz:[1,8,13,21,30,34,35,36],oral:29,orang:0,order:[0,1,2,3,5,6,7,8,9,10,11,12,15,16,23,24,26,29,30,31,32,33,36],ordinari:[0,2,3,7,11,13,15,16,17,19,21,22,32,33,34,35],oreilli:[28,29],org:[0,3,4,9,11,21,22,23,24,28,29,31,34,35,36],organ:[6,7,10,23,32,33],orgin:36,orient:[1,5,26,30,31],origin:[0,3,5,6,8,11,12,13,23,29,30,32,34,35],orthogn:[5,30],orthogon:[0,5,6,8,11,13,17,23,29,30,31,34],orthonorm:[5,30,31],os:[0,1,4,5,6,7,8,9,27,29,30,31,32,33],oscar:[1,36],oscil:[3,13,34,35],oserror:[0,3,4,7,14,33],oslo:[0,15,22,24,25,27,29,30,31,32,33,34,35,36],osx:[0,15,22,24,29],other:[0,1,2,3,5,6,7,8,10,13,14,15,19,22,25,26,27,28,31,32,34],otherwis:[0,1,4,7,13,21,23,29,33,34,35],ouput:[5,7,12,31,32,33],our:[1,2,3,6,7,8,9,10,12,14,15,16,17,18,19,21,22,23,24,26,31,32,35],ourmodel:0,ourselv:[0,5,6,8,11,13,29,30,31,32,33,34],out1:[],out2:[],out:[0,1,2,4,5,6,7,8,9,10,11,12,13,16,21,22,23,24,26,29,30,31,32,33,34,35,36],out_fil:9,outcom:[0,7,9,10,12,26,30,33],outdoor:9,outer:[6,12,13],outfil:4,outgrad:2,outlier:[0,8,29,30],outlin:[6,10,11,32],outlook:9,outperform:10,output:[0,1,3,4,5,6,7,8,9,10,12,13,16,23,24,26,29,30,31,32,33,34,35],output_bia:1,output_bias_gradi:[1,36],output_shap:4,output_weight:1,output_weights_gradi:[1,36],outputlayer1:[12,35],outputlayer2:[12,35],outsid:4,over1:[13,34,35],over:[0,1,3,4,5,6,9,10,12,13,21,23,24,29,30,31,32,33,34,35],overal:[1,10],overcast:9,overcom:[12,13,34,35,36],overdetermin:[0,29],overfit:[0,1,3,6,9,10,13,21,32,34,35,36],overflow:[1,5,31,32],overhead:[12,36],overlap:[3,7,8,9,33],overlin:[0,5,6,9,10,11,14,23,29,30,31],overst:0,overtrain:4,overview:[3,33],own:[4,5,6,8,12,13,21,22,23,24,31,34,35,36],owner:0,ownmsepredict:0,ownmsetrain:0,ownridgebeta:[0,6,31],ownypredictridg:0,ownytilderidg:0,oxid:0,p0:2,p1:2,p:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,17,23,26,29,30,31,32,33,34,36],p_:[2,4,8,9],p_hidden:2,p_i:[5,26,31,32],p_j:26,p_n:26,p_output:2,p_x:26,pa:36,pack:[0,29],packag:[0,1,2,3,4,5,6,7,8,9,11,13,14,15,21,22,24,26,30,31,33,34,35],packtpub:29,packtpublish:29,pad:[3,4],page:[0,9,22,29,31,32,33,34],pai:[0,1,9,13,34,35,36],pair:[0,2,3,9,22,26,29],panda:[0,4,5,6,7,9,11,15,22,24,31,32,33],panel:29,paper:1,paradigm:[0,29],parallel:[10,13,21,22,23,29,34,35],param:2,param_distribut:33,param_grid:33,paramat:2,paramet:[0,1,2,3,4,5,6,7,8,9,10,12,13,16,17,18,19,21,24,26,31,32],parameter:[0,6,10,24,29,30],parametr:[0,6,15,16,29,30,32],paramt:[3,5,31,32,36],parent:[2,36],parent_argnum:[],part:[0,1,3,5,6,10,17,18,21,23,25,26,27,29,31,32,35],partial:[0,1,5,6,7,8,10,11,12,13,16,26,29,30,31,33,34,36],particip:[22,25,27,29],particl:[0,4,13,26,29,34,35],particular:[0,1,2,3,5,6,9,10,11,12,13,16,24,26,28,29,30,31,32,33,34,35,36],particularli:[5,6,8,11,13,21,26,30,32,33,34,35],partit:[1,4,9],partli:[6,29,32],pass:[2,3,12,14,33,36],passkwarg:2,password:24,past:[10,26],patch:[6,26,32],path:[0,3,4,6,7,9,14,15,22,29,30,32,33],pathcollect:[21,35],patient:[7,33],patter:4,pattern:[0,3,4,12,25,28,29,35,36],pauli:[0,29],pc:[11,22],pca:[0,7,22,29,30,33],pd:[0,4,5,6,7,9,11,29,30,31,32,33],pde:2,pdf:[0,3,4,5,6,9,16,20,24,28,29,31,32,33,35],pedagog:[0,29,30],penal:[6,30,31],penalti:[6,13,24,30,31,33,34],penros:[5,6,31],pentagon:[13,33,34],peopl:[0,1,9,13,22,34,35,36],per:[0,1,6,25,27,29,32,36],percentag:[0,10,11,27],perceptron:[0,1,7,29,33],peregrin:29,perfect:[0,1,13,21,29,34,35],perfectli:[4,6,32],perform:[0,2,3,4,5,6,8,10,11,12,13,14,15,16,17,19,21,22,23,24,26,29,30,31,32,33,34,35,36],performac:4,perhap:[0,5,13,29,30,31,33,34],perimet:[1,9],period:[1,4,26],permut:11,persist:[13,34,35],person:[5,6,7,25,27,29,30,31,32,33],perspect:28,pertin:[12,29,36],petal:[8,9],peter:[28,30],petersen:36,phantom:26,phase:[6,12,35,36],phenomena:26,phi:8,phi_k:8,philipp:36,philosophi:[13,34],phone:[27,29],photo:4,phrase:[0,29],physic:[0,1,4,7,12,13,26,27,28,29,30,31,32,33,34,35,36],pi:[2,3,5,6,7,9,12,13,26,31,32,33,34,35,36],pick:[1,9,10,11,13,14,34,35],pickl:1,pictur:[0,29],pie:[22,29],piec:[11,14],pillow:[0,15,22,24,29],pinv:[5,6,13,21,30,31,34,35,36],pip3:[0,1,15,24,29],pip:[0,1,15,22,24,29],pipelin:[0,6,8,10,30,32],pippin:29,pit:4,pitfal:[6,30,31],pitt:[12,35,36],pixel:[1,3,4],pixel_height:[1,3],pixel_width:[1,3],place:[0,4,6,8,13,23,24,29,32,33,34],plai:[0,3,4,5,6,8,11,22,29,30,31,32,33,36],plain:[8,10,12,13,14,21,33,34,36],plan:[6,9,27,28,29],plane:[8,9],plateau:[5,31],platform:[22,29],plausibl:[12,35,36],pleas:[9,11,13,24,27,29,34,35],plenti:[1,36],plethora:[3,12,35,36],pliahhy2ibx9hdharr6b7xevztgzra1p:[35,36],plot:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,21,22,23,24,26,29,30,31,34,35,36],plot_all_sc:[24,31],plot_confusion_matrix:[7,10,33],plot_count:6,plot_cumulative_gain:[7,10,33],plot_data:1,plot_dataset:8,plot_decision_boundari:[9,10],plot_import:10,plot_max:4,plot_min:4,plot_model:4,plot_numb:4,plot_predict:8,plot_regression_predict:9,plot_result:4,plot_roc:[7,10,33],plot_surfac:[2,6,13,24,34],plot_train:9,plot_tre:[9,10],plqvvvaa0qudcjd5baw2dxe6of2tius3v3:[35,36],plt:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],plu:[0,3,5,7,29,30,31,33],pluggabl:[3,4,14],plugin:[3,4,14],pm:[8,32],pmatrix:2,pml:28,pn:3,png:[0,4,6,7,9,29,30,32,33],point:[0,1,2,3,5,6,7,8,9,10,11,13,14,15,16,17,19,21,23,24,26,27,29,30,32,33,34,35],point_1:4,point_2:4,poisson:[22,26,29],poli:[6,8,32,33],poly100_kernel_svm_clf:8,poly3:0,poly3_plot:0,poly3dcollect:34,poly_featur:[8,9],poly_features10:9,poly_fit10:9,poly_fit:9,poly_kernel_svm_clf:8,polydegre:[0,5,6,10,30,31,32],polygon:[13,33,34],polym:[12,35,36],polymi:24,polynomi:[0,5,6,7,8,9,10,11,15,16,17,19,21,24,29,30,32,33,35,36],polynomial_featur:[6,32],polynomial_svm_clf:8,polynomialfeatur:[0,6,8,9,30,32,33],polytrop:[0,6,29,32],pool:3,pool_siz:3,poor:[1,13,21,33,34,35,36],poorli:[0,30],pop:2,popul:[0,5,29,30,31,32],popular:[0,1,3,6,7,8,9,11,12,15,22,23,24,26,30,33,35,36],popularli:[0,29],portabl:10,portion:[11,13,21,34,35],pose:[0,4,5,6,11,26,29,32],posit:[0,1,2,3,5,7,8,10,11,13,14,23,26,29,30,31,32,33,34,35,36],possibl:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,15,19,21,22,23,24,26,27,29,30,31,32,33,34,35,36],posterior:[5,31,32],postpon:[0,29,30],postscript:24,postul:[5,31,32],potenti:[0,3,5,6,12,13,29,30,31,32,34,35,36],pott:[12,35,36],power:[0,1,5,6,8,9,12,13,29,30,32,34,35,36],pp:[5,6,18,31,32,33,36],practic:[0,5,6,7,8,24,26,30,31,32,33],practition:[0,1,3,29,36],pre:29,precalcul:36,preced:[1,11,12,26,35],preceed:4,preceq:8,precis:[0,2,5,11,13,23,24,26,29,30,31,32,34,35,36],pred:[6,32,34,35],predicit:0,predict:[0,1,5,6,7,8,9,10,15,16,22,24,28,29,30,31,32,33,35,36],predict_prob:1,predict_proba:[7,10,33,35,36],predictor:[0,5,6,7,9,10,11,29,30,31],prefer:[0,1,6,8,9,11,13,15,22,24,29,36],prepar:[0,6,23,24,29,30],preprocess:[0,4,6,7,8,9,10,11,24,31,32,33],prerequisit:0,prescript:24,presenc:[13,34,35],present:[0,5,6,7,9,12,13,21,23,24,26,29,30,31,34,35,36],preserv:[3,11,23],press:[13,28,33,34,36],pretrain:[1,4,36],pretti:[0,4,8,9,15,22,24,29],prev_centroid:14,prevent:[13,26,34,35],previou:[0,1,2,3,4,5,6,8,10,11,12,13,21,23,24,26,30,33,34,35,36],previous:[2,3,9,10,26],price:[0,4,9,13,34,35],primal:8,primari:[0,7,29,33],prime:26,primit:2,princip:[0,5,7,22,29,30,33],principl:[0,6,7,8,14,29,32,33],print:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,21,23,26,29,30,31,32,33,34,35,36],print_funct:[8,9],printout:[0,29],prior:[0,5,6,29,31,32],privat:0,prob:[1,26],probabilist:[0,28,29,30],probabl:[0,1,3,4,6,7,10,13,22,29,30,33,34,35,36],problem:[0,3,4,5,6,7,8,9,10,11,12,16,17,22,23,24,26,32],probml:28,proce:[0,5,6,7,8,9,10,11,13,23,29,30,31,32,34,36],procedur:[2,4,5,6,8,10,11,13,21,24,30,31,32,33,34,35],proceed:23,process:[0,2,4,6,9,10,12,13,15,21,22,23,24,26,28,29,32,33,34,35,36],prod:28,prod_:[1,5,7,31,32,33],produc:[0,3,4,5,6,9,10,11,12,13,22,23,24,26,29,30,31,32,34,35,36],product:[0,1,3,5,6,7,8,12,13,16,21,22,23,29,30,31,32,33,35,36],profess:[0,29],program:[0,1,4,5,6,8,12,14,15,16,21,22,23,25,26,27,29,30,35],programm:23,progress:[1,4,14,34,36],prohibit:[6,32],project1:[6,24],project:[0,1,2,3,5,11,13,17,18,19,20,21,22,25,27,30,31,32,34,35,36],project_root_dir:[0,6,7,9,29,30,32,33],projectwrit:24,promin:[12,35,36],promis:8,promot:[27,29],prone:[9,36],pronounc:[13,22,29,34,35],proof:[0,11,12,13,29,32,33,34,36],propag:[2,3,13,34,35],proper:[0,2,6,7,24,32],properli:[1,6,8,10,13,21,24,34,35,36],properti:[0,1,3,12,13,16,17,23,29,32,34,35,36],propgag:36,proport:[0,1,5,9,11,13,16,26,29,30,34,35],propos:[1,4,6,10,24,29,36],propto:[5,13,31,32,33,34,35],proton:[0,29],prove:[3,13,33,34,35],provid:[0,1,3,4,5,6,8,9,10,12,13,15,21,22,23,24,26,29,30,31,32,33,34,35,36],proxi:[1,13,21,34,35,36],prune:9,pseudo:[23,26,34],pseudocod:24,pseudoinv:[5,31],pseudoinvers:[5,6,31],pseudorandom:[6,26,32],psycholog:[0,29],pt:[13,34],publish:36,punish:[0,1,29],pure:[3,9,26],purest:9,puriti:9,purpos:[0,3,10,12,14,29,35,36],put:1,py:[0,1,2,3,4,5,6,7,8,9,11,14,21,29,31,32,33,35],py_tf:[3,4,14],pycod:29,pydata:22,pydot:9,pyhton2:29,pylab:[0,7,29,33],pypi:22,pyplot:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,32,33,34,35,36],pythagora:[5,31,32],python2:[0,15,24,29],python3:[0,2,3,4,6,7,8,9,11,14,15,21,22,24,29,31,33,35],python:[1,2,3,4,5,6,8,11,12,13,14,16,21,24,26,30,31,34,35,36],pytorch:[0,22,24,29,36],q:[5,6,8,11,26,30,32],qp:8,qquad:[2,11,13,23,34,35],qr:[5,6,23,30],quad:[1,13,23,34],quadrat:[0,8,9,13,15,16,29,34],qualit:[4,9,24,26],qualiti:[0,9,15,16,22,29,30,36],quantifi:[1,36],quantil:10,quantit:[0,6,9,24,29,32],quantiti:[0,2,5,6,7,9,10,11,12,14,16,23,26,29,30,31,32,33,36],quantum:[4,12,28,29,35,36],quartil:[0,30],quasi:36,quench:5,queri:9,question:[0,5,6,9,11,12,13,24,27,29,30,31,32,34,35,36],qugan:4,quick:[4,26],quickli:[1,3,9,11,13,33,34,36],quit:[1,5,6,9,10,12,30,32,35,36],quot:4,r2:[0,5,6,29,30,31,33],r2_score:[0,29],r2score:[0,29],r:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,21,22,23,24,26,30,31,32,33,34,35,36],r_1:9,r_2:9,r_j:9,r_m:9,rad:0,radial:[0,8,12,35,36],radioact:26,radiu:[0,1,9,30],rag:2,rain:9,rais:[0,2,3,4,7,14,31,33],ramp:[1,36],ran0:26,ran1:26,ran2:26,ran3:26,rand:[0,4,5,6,9,10,13,15,16,21,23,29,30,31,32,33,34,35],randint:[6,9,13,21,32,34,35],randn:[0,1,2,5,6,9,11,13,15,16,21,29,30,31,32,33,34,35,36],random:[0,1,2,3,4,5,6,8,9,13,14,15,16,21,22,23,24,29,30,31,32,34,35,36],random_forest_model:10,random_index:[13,21,34,35],random_indic:[1,3],random_st:[0,7,8,9,10,11,33,35,36],randomforestclassifi:10,randomizedsearchcv:33,randomli:[1,6,9,13,14,21,32,33,34,35],randuniform:33,rang:[0,1,2,3,4,5,6,7,9,10,11,12,13,14,21,23,26,29,30,31,32,33,34,35,36],rangl:[0,6,11,26,29,30],rangle_x:26,rank:[5,30],rankdir:4,raphson:[1,8,13],rapidli:0,rare:[1,13,29,33,34,35,36],raschka:[29,30,31,32,33,34,35],rasckha:29,rashcka:36,rashkca:36,rate:[0,1,2,3,4,8,9,10,12,13,33,36],rather:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,23,26,29,30,31,32,33,34,35,36],ratio:[4,7,9,10,11,33],rational:[0,29],ravel:[5,6,7,8,9,10,11,13,23,30,32,33,34],raw:3,rbf:[8,11,12,35,36],rbf_kernel_svm_clf:8,rbf_pca:11,rc:[0,26],rc_temp:[0,7,33],rcond:[0,29,30],rcparam:[0,1,3,7,8,9,10,26,29,33],re:[2,4,13,33,34],reach:[1,4,5,6,9,10,11,12,13,14,31,32,33,34,35,36],read:[0,2,3,4,5,6,7,8,11,12,16,21,23,24,25,26,28,31,34],read_csv:[0,6,7,9,29,32,33],read_fwf:[0,29],reader:[0,6,23,26,29,30,31],readi:[0,1,5,6,8,10,11,12,23,24,29,31,32,36],readili:1,readthedoc:22,real:[0,1,2,4,7,10,11,12,23,30,32,33,35],real_loss:4,real_output:4,realist:8,realiti:26,realiz:[1,12,35],realli:[0,1,29,36],rearrang:[13,34,35],reason:[0,1,3,4,10,13,28,29,33,34,35,36],reassign:1,recal:[5,6,9,10,11,12,23,26,29,30,31,32,33,34,36],recast:3,receiv:[1,3,10,12,26,35,36],recent:[0,1,2,3,4,6,7,10,13,14,21,24,28,29,31,32,33,34,35,36],recept:[3,12,35,36],receptive_field:3,recip:[0,6,7,23,24,29,30,33],reciproc:[5,31],recogn:[0,4,5,10,29,31,32],recognit:[0,1,3,12,25,28,29,35,36],recommen:29,recommend:[0,2,3,4,5,6,8,13,15,18,21,22,23,24,28,31,32,34,35],reconsid:9,reconstruct:11,record:[10,24,25,27,29,34,35],rectangl:[9,13,33,34],rectangular:[5,30],rectifi:[1,3,12,35,36],recur:[0,22,29],recurr:[0,1,22,29],recurs:[9,22,23,29],red:[0,3,4,6,8,9,21,32,34,35],redefin:[0,10,29,30],redefinit:31,reduc:[1,2,3,5,6,9,10,11,13,21,29,31,32,33,34,35],reduct:[0,2,10,11,22,26,29,30],refer:[0,1,2,3,5,6,9,11,12,13,14,20,23,28,29,30,32,33,34,35,36],referenc:[2,36],refin:[12,35,36],refit:[6,32],reflect:[0,1,4,5,24,26,29],refresh:[22,29],refreshprogrammingskil:29,reg:[10,11],regard:[1,9,13,34,36],regardless:[12,35,36],region:[3,4,6,9,12,24,35,36],regist:[6,24,26],reglasso:[5,31],regr_1:[0,9],regr_2:[0,9],regr_3:[0,9],regress:[1,8,11,12,15,16,21,22,23],regressor:[0,7,10,29,33],regridg:[0,5,6,31,33],regular:[0,3,4,5,6,7,9,13,17,27,29,30,31,32,34,35,36],regularis:6,reilli:[0,15,28,29],reinforc:[0,8,22,29],reiter:1,reject:7,rel:[0,4,6,7,9,12,13,26,29,30,32,33,34,35,36],relat:[0,1,3,4,5,11,13,14,23,26,29,31,32,34,35,36],relationship:[0,4,9,29],relativeerror:[0,29,30],releas:[1,22,29],relev:[0,1,5,7,11,15,21,22,24,26,29,31],reli:[0,6,8],reliabilti:24,reliabl:[7,26,33],relu:[3,4,29],remain:[1,2,4,6,12,23,26,30,31,32,33,35,36],remaind:26,reman:2,remark:[1,36],rememb:[0,8,13,23,24,29,34,35],remind:[0,5,11,13,23,26,30,31,32],remov:[0,4,5,6,30,31],render:[0,9,29,30],reorder:[5,7,30,31,33],reorgan:[0,29],repeat:[0,1,3,4,5,6,9,10,11,13,14,21,23,24,26,29,31,32,33,34,35,36],repeated:29,repeatedli:[0,6,10,13,32,34,35],repet:3,repetit:[6,29,30,32,33,34],rephras:[13,33,34],replac:[0,1,3,4,5,6,10,12,14,15,16,21,22,24,29,30,31,32,33,36],replica:[6,32],repo:24,report:[20,29,34,35],reportexampl:[20,24],reportsampl:20,repositori:[0,4,24,29],repres:[0,1,2,3,4,5,6,7,8,9,10,12,13,26,29,30,31,32,33,34,35,36],represent:[0,1,3,6,9,26,29,32,33],representd:3,reproduc:[0,5,6,9,12,15,16,22,24,26,29,30,36],repuls:[0,29],request:[0,13,21,34,35],requir:[0,1,3,4,5,6,8,9,11,12,13,17,23,29,30,31,32,33,34,35,36],rerun:9,res1:2,res2:2,res3:2,res_analyt:2,res_analytical1:2,res_analytical2:2,res_analytical3:2,resaml:[6,24],resampl:[0,7,10,19,22,29,30,33,34],rescal:[0,11,12,30,35],rescu:[5,31,32],reseach:[6,24],research:[0,4,13,21,22,28,29,34,35],resembl:[6,26,32],reserv:[1,5,6,26,31,32],reshap:[0,1,2,3,4,6,8,9,10,15,16,23,29,30,32],residenti:0,residu:[0,5,13,29,34],resiz:[5,30],resourc:29,respect:[0,1,2,3,5,6,7,8,10,11,12,13,14,16,17,21,24,26,29,30,31,32,33,34,35,36],respond:[12,35,36],respons:[0,7,9,12,29,30,33,35,36],rest:[0,5,30],restat:[0,12,29],restor:4,restored_discrimin:4,restored_gener:4,restrict:[0,3,9,12,29,35,36],result:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,21,22,23,24,26,29,32,33,34,35],retail:0,retain:[5,6,30,32,33],rethink:32,retriev:29,return_data:14,return_sequ:4,return_x_i:9,reus:[1,3,6,18,19,20,24,36],reveal:[0,12,29,35,36],revers:[1,23],review:[22,23],revisit:[14,36],revolut:29,reward:[0,4,29],rewrit:[0,3,5,6,7,8,10,11,12,13,19,23,24,26,31,33,34,35,36],rewritten:[2,6,8,10,26,32],rewrot:[13,33,34],rf:10,rgb:3,rgoj5yh7evk:22,rh:[6,32],rho:[0,10,13,21,29,34,35],rho_1:10,rho_2:10,rho_m:10,rich:[0,29],ride:9,rideclass:9,ridedata:9,ridg:[7,11,13,21,22,29],ridge_sk:6,ridgebeta:[5,31],ridgecv:33,right:[0,1,2,3,5,6,7,8,9,10,12,13,14,16,17,19,23,24,26,29,30,31,32,33,34,35,36],right_sid:2,rightarrow:[0,1,5,6,8,11,12,13,26,29,30,32,33,34,35,36],rigor:[0,29],ring:6,rise:[0,29],risk:[0,13,15,16,29,33,34,35],rival:4,river:0,rlm:29,rm:[0,26],rmse:0,rmsporp:[13,21,34,35],rmsprop:[1,3,4,13,36],rnd_clf:10,rng:26,rnn1:4,rnn2:4,rnn:[4,12,35,36],rnn_2layer:4,rnn_input:4,rnn_output:4,rnn_train:4,rntrick1:26,rntrick2:26,rntrick3:26,rntrick4:26,ro:[0,13,21,29,33,34,35],robert:[18,24,28],robust:[0,29],robustscal:[0,30],roc:[7,10],role:[0,2,5,6,8,22,29,30,31,32,33,36],roll:6,room:[0,27,29],root:[0,5,9,13,26,30,31,33,34,35],rot:29,rotat:[1,8,9,10],rotation_matrix:9,roughli:[1,3,36],round:[0,7,9,13,33,34,35],routin:[13,23,29,33,34],row:[0,1,2,5,6,9,11,23,29,30,31,32],row_stack:[],rr:[5,30],rrr:[5,30],rug:[13,33,34,35],rule:[0,1,5,6,13,24,29,30,31,32,34,35],run:[0,1,2,4,5,6,8,9,11,13,15,21,22,24,29,30,31,32,33,34,35],runtim:[1,6,14,36],runtimewarn:[1,6,32],rust:[0,15,22,23,29],rvert:1,rvert_2:1,s:[0,1,2,3,4,5,6,7,9,11,12,13,16,17,18,22,23,24,26,29,30,31,36],s_1:6,s_:[3,6],s_i:[6,7,33],s_j:6,s_k:6,saddl:[13,33,34,35],sai:[0,1,2,3,4,5,6,7,8,9,10,11,12,23,24,26,29,30,31,32,33,36],said:[6,9,13,33,34],sake:[0,5,7,11,29,30,31,33,36],sale:[0,29],sam:29,same:[0,1,2,3,4,5,6,8,9,11,12,14,17,23,24,26,29,30,31,33,36],samm:10,sampl:[0,1,2,3,4,5,6,7,8,9,10,13,14,15,16,19,21,22,23,24,26,29,30,31,32,33,34,35,36],sample_vari:14,sampleexptvari:26,samwis:29,sastri:11,satisfactori:[0,29],satisfi:[1,2,3,6,8,13,23,26,32,33,34],satur:[1,6,32,36],save:[0,4,6,7,9,13,21,29,30,32,33,34,35],save_fig:[0,6,7,9,10,29,30,32,33],savefig:[0,4,6,7,9,26,29,30,32,33],savetxt:4,saw:[5,30],scalabl:10,scalar:[2,5,6,10,30,31,32,36],scale:[0,1,3,5,6,7,8,9,10,11,12,13,15,16,17,21,22,23,24,27,29,31,33,34,35,36],scale_mean:4,scale_std:4,scaler:[0,7,8,9,10,11,24,30,31],scan:[5,7,31,32,33],scari:[5,31,32],scatter:[0,1,6,7,8,9,14,21,29,30,31,32,33,35],scenario:[6,13,33,34,35],schedul:[13,27,34,35],scheme:[1,13,33,34,35,36],schrage:26,scienc:[0,1,10,12,13,22,25,26,27,28,33,34,35,36],scientif:[0,15,22,24,29,34,35],scientist:[0,29],scikit:[3,5,6,8,9,10,13,21,22,23,24,25,28,35,36],scikit_learn:[0,16],scikitlearn:29,scikitplot:[7,10,33],scipi:[0,3,5,6,13,15,22,23,24,29,30,31,32,33,34],scl:6,score:[0,1,3,6,7,9,10,11,15,16,24,27,29,30,32,33,34,35,36],scores_kfold:[6,32,33],scratch:[1,13,35,36],sdg:[13,21,34,35],sdv4f4s2sb8:35,seaborn:[0,1,3,6,7,21,29,33],seamless:[0,15,22,24,29],search:[0,1,3,5,9,13,29,31,34,35,36],sebastian:[29,36],sebastianraschka:29,sec:6,second:[0,2,3,4,5,6,7,8,9,11,12,14,15,16,22,23,24,26,27,29,30,32,33,36],second_mo:[21,34,35],second_term:[21,34,35],secondeigvector:11,secondli:[12,36],section:[4,11,16,17,23,24,26,30,31,33,34,35],sector:0,see:[0,1,2,3,4,5,6,7,8,10,11,12,13,15,16,17,18,21,22,23,24,26,29,30,31,32,33,34,35,36],seed:[0,1,2,3,4,5,6,8,9,11,13,14,15,16,21,24,26,29,30,31,32,33,34,35,36],seed_imag:4,seek:[1,2,8,36],seem:[1,3,4,34,35,36],seemingli:[0,29],seen:[0,1,3,5,10,12,17,26,29],segment:[13,33,34],seismic:6,seldomli:[0,29],select:[1,5,6,8,9,10,11,17,24,25,26,27,28,29,30,31,32],self:[0,1,5,7,21,29,30,31,33,35],sell:4,semest:[7,25,33],semi:[8,13,33,34],semilogx:6,send:[5,12,13,27,29,34,35,36],senior:[25,27],sens:[0,4,6,8,24,29,32],sensibl:3,sensit:[0,5,6,9,13,29,30,31,32,35],sent:[2,36],sentdex:[35,36],sentenc:[4,12,35,36],separ:[0,1,2,4,6,8,9,12,14,15,22,24,26,29,32,35,36],septemb:[17,18,19,20,24,29],sequenc:[2,3,4,7,9,10,12,13,22,23,26,29,33,34,35,36],sequenti:[1,3,4,10,12,26,35,36],seri:[0,1,2,3,4,5,6,10,11,12,13,23,29,30,31,32,33,34,35,36],serif:[0,7,26,29,33],serv:[0,1,2,3,5,7,13,21,24,28,29,30,31,32,33,34,35,36],servic:24,session:[1,20,24,25,27,29],set:[1,4,5,6,7,8,10,11,13,14,16,17,21,22,23,24,26,27,31,32,34,35],set_major_formatt:[6,24],set_major_loc:[6,24],set_tick:[1,6,8],set_ticklabel:[1,6],set_titl:[0,1,2,3,7,12,14,29,33,35,36],set_xlabel:[0,1,2,3,7,12,29,33,35,36],set_xlim:[7,12,33,35,36],set_xticklabel:1,set_ylabel:[0,1,2,3,7,29,33],set_ylim:[7,12,33,35,36],set_ytick:[7,33],set_yticklabel:[1,6],set_zlim:[6,24],seth:4,setminu:[6,33],setosa:[8,9],setosa_or_versicolor:8,setp:[6,32],setup:[1,4,6,8,21,22,29,30,36],sever:[0,3,5,6,7,8,9,11,12,13,21,22,23,26,29,30,31,32,33,34,35,36],sgd:[1,3,21,33],sgd_clf:8,sgdclassifi:8,sgdreg:[13,33,34],sgdregressor:[13,33,34],sgn:[5,30,31],shallow:[13,34,35],shape:[0,1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,23,29,30,31,32,33,34,35,36],shape_bas:[],share:[1,3,29,36],she:[7,33],shell:[21,35],shift:[1,6,12,26,31,35,36],ship:3,shire:29,shortcom:[13,33,34,35],shorten:4,shorter:26,shorthand:[29,32],shortli:[23,29],should:[0,2,3,5,6,8,9,11,12,15,16,21,23,24,26,29,30,31,32],show:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,19,21,23,24,26,29,30,31,32,33,34,35,36],show_shap:4,shown:[0,4,5,8,9,11,12,13,21,23,30,33,34,35,36],shrink:[3,5,6,8,11,24,30,31],shrinkag:[5,6,30,31],shrunk:11,shuffl:[0,1,4,6,13,21,30,32,33,34,35],sickit:36,side:[0,2,5,8,12,13,23,29,31,32,33,34,35,36],sigh:[22,29],sigma0:26,sigma1:26,sigma2:26,sigma:[0,1,5,6,7,10,11,12,13,17,18,19,23,24,26,29,30,31,32,33,34,35,36],sigma_0:[5,30,31],sigma_1:[5,30,31,36],sigma_2:[5,30,31,36],sigma_:[5,23,29,30,31,32],sigma_fn:[7,12,33,35,36],sigma_i:[0,5,29,30,31],sigma_j:[5,17,30,31],sigma_m:[6,26,32],sigma_n:[11,26],sigma_t:[13,34,35],sigma_x:26,sigmoid:[1,2,4,7,8,10,12,33,34,35],sigmundson:[6,30,31],sign:[1,2,7,8,10,26,27,33,35],signal:[1,3,10,12,35,36],signifi:4,signific:[1,36],significantli:[1,13,21,26,33,34,35,36],sigurd:29,sim:[4,5,6,13,18,24,26,31,32,34,35],similar:[0,1,2,3,4,5,6,7,8,9,10,11,14,17,22,23,24,29,31,32,33,36],similarli:[0,1,3,5,8,10,13,20,26,29,30,31,36],simpl:[1,2,3,5,6,7,8,10,11,12,14,15,16,17,19,21,22,23,24,26,32],simplepredict:10,simpler:[0,1,5,6,7,13,16,19,21,22,24,29,31,34,35],simplernn:4,simplest:[0,1,3,4,9,10,12,14,29,35,36],simpletre:10,simpli:[0,1,2,4,5,6,8,9,10,11,12,15,22,23,24,26,29,30,31,32,35,36],simplic:[2,5,6,7,8,9,10,11,12,14,30,31,33,35,36],simplicti:[5,30],simplif:36,simplifi:[0,6,9,15,22,24,29,30,31,32,36],simplist:[3,6,26,32],simul:[6,32],simultan:[6,32],sin:[0,1,2,3,4,9,12,13,21,23,29,34,35,36],sinc:[0,1,2,3,5,6,7,8,9,10,11,13,21,23,26,28,29,30,31,32,33,34,35,36],sine:[3,12,35,36],singl:[0,1,2,3,5,6,7,8,9,12,13,23,26,29,30,31,32,33,34],singular:[0,6,13,23,24,29,31,32,33,34],sinusoid:3,site:[0,2,3,4,6,7,8,9,11,14,21,24,25,29,31,33,35],situat:[0,4,5,7,13,21,26,29,30,33,34,35],six:[3,26,36],size:[0,1,2,3,4,5,6,8,9,10,11,13,21,23,24,26,29,31,32,33,34,35,36],sketch:10,ski:9,skill:0,skip:11,skl:[0,6,29,30,31],sklearn:[0,1,3,5,6,7,8,9,10,11,13,14,29,30,31,32,33,34,35,36],skplt:[7,10,33],sl:[6,31,33],slack:8,slice:[2,23,29],slide:[0,3,15,16,24,26,29,30,32,34,36],slight:[6,13,32,34,35],slightli:[1,2,3,5,6,7,10,26,30,31,32,33,36],slope:[8,11,12,35],slow:[0,2,8,13,30,33,34,35],slower:[5,23,29,30,31],slowest:23,slowli:12,slp:1,small:[0,1,2,3,5,6,8,9,10,11,12,13,21,22,23,24,26,29,30,31,32,33,34,35,36],smaller:[0,1,2,5,6,8,9,11,13,26,29,30,31,32,33,34,35,36],smallest:[0,4,14,15,16,29,33],smallest_row_index:14,smooth:[0,3,6,9,13,24,29,33,34],sn:[0,1,3,6,7,29,33],sne:11,sneak:29,so:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,19,21,22,23,24,26,27,29,30,31,32,33,34,35,36],soar:6,social:0,soft:[1,7,10,12,33,35,36],soften:8,softmax:[3,7,33,36],softwar:[0,8,15,22,23,36],sol:8,sole:[0,6,29],solid:[0,7,33],solut:[0,1,2,3,5,6,8,10,11,13,17,18,23,24,26,29,30,31,32,33,34,35,36],solution_ev:34,soluton:2,solv:[0,1,3,5,6,8,10,11,12,13,23,24,29,30,35,36],solve_expdec:2,solve_ode_deep_neural_network:2,solve_ode_neural_network:2,solve_pde_deep_neural_network:2,solveod:2,solveode_popul:2,solver:[2,7,8,9,10,11,21,23,29,33,35],some:[0,1,2,3,4,5,6,7,8,9,10,11,12,14,24,26,29,31,32,35],some_model:[6,30,31],somehow:4,someth:[0,1,3,4,7,9,11,24,26,29,30,33,36],sometim:[0,1,11,12,13,14,29,30,34,35,36],somewhat:[35,36],soon:[23,27,30],sophist:[0,29],sopt:[13,34],sort:[5,6,9,11,26,30,32],sound:[3,5,31,32],sourc:[0,1,3,6,15,22,23,24,26,29,32],space:[0,1,4,5,8,9,11,12,13,14,21,26,30,31,32,33,34,35,36],span:[0,3,5,9,11,23,29,30],spare:[1,36],spars:[3,6,23,29],sparse_mtx:[23,29],sparsecategoricalcrossentropi:3,sparsiti:10,spatial:[1,2,3,12,35,36],speak:26,special:[6,7,10,12,13,23,26,29,30,31,33,34,36],specif:[0,1,2,3,4,5,6,7,8,9,11,12,16,22,23,24,26,28,29,30,31,32,33,35,36],specifi:[0,3,5,6,7,9,11,13,14,21,24,26,29,31,32,33,34,35],specifici:[0,10,29],spectacular:3,spectral:1,speech:[0,1,3,4,12,35,36],speed:[1,2,4,13,34,35,36],spend:26,spent:24,sphere:[0,30],spin:6,spite:0,spline:8,split:[1,3,4,5,6,8,9,10,11,14,17,24,26,31,32,33],splite:0,splitter:[1,10],spontan:26,spot:3,spread:[0,11,26,29,30],springer:[18,24,28,29,32],spuriou:[13,21,34,35],sqquar:31,sqrsignal:3,sqrt:[0,3,4,5,6,8,10,11,13,17,21,26,30,31,32,34,35,36],squar:[1,2,3,4,7,8,9,11,13,14,15,16,17,19,21,22,23,26,32,33,34,35,36],squarederror:10,squaredeuclidean:14,squash:[12,35,36],srtm:[6,24],srtm_data_norway_1:[6,24],stabil:[5,24],stabl:[0,4,5,6,9,11,22,24,29,30,31],stack:[3,4],stage:[5,13,21,24,34,35,36],stai:[0,2,4,5,11,17,29,30],stand:[0,5,9,12,29,30,31,35],standadscal:30,standard:[0,1,4,5,6,7,8,10,12,15,16,17,19,21,23,24,26,29,31,33,35,36],standard_basi:[],standardscal:[0,6,7,8,9,10,11,30,31],stanford:[13,33],start:[0,1,2,3,4,5,6,8,9,10,11,12,13,14,20,23,26,27,29,30,32,33,34,36],start_box:[],start_nod:[],start_tim:14,starting_point:[21,35],stat:[6,32,33],state:[1,2,4,5,6,7,8,10,11,12,13,22,26,30,31,32,33,34,35,36],statement:[0,7,23,29,33],stationari:[33,34],statist:[0,1,3,4,7,9,10,11,12,13,14,18,23,24,25,28,30,33,34,35,36],statu:[0,7,9,11,29,33],stavang:[6,24],std:[0,4,6,29,30,32],steep:[13,21,33,34,35],steepest:35,step:[0,1,2,4,6,7,9,10,11,12,13,14,21,23,24,29,36],step_fn:[7,12,33,35,36],step_length:[13,34,35],step_siz:34,steps_list:9,stereo:3,still:[0,2,3,5,6,11,13,17,26,32,33,34,35,36],stimuli:[12,35,36],stk2100:[28,29],stk3155:[15,24,25,27],stk4021:[28,29],stk4051:[28,29],stk4155:[25,27],stk5000:28,stk:[28,29],stochast:[0,1,5,6,8,11,12,15,16,24,29,31,32,33,36],stock:4,stoke:[12,35,36],stone:[0,7,24,33,36],stop:[1,4,9,11,13,14,21,33,36],stopiter:[0,7,33],storag:[5,30],store:[0,1,2,3,6,11,13,24,26,29,34,35],storehaug:[27,29],str:[1,3,4],straight:[0,6,8,13,29,32,33,34],straightforward:[0,2,3,5,6,8,9,10,13,23,29,30,31,32,33,34],strategi:[0,1,9,29],stratifi:[6,32],strength:[0,5,14,30],stretch:11,strict:[8,13,33,34],strictli:[8,13,33,34],stride:[4,23],strike:6,string:1,stroke:[7,33],strong:[3,6,9,10,12,23,26,32,35,36],strongli:[0,8,22,23],stronli:0,structur:[0,1,2,3,6,9,10,12,22,29,32,33,34,35],stuck:[1,13,33,34,35,36],student:[0,24,25,27,28,29],studi:[0,3,4,5,6,7,8,11,12,13,17,19,21,22,24,28,29,30,31,34,35,36],studier:28,style:[0,7,9,23,29,33],sub:[9,12,35,36],subarg:[],subdivid:[0,23,29],subfield:0,subject:[6,8,26],submit:29,subplot:[0,1,3,4,6,7,8,9,10,14,29,32,33],subplots_adjust:[8,26],subprogram:[23,29],subract:[0,30],subroutin:[0,29],subscript:1,subsequ:[1,4,5,6,12,23,26,30,32,35,36],subset:[1,6,9,12,13,22,29,32,33,34,35,36],subspac:[0,8,11,30],substanti:[9,10],substep:11,substitut:[3,6,12,23,32,35],subsubset:9,subtask:6,subtl:[1,36],subtract:[0,4,5,6,11,13,17,21,23,24,26,31,32,34,35],subtre:9,subval:[],succeed:[0,4,29],success:[3,7,9,13,26,33,34],successfulli:[4,9],sudo:[0,15,22,24,29],suffer:[0,1,2,5,10,29,30,31,36],suffici:[1,6,8,11,13,32,33,34],suggest:[1,13,24,28,34,36],suit:[8,12,35,36],suitabl:[0,26,30],sum:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,21,23,24,26,29,30,31,33,34,35],sum_:[0,1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,23,24,26,29,30,31,32,33,34,35,36],sum_i:[0,2,5,6,8,13,17,19,24,30,31,32,34,35],sum_j:6,sum_ja_:0,sum_k:[6,8,12,23,36],sum_logist:[13,34],sum_m:3,sum_n:3,sum_nx_:3,summar:[5,6,9,31,32,33,35],summari:[1,3,4,10,21,25,31],summat:[0,3,16,30],sunni:9,superconduct:31,superfici:3,superscript:[1,12,35,36],supervis:[0,5,6,7,9,12,22,29,30,32,33,35],supplement:[7,24,33],support:[0,1,9,10,11,13,22,29,30,34,36],suppos:[0,5,6,7,8,10,11,12,13,23,29,30,31,32,33,34,35,36],suppress:[5,8,13,31,34,35],sure:[0,1,4,6,24,36],surf:[6,24],surfac:[0,6,24,29],surpass:6,surpris:[0,29],surround:[3,22],survei:[0,5,6,29,30,31,32],svc:[8,9,10],svd:[0,6,11,17,29,32],svdinv:[5,31],svm:[8,9,10,11],svm_clf:[8,10],swath:[5,30],sy:[13,33,34],symbol:[1,3,4,5,11,13,14,22,26,29,30,31,34,35,36],symmeteri:1,symmetr:[0,5,8,11,12,13,23,29,30,34,35,36],symmetri:[6,9],sympi:[0,15,22,24,29,36],synonim:26,syntax:13,syntaxerror:8,system:[0,1,3,4,6,7,9,10,12,13,15,22,23,24,29,33,34,35,36],systemat:[4,6,32],t0:[3,6,13,21,34,35],t1:[2,13,21,34,35],t2:2,t3:2,t:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23,24,26,27,29,32,33,34,35,36],t_0:[2,9,13,34,35],t_1:[13,34,35],t_:2,t_b:10,t_i:[1,2,5,12,30],t_j:12,t_k:9,tabl:[9,24,26,27,29,35,36],tabul:[0,29],tabular:29,tackl:4,tag:[2,3,4,5,6,7,12,13,14,21,23,26,30,33,34,35,36],tagrget:36,taht:[0,29],tail:26,tailor:[2,8,11,29,36],taiwan:[0,29],take:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,16,21,22,23,26,29,30,31,32,33,34,35,36],taken:[0,1,3,6,10,13,23,29,32,34],tan:3,tangent:[1,4,12,13,33,34,35,36],tanh:[1,4,7,8,12,33,34,35,36],target:[0,1,2,3,4,5,6,7,8,9,10,11,12,29,30,31,32,33,34,35,36],target_iscomplex:2,target_meta:2,target_nam:9,target_ndim:[],target_shap:2,task:[0,1,3,6,9,11,12,14,20,24,29,32,35,36],tau:[3,5,26,31,32],taught:29,tax:0,taylor:[2,13,33,34,36],taylornr:[13,33,34],tba:[],tc:8,td:[1,6,29,32],teach:29,team:1,teaser:0,technic:[0,5,6,13,15,24,29,30,34,35],techniqu:[0,1,8,10,13,22,26,28,29,30,32,33,34,35,36],technolog:[0,1],tell:[0,4,6,10,11,13,26,32,34,35],temp1:1,temp2:1,temp:1,temperatur:[0,9,29],temporarili:[1,36],ten:[3,17,29,36],tend:[3,5,6,8,9,10,12,13,14,21,30,31,32,34,35],tendenc:[0,29],tension:[6,32],tensor:3,tensordot:[],tensordot_adjoint_0:[],tensordot_adjoint_1:[],tensorflow:[0,2,4,8,14,15,22,23,24,25,28,29,30],term1:[5,6,11,24,30],term2:[5,6,11,24,30],term3:[5,6,11,24,30],term4:[5,6,11,24,30],term:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,21,24,26,29,30,31,33,34,35],termin:[0,4,5,9,10,13,15,21,29,30,34,35],terrain1:[6,24],terrain:[6,21,24],test:[3,4,5,6,7,8,9,10,13,17,19,21,23,24,26,32,33,34,35,36],test_acc:3,test_accuraci:[1,3],test_error:6,test_imag:[3,4],test_ind:[6,32,33],test_input:4,test_label:[3,4],test_loss:3,test_pr:1,test_predict:1,test_rnn:4,test_scor:[7,10,33],test_siz:[0,1,3,5,6,10,29,30,31,32,33],test_split:9,tester:31,testerror:[0,6,30,32],testi:4,testpredict:4,testx:4,text:[0,1,2,4,5,8,9,11,13,15,21,23,26,28,30,32,33,34,35],textbook:[16,17,21,24,30,32],textual:9,textur:[1,9],tf:[1,3,4,13,14,33,34],tf_loadlibrari:[3,4,14],th:[0,1,2,5,6,7,9,12,13,14,15,16,23,24,26,29,30,31,32,33,34,35,36],than:[0,1,2,3,4,5,6,7,9,10,11,12,13,17,22,26,29,30,31,32,35,36],thank:[4,6,30,31],theano:[1,22,29],thei:[0,1,2,3,4,5,6,7,8,9,11,12,13,23,24,26,29,30,31,32,33,34,35,36],them:[0,1,3,4,6,8,9,10,11,12,13,23,24,29,30,31,34,35,36],theme:[0,29,34],themselv:[0,26,29],thenc:[6,32],theorem:[2,6,7,30,33,35],theoret:[0,4,10,29],theori:[0,1,3,8,9,12,13,18,22,24,28,29,31,34,35,36],thereaft:[0,5,6,11,12,15,16,17,23,24,29,32,36],therebi:[0,5,7,11,29,30,31,33,36],therefor:[0,1,2,3,4,6,7,8,11,13,26,29,30,32,33,34,35],therein:11,thereof:[0,6,13,29,32,34,35],theta:[1,4,13,21,26,34,35,36],theta_:[1,13,34,35],theta_i:1,theta_linreg:[13,21,34,35],theta_t:[13,34,35],thetaand:[35,36],thetaor:[35,36],thetaxor:[35,36],thi:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,22,23,24,25,26,28,30,31,32,33,34,35],thing:[0,1,2,4,5,7,9,26,29,31,32,33,36],think:[0,1,3,4,6,9,12,13,14,26,29,32,33,34,35,36],third:[0,3,6,13,21,27,29,33,34,35],thirti:[7,33],thorughout:29,those:[0,3,5,6,8,9,10,11,21,23,24,25,29,30,32,36],though:[1,2,3,4,13,23,26,34,35],thought:[6,14,24,26,32],thousand:[0,1,24,30,34,35,36],three:[0,1,3,5,6,8,9,12,15,23,24,25,26,27,29,30,31,32,33,35],threshold:[1,3,9,10,11,12,13,34,35,36],through:[0,1,2,3,4,5,6,8,11,12,13,14,22,23,26,29,30,31,32,33,34,35],throughout:[0,4,5,14,22,23,26,29],thu:[0,1,2,5,6,7,8,10,11,12,13,21,24,27,29,30,31,32,33,34,35,36],thumb:[0,6,24,29,30],thursdai:[27,30],tibshirani:[6,18,24,25,28,29,32],tick:6,tick_param:6,ticker:[6,13,24,26,33,34],tif:[6,24],tight_layout:[1,7,33],tightli:11,tild:[0,5,6,7,11,15,16,17,18,19,24,26,29,30,31,32,36],till:[0,4,7,8,9,10,12,23,29,30,31,33,36],time:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,21,22,23,24,26,29,30,31,32,33,36],timeit:4,timer:4,tini:[1,36],tip:3,titl:[0,1,2,3,4,6,7,8,9,10,13,21,24,26,29,32,33,34,35,36],tmp:[13,34,35],tn:[2,3,7],to_categor:[1,3,4],to_categorical_numpi:1,to_numer:[0,6,29,32],todai:3,togeth:[0,3,6,8,11,13,21,22,29,34,35],toi:[14,34,35],told:[13,34],toler:[2,6,14],tolist:4,tomographi:[12,35,36],too:[0,2,4,5,6,9,11,13,15,26,28,29,30,32,33,34,35],took:[8,29],tool:[0,1,3,6,13,22,30,32,34,35,36],toolbox:8,top:[0,3,5,6,9,10,18,22,29,31,32],topic:[0,5,6,7,8,22,24,30,31,33],topograph:24,topolog:[1,3,12,35,36],toposort:2,torkjellsdatt:[27,29],toss:[10,26],total:[0,1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,23,26,27,29,30,32,33,34,36],total_loss:4,totalclustervari:14,totalscatt:14,toward:[1,2,7,12,13,24,33,34],towardsdatasci:[34,35],town:0,tp:[4,7],tpng:9,tpu:[13,21,22,29,34,35],tqdm:6,tr:30,trace:2,trace_stack:[],traceback:[0,1,2,3,4,6,7,10,13,14,24,29,31,33],tracer:2,track:[3,13,14,23,30,33,34,35],tract:0,tractabl:[0,29,30],trade:[5,9,19,31,32],tradeoff:[0,5,19,24,29,30,31,33],tradit:[0,1,4,6,29,32],train:[2,3,5,6,8,9,10,11,12,13,17,19,21,24,31,32,33,34,35],train_accuraci:[0,1,3,29],train_dataset:4,train_end:[0,1,30],train_error:6,train_imag:[3,4],train_ind:[6,32,33],train_label:[3,4],train_pr:1,train_siz:[0,1,3,30],train_step:4,train_test_split:[0,1,3,5,6,7,9,10,11,29,30,31,32,33],train_test_split_numpi:[0,1,30],trainable_vari:4,trained_model:[6,30,31],trainerror:[0,30],traini:4,training_checkpoint:4,training_dataset:4,training_gradi:[13,21,34,35],training_gradient_fun:[34,35],training_loss:[34,35],trainingerror:[6,32],trainpredict:4,trainscor:4,trainx:4,trait:[0,29],trajectori:4,trajectory_i:[21,35],trajectory_x:[21,35],transfer:9,transform:[0,5,6,7,8,9,10,11,12,13,21,22,23,29,30,31,32,33,34,35,36],transit:[6,12,35,36],translat:[1,4,6,10,29,30,31],transpos:[1,5,11,23,30,31],travers:[0,5],treat:[0,1,3,6,12,13,26,29,30,31,32,33,34,35,36],tree:[0,1,6,22,24,29,36],tree_clf:[9,10],tree_clf_:9,tree_clf_sr:9,tree_reg1:9,tree_reg2:9,tree_reg:9,trend:26,treue:7,trevor:[18,24,28],tri:[2,3,4,9,13,33,34],triain:0,trial:[0,2,4,6,13,26,29,32,33,34],triangl:[13,33,34],triangular:23,trick:[3,4,8,11,13,21,26,34,35],trickier:26,tridiagon:23,trigger:[0,7,33],trillion:22,trivial:[0,1,5,11,26,29,31],troubl:[0,8,12,30,36],truck:3,true_beta:[6,30,31],true_divid:1,true_fun:[6,32],truncat:[21,35,36],trust:9,tucker:8,tuesdai:[27,29,32,33,34],tumor:[7,9,33],tumour:[7,33],tunabl:[1,21],tune:[4,9,13,21,23,29,33,34,35],tup:[],tupl:2,turn:[0,1,5,6,7,8,9,10,11,12,13,19,23,24,26,29,30,32,33,34,35,36],tutori:[1,4],tv:2,tveito:2,tvw1zdmznwm:35,tweak:[1,4,10,26,36],twice:[13,33,34],twist:11,two:[0,1,2,4,5,6,7,9,10,11,12,13,15,16,23,25,26,28,29,31,32,34,35],tx:[13,33,34,35,36],tx_1:[13,33,34],txt:4,ty:[13,33,34],type:[0,1,3,6,8,10,13,16,23,24,26,30,31,32,33,34],typeerror:[2,6,13],typic:[0,1,2,3,4,5,7,9,10,12,13,21,26,29,30,31,32,33,34,35,36],typo:24,u:[0,2,5,6,8,10,11,12,17,23,29,30,31,35,36],u_:23,u_i:[12,35],u_m:10,ua:[0,29],ubuntu:[0,15,22,24,29],uci:0,ufunc:2,uio:[24,27,28],un:14,unabl:9,unari:[23,29],unary_f:2,unary_oper:2,unary_to_nari:2,unbalanc:[6,9,32,33],unbias:[0,5,6,29,31,32],unbroadcast:2,unbroadcast_f:2,uncent:[6,31],uncertainti:[0,5,29,31,32],uncertitud:26,unchang:[1,3,36],uncorrel:[10,26],undefin:[5,30],under:[0,1,5,6,10,13,15,16,22,24,29,30,31,32,33,34],underdetermin:[0,29],underfit:[1,6,32,36],underflowproblem:[5,31,32],undergo:[5,31,32],undergradu:[25,27],underli:[0,1,9,13,26,29,34,35,36],underset:[4,14],understand:[0,1,3,5,6,10,13,14,21,22,29,30,31,33,34,35,36],understood:[8,13,34,35],undesir:8,undetermin:[5,8,31,32],undo:4,unexpect:[6,13,32],unexpected:26,unfair:[6,30,31],unfortun:[1,8,9,10,36],unicode_liter:[8,9],uniform:[0,1,5,6,11,13,15,16,24,26,29,30,33,34],uniformli:[13,26,33,34,35],unifrompdf:26,unimport:[13,33,34],union:[5,6,31,32,33],uniqu:[0,2,6,13,14,23,29,32,33,34],unique_cluster_label:14,unit:[0,1,3,4,5,10,12,26,29,30,31,35,36],unitari:[5,6,23,30],unitarili:[23,29],uniti:26,univari:26,univers:[0,1,2,13,15,22,24,25,27,29,30,31,32,33,34,35],unix:1,unknow:[0,23,29],unknown:[0,1,3,4,5,6,8,10,13,16,21,23,29,30,31,32,34,35,36],unknowwn:12,unlabel:[1,36],unless:[0,3,6,11,13,24,29,32,33,34,36],unlik:[1,3,8,13,33,34,35,36],unnecessarili:9,unord:3,unravel:1,unrol:[3,11],unseen:[0,7,9,33],unstabl:[1,36],unsupervis:[0,1,4,12,22,29,35,36],unsymmetr:[23,29],until:[1,2,4,9,12,13,14,33,34,35,36],untouch:0,unusu:[12,35,36],up:[1,3,4,5,6,8,10,11,13,14,16,18,22,23,24,26,27,31,34],updat:[1,2,10,12,13,14,21,34,35],uploa:29,upload:[22,24,28],upon:[0,1,6,7,11,23,24,36],upper:[0,8,9,16,23,30],uppercas:[23,29],upsampl:4,upscal:4,uptad:36,url:[0,7,29,30,33,35],us:[4,5,6,8,9,10,11,12,14,15,16,17,18,19,23,25,26,28,31,32],usa:[29,35],usag:[0,8,22,29,30,35,36],usd10000:0,usd:0,use_bia:4,usecol:[0,29],useless:1,user:[0,1,2,3,4,6,7,8,9,11,14,15,21,22,23,24,29,30,31,33,35],usernam:24,userwarn:[6,21,35],usetex:26,usg:[6,24],usr:26,usual:[0,3,4,7,12,13,14,29,33,34,35,36],ut:[5,31],utf:[0,7,33],util:[1,3,4,6,7,10,14,29,32,33,36],ux:23,v0:26,v1:26,v2:26,v8xr:[35,36],v:[2,4,5,6,11,13,17,21,22,30,31,34,35,36],v_0:11,va:1,vahid:29,val:[13,34,35],val_accuraci:3,val_loss:4,vale:2,valid:[0,1,4,7,9,10,13,21,22,26,29,30,34,35,36],validation_data:3,validation_split:4,valu:[0,1,2,3,4,6,7,8,9,10,12,13,14,15,16,19,21,22,23,24,29,34,35,36],valuat:9,valueerror:[],valy:4,van:[0,18,24,29,30,31,32],vandenbergh:[8,13,33,34],vandermond:[0,29],vanilla:[0,6,11,14,30,31],vanish:[1,4,13,26,33,34],var_x:26,varabl:8,varepsilon:[5,6,18,24,31,32],varepsilon_:[5,6,31,32],varepsilon_i:[5,6,31,32],vari:[0,1,3,5,6,10,15,16,29,32,36],variabl:[0,1,2,5,6,7,8,10,11,12,13,14,21,23,29,30,31,32,35,36],varianc:[0,1,5,7,9,10,11,13,14,18,19,21,22,23,26,29,30,33,34,35,36],variance_i:[5,11,30],variance_x:[5,11,30],variant:[0,1,6,8,12,13,29,30,33,34,35,36],variat:[3,4,11,29],varieti:[0,3,12,15,22,24,29,35,36],variou:[1,3,5,6,7,8,9,11,12,13,16,18,21,22,23,24,26,30,31,34,35,36],varydimens:4,vastli:3,vaue:1,vault:0,vdot:[2,13,33,34],ve:24,vec:[6,32],vector:[0,1,2,3,4,5,6,7,9,10,11,13,14,16,17,21,22,31,32,33,34,36],vector_mean:14,ventur:[0,8,15,22,29],verbos:[1,3,4],veri:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,24,26,28,29,30,31,32,33,34,35,36],verifi:[3,11,23,29],versatil:[8,29],versicolor:[8,9],version:[0,3,10,13,14,15,22,23,24,26,29,34],versu:[1,36],vert:[0,1,5,6,7,8,9,11,13,17,29,30,31,32,33,34,36],vert_1:[5,6,30,31,32],vert_2:[5,6,11,17,30,31,32],via:[0,5,6,7,8,9,10,11,12,15,19,22,23,24,25,26,27,29,30,31,32,33,35,36],vidal:11,video:[0,1,12,22,25,27,29,30,31,32,36],view:[1,3,5,6,12,13,21,26,28,29,31,32,34,35],violat:8,virginica:9,viridi:[0,1,2,3,29],virtual:[1,36],viscos:[13,34,35],viscou:[13,34,35],visibledeprecationwarn:2,vision:[0,3],visual:[0,3,11,12,15,22,29,30,35,36],visualis:1,viz:[6,8,26],vjp:2,vjp_argnum:2,vjpfun:2,vjpmaker:[],vjpnode:[],vmap:[13,34],vmax:[1,6],vmh0zpt0tli:35,vmin:[1,6],voic:3,volum:[0,3,29],von:36,vote:10,voting_clf:10,votingclassifi:10,votingsimpl:10,vs:[0,4,6,34],vspace:2,vstack:[5,11,23,26,29,30],vt:[5,30,31],w1:8,w2:[8,11],w3:8,w:[0,1,2,3,4,5,6,7,8,10,11,12,13,14,23,26,29,30,32,33,34,35,36],w_0:36,w_1:[8,23,36],w_1a_0:36,w_1x:36,w_1x_1:8,w_1x_:8,w_2:[8,23,36],w_2a_1:36,w_2x_2:8,w_2x_:8,w_3:23,w_4:23,w_:[1,12,35,36],w_hidden:2,w_i:[1,2,10,36],w_ix_i:[12,35,36],w_j:23,w_m:23,w_output:2,w_px_:8,w_px_p:8,wa:[0,1,3,4,5,6,7,10,11,12,14,17,23,24,29,30,31,32,33,35,36],wai:[0,1,2,3,4,5,6,7,8,10,11,12,13,14,17,23,26,29,30,31,33,34],walk:9,walker:26,wang:[0,29],want:[0,1,2,3,4,5,6,8,9,10,11,12,13,14,15,16,17,22,24,26,29,30,31,32,33,34,35,36],warn:[4,8],warrant:[6,32,33],wast:[3,34,35],watch:[22,35,36],wave:3,wavelet:8,we:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,28,30,31,32,33],weak:[9,10,14],weather:[1,12,35,36],web:[22,25,27,29],webpag:29,websit:[6,23,24,25,29],wedg:[8,26,36],wednesdai:[27,29,32,33,34],wee:11,week:[0,5,6,7,24,25,27],weekli:[16,22,24,27,28,29,35],weierstrass:36,weight:[0,1,2,3,6,7,9,10,12,13,24,26,33,34,35,36],weigth:2,welchlab:[35,36],welcom:[8,22],well:[0,1,2,3,4,5,6,7,8,9,10,12,13,15,16,19,20,21,22,23,24,26,28,29,30,31,32,33,34,35,36],went:8,were:[0,1,3,4,5,6,7,8,10,11,12,14,26,29,30,32,33,35,36],wessel:[0,18,24,29,30,31,32],what:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,19,22,23,24,26,33,34,35,36],whatev:3,when:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,17,18,21,23,24,26,29,30,31,32,33,36],whenev:[13,21,26,34,35,36],where:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,21,22,23,24,26,27,29,30,31,32,33,34,35,36],wherea:[6,26,32],wherefrom:24,wherein:[1,12,35,36],whether:[0,3,5,7,9,24,26,29,31,33],which:[0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23,24,25,26,27,29,30,31,32,33],whichev:[1,3],white:9,whiteboard:[31,32,33,34,35,36],who:[0,25],whole:[1,3,4,5,9,11,13,31,32,34,35],whose:[0,6,10,26,30,32],whow:[11,30],why:[0,1,3,6,13,21,24,31,33,34],wide:[0,1,3,6,7,12,15,22,23,24,29,32,33,35,36],widehat:[6,32],width:[0,3,8,9,29],wieringen:[0,18,24,29,30,31,32],win:10,wind:9,wing:[27,29],winther:2,wiothout:[6,30],wiscons:[7,33],wisconsin:10,wisdom:[6,31],wise:[0,1,5,12,13,30,34,35],wish:[0,2,5,7,8,11,13,14,23,24,29,30,33,34,36],with_std:[0,30],wither:6,within:[0,2,3,4,7,9,12,13,14,26,28,29,33,34],withinclust:14,without:[0,1,5,6,8,9,11,12,13,21,29,30,31,32,34,35,36],wo5dmep_bbi:[35,36],won:[0,29,36],wonder:8,word:[0,1,3,4,5,6,7,14,26,29,30,31,32],work:[0,1,4,6,7,8,9,13,15,21,22,24,25,26,27,29,30,32,33,34,35,36],workshop:29,world:[0,8,30],worldwid:[0,29],wors:[0,1,3,4,6,29,32,36],worst:9,worth:9,worthi:24,would:[0,1,3,5,6,7,8,9,10,11,12,13,23,24,26,29,30,31,32,33,34,35,36],wrap:[6,23,29],wrap_util:2,write:[0,1,2,3,5,6,7,8,12,13,15,16,17,20,21,23,29,30,32,33,34,35,36],written:[0,2,3,5,11,12,13,16,22,23,24,26,29,30,31,32,33,34,35,36],wrong:[1,8,36],wrongli:10,wrote:[5,11,30],wrt:[2,10,13,21,34,35,36],wth:[10,13,21,34,35],wurstemberg:36,www:[22,23,24,28,29,31,35,36],wx_1:8,x0:8,x1:[4,8,9,10,13,34,35],x1_exampl:8,x1d:8,x2:[8,9,10,13,34,35],x2d:[8,11],x2d_train:11,x2dsl:11,x3:[8,9],x4:9,x:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,29,32,33,34,35,36],x_0:[0,5,11,23,29,30,31,32,36],x_1:[0,2,5,6,7,8,9,10,11,13,23,26,29,30,31,32,33,34,35,36],x_2:[0,2,5,6,7,8,9,10,11,13,23,26,29,30,32,33,34,35,36],x_3:[8,23,26,36],x_4:[23,36],x_5:36,x_:[0,2,3,5,6,8,10,11,13,14,18,23,24,26,29,30,31,32,33,34,36],x_center:11,x_data:1,x_data_ful:1,x_hidden:2,x_i:[0,1,2,5,6,7,8,9,10,11,12,13,14,17,23,26,29,30,31,32,33,34,35,36],x_input:2,x_ix_:[0,29],x_iy_i:8,x_j:[0,2,8,9,12,16,26,30,35,36],x_jy_j:8,x_k:[12,14,23,26,30,35],x_l:[26,36],x_m:[6,12,23,26,32,35],x_n:[0,2,3,6,8,11,12,13,23,26,29,32,33,34,35,36],x_new:[9,10],x_offset:[6,30,31],x_output:2,x_p:[3,7,9,33],x_poli:9,x_poly10:9,x_pred:4,x_prev:2,x_reduc:11,x_scale:8,x_small:[13,34],x_test:[0,1,3,5,6,7,9,10,11,29,30,31,32,33],x_test_own:6,x_test_scal:[0,6,7,9,10,11,30,31],x_tot:4,x_train:[0,1,3,4,5,6,7,9,10,11,29,30,31,32,33],x_train_mean:[6,30,31],x_train_own:6,x_train_scal:[0,6,7,9,10,11,30,31],x_val:1,xarrai:[22,29],xavier:[1,36],xbkjd4ccgq:29,xbnew:[13,33,34],xcode:[0,15,22,24,29],xdclassiffierconfus:10,xdclassiffierroc:10,xg_clf:10,xgb:10,xgbclassifi:10,xgboost:9,xgboot:10,xgbregressor:10,xgparam:10,xgtree:10,xi:[8,13,21,34,35],xi_1:8,xi_:8,xi_i:8,xinv:[31,35,36],xk:8,xla:[13,21,22,29,34,35],xlabel:[0,1,2,3,4,5,6,7,8,9,10,13,21,24,26,29,31,32,33,34,35],xlim:[6,10,32],xm:9,xmesh:[13,34],xnew:[0,13,21,29,33,34,35],xp:26,xpanda:[0,30],xpd:[5,11,30],xplot:0,xs:9,xscale:[0,30],xsr:9,xt_x:[13,21,33,34,35],xtest:[6,32,33],xtick:[3,6,8,9,32],xtrain:[6,32,33],xu:[0,29],xx:[0,23,29],xy:[0,6,8,23,24,29],xytext:8,xz:[23,29],y1:4,y2:4,y3:4,y:[0,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21,23,24,26,29,30,31,32,33,34,35,36],y_0:[0,5,11,23,29,30,31,32],y_1:[0,5,8,9,11,13,23,29,30,31,32,33,34],y_1y_1:8,y_1y_1k:8,y_1y_2:8,y_1y_2k:8,y_1y_n:8,y_1y_nk:8,y_2:[0,5,8,9,11,23,29,30],y_2y_1:8,y_2y_1k:8,y_2y_2:8,y_2y_2k:8,y_3:[0,9,23],y_4:23,y_:[0,1,5,6,10,11,23,29,30,31,32],y_data:[0,1,5,6,29,30,31,33],y_data_ful:1,y_decis:8,y_fit:[0,30],y_i:[0,1,5,6,7,8,9,10,11,12,13,15,16,17,18,19,23,24,29,30,31,32,33,34,35,36],y_if_:10,y_ix_:[0,29],y_ix_i:[7,8,13,30,33,34],y_iy_jk:8,y_j:[6,8,12,19,24,32,35,36],y_k:[12,35],y_m:23,y_model:[0,4,5,6,29,30,31,33],y_n:[8,13,33,34],y_ny_1:8,y_ny_1k:8,y_ny_2:8,y_ny_2k:8,y_ny_n:8,y_ny_nk:8,y_offset:[6,30,31],y_plot:9,y_pred1:9,y_pred2:9,y_pred:[0,1,4,6,7,8,9,10,30,31,32,33],y_pred_rf:10,y_pred_tre:10,y_predict:35,y_proba:[7,10,33],y_scaler:[6,31],y_test:[0,1,3,4,5,6,7,9,10,11,29,30,31,32,33],y_test_onehot:1,y_test_predict:0,y_tot:4,y_train:[0,1,3,4,5,6,7,9,10,11,29,30,31,32,33],y_train_mean:[6,30,31],y_train_onehot:1,y_train_predict:0,y_train_scal:[6,31],y_val:1,yand:[35,36],ye:[3,6,7,32,33],year:[0,22,29],yet:[0,1,6,8,11,13,29,33,34,36],yi:[13,21,34,35],yield:[0,2,5,6,7,8,10,12,13,14,23,26,29,31,32,33,34,35,36],yk:8,ylabel:[0,1,2,3,4,5,6,7,8,9,10,13,21,24,26,29,31,32,33,34,35],ylim:[3,6,32],ym:9,ymesh:[13,34],yn:0,yo:[8,9,10],yor:[35,36],yoshua:[1,28,36],you:[0,1,2,3,4,5,6,8,9,10,11,13,15,16,17,19,20,21,22,23,24,26,27,28,29,30,31,32,33,34,35,36],young:0,your:[1,2,4,5,6,8,11,13,17,19,20,21,22,23,24,31,32,33,34,35,36],yourself:[11,13,29,34],youtu:[33,35],youtub:[22,35,36],ypred:[6,32,33],ypredict2:[13,21,33,34,35],ypredict:[0,13,21,29,30,33,34,35],ypredictlasso:[5,31],ypredictol:[0,5,31],ypredictown:[6,30,31],ypredictownridg:[6,31],ypredictridg:[0,5,6,31,33],ypredictskl:[6,30,31],yridg:29,ys:9,ytest:[6,32,33],ytick:[3,6,8,9,32],ytild:[0,6,29,30,32],ytildelasso:[5,31],ytildenp:[0,29,30],ytildeol:[0,5,31],ytildeownridg:[6,31],ytilderidg:[5,6,31],ytrain:[6,32,33],yuxi:29,yx:[23,29],yxor:[35,36],yy:[23,29],yz:[23,29],z:[0,1,2,3,4,5,6,7,8,9,11,12,13,23,24,26,29,30,32,33,34,35,36],z_0:[23,29,36],z_1:[23,29,36],z_2:[23,29,36],z_:[1,2,12,23,29,36],z_c:1,z_h:1,z_hidden:2,z_i:[1,12,35],z_j:[1,12],z_k:[12,30,36],z_m:1,z_mod:9,z_o:1,z_output:2,zaman:26,zaxi:[6,24],zero:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,21,23,24,26,29,30,31,32,33,34,35,36],zeros_lik:4,zeroth:30,zfill:4,zip:[2,4,6],zm_h:[0,29],zn:0,zone:0,zoom:29,zx:[23,29],zy:[23,29],zz:[23,29]},titles:["3. Linear Regression","14. Building a Feed Forward Neural Network","15. Solving Differential Equations with Deep Learning","16. Convolutional Neural Networks","17. Recurrent neural networks: Overarching view","4. Ridge and Lasso Regression","5. Resampling Methods","6. Logistic Regression","8. Support Vector Machines, overarching aims","9. Decision trees, overarching aims","10. Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods","11. Basic ideas of the Principal Component Analysis (PCA)","13. Neural networks","7. Optimization, the central part of any Machine Learning algortithm","12. Clustering and Unsupervised Learning","Exercises week 34","Exercises week 35","Exercises week 36","Exercises week 37","Exercises week 38","Exercises week 39","Exercises week 41","Applied Data Analysis and Machine Learning","2. Linear Algebra, Handling of Arrays and more Python Features","Project 1 on Machine Learning, deadline October 7 (midnight), 2024","Teaching schedule with links to material","1. Elements of Probability Theory and Statistical Data Analysis","Teachers and Grading","Textbooks","Week 34: Introduction to the course, Logistics and Practicalities","Week 35: From Ordinary Linear Regression to Ridge and Lasso Regression","Week 36: Linear Regression and Statistical interpretations","Week 37: Statistical interpretations and Resampling Methods","Week 38: Logistic Regression and Optimization","Week 39: Optimization and Gradient Methods","Week 40: Gradient descent methods (continued) and start Neural networks","Week 41 Neural networks and constructing a neural network code"],titleterms:{"1":[0,15,16,17,18,24,29,30,36],"11":36,"16":33,"2":[0,15,16,17,18,29,30,31,36],"2023":27,"2024":[24,34,35,36],"21":[],"23":34,"26":30,"27":34,"3":[0,15,16,29,30,36],"30":35,"34":[15,29],"35":[16,30],"36":[17,31],"37":[18,32],"38":[19,33],"39":[20,21,34],"4":[0,30],"40":[21,35],"41":[21,36],"5":0,"7":[24,36],"9":32,"case":[8,10,26,30,31,33,34],"class":[33,36],"do":[1,31,32,34,35,36],"final":[12,21,30,31,34,35,36],"float":36,"function":[0,1,6,7,8,10,11,12,13,21,24,26,29,30,31,32,33,34,35,36],"import":[5,21,23,29,30,31,35,36],"new":[4,31,32,36],A:[0,1,4,8,9,21,29,31,32,33,35,36],AND:[35,36],And:[21,29,30,31,33,34,35],But:[21,34,35],For:30,In:[27,36],Is:36,Ising:6,OR:[35,36],The:[0,1,2,3,5,6,7,8,9,11,12,17,22,29,30,31,32,33,34,35,36],To:[29,30],With:[4,31],about:[29,30],abov:[31,36],activ:[1,12,31,35,36],ad:[0,6,17,24,29,30,35,36],adaboost:10,adagrad:[13,21,34,35],adam:[13,21,34,35],adapt:[10,21,34,35],adjust:1,advanc:[21,35],adversari:4,again:[3,9,33],ai:[24,29],aim:[8,9,17,18,19,20,21,29],aka:[29,30],al:[21,35],algebra:[23,29],algorithm:[9,10,11,12,21,30,34,35,36],algortithm:[13,33,34],all:[8,36],an:[0,4,10,29,36],analys:[5,30],analysi:[0,5,6,11,22,24,26,29,30,31,32,36],analyt:[0,16,17,21],analyz:36,ani:[13,33,34],anoth:[9,31,32],appli:22,approach:[0,8,14,29,32,34,35],approxim:[12,36],architectur:1,argument:[34,35],arrai:[23,29],artifici:[35,36],assist:27,assumpt:[31,32],august:30,autocorrel:26,autograd:[2,13,21,34,35],automat:[13,21,34,35,36],avoid:[],b:[17,24,34],back:[1,11,12,36],background:[22,24,32],bag:10,base:[13,21,32,34,35],basic:[0,5,7,9,10,11,23,30,31,32,33,36],batch:[1,34,35,36],bay:[5,31,32],befor:11,bengio:36,beta:[31,32],better:[8,35,36],bia:[6,24,32],bias:36,binari:1,bind:29,bird:10,boldsymbol:[30,31,32],book:36,boost:10,bootstrap:[6,10,32],boston:0,breast:1,brief:[29,32,33,34],bring:[12,36],build:[1,3,9],c:[24,29],calcul:30,can:[21,29,32,34,35,36],cancer:[1,7,9,11,33],cart:9,center:30,central:[13,22,26,32,33,34],chain:[12,36],challeng:33,chang:10,channel:29,chi:[0,29],choic:36,choos:1,cifar01:3,classic:11,classif:[1,9,10,33],classifi:[8,33],clip:[1,36],cluster:14,cnn:3,code:[0,1,2,5,9,11,12,13,14,21,29,30,31,32,33,34,35,36],collect:[1,3],come:33,commun:29,compact:[33,36],compar:[2,10],comparison:31,compet:[21,34,35],complet:[30,36],complex:[0,6,24,30],complic:[6,34,35,36],compon:11,comput:[9,34,35],computation:32,computerlab:29,con:9,concept:26,condit:[31,32,33,34],confid:32,conjug:[13,34],consider:36,construct:36,continu:35,contn:29,convex:[8,13,33,34],convolut:[3,12,35,36],correctli:[31,32],correl:[11,30,33],correspond:[33,34],cost:[1,10,30,31,32,33,34,36],count:36,cours:[22,28,29],covari:[5,11,26,30],cover:29,cross:[6,24,32,33],cython:29,d:24,data:[0,1,3,6,7,9,11,15,16,22,24,26,29,30,31,33,36],dataset:[1,3],deadlin:[24,29],decai:[2,34,35],decis:[9,10],decomposit:[5,11,17,23,30],deep:[1,2,29,33,36],defin:[1,29,36],definit:36,degre:[0,30],deliveri:24,delta:32,dens:[0,29],deriv:[5,12,30,31,32,33,34,36],descent:[2,10,13,21,33,34,35],descript:24,design:30,detail:[3,29],develop:1,diagon:11,differ:[8,34,35],different:21,differenti:[2,13,34,35,36],diffus:2,dimension:[2,3,8,24,30],directli:[34,35],disadvantag:9,discret:26,discuss:33,distribut:[5,26,31,32],distrubut:32,doe:[30,31,35,36],domain:26,dot:34,down:[1,36],dropout:[1,36],e:24,each:33,economi:30,electron:24,element:[0,26,29,34,35],elimin:23,elu:36,energi:29,ensembl:10,entri:36,entropi:[9,33],environ:[0,15,29],equat:[0,2,12,29,30,31,33,34,36],error:[0,10,29,30,32],essenti:29,estim:[31,32],et:[21,35],etc:29,euler:2,evalu:[1,36],exampl:[0,1,2,3,4,6,7,8,9,10,21,29,30,31,32,33,34,35,36],exercis:[0,6,15,16,17,18,19,20,21,29,30,36],expect:[18,26,31,32],expens:32,experi:26,explicit:36,explod:36,explor:[0,15,16,29],exponenti:2,express:[17,18,30,33,34,36],extend:[33,34,36],extrapol:4,extrem:[10,29],ey:10,f:24,fall:27,famili:[1,29,30,36],famou:23,fantast:30,featur:[9,23,30],feed:[1,12,35,36],find:[32,34],fine:[1,36],first:[4,12,29,30,31,33,34,36],fit:[0,10,29,31],fix:30,fold:[32,33],forc:3,forest:10,format:[24,29],forward:[1,2,12,35,36],fourier:3,frank:[6,24,30],freedom:[0,30],frequent:30,frequentist:[0,29],fridai:[],from:[5,10,12,21,30,31,32,33,34,35,36],full:2,funtion:36,further:[3,5,30],g:24,gan:4,gate:[35,36],gaussian:23,gd:[13,21,34,35],gener:[4,9,29,36],geometr:[11,33,34],get:[21,35,36],gini:9,glorot:36,good:[0,29],goodfellow:[21,35],grade:[27,29],gradient:[1,2,10,13,21,33,34,35,36],grid:33,group:33,growth:2,ha:22,hand:36,handl:[23,29,30],happen:[31,32],hessian:[30,33,34],hidden:[2,36],histogram:32,homework:[33,34],homogen:36,hous:0,how:33,hyperbol:[35,36],hyperparamet:[1,36],hyperplan:8,i:1,id3:9,idea:11,ideal:[33,34],ident:[31,32],identifi:32,ii:29,iid:[31,32],illustr:[31,35,36],implement:[1,35],implic:[5,30],improv:[1,34],includ:[13,21,33,34,35,36],increment:11,independ:[31,32],index:9,inform:27,ingredi:36,input:[2,36],insight:36,instal:[22,24,29],instructor:27,intercept:30,intermedi:36,interpret:[5,11,29,30,31,32,33,34],interv:32,introduc:[11,13,21,30,34,35],introduct:[0,6,22,23,24,29,35,36],invers:[5,23,31],invert:30,iter:[10,34],its:30,jacobian:30,jax:[13,21,34,35],job:[35,36],julia:29,jungl:10,k:[32,33,36],kera:[1,3],kernel:[8,11],l:36,lab:[32,33,34,35],lagrangian:8,lambda:33,lasso:[5,6,24,30,31,32,33,35],last:[30,33,35,36],later:[5,30],layer:[1,2,3,12,36],layout:36,learn:[0,1,2,11,13,14,15,16,21,22,24,29,30,31,32,33,34,35,36],least:[5,6,18,24,29,30,31],lectur:[29,30,31,32,33,34,35,36],level:10,librari:[22,29],likelihood:[7,31,32,33],limit:[1,13,26,32,33,34,35,36],linear:[0,8,13,23,29,30,31,33],link:[5,11,25,28,30,31,32],list:36,literatur:24,logist:[7,29,33,34,35,36],loop:[34,35],loss:[30,33,34],lu:23,machin:[0,8,13,22,24,29,33,34],made:[31,32],main:[26,29],make:[0,9,10,15,16,29,30],mani:[10,12],manipul:30,margin:[31,32],mass:29,materi:[24,25,29,30,31,32,33,36],math:[5,30],mathemat:[3,5,8,30,34,35,36],matric:[5,23,29,31],matrix:[1,5,11,12,23,29,30,31,33,34,35],matter:[0,29],max:30,maximum:[31,32,33],mean:[0,30,31,33],measur:33,meet:[5,10,26,29,30],mercer:8,method:[6,9,10,13,21,24,29,32,33,34,35],midnight:24,min:30,mini:[34,35],minibatch:[21,34,35],minim:[29,33],ml:29,mle:[31,32],mlp:12,mnist:[3,4],mode:36,model:[0,1,4,6,12,29,35,36],moment:[34,35],momentum:[13,21,34,35],mondai:[30,31,32,33,34,35,36],moon:[8,9],more:[3,6,21,23,24,29,30,31,32,33,34,35,36],multi:[35,36],multilay:[12,35,36],multipl:[1,3],multipli:8,multivari:36,need:[24,29],network:[1,2,3,4,7,12,29,33,35,36],neural:[1,2,3,4,7,12,29,35,36],neuron:[35,36],newton:[21,33,34,35],nn:36,node:36,noen:21,non:8,none:[34,35],normal:[0,1,32,36],notat:[12,35],note:[21,24,30,31,35],now:[1,9,13,21,31,32,34,35],nuclear:[0,29],nueral:33,numba:29,number:[0,2,21,26,30,34,35,36],numer:[2,24,26],numpi:[21,23,29,34,35],object:3,observ:36,obtain:11,octob:[24,36],od:2,off:[6,24],ol:[5,6,21,24,31,32,34,35],one:[2,12,33,34,36],ones:[35,36],oper:[23,36],optim:[1,8,13,22,29,30,33,34,35,36],order:[13,21,34,35],ordinari:[5,6,18,24,29,30,31],organ:[0,29],orient:[],oslo:28,other:[4,9,11,12,23,24,29,30,33,35,36],ouput:36,our:[0,4,5,11,13,29,30,33,34,36],outcom:[22,29],output:[2,36],over:36,overarch:[0,4,8,9,17,18,19,20,21,29,30,36],overview:[10,29,34,35],own:[0,10,11,15,16,29,30],packag:[23,29],panda:[29,30],paper:[24,36],parallel:36,paramet:[29,30,33,34,35,36],part:[13,22,24,30,33,34,36],partial:2,pass:1,pca:11,pdf:26,pencil:24,percepetron:36,perceptron:[12,35,36],perform:[1,9],period:3,perspect:[1,36],plan:[30,31,32,33,34,35,36],plot:[32,33],point:[4,36],poisson:2,polynomi:[3,31],popul:2,popular:29,practic:[13,21,27,29,34,35],pre:[1,3],preambl:24,predict:4,predictor:33,preprocess:30,prerequisit:[3,22,29],princip:11,principl:3,pro:9,probabl:[5,26,31,32],problem:[1,2,13,21,29,30,31,33,34,35,36],procedur:[9,29],process:[1,3],product:34,program:[2,13,24,33,34,36],project:[6,24,29,33],prop:[13,34,35],propag:[1,12,36],properti:[5,26,30,33],python:[0,9,15,22,23,29],quick:8,r:29,random:[10,11,26,33],raphson:[33,34],rate:[21,34,35],read:[9,29,30,32,33,35,36],real:[6,24,29,36],recommend:[29,30,36],rectangular:31,recurr:[4,12,35,36],recurs:[34,35],reduc:[0,30,36],reduct:3,refer:24,reformul:2,regress:[0,5,6,7,9,10,13,17,18,24,29,30,31,32,33,34,35,36],regular:[1,33],relat:30,relev:[28,30,33,35,36],relu:[1,36],remark:3,remind:[6,8,29,33,34,36],repeat:30,replac:[13,34,35],report:24,repositori:32,repres:[],requir:[2,22],resampl:[6,24,32],rescal:[6,31],residu:30,resourc:2,result:[30,31,36],revers:36,revisit:[13,33,34],rewrit:[29,30,32],rewritten:33,ridg:[0,5,6,17,18,24,30,31,32,33,34,35],rm:[13,34,35],rmsprop:[21,34,35],root:36,rule:[12,36],s:[8,10,21,32,33,34,35],same:[13,21,32,34,35],sampl:11,scale:30,schedul:[25,29],schemat:9,scheme:2,scienc:29,scikit:[0,1,11,15,16,29,30,31,32,33,34],search:33,second:[13,21,34,35],select:33,semest:27,sensit:[33,34],septemb:[31,32,33,34,35],seriou:36,session:[30,31,32,33,34,35,36],set:[0,2,3,9,12,15,29,30,33,36],sgd:[13,34,35],should:[1,36],sigmoid:36,similar:[13,21,34,35],simpl:[0,4,9,13,29,30,31,33,34,35,36],simpler:36,singl:[10,35,36],singular:[5,11,17,30],size:30,slightli:[34,35],smarter:36,soft:8,softmax:1,softwar:[24,29],solv:[2,31,33,34],solver:13,some:[13,23,30,33,34,36],specifi:2,split:[0,15,16,29,30],squar:[0,5,6,10,18,24,29,30,31],standard:[13,30,32,34],start:[21,35],state:[0,29],statist:[5,6,22,26,29,31,32],steepest:[10,13,33,34],step:[32,33,34,35],still:30,stochast:[13,21,26,34,35],stop:[34,35],strongli:29,studi:33,subtract:30,suggest:[29,33,35],sum:[32,36],summari:[27,29,35],superposit:3,supervis:[1,36],support:8,svd:[5,30,31],syntax:34,systemat:3,t:[30,31],taken:[21,35],teach:[25,27],teacher:[27,29],technic:31,techniqu:[6,11,24],technolog:22,tensorflow:[1,3],tent:29,term:[32,36],test:[0,1,15,16,29,30,31],text:29,textbook:[28,29],than:[33,34],theorem:[5,8,11,12,26,31,32,36],theori:26,thi:[17,18,19,20,21,29,36],think:30,three:36,through:36,thursdai:[],time:[34,35],tip:[13,21,34,35],togeth:[12,36],tool:[24,29],top:[1,36],topic:29,toward:11,trade:[6,24],tradeoff:[6,32],train:[0,1,4,15,16,29,30,36],transform:3,tree:[9,10],tuesdai:[31,35,36],tune:[1,36],two:[3,8,22,24,30,33,36],type:[2,4,12,29,35,36],uio:29,understand:32,univers:[12,28,36],unsupervis:14,unsupport:34,up:[0,2,9,12,15,21,29,30,32,33,35,36],updat:36,us:[0,1,2,3,7,13,21,22,24,29,30,33,34,35,36],usag:[31,32],valid:[6,24,32,33],valu:[5,11,17,18,26,30,31,32,33],vanish:36,vari:[21,34,35],variabl:[26,33,34],varianc:[6,24,31,32],variou:[0,15,29,32,33],vector:[8,12,23,29,30,35],video:[33,34,35],view:[0,4,10,30,36],visual:[1,9],vs:3,wai:[9,21,32,35,36],warm:[21,35],wave:2,we:[21,29,34,35,36],wednesdai:[31,35,36],week:[15,16,17,18,19,20,21,29,30,31,32,33,34,35,36],weekend:33,weekli:25,weight:[],what:[0,29,30,31,32],when:[34,35],which:[1,21,34,35,36],why:[29,30,32,35,36],wisconsin:[7,33],word:36,wrap:[30,32],write:[4,11,24,31],x:[30,31],xgboost:10,xor:[35,36],yet:31,your:[0,10,15,16,29,30],yourself:33,z_j:36}}) \ No newline at end of file diff --git a/doc/LectureNotes/_build/html/week41.html b/doc/LectureNotes/_build/html/week41.html index 55032c223..27f8d1715 100644 --- a/doc/LectureNotes/_build/html/week41.html +++ b/doc/LectureNotes/_build/html/week41.html @@ -479,70 +479,88 @@ const thebe_selector_output = ".output, .cell_output"
  • - - Mathematical model + + Mathematics of deep learning
  • - - Mathematical model + + Reminder on books with hands-on material and codes
  • - - Mathematical model + + Reading recommendations
  • - - Mathematical model + + Mathematics of deep learning and neural networks
  • - - Mathematical model - - -
  • -
  • - - The multilayer perceptron (MLP) + + Basics of an NN
  • - - From one to many layers, the universal approximation theorem + + Overarching view of a neural network
  • - - Deriving the back propagation code for a multilayer perceptron model + + The optimization problem + +
  • +
  • + + Parameters of neural networks + +
  • +
  • + + Other ingredients of a neural network + +
  • +
  • + + Other parameters + +
  • +
  • + + Universal approximation theorem + +
  • +
  • + + Some parallels from real analysis + +
  • +
  • + + The approximation theorem in words + +
  • +
  • + + More on the general approximation theorem + +
  • +
  • + + Class of functions we can approximate + +
  • +
  • + + Setting up the equations for a neural network + +
  • +
  • + + Layout of a neural network with three hidden layers
  • @@ -550,6 +568,11 @@ const thebe_selector_output = ".output, .cell_output" Definitions
  • +
  • + + Inputs to the activation function + +
  • Derivatives and the chain rule @@ -561,8 +584,213 @@ const thebe_selector_output = ".output, .cell_output"
  • - - Bringing it together, first back propagation equation + + Simpler examples first, and automatic differentiation + +
  • +
  • + + Reminder on the chain rule and gradients + +
  • +
  • + + Multivariable functions + +
  • +
  • + + Automatic differentiation through examples + +
  • +
  • + + Simple example + +
  • +
  • + + Smarter way of evaluating the above function + +
  • +
  • + + Reducing the number of operations + +
  • +
  • + + Chain rule, forward and reverse modes + +
  • +
  • + + Forward and reverse modes + +
  • +
  • + + More complicated function + +
  • +
  • + + Counting the number of floating point operations + +
  • +
  • + + Defining intermediate operations + +
  • +
  • + + New expression for the derivative + +
  • +
  • + + Final derivatives + +
  • +
  • + + In general not this simple + +
  • +
  • + + Automatic differentiation + +
  • +
  • + + Chain rule + +
  • +
  • + + First network example, simple percepetron with one input + +
  • +
  • + + Layout of a simple neural network with no hidden layer + +
  • +
  • + + Optimizing the parameters + +
  • +
  • + + Adding a hidden layer + +
  • +
  • + + Layout of a simple neural network with one hidden layer + +
  • +
  • + + The derivatives + +
  • +
  • + + Important observations + +
  • +
  • + + The training + +
  • +
  • + + Code example + +
  • +
  • + + Exercise 1: Including more data + +
  • +
  • + + Simple neural network and the back propagation equations + +
  • +
  • + + Layout of a simple neural network with two input nodes, one hidden layer and one output node + +
  • +
  • + + The ouput layer + +
  • +
  • + + Compact expressions + +
  • +
  • + + Output layer + +
  • +
  • + + Explicit derivatives + +
  • +
  • + + Derivatives of the hidden layer + +
  • +
  • + + Final expression + +
  • +
  • + + Completing the list + +
  • +
  • + + Final expressions for the biases of the hidden layer + +
  • +
  • + + Gradient expressions + +
  • +
  • + + Exercise 2: Extended program + +
  • +
  • + + Getting serious, the back propagation equations for a neural network + +
  • +
  • + + Analyzing the last results + +
  • +
  • + + More considerations
  • @@ -583,159 +811,155 @@ const thebe_selector_output = ".output, .cell_output" Final back propagating equation
  • +
  • + + Using the chain rule and summing over all + + \(k\) + + entries + +
  • - Setting up the Back propagation algorithm + Setting up the back propagation algorithm
  • - - Setting up the Back propagation algorithm + + Setting up the back propagation algorithm, part 2
  • - - Setting up the Back propagation algorithm + + Setting up the Back propagation algorithm, part 3
  • - - Setting up a Multi-layer perceptron model for classification + + Updating the gradients + + +
  • +
  • + + Fine-tuning neural network hyperparameters
  • - - Defining the cost function + + Hidden layers
  • - - Example: binary classification problem + + Vanishing gradients
  • - - The Softmax function + + Exploding gradients
  • - - Developing a code for doing neural networks with back propagation + + Is the Logistic activation function (Sigmoid) our choice?
  • - - Collect and pre-process data + + Logistic function as the root of problems
  • - - Train and test datasets + + The derivative of the Logistic funtion
  • - - Define model and architecture + + Insights from the paper by Glorot and Bengio
  • - - Layers + + The RELU function family
  • - - Weights and biases + + ELU function
  • - - Feed-forward pass + + Which activation function should we use?
  • - - Matrix multiplications + + More on activation functions, output layers
  • - - Choose cost function and optimizer + + Batch Normalization
  • - - Optimizing the cost function + + Dropout
  • - - Regularization + + Gradient Clipping
  • - - Matrix multiplication + + A top-down perspective on Neural networks
  • - - Improving performance + + More top-down perspectives
  • - - Full object-oriented implementation + + Limitations of supervised learning with deep networks
  • - - Evaluate model performance on test data + + Limitations of NNs
  • - - Adjust hyperparameters + + Homogeneous data
  • - - Visualization - -
  • -
  • - - scikit-learn implementation - -
  • -
  • - - Visualization - -
  • -
  • - - Testing our code for the XOR, OR and AND gates - -
  • -
  • - - The AND and XOR Gates - -
  • -
  • - - Representing the Data Sets - -
  • -
  • - - Setting up the Neural Network - -
  • -
  • - - The Code using Scikit-Learn + + More limitations
  • @@ -844,70 +1068,88 @@ const thebe_selector_output = ".output, .cell_output"
  • - - Mathematical model + + Mathematics of deep learning
  • - - Mathematical model + + Reminder on books with hands-on material and codes
  • - - Mathematical model + + Reading recommendations
  • - - Mathematical model + + Mathematics of deep learning and neural networks
  • - - Mathematical model - - -
  • -
  • - - The multilayer perceptron (MLP) + + Basics of an NN
  • - - From one to many layers, the universal approximation theorem + + Overarching view of a neural network
  • - - Deriving the back propagation code for a multilayer perceptron model + + The optimization problem + +
  • +
  • + + Parameters of neural networks + +
  • +
  • + + Other ingredients of a neural network + +
  • +
  • + + Other parameters + +
  • +
  • + + Universal approximation theorem + +
  • +
  • + + Some parallels from real analysis + +
  • +
  • + + The approximation theorem in words + +
  • +
  • + + More on the general approximation theorem + +
  • +
  • + + Class of functions we can approximate + +
  • +
  • + + Setting up the equations for a neural network + +
  • +
  • + + Layout of a neural network with three hidden layers
  • @@ -915,6 +1157,11 @@ const thebe_selector_output = ".output, .cell_output" Definitions
  • +
  • + + Inputs to the activation function + +
  • Derivatives and the chain rule @@ -926,8 +1173,213 @@ const thebe_selector_output = ".output, .cell_output"
  • - - Bringing it together, first back propagation equation + + Simpler examples first, and automatic differentiation + +
  • +
  • + + Reminder on the chain rule and gradients + +
  • +
  • + + Multivariable functions + +
  • +
  • + + Automatic differentiation through examples + +
  • +
  • + + Simple example + +
  • +
  • + + Smarter way of evaluating the above function + +
  • +
  • + + Reducing the number of operations + +
  • +
  • + + Chain rule, forward and reverse modes + +
  • +
  • + + Forward and reverse modes + +
  • +
  • + + More complicated function + +
  • +
  • + + Counting the number of floating point operations + +
  • +
  • + + Defining intermediate operations + +
  • +
  • + + New expression for the derivative + +
  • +
  • + + Final derivatives + +
  • +
  • + + In general not this simple + +
  • +
  • + + Automatic differentiation + +
  • +
  • + + Chain rule + +
  • +
  • + + First network example, simple percepetron with one input + +
  • +
  • + + Layout of a simple neural network with no hidden layer + +
  • +
  • + + Optimizing the parameters + +
  • +
  • + + Adding a hidden layer + +
  • +
  • + + Layout of a simple neural network with one hidden layer + +
  • +
  • + + The derivatives + +
  • +
  • + + Important observations + +
  • +
  • + + The training + +
  • +
  • + + Code example + +
  • +
  • + + Exercise 1: Including more data + +
  • +
  • + + Simple neural network and the back propagation equations + +
  • +
  • + + Layout of a simple neural network with two input nodes, one hidden layer and one output node + +
  • +
  • + + The ouput layer + +
  • +
  • + + Compact expressions + +
  • +
  • + + Output layer + +
  • +
  • + + Explicit derivatives + +
  • +
  • + + Derivatives of the hidden layer + +
  • +
  • + + Final expression + +
  • +
  • + + Completing the list + +
  • +
  • + + Final expressions for the biases of the hidden layer + +
  • +
  • + + Gradient expressions + +
  • +
  • + + Exercise 2: Extended program + +
  • +
  • + + Getting serious, the back propagation equations for a neural network + +
  • +
  • + + Analyzing the last results + +
  • +
  • + + More considerations
  • @@ -948,159 +1400,155 @@ const thebe_selector_output = ".output, .cell_output" Final back propagating equation
  • +
  • + + Using the chain rule and summing over all + + \(k\) + + entries + +
  • - Setting up the Back propagation algorithm + Setting up the back propagation algorithm
  • - - Setting up the Back propagation algorithm + + Setting up the back propagation algorithm, part 2
  • - - Setting up the Back propagation algorithm + + Setting up the Back propagation algorithm, part 3
  • - - Setting up a Multi-layer perceptron model for classification + + Updating the gradients + + +
  • +
  • + + Fine-tuning neural network hyperparameters
  • - - Defining the cost function + + Hidden layers
  • - - Example: binary classification problem + + Vanishing gradients
  • - - The Softmax function + + Exploding gradients
  • - - Developing a code for doing neural networks with back propagation + + Is the Logistic activation function (Sigmoid) our choice?
  • - - Collect and pre-process data + + Logistic function as the root of problems
  • - - Train and test datasets + + The derivative of the Logistic funtion
  • - - Define model and architecture + + Insights from the paper by Glorot and Bengio
  • - - Layers + + The RELU function family
  • - - Weights and biases + + ELU function
  • - - Feed-forward pass + + Which activation function should we use?
  • - - Matrix multiplications + + More on activation functions, output layers
  • - - Choose cost function and optimizer + + Batch Normalization
  • - - Optimizing the cost function + + Dropout
  • - - Regularization + + Gradient Clipping
  • - - Matrix multiplication + + A top-down perspective on Neural networks
  • - - Improving performance + + More top-down perspectives
  • - - Full object-oriented implementation + + Limitations of supervised learning with deep networks
  • - - Evaluate model performance on test data + + Limitations of NNs
  • - - Adjust hyperparameters + + Homogeneous data
  • - - Visualization - -
  • -
  • - - scikit-learn implementation - -
  • -
  • - - Visualization - -
  • -
  • - - Testing our code for the XOR, OR and AND gates - -
  • -
  • - - The AND and XOR Gates - -
  • -
  • - - Representing the Data Sets - -
  • -
  • - - Setting up the Neural Network - -
  • -
  • - - The Code using Scikit-Learn + + More limitations
  • @@ -1481,196 +1929,1241 @@ Test set accuracy with Logistic Regression for AND gate: 0.75 -
    -

    Mathematical model

    -

    The output \(y\) is produced via the activation function \(f\)

    + +
    +

    Reminder on books with hands-on material and codes

    + +
    +
    +

    Reading recommendations

    +
      +
    1. Rashkca et al., chapter 11, jupyter-notebook sent separately, from GitHub

    2. +
    3. Goodfellow et al, chapter 6 and 7 contain most of the neural network background.

    4. +
    +
    +
    +

    Mathematics of deep learning and neural networks

    +

    Neural networks, in its so-called feed-forward form, where each +iterations contains a feed-forward stage and a back-propgagation +stage, consist of series of affine matrix-matrix and matrix-vector +multiplications. The unknown parameters (the so-called biases and +weights which deternine the architecture of a neural network), are +uptaded iteratively using the so-called back-propagation algorithm. +This algorithm corresponds to the so-called reverse mode of +automatic differentation.

    +
    +
    +

    Basics of an NN

    +

    A neural network consists of a series of hidden layers, in addition to +the input and output layers. Each layer \(l\) has a set of parameters +\(\boldsymbol{\Theta}^{(l)}=(\boldsymbol{W}^{(l)},\boldsymbol{b}^{(l)})\) which are related to the +parameters in other layers through a series of affine transformations, +for a standard NN these are matrix-matrix and matrix-vector +multiplications. For all layers we will simply use a collective variable \(\boldsymbol{\Theta}\).

    +

    It consist of two basic steps:

    +
      +
    1. a feed forward stage which takes a given input and produces a final output which is compared with the target values through our cost/loss function.

    2. +
    3. a back-propagation state where the unknown parameters \(\boldsymbol{\Theta}\) are updated through the optimization of the their gradients. The expressions for the gradients are obtained via the chain rule, starting from the derivative of the cost/function.

    4. +
    +

    These two steps make up one iteration. This iterative process is continued till we reach an eventual stopping criterion.

    +
    +
    +

    Overarching view of a neural network

    +

    The architecture of a neural network defines our model. This model +aims at describing some function \(f(\boldsymbol{x}\) which represents +some final result (outputs or tagrget values) given a specific inpput +\(\boldsymbol{x}\). Note that here \(\boldsymbol{y}\) and \(\boldsymbol{x}\) are not limited to be +vectors.

    +

    The architecture consists of

    +
      +
    1. An input and an output layer where the input layer is defined by the inputs \(\boldsymbol{x}\). The output layer produces the model ouput \(\boldsymbol{\tilde{y}}\) which is compared with the target value \(\boldsymbol{y}\)

    2. +
    3. A given number of hidden layers and neurons/nodes/units for each layer (this may vary)

    4. +
    5. A given activation function \(\sigma(\boldsymbol{z})\) with arguments \(\boldsymbol{z}\) to be defined below. The activation functions may differ from layer to layer.

    6. +
    7. The last layer, normally called output layer has normally an activation function tailored to the specific problem

    8. +
    9. Finally we define a so-called cost or loss function which is used to gauge the quality of our model.

    10. +
    +
    +
    +

    The optimization problem

    +

    The cost function is a function of the unknown parameters +\(\boldsymbol{\Theta}\) where the latter is a container for all possible +parameters needed to define a neural network

    +

    If we are dealing with a regression task a typical cost/loss function +is the mean squared error

    \[ -y = f\left(\sum_{i=1}^n w_ix_i + b_i\right) = f(z), +C(\boldsymbol{\Theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. \]
    -

    This function receives \(x_i\) as inputs. -Here the activation \(z=(\sum_{i=1}^n w_ix_i+b_i)\). -In an FFNN of such neurons, the inputs \(x_i\) are the outputs of -the neurons in the preceding layer. Furthermore, an MLP is -fully-connected, which means that each neuron receives a weighted sum -of the outputs of all neurons in the previous layer.

    +

    This function represents one of many possible ways to define +the so-called cost function. Note that here we have assumed a linear dependence in terms of the paramters \(\boldsymbol{\Theta}\). This is in general not the case.

    -
    -

    Mathematical model

    -

    First, for each node \(i\) in the first hidden layer, we calculate a weighted sum \(z_i^1\) of the input coordinates \(x_j\),

    +
    +

    Parameters of neural networks

    +

    For neural networks the parameters +\(\boldsymbol{\Theta}\) are given by the so-called weights and biases (to be +defined below).

    +

    The weights are given by matrix elements \(w_{ij}^{(l)}\) where the +superscript indicates the layer number. The biases are typically given +by vector elements representing each single node of a given layer, +that is \(b_j^{(l)}\).

    +
    +
    +

    Other ingredients of a neural network

    +

    Having defined the architecture of a neural network, the optimization +of the cost function with respect to the parameters \(\boldsymbol{\Theta}\), +involves the calculations of gradients and their optimization. The +gradients represent the derivatives of a multidimensional object and +are often approximated by various gradient methods, including

    +
      +
    1. various quasi-Newton methods,

    2. +
    3. plain gradient descent (GD) with a constant learning rate \(\eta\),

    4. +
    5. GD with momentum and other approximations to the learning rates such as

    6. +
    +
      +
    • Adapative gradient (ADAgrad)

    • +
    • Root mean-square propagation (RMSprop)

    • +
    • Adaptive gradient with momentum (ADAM) and many other

    • +
    +
      +
    1. Stochastic gradient descent and various families of learning rate approximations

    2. +
    +
    +
    +

    Other parameters

    +

    In addition to the above, there are often additional hyperparamaters +which are included in the setup of a neural network. These will be +discussed below.

    +
    +
    +

    Universal approximation theorem

    +

    The universal approximation theorem plays a central role in deep +learning. Cybenko (1989) showed +the following:

    +

    Let \(\sigma\) be any continuous sigmoidal function such that

    +
    +\[\begin{split} +\sigma(z) = \left\{\begin{array}{cc} 1 & z\rightarrow \infty\\ 0 & z \rightarrow -\infty \end{array}\right. +\end{split}\]
    +

    Given a continuous and deterministic function \(F(\boldsymbol{x})\) on the unit +cube in \(d\)-dimensions \(F\in [0,1]^d\), \(x\in [0,1]^d\) and a parameter +\(\epsilon >0\), there is a one-layer (hidden) neural network +\(f(\boldsymbol{x};\boldsymbol{\Theta})\) with \(\boldsymbol{\Theta}=(\boldsymbol{W},\boldsymbol{b})\) and \(\boldsymbol{W}\in +\mathbb{R}^{m\times n}\) and \(\boldsymbol{b}\in \mathbb{R}^{n}\), for which

    +
    +\[ +\vert F(\boldsymbol{x})-f(\boldsymbol{x};\boldsymbol{\Theta})\vert < \epsilon \hspace{0.1cm} \forall \boldsymbol{x}\in[0,1]^d. +\]
    +
    +
    +

    Some parallels from real analysis

    +

    For those of you familiar with for example the Stone-Weierstrass +theorem +for polynomial approximations or the convergence criterion for Fourier +series, there are similarities in the derivation of the proof for +neural networks.

    +
    +
    +

    The approximation theorem in words

    +

    Any continuous function \(y=F(\boldsymbol{x})\) supported on the unit cube in +\(d\)-dimensions can be approximated by a one-layer sigmoidal network to +arbitrary accuracy.

    +

    Hornik (1991) extended the theorem by letting any non-constant, bounded activation function to be included using that the expectation value

    +
    +\[ +\mathbb{E}[\vert F(\boldsymbol{x})\vert^2] =\int_{\boldsymbol{x}\in D} \vert F(\boldsymbol{x})\vert^2p(\boldsymbol{x})d\boldsymbol{x} < \infty. +\]
    +

    Then we have

    +
    +\[ +\mathbb{E}[\vert F(\boldsymbol{x})-f(\boldsymbol{x};\boldsymbol{\Theta})\vert^2] =\int_{\boldsymbol{x}\in D} \vert F(\boldsymbol{x})-f(\boldsymbol{x};\boldsymbol{\Theta})\vert^2p(\boldsymbol{x})d\boldsymbol{x} < \epsilon. +\]
    +
    +
    +

    More on the general approximation theorem

    +

    None of the proofs give any insight into the relation between the +number of of hidden layers and nodes and the approximation error +\(\epsilon\), nor the magnitudes of \(\boldsymbol{W}\) and \(\boldsymbol{b}\).

    +

    Neural networks (NNs) have what we may call a kind of universality no matter what function we want to compute.

    +

    It does not mean that an NN can be used to exactly compute any function. Rather, we get an approximation that is as good as we want.

    +
    +
    +

    Class of functions we can approximate

    +

    The class of functions that can be approximated are the continuous ones. +If the function \(F(\boldsymbol{x})\) is discontinuous, it won’t in general be possible to approximate it. However, an NN may still give an approximation even if we fail in some points.

    +
    +
    +

    Setting up the equations for a neural network

    +

    The questions we want to ask are how do changes in the biases and the +weights in our network change the cost function and how can we use the +final output to modify the weights and biases?

    +

    To derive these equations let us start with a plain regression problem +and define our cost function as

    +
    +\[ +{\cal C}(\boldsymbol{\Theta}) = \frac{1}{2}\sum_{i=1}^n\left(y_i - \tilde{y}_i\right)^2, +\]
    +

    where the \(y_i\)s are our \(n\) targets (the values we want to +reproduce), while the outputs of the network after having propagated +all inputs \(\boldsymbol{x}\) are given by \(\boldsymbol{\tilde{y}}_i\).

    +
    +
    +

    Layout of a neural network with three hidden layers

    + + +

    Figure 1:

    +
    +
    +

    Definitions

    +

    With our definition of the targets \(\boldsymbol{y}\), the outputs of the +network \(\boldsymbol{\tilde{y}}\) and the inputs \(\boldsymbol{x}\) we +define now the activation \(z_j^l\) of node/neuron/unit \(j\) of the +\(l\)-th layer as a function of the bias, the weights which add up from +the previous layer \(l-1\) and the forward passes/outputs +\(\hat{a}^{l-1}\) from the previous layer as

    +
    +\[ +z_j^l = \sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l, +\]
    +

    where \(b_k^l\) are the biases from layer \(l\). Here \(M_{l-1}\) +represents the total number of nodes/neurons/units of layer \(l-1\). The +figure in the whiteboard notes illustrates this equation. We can rewrite this in a more +compact form as the matrix-vector products we discussed earlier,

    +
    +\[ +\hat{z}^l = \left(\hat{W}^l\right)^T\hat{a}^{l-1}+\hat{b}^l. +\]
    +
    +
    +

    Inputs to the activation function

    +

    With the activation values \(\boldsymbol{z}^l\) we can in turn define the +output of layer \(l\) as \(\boldsymbol{a}^l = f(\boldsymbol{z}^l)\) where \(f\) is our +activation function. In the examples here we will use the sigmoid +function discussed in our logistic regression lectures. We will also use the same activation function \(f\) for all layers +and their nodes. It means we have

    +
    +\[ +a_j^l = \sigma(z_j^l) = \frac{1}{1+\exp{-(z_j^l)}}. +\]
    +
    +
    +

    Derivatives and the chain rule

    +

    From the definition of the activation \(z_j^l\) we have

    +
    +\[ +\frac{\partial z_j^l}{\partial w_{ij}^l} = a_i^{l-1}, +\]
    +

    and

    +
    +\[ +\frac{\partial z_j^l}{\partial a_i^{l-1}} = w_{ji}^l. +\]
    +

    With our definition of the activation function we have that (note that this function depends only on \(z_j^l\))

    +
    +\[ +\frac{\partial a_j^l}{\partial z_j^{l}} = a_j^l(1-a_j^l)=\sigma(z_j^l)(1-\sigma(z_j^l)). +\]
    +
    +
    +

    Derivative of the cost function

    +

    With these definitions we can now compute the derivative of the cost function in terms of the weights.

    +

    Let us specialize to the output layer \(l=L\). Our cost function is

    +
    +\[ +{\cal C}(\boldsymbol{\Theta}^L) = \frac{1}{2}\sum_{i=1}^n\left(y_i - \tilde{y}_i\right)^2=\frac{1}{2}\sum_{i=1}^n\left(a_i^L - y_i\right)^2, +\]
    +

    The derivative of this function with respect to the weights is

    +
    +\[ +\frac{\partial{\cal C}(\boldsymbol{\Theta}^L)}{\partial w_{jk}^L} = \left(a_j^L - y_j\right)\frac{\partial a_j^L}{\partial w_{jk}^{L}}, +\]
    +

    The last partial derivative can easily be computed and reads (by applying the chain rule)

    +
    +\[ +\frac{\partial a_j^L}{\partial w_{jk}^{L}} = \frac{\partial a_j^L}{\partial z_{j}^{L}}\frac{\partial z_j^L}{\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1}. +\]
    +
    +
    +

    Simpler examples first, and automatic differentiation

    +

    In order to understand the back propagation algorithm and its +derivation (an implementation of the chain rule), let us first digress +with some simple examples. These examples are also meant to motivate +the link with back propagation and automatic differentiation.

    +
    +
    +

    Reminder on the chain rule and gradients

    +

    If we have a multivariate function \(f(x,y)\) where \(x=x(t)\) and \(y=y(t)\) are functions of a variable \(t\), we have that the gradient of \(f\) with respect to \(t\) (without the explicit unit vector components)

    +
    +\[\begin{split} +\frac{df}{dt} = \begin{bmatrix}\frac{\partial f}{\partial x} & \frac{\partial f}{\partial y} \end{bmatrix} \begin{bmatrix}\frac{\partial x}{\partial t} \\ \frac{\partial y}{\partial t} \end{bmatrix}=\frac{\partial f}{\partial x} \frac{\partial x}{\partial t} +\frac{\partial f}{\partial y} \frac{\partial y}{\partial t}. +\end{split}\]
    +
    +
    +

    Multivariable functions

    +

    If we have a multivariate function \(f(x,y)\) where \(x=x(t,s)\) and \(y=y(t,s)\) are functions of the variables \(t\) and \(s\), we have that the partial derivatives

    +
    +\[ +\frac{\partial f}{\partial s}=\frac{\partial f}{\partial x}\frac{\partial x}{\partial s}+\frac{\partial f}{\partial y}\frac{\partial y}{\partial s}, +\]
    +

    and

    +
    +\[ +\frac{\partial f}{\partial t}=\frac{\partial f}{\partial x}\frac{\partial x}{\partial t}+\frac{\partial f}{\partial y}\frac{\partial y}{\partial t}. +\]
    +

    the gradient of \(f\) with respect to \(t\) and \(s\) (without the explicit unit vector components)

    +
    +\[\begin{split} +\frac{df}{d(s,t)} = \begin{bmatrix}\frac{\partial f}{\partial x} & \frac{\partial f}{\partial y} \end{bmatrix} \begin{bmatrix}\frac{\partial x}{\partial s} &\frac{\partial x}{\partial t} \\ \frac{\partial y}{\partial s} & \frac{\partial y}{\partial t} \end{bmatrix}. +\end{split}\]
    +
    +
    +

    Automatic differentiation through examples

    +

    A great introduction to automatic differentiation is given by Baydin et al., see https://arxiv.org/abs/1502.05767.

    +

    Automatic differentiation is a represented by a repeated application +of the chain rule on well-known functions and allows for the +calculation of derivatives to numerical precision. It is not the same +as the calculation of symbolic derivatives via for example SymPy, nor +does it use approximative formulae based on Taylor-expansions of a +function around a given value. The latter are error prone due to +truncation errors and values of the step size \(\Delta\).

    +
    +
    +

    Simple example

    +

    Our first example is rather simple,

    +
    +\[ +f(x) =\exp{x^2}, +\]
    +

    with derivative

    +
    +\[ +f'(x) =2x\exp{x^2}. +\]
    +

    We can use SymPy to extract the pertinent lines of Python code through the following simple example

    +
    +
    +
    from __future__ import division
    +from sympy import *
    +x = symbols('x')
    +expr = exp(x*x)
    +simplify(expr)
    +derivative = diff(expr,x)
    +print(python(expr))
    +print(python(derivative))
    +
    +
    +
    +
    +
    x = Symbol('x')
    +e = exp(x**2)
    +x = Symbol('x')
    +e = 2*x*exp(x**2)
    +
    +
    +
    +
    +
    +
    +

    Smarter way of evaluating the above function

    +

    If we study this function, we note that we can reduce the number of operations by introducing an intermediate variable

    +
    +\[ +a = x^2, +\]
    +

    leading to

    +
    +\[ +f(x) = f(a(x)) = b= \exp{a}. +\]
    +

    We now assume that all operations can be counted in terms of equal +floating point operations. This means that in order to calculate +\(f(x)\) we need first to square \(x\) and then compute the exponential. We +have thus two floating point operations only.

    +
    +
    +

    Reducing the number of operations

    +

    With the introduction of a precalculated quantity \(a\) and thereby \(f(x)\) we have that the derivative can be written as

    +
    +\[ +f'(x) = 2xb, +\]
    +

    which reduces the number of operations from four in the orginal +expression to two. This means that if we need to compute \(f(x)\) and +its derivative (a common task in optimizations), we have reduced the +number of operations from six to four in total.

    +

    Note that the usage of a symbolic software like SymPy does not +include such simplifications and the calculations of the function and +the derivatives yield in general more floating point operations.

    +
    +
    +

    Chain rule, forward and reverse modes

    +

    In the above example we have introduced the variables \(a\) and \(b\), and our function is

    +
    +\[ +f(x) = f(a(x)) = b= \exp{a}, +\]
    +

    with \(a=x^2\). We can decompose the derivative of \(f\) with respect to \(x\) as

    +
    +\[ +\frac{df}{dx}=\frac{df}{db}\frac{db}{da}\frac{da}{dx}. +\]
    +

    We note that since \(b=f(x)\) that

    +
    +\[ +\frac{df}{db}=1, +\]
    +

    leading to

    +
    +\[ +\frac{df}{dx}=\frac{db}{da}\frac{da}{dx}=2x\exp{x^2}, +\]
    +

    as before.

    +
    +
    +

    Forward and reverse modes

    +

    We have that

    +
    +\[ +\frac{df}{dx}=\frac{df}{db}\frac{db}{da}\frac{da}{dx}, +\]
    +

    which we can rewrite either as

    +
    +\[ +\frac{df}{dx}=\left[\frac{df}{db}\frac{db}{da}\right]\frac{da}{dx}, +\]
    +

    or

    +
    +\[ +\frac{df}{dx}=\frac{df}{db}\left[\frac{db}{da}\frac{da}{dx}\right]. +\]
    +

    The first expression is called reverse mode (or back propagation) +since we start by evaluating the derivatives at the end point and then +propagate backwards. This is the standard way of evaluating +derivatives (gradients) when optimizing the parameters of a neural +network. In the context of deep learning this is computationally +more efficient since the output of a neural network consists of either +one or some few other output variables.

    +

    The second equation defines the so-called forward mode.

    +
    +
    +

    More complicated function

    +

    We increase our ambitions and introduce a slightly more complicated function

    +
    +\[ +f(x) =\sqrt{x^2+exp{x^2}}, +\]
    +

    with derivative

    +
    +\[ +f'(x) =\frac{x(1+\exp{x^2})}{\sqrt{x^2+exp{x^2}}}. +\]
    +

    The corresponding SymPy code reads

    +
    +
    +
    from __future__ import division
    +from sympy import *
    +x = symbols('x')
    +expr = sqrt(x*x+exp(x*x))
    +simplify(expr)
    +derivative = diff(expr,x)
    +print(python(expr))
    +print(python(derivative))
    +
    +
    +
    +
    +
    x = Symbol('x')
    +e = sqrt(x**2 + exp(x**2))
    +x = Symbol('x')
    +e = (x*exp(x**2) + x)/sqrt(x**2 + exp(x**2))
    +
    +
    +
    +
    +
    +
    +

    Counting the number of floating point operations

    +

    A simple count of operations shows that we need five operations for +the function itself and ten for the derivative. Fifteen operations in total if we wish to proceed with the above codes.

    +

    Can we reduce this to +say half the number of operations?

    +
    +
    +

    Defining intermediate operations

    +

    We can indeed reduce the number of operation to half of those listed in the brute force approach above. +We define the following quantities

    +
    +\[ +a = x^2, +\]
    +

    and

    +
    +\[ +b = \exp{x^2} = \exp{a}, +\]
    +

    and

    +
    +\[ +c= a+b, +\]
    +

    and

    +
    +\[ +d=f(x)=\sqrt{c}. +\]
    +
    +
    +

    New expression for the derivative

    +

    With these definitions we obtain the following partial derivatives

    +
    +\[ +\frac{\partial a}{\partial x} = 2x, +\]
    +

    and

    +
    +\[ +\frac{\partial b}{\partial a} = \exp{a}, +\]
    +

    and

    +
    +\[ +\frac{\partial c}{\partial a} = 1, +\]
    +

    and

    +
    +\[ +\frac{\partial c}{\partial b} = 1, +\]
    +

    and

    +
    +\[ +\frac{\partial d}{\partial c} = \frac{1}{2\sqrt{c}}, +\]
    +

    and finally

    +
    +\[ +\frac{\partial f}{\partial d} = 1. +\]
    +
    +
    +

    Final derivatives

    +

    Our final derivatives are thus

    +
    +\[ +\frac{\partial f}{\partial c} = \frac{\partial f}{\partial d} \frac{\partial d}{\partial c} = \frac{1}{2\sqrt{c}}, +\]
    +
    +\[ +\frac{\partial f}{\partial b} = \frac{\partial f}{\partial c} \frac{\partial c}{\partial b} = \frac{1}{2\sqrt{c}}, +\]
    +
    +\[ +\frac{\partial f}{\partial a} = \frac{\partial f}{\partial c} \frac{\partial c}{\partial a}+ +\frac{\partial f}{\partial b} \frac{\partial b}{\partial a} = \frac{1+\exp{a}}{2\sqrt{c}}, +\]
    +

    and finally

    +
    +\[ +\frac{\partial f}{\partial x} = \frac{\partial f}{\partial a} \frac{\partial a}{\partial x} = \frac{x(1+\exp{a})}{\sqrt{c}}, +\]
    +

    which is just

    +
    +\[ +\frac{\partial f}{\partial x} = \frac{x(1+b)}{d}, +\]
    +

    and requires only three operations if we can reuse all intermediate variables.

    +
    +
    +

    In general not this simple

    +

    In general, see the generalization below, unless we can obtain simple +analytical expressions which we can simplify further, the final +implementation of automatic differentiation involves repeated +calculations (and thereby operations) of derivatives of elementary +functions.

    +
    +
    +

    Automatic differentiation

    +

    We can make this example more formal. Automatic differentiation is a +formalization of the previous example (see graph).

    +

    We define \(\boldsymbol{x}\in x_1,\dots, x_l\) input variables to a given function \(f(\boldsymbol{x})\) and \(x_{l+1},\dots, x_L\) intermediate variables.

    +

    In the above example we have only one input variable, \(l=1\) and four intermediate variables, that is

    +
    +\[ +\begin{bmatrix} x_1=x & x_2 = x^2=a & x_3 =\exp{a}= b & x_4=c=a+b & x_5 = \sqrt{c}=d \end{bmatrix}. +\]
    +

    Furthemore, for \(i=l+1, \dots, L\) (here \(i=2,3,4,5\) and \(f=x_L=d\)), we +define the elementary functions \(g_i(x_{Pa(x_i)})\) where \(x_{Pa(x_i)}\) are the parent nodes of the variable \(x_i\).

    +

    In our case, we have for example for \(x_3=g_3(x_{Pa(x_i)})=\exp{a}\), that \(g_3=\exp{()}\) and \(x_{Pa(x_3)}=a\).

    +
    +
    +

    Chain rule

    +

    We can now compute the gradients by back-propagating the derivatives using the chain rule. +We have defined

    +
    +\[ +\frac{\partial f}{\partial x_L} = 1, +\]
    +

    which allows us to find the derivatives of the various variables \(x_i\) as

    +
    +\[ +\frac{\partial f}{\partial x_i} = \sum_{x_j:x_i\in Pa(x_j)}\frac{\partial f}{\partial x_j} \frac{\partial x_j}{\partial x_i}=\sum_{x_j:x_i\in Pa(x_j)}\frac{\partial f}{\partial x_j} \frac{\partial g_j}{\partial x_i}. +\]
    +

    Whenever we have a function which can be expressed as a computation +graph and the various functions can be expressed in terms of +elementary functions that are differentiable, then automatic +differentiation works. The functions may not need to be elementary +functions, they could also be computer programs, although not all +programs can be automatically differentiated.

    +
    +
    +

    First network example, simple percepetron with one input

    +

    As yet another example we define now a simple perceptron model with +all quantities given by scalars. We consider only one input variable +\(x\) and one target value \(y\). We define an activation function +\(\sigma_1\) which takes as input

    +
    +\[ +z_1 = w_1x+b_1, +\]
    +

    where \(w_1\) is the weight and \(b_1\) is the bias. These are the +parameters we want to optimize. The output is \(a_1=\sigma(z_1)\) (see +graph from whiteboard notes). This output is then fed into the +cost/loss function, which we here for the sake of simplicity just +define as the squared error

    +
    +\[ +C(x;w_1,b_1)=\frac{1}{2}(a_1-y)^2. +\]
    +
    +
    +

    Layout of a simple neural network with no hidden layer

    + + +

    Figure 1:

    +
    +
    +

    Optimizing the parameters

    +

    In setting up the feed forward and back propagation parts of the +algorithm, we need now the derivative of the various variables we want +to train.

    +

    We need

    +
    +\[ +\frac{\partial C}{\partial w_1} \hspace{0.1cm}\mathrm{and}\hspace{0.1cm}\frac{\partial C}{\partial b_1}. +\]
    +

    Using the chain rule we find

    +
    +\[ +\frac{\partial C}{\partial w_1}=\frac{\partial C}{\partial a_1}\frac{\partial a_1}{\partial z_1}\frac{\partial z_1}{\partial w_1}=(a_1-y)\sigma_1'x, +\]
    +

    and

    +
    +\[ +\frac{\partial C}{\partial b_1}=\frac{\partial C}{\partial a_1}\frac{\partial a_1}{\partial z_1}\frac{\partial z_1}{\partial b_1}=(a_1-y)\sigma_1', +\]
    +

    which we later will just define as

    +
    +\[ +\frac{\partial C}{\partial a_1}\frac{\partial a_1}{\partial z_1}=\delta_1. +\]
    +
    +
    +

    Adding a hidden layer

    +

    We change our simple model to (see graph) +a network with just one hidden layer but with scalar variables only.

    +

    Our output variable changes to \(a_2\) and \(a_1\) is now the output from the hidden node and \(a_0=x\). +We have then

    +
    +\[ +z_1 = w_1a_0+b_1 \hspace{0.1cm} \wedge a_1 = \sigma_1(z_1), +\]
    +
    +\[ +z_2 = w_2a_1+b_2 \hspace{0.1cm} \wedge a_2 = \sigma_2(z_2), +\]
    +

    and the cost function

    +
    +\[ +C(x;\boldsymbol{\Theta})=\frac{1}{2}(a_2-y)^2, +\]
    +

    with \(\boldsymbol{\Theta}=[w_1,w_2,b_1,b_2]\).

    +
    +
    +

    Layout of a simple neural network with one hidden layer

    + + +

    Figure 1:

    +
    +
    +

    The derivatives

    +

    The derivatives are now, using the chain rule again

    +
    +\[ +\frac{\partial C}{\partial w_2}=\frac{\partial C}{\partial a_2}\frac{\partial a_2}{\partial z_2}\frac{\partial z_2}{\partial w_2}=(a_2-y)\sigma_2'a_1=\delta_2a_1, +\]
    +
    +\[ +\frac{\partial C}{\partial b_2}=\frac{\partial C}{\partial a_2}\frac{\partial a_2}{\partial z_2}\frac{\partial z_2}{\partial b_2}=(a_2-y)\sigma_2'=\delta_2, +\]
    +
    +\[ +\frac{\partial C}{\partial w_1}=\frac{\partial C}{\partial a_2}\frac{\partial a_2}{\partial z_2}\frac{\partial z_2}{\partial a_1}\frac{\partial a_1}{\partial z_1}\frac{\partial z_1}{\partial w_1}=(a_2-y)\sigma_2'a_1\sigma_1'a_0, +\]
    +
    +\[ +\frac{\partial C}{\partial b_1}=\frac{\partial C}{\partial a_2}\frac{\partial a_2}{\partial z_2}\frac{\partial z_2}{\partial a_1}\frac{\partial a_1}{\partial z_1}\frac{\partial z_1}{\partial b_1}=(a_2-y)\sigma_2'\sigma_1'=\delta_1. +\]
    +

    Can you generalize this to more than one hidden layer?

    +
    +
    +

    Important observations

    +

    From the above equations we see that the derivatives of the activation +functions play a central role. If they vanish, the training may +stop. This is called the vanishing gradient problem, see discussions below. If they become +large, the parameters \(w_i\) and \(b_i\) may simply go to infinity. This +is referenced as the exploding gradient problem.

    +
    +
    +

    The training

    +

    The training of the parameters is done through various gradient descent approximations with

    +
    +\[ +w_{i}\leftarrow w_{i}- \eta \delta_i a_{i-1}, +\]
    +

    and

    +
    +\[ +b_i \leftarrow b_i-\eta \delta_i, +\]
    +

    with \(\eta\) is the learning rate.

    +

    One iteration consists of one feed forward step and one back-propagation step. Each back-propagation step does one update of the parameters \(\boldsymbol{\Theta}\).

    +

    For the first hidden layer \(a_{i-1}=a_0=x\) for this simple model.

    +
    +
    +

    Code example

    +

    The code here implements the above model with one hidden layer and +scalar variables for the same function we studied in the previous +example. The code is however set up so that we can add multiple +inputs \(x\) and target values \(y\). Note also that we have the +possibility of defining a feature matrix \(\boldsymbol{X}\) with more than just +one column for the input values. This will turn useful in our next example. We have also defined matrices and vectors for all of our operations although it is not necessary here.

    +
    +
    +
    import numpy as np
    +# We use the Sigmoid function as activation function
    +def sigmoid(z):
    +    return 1.0/(1.0+np.exp(-z))
    +
    +def forwardpropagation(x):
    +    # weighted sum of inputs to the hidden layer
    +    z_1 = np.matmul(x, w_1) + b_1
    +    # activation in the hidden layer
    +    a_1 = sigmoid(z_1)
    +    # weighted sum of inputs to the output layer
    +    z_2 = np.matmul(a_1, w_2) + b_2
    +    a_2 = z_2
    +    return a_1, a_2
    +
    +def backpropagation(x, y):
    +    a_1, a_2 = forwardpropagation(x)
    +    # parameter delta for the output layer, note that a_2=z_2 and its derivative wrt z_2 is just 1
    +    delta_2 = a_2 - y
    +    print(0.5*((a_2-y)**2))
    +    # delta for  the hidden layer
    +    delta_1 = np.matmul(delta_2, w_2.T) * a_1 * (1 - a_1)
    +    # gradients for the output layer
    +    output_weights_gradient = np.matmul(a_1.T, delta_2)
    +    output_bias_gradient = np.sum(delta_2, axis=0)
    +    # gradient for the hidden layer
    +    hidden_weights_gradient = np.matmul(x.T, delta_1)
    +    hidden_bias_gradient = np.sum(delta_1, axis=0)
    +    return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient
    +
    +
    +# ensure the same random numbers appear every time
    +np.random.seed(0)
    +# Input variable
    +x = np.array([4.0],dtype=np.float64)
    +# Target values
    +y = 2*x+1.0 
    +
    +# Defining the neural network, only scalars here
    +n_inputs = x.shape
    +n_features = 1
    +n_hidden_neurons = 1
    +n_outputs = 1
    +
    +# Initialize the network
    +# weights and bias in the hidden layer
    +w_1 = np.random.randn(n_features, n_hidden_neurons)
    +b_1 = np.zeros(n_hidden_neurons) + 0.01
    +
    +# weights and bias in the output layer
    +w_2 = np.random.randn(n_hidden_neurons, n_outputs)
    +b_2 = np.zeros(n_outputs) + 0.01
    +
    +eta = 0.1
    +for i in range(50):
    +    # calculate gradients
    +    derivW2, derivB2, derivW1, derivB1 = backpropagation(x, y)
    +    # update weights and biases
    +    w_2 -= eta * derivW2
    +    b_2 -= eta * derivB2
    +    w_1 -= eta * derivW1
    +    b_1 -= eta * derivB1
    +
    +
    +
    +
    +
    [36.89563074]
    +[23.62323175]
    +[15.1251681]
    +[9.68402334]
    +[6.20020163]
    +[3.96963458]
    +[2.54150298]
    +[1.62714703]
    +[1.0417409]
    +[0.66694492]
    +[0.42699034]
    +[0.27336592]
    +[0.17501258]
    +[0.11204514]
    +[0.07173249]
    +[0.04592382]
    +[0.02940083]
    +[0.01882264]
    +[0.01205039]
    +[0.00771475]
    +[0.00493903]
    +[0.003162]
    +[0.00202433]
    +[0.00129599]
    +[0.0008297]
    +[0.00053118]
    +[0.00034006]
    +[0.00021771]
    +[0.00013938]
    +[8.92313548e-05]
    +[5.71263851e-05]
    +[3.6572612e-05]
    +[2.34139775e-05]
    +[1.49897504e-05]
    +[9.5965161e-06]
    +[6.14373934e-06]
    +[3.93325371e-06]
    +[2.51808934e-06]
    +[1.61209378e-06]
    +[1.03207075e-06]
    +[6.60737006e-07]
    +[4.23007231e-07]
    +[2.70811405e-07]
    +[1.73374853e-07]
    +[1.10995472e-07]
    +[7.10598715e-08]
    +[4.54928947e-08]
    +[2.91247848e-08]
    +[1.86458368e-08]
    +[1.19371605e-08]
    +
    +
    +
    +
    +

    We see that after some few iterations (the results do depend on the learning rate however), we get an error which is rather small.

    +
    +
    +

    Exercise 1: Including more data

    +

    Try to increase the amount of input and +target/output data. Try also to perform calculations for more values +of the learning rates. Feel free to add either hyperparameters with an +\(l_1\) norm or an \(l_2\) norm and discuss your results. +Discuss your results as functions of the amount of training data and various learning rates.

    +

    Challenge: Try to change the activation functions and replace the hard-coded analytical expressions with automatic derivation via either autograd or JAX.

    +
    +
    +

    Simple neural network and the back propagation equations

    +

    Let us now try to increase our level of ambition and attempt at setting +up the equations for a neural network with two input nodes, one hidden +layer with two hidden nodes and one output layer with one output node/neuron only (see graph)..

    +

    We need to define the following parameters and variables with the input layer (layer \((0)\)) +where we label the nodes \(x_0\) and \(x_1\)

    +
    +\[ +x_0 = a_0^{(0)} \wedge x_1 = a_1^{(0)}. +\]
    +

    The hidden layer (layer \((1)\)) has nodes which yield the outputs \(a_0^{(1)}\) and \(a_1^{(1)}\)) with weight \(\boldsymbol{w}\) and bias \(\boldsymbol{b}\) parameters

    +
    +\[ +w_{ij}^{(1)}=\left\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)}\right\} \wedge b^{(1)}=\left\{b_0^{(1)},b_1^{(1)}\right\}. +\]
    +
    +
    +

    Layout of a simple neural network with two input nodes, one hidden layer and one output node

    + + +

    Figure 1:

    +
    +
    +

    The ouput layer

    +

    Finally, we have the ouput layer given by layer label \((2)\) with output \(a^{(2)}\) and weights and biases to be determined given by the variables

    +
    +\[ +w_{i}^{(2)}=\left\{w_{0}^{(2)},w_{1}^{(2)}\right\} \wedge b^{(2)}. +\]
    +

    Our output is \(\tilde{y}=a^{(2)}\) and we define a generic cost function \(C(a^{(2)},y;\boldsymbol{\Theta})\) where \(y\) is the target value (a scalar here). +The parameters we need to optimize are given by

    +
    +\[ +\boldsymbol{\Theta}=\left\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)},w_{0}^{(2)},w_{1}^{(2)},b_0^{(1)},b_1^{(1)},b^{(2)}\right\}. +\]
    +
    +
    +

    Compact expressions

    +

    We can define the inputs to the activation functions for the various layers in terms of various matrix-vector multiplications and vector additions. +The inputs to the first hidden layer are

    +
    +\[\begin{split} +\begin{bmatrix}z_0^{(1)} \\ z_1^{(1)} \end{bmatrix}=\begin{bmatrix}w_{00}^{(1)} & w_{01}^{(1)}\\ w_{10}^{(1)} &w_{11}^{(1)} \end{bmatrix}\begin{bmatrix}a_0^{(0)} \\ a_1^{(0)} \end{bmatrix}+\begin{bmatrix}b_0^{(1)} \\ b_1^{(1)} \end{bmatrix}, +\end{split}\]
    +

    with outputs

    +
    +\[\begin{split} +\begin{bmatrix}a_0^{(1)} \\ a_1^{(1)} \end{bmatrix}=\begin{bmatrix}\sigma^{(1)}(z_0^{(1)}) \\ \sigma^{(1)}(z_1^{(1)}) \end{bmatrix}. +\end{split}\]
    +
    +
    +

    Output layer

    +

    For the final output layer we have the inputs to the final activation function

    +
    +\[ +z^{(2)} = w_{0}^{(2)}a_0^{(1)} +w_{1}^{(2)}a_1^{(1)}+b^{(2)}, +\]
    +

    resulting in the output

    +
    +\[ +a^{(2)}=\sigma^{(2)}(z^{(2)}). +\]
    +
    +
    +

    Explicit derivatives

    +

    In total we have nine parameters which we need to train. Using the +chain rule (or just the back-propagation algorithm) we can find all +derivatives. Since we will use automatic differentiation in reverse +mode, we start with the derivatives of the cost function with respect +to the parameters of the output layer, namely

    +
    +\[ +\frac{\partial C}{\partial w_{i}^{(2)}}=\frac{\partial C}{\partial a^{(2)}}\frac{\partial a^{(2)}}{\partial z^{(2)}}\frac{\partial z^{(2)}}{\partial w_{i}^{(2)}}=\delta^{(2)}a_i^{(1)}, +\]
    +

    with

    +
    +\[ +\delta^{(2)}=\frac{\partial C}{\partial a^{(2)}}\frac{\partial a^{(2)}}{\partial z^{(2)}} +\]
    +

    and finally

    +
    +\[ +\frac{\partial C}{\partial b^{(2)}}=\frac{\partial C}{\partial a^{(2)}}\frac{\partial a^{(2)}}{\partial z^{(2)}}\frac{\partial z^{(2)}}{\partial b^{(2)}}=\delta^{(2)}. +\]
    +
    +
    +

    Derivatives of the hidden layer

    +

    Using the chain rule we have the following expressions for say one of the weight parameters (it is easy to generalize to the other weight parameters)

    +
    +\[ +\frac{\partial C}{\partial w_{00}^{(1)}}=\frac{\partial C}{\partial a^{(2)}}\frac{\partial a^{(2)}}{\partial z^{(2)}} +\frac{\partial z^{(2)}}{\partial z_0^{(1)}}\frac{\partial z_0^{(1)}}{\partial w_{00}^{(1)}}= \delta^{(2)}\frac{\partial z^{(2)}}{\partial z_0^{(1)}}\frac{\partial z_0^{(1)}}{\partial w_{00}^{(1)}}, +\]
    +

    which, noting that

    +
    +\[ +z^{(2)} =w_0^{(2)}a_0^{(1)}+w_1^{(2)}a_1^{(1)}+b^{(2)}, +\]
    +

    allows us to rewrite

    +
    +\[ +\frac{\partial z^{(2)}}{\partial z_0^{(1)}}\frac{\partial z_0^{(1)}}{\partial w_{00}^{(1)}}=w_0^{(2)}\frac{\partial a_0^{(1)}}{\partial z_0^{(1)}}a_0^{(1)}. +\]
    +
    +
    +

    Final expression

    +

    Defining

    +
    +\[ +\delta_0^{(1)}=w_0^{(2)}\frac{\partial a_0^{(1)}}{\partial z_0^{(1)}}\delta^{(2)}, +\]
    +

    we have

    +
    +\[ +\frac{\partial C}{\partial w_{00}^{(1)}}=\delta_0^{(1)}a_0^{(1)}. +\]
    +

    Similarly, we obtain

    +
    +\[ +\frac{\partial C}{\partial w_{01}^{(1)}}=\delta_0^{(1)}a_1^{(1)}. +\]
    +
    +
    +

    Completing the list

    +

    Similarly, we find

    +
    +\[ +\frac{\partial C}{\partial w_{10}^{(1)}}=\delta_1^{(1)}a_0^{(1)}, +\]
    +

    and

    +
    +\[ +\frac{\partial C}{\partial w_{11}^{(1)}}=\delta_1^{(1)}a_1^{(1)}, +\]
    +

    where we have defined

    +
    +\[ +\delta_1^{(1)}=w_1^{(2)}\frac{\partial a_1^{(1)}}{\partial z_1^{(1)}}\delta^{(2)}. +\]
    +
    +
    +

    Final expressions for the biases of the hidden layer

    +

    For the sake of completeness, we list the derivatives of the biases, which are

    +
    +\[ +\frac{\partial C}{\partial b_{0}^{(1)}}=\delta_0^{(1)}, +\]
    +

    and

    +
    +\[ +\frac{\partial C}{\partial b_{1}^{(1)}}=\delta_1^{(1)}. +\]
    +

    As we will see below, these expressions can be generalized in a more compact form.

    +
    +
    +

    Gradient expressions

    +

    For this specific model, with just one output node and two hidden +nodes, the gradient descent equations take the following form for output layer

    +
    +\[ +w_{i}^{(2)}\leftarrow w_{i}^{(2)}- \eta \delta^{(2)} a_{i}^{(1)}, +\]
    +

    and

    +
    +\[ +b^{(2)} \leftarrow b^{(2)}-\eta \delta^{(2)}, +\]
    +

    and

    +
    +\[ +w_{ij}^{(1)}\leftarrow w_{ij}^{(1)}- \eta \delta_{i}^{(1)} a_{j}^{(0)}, +\]
    +

    and

    +
    +\[ +b_{i}^{(1)} \leftarrow b_{i}^{(1)}-\eta \delta_{i}^{(1)}, +\]
    +

    where \(\eta\) is the learning rate.

    +
    +
    +

    Exercise 2: Extended program

    +

    We extend our simple code to a function which depends on two variable \(x_0\) and \(x_1\), that is

    +
    +\[ +y=f(x_0,x_1)=x_0^2+3x_0x_1+x_1^2+5. +\]
    +

    We feed our network with \(n=100\) entries \(x_0\) and \(x_1\). We have thus two features represented by these variable and an input matrix/design matrix \(\boldsymbol{X}\in \mathbf{R}^{n\times 2}\)

    +
    +\[\begin{split} +\boldsymbol{X}=\begin{bmatrix} x_{00} & x_{01} \\ x_{00} & x_{01} \\ x_{10} & x_{11} \\ x_{20} & x_{21} \\ \dots & \dots \\ \dots & \dots \\ x_{n-20} & x_{n-21} \\ x_{n-10} & x_{n-11} \end{bmatrix}. +\end{split}\]
    +

    Write a code, based on the previous code examples, which takes as input these data and fit the above function. +You can extend your code to include automatic differentiation.

    +

    With these examples, we are now ready to embark upon the writing of more a general code for neural networks.

    +
    +
    +

    Getting serious, the back propagation equations for a neural network

    +

    Now it is time to move away from one node in each layer only. Our inputs are also represented either by several inputs.

    +

    We have thus

    +
    +\[ +\frac{\partial{\cal C}((\boldsymbol{\Theta}^L)}{\partial w_{jk}^L} = \left(a_j^L - y_j\right)a_j^L(1-a_j^L)a_k^{L-1}, +\]
    +

    Defining

    +
    +\[ +\delta_j^L = a_j^L(1-a_j^L)\left(a_j^L - y_j\right) = \sigma'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}, +\]
    +

    and using the Hadamard product of two vectors we can write this as

    +
    +\[ +\boldsymbol{\delta}^L = \sigma'(\hat{z}^L)\circ\frac{\partial {\cal C}}{\partial (\boldsymbol{a}^L)}. +\]
    +
    +
    +

    Analyzing the last results

    +

    This is an important expression. The second term on the right handside +measures how fast the cost function is changing as a function of the \(j\)th +output activation. If, for example, the cost function doesn’t depend +much on a particular output node \(j\), then \(\delta_j^L\) will be small, +which is what we would expect. The first term on the right, measures +how fast the activation function \(f\) is changing at a given activation +value \(z_j^L\).

    +
    +
    +

    More considerations

    +

    Notice that everything in the above equations is easily computed. In +particular, we compute \(z_j^L\) while computing the behaviour of the +network, and it is only a small additional overhead to compute +\(\sigma'(z^L_j)\). The exact form of the derivative with respect to the +output depends on the form of the cost function. +However, provided the cost function is known there should be little +trouble in calculating

    +
    +\[ +\frac{\partial {\cal C}}{\partial (a_j^L)} +\]
    +

    With the definition of \(\delta_j^L\) we have a more compact definition of the derivative of the cost function in terms of the weights, namely

    +
    +\[ +\frac{\partial{\cal C}}{\partial w_{jk}^L} = \delta_j^La_k^{L-1}. +\]
    +
    +
    +

    Derivatives in terms of \(z_j^L\)

    +

    It is also easy to see that our previous equation can be written as

    +
    +\[ +\delta_j^L =\frac{\partial {\cal C}}{\partial z_j^L}= \frac{\partial {\cal C}}{\partial a_j^L}\frac{\partial a_j^L}{\partial z_j^L}, +\]
    +

    which can also be interpreted as the partial derivative of the cost function with respect to the biases \(b_j^L\), namely

    +
    +\[ +\delta_j^L = \frac{\partial {\cal C}}{\partial b_j^L}\frac{\partial b_j^L}{\partial z_j^L}=\frac{\partial {\cal C}}{\partial b_j^L}, +\]
    +

    That is, the error \(\delta_j^L\) is exactly equal to the rate of change of the cost function as a function of the bias.

    +
    +
    +

    Bringing it together

    +

    We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are

    \[ -\begin{equation} z_i^1 = \sum_{j=1}^{M} w_{ij}^1 x_j + b_i^1 +\begin{equation} +\frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \delta_j^La_k^{L-1}, \label{_auto1} \tag{2} \end{equation} \]
    -

    Here \(b_i\) is the so-called bias which is normally needed in -case of zero activation weights or inputs. How to fix the biases and -the weights will be discussed below. The value of \(z_i^1\) is the -argument to the activation function \(f_i\) of each node \(i\), The -variable \(M\) stands for all possible inputs to a given node \(i\) in the -first layer. We define the output \(y_i^1\) of all neurons in layer 1 as

    - -
    -
    -\[ -\begin{equation} - y_i^1 = f(z_i^1) = f\left(\sum_{j=1}^M w_{ij}^1 x_j + b_i^1\right) -\label{outputLayer1} \tag{3} -\end{equation} -\]
    -

    where we assume that all nodes in the same layer have identical -activation functions, hence the notation \(f\). In general, we could assume in the more general case that different layers have different activation functions. -In this case we would identify these functions with a superscript \(l\) for the \(l\)-th layer,

    - -
    -
    -\[ -\begin{equation} - y_i^l = f^l(u_i^l) = f^l\left(\sum_{j=1}^{N_{l-1}} w_{ij}^l y_j^{l-1} + b_i^l\right) -\label{generalLayer} \tag{4} -\end{equation} -\]
    -

    where \(N_l\) is the number of nodes in layer \(l\). When the output of -all the nodes in the first hidden layer are computed, the values of -the subsequent layer can be calculated and so forth until the output -is obtained.

    -
    -
    -

    Mathematical model

    -

    The output of neuron \(i\) in layer 2 is thus,

    +

    and

    \[ \begin{equation} - y_i^2 = f^2\left(\sum_{j=1}^N w_{ij}^2 y_j^1 + b_i^2\right) -\label{_auto2} \tag{5} +\delta_j^L = \sigma'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}, +\label{_auto2} \tag{3} \end{equation} \]
    - -
    -
    -\[ -\begin{equation} - = f^2\left[\sum_{j=1}^N w_{ij}^2f^1\left(\sum_{k=1}^M w_{jk}^1 x_k + b_j^1\right) + b_i^2\right] -\label{outputLayer2} \tag{6} -\end{equation} -\]
    -

    where we have substituted \(y_k^1\) with the inputs \(x_k\). Finally, the ANN output reads

    +

    and

    \[ \begin{equation} - y_i^3 = f^3\left(\sum_{j=1}^N w_{ij}^3 y_j^2 + b_i^3\right) -\label{_auto3} \tag{7} -\end{equation} -\]
    - -
    -
    -\[ -\begin{equation} - = f_3\left[\sum_{j} w_{ij}^3 f^2\left(\sum_{k} w_{jk}^2 f^1\left(\sum_{m} w_{km}^1 x_m + b_k^1\right) + b_j^2\right) - + b_1^3\right] -\label{_auto4} \tag{8} +\delta_j^L = \frac{\partial {\cal C}}{\partial b_j^L}, +\label{_auto3} \tag{4} \end{equation} \]
    -
    -

    Mathematical model

    -

    We can generalize this expression to an MLP with \(l\) hidden -layers. The complete functional form is,

    - -
    +
    +

    Final back propagating equation

    +

    We have that (replacing \(L\) with a general layer \(l\))

    \[ -\begin{equation} -y^{l+1}_i = f^{l+1}\left[\!\sum_{j=1}^{N_l} w_{ij}^3 f^l\left(\sum_{k=1}^{N_{l-1}}w_{jk}^{l-1}\left(\dots f^1\left(\sum_{n=1}^{N_0} w_{mn}^1 x_n+ b_m^1\right)\dots\right)+b_k^2\right)+b_1^3\right] -\label{completeNN} \tag{9} -\end{equation} +\delta_j^l =\frac{\partial {\cal C}}{\partial z_j^l}. \]
    -

    which illustrates a basic property of MLPs: The only independent -variables are the input values \(x_n\).

    +

    We want to express this in terms of the equations for layer \(l+1\).

    -
    -

    Mathematical model

    -

    This confirms that an MLP, despite its quite convoluted mathematical -form, is nothing more than an analytic function, specifically a -mapping of real-valued vectors \(\hat{x} \in \mathbb{R}^n \rightarrow -\hat{y} \in \mathbb{R}^m\).

    -

    Furthermore, the flexibility and universality of an MLP can be -illustrated by realizing that the expression is essentially a nested -sum of scaled activation functions of the form

    - -
    +
    +

    Using the chain rule and summing over all \(k\) entries

    +

    We obtain

    \[ -\begin{equation} - f(x) = c_1 f(c_2 x + c_3) + c_4 -\label{_auto5} \tag{10} -\end{equation} +\delta_j^l =\sum_k \frac{\partial {\cal C}}{\partial z_k^{l+1}}\frac{\partial z_k^{l+1}}{\partial z_j^{l}}=\sum_k \delta_k^{l+1}\frac{\partial z_k^{l+1}}{\partial z_j^{l}}, \]
    -

    where the parameters \(c_i\) are weights and biases. By adjusting these -parameters, the activation functions can be shifted up and down or -left and right, change slope or be rescaled which is the key to the -flexibility of a neural network.

    -
    -

    Matrix-vector notation

    -

    We can introduce a more convenient notation for the activations in an A NN.

    -

    Additionally, we can represent the biases and activations -as layer-wise column vectors \(\hat{b}_l\) and \(\hat{y}_l\), so that the \(i\)-th element of each vector -is the bias \(b_i^l\) and activation \(y_i^l\) of node \(i\) in layer \(l\) respectively.

    -

    We have that \(\mathrm{W}_l\) is an \(N_{l-1} \times N_l\) matrix, while \(\hat{b}_l\) and \(\hat{y}_l\) are \(N_l \times 1\) column vectors. -With this notation, the sum becomes a matrix-vector multiplication, and we can write -the equation for the activations of hidden layer 2 (assuming three nodes for simplicity) as

    - -
    -
    -\[\begin{split} -\begin{equation} - \hat{y}_2 = f_2(\mathrm{W}_2 \hat{y}_{1} + \hat{b}_{2}) = - f_2\left(\left[\begin{array}{ccc} - w^2_{11} &w^2_{12} &w^2_{13} \\ - w^2_{21} &w^2_{22} &w^2_{23} \\ - w^2_{31} &w^2_{32} &w^2_{33} \\ - \end{array} \right] \cdot - \left[\begin{array}{c} - y^1_1 \\ - y^1_2 \\ - y^1_3 \\ - \end{array}\right] + - \left[\begin{array}{c} - b^2_1 \\ - b^2_2 \\ - b^2_3 \\ - \end{array}\right]\right). -\label{_auto6} \tag{11} -\end{equation} -\end{split}\]
    -
    -
    -

    Matrix-vector notation and activation

    -

    The activation of node \(i\) in layer 2 is

    - -
    +

    and recalling that

    \[ -\begin{equation} - y^2_i = f_2\Bigr(w^2_{i1}y^1_1 + w^2_{i2}y^1_2 + w^2_{i3}y^1_3 + b^2_i\Bigr) = - f_2\left(\sum_{j=1}^3 w^2_{ij} y_j^1 + b^2_i\right). -\label{_auto7} \tag{12} -\end{equation} +z_j^{l+1} = \sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1}, \]
    -

    This is not just a convenient and compact notation, but also a useful -and intuitive way to think about MLPs: The output is calculated by a -series of matrix-vector multiplications and vector additions that are -used as input to the activation functions. For each operation -\(\mathrm{W}_l \hat{y}_{l-1}\) we move forward one layer.

    +

    with \(M_l\) being the number of nodes in layer \(l\), we obtain

    +
    +\[ +\delta_j^l =\sum_k \delta_k^{l+1}w_{kj}^{l+1}\sigma'(z_j^l), +\]
    +

    This is our final equation.

    +

    We are now ready to set up the algorithm for back propagation and learning the weights and biases.

    +
    +

    Setting up the back propagation algorithm

    +

    The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.

    +

    First, we set up the input data \(\hat{x}\) and the activations +\(\hat{z}_1\) of the input layer and compute the activation function and +the pertinent outputs \(\hat{a}^1\).

    +

    Secondly, we perform then the feed forward till we reach the output +layer and compute all \(\hat{z}_l\) of the input layer and compute the +activation function and the pertinent outputs \(\hat{a}^l\) for +\(l=1,2,3,\dots,L\).

    +

    Notation: The first hidden layer has \(l=1\) as label and the final output layer has \(l=L\).

    +
    +
    +

    Setting up the back propagation algorithm, part 2

    +

    Thereafter we compute the ouput error \(\hat{\delta}^L\) by computing all

    +
    +\[ +\delta_j^L = \sigma'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}. +\]
    +

    Then we compute the back propagate error for each \(l=L-1,L-2,\dots,1\) as

    +
    +\[ +\delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}\sigma'(z_j^l). +\]
    +
    +
    +

    Setting up the Back propagation algorithm, part 3

    +

    Finally, we update the weights and the biases using gradient descent +for each \(l=L-1,L-2,\dots,1\) and update the weights and biases +according to the rules

    +
    +\[ +w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, +\]
    +
    +\[ +b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, +\]
    +

    with \(\eta\) being the learning rate.

    +
    +
    +

    Updating the gradients

    +

    With the back propagate error for each \(l=L-1,L-2,\dots,1\) as

    +
    +\[ +\delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}sigma'(z_j^l), +\]
    +

    we update the weights and the biases using gradient descent for each \(l=L-1,L-2,\dots,1\) and update the weights and biases according to the rules

    +
    +\[ +w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, +\]
    +
    +\[ +b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, +\]

    Activation functions

    A property that characterizes a neural network, other than its @@ -1787,1904 +3280,283 @@ become the most popular for deep neural networks

    -_images/week41_59_0.png -_images/week41_59_1.png -_images/week41_59_2.png -_images/week41_59_3.png +_images/week41_304_0.png +_images/week41_304_1.png +_images/week41_304_2.png +_images/week41_304_3.png
    -
    -

    The multilayer perceptron (MLP)

    -

    The multilayer perceptron is a very popular, and easy to implement approach, to deep learning. It consists of

    -
      -
    1. A neural network with one or more layers of nodes between the input and the output nodes.

    2. -
    3. The multilayer network structure, or architecture, or topology, consists of an input layer, one or more hidden layers, and one output layer.

    4. -
    5. The input nodes pass values to the first hidden layer, its nodes pass the information on to the second and so on till we reach the output layer.

    6. -
    -

    As a convention it is normal to call a network with one layer of input units, one layer of hidden -units and one layer of output units as a two-layer network. A network with two layers of hidden units is called a three-layer network etc etc.

    -

    For an MLP network there is no direct connection between the output nodes/neurons/units and the input nodes/neurons/units. -Hereafter we will call the various entities of a layer for nodes. -There are also no connections within a single layer.

    -

    The number of input nodes does not need to equal the number of output -nodes. This applies also to the hidden layers. Each layer may have its -own number of nodes and activation functions.

    -

    The hidden layers have their name from the fact that they are not -linked to observables and as we will see below when we define the -so-called activation \(\hat{z}\), we can think of this as a basis -expansion of the original inputs \(\hat{x}\). The difference however -between neural networks and say linear regression is that now these -basis functions (which will correspond to the weights in the network) -are learned from data. This results in an important difference between -neural networks and deep learning approaches on one side and methods -like logistic regression or linear regression and their modifications on the other side.

    -
    -
    -

    From one to many layers, the universal approximation theorem

    -

    A neural network with only one layer, what we called the simple -perceptron, is best suited if we have a standard binary model with -clear (linear) boundaries between the outcomes. As such it could -equally well be replaced by standard linear regression or logistic -regression. Networks with one or more hidden layers approximate -systems with more complex boundaries.

    -

    As stated earlier, -an important theorem in studies of neural networks, restated without -proof here, is the universal approximation -theorem.

    -

    It states that a feed-forward network with a single hidden layer -containing a finite number of neurons can approximate continuous -functions on compact subsets of real functions. The theorem thus -states that simple neural networks can represent a wide variety of -interesting functions when given appropriate parameters. It is the -multilayer feedforward architecture itself which gives neural networks -the potential of being universal approximators.

    -
    -
    -

    Deriving the back propagation code for a multilayer perceptron model

    -

    As we have seen now in a feed forward network, we can express the final output of our network in terms of basic matrix-vector multiplications. -The unknowwn quantities are our weights \(w_{ij}\) and we need to find an algorithm for changing them so that our errors are as small as possible. -This leads us to the famous back propagation algorithm.

    -

    The questions we want to ask are how do changes in the biases and the -weights in our network change the cost function and how can we use the -final output to modify the weights?

    -

    To derive these equations let us start with a plain regression problem -and define our cost function as

    -
    -\[ -{\cal C}(\hat{W}) = \frac{1}{2}\sum_{i=1}^n\left(y_i - t_i\right)^2, -\]
    -

    where the \(t_i\)s are our \(n\) targets (the values we want to -reproduce), while the outputs of the network after having propagated -all inputs \(\hat{x}\) are given by \(y_i\). Below we will demonstrate -how the basic equations arising from the back propagation algorithm -can be modified in order to study classification problems with \(K\) -classes.

    -
    -
    -

    Definitions

    -

    With our definition of the targets \(\hat{t}\), the outputs of the -network \(\hat{y}\) and the inputs \(\hat{x}\) we -define now the activation \(z_j^l\) of node/neuron/unit \(j\) of the -\(l\)-th layer as a function of the bias, the weights which add up from -the previous layer \(l-1\) and the forward passes/outputs -\(\hat{a}^{l-1}\) from the previous layer as

    -
    -\[ -z_j^l = \sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l, -\]
    -

    where \(b_k^l\) are the biases from layer \(l\). Here \(M_{l-1}\) -represents the total number of nodes/neurons/units of layer \(l-1\). The -figure here illustrates this equation. We can rewrite this in a more -compact form as the matrix-vector products we discussed earlier,

    -
    -\[ -\hat{z}^l = \left(\hat{W}^l\right)^T\hat{a}^{l-1}+\hat{b}^l. -\]
    -

    With the activation values \(\hat{z}^l\) we can in turn define the -output of layer \(l\) as \(\hat{a}^l = f(\hat{z}^l)\) where \(f\) is our -activation function. In the examples here we will use the sigmoid -function discussed in our logistic regression lectures. We will also use the same activation function \(f\) for all layers -and their nodes. It means we have

    -
    -\[ -a_j^l = f(z_j^l) = \frac{1}{1+\exp{-(z_j^l)}}. -\]
    -
    -
    -

    Derivatives and the chain rule

    -

    From the definition of the activation \(z_j^l\) we have

    -
    -\[ -\frac{\partial z_j^l}{\partial w_{ij}^l} = a_i^{l-1}, -\]
    -

    and

    -
    -\[ -\frac{\partial z_j^l}{\partial a_i^{l-1}} = w_{ji}^l. -\]
    -

    With our definition of the activation function we have that (note that this function depends only on \(z_j^l\))

    -
    -\[ -\frac{\partial a_j^l}{\partial z_j^{l}} = a_j^l(1-a_j^l)=f(z_j^l)(1-f(z_j^l)). -\]
    -
    -
    -

    Derivative of the cost function

    -

    With these definitions we can now compute the derivative of the cost function in terms of the weights.

    -

    Let us specialize to the output layer \(l=L\). Our cost function is

    -
    -\[ -{\cal C}(\hat{W^L}) = \frac{1}{2}\sum_{i=1}^n\left(y_i - t_i\right)^2=\frac{1}{2}\sum_{i=1}^n\left(a_i^L - t_i\right)^2, -\]
    -

    The derivative of this function with respect to the weights is

    -
    -\[ -\frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \left(a_j^L - t_j\right)\frac{\partial a_j^L}{\partial w_{jk}^{L}}, -\]
    -

    The last partial derivative can easily be computed and reads (by applying the chain rule)

    -
    -\[ -\frac{\partial a_j^L}{\partial w_{jk}^{L}} = \frac{\partial a_j^L}{\partial z_{j}^{L}}\frac{\partial z_j^L}{\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1}, -\]
    -
    -
    -

    Bringing it together, first back propagation equation

    -

    We have thus

    -
    -\[ -\frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \left(a_j^L - t_j\right)a_j^L(1-a_j^L)a_k^{L-1}, -\]
    -

    Defining

    -
    -\[ -\delta_j^L = a_j^L(1-a_j^L)\left(a_j^L - t_j\right) = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}, -\]
    -

    and using the Hadamard product of two vectors we can write this as

    -
    -\[ -\hat{\delta}^L = f'(\hat{z}^L)\circ\frac{\partial {\cal C}}{\partial (\hat{a}^L)}. -\]
    -

    This is an important expression. The second term on the right handside -measures how fast the cost function is changing as a function of the \(j\)th -output activation. If, for example, the cost function doesn’t depend -much on a particular output node \(j\), then \(\delta_j^L\) will be small, -which is what we would expect. The first term on the right, measures -how fast the activation function \(f\) is changing at a given activation -value \(z_j^L\).

    -

    Notice that everything in the above equations is easily computed. In -particular, we compute \(z_j^L\) while computing the behaviour of the -network, and it is only a small additional overhead to compute -\(f'(z^L_j)\). The exact form of the derivative with respect to the -output depends on the form of the cost function. -However, provided the cost function is known there should be little -trouble in calculating

    -
    -\[ -\frac{\partial {\cal C}}{\partial (a_j^L)} -\]
    -

    With the definition of \(\delta_j^L\) we have a more compact definition of the derivative of the cost function in terms of the weights, namely

    -
    -\[ -\frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \delta_j^La_k^{L-1}. -\]
    -
    -
    -

    Derivatives in terms of \(z_j^L\)

    -

    It is also easy to see that our previous equation can be written as

    -
    -\[ -\delta_j^L =\frac{\partial {\cal C}}{\partial z_j^L}= \frac{\partial {\cal C}}{\partial a_j^L}\frac{\partial a_j^L}{\partial z_j^L}, -\]
    -

    which can also be interpreted as the partial derivative of the cost function with respect to the biases \(b_j^L\), namely

    -
    -\[ -\delta_j^L = \frac{\partial {\cal C}}{\partial b_j^L}\frac{\partial b_j^L}{\partial z_j^L}=\frac{\partial {\cal C}}{\partial b_j^L}, -\]
    -

    That is, the error \(\delta_j^L\) is exactly equal to the rate of change of the cost function as a function of the bias.

    -
    -
    -

    Bringing it together

    -

    We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are

    -

    The starting equations.

    - -
    -
    -\[ -\begin{equation} -\frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \delta_j^La_k^{L-1}, -\label{_auto8} \tag{13} -\end{equation} -\]
    -

    and

    - -
    -
    -\[ -\begin{equation} -\delta_j^L = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}, -\label{_auto9} \tag{14} -\end{equation} -\]
    -

    and

    - -
    -
    -\[ -\begin{equation} -\delta_j^L = \frac{\partial {\cal C}}{\partial b_j^L}, -\label{_auto10} \tag{15} -\end{equation} -\]
    -

    An interesting consequence of the above equations is that when the -activation \(a_k^{L-1}\) is small, the gradient term, that is the -derivative of the cost function with respect to the weights, will also -tend to be small. We say then that the weight learns slowly, meaning -that it changes slowly when we minimize the weights via say gradient -descent. In this case we say the system learns slowly.

    -

    Another interesting feature is that is when the activation function, -represented by the sigmoid function here, is rather flat when we move towards -its end values \(0\) and \(1\) (see the above Python codes). In these -cases, the derivatives of the activation function will also be close -to zero, meaning again that the gradients will be small and the -network learns slowly again.

    -

    We need a fourth equation and we are set. We are going to propagate -backwards in order to the determine the weights and biases. In order -to do so we need to represent the error in the layer before the final -one \(L-1\) in terms of the errors in the final output layer.

    -
    -
    -

    Final back propagating equation

    -

    We have that (replacing \(L\) with a general layer \(l\))

    -
    -\[ -\delta_j^l =\frac{\partial {\cal C}}{\partial z_j^l}. -\]
    -

    We want to express this in terms of the equations for layer \(l+1\). Using the chain rule and summing over all \(k\) entries we have

    -
    -\[ -\delta_j^l =\sum_k \frac{\partial {\cal C}}{\partial z_k^{l+1}}\frac{\partial z_k^{l+1}}{\partial z_j^{l}}=\sum_k \delta_k^{l+1}\frac{\partial z_k^{l+1}}{\partial z_j^{l}}, -\]
    -

    and recalling that

    -
    -\[ -z_j^{l+1} = \sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1}, -\]
    -

    with \(M_l\) being the number of nodes in layer \(l\), we obtain

    -
    -\[ -\delta_j^l =\sum_k \delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l), -\]
    -

    This is our final equation.

    -

    We are now ready to set up the algorithm for back propagation and learning the weights and biases.

    -
    -
    -

    Setting up the Back propagation algorithm

    -

    The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.

    -

    First, we set up the input data \(\hat{x}\) and the activations -\(\hat{z}_1\) of the input layer and compute the activation function and -the pertinent outputs \(\hat{a}^1\).

    -

    Secondly, we perform then the feed forward till we reach the output -layer and compute all \(\hat{z}_l\) of the input layer and compute the -activation function and the pertinent outputs \(\hat{a}^l\) for -\(l=2,3,\dots,L\).

    -

    Thereafter we compute the ouput error \(\hat{\delta}^L\) by computing all

    -
    -\[ -\delta_j^L = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}. -\]
    -

    Then we compute the back propagate error for each \(l=L-1,L-2,\dots,2\) as

    -
    -\[ -\delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l). -\]
    -

    Finally, we update the weights and the biases using gradient descent for each \(l=L-1,L-2,\dots,2\) and update the weights and biases according to the rules

    -
    -\[ -w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, -\]
    -
    -\[ -b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, -\]
    -

    The parameter \(\eta\) is the learning parameter discussed in connection with the gradient descent methods. -Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training.

    -
    -
    -

    Setting up the Back propagation algorithm

    -

    The four equations above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.

    -

    First, we set up the input data \(\boldsymbol{x}\) and the activations -\(\boldsymbol{z}_1\) of the input layer and compute the activation function and -the pertinent outputs \(\boldsymbol{a}^1\).

    -

    Secondly, we perform then the feed forward till we reach the output -layer and compute all \(\boldsymbol{z}_l\) of the input layer and compute the -activation function and the pertinent outputs \(\boldsymbol{a}^l\) for -\(l=2,3,\dots,L\).

    -

    Thereafter we compute the ouput error \(\boldsymbol{\delta}^L\) by computing all

    -
    -\[ -\delta_j^L = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}. -\]
    -

    Then we compute the back propagate error for each \(l=L-1,L-2,\dots,2\) as

    -
    -\[ -\delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l). -\]
    -

    Finally, we update the weights and the biases using gradient descent for each \(l=L-1,L-2,\dots,2\) and update the weights and biases according to the rules

    -
    -\[ -w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, -\]
    -
    -\[ -b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, -\]
    -

    The parameter \(\eta\) is the learning parameter discussed in connection with the gradient descent methods. -Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training.

    -
    -
    -

    Setting up the Back propagation algorithm

    -

    The four equations derived discussed above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.

    -

    First, we set up the input data \(\boldsymbol{x}\) and the activations -\(\boldsymbol{z}_1\) of the input layer and compute the activation function and -the pertinent outputs \(\boldsymbol{a}^1\).

    -

    Secondly, we perform then the feed forward till we reach the output -layer and compute all \(\boldsymbol{z}_l\) of the input layer and compute the -activation function and the pertinent outputs \(\boldsymbol{a}^l\) for -\(l=2,3,\dots,L\).

    -

    Thereafter we compute the ouput error \(\boldsymbol{\delta}^L\) by computing all

    -
    -\[ -\delta_j^L = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}. -\]
    -

    Then we compute the back propagate error for each \(l=L-1,L-2,\dots,2\) as

    -
    -\[ -\delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l). -\]
    -

    Finally, we update the weights and the biases using gradient descent for each \(l=L-1,L-2,\dots,2\) and update the weights and biases according to the rules

    -
    -\[ -w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, -\]
    -
    -\[ -b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, -\]
    -

    The parameter \(\eta\) is the learning parameter discussed in connection with the gradient descent methods. -Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training.

    -
    -
    -

    Setting up a Multi-layer perceptron model for classification

    -

    We are now gong to develop an example based on the MNIST data -base. This is a classification problem and we need to use our -cross-entropy function we discussed in connection with logistic -regression. The cross-entropy defines our cost function for the -classificaton problems with neural networks.

    -

    In binary classification with two classes \((0, 1)\) we define the -logistic/sigmoid function as the probability that a particular input -is in class \(0\) or \(1\). This is possible because the logistic -function takes any input from the real numbers and inputs a number -between 0 and 1, and can therefore be interpreted as a probability. It -also has other nice properties, such as a derivative that is simple to -calculate.

    -

    For an input \(\boldsymbol{a}\) from the hidden layer, the probability that the input \(\boldsymbol{x}\) -is in class 0 or 1 is just. We let \(\theta\) represent the unknown weights and biases to be adjusted by our equations). The variable \(x\) -represents our activation values \(z\). We have

    -
    -\[ -P(y = 0 \mid \boldsymbol{x}, \boldsymbol{\theta}) = \frac{1}{1 + \exp{(- \boldsymbol{x}})} , -\]
    -

    and

    -
    -\[ -P(y = 1 \mid \boldsymbol{x}, \boldsymbol{\theta}) = 1 - P(y = 0 \mid \boldsymbol{x}, \boldsymbol{\theta}) , -\]
    -

    where \(y \in \{0, 1\}\) and \(\boldsymbol{\theta}\) represents the weights and biases -of our network.

    -
    -
    -

    Defining the cost function

    -

    Our cost function is given as (see the Logistic regression lectures)

    -
    -\[ -\mathcal{C}(\boldsymbol{\theta}) = - \ln P(\mathcal{D} \mid \boldsymbol{\theta}) = - \sum_{i=1}^n -y_i \ln[P(y_i = 0)] + (1 - y_i) \ln [1 - P(y_i = 0)] = \sum_{i=1}^n \mathcal{L}_i(\boldsymbol{\theta}) . -\]
    -

    This last equality means that we can interpret our cost function as a sum over the loss function -for each point in the dataset \(\mathcal{L}_i(\boldsymbol{\theta})\).
    -The negative sign is just so that we can think about our algorithm as minimizing a positive number, rather -than maximizing a negative number.

    -

    In multiclass classification it is common to treat each integer label as a so called one-hot vector:

    -

    \(y = 5 \quad \rightarrow \quad \boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,\) and

    -

    \(y = 1 \quad \rightarrow \quad \boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,\)

    -

    i.e. a binary bit string of length \(C\), where \(C = 10\) is the number of classes in the MNIST dataset (numbers from \(0\) to \(9\))..

    -

    If \(\boldsymbol{x}_i\) is the \(i\)-th input (image), \(y_{ic}\) refers to the \(c\)-th component of the \(i\)-th -output vector \(\boldsymbol{y}_i\).
    -The probability of \(\boldsymbol{x}_i\) being in class \(c\) will be given by the softmax function:

    -
    -\[ -P(y_{ic} = 1 \mid \boldsymbol{x}_i, \boldsymbol{\theta}) = \frac{\exp{((\boldsymbol{a}_i^{hidden})^T \boldsymbol{w}_c)}} -{\sum_{c'=0}^{C-1} \exp{((\boldsymbol{a}_i^{hidden})^T \boldsymbol{w}_{c'})}} , -\]
    -

    which reduces to the logistic function in the binary case.
    -The likelihood of this \(C\)-class classifier -is now given as:

    -
    -\[ -P(\mathcal{D} \mid \boldsymbol{\theta}) = \prod_{i=1}^n \prod_{c=0}^{C-1} [P(y_{ic} = 1)]^{y_{ic}} . -\]
    -

    Again we take the negative log-likelihood to define our cost function:

    -
    -\[ -\mathcal{C}(\boldsymbol{\theta}) = - \log{P(\mathcal{D} \mid \boldsymbol{\theta})}. -\]
    -

    See the logistic regression lectures for a full definition of the cost function.

    -

    The back propagation equations need now only a small change, namely the definition of a new cost function. We are thus ready to use the same equations as before!

    -
    -
    -

    Example: binary classification problem

    -

    As an example of the above, relevant for project 2 as well, let us consider a binary class. As discussed in our logistic regression lectures, we defined a cost function in terms of the parameters \(\beta\) as

    -
    -\[ -\mathcal{C}(\boldsymbol{\beta}) = - \sum_{i=1}^n \left(y_i\log{p(y_i \vert x_i,\boldsymbol{\beta})}+(1-y_i)\log{1-p(y_i \vert x_i,\boldsymbol{\beta})}\right), -\]
    -

    where we had defined the logistic (sigmoid) function

    -
    -\[ -p(y_i =1\vert x_i,\boldsymbol{\beta})=\frac{\exp{(\beta_0+\beta_1 x_i)}}{1+\exp{(\beta_0+\beta_1 x_i)}}, -\]
    -

    and

    -
    -\[ -p(y_i =0\vert x_i,\boldsymbol{\beta})=1-p(y_i =1\vert x_i,\boldsymbol{\beta}). -\]
    -

    The parameters \(\boldsymbol{\beta}\) were defined using a minimization method like gradient descent or Newton-Raphson’s method.

    -

    Now we replace \(x_i\) with the activation \(z_i^l\) for a given layer \(l\) and the outputs as \(y_i=a_i^l=f(z_i^l)\), with \(z_i^l\) now being a function of the weights \(w_{ij}^l\) and biases \(b_i^l\). -We have then

    -
    -\[ -a_i^l = y_i = \frac{\exp{(z_i^l)}}{1+\exp{(z_i^l)}}, -\]
    -

    with

    -
    -\[ -z_i^l = \sum_{j}w_{ij}^l a_j^{l-1}+b_i^l, -\]
    -

    where the superscript \(l-1\) indicates that these are the outputs from layer \(l-1\). -Our cost function at the final layer \(l=L\) is now

    -
    -\[ -\mathcal{C}(\boldsymbol{W}) = - \sum_{i=1}^n \left(t_i\log{a_i^L}+(1-t_i)\log{(1-a_i^L)}\right), -\]
    -

    where we have defined the targets \(t_i\). The derivatives of the cost function with respect to the output \(a_i^L\) are then easily calculated and we get

    -
    -\[ -\frac{\partial \mathcal{C}(\boldsymbol{W})}{\partial a_i^L} = \frac{a_i^L-t_i}{a_i^L(1-a_i^L)}. -\]
    -

    In case we use another activation function than the logistic one, we need to evaluate other derivatives.

    -
    -
    -

    The Softmax function

    -

    In case we employ the more general case given by the Softmax equation, we need to evaluate the derivative of the activation function with respect to the activation \(z_i^l\), that is we need

    -
    -\[ -\frac{\partial f(z_i^l)}{\partial w_{jk}^l} = -\frac{\partial f(z_i^l)}{\partial z_j^l} \frac{\partial z_j^l}{\partial w_{jk}^l}= \frac{\partial f(z_i^l)}{\partial z_j^l}a_k^{l-1}. -\]
    -

    For the Softmax function we have

    -
    -\[ -f(z_i^l) = \frac{\exp{(z_i^l)}}{\sum_{m=1}^K\exp{(z_m^l)}}. -\]
    -

    Its derivative with respect to \(z_j^l\) gives

    -
    -\[ -\frac{\partial f(z_i^l)}{\partial z_j^l}= f(z_i^l)\left(\delta_{ij}-f(z_j^l)\right), -\]
    -

    which in case of the simply binary model reduces to having \(i=j\).

    -
    -
    -

    Developing a code for doing neural networks with back propagation

    -

    One can identify a set of key steps when using neural networks to solve supervised learning problems:

    -
      -
    1. Collect and pre-process data

    2. -
    3. Define model and architecture

    4. -
    5. Choose cost function and optimizer

    6. -
    7. Train the model

    8. -
    9. Evaluate model performance on test data

    10. -
    11. Adjust hyperparameters (if necessary, network architecture)

    12. -
    -
    -
    -

    Collect and pre-process data

    -

    Here we will be using the MNIST dataset, which is readily available through the scikit-learn -package. You may also find it for example here.
    -The MNIST (Modified National Institute of Standards and Technology) database is a large database -of handwritten digits that is commonly used for training various image processing systems.
    -The MNIST dataset consists of 70 000 images of size \(28\times 28\) pixels, each labeled from 0 to 9.
    -The scikit-learn dataset we will use consists of a selection of 1797 images of size \(8\times 8\) collected and processed from this database.

    -

    To feed data into a feed-forward neural network we need to represent -the inputs as a design/feature matrix \(X = (n_{inputs}, n_{features})\). Each -row represents an input, in this case a handwritten digit, and -each column represents a feature, in this case a pixel. The -correct answers, also known as labels or targets are -represented as a 1D array of integers -\(Y = (n_{inputs}) = (5, 3, 1, 8,...)\).

    -

    As an example, say we want to build a neural network using supervised learning to predict Body-Mass Index (BMI) from -measurements of height (in m)
    -and weight (in kg). If we have measurements of 5 people the design/feature matrix could be for example:

    -
    -\[\begin{split} X = \begin{bmatrix} -1.85 & 81\\ -1.71 & 65\\ -1.95 & 103\\ -1.55 & 42\\ -1.63 & 56 -\end{bmatrix} ,\end{split}\]
    -

    and the targets would be:

    -
    -\[ Y = (23.7, 22.2, 27.1, 17.5, 21.1) \]
    -

    Since each input image is a 2D matrix, we need to flatten the image -(i.e. “unravel” the 2D matrix into a 1D array) to turn the data into a -design/feature matrix. This means we lose all spatial information in the -image, such as locality and translational invariance. More complicated -architectures such as Convolutional Neural Networks can take advantage -of such information, and are most commonly applied when analyzing -images.

    -
    -
    -
    # import necessary packages
    -import numpy as np
    -import matplotlib.pyplot as plt
    -from sklearn import datasets
    -
    -
    -# ensure the same random numbers appear every time
    -np.random.seed(0)
    -
    -# display images in notebook
    -%matplotlib inline
    -plt.rcParams['figure.figsize'] = (12,12)
    -
    -
    -# download MNIST dataset
    -digits = datasets.load_digits()
    -
    -# define inputs and labels
    -inputs = digits.images
    -labels = digits.target
    -
    -print("inputs = (n_inputs, pixel_width, pixel_height) = " + str(inputs.shape))
    -print("labels = (n_inputs) = " + str(labels.shape))
    -
    -
    -# flatten the image
    -# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64
    -n_inputs = len(inputs)
    -inputs = inputs.reshape(n_inputs, -1)
    -print("X = (n_inputs, n_features) = " + str(inputs.shape))
    -
    -
    -# choose some random images to display
    -indices = np.arange(n_inputs)
    -random_indices = np.random.choice(indices, size=5)
    -
    -for i, image in enumerate(digits.images[random_indices]):
    -    plt.subplot(1, 5, i+1)
    -    plt.axis('off')
    -    plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
    -    plt.title("Label: %d" % digits.target[random_indices[i]])
    -plt.show()
    -
    -
    -
    -
    -
    inputs = (n_inputs, pixel_width, pixel_height) = (1797, 8, 8)
    -labels = (n_inputs) = (1797,)
    -X = (n_inputs, n_features) = (1797, 64)
    -
    -
    -_images/week41_176_1.png -
    -
    -
    -
    -

    Train and test datasets

    -

    Performing analysis before partitioning the dataset is a major error, that can lead to incorrect conclusions.

    -

    We will reserve \(80 \%\) of our dataset for training and \(20 \%\) for testing.

    -

    It is important that the train and test datasets are drawn randomly from our dataset, to ensure -no bias in the sampling.
    -Say you are taking measurements of weather data to predict the weather in the coming 5 days. -You don’t want to train your model on measurements taken from the hours 00.00 to 12.00, and then test it on data -collected from 12.00 to 24.00.

    -
    -
    -
    from sklearn.model_selection import train_test_split
    -
    -# one-liner from scikit-learn library
    -train_size = 0.8
    -test_size = 1 - train_size
    -X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
    -                                                    test_size=test_size)
    -
    -# equivalently in numpy
    -def train_test_split_numpy(inputs, labels, train_size, test_size):
    -    n_inputs = len(inputs)
    -    inputs_shuffled = inputs.copy()
    -    labels_shuffled = labels.copy()
    -    
    -    np.random.shuffle(inputs_shuffled)
    -    np.random.shuffle(labels_shuffled)
    -    
    -    train_end = int(n_inputs*train_size)
    -    X_train, X_test = inputs_shuffled[:train_end], inputs_shuffled[train_end:]
    -    Y_train, Y_test = labels_shuffled[:train_end], labels_shuffled[train_end:]
    -    
    -    return X_train, X_test, Y_train, Y_test
    -
    -#X_train, X_test, Y_train, Y_test = train_test_split_numpy(inputs, labels, train_size, test_size)
    -
    -print("Number of training images: " + str(len(X_train)))
    -print("Number of test images: " + str(len(X_test)))
    -
    -
    -
    -
    -
    Number of training images: 1437
    -Number of test images: 360
    -
    -
    -
    -
    -
    -
    -

    Define model and architecture

    -

    Our simple feed-forward neural network will consist of an input layer, a single hidden layer and an output layer. The activation \(y\) of each neuron is a weighted sum of inputs, passed through an activation function. In case of the simple perceptron model we have

    -
    -\[ z = \sum_{i=1}^n w_i a_i ,\]
    -
    -\[ y = f(z) ,\]
    -

    where \(f\) is the activation function, \(a_i\) represents input from neuron \(i\) in the preceding layer -and \(w_i\) is the weight to input \(i\).
    -The activation of the neurons in the input layer is just the features (e.g. a pixel value).

    -

    The simplest activation function for a neuron is the Heaviside function:

    -
    -\[\begin{split} f(z) = -\begin{cases} -1, & z > 0\\ -0, & \text{otherwise} -\end{cases} -\end{split}\]
    -

    A feed-forward neural network with this activation is known as a perceptron.
    -For a binary classifier (i.e. two classes, 0 or 1, dog or not-dog) we can also use this in our output layer.
    -This activation can be generalized to \(k\) classes (using e.g. the one-against-all strategy), -and we call these architectures multiclass perceptrons.

    -

    However, it is now common to use the terms Single Layer Perceptron (SLP) (1 hidden layer) and
    -Multilayer Perceptron (MLP) (2 or more hidden layers) to refer to feed-forward neural networks with any activation function.

    -

    Typical choices for activation functions include the sigmoid function, hyperbolic tangent, and Rectified Linear Unit (ReLU).
    -We will be using the sigmoid function \(\sigma(x)\):

    -
    -\[ f(x) = \sigma(x) = \frac{1}{1 + e^{-x}} ,\]
    -

    which is inspired by probability theory (see logistic regression) and was most commonly used until about 2011. See the discussion below concerning other activation functions.

    -
    -
    -

    Layers

    +
    +

    Fine-tuning neural network hyperparameters

    +

    The flexibility of neural networks is also one of their main +drawbacks: there are many hyperparameters to tweak. Not only can you +use any imaginable network topology (how neurons/nodes are +interconnected), but even in a simple FFNN you can change the number +of layers, the number of neurons per layer, the type of activation +function to use in each layer, the weight initialization logic, the +stochastic gradient optmized and much more. How do you know what +combination of hyperparameters is the best for your task?

      -
    • Input

    • +
    • You can use grid search with cross-validation to find the right hyperparameters.

    -

    Since each input image has 8x8 = 64 pixels or features, we have an input layer of 64 neurons.

    +

    However,since there are many hyperparameters to tune, and since +training a neural network on a large dataset takes a lot of time, you +will only be able to explore a tiny part of the hyperparameter space.

      -
    • Hidden layer

    • +
    • You can use randomized search.

    • +
    • Or use tools like Oscar, which implements more complex algorithms to help you find a good set of hyperparameters quickly.

    -

    We will use 50 neurons in the hidden layer receiving input from the neurons in the input layer.
    -Since each neuron in the hidden layer is connected to the 64 inputs we have 64x50 = 3200 weights to the hidden layer.

    -
      -
    • Output

    • -
    -

    If we were building a binary classifier, it would be sufficient with a single neuron in the output layer, -which could output 0 or 1 according to the Heaviside function. This would be an example of a hard classifier, meaning it outputs the class of the input directly. However, if we are dealing with noisy data it is often beneficial to use a soft classifier, which outputs the probability of being in class 0 or 1.

    -

    For a soft binary classifier, we could use a single neuron and interpret the output as either being the probability of being in class 0 or the probability of being in class 1. Alternatively we could use 2 neurons, and interpret each neuron as the probability of being in each class.

    -

    Since we are doing multiclass classification, with 10 categories, it is natural to use 10 neurons in the output layer. We number the neurons \(j = 0,1,...,9\). The activation of each output neuron \(j\) will be according to the softmax function:

    -
    -\[ P(\text{class $j$} \mid \text{input $\boldsymbol{a}$}) = \frac{\exp{(\boldsymbol{a}^T \boldsymbol{w}_j)}} -{\sum_{c=0}^{9} \exp{(\boldsymbol{a}^T \boldsymbol{w}_c)}} ,\]
    -

    i.e. each neuron \(j\) outputs the probability of being in class \(j\) given an input from the hidden layer \(\boldsymbol{a}\), with \(\boldsymbol{w}_j\) the weights of neuron \(j\) to the inputs.
    -The denominator is a normalization factor to ensure the outputs (probabilities) sum up to 1.
    -The exponent is just the weighted sum of inputs as before:

    -
    -\[ z_j = \sum_{i=1}^n w_ {ij} a_i+b_j.\]
    -

    Since each neuron in the output layer is connected to the 50 inputs from the hidden layer we have 50x10 = 500 -weights to the output layer.

    -
    -

    Weights and biases

    -

    Typically weights are initialized with small values distributed around zero, drawn from a uniform -or normal distribution. Setting all weights to zero means all neurons give the same output, making the network useless.

    -

    Adding a bias value to the weighted sum of inputs allows the neural network to represent a greater range -of values. Without it, any input with the value 0 will be mapped to zero (before being passed through the activation). The bias unit has an output of 1, and a weight to each neuron \(j\), \(b_j\):

    -
    -\[ z_j = \sum_{i=1}^n w_ {ij} a_i + b_j.\]
    -

    The bias weights \(\boldsymbol{b}\) are often initialized to zero, but a small value like \(0.01\) ensures all neurons have some output which can be backpropagated in the first training cycle.

    -
    -
    -
    # building our neural network
    -
    -n_inputs, n_features = X_train.shape
    -n_hidden_neurons = 50
    -n_categories = 10
    -
    -# we make the weights normally distributed using numpy.random.randn
    -
    -# weights and bias in the hidden layer
    -hidden_weights = np.random.randn(n_features, n_hidden_neurons)
    -hidden_bias = np.zeros(n_hidden_neurons) + 0.01
    -
    -# weights and bias in the output layer
    -output_weights = np.random.randn(n_hidden_neurons, n_categories)
    -output_bias = np.zeros(n_categories) + 0.01
    -
    -
    -
    -
    -
    -
    -

    Feed-forward pass

    -

    Denote \(F\) the number of features, \(H\) the number of hidden neurons and \(C\) the number of categories.
    -For each input image we calculate a weighted sum of input features (pixel values) to each neuron \(j\) in the hidden layer \(l\):

    -
    -\[ z_{j}^{l} = \sum_{i=1}^{F} w_{ij}^{l} x_i + b_{j}^{l},\]
    -

    this is then passed through our activation function

    -
    -\[ a_{j}^{l} = f(z_{j}^{l}) .\]
    -

    We calculate a weighted sum of inputs (activations in the hidden layer) to each neuron \(j\) in the output layer:

    -
    -\[ z_{j}^{L} = \sum_{i=1}^{H} w_{ij}^{L} a_{i}^{l} + b_{j}^{L}.\]
    -

    Finally we calculate the output of neuron \(j\) in the output layer using the softmax function:

    -
    -\[ a_{j}^{L} = \frac{\exp{(z_j^{L})}} -{\sum_{c=0}^{C-1} \exp{(z_c^{L})}} .\]
    -
    -
    -

    Matrix multiplications

    -

    Since our data has the dimensions \(X = (n_{inputs}, n_{features})\) and our weights to the hidden -layer have the dimensions
    -\(W_{hidden} = (n_{features}, n_{hidden})\), -we can easily feed the network all our training data in one go by taking the matrix product

    -
    -\[ X W^{h} = (n_{inputs}, n_{hidden}),\]
    -

    and obtain a matrix that holds the weighted sum of inputs to the hidden layer -for each input image and each hidden neuron.
    -We also add the bias to obtain a matrix of weighted sums to the hidden layer \(Z^{h}\):

    -
    -\[ \boldsymbol{z}^{l} = \boldsymbol{X} \boldsymbol{W}^{l} + \boldsymbol{b}^{l} ,\]
    -

    meaning the same bias (1D array with size equal number of hidden neurons) is added to each input image.
    -This is then passed through the activation:

    -
    -\[ \boldsymbol{a}^{l} = f(\boldsymbol{z}^l) .\]
    -

    This is fed to the output layer:

    -
    -\[ \boldsymbol{z}^{L} = \boldsymbol{a}^{L} \boldsymbol{W}^{L} + \boldsymbol{b}^{L} .\]
    -

    Finally we receive our output values for each image and each category by passing it through the softmax function:

    -
    -\[ output = softmax (\boldsymbol{z}^{L}) = (n_{inputs}, n_{categories}) .\]
    -
    -
    -
    # setup the feed-forward pass, subscript h = hidden layer
    -
    -def sigmoid(x):
    -    return 1/(1 + np.exp(-x))
    -
    -def feed_forward(X):
    -    # weighted sum of inputs to the hidden layer
    -    z_h = np.matmul(X, hidden_weights) + hidden_bias
    -    # activation in the hidden layer
    -    a_h = sigmoid(z_h)
    -    
    -    # weighted sum of inputs to the output layer
    -    z_o = np.matmul(a_h, output_weights) + output_bias
    -    # softmax output
    -    # axis 0 holds each input and axis 1 the probabilities of each category
    -    exp_term = np.exp(z_o)
    -    probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -    
    -    return probabilities
    -
    -probabilities = feed_forward(X_train)
    -print("probabilities = (n_inputs, n_categories) = " + str(probabilities.shape))
    -print("probability that image 0 is in category 0,1,2,...,9 = \n" + str(probabilities[0]))
    -print("probabilities sum up to: " + str(probabilities[0].sum()))
    -print()
    -
    -# we obtain a prediction by taking the class with the highest likelihood
    -def predict(X):
    -    probabilities = feed_forward(X)
    -    return np.argmax(probabilities, axis=1)
    -
    -predictions = predict(X_train)
    -print("predictions = (n_inputs) = " + str(predictions.shape))
    -print("prediction for image 0: " + str(predictions[0]))
    -print("correct label for image 0: " + str(Y_train[0]))
    -
    -
    -
    -
    -
    probabilities = (n_inputs, n_categories) = (1437, 10)
    -probability that image 0 is in category 0,1,2,...,9 = 
    -[5.41511965e-04 2.17174962e-03 8.84355903e-03 1.44970586e-03
    - 1.10378326e-04 5.08318298e-09 2.03256632e-04 1.92507116e-03
    - 9.84443254e-01 3.11507992e-04]
    -probabilities sum up to: 1.0
    -
    -predictions = (n_inputs) = (1437,)
    -prediction for image 0: 8
    -correct label for image 0: 6
    -
    -
    -
    -
    -
    -
    -

    Choose cost function and optimizer

    -

    To measure how well our neural network is doing we need to introduce a cost function.
    -We will call the function that gives the error of a single sample output the loss function, and the function -that gives the total error of our network across all samples the cost function. -A typical choice for multiclass classification is the cross-entropy loss, also known as the negative log likelihood.

    -

    In multiclass classification it is common to treat each integer label as a so called one-hot vector:

    -
    -\[ y = 5 \quad \rightarrow \quad \boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,\]
    -
    -\[ y = 1 \quad \rightarrow \quad \boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,\]
    -

    i.e. a binary bit string of length \(C\), where \(C = 10\) is the number of classes in the MNIST dataset.

    -

    Let \(y_{ic}\) denote the \(c\)-th component of the \(i\)-th one-hot vector.
    -We define the cost function \(\mathcal{C}\) as a sum over the cross-entropy loss for each point \(\boldsymbol{x}_i\) in the dataset.

    -

    In the one-hot representation only one of the terms in the loss function is non-zero, namely the -probability of the correct category \(c'\)
    -(i.e. the category \(c'\) such that \(y_{ic'} = 1\)). This means that the cross entropy loss only punishes you for how wrong -you got the correct label. The probability of category \(c\) is given by the softmax function. The vector \(\boldsymbol{\theta}\) represents the parameters of our network, i.e. all the weights and biases.

    -
    -
    -

    Optimizing the cost function

    -

    The network is trained by finding the weights and biases that minimize the cost function. One of the most widely used classes of methods is gradient descent and its generalizations. The idea behind gradient descent -is simply to adjust the weights in the direction where the gradient of the cost function is large and negative. This ensures we flow toward a local minimum of the cost function.
    -Each parameter \(\theta\) is iteratively adjusted according to the rule

    -
    -\[ \theta_{i+1} = \theta_i - \eta \nabla \mathcal{C}(\theta_i) ,\]
    -

    where \(\eta\) is known as the learning rate, which controls how big a step we take towards the minimum.
    -This update can be repeated for any number of iterations, or until we are satisfied with the result.

    -

    A simple and effective improvement is a variant called Batch Gradient Descent.
    -Instead of calculating the gradient on the whole dataset, we calculate an approximation of the gradient -on a subset of the data called a minibatch.
    -If there are \(N\) data points and we have a minibatch size of \(M\), the total number of batches -is \(N/M\).
    -We denote each minibatch \(B_k\), with \(k = 1, 2,...,N/M\). The gradient then becomes:

    -
    -\[ \nabla \mathcal{C}(\theta) = \frac{1}{N} \sum_{i=1}^N \nabla \mathcal{L}_i(\theta) \quad \rightarrow \quad -\frac{1}{M} \sum_{i \in B_k} \nabla \mathcal{L}_i(\theta) ,\]
    -

    i.e. instead of averaging the loss over the entire dataset, we average over a minibatch.

    -

    This has two important benefits:

    -
      -
    1. Introducing stochasticity decreases the chance that the algorithm becomes stuck in a local minima.

    2. -
    3. It significantly speeds up the calculation, since we do not have to use the entire dataset to calculate the gradient.

    4. -
    -

    The various optmization methods, with codes and algorithms, are discussed in our lectures on Gradient descent approaches.

    -
    -
    -

    Regularization

    -

    It is common to add an extra term to the cost function, proportional -to the size of the weights. This is equivalent to constraining the -size of the weights, so that they do not grow out of control. -Constraining the size of the weights means that the weights cannot -grow arbitrarily large to fit the training data, and in this way -reduces overfitting.

    -

    We will measure the size of the weights using the so called L2-norm, meaning our cost function becomes:

    -
    -\[ \mathcal{C}(\theta) = \frac{1}{N} \sum_{i=1}^N \mathcal{L}_i(\theta) \quad \rightarrow \quad -\frac{1}{N} \sum_{i=1}^N \mathcal{L}_i(\theta) + \lambda \lvert \lvert \boldsymbol{w} \rvert \rvert_2^2 -= \frac{1}{N} \sum_{i=1}^N \mathcal{L}(\theta) + \lambda \sum_{ij} w_{ij}^2,\]
    -

    i.e. we sum up all the weights squared. The factor \(\lambda\) is known as a regularization parameter.

    -

    In order to train the model, we need to calculate the derivative of -the cost function with respect to every bias and weight in the -network. In total our network has \((64 + 1)\times 50=3250\) weights in -the hidden layer and \((50 + 1)\times 10=510\) weights to the output -layer (\(+1\) for the bias), and the gradient must be calculated for -every parameter. We use the backpropagation algorithm discussed -above. This is a clever use of the chain rule that allows us to -calculate the gradient efficently.

    -
    -
    -

    Matrix multiplication

    -

    To more efficently train our network these equations are implemented using matrix operations.
    -The error in the output layer is calculated simply as, with \(\boldsymbol{t}\) being our targets,

    -
    -\[ \delta_L = \boldsymbol{t} - \boldsymbol{y} = (n_{inputs}, n_{categories}) .\]
    -

    The gradient for the output weights is calculated as

    -
    -\[ \nabla W_{L} = \boldsymbol{a}^T \delta_L = (n_{hidden}, n_{categories}) ,\]
    -

    where \(\boldsymbol{a} = (n_{inputs}, n_{hidden})\). This simply means that we are summing up the gradients for each input.
    -Since we are going backwards we have to transpose the activation matrix.

    -

    The gradient with respect to the output bias is then

    -
    -\[ \nabla \boldsymbol{b}_{L} = \sum_{i=1}^{n_{inputs}} \delta_L = (n_{categories}) .\]
    -

    The error in the hidden layer is

    -
    -\[ \Delta_h = \delta_L W_{L}^T \circ f'(z_{h}) = \delta_L W_{L}^T \circ a_{h} \circ (1 - a_{h}) = (n_{inputs}, n_{hidden}) ,\]
    -

    where \(f'(a_{h})\) is the derivative of the activation in the hidden layer. The matrix products mean -that we are summing up the products for each neuron in the output layer. The symbol \(\circ\) denotes -the Hadamard product, meaning element-wise multiplication.

    -

    This again gives us the gradients in the hidden layer:

    -
    -\[ \nabla W_{h} = X^T \delta_h = (n_{features}, n_{hidden}) ,\]
    -
    -\[ \nabla b_{h} = \sum_{i=1}^{n_{inputs}} \delta_h = (n_{hidden}) .\]
    -
    -
    -
    # to categorical turns our integer vector into a onehot representation
    -from sklearn.metrics import accuracy_score
    -
    -# one-hot in numpy
    -def to_categorical_numpy(integer_vector):
    -    n_inputs = len(integer_vector)
    -    n_categories = np.max(integer_vector) + 1
    -    onehot_vector = np.zeros((n_inputs, n_categories))
    -    onehot_vector[range(n_inputs), integer_vector] = 1
    -    
    -    return onehot_vector
    -
    -#Y_train_onehot, Y_test_onehot = to_categorical(Y_train), to_categorical(Y_test)
    -Y_train_onehot, Y_test_onehot = to_categorical_numpy(Y_train), to_categorical_numpy(Y_test)
    -
    -def feed_forward_train(X):
    -    # weighted sum of inputs to the hidden layer
    -    z_h = np.matmul(X, hidden_weights) + hidden_bias
    -    # activation in the hidden layer
    -    a_h = sigmoid(z_h)
    -    
    -    # weighted sum of inputs to the output layer
    -    z_o = np.matmul(a_h, output_weights) + output_bias
    -    # softmax output
    -    # axis 0 holds each input and axis 1 the probabilities of each category
    -    exp_term = np.exp(z_o)
    -    probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -    
    -    # for backpropagation need activations in hidden and output layers
    -    return a_h, probabilities
    -
    -def backpropagation(X, Y):
    -    a_h, probabilities = feed_forward_train(X)
    -    
    -    # error in the output layer
    -    error_output = probabilities - Y
    -    # error in the hidden layer
    -    error_hidden = np.matmul(error_output, output_weights.T) * a_h * (1 - a_h)
    -    
    -    # gradients for the output layer
    -    output_weights_gradient = np.matmul(a_h.T, error_output)
    -    output_bias_gradient = np.sum(error_output, axis=0)
    -    
    -    # gradient for the hidden layer
    -    hidden_weights_gradient = np.matmul(X.T, error_hidden)
    -    hidden_bias_gradient = np.sum(error_hidden, axis=0)
    -
    -    return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient
    -
    -print("Old accuracy on training data: " + str(accuracy_score(predict(X_train), Y_train)))
    -
    -eta = 0.01
    -lmbd = 0.01
    -for i in range(1000):
    -    # calculate gradients
    -    dWo, dBo, dWh, dBh = backpropagation(X_train, Y_train_onehot)
    -    
    -    # regularization term gradients
    -    dWo += lmbd * output_weights
    -    dWh += lmbd * hidden_weights
    -    
    -    # update weights and biases
    -    output_weights -= eta * dWo
    -    output_bias -= eta * dBo
    -    hidden_weights -= eta * dWh
    -    hidden_bias -= eta * dBh
    -
    -print("New accuracy on training data: " + str(accuracy_score(predict(X_train), Y_train)))
    -
    -
    -
    -
    -
    Old accuracy on training data: 0.1440501043841336
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    New accuracy on training data: 0.09951287404314545
    -
    -
    -
    -
    -
    -
    -

    Improving performance

    -

    As we can see the network does not seem to be learning at all. It seems to be just guessing the label for each image.
    -In order to obtain a network that does something useful, we will have to do a bit more work.

    -

    The choice of hyperparameters such as learning rate and regularization parameter is hugely influential for the performance of the network. Typically a grid-search is performed, wherein we test different hyperparameters separated by orders of magnitude. For example we could test the learning rates \(\eta = 10^{-6}, 10^{-5},...,10^{-1}\) with different regularization parameters \(\lambda = 10^{-6},...,10^{-0}\).

    -

    Next, we haven’t implemented minibatching yet, which introduces stochasticity and is though to act as an important regularizer on the weights. We call a feed-forward + backward pass with a minibatch an iteration, and a full training period -going through the entire dataset (\(n/M\) batches) an epoch.

    -

    If this does not improve network performance, you may want to consider altering the network architecture, adding more neurons or hidden layers.
    -Andrew Ng goes through some of these considerations in this video. You can find a summary of the video here.

    -
    -
    -

    Full object-oriented implementation

    -

    It is very natural to think of the network as an object, with specific instances of the network -being realizations of this object with different hyperparameters. An implementation using Python classes provides a clean structure and interface, and the full implementation of our neural network is given below.

    -
    -
    -
    class NeuralNetwork:
    -    def __init__(
    -            self,
    -            X_data,
    -            Y_data,
    -            n_hidden_neurons=50,
    -            n_categories=10,
    -            epochs=10,
    -            batch_size=100,
    -            eta=0.1,
    -            lmbd=0.0):
    -
    -        self.X_data_full = X_data
    -        self.Y_data_full = Y_data
    -
    -        self.n_inputs = X_data.shape[0]
    -        self.n_features = X_data.shape[1]
    -        self.n_hidden_neurons = n_hidden_neurons
    -        self.n_categories = n_categories
    -
    -        self.epochs = epochs
    -        self.batch_size = batch_size
    -        self.iterations = self.n_inputs // self.batch_size
    -        self.eta = eta
    -        self.lmbd = lmbd
    -
    -        self.create_biases_and_weights()
    -
    -    def create_biases_and_weights(self):
    -        self.hidden_weights = np.random.randn(self.n_features, self.n_hidden_neurons)
    -        self.hidden_bias = np.zeros(self.n_hidden_neurons) + 0.01
    -
    -        self.output_weights = np.random.randn(self.n_hidden_neurons, self.n_categories)
    -        self.output_bias = np.zeros(self.n_categories) + 0.01
    -
    -    def feed_forward(self):
    -        # feed-forward for training
    -        self.z_h = np.matmul(self.X_data, self.hidden_weights) + self.hidden_bias
    -        self.a_h = sigmoid(self.z_h)
    -
    -        self.z_o = np.matmul(self.a_h, self.output_weights) + self.output_bias
    -
    -        exp_term = np.exp(self.z_o)
    -        self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -    def feed_forward_out(self, X):
    -        # feed-forward for output
    -        z_h = np.matmul(X, self.hidden_weights) + self.hidden_bias
    -        a_h = sigmoid(z_h)
    -
    -        z_o = np.matmul(a_h, self.output_weights) + self.output_bias
    -        
    -        exp_term = np.exp(z_o)
    -        probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -        return probabilities
    -
    -    def backpropagation(self):
    -        error_output = self.probabilities - self.Y_data
    -        error_hidden = np.matmul(error_output, self.output_weights.T) * self.a_h * (1 - self.a_h)
    -
    -        self.output_weights_gradient = np.matmul(self.a_h.T, error_output)
    -        self.output_bias_gradient = np.sum(error_output, axis=0)
    -
    -        self.hidden_weights_gradient = np.matmul(self.X_data.T, error_hidden)
    -        self.hidden_bias_gradient = np.sum(error_hidden, axis=0)
    -
    -        if self.lmbd > 0.0:
    -            self.output_weights_gradient += self.lmbd * self.output_weights
    -            self.hidden_weights_gradient += self.lmbd * self.hidden_weights
    -
    -        self.output_weights -= self.eta * self.output_weights_gradient
    -        self.output_bias -= self.eta * self.output_bias_gradient
    -        self.hidden_weights -= self.eta * self.hidden_weights_gradient
    -        self.hidden_bias -= self.eta * self.hidden_bias_gradient
    -
    -    def predict(self, X):
    -        probabilities = self.feed_forward_out(X)
    -        return np.argmax(probabilities, axis=1)
    -
    -    def predict_probabilities(self, X):
    -        probabilities = self.feed_forward_out(X)
    -        return probabilities
    -
    -    def train(self):
    -        data_indices = np.arange(self.n_inputs)
    -
    -        for i in range(self.epochs):
    -            for j in range(self.iterations):
    -                # pick datapoints with replacement
    -                chosen_datapoints = np.random.choice(
    -                    data_indices, size=self.batch_size, replace=False
    -                )
    -
    -                # minibatch training data
    -                self.X_data = self.X_data_full[chosen_datapoints]
    -                self.Y_data = self.Y_data_full[chosen_datapoints]
    -
    -                self.feed_forward()
    -                self.backpropagation()
    -
    -
    -
    -
    -
    -
    -

    Evaluate model performance on test data

    -

    To measure the performance of our network we evaluate how well it does it data it has never seen before, i.e. the test data.
    -We measure the performance of the network using the accuracy score.
    -The accuracy is as you would expect just the number of images correctly labeled divided by the total number of images. A perfect classifier will have an accuracy score of \(1\).

    -
    -\[ \text{Accuracy} = \frac{\sum_{i=1}^n I(\tilde{y}_i = y_i)}{n} ,\]
    -

    where \(I\) is the indicator function, \(1\) if \(\tilde{y}_i = y_i\) and \(0\) otherwise.

    -
    -
    -
    epochs = 100
    -batch_size = 100
    -
    -dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,
    -                    n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)
    -dnn.train()
    -test_predict = dnn.predict(X_test)
    -
    -# accuracy score from scikit library
    -print("Accuracy score on test set: ", accuracy_score(Y_test, test_predict))
    -
    -# equivalent in numpy
    -def accuracy_score_numpy(Y_test, Y_pred):
    -    return np.sum(Y_test == Y_pred) / len(Y_test)
    -
    -#print("Accuracy score on test set: ", accuracy_score_numpy(Y_test, test_predict))
    -
    -
    -
    -
    -
    Accuracy score on test set:  0.9444444444444444
    -
    -
    -
    -
    -
    -
    -

    Adjust hyperparameters

    -

    We now perform a grid search to find the optimal hyperparameters for the network.
    -Note that we are only using 1 layer with 50 neurons, and human performance is estimated to be around \(98\%\) (\(2\%\) error rate).

    -
    -
    -
    eta_vals = np.logspace(-5, 1, 7)
    -lmbd_vals = np.logspace(-5, 1, 7)
    -# store the models for later use
    -DNN_numpy = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    -
    -# grid search
    -for i, eta in enumerate(eta_vals):
    -    for j, lmbd in enumerate(lmbd_vals):
    -        dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,
    -                            n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)
    -        dnn.train()
    -        
    -        DNN_numpy[i][j] = dnn
    -        
    -        test_predict = dnn.predict(X_test)
    -        
    -        print("Learning rate  = ", eta)
    -        print("Lambda = ", lmbd)
    -        print("Accuracy score on test set: ", accuracy_score(Y_test, test_predict))
    -        print()
    -
    -
    -
    -
    -
    Learning rate  =  1e-05
    -Lambda =  1e-05
    -Accuracy score on test set:  0.11666666666666667
    -
    -
    -
    Learning rate  =  1e-05
    -Lambda =  0.0001
    -Accuracy score on test set:  0.20833333333333334
    -
    -
    -
    Learning rate  =  1e-05
    -Lambda =  0.001
    -Accuracy score on test set:  0.12222222222222222
    -
    -
    -
    Learning rate  =  1e-05
    -Lambda =  0.01
    -Accuracy score on test set:  0.14722222222222223
    -
    -
    -
    Learning rate  =  1e-05
    -Lambda =  0.1
    -Accuracy score on test set:  0.17777777777777778
    -
    -
    -
    Learning rate  =  1e-05
    -Lambda =  1.0
    -Accuracy score on test set:  0.16111111111111112
    -
    -
    -
    Learning rate  =  1e-05
    -Lambda =  10.0
    -Accuracy score on test set:  0.20277777777777778
    -
    -
    -
    Learning rate  =  0.0001
    -Lambda =  1e-05
    -Accuracy score on test set:  0.5305555555555556
    -
    -
    -
    Learning rate  =  0.0001
    -Lambda =  0.0001
    -Accuracy score on test set:  0.5944444444444444
    -
    -
    -
    Learning rate  =  0.0001
    -Lambda =  0.001
    -Accuracy score on test set:  0.5888888888888889
    -
    -
    -
    Learning rate  =  0.0001
    -Lambda =  0.01
    -Accuracy score on test set:  0.6111111111111112
    -
    -
    -
    Learning rate  =  0.0001
    -Lambda =  0.1
    -Accuracy score on test set:  0.5222222222222223
    -
    -
    -
    Learning rate  =  0.0001
    -Lambda =  1.0
    -Accuracy score on test set:  0.5555555555555556
    -
    -
    -
    Learning rate  =  0.0001
    -Lambda =  10.0
    -Accuracy score on test set:  0.8055555555555556
    -
    -
    -
    Learning rate  =  0.001
    -Lambda =  1e-05
    -Accuracy score on test set:  0.85
    -
    -
    -
    Learning rate  =  0.001
    -Lambda =  0.0001
    -Accuracy score on test set:  0.85
    -
    -
    -
    Learning rate  =  0.001
    -Lambda =  0.001
    -Accuracy score on test set:  0.875
    -
    -
    -
    Learning rate  =  0.001
    -Lambda =  0.01
    -Accuracy score on test set:  0.8666666666666667
    -
    -
    -
    Learning rate  =  0.001
    -Lambda =  0.1
    -Accuracy score on test set:  0.8638888888888889
    -
    -
    -
    Learning rate  =  0.001
    -Lambda =  1.0
    -Accuracy score on test set:  0.9555555555555556
    -
    -
    -
    Learning rate  =  0.001
    -Lambda =  10.0
    -Accuracy score on test set:  0.925
    -
    -
    -
    Learning rate  =  0.01
    -Lambda =  1e-05
    -Accuracy score on test set:  0.9472222222222222
    -
    -
    -
    Learning rate  =  0.01
    -Lambda =  0.0001
    -Accuracy score on test set:  0.9277777777777778
    -
    -
    -
    Learning rate  =  0.01
    -Lambda =  0.001
    -Accuracy score on test set:  0.9472222222222222
    -
    -
    -
    Learning rate  =  0.01
    -Lambda =  0.01
    -Accuracy score on test set:  0.9305555555555556
    -
    -
    -
    Learning rate  =  0.01
    -Lambda =  0.1
    -Accuracy score on test set:  0.9555555555555556
    -
    -
    -
    Learning rate  =  0.01
    -Lambda =  1.0
    -Accuracy score on test set:  0.7694444444444445
    -
    -
    -
    Learning rate  =  0.01
    -Lambda =  10.0
    -Accuracy score on test set:  0.19166666666666668
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    Learning rate  =  0.1
    -Lambda =  1e-05
    -Accuracy score on test set:  0.10555555555555556
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    Learning rate  =  0.1
    -Lambda =  0.0001
    -Accuracy score on test set:  0.08611111111111111
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    Learning rate  =  0.1
    -Lambda =  0.001
    -Accuracy score on test set:  0.10555555555555556
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    Learning rate  =  0.1
    -Lambda =  0.01
    -Accuracy score on test set:  0.08888888888888889
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    Learning rate  =  0.1
    -Lambda =  0.1
    -Accuracy score on test set:  0.08611111111111111
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    Learning rate  =  0.1
    -Lambda =  1.0
    -Accuracy score on test set:  0.08888888888888889
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    Learning rate  =  0.1
    -Lambda =  10.0
    -Accuracy score on test set:  0.09166666666666666
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  1.0
    -Lambda =  1e-05
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  1.0
    -Lambda =  0.0001
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  1.0
    -Lambda =  0.001
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  1.0
    -Lambda =  0.01
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  1.0
    -Lambda =  0.1
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -
    -
    -
    Learning rate  =  1.0
    -Lambda =  1.0
    -Accuracy score on test set:  0.10555555555555556
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  1.0
    -Lambda =  10.0
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  10.0
    -Lambda =  1e-05
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  10.0
    -Lambda =  0.0001
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  10.0
    -Lambda =  0.001
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    Learning rate  =  10.0
    -Lambda =  0.01
    -Accuracy score on test set:  0.07777777777777778
    -
    -
    -
    /var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp
    -  return 1/(1 + np.exp(-x))
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp
    -  exp_term = np.exp(self.z_o)
    -/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide
    -  self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)
    -
    -
    -
    ---------------------------------------------------------------------------
    -KeyboardInterrupt                         Traceback (most recent call last)
    -Cell In[12], line 11
    -      8 for j, lmbd in enumerate(lmbd_vals):
    -      9     dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,
    -     10                         n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)
    ----> 11     dnn.train()
    -     13     DNN_numpy[i][j] = dnn
    -     15     test_predict = dnn.predict(X_test)
    -
    -Cell In[10], line 99, in NeuralNetwork.train(self)
    -     96 self.Y_data = self.Y_data_full[chosen_datapoints]
    -     98 self.feed_forward()
    ----> 99 self.backpropagation()
    -
    -Cell In[10], line 64, in NeuralNetwork.backpropagation(self)
    -     61 self.output_weights_gradient = np.matmul(self.a_h.T, error_output)
    -     62 self.output_bias_gradient = np.sum(error_output, axis=0)
    ----> 64 self.hidden_weights_gradient = np.matmul(self.X_data.T, error_hidden)
    -     65 self.hidden_bias_gradient = np.sum(error_hidden, axis=0)
    -     67 if self.lmbd > 0.0:
    -
    -KeyboardInterrupt: 
    -
    -
    -
    -
    -
    -
    -

    Visualization

    -
    -
    -
    # visual representation of grid search
    -# uses seaborn heatmap, you can also do this with matplotlib imshow
    -import seaborn as sns
    -
    -sns.set()
    -
    -train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    -test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    -
    -for i in range(len(eta_vals)):
    -    for j in range(len(lmbd_vals)):
    -        dnn = DNN_numpy[i][j]
    -        
    -        train_pred = dnn.predict(X_train) 
    -        test_pred = dnn.predict(X_test)
    -
    -        train_accuracy[i][j] = accuracy_score(Y_train, train_pred)
    -        test_accuracy[i][j] = accuracy_score(Y_test, test_pred)
    -
    -        
    -fig, ax = plt.subplots(figsize = (10, 10))
    -sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    -ax.set_title("Training Accuracy")
    -ax.set_ylabel("$\eta$")
    -ax.set_xlabel("$\lambda$")
    -plt.show()
    -
    -fig, ax = plt.subplots(figsize = (10, 10))
    -sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    -ax.set_title("Test Accuracy")
    -ax.set_ylabel("$\eta$")
    -ax.set_xlabel("$\lambda$")
    -plt.show()
    -
    -
    -
    -
    -
    -
    -

    scikit-learn implementation

    -

    scikit-learn focuses more -on traditional machine learning methods, such as regression, -clustering, decision trees, etc. As such, it has only two types of -neural networks: Multi Layer Perceptron outputting continuous values, -MPLRegressor, and Multi Layer Perceptron outputting labels, -MLPClassifier. We will see how simple it is to use these classes.

    -

    scikit-learn implements a few improvements from our neural network, -such as early stopping, a varying learning rate, different -optimization methods, etc. We would therefore expect a better -performance overall.

    -
    -
    -
    from sklearn.neural_network import MLPClassifier
    -# store models for later use
    -DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    -
    -for i, eta in enumerate(eta_vals):
    -    for j, lmbd in enumerate(lmbd_vals):
    -        dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic',
    -                            alpha=lmbd, learning_rate_init=eta, max_iter=epochs)
    -        dnn.fit(X_train, Y_train)
    -        
    -        DNN_scikit[i][j] = dnn
    -        
    -        print("Learning rate  = ", eta)
    -        print("Lambda = ", lmbd)
    -        print("Accuracy score on test set: ", dnn.score(X_test, Y_test))
    -        print()
    -
    -
    -
    -
    -
    -
    -

    Visualization

    -
    -
    -
    # optional
    -# visual representation of grid search
    -# uses seaborn heatmap, could probably do this in matplotlib
    -import seaborn as sns
    -
    -sns.set()
    -
    -train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    -test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    -
    -for i in range(len(eta_vals)):
    -    for j in range(len(lmbd_vals)):
    -        dnn = DNN_scikit[i][j]
    -        
    -        train_pred = dnn.predict(X_train) 
    -        test_pred = dnn.predict(X_test)
    -
    -        train_accuracy[i][j] = accuracy_score(Y_train, train_pred)
    -        test_accuracy[i][j] = accuracy_score(Y_test, test_pred)
    -
    -        
    -fig, ax = plt.subplots(figsize = (10, 10))
    -sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
    -ax.set_title("Training Accuracy")
    -ax.set_ylabel("$\eta$")
    -ax.set_xlabel("$\lambda$")
    -plt.show()
    -
    -fig, ax = plt.subplots(figsize = (10, 10))
    -sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    -ax.set_title("Test Accuracy")
    -ax.set_ylabel("$\eta$")
    -ax.set_xlabel("$\lambda$")
    -plt.show()
    -
    -
    -
    -
    -
    -
    -

    Testing our code for the XOR, OR and AND gates

    -

    Last week we discussed three different types of gates, the so-called -XOR, the OR and the AND gates. Their inputs and outputs can be -summarized using the following tables, first for the OR gate with -inputs \(x_1\) and \(x_2\) and outputs \(y\):

    - - - - - - - - - - -
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 1
    1 0 1
    1 1 1
    -
    -

    The AND and XOR Gates

    -

    The AND gate is defined as

    - - - - - - - - - - -
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 0
    1 0 0
    1 1 1
    -

    And finally we have the XOR gate

    - - - - - - - - - - -
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 1
    1 0 1
    1 1 0
    -
    -

    Representing the Data Sets

    -

    Our design matrix is defined by the input values \(x_1\) and \(x_2\). Since we have four possible outputs, our design matrix reads

    +
    +

    Hidden layers

    +

    For many problems you can start with just one or two hidden layers and +it will work just fine. For the MNIST data set you ca easily get a +high accuracy using just one hidden layer with a few hundred neurons. +You can reach for this data set above 98% accuracy using two hidden +layers with the same total amount of neurons, in roughly the same +amount of training time.

    +

    For more complex problems, you can gradually ramp up the number of +hidden layers, until you start overfitting the training set. Very +complex tasks, such as large image classification or speech +recognition, typically require networks with dozens of layers and they +need a huge amount of training data. However, you will rarely have to +train such networks from scratch: it is much more common to reuse +parts of a pretrained state-of-the-art network that performs a similar +task.

    +
    +
    +

    Vanishing gradients

    +

    The Back propagation algorithm we derived above works by going from +the output layer to the input layer, propagating the error gradient on +the way. Once the algorithm has computed the gradient of the cost +function with regards to each parameter in the network, it uses these +gradients to update each parameter with a Gradient Descent (GD) step.

    +

    Unfortunately for us, the gradients often get smaller and smaller as +the algorithm progresses down to the first hidden layers. As a result, +the GD update leaves the lower layer connection weights virtually +unchanged, and training never converges to a good solution. This is +known in the literature as the vanishing gradients problem.

    +
    +
    +

    Exploding gradients

    +

    In other cases, the opposite can happen, namely the the gradients can +grow bigger and bigger. The result is that many of the layers get +large updates of the weights the algorithm diverges. This is the +exploding gradients problem, which is mostly encountered in +recurrent neural networks. More generally, deep neural networks suffer +from unstable gradients, different layers may learn at widely +different speeds

    +
    +
    +

    Is the Logistic activation function (Sigmoid) our choice?

    +

    Although this unfortunate behavior has been empirically observed for +quite a while (it was one of the reasons why deep neural networks were +mostly abandoned for a long time), it is only around 2010 that +significant progress was made in understanding it.

    +

    A paper titled Understanding the Difficulty of Training Deep +Feedforward Neural Networks by Xavier Glorot and Yoshua Bengio found that +the problems with the popular logistic +sigmoid activation function and the weight initialization technique +that was most popular at the time, namely random initialization using +a normal distribution with a mean of 0 and a standard deviation of +1.

    +
    +
    +

    Logistic function as the root of problems

    +

    They showed that with this activation function and this +initialization scheme, the variance of the outputs of each layer is +much greater than the variance of its inputs. Going forward in the +network, the variance keeps increasing after each layer until the +activation function saturates at the top layers. This is actually made +worse by the fact that the logistic function has a mean of 0.5, not 0 +(the hyperbolic tangent function has a mean of 0 and behaves slightly +better than the logistic function in deep networks).

    +
    +
    +

    The derivative of the Logistic funtion

    +

    Looking at the logistic activation function, when inputs become large +(negative or positive), the function saturates at 0 or 1, with a +derivative extremely close to 0. Thus when backpropagation kicks in, +it has virtually no gradient to propagate back through the network, +and what little gradient exists keeps getting diluted as +backpropagation progresses down through the top layers, so there is +really nothing left for the lower layers.

    +

    In their paper, Glorot and Bengio propose a way to significantly +alleviate this problem. We need the signal to flow properly in both +directions: in the forward direction when making predictions, and in +the reverse direction when backpropagating gradients. We don’t want +the signal to die out, nor do we want it to explode and saturate. For +the signal to flow properly, the authors argue that we need the +variance of the outputs of each layer to be equal to the variance of +its inputs, and we also need the gradients to have equal variance +before and after flowing through a layer in the reverse direction.

    +
    +
    +

    Insights from the paper by Glorot and Bengio

    +

    One of the insights in the 2010 paper by Glorot and Bengio was that +the vanishing/exploding gradients problems were in part due to a poor +choice of activation function. Until then most people had assumed that +if Nature had chosen to use roughly sigmoid activation functions in +biological neurons, they must be an excellent choice. But it turns out +that other activation functions behave much better in deep neural +networks, in particular the ReLU activation function, mostly because +it does not saturate for positive values (and also because it is quite +fast to compute).

    +
    +
    +

    The RELU function family

    +

    The ReLU activation function suffers from a problem known as the dying +ReLUs: during training, some neurons effectively die, meaning they +stop outputting anything other than 0.

    +

    In some cases, you may find that half of your network’s neurons are +dead, especially if you used a large learning rate. During training, +if a neuron’s weights get updated such that the weighted sum of the +neuron’s inputs is negative, it will start outputting 0. When this +happen, the neuron is unlikely to come back to life since the gradient +of the ReLU function is 0 when its input is negative.

    +
    +
    +

    ELU function

    +

    To solve this problem, nowadays practitioners use a variant of the +ReLU function, such as the leaky ReLU discussed above or the so-called +exponential linear unit (ELU) function

    \[\begin{split} -\boldsymbol{X}=\begin{bmatrix} 0 & 0 \\ - 0 & 1 \\ - 1 & 0 \\ - 1 & 1 \end{bmatrix}, +ELU(z) = \left\{\begin{array}{cc} \alpha\left( \exp{(z)}-1\right) & z < 0,\\ z & z \ge 0.\end{array}\right. \end{split}\]
    -

    while the vector of outputs is \(\boldsymbol{y}^T=[0,1,1,0]\) for the XOR gate, \(\boldsymbol{y}^T=[0,0,0,1]\) for the AND gate and \(\boldsymbol{y}^T=[0,1,1,1]\) for the OR gate.

    -
    -

    Setting up the Neural Network

    -

    We define first our design matrix and the various output vectors for the different gates.

    -
    -
    -
    """
    -Simple code that tests XOR, OR and AND gates with linear regression
    -"""
    -
    -# import necessary packages
    -import numpy as np
    -import matplotlib.pyplot as plt
    -from sklearn import datasets
    -
    -def sigmoid(x):
    -    return 1/(1 + np.exp(-x))
    -
    -def feed_forward(X):
    -    # weighted sum of inputs to the hidden layer
    -    z_h = np.matmul(X, hidden_weights) + hidden_bias
    -    # activation in the hidden layer
    -    a_h = sigmoid(z_h)
    -    
    -    # weighted sum of inputs to the output layer
    -    z_o = np.matmul(a_h, output_weights) + output_bias
    -    # softmax output
    -    # axis 0 holds each input and axis 1 the probabilities of each category
    -    probabilities = sigmoid(z_o)
    -    return probabilities
    -
    -# we obtain a prediction by taking the class with the highest likelihood
    -def predict(X):
    -    probabilities = feed_forward(X)
    -    return np.argmax(probabilities, axis=1)
    -
    -# ensure the same random numbers appear every time
    -np.random.seed(0)
    -
    -# Design matrix
    -X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64)
    -
    -# The XOR gate
    -yXOR = np.array( [ 0, 1 ,1, 0])
    -# The OR gate
    -yOR = np.array( [ 0, 1 ,1, 1])
    -# The AND gate
    -yAND = np.array( [ 0, 0 ,0, 1])
    -
    -# Defining the neural network
    -n_inputs, n_features = X.shape
    -n_hidden_neurons = 2
    -n_categories = 2
    -n_features = 2
    -
    -# we make the weights normally distributed using numpy.random.randn
    -
    -# weights and bias in the hidden layer
    -hidden_weights = np.random.randn(n_features, n_hidden_neurons)
    -hidden_bias = np.zeros(n_hidden_neurons) + 0.01
    -
    -# weights and bias in the output layer
    -output_weights = np.random.randn(n_hidden_neurons, n_categories)
    -output_bias = np.zeros(n_categories) + 0.01
    -
    -probabilities = feed_forward(X)
    -print(probabilities)
    -
    -
    -predictions = predict(X)
    -print(predictions)
    -
    +
    +

    Which activation function should we use?

    +

    In general it seems that the ELU activation function is better than +the leaky ReLU function (and its variants), which is better than +ReLU. ReLU performs better than \(\tanh\) which in turn performs better +than the logistic function.

    +

    If runtime performance is an issue, then you may opt for the leaky +ReLU function over the ELU function If you don’t want to tweak yet +another hyperparameter, you may just use the default \(\alpha\) of +\(0.01\) for the leaky ReLU, and \(1\) for ELU. If you have spare time and +computing power, you can use cross-validation or bootstrap to evaluate +other activation functions.

    +
    +

    More on activation functions, output layers

    +

    In most cases you can use the ReLU activation function in the hidden +layers (or one of its variants).

    +

    It is a bit faster to compute than other activation functions, and the +gradient descent optimization does in general not get stuck.

    +

    For the output layer:

    +
      +
    • For classification the softmax activation function is generally a good choice for classification tasks (when the classes are mutually exclusive).

    • +
    • For regression tasks, you can simply use no activation function at all.

    • +
    +
    +

    Batch Normalization

    +

    Batch Normalization aims to address the vanishing/exploding gradients +problems, and more generally the problem that the distribution of each +layer’s inputs changes during training, as the parameters of the +previous layers change.

    +

    The technique consists of adding an operation in the model just before +the activation function of each layer, simply zero-centering and +normalizing the inputs, then scaling and shifting the result using two +new parameters per layer (one for scaling, the other for shifting). In +other words, this operation lets the model learn the optimal scale and +mean of the inputs for each layer. In order to zero-center and +normalize the inputs, the algorithm needs to estimate the inputs’ mean +and standard deviation. It does so by evaluating the mean and standard +deviation of the inputs over the current mini-batch, from this the +name batch normalization.

    -

    Not an impressive result, but this was our first forward pass with randomly assigned weights. Let us now add the full network with the back-propagation algorithm discussed above.

    +
    +

    Dropout

    +

    It is a fairly simple algorithm: at every training step, every neuron +(including the input neurons but excluding the output neurons) has a +probability \(p\) of being temporarily dropped out, meaning it will be +entirely ignored during this training step, but it may be active +during the next step.

    +

    The hyperparameter \(p\) is called the dropout rate, and it is typically +set to 50%. After training, the neurons are not dropped anymore. It +is viewed as one of the most popular regularization techniques.

    -
    -

    The Code using Scikit-Learn

    -
    -
    -
    # import necessary packages
    -import numpy as np
    -import matplotlib.pyplot as plt
    -from sklearn.neural_network import MLPClassifier
    -from sklearn.metrics import accuracy_score
    -import seaborn as sns
    -
    -# ensure the same random numbers appear every time
    -np.random.seed(0)
    -
    -# Design matrix
    -X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64)
    -
    -# The XOR gate
    -yXOR = np.array( [ 0, 1 ,1, 0])
    -# The OR gate
    -yOR = np.array( [ 0, 1 ,1, 1])
    -# The AND gate
    -yAND = np.array( [ 0, 0 ,0, 1])
    -
    -# Defining the neural network
    -n_inputs, n_features = X.shape
    -n_hidden_neurons = 2
    -n_categories = 2
    -n_features = 2
    -
    -eta_vals = np.logspace(-5, 1, 7)
    -lmbd_vals = np.logspace(-5, 1, 7)
    -# store models for later use
    -DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
    -epochs = 100
    -
    -for i, eta in enumerate(eta_vals):
    -    for j, lmbd in enumerate(lmbd_vals):
    -        dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic',
    -                            alpha=lmbd, learning_rate_init=eta, max_iter=epochs)
    -        dnn.fit(X, yXOR)
    -        DNN_scikit[i][j] = dnn
    -        print("Learning rate  = ", eta)
    -        print("Lambda = ", lmbd)
    -        print("Accuracy score on data set: ", dnn.score(X, yXOR))
    -        print()
    -
    -sns.set()
    -test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
    -for i in range(len(eta_vals)):
    -    for j in range(len(lmbd_vals)):
    -        dnn = DNN_scikit[i][j]
    -        test_pred = dnn.predict(X)
    -        test_accuracy[i][j] = accuracy_score(yXOR, test_pred)
    -
    -fig, ax = plt.subplots(figsize = (10, 10))
    -sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
    -ax.set_title("Test Accuracy")
    -ax.set_ylabel("$\eta$")
    -ax.set_xlabel("$\lambda$")
    -plt.show()
    -
    +
    +

    Gradient Clipping

    +

    A popular technique to lessen the exploding gradients problem is to +simply clip the gradients during backpropagation so that they never +exceed some threshold (this is mostly useful for recurrent neural +networks).

    +

    This technique is called Gradient Clipping.

    +

    In general however, Batch +Normalization is preferred.

    +
    +

    A top-down perspective on Neural networks

    +

    The first thing we would like to do is divide the data into two or +three parts. A training set, a validation or dev (development) set, +and a test set. The test set is the data on which we want to make +predictions. The dev set is a subset of the training data we use to +check how well we are doing out-of-sample, after training the model on +the training dataset. We use the validation error as a proxy for the +test error in order to make tweaks to our model. It is crucial that we +do not use any of the test data to train the algorithm. This is a +cardinal sin in ML. Then:

    +
      +
    1. Estimate optimal error rate

    2. +
    3. Minimize underfitting (bias) on training data set.

    4. +
    5. Make sure you are not overfitting.

    6. +
    +
    +

    More top-down perspectives

    +

    If the validation and test sets are drawn from the same distributions, +then a good performance on the validation set should lead to similarly +good performance on the test set.

    +

    However, sometimes +the training data and test data differ in subtle ways because, for +example, they are collected using slightly different methods, or +because it is cheaper to collect data in one way versus another. In +this case, there can be a mismatch between the training and test +data. This can lead to the neural network overfitting these small +differences between the test and training sets, and a poor performance +on the test set despite having a good performance on the validation +set. To rectify this, Andrew Ng suggests making two validation or dev +sets, one constructed from the training data and one constructed from +the test data. The difference between the performance of the algorithm +on these two validation sets quantifies the train-test mismatch. This +can serve as another important diagnostic when using DNNs for +supervised learning.

    +
    +

    Limitations of supervised learning with deep networks

    +

    Like all statistical methods, supervised learning using neural +networks has important limitations. This is especially important when +one seeks to apply these methods, especially to physics problems. Like +all tools, DNNs are not a universal solution. Often, the same or +better performance on a task can be achieved by using a few +hand-engineered features (or even a collection of random +features).

    +
    +
    +

    Limitations of NNs

    +

    Here we list some of the important limitations of supervised neural network based models.

    +
      +
    • Need labeled data. All supervised learning methods, DNNs for supervised learning require labeled data. Often, labeled data is harder to acquire than unlabeled data (e.g. one must pay for human experts to label images).

    • +
    • Supervised neural networks are extremely data intensive. DNNs are data hungry. They perform best when data is plentiful. This is doubly so for supervised methods where the data must also be labeled. The utility of DNNs is extremely limited if data is hard to acquire or the datasets are small (hundreds to a few thousand samples). In this case, the performance of other methods that utilize hand-engineered features can exceed that of DNNs.

    • +
    +
    +
    +

    Homogeneous data

    +
      +
    • Homogeneous data. Almost all DNNs deal with homogeneous data of one type. It is very hard to design architectures that mix and match data types (i.e. some continuous variables, some discrete variables, some time series). In applications beyond images, video, and language, this is often what is required. In contrast, ensemble models like random forests or gradient-boosted trees have no difficulty handling mixed data types.

    • +
    +
    +
    +

    More limitations

    +
      +
    • Many problems are not about prediction. In natural science we are often interested in learning something about the underlying distribution that generates the data. In this case, it is often difficult to cast these ideas in a supervised learning setting. While the problems are related, it is possible to make good predictions with a wrong model. The model might or might not be useful for understanding the underlying science.

    • +
    +

    Some of these remarks are particular to DNNs, others are shared by all supervised learning methods. This motivates the use of unsupervised methods which in part circumvent these problems.

    diff --git a/doc/LectureNotes/_build/jupyter_execute/week41.ipynb b/doc/LectureNotes/_build/jupyter_execute/week41.ipynb index 79903d776..06c053e27 100644 --- a/doc/LectureNotes/_build/jupyter_execute/week41.ipynb +++ b/doc/LectureNotes/_build/jupyter_execute/week41.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "4fed6eef", + "id": "4411828b", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "6a758aaa", + "id": "c234e82d", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "7436d60f", + "id": "e602572c", "metadata": { "editable": true }, @@ -37,7 +37,7 @@ }, { "cell_type": "markdown", - "id": "4a06fa29", + "id": "8c040a6e", "metadata": { "editable": true }, @@ -70,7 +70,7 @@ }, { "cell_type": "markdown", - "id": "c77f547a", + "id": "d7c3f47c", "metadata": { "editable": true }, @@ -87,7 +87,7 @@ }, { "cell_type": "markdown", - "id": "a1ba6a50", + "id": "ee26bc0e", "metadata": { "editable": true }, @@ -97,7 +97,7 @@ }, { "cell_type": "markdown", - "id": "9ef418c8", + "id": "604a7680", "metadata": { "editable": true }, @@ -115,7 +115,7 @@ }, { "cell_type": "markdown", - "id": "b58ec2e6", + "id": "df00fb0e", "metadata": { "editable": true }, @@ -139,7 +139,7 @@ }, { "cell_type": "markdown", - "id": "7d1b99e3", + "id": "b60314ed", "metadata": { "editable": true }, @@ -157,7 +157,7 @@ }, { "cell_type": "markdown", - "id": "367512fa", + "id": "9d2e1d85", "metadata": { "editable": true }, @@ -197,7 +197,7 @@ }, { "cell_type": "markdown", - "id": "3d79cfce", + "id": "c6af91e7", "metadata": { "editable": true }, @@ -226,7 +226,7 @@ }, { "cell_type": "markdown", - "id": "cbcafcdc", + "id": "1b2b8e1c", "metadata": { "editable": true }, @@ -247,7 +247,7 @@ }, { "cell_type": "markdown", - "id": "1ab04b48", + "id": "db4860d5", "metadata": { "editable": true }, @@ -276,7 +276,7 @@ }, { "cell_type": "markdown", - "id": "e4cf80b3", + "id": "4c21c5ca", "metadata": { "editable": true }, @@ -297,7 +297,7 @@ }, { "cell_type": "markdown", - "id": "f27655c6", + "id": "4314d49c", "metadata": { "editable": true }, @@ -318,7 +318,7 @@ }, { "cell_type": "markdown", - "id": "fa00e7d8", + "id": "94acdaed", "metadata": { "editable": true }, @@ -335,7 +335,7 @@ }, { "cell_type": "markdown", - "id": "7b05bd13", + "id": "5c342880", "metadata": { "editable": true }, @@ -356,7 +356,7 @@ }, { "cell_type": "markdown", - "id": "3600caa3", + "id": "f8e04154", "metadata": { "editable": true }, @@ -372,7 +372,7 @@ }, { "cell_type": "markdown", - "id": "99af52bb", + "id": "80e11a79", "metadata": { "editable": true }, @@ -389,7 +389,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "04ecfb00", + "id": "60cf9550", "metadata": { "collapsed": false, "editable": true @@ -449,7 +449,7 @@ }, { "cell_type": "markdown", - "id": "0026adeb", + "id": "72e221bf", "metadata": { "editable": true }, @@ -459,7 +459,7 @@ }, { "cell_type": "markdown", - "id": "e23f3056", + "id": "67d0709a", "metadata": { "editable": true }, @@ -470,7 +470,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "a30fe879", + "id": "4afcb37f", "metadata": { "collapsed": false, "editable": true @@ -554,7 +554,7 @@ }, { "cell_type": "markdown", - "id": "7773ba9d", + "id": "ac931e42", "metadata": { "editable": true }, @@ -564,7 +564,7 @@ }, { "cell_type": "markdown", - "id": "4a85ef26", + "id": "e5455ad8", "metadata": { "editable": true }, @@ -575,7 +575,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "2f8dd9ef", + "id": "cfbed3e7", "metadata": { "collapsed": false, "editable": true @@ -603,58 +603,3176 @@ }, { "cell_type": "markdown", - "id": "5b0fb3ff", + "id": "a619dfb2", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", + "## Mathematics of deep learning\n", "\n", - "The output $y$ is produced via the activation function $f$" + "**Two recent books online.**\n", + "\n", + "1. [The Modern Mathematics of Deep Learning, by Julius Berner, Philipp Grohs, Gitta Kutyniok, Philipp Petersen](https://arxiv.org/abs/2105.04026), published as [Mathematical Aspects of Deep Learning, pp. 1-111. Cambridge University Press, 2022](https://doi.org/10.1017/9781009025096.002)\n", + "\n", + "2. [Mathematical Introduction to Deep Learning: Methods, Implementations, and Theory, Arnulf Jentzen, Benno Kuckuck, Philippe von Wurstemberger](https://doi.org/10.48550/arXiv.2310.20360)" ] }, { "cell_type": "markdown", - "id": "f5c984c2", + "id": "2cc88c73", + "metadata": { + "editable": true + }, + "source": [ + "## Reminder on books with hands-on material and codes\n", + "* [Sebastian Rashcka et al, Machine learning with Sickit-Learn and PyTorch](https://sebastianraschka.com/blog/2022/ml-pytorch-book.html)" + ] + }, + { + "cell_type": "markdown", + "id": "233d2972", + "metadata": { + "editable": true + }, + "source": [ + "## Reading recommendations\n", + "\n", + "1. Rashkca et al., chapter 11, jupyter-notebook sent separately, from [GitHub](https://github.com/rasbt/machine-learning-book)\n", + "\n", + "2. Goodfellow et al, chapter 6 and 7 contain most of the neural network background." + ] + }, + { + "cell_type": "markdown", + "id": "27cc80b0", + "metadata": { + "editable": true + }, + "source": [ + "## Mathematics of deep learning and neural networks\n", + "\n", + "Neural networks, in its so-called feed-forward form, where each\n", + "iterations contains a feed-forward stage and a back-propgagation\n", + "stage, consist of series of affine matrix-matrix and matrix-vector\n", + "multiplications. The unknown parameters (the so-called biases and\n", + "weights which deternine the architecture of a neural network), are\n", + "uptaded iteratively using the so-called back-propagation algorithm.\n", + "This algorithm corresponds to the so-called reverse mode of \n", + "automatic differentation." + ] + }, + { + "cell_type": "markdown", + "id": "ea3a3c02", + "metadata": { + "editable": true + }, + "source": [ + "## Basics of an NN\n", + "\n", + "A neural network consists of a series of hidden layers, in addition to\n", + "the input and output layers. Each layer $l$ has a set of parameters\n", + "$\\boldsymbol{\\Theta}^{(l)}=(\\boldsymbol{W}^{(l)},\\boldsymbol{b}^{(l)})$ which are related to the\n", + "parameters in other layers through a series of affine transformations,\n", + "for a standard NN these are matrix-matrix and matrix-vector\n", + "multiplications. For all layers we will simply use a collective variable $\\boldsymbol{\\Theta}$.\n", + "\n", + "It consist of two basic steps:\n", + "1. a feed forward stage which takes a given input and produces a final output which is compared with the target values through our cost/loss function.\n", + "\n", + "2. a back-propagation state where the unknown parameters $\\boldsymbol{\\Theta}$ are updated through the optimization of the their gradients. The expressions for the gradients are obtained via the chain rule, starting from the derivative of the cost/function.\n", + "\n", + "These two steps make up one iteration. This iterative process is continued till we reach an eventual stopping criterion." + ] + }, + { + "cell_type": "markdown", + "id": "502d4ad7", + "metadata": { + "editable": true + }, + "source": [ + "## Overarching view of a neural network\n", + "\n", + "The architecture of a neural network defines our model. This model\n", + "aims at describing some function $f(\\boldsymbol{x}$ which represents\n", + "some final result (outputs or tagrget values) given a specific inpput\n", + "$\\boldsymbol{x}$. Note that here $\\boldsymbol{y}$ and $\\boldsymbol{x}$ are not limited to be\n", + "vectors.\n", + "\n", + "The architecture consists of\n", + "1. An input and an output layer where the input layer is defined by the inputs $\\boldsymbol{x}$. The output layer produces the model ouput $\\boldsymbol{\\tilde{y}}$ which is compared with the target value $\\boldsymbol{y}$\n", + "\n", + "2. A given number of hidden layers and neurons/nodes/units for each layer (this may vary)\n", + "\n", + "3. A given activation function $\\sigma(\\boldsymbol{z})$ with arguments $\\boldsymbol{z}$ to be defined below. The activation functions may differ from layer to layer.\n", + "\n", + "4. The last layer, normally called **output** layer has normally an activation function tailored to the specific problem\n", + "\n", + "5. Finally we define a so-called cost or loss function which is used to gauge the quality of our model." + ] + }, + { + "cell_type": "markdown", + "id": "9182519a", + "metadata": { + "editable": true + }, + "source": [ + "## The optimization problem\n", + "\n", + "The cost function is a function of the unknown parameters\n", + "$\\boldsymbol{\\Theta}$ where the latter is a container for all possible\n", + "parameters needed to define a neural network\n", + "\n", + "If we are dealing with a regression task a typical cost/loss function\n", + "is the mean squared error" + ] + }, + { + "cell_type": "markdown", + "id": "15b78cfd", "metadata": { "editable": true }, "source": [ "$$\n", - "y = f\\left(\\sum_{i=1}^n w_ix_i + b_i\\right) = f(z),\n", + "C(\\boldsymbol{\\Theta})=\\frac{1}{n}\\left\\{\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\theta}\\right)^T\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\theta}\\right)\\right\\}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "9743f4cb", + "id": "093b77f1", "metadata": { "editable": true }, "source": [ - "This function receives $x_i$ as inputs.\n", - "Here the activation $z=(\\sum_{i=1}^n w_ix_i+b_i)$. \n", - "In an FFNN of such neurons, the *inputs* $x_i$ are the *outputs* of\n", - "the neurons in the preceding layer. Furthermore, an MLP is\n", - "fully-connected, which means that each neuron receives a weighted sum\n", - "of the outputs of *all* neurons in the previous layer." + "This function represents one of many possible ways to define\n", + "the so-called cost function. Note that here we have assumed a linear dependence in terms of the paramters $\\boldsymbol{\\Theta}$. This is in general not the case." ] }, { "cell_type": "markdown", - "id": "e89c3e3f", + "id": "b6c8a224", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", + "## Parameters of neural networks\n", + "For neural networks the parameters\n", + "$\\boldsymbol{\\Theta}$ are given by the so-called weights and biases (to be\n", + "defined below).\n", "\n", - "First, for each node $i$ in the first hidden layer, we calculate a weighted sum $z_i^1$ of the input coordinates $x_j$," + "The weights are given by matrix elements $w_{ij}^{(l)}$ where the\n", + "superscript indicates the layer number. The biases are typically given\n", + "by vector elements representing each single node of a given layer,\n", + "that is $b_j^{(l)}$." ] }, { "cell_type": "markdown", - "id": "21c83fef", + "id": "f30d7e81", + "metadata": { + "editable": true + }, + "source": [ + "## Other ingredients of a neural network\n", + "\n", + "Having defined the architecture of a neural network, the optimization\n", + "of the cost function with respect to the parameters $\\boldsymbol{\\Theta}$,\n", + "involves the calculations of gradients and their optimization. The\n", + "gradients represent the derivatives of a multidimensional object and\n", + "are often approximated by various gradient methods, including\n", + "1. various quasi-Newton methods,\n", + "\n", + "2. plain gradient descent (GD) with a constant learning rate $\\eta$,\n", + "\n", + "3. GD with momentum and other approximations to the learning rates such as\n", + "\n", + " * Adapative gradient (ADAgrad)\n", + "\n", + " * Root mean-square propagation (RMSprop)\n", + "\n", + " * Adaptive gradient with momentum (ADAM) and many other\n", + "\n", + "4. Stochastic gradient descent and various families of learning rate approximations" + ] + }, + { + "cell_type": "markdown", + "id": "5089007e", + "metadata": { + "editable": true + }, + "source": [ + "## Other parameters\n", + "\n", + "In addition to the above, there are often additional hyperparamaters\n", + "which are included in the setup of a neural network. These will be\n", + "discussed below." + ] + }, + { + "cell_type": "markdown", + "id": "3f9eedcb", + "metadata": { + "editable": true + }, + "source": [ + "## Universal approximation theorem\n", + "\n", + "The universal approximation theorem plays a central role in deep\n", + "learning. [Cybenko (1989)](https://link.springer.com/article/10.1007/BF02551274) showed\n", + "the following:\n", + "\n", + "Let $\\sigma$ be any continuous sigmoidal function such that" + ] + }, + { + "cell_type": "markdown", + "id": "ac052134", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\sigma(z) = \\left\\{\\begin{array}{cc} 1 & z\\rightarrow \\infty\\\\ 0 & z \\rightarrow -\\infty \\end{array}\\right.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c0e639b1", + "metadata": { + "editable": true + }, + "source": [ + "Given a continuous and deterministic function $F(\\boldsymbol{x})$ on the unit\n", + "cube in $d$-dimensions $F\\in [0,1]^d$, $x\\in [0,1]^d$ and a parameter\n", + "$\\epsilon >0$, there is a one-layer (hidden) neural network\n", + "$f(\\boldsymbol{x};\\boldsymbol{\\Theta})$ with $\\boldsymbol{\\Theta}=(\\boldsymbol{W},\\boldsymbol{b})$ and $\\boldsymbol{W}\\in\n", + "\\mathbb{R}^{m\\times n}$ and $\\boldsymbol{b}\\in \\mathbb{R}^{n}$, for which" + ] + }, + { + "cell_type": "markdown", + "id": "6d2878d4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert < \\epsilon \\hspace{0.1cm} \\forall \\boldsymbol{x}\\in[0,1]^d.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dbb5133d", + "metadata": { + "editable": true + }, + "source": [ + "## Some parallels from real analysis\n", + "\n", + "For those of you familiar with for example the [Stone-Weierstrass\n", + "theorem](https://en.wikipedia.org/wiki/Stone%E2%80%93Weierstrass_theorem)\n", + "for polynomial approximations or the convergence criterion for Fourier\n", + "series, there are similarities in the derivation of the proof for\n", + "neural networks." + ] + }, + { + "cell_type": "markdown", + "id": "0da134a5", + "metadata": { + "editable": true + }, + "source": [ + "## The approximation theorem in words\n", + "\n", + "**Any continuous function $y=F(\\boldsymbol{x})$ supported on the unit cube in\n", + "$d$-dimensions can be approximated by a one-layer sigmoidal network to\n", + "arbitrary accuracy.**\n", + "\n", + "[Hornik (1991)](https://www.sciencedirect.com/science/article/abs/pii/089360809190009T) extended the theorem by letting any non-constant, bounded activation function to be included using that the expectation value" + ] + }, + { + "cell_type": "markdown", + "id": "5346e8a0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathbb{E}[\\vert F(\\boldsymbol{x})\\vert^2] =\\int_{\\boldsymbol{x}\\in D} \\vert F(\\boldsymbol{x})\\vert^2p(\\boldsymbol{x})d\\boldsymbol{x} < \\infty.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "36737d10", + "metadata": { + "editable": true + }, + "source": [ + "Then we have" + ] + }, + { + "cell_type": "markdown", + "id": "d81b95ba", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathbb{E}[\\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert^2] =\\int_{\\boldsymbol{x}\\in D} \\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert^2p(\\boldsymbol{x})d\\boldsymbol{x} < \\epsilon.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8432cac2", + "metadata": { + "editable": true + }, + "source": [ + "## More on the general approximation theorem\n", + "\n", + "None of the proofs give any insight into the relation between the\n", + "number of of hidden layers and nodes and the approximation error\n", + "$\\epsilon$, nor the magnitudes of $\\boldsymbol{W}$ and $\\boldsymbol{b}$.\n", + "\n", + "Neural networks (NNs) have what we may call a kind of universality no matter what function we want to compute.\n", + "\n", + "It does not mean that an NN can be used to exactly compute any function. Rather, we get an approximation that is as good as we want." + ] + }, + { + "cell_type": "markdown", + "id": "04d4d751", + "metadata": { + "editable": true + }, + "source": [ + "## Class of functions we can approximate\n", + "\n", + "The class of functions that can be approximated are the continuous ones.\n", + "If the function $F(\\boldsymbol{x})$ is discontinuous, it won't in general be possible to approximate it. However, an NN may still give an approximation even if we fail in some points." + ] + }, + { + "cell_type": "markdown", + "id": "df8f957e", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the equations for a neural network\n", + "\n", + "The questions we want to ask are how do changes in the biases and the\n", + "weights in our network change the cost function and how can we use the\n", + "final output to modify the weights and biases?\n", + "\n", + "To derive these equations let us start with a plain regression problem\n", + "and define our cost function as" + ] + }, + { + "cell_type": "markdown", + "id": "0fc51d93", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\cal C}(\\boldsymbol{\\Theta}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - \\tilde{y}_i\\right)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "fc372df4", + "metadata": { + "editable": true + }, + "source": [ + "where the $y_i$s are our $n$ targets (the values we want to\n", + "reproduce), while the outputs of the network after having propagated\n", + "all inputs $\\boldsymbol{x}$ are given by $\\boldsymbol{\\tilde{y}}_i$." + ] + }, + { + "cell_type": "markdown", + "id": "e1cbafd1", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a neural network with three hidden layers\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "aadba1e0", + "metadata": { + "editable": true + }, + "source": [ + "## Definitions\n", + "\n", + "With our definition of the targets $\\boldsymbol{y}$, the outputs of the\n", + "network $\\boldsymbol{\\tilde{y}}$ and the inputs $\\boldsymbol{x}$ we\n", + "define now the activation $z_j^l$ of node/neuron/unit $j$ of the\n", + "$l$-th layer as a function of the bias, the weights which add up from\n", + "the previous layer $l-1$ and the forward passes/outputs\n", + "$\\hat{a}^{l-1}$ from the previous layer as" + ] + }, + { + "cell_type": "markdown", + "id": "4f0a354f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_j^l = \\sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5b489754", + "metadata": { + "editable": true + }, + "source": [ + "where $b_k^l$ are the biases from layer $l$. Here $M_{l-1}$\n", + "represents the total number of nodes/neurons/units of layer $l-1$. The\n", + "figure in the whiteboard notes illustrates this equation. We can rewrite this in a more\n", + "compact form as the matrix-vector products we discussed earlier," + ] + }, + { + "cell_type": "markdown", + "id": "109a6626", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\hat{z}^l = \\left(\\hat{W}^l\\right)^T\\hat{a}^{l-1}+\\hat{b}^l.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d075c31b", + "metadata": { + "editable": true + }, + "source": [ + "## Inputs to the activation function\n", + "\n", + "With the activation values $\\boldsymbol{z}^l$ we can in turn define the\n", + "output of layer $l$ as $\\boldsymbol{a}^l = f(\\boldsymbol{z}^l)$ where $f$ is our\n", + "activation function. In the examples here we will use the sigmoid\n", + "function discussed in our logistic regression lectures. We will also use the same activation function $f$ for all layers\n", + "and their nodes. It means we have" + ] + }, + { + "cell_type": "markdown", + "id": "ea32a509", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a_j^l = \\sigma(z_j^l) = \\frac{1}{1+\\exp{-(z_j^l)}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8ac36725", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives and the chain rule\n", + "\n", + "From the definition of the activation $z_j^l$ we have" + ] + }, + { + "cell_type": "markdown", + "id": "f3600e09", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z_j^l}{\\partial w_{ij}^l} = a_i^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3e537038", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "34b99ae7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z_j^l}{\\partial a_i^{l-1}} = w_{ji}^l.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e4faa2f2", + "metadata": { + "editable": true + }, + "source": [ + "With our definition of the activation function we have that (note that this function depends only on $z_j^l$)" + ] + }, + { + "cell_type": "markdown", + "id": "b4243031", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a_j^l}{\\partial z_j^{l}} = a_j^l(1-a_j^l)=\\sigma(z_j^l)(1-\\sigma(z_j^l)).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b528c44c", + "metadata": { + "editable": true + }, + "source": [ + "## Derivative of the cost function\n", + "\n", + "With these definitions we can now compute the derivative of the cost function in terms of the weights.\n", + "\n", + "Let us specialize to the output layer $l=L$. Our cost function is" + ] + }, + { + "cell_type": "markdown", + "id": "602e81ab", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\cal C}(\\boldsymbol{\\Theta}^L) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - \\tilde{y}_i\\right)^2=\\frac{1}{2}\\sum_{i=1}^n\\left(a_i^L - y_i\\right)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4ac5e382", + "metadata": { + "editable": true + }, + "source": [ + "The derivative of this function with respect to the weights is" + ] + }, + { + "cell_type": "markdown", + "id": "02edfab2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}(\\boldsymbol{\\Theta}^L)}{\\partial w_{jk}^L} = \\left(a_j^L - y_j\\right)\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "02fffe9d", + "metadata": { + "editable": true + }, + "source": [ + "The last partial derivative can easily be computed and reads (by applying the chain rule)" + ] + }, + { + "cell_type": "markdown", + "id": "f4d679cc", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}} = \\frac{\\partial a_j^L}{\\partial z_{j}^{L}}\\frac{\\partial z_j^L}{\\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3638d432", + "metadata": { + "editable": true + }, + "source": [ + "## Simpler examples first, and automatic differentiation\n", + "\n", + "In order to understand the back propagation algorithm and its\n", + "derivation (an implementation of the chain rule), let us first digress\n", + "with some simple examples. These examples are also meant to motivate\n", + "the link with back propagation and [automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation)." + ] + }, + { + "cell_type": "markdown", + "id": "d3039347", + "metadata": { + "editable": true + }, + "source": [ + "## Reminder on the chain rule and gradients\n", + "\n", + "If we have a multivariate function $f(x,y)$ where $x=x(t)$ and $y=y(t)$ are functions of a variable $t$, we have that the gradient of $f$ with respect to $t$ (without the explicit unit vector components)" + ] + }, + { + "cell_type": "markdown", + "id": "f48bfb76", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dt} = \\begin{bmatrix}\\frac{\\partial f}{\\partial x} & \\frac{\\partial f}{\\partial y} \\end{bmatrix} \\begin{bmatrix}\\frac{\\partial x}{\\partial t} \\\\ \\frac{\\partial y}{\\partial t} \\end{bmatrix}=\\frac{\\partial f}{\\partial x} \\frac{\\partial x}{\\partial t} +\\frac{\\partial f}{\\partial y} \\frac{\\partial y}{\\partial t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "63176c54", + "metadata": { + "editable": true + }, + "source": [ + "## Multivariable functions\n", + "\n", + "If we have a multivariate function $f(x,y)$ where $x=x(t,s)$ and $y=y(t,s)$ are functions of the variables $t$ and $s$, we have that the partial derivatives" + ] + }, + { + "cell_type": "markdown", + "id": "f966f6f1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial s}=\\frac{\\partial f}{\\partial x}\\frac{\\partial x}{\\partial s}+\\frac{\\partial f}{\\partial y}\\frac{\\partial y}{\\partial s},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b0a5a64e", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "fedfd000", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial t}=\\frac{\\partial f}{\\partial x}\\frac{\\partial x}{\\partial t}+\\frac{\\partial f}{\\partial y}\\frac{\\partial y}{\\partial t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "49281876", + "metadata": { + "editable": true + }, + "source": [ + "the gradient of $f$ with respect to $t$ and $s$ (without the explicit unit vector components)" + ] + }, + { + "cell_type": "markdown", + "id": "78dc9b72", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{d(s,t)} = \\begin{bmatrix}\\frac{\\partial f}{\\partial x} & \\frac{\\partial f}{\\partial y} \\end{bmatrix} \\begin{bmatrix}\\frac{\\partial x}{\\partial s} &\\frac{\\partial x}{\\partial t} \\\\ \\frac{\\partial y}{\\partial s} & \\frac{\\partial y}{\\partial t} \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "bf854510", + "metadata": { + "editable": true + }, + "source": [ + "## Automatic differentiation through examples\n", + "\n", + "A great introduction to automatic differentiation is given by Baydin et al., see .\n", + "\n", + "Automatic differentiation is a represented by a repeated application\n", + "of the chain rule on well-known functions and allows for the\n", + "calculation of derivatives to numerical precision. It is not the same\n", + "as the calculation of symbolic derivatives via for example SymPy, nor\n", + "does it use approximative formulae based on Taylor-expansions of a\n", + "function around a given value. The latter are error prone due to\n", + "truncation errors and values of the step size $\\Delta$." + ] + }, + { + "cell_type": "markdown", + "id": "35771431", + "metadata": { + "editable": true + }, + "source": [ + "## Simple example\n", + "\n", + "Our first example is rather simple," + ] + }, + { + "cell_type": "markdown", + "id": "6570ba80", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) =\\exp{x^2},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c30b4d72", + "metadata": { + "editable": true + }, + "source": [ + "with derivative" + ] + }, + { + "cell_type": "markdown", + "id": "183d5f0b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) =2x\\exp{x^2}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b2363c0a", + "metadata": { + "editable": true + }, + "source": [ + "We can use SymPy to extract the pertinent lines of Python code through the following simple example" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "0b51ea21", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x = Symbol('x')\n", + "e = exp(x**2)\n", + "x = Symbol('x')\n", + "e = 2*x*exp(x**2)\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from sympy import *\n", + "x = symbols('x')\n", + "expr = exp(x*x)\n", + "simplify(expr)\n", + "derivative = diff(expr,x)\n", + "print(python(expr))\n", + "print(python(derivative))" + ] + }, + { + "cell_type": "markdown", + "id": "07e24343", + "metadata": { + "editable": true + }, + "source": [ + "## Smarter way of evaluating the above function\n", + "If we study this function, we note that we can reduce the number of operations by introducing an intermediate variable" + ] + }, + { + "cell_type": "markdown", + "id": "1337dd0f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a = x^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a7589947", + "metadata": { + "editable": true + }, + "source": [ + "leading to" + ] + }, + { + "cell_type": "markdown", + "id": "3586c972", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) = f(a(x)) = b= \\exp{a}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0ac52a19", + "metadata": { + "editable": true + }, + "source": [ + "We now assume that all operations can be counted in terms of equal\n", + "floating point operations. This means that in order to calculate\n", + "$f(x)$ we need first to square $x$ and then compute the exponential. We\n", + "have thus two floating point operations only." + ] + }, + { + "cell_type": "markdown", + "id": "18b67b7b", + "metadata": { + "editable": true + }, + "source": [ + "## Reducing the number of operations\n", + "\n", + "With the introduction of a precalculated quantity $a$ and thereby $f(x)$ we have that the derivative can be written as" + ] + }, + { + "cell_type": "markdown", + "id": "75f72d6b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) = 2xb,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ff72bef0", + "metadata": { + "editable": true + }, + "source": [ + "which reduces the number of operations from four in the orginal\n", + "expression to two. This means that if we need to compute $f(x)$ and\n", + "its derivative (a common task in optimizations), we have reduced the\n", + "number of operations from six to four in total.\n", + "\n", + "**Note** that the usage of a symbolic software like SymPy does not\n", + "include such simplifications and the calculations of the function and\n", + "the derivatives yield in general more floating point operations." + ] + }, + { + "cell_type": "markdown", + "id": "ef55737f", + "metadata": { + "editable": true + }, + "source": [ + "## Chain rule, forward and reverse modes\n", + "\n", + "In the above example we have introduced the variables $a$ and $b$, and our function is" + ] + }, + { + "cell_type": "markdown", + "id": "35ab7175", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) = f(a(x)) = b= \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "edc79b33", + "metadata": { + "editable": true + }, + "source": [ + "with $a=x^2$. We can decompose the derivative of $f$ with respect to $x$ as" + ] + }, + { + "cell_type": "markdown", + "id": "4dc12ed8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\frac{db}{da}\\frac{da}{dx}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "bc945b59", + "metadata": { + "editable": true + }, + "source": [ + "We note that since $b=f(x)$ that" + ] + }, + { + "cell_type": "markdown", + "id": "68eac5d0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{db}=1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6ea49d77", + "metadata": { + "editable": true + }, + "source": [ + "leading to" + ] + }, + { + "cell_type": "markdown", + "id": "4a65d6fd", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{db}{da}\\frac{da}{dx}=2x\\exp{x^2},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c66da8ef", + "metadata": { + "editable": true + }, + "source": [ + "as before." + ] + }, + { + "cell_type": "markdown", + "id": "b055e013", + "metadata": { + "editable": true + }, + "source": [ + "## Forward and reverse modes\n", + "\n", + "We have that" + ] + }, + { + "cell_type": "markdown", + "id": "006ef4f0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\frac{db}{da}\\frac{da}{dx},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "99fd1e13", + "metadata": { + "editable": true + }, + "source": [ + "which we can rewrite either as" + ] + }, + { + "cell_type": "markdown", + "id": "d711ba8b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\left[\\frac{df}{db}\\frac{db}{da}\\right]\\frac{da}{dx},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "394f38fd", + "metadata": { + "editable": true + }, + "source": [ + "or" + ] + }, + { + "cell_type": "markdown", + "id": "2f589cea", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\left[\\frac{db}{da}\\frac{da}{dx}\\right].\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "783c3588", + "metadata": { + "editable": true + }, + "source": [ + "The first expression is called reverse mode (or back propagation)\n", + "since we start by evaluating the derivatives at the end point and then\n", + "propagate backwards. This is the standard way of evaluating\n", + "derivatives (gradients) when optimizing the parameters of a neural\n", + "network. In the context of deep learning this is computationally\n", + "more efficient since the output of a neural network consists of either\n", + "one or some few other output variables.\n", + "\n", + "The second equation defines the so-called **forward mode**." + ] + }, + { + "cell_type": "markdown", + "id": "d1627f43", + "metadata": { + "editable": true + }, + "source": [ + "## More complicated function\n", + "\n", + "We increase our ambitions and introduce a slightly more complicated function" + ] + }, + { + "cell_type": "markdown", + "id": "53035043", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) =\\sqrt{x^2+exp{x^2}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f3293e4c", + "metadata": { + "editable": true + }, + "source": [ + "with derivative" + ] + }, + { + "cell_type": "markdown", + "id": "b6087529", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) =\\frac{x(1+\\exp{x^2})}{\\sqrt{x^2+exp{x^2}}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "9a91562c", + "metadata": { + "editable": true + }, + "source": [ + "The corresponding SymPy code reads" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "49153549", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x = Symbol('x')\n", + "e = sqrt(x**2 + exp(x**2))\n", + "x = Symbol('x')\n", + "e = (x*exp(x**2) + x)/sqrt(x**2 + exp(x**2))\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from sympy import *\n", + "x = symbols('x')\n", + "expr = sqrt(x*x+exp(x*x))\n", + "simplify(expr)\n", + "derivative = diff(expr,x)\n", + "print(python(expr))\n", + "print(python(derivative))" + ] + }, + { + "cell_type": "markdown", + "id": "3f8e08c9", + "metadata": { + "editable": true + }, + "source": [ + "## Counting the number of floating point operations\n", + "\n", + "A simple count of operations shows that we need five operations for\n", + "the function itself and ten for the derivative. Fifteen operations in total if we wish to proceed with the above codes.\n", + "\n", + "Can we reduce this to\n", + "say half the number of operations?" + ] + }, + { + "cell_type": "markdown", + "id": "9479dadf", + "metadata": { + "editable": true + }, + "source": [ + "## Defining intermediate operations\n", + "\n", + "We can indeed reduce the number of operation to half of those listed in the brute force approach above.\n", + "We define the following quantities" + ] + }, + { + "cell_type": "markdown", + "id": "9e5f867e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a = x^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "21ee2a8a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "e09cf187", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b = \\exp{x^2} = \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c999c36b", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "8fbf66c6", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "c= a+b,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dd11cc6a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "69e9e950", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "d=f(x)=\\sqrt{c}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "970b6167", + "metadata": { + "editable": true + }, + "source": [ + "## New expression for the derivative\n", + "\n", + "With these definitions we obtain the following partial derivatives" + ] + }, + { + "cell_type": "markdown", + "id": "5655fa59", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a}{\\partial x} = 2x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1c8a1f68", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "edaf4340", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial b}{\\partial a} = \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f39563ef", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "c3fad1fe", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial c}{\\partial a} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2f26318c", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "75e08a4f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial c}{\\partial b} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2729f6dc", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "7ccfc31a", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial d}{\\partial c} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1e39402f", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "a8313c23", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial d} = 1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "64f5a96d", + "metadata": { + "editable": true + }, + "source": [ + "## Final derivatives\n", + "Our final derivatives are thus" + ] + }, + { + "cell_type": "markdown", + "id": "e087f8b8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial c} = \\frac{\\partial f}{\\partial d} \\frac{\\partial d}{\\partial c} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ab9adb45", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial b} = \\frac{\\partial f}{\\partial c} \\frac{\\partial c}{\\partial b} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e7125560", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial a} = \\frac{\\partial f}{\\partial c} \\frac{\\partial c}{\\partial a}+\n", + "\\frac{\\partial f}{\\partial b} \\frac{\\partial b}{\\partial a} = \\frac{1+\\exp{a}}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6c4ad559", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "b42e32a4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x} = \\frac{\\partial f}{\\partial a} \\frac{\\partial a}{\\partial x} = \\frac{x(1+\\exp{a})}{\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "40de97ba", + "metadata": { + "editable": true + }, + "source": [ + "which is just" + ] + }, + { + "cell_type": "markdown", + "id": "22d0d252", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x} = \\frac{x(1+b)}{d},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "be68a064", + "metadata": { + "editable": true + }, + "source": [ + "and requires only three operations if we can reuse all intermediate variables." + ] + }, + { + "cell_type": "markdown", + "id": "ed92fb3c", + "metadata": { + "editable": true + }, + "source": [ + "## In general not this simple\n", + "\n", + "In general, see the generalization below, unless we can obtain simple\n", + "analytical expressions which we can simplify further, the final\n", + "implementation of automatic differentiation involves repeated\n", + "calculations (and thereby operations) of derivatives of elementary\n", + "functions." + ] + }, + { + "cell_type": "markdown", + "id": "b565b39a", + "metadata": { + "editable": true + }, + "source": [ + "## Automatic differentiation\n", + "\n", + "We can make this example more formal. Automatic differentiation is a\n", + "formalization of the previous example (see graph).\n", + "\n", + "We define $\\boldsymbol{x}\\in x_1,\\dots, x_l$ input variables to a given function $f(\\boldsymbol{x})$ and $x_{l+1},\\dots, x_L$ intermediate variables.\n", + "\n", + "In the above example we have only one input variable, $l=1$ and four intermediate variables, that is" + ] + }, + { + "cell_type": "markdown", + "id": "587ae22d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix} x_1=x & x_2 = x^2=a & x_3 =\\exp{a}= b & x_4=c=a+b & x_5 = \\sqrt{c}=d \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a54b74ca", + "metadata": { + "editable": true + }, + "source": [ + "Furthemore, for $i=l+1, \\dots, L$ (here $i=2,3,4,5$ and $f=x_L=d$), we\n", + "define the elementary functions $g_i(x_{Pa(x_i)})$ where $x_{Pa(x_i)}$ are the parent nodes of the variable $x_i$.\n", + "\n", + "In our case, we have for example for $x_3=g_3(x_{Pa(x_i)})=\\exp{a}$, that $g_3=\\exp{()}$ and $x_{Pa(x_3)}=a$." + ] + }, + { + "cell_type": "markdown", + "id": "bcfc076a", + "metadata": { + "editable": true + }, + "source": [ + "## Chain rule\n", + "\n", + "We can now compute the gradients by back-propagating the derivatives using the chain rule.\n", + "We have defined" + ] + }, + { + "cell_type": "markdown", + "id": "b4194098", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x_L} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "acc7030d", + "metadata": { + "editable": true + }, + "source": [ + "which allows us to find the derivatives of the various variables $x_i$ as" + ] + }, + { + "cell_type": "markdown", + "id": "02f92f41", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x_i} = \\sum_{x_j:x_i\\in Pa(x_j)}\\frac{\\partial f}{\\partial x_j} \\frac{\\partial x_j}{\\partial x_i}=\\sum_{x_j:x_i\\in Pa(x_j)}\\frac{\\partial f}{\\partial x_j} \\frac{\\partial g_j}{\\partial x_i}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5541dfd1", + "metadata": { + "editable": true + }, + "source": [ + "Whenever we have a function which can be expressed as a computation\n", + "graph and the various functions can be expressed in terms of\n", + "elementary functions that are differentiable, then automatic\n", + "differentiation works. The functions may not need to be elementary\n", + "functions, they could also be computer programs, although not all\n", + "programs can be automatically differentiated." + ] + }, + { + "cell_type": "markdown", + "id": "f73cf263", + "metadata": { + "editable": true + }, + "source": [ + "## First network example, simple percepetron with one input\n", + "\n", + "As yet another example we define now a simple perceptron model with\n", + "all quantities given by scalars. We consider only one input variable\n", + "$x$ and one target value $y$. We define an activation function\n", + "$\\sigma_1$ which takes as input" + ] + }, + { + "cell_type": "markdown", + "id": "4b8722cb", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_1 = w_1x+b_1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a604334f", + "metadata": { + "editable": true + }, + "source": [ + "where $w_1$ is the weight and $b_1$ is the bias. These are the\n", + "parameters we want to optimize. The output is $a_1=\\sigma(z_1)$ (see\n", + "graph from whiteboard notes). This output is then fed into the\n", + "**cost/loss** function, which we here for the sake of simplicity just\n", + "define as the squared error" + ] + }, + { + "cell_type": "markdown", + "id": "0017f42e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(x;w_1,b_1)=\\frac{1}{2}(a_1-y)^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8c47d806", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with no hidden layer\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "df503def", + "metadata": { + "editable": true + }, + "source": [ + "## Optimizing the parameters\n", + "\n", + "In setting up the feed forward and back propagation parts of the\n", + "algorithm, we need now the derivative of the various variables we want\n", + "to train.\n", + "\n", + "We need" + ] + }, + { + "cell_type": "markdown", + "id": "bdc97982", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1} \\hspace{0.1cm}\\mathrm{and}\\hspace{0.1cm}\\frac{\\partial C}{\\partial b_1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "42716985", + "metadata": { + "editable": true + }, + "source": [ + "Using the chain rule we find" + ] + }, + { + "cell_type": "markdown", + "id": "6df9aa60", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1}=\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial w_1}=(a_1-y)\\sigma_1'x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "30f9e077", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "77e9d494", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_1}=\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial b_1}=(a_1-y)\\sigma_1',\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1136c644", + "metadata": { + "editable": true + }, + "source": [ + "which we later will just define as" + ] + }, + { + "cell_type": "markdown", + "id": "b9f253ba", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}=\\delta_1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "14d41c44", + "metadata": { + "editable": true + }, + "source": [ + "## Adding a hidden layer\n", + "\n", + "We change our simple model to (see graph)\n", + "a network with just one hidden layer but with scalar variables only.\n", + "\n", + "Our output variable changes to $a_2$ and $a_1$ is now the output from the hidden node and $a_0=x$.\n", + "We have then" + ] + }, + { + "cell_type": "markdown", + "id": "d7c607f5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_1 = w_1a_0+b_1 \\hspace{0.1cm} \\wedge a_1 = \\sigma_1(z_1),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "609e28e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_2 = w_2a_1+b_2 \\hspace{0.1cm} \\wedge a_2 = \\sigma_2(z_2),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "494580d5", + "metadata": { + "editable": true + }, + "source": [ + "and the cost function" + ] + }, + { + "cell_type": "markdown", + "id": "03665a6f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(x;\\boldsymbol{\\Theta})=\\frac{1}{2}(a_2-y)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "911b5d2c", + "metadata": { + "editable": true + }, + "source": [ + "with $\\boldsymbol{\\Theta}=[w_1,w_2,b_1,b_2]$." + ] + }, + { + "cell_type": "markdown", + "id": "91e4f869", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with one hidden layer\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "43efdd27", + "metadata": { + "editable": true + }, + "source": [ + "## The derivatives\n", + "\n", + "The derivatives are now, using the chain rule again" + ] + }, + { + "cell_type": "markdown", + "id": "25d99018", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_2}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial w_2}=(a_2-y)\\sigma_2'a_1=\\delta_2a_1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6924f790", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_2}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial b_2}=(a_2-y)\\sigma_2'=\\delta_2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f457fe37", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial w_1}=(a_2-y)\\sigma_2'a_1\\sigma_1'a_0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "81e40678", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_1}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial b_1}=(a_2-y)\\sigma_2'\\sigma_1'=\\delta_1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c954b1f9", + "metadata": { + "editable": true + }, + "source": [ + "Can you generalize this to more than one hidden layer?" + ] + }, + { + "cell_type": "markdown", + "id": "87d10fa3", + "metadata": { + "editable": true + }, + "source": [ + "## Important observations\n", + "\n", + "From the above equations we see that the derivatives of the activation\n", + "functions play a central role. If they vanish, the training may\n", + "stop. This is called the vanishing gradient problem, see discussions below. If they become\n", + "large, the parameters $w_i$ and $b_i$ may simply go to infinity. This\n", + "is referenced as the exploding gradient problem." + ] + }, + { + "cell_type": "markdown", + "id": "c20ef010", + "metadata": { + "editable": true + }, + "source": [ + "## The training\n", + "\n", + "The training of the parameters is done through various gradient descent approximations with" + ] + }, + { + "cell_type": "markdown", + "id": "e9de19ea", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}\\leftarrow w_{i}- \\eta \\delta_i a_{i-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3487e8b8", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "7baa62bc", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_i \\leftarrow b_i-\\eta \\delta_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a3c1590a", + "metadata": { + "editable": true + }, + "source": [ + "with $\\eta$ is the learning rate.\n", + "\n", + "One iteration consists of one feed forward step and one back-propagation step. Each back-propagation step does one update of the parameters $\\boldsymbol{\\Theta}$.\n", + "\n", + "For the first hidden layer $a_{i-1}=a_0=x$ for this simple model." + ] + }, + { + "cell_type": "markdown", + "id": "3c3dc625", + "metadata": { + "editable": true + }, + "source": [ + "## Code example\n", + "\n", + "The code here implements the above model with one hidden layer and\n", + "scalar variables for the same function we studied in the previous\n", + "example. The code is however set up so that we can add multiple\n", + "inputs $x$ and target values $y$. Note also that we have the\n", + "possibility of defining a feature matrix $\\boldsymbol{X}$ with more than just\n", + "one column for the input values. This will turn useful in our next example. We have also defined matrices and vectors for all of our operations although it is not necessary here." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "e9fb1fc9", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[36.89563074]\n", + "[23.62323175]\n", + "[15.1251681]\n", + "[9.68402334]\n", + "[6.20020163]\n", + "[3.96963458]\n", + "[2.54150298]\n", + "[1.62714703]\n", + "[1.0417409]\n", + "[0.66694492]\n", + "[0.42699034]\n", + "[0.27336592]\n", + "[0.17501258]\n", + "[0.11204514]\n", + "[0.07173249]\n", + "[0.04592382]\n", + "[0.02940083]\n", + "[0.01882264]\n", + "[0.01205039]\n", + "[0.00771475]\n", + "[0.00493903]\n", + "[0.003162]\n", + "[0.00202433]\n", + "[0.00129599]\n", + "[0.0008297]\n", + "[0.00053118]\n", + "[0.00034006]\n", + "[0.00021771]\n", + "[0.00013938]\n", + "[8.92313548e-05]\n", + "[5.71263851e-05]\n", + "[3.6572612e-05]\n", + "[2.34139775e-05]\n", + "[1.49897504e-05]\n", + "[9.5965161e-06]\n", + "[6.14373934e-06]\n", + "[3.93325371e-06]\n", + "[2.51808934e-06]\n", + "[1.61209378e-06]\n", + "[1.03207075e-06]\n", + "[6.60737006e-07]\n", + "[4.23007231e-07]\n", + "[2.70811405e-07]\n", + "[1.73374853e-07]\n", + "[1.10995472e-07]\n", + "[7.10598715e-08]\n", + "[4.54928947e-08]\n", + "[2.91247848e-08]\n", + "[1.86458368e-08]\n", + "[1.19371605e-08]\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "# We use the Sigmoid function as activation function\n", + "def sigmoid(z):\n", + " return 1.0/(1.0+np.exp(-z))\n", + "\n", + "def forwardpropagation(x):\n", + " # weighted sum of inputs to the hidden layer\n", + " z_1 = np.matmul(x, w_1) + b_1\n", + " # activation in the hidden layer\n", + " a_1 = sigmoid(z_1)\n", + " # weighted sum of inputs to the output layer\n", + " z_2 = np.matmul(a_1, w_2) + b_2\n", + " a_2 = z_2\n", + " return a_1, a_2\n", + "\n", + "def backpropagation(x, y):\n", + " a_1, a_2 = forwardpropagation(x)\n", + " # parameter delta for the output layer, note that a_2=z_2 and its derivative wrt z_2 is just 1\n", + " delta_2 = a_2 - y\n", + " print(0.5*((a_2-y)**2))\n", + " # delta for the hidden layer\n", + " delta_1 = np.matmul(delta_2, w_2.T) * a_1 * (1 - a_1)\n", + " # gradients for the output layer\n", + " output_weights_gradient = np.matmul(a_1.T, delta_2)\n", + " output_bias_gradient = np.sum(delta_2, axis=0)\n", + " # gradient for the hidden layer\n", + " hidden_weights_gradient = np.matmul(x.T, delta_1)\n", + " hidden_bias_gradient = np.sum(delta_1, axis=0)\n", + " return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient\n", + "\n", + "\n", + "# ensure the same random numbers appear every time\n", + "np.random.seed(0)\n", + "# Input variable\n", + "x = np.array([4.0],dtype=np.float64)\n", + "# Target values\n", + "y = 2*x+1.0 \n", + "\n", + "# Defining the neural network, only scalars here\n", + "n_inputs = x.shape\n", + "n_features = 1\n", + "n_hidden_neurons = 1\n", + "n_outputs = 1\n", + "\n", + "# Initialize the network\n", + "# weights and bias in the hidden layer\n", + "w_1 = np.random.randn(n_features, n_hidden_neurons)\n", + "b_1 = np.zeros(n_hidden_neurons) + 0.01\n", + "\n", + "# weights and bias in the output layer\n", + "w_2 = np.random.randn(n_hidden_neurons, n_outputs)\n", + "b_2 = np.zeros(n_outputs) + 0.01\n", + "\n", + "eta = 0.1\n", + "for i in range(50):\n", + " # calculate gradients\n", + " derivW2, derivB2, derivW1, derivB1 = backpropagation(x, y)\n", + " # update weights and biases\n", + " w_2 -= eta * derivW2\n", + " b_2 -= eta * derivB2\n", + " w_1 -= eta * derivW1\n", + " b_1 -= eta * derivB1" + ] + }, + { + "cell_type": "markdown", + "id": "351debb8", + "metadata": { + "editable": true + }, + "source": [ + "We see that after some few iterations (the results do depend on the learning rate however), we get an error which is rather small." + ] + }, + { + "cell_type": "markdown", + "id": "c6579e36", + "metadata": { + "editable": true + }, + "source": [ + "## Exercise 1: Including more data\n", + "\n", + "Try to increase the amount of input and\n", + "target/output data. Try also to perform calculations for more values\n", + "of the learning rates. Feel free to add either hyperparameters with an\n", + "$l_1$ norm or an $l_2$ norm and discuss your results.\n", + "Discuss your results as functions of the amount of training data and various learning rates.\n", + "\n", + "**Challenge:** Try to change the activation functions and replace the hard-coded analytical expressions with automatic derivation via either **autograd** or **JAX**." + ] + }, + { + "cell_type": "markdown", + "id": "2c80a4b1", + "metadata": { + "editable": true + }, + "source": [ + "## Simple neural network and the back propagation equations\n", + "\n", + "Let us now try to increase our level of ambition and attempt at setting \n", + "up the equations for a neural network with two input nodes, one hidden\n", + "layer with two hidden nodes and one output layer with one output node/neuron only (see graph)..\n", + "\n", + "We need to define the following parameters and variables with the input layer (layer $(0)$) \n", + "where we label the nodes $x_0$ and $x_1$" + ] + }, + { + "cell_type": "markdown", + "id": "c834edc8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "x_0 = a_0^{(0)} \\wedge x_1 = a_1^{(0)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "79bd199b", + "metadata": { + "editable": true + }, + "source": [ + "The hidden layer (layer $(1)$) has nodes which yield the outputs $a_0^{(1)}$ and $a_1^{(1)}$) with weight $\\boldsymbol{w}$ and bias $\\boldsymbol{b}$ parameters" + ] + }, + { + "cell_type": "markdown", + "id": "0a856855", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{ij}^{(1)}=\\left\\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)}\\right\\} \\wedge b^{(1)}=\\left\\{b_0^{(1)},b_1^{(1)}\\right\\}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "54280198", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with two input nodes, one hidden layer and one output node\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "b2cee09c", + "metadata": { + "editable": true + }, + "source": [ + "## The ouput layer\n", + "\n", + "Finally, we have the ouput layer given by layer label $(2)$ with output $a^{(2)}$ and weights and biases to be determined given by the variables" + ] + }, + { + "cell_type": "markdown", + "id": "710131c9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}^{(2)}=\\left\\{w_{0}^{(2)},w_{1}^{(2)}\\right\\} \\wedge b^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "cd8b54e5", + "metadata": { + "editable": true + }, + "source": [ + "Our output is $\\tilde{y}=a^{(2)}$ and we define a generic cost function $C(a^{(2)},y;\\boldsymbol{\\Theta})$ where $y$ is the target value (a scalar here).\n", + "The parameters we need to optimize are given by" + ] + }, + { + "cell_type": "markdown", + "id": "8998ad11", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{\\Theta}=\\left\\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)},w_{0}^{(2)},w_{1}^{(2)},b_0^{(1)},b_1^{(1)},b^{(2)}\\right\\}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7d430cf7", + "metadata": { + "editable": true + }, + "source": [ + "## Compact expressions\n", + "\n", + "We can define the inputs to the activation functions for the various layers in terms of various matrix-vector multiplications and vector additions.\n", + "The inputs to the first hidden layer are" + ] + }, + { + "cell_type": "markdown", + "id": "9b5a6c95", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix}z_0^{(1)} \\\\ z_1^{(1)} \\end{bmatrix}=\\begin{bmatrix}w_{00}^{(1)} & w_{01}^{(1)}\\\\ w_{10}^{(1)} &w_{11}^{(1)} \\end{bmatrix}\\begin{bmatrix}a_0^{(0)} \\\\ a_1^{(0)} \\end{bmatrix}+\\begin{bmatrix}b_0^{(1)} \\\\ b_1^{(1)} \\end{bmatrix},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "31d044d8", + "metadata": { + "editable": true + }, + "source": [ + "with outputs" + ] + }, + { + "cell_type": "markdown", + "id": "f5125cb7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix}a_0^{(1)} \\\\ a_1^{(1)} \\end{bmatrix}=\\begin{bmatrix}\\sigma^{(1)}(z_0^{(1)}) \\\\ \\sigma^{(1)}(z_1^{(1)}) \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0eed1fab", + "metadata": { + "editable": true + }, + "source": [ + "## Output layer\n", + "\n", + "For the final output layer we have the inputs to the final activation function" + ] + }, + { + "cell_type": "markdown", + "id": "9a9811d2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z^{(2)} = w_{0}^{(2)}a_0^{(1)} +w_{1}^{(2)}a_1^{(1)}+b^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "98bf5097", + "metadata": { + "editable": true + }, + "source": [ + "resulting in the output" + ] + }, + { + "cell_type": "markdown", + "id": "e749c895", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a^{(2)}=\\sigma^{(2)}(z^{(2)}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ea6692ce", + "metadata": { + "editable": true + }, + "source": [ + "## Explicit derivatives\n", + "\n", + "In total we have nine parameters which we need to train. Using the\n", + "chain rule (or just the back-propagation algorithm) we can find all\n", + "derivatives. Since we will use automatic differentiation in reverse\n", + "mode, we start with the derivatives of the cost function with respect\n", + "to the parameters of the output layer, namely" + ] + }, + { + "cell_type": "markdown", + "id": "bf74eae4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{i}^{(2)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\\frac{\\partial z^{(2)}}{\\partial w_{i}^{(2)}}=\\delta^{(2)}a_i^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d590dc50", + "metadata": { + "editable": true + }, + "source": [ + "with" + ] + }, + { + "cell_type": "markdown", + "id": "eb0b8e3c", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta^{(2)}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7928cd11", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "8fc852e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b^{(2)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\\frac{\\partial z^{(2)}}{\\partial b^{(2)}}=\\delta^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "634713ba", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives of the hidden layer\n", + "\n", + "Using the chain rule we have the following expressions for say one of the weight parameters (it is easy to generalize to the other weight parameters)" + ] + }, + { + "cell_type": "markdown", + "id": "0f6ca3e6", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{00}^{(1)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\n", + "\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}}= \\delta^{(2)}\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3b54e63f", + "metadata": { + "editable": true + }, + "source": [ + "which, noting that" + ] + }, + { + "cell_type": "markdown", + "id": "a69c61ff", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z^{(2)} =w_0^{(2)}a_0^{(1)}+w_1^{(2)}a_1^{(1)}+b^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a73b8fe2", + "metadata": { + "editable": true + }, + "source": [ + "allows us to rewrite" + ] + }, + { + "cell_type": "markdown", + "id": "093c845d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}}=w_0^{(2)}\\frac{\\partial a_0^{(1)}}{\\partial z_0^{(1)}}a_0^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dcd12209", + "metadata": { + "editable": true + }, + "source": [ + "## Final expression\n", + "Defining" + ] + }, + { + "cell_type": "markdown", + "id": "5d5e8985", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_0^{(1)}=w_0^{(2)}\\frac{\\partial a_0^{(1)}}{\\partial z_0^{(1)}}\\delta^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "506f74bf", + "metadata": { + "editable": true + }, + "source": [ + "we have" + ] + }, + { + "cell_type": "markdown", + "id": "b474afaa", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{00}^{(1)}}=\\delta_0^{(1)}a_0^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7d14d370", + "metadata": { + "editable": true + }, + "source": [ + "Similarly, we obtain" + ] + }, + { + "cell_type": "markdown", + "id": "ca679e05", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{01}^{(1)}}=\\delta_0^{(1)}a_1^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "251a03fd", + "metadata": { + "editable": true + }, + "source": [ + "## Completing the list\n", + "\n", + "Similarly, we find" + ] + }, + { + "cell_type": "markdown", + "id": "b7575ec0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{10}^{(1)}}=\\delta_1^{(1)}a_0^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "02453de3", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "4e989854", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{11}^{(1)}}=\\delta_1^{(1)}a_1^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "05a25565", + "metadata": { + "editable": true + }, + "source": [ + "where we have defined" + ] + }, + { + "cell_type": "markdown", + "id": "d9e571d7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_1^{(1)}=w_1^{(2)}\\frac{\\partial a_1^{(1)}}{\\partial z_1^{(1)}}\\delta^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f96632e9", + "metadata": { + "editable": true + }, + "source": [ + "## Final expressions for the biases of the hidden layer\n", + "\n", + "For the sake of completeness, we list the derivatives of the biases, which are" + ] + }, + { + "cell_type": "markdown", + "id": "e15002e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_{0}^{(1)}}=\\delta_0^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8c683755", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "da56a290", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_{1}^{(1)}}=\\delta_1^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e42a9d6c", + "metadata": { + "editable": true + }, + "source": [ + "As we will see below, these expressions can be generalized in a more compact form." + ] + }, + { + "cell_type": "markdown", + "id": "21dd6563", + "metadata": { + "editable": true + }, + "source": [ + "## Gradient expressions\n", + "\n", + "For this specific model, with just one output node and two hidden\n", + "nodes, the gradient descent equations take the following form for output layer" + ] + }, + { + "cell_type": "markdown", + "id": "67fc0189", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}^{(2)}\\leftarrow w_{i}^{(2)}- \\eta \\delta^{(2)} a_{i}^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "daddd95e", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "5bf8af85", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b^{(2)} \\leftarrow b^{(2)}-\\eta \\delta^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5a72ea0a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "edd32da2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{ij}^{(1)}\\leftarrow w_{ij}^{(1)}- \\eta \\delta_{i}^{(1)} a_{j}^{(0)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "75c31af5", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "c037d92b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_{i}^{(1)} \\leftarrow b_{i}^{(1)}-\\eta \\delta_{i}^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5937fd51", + "metadata": { + "editable": true + }, + "source": [ + "where $\\eta$ is the learning rate." + ] + }, + { + "cell_type": "markdown", + "id": "3f0f6cd3", + "metadata": { + "editable": true + }, + "source": [ + "## Exercise 2: Extended program\n", + "\n", + "We extend our simple code to a function which depends on two variable $x_0$ and $x_1$, that is" + ] + }, + { + "cell_type": "markdown", + "id": "057366c1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "y=f(x_0,x_1)=x_0^2+3x_0x_1+x_1^2+5.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "293fa11b", + "metadata": { + "editable": true + }, + "source": [ + "We feed our network with $n=100$ entries $x_0$ and $x_1$. We have thus two features represented by these variable and an input matrix/design matrix $\\boldsymbol{X}\\in \\mathbf{R}^{n\\times 2}$" + ] + }, + { + "cell_type": "markdown", + "id": "d652c45d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{X}=\\begin{bmatrix} x_{00} & x_{01} \\\\ x_{00} & x_{01} \\\\ x_{10} & x_{11} \\\\ x_{20} & x_{21} \\\\ \\dots & \\dots \\\\ \\dots & \\dots \\\\ x_{n-20} & x_{n-21} \\\\ x_{n-10} & x_{n-11} \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8ca9d167", + "metadata": { + "editable": true + }, + "source": [ + "Write a code, based on the previous code examples, which takes as input these data and fit the above function.\n", + "You can extend your code to include automatic differentiation.\n", + "\n", + "With these examples, we are now ready to embark upon the writing of more a general code for neural networks." + ] + }, + { + "cell_type": "markdown", + "id": "8fed1e03", + "metadata": { + "editable": true + }, + "source": [ + "## Getting serious, the back propagation equations for a neural network\n", + "\n", + "Now it is time to move away from one node in each layer only. Our inputs are also represented either by several inputs.\n", + "\n", + "We have thus" + ] + }, + { + "cell_type": "markdown", + "id": "6394a2a5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}((\\boldsymbol{\\Theta}^L)}{\\partial w_{jk}^L} = \\left(a_j^L - y_j\\right)a_j^L(1-a_j^L)a_k^{L-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c2e22893", + "metadata": { + "editable": true + }, + "source": [ + "Defining" + ] + }, + { + "cell_type": "markdown", + "id": "5e054d69", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L = a_j^L(1-a_j^L)\\left(a_j^L - y_j\\right) = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dd5f9a8d", + "metadata": { + "editable": true + }, + "source": [ + "and using the Hadamard product of two vectors we can write this as" + ] + }, + { + "cell_type": "markdown", + "id": "ff6e8f86", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{\\delta}^L = \\sigma'(\\hat{z}^L)\\circ\\frac{\\partial {\\cal C}}{\\partial (\\boldsymbol{a}^L)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6e186667", + "metadata": { + "editable": true + }, + "source": [ + "## Analyzing the last results\n", + "\n", + "This is an important expression. The second term on the right handside\n", + "measures how fast the cost function is changing as a function of the $j$th\n", + "output activation. If, for example, the cost function doesn't depend\n", + "much on a particular output node $j$, then $\\delta_j^L$ will be small,\n", + "which is what we would expect. The first term on the right, measures\n", + "how fast the activation function $f$ is changing at a given activation\n", + "value $z_j^L$." + ] + }, + { + "cell_type": "markdown", + "id": "0e0a514f", + "metadata": { + "editable": true + }, + "source": [ + "## More considerations\n", + "\n", + "Notice that everything in the above equations is easily computed. In\n", + "particular, we compute $z_j^L$ while computing the behaviour of the\n", + "network, and it is only a small additional overhead to compute\n", + "$\\sigma'(z^L_j)$. The exact form of the derivative with respect to the\n", + "output depends on the form of the cost function.\n", + "However, provided the cost function is known there should be little\n", + "trouble in calculating" + ] + }, + { + "cell_type": "markdown", + "id": "e8259ee9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3c817881", + "metadata": { + "editable": true + }, + "source": [ + "With the definition of $\\delta_j^L$ we have a more compact definition of the derivative of the cost function in terms of the weights, namely" + ] + }, + { + "cell_type": "markdown", + "id": "0f3e5b1c", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4e14ef60", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives in terms of $z_j^L$\n", + "\n", + "It is also easy to see that our previous equation can be written as" + ] + }, + { + "cell_type": "markdown", + "id": "886fbebf", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L =\\frac{\\partial {\\cal C}}{\\partial z_j^L}= \\frac{\\partial {\\cal C}}{\\partial a_j^L}\\frac{\\partial a_j^L}{\\partial z_j^L},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "16d62157", + "metadata": { + "editable": true + }, + "source": [ + "which can also be interpreted as the partial derivative of the cost function with respect to the biases $b_j^L$, namely" + ] + }, + { + "cell_type": "markdown", + "id": "4a81d6b5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L}\\frac{\\partial b_j^L}{\\partial z_j^L}=\\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0bcee50c", + "metadata": { + "editable": true + }, + "source": [ + "That is, the error $\\delta_j^L$ is exactly equal to the rate of change of the cost function as a function of the bias." + ] + }, + { + "cell_type": "markdown", + "id": "0ed7f7a0", + "metadata": { + "editable": true + }, + "source": [ + "## Bringing it together\n", + "\n", + "We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are" + ] + }, + { + "cell_type": "markdown", + "id": "a502b908", "metadata": { "editable": true }, @@ -663,7 +3781,8 @@ "
    \n", "\n", "$$\n", - "\\begin{equation} z_i^1 = \\sum_{j=1}^{M} w_{ij}^1 x_j + b_i^1\n", + "\\begin{equation}\n", + "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1},\n", "\\label{_auto1} \\tag{2}\n", "\\end{equation}\n", "$$" @@ -671,95 +3790,17 @@ }, { "cell_type": "markdown", - "id": "3267338f", + "id": "fa4de05b", "metadata": { "editable": true }, "source": [ - "Here $b_i$ is the so-called bias which is normally needed in\n", - "case of zero activation weights or inputs. How to fix the biases and\n", - "the weights will be discussed below. The value of $z_i^1$ is the\n", - "argument to the activation function $f_i$ of each node $i$, The\n", - "variable $M$ stands for all possible inputs to a given node $i$ in the\n", - "first layer. We define the output $y_i^1$ of all neurons in layer 1 as" + "and" ] }, { "cell_type": "markdown", - "id": "04a1a613", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - " y_i^1 = f(z_i^1) = f\\left(\\sum_{j=1}^M w_{ij}^1 x_j + b_i^1\\right)\n", - "\\label{outputLayer1} \\tag{3}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bc8b70e2", - "metadata": { - "editable": true - }, - "source": [ - "where we assume that all nodes in the same layer have identical\n", - "activation functions, hence the notation $f$. In general, we could assume in the more general case that different layers have different activation functions.\n", - "In this case we would identify these functions with a superscript $l$ for the $l$-th layer," - ] - }, - { - "cell_type": "markdown", - "id": "10686541", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - " y_i^l = f^l(u_i^l) = f^l\\left(\\sum_{j=1}^{N_{l-1}} w_{ij}^l y_j^{l-1} + b_i^l\\right)\n", - "\\label{generalLayer} \\tag{4}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "a92cdf36", - "metadata": { - "editable": true - }, - "source": [ - "where $N_l$ is the number of nodes in layer $l$. When the output of\n", - "all the nodes in the first hidden layer are computed, the values of\n", - "the subsequent layer can be calculated and so forth until the output\n", - "is obtained." - ] - }, - { - "cell_type": "markdown", - "id": "74dcfa13", - "metadata": { - "editable": true - }, - "source": [ - "## Mathematical model\n", - "\n", - "The output of neuron $i$ in layer 2 is thus," - ] - }, - { - "cell_type": "markdown", - "id": "0147afef", + "id": "cea42eaf", "metadata": { "editable": true }, @@ -769,43 +3810,25 @@ "\n", "$$\n", "\\begin{equation}\n", - " y_i^2 = f^2\\left(\\sum_{j=1}^N w_{ij}^2 y_j^1 + b_i^2\\right) \n", - "\\label{_auto2} \\tag{5}\n", + "\\delta_j^L = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", + "\\label{_auto2} \\tag{3}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "4a4d5b2e", + "id": "d04fa6e6", "metadata": { "editable": true }, "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation} \n", - " = f^2\\left[\\sum_{j=1}^N w_{ij}^2f^1\\left(\\sum_{k=1}^M w_{jk}^1 x_k + b_j^1\\right) + b_i^2\\right]\n", - "\\label{outputLayer2} \\tag{6}\n", - "\\end{equation}\n", - "$$" + "and" ] }, { "cell_type": "markdown", - "id": "31742756", - "metadata": { - "editable": true - }, - "source": [ - "where we have substituted $y_k^1$ with the inputs $x_k$. Finally, the ANN output reads" - ] - }, - { - "cell_type": "markdown", - "id": "123af90c", + "id": "8716ad2e", "metadata": { "editable": true }, @@ -815,224 +3838,304 @@ "\n", "$$\n", "\\begin{equation}\n", - " y_i^3 = f^3\\left(\\sum_{j=1}^N w_{ij}^3 y_j^2 + b_i^3\\right) \n", - "\\label{_auto3} \\tag{7}\n", + "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", + "\\label{_auto3} \\tag{4}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "aeb7cc95", + "id": "f64753b2", "metadata": { "editable": true }, "source": [ - "\n", - "
    \n", + "## Final back propagating equation\n", "\n", + "We have that (replacing $L$ with a general layer $l$)" + ] + }, + { + "cell_type": "markdown", + "id": "4ad6d6d3", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation} \n", - " = f_3\\left[\\sum_{j} w_{ij}^3 f^2\\left(\\sum_{k} w_{jk}^2 f^1\\left(\\sum_{m} w_{km}^1 x_m + b_k^1\\right) + b_j^2\\right)\n", - " + b_1^3\\right]\n", - "\\label{_auto4} \\tag{8}\n", - "\\end{equation}\n", + "\\delta_j^l =\\frac{\\partial {\\cal C}}{\\partial z_j^l}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "3ab7d88c", + "id": "a8d42ee3", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", - "\n", - "We can generalize this expression to an MLP with $l$ hidden\n", - "layers. The complete functional form is," + "We want to express this in terms of the equations for layer $l+1$." ] }, { "cell_type": "markdown", - "id": "9b07f5bb", + "id": "0628c4b8", "metadata": { "editable": true }, "source": [ - "\n", - "
    \n", + "## Using the chain rule and summing over all $k$ entries\n", "\n", + "We obtain" + ] + }, + { + "cell_type": "markdown", + "id": "0868f3d3", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation}\n", - "y^{l+1}_i = f^{l+1}\\left[\\!\\sum_{j=1}^{N_l} w_{ij}^3 f^l\\left(\\sum_{k=1}^{N_{l-1}}w_{jk}^{l-1}\\left(\\dots f^1\\left(\\sum_{n=1}^{N_0} w_{mn}^1 x_n+ b_m^1\\right)\\dots\\right)+b_k^2\\right)+b_1^3\\right] \n", - "\\label{completeNN} \\tag{9}\n", - "\\end{equation}\n", + "\\delta_j^l =\\sum_k \\frac{\\partial {\\cal C}}{\\partial z_k^{l+1}}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}}=\\sum_k \\delta_k^{l+1}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}},\n", "$$" ] }, { "cell_type": "markdown", - "id": "e9b4beb5", + "id": "89190c24", "metadata": { "editable": true }, "source": [ - "which illustrates a basic property of MLPs: The only independent\n", - "variables are the input values $x_n$." + "and recalling that" ] }, { "cell_type": "markdown", - "id": "57213d71", + "id": "96af414a", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", - "\n", - "This confirms that an MLP, despite its quite convoluted mathematical\n", - "form, is nothing more than an analytic function, specifically a\n", - "mapping of real-valued vectors $\\hat{x} \\in \\mathbb{R}^n \\rightarrow\n", - "\\hat{y} \\in \\mathbb{R}^m$.\n", - "\n", - "Furthermore, the flexibility and universality of an MLP can be\n", - "illustrated by realizing that the expression is essentially a nested\n", - "sum of scaled activation functions of the form" - ] - }, - { - "cell_type": "markdown", - "id": "85dc952c", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", "$$\n", - "\\begin{equation}\n", - " f(x) = c_1 f(c_2 x + c_3) + c_4\n", - "\\label{_auto5} \\tag{10}\n", - "\\end{equation}\n", + "z_j^{l+1} = \\sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1},\n", "$$" ] }, { "cell_type": "markdown", - "id": "4a67580f", + "id": "fe790abf", "metadata": { "editable": true }, "source": [ - "where the parameters $c_i$ are weights and biases. By adjusting these\n", - "parameters, the activation functions can be shifted up and down or\n", - "left and right, change slope or be rescaled which is the key to the\n", - "flexibility of a neural network." + "with $M_l$ being the number of nodes in layer $l$, we obtain" ] }, { "cell_type": "markdown", - "id": "19f79e3c", + "id": "ece1f6fe", "metadata": { "editable": true }, "source": [ - "### Matrix-vector notation\n", - "\n", - "We can introduce a more convenient notation for the activations in an A NN. \n", - "\n", - "Additionally, we can represent the biases and activations\n", - "as layer-wise column vectors $\\hat{b}_l$ and $\\hat{y}_l$, so that the $i$-th element of each vector \n", - "is the bias $b_i^l$ and activation $y_i^l$ of node $i$ in layer $l$ respectively. \n", - "\n", - "We have that $\\mathrm{W}_l$ is an $N_{l-1} \\times N_l$ matrix, while $\\hat{b}_l$ and $\\hat{y}_l$ are $N_l \\times 1$ column vectors. \n", - "With this notation, the sum becomes a matrix-vector multiplication, and we can write\n", - "the equation for the activations of hidden layer 2 (assuming three nodes for simplicity) as" - ] - }, - { - "cell_type": "markdown", - "id": "e350b83c", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", "$$\n", - "\\begin{equation}\n", - " \\hat{y}_2 = f_2(\\mathrm{W}_2 \\hat{y}_{1} + \\hat{b}_{2}) = \n", - " f_2\\left(\\left[\\begin{array}{ccc}\n", - " w^2_{11} &w^2_{12} &w^2_{13} \\\\\n", - " w^2_{21} &w^2_{22} &w^2_{23} \\\\\n", - " w^2_{31} &w^2_{32} &w^2_{33} \\\\\n", - " \\end{array} \\right] \\cdot\n", - " \\left[\\begin{array}{c}\n", - " y^1_1 \\\\\n", - " y^1_2 \\\\\n", - " y^1_3 \\\\\n", - " \\end{array}\\right] + \n", - " \\left[\\begin{array}{c}\n", - " b^2_1 \\\\\n", - " b^2_2 \\\\\n", - " b^2_3 \\\\\n", - " \\end{array}\\right]\\right).\n", - "\\label{_auto6} \\tag{11}\n", - "\\end{equation}\n", + "\\delta_j^l =\\sum_k \\delta_k^{l+1}w_{kj}^{l+1}\\sigma'(z_j^l),\n", "$$" ] }, { "cell_type": "markdown", - "id": "3b64eaf6", + "id": "9cafdde6", "metadata": { "editable": true }, "source": [ - "### Matrix-vector notation and activation\n", + "This is our final equation.\n", "\n", - "The activation of node $i$ in layer 2 is" + "We are now ready to set up the algorithm for back propagation and learning the weights and biases." ] }, { "cell_type": "markdown", - "id": "dc8ca05e", + "id": "0766f482", "metadata": { "editable": true }, "source": [ - "\n", - "
    \n", + "## Setting up the back propagation algorithm\n", "\n", + "The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", + "\n", + "**First**, we set up the input data $\\hat{x}$ and the activations\n", + "$\\hat{z}_1$ of the input layer and compute the activation function and\n", + "the pertinent outputs $\\hat{a}^1$.\n", + "\n", + "**Secondly**, we perform then the feed forward till we reach the output\n", + "layer and compute all $\\hat{z}_l$ of the input layer and compute the\n", + "activation function and the pertinent outputs $\\hat{a}^l$ for\n", + "$l=1,2,3,\\dots,L$.\n", + "\n", + "**Notation**: The first hidden layer has $l=1$ as label and the final output layer has $l=L$." + ] + }, + { + "cell_type": "markdown", + "id": "e29ae382", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the back propagation algorithm, part 2\n", + "\n", + "Thereafter we compute the ouput error $\\hat{\\delta}^L$ by computing all" + ] + }, + { + "cell_type": "markdown", + "id": "518b6578", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation}\n", - " y^2_i = f_2\\Bigr(w^2_{i1}y^1_1 + w^2_{i2}y^1_2 + w^2_{i3}y^1_3 + b^2_i\\Bigr) = \n", - " f_2\\left(\\sum_{j=1}^3 w^2_{ij} y_j^1 + b^2_i\\right).\n", - "\\label{_auto7} \\tag{12}\n", - "\\end{equation}\n", + "\\delta_j^L = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "079a6c4b", + "id": "4f804851", "metadata": { "editable": true }, "source": [ - "This is not just a convenient and compact notation, but also a useful\n", - "and intuitive way to think about MLPs: The output is calculated by a\n", - "series of matrix-vector multiplications and vector additions that are\n", - "used as input to the activation functions. For each operation\n", - "$\\mathrm{W}_l \\hat{y}_{l-1}$ we move forward one layer." + "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,1$ as" ] }, { "cell_type": "markdown", - "id": "3498dab8", + "id": "359aae81", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}\\sigma'(z_j^l).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "70123228", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the Back propagation algorithm, part 3\n", + "\n", + "Finally, we update the weights and the biases using gradient descent\n", + "for each $l=L-1,L-2,\\dots,1$ and update the weights and biases\n", + "according to the rules" + ] + }, + { + "cell_type": "markdown", + "id": "2df5a3de", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8081e4e4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3c40603c", + "metadata": { + "editable": true + }, + "source": [ + "with $\\eta$ being the learning rate." + ] + }, + { + "cell_type": "markdown", + "id": "26de0b47", + "metadata": { + "editable": true + }, + "source": [ + "## Updating the gradients\n", + "\n", + "With the back propagate error for each $l=L-1,L-2,\\dots,1$ as" + ] + }, + { + "cell_type": "markdown", + "id": "a172a64a", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}sigma'(z_j^l),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dfd6fc88", + "metadata": { + "editable": true + }, + "source": [ + "we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,1$ and update the weights and biases according to the rules" + ] + }, + { + "cell_type": "markdown", + "id": "a7df4398", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "cfd24fc1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "869c3364", "metadata": { "editable": true }, @@ -1055,7 +4158,7 @@ }, { "cell_type": "markdown", - "id": "c0b93415", + "id": "91102a3c", "metadata": { "editable": true }, @@ -1074,7 +4177,7 @@ }, { "cell_type": "markdown", - "id": "74a5d31d", + "id": "9609f422", "metadata": { "editable": true }, @@ -1086,7 +4189,7 @@ }, { "cell_type": "markdown", - "id": "539998aa", + "id": "cdd8d562", "metadata": { "editable": true }, @@ -1096,7 +4199,7 @@ }, { "cell_type": "markdown", - "id": "e4b4b760", + "id": "118a47f2", "metadata": { "editable": true }, @@ -1108,7 +4211,7 @@ }, { "cell_type": "markdown", - "id": "b98e352b", + "id": "5d6387b5", "metadata": { "editable": true }, @@ -1124,8 +4227,8 @@ }, { "cell_type": "code", - "execution_count": 4, - "id": "9f6ead02", + "execution_count": 7, + "id": "33449cca", "metadata": { "collapsed": false, "editable": true @@ -1140,7 +4243,7 @@ }, "metadata": { "filenames": { - "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_59_0.png" + "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_304_0.png" } }, "output_type": "display_data" @@ -1154,7 +4257,7 @@ }, "metadata": { "filenames": { - "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_59_1.png" + "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_304_1.png" } }, "output_type": "display_data" @@ -1168,7 +4271,7 @@ }, "metadata": { "filenames": { - "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_59_2.png" + "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_304_2.png" } }, "output_type": "display_data" @@ -1182,7 +4285,7 @@ }, "metadata": { "filenames": { - "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_59_3.png" + "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_304_3.png" } }, "output_type": "display_data" @@ -1264,3562 +4367,459 @@ }, { "cell_type": "markdown", - "id": "95f54888", + "id": "e8fafa8a", "metadata": { "editable": true }, "source": [ - "## The multilayer perceptron (MLP)\n", + "## Fine-tuning neural network hyperparameters\n", "\n", - "The multilayer perceptron is a very popular, and easy to implement approach, to deep learning. It consists of\n", - "1. A neural network with one or more layers of nodes between the input and the output nodes.\n", + "The flexibility of neural networks is also one of their main\n", + "drawbacks: there are many hyperparameters to tweak. Not only can you\n", + "use any imaginable network topology (how neurons/nodes are\n", + "interconnected), but even in a simple FFNN you can change the number\n", + "of layers, the number of neurons per layer, the type of activation\n", + "function to use in each layer, the weight initialization logic, the\n", + "stochastic gradient optmized and much more. How do you know what\n", + "combination of hyperparameters is the best for your task?\n", "\n", - "2. The multilayer network structure, or architecture, or topology, consists of an input layer, one or more hidden layers, and one output layer.\n", + "* You can use grid search with cross-validation to find the right hyperparameters.\n", "\n", - "3. The input nodes pass values to the first hidden layer, its nodes pass the information on to the second and so on till we reach the output layer.\n", + "However,since there are many hyperparameters to tune, and since\n", + "training a neural network on a large dataset takes a lot of time, you\n", + "will only be able to explore a tiny part of the hyperparameter space.\n", "\n", - "As a convention it is normal to call a network with one layer of input units, one layer of hidden\n", - "units and one layer of output units as a two-layer network. A network with two layers of hidden units is called a three-layer network etc etc.\n", + "* You can use randomized search.\n", "\n", - "For an MLP network there is no direct connection between the output nodes/neurons/units and the input nodes/neurons/units.\n", - "Hereafter we will call the various entities of a layer for nodes.\n", - "There are also no connections within a single layer.\n", - "\n", - "The number of input nodes does not need to equal the number of output\n", - "nodes. This applies also to the hidden layers. Each layer may have its\n", - "own number of nodes and activation functions.\n", - "\n", - "The hidden layers have their name from the fact that they are not\n", - "linked to observables and as we will see below when we define the\n", - "so-called activation $\\hat{z}$, we can think of this as a basis\n", - "expansion of the original inputs $\\hat{x}$. The difference however\n", - "between neural networks and say linear regression is that now these\n", - "basis functions (which will correspond to the weights in the network)\n", - "are learned from data. This results in an important difference between\n", - "neural networks and deep learning approaches on one side and methods\n", - "like logistic regression or linear regression and their modifications on the other side." + "* Or use tools like [Oscar](http://oscar.calldesk.ai/), which implements more complex algorithms to help you find a good set of hyperparameters quickly." ] }, { "cell_type": "markdown", - "id": "91bf2419", + "id": "00965f5d", "metadata": { "editable": true }, "source": [ - "## From one to many layers, the universal approximation theorem\n", + "## Hidden layers\n", "\n", - "A neural network with only one layer, what we called the simple\n", - "perceptron, is best suited if we have a standard binary model with\n", - "clear (linear) boundaries between the outcomes. As such it could\n", - "equally well be replaced by standard linear regression or logistic\n", - "regression. Networks with one or more hidden layers approximate\n", - "systems with more complex boundaries.\n", + "For many problems you can start with just one or two hidden layers and\n", + "it will work just fine. For the MNIST data set you ca easily get a\n", + "high accuracy using just one hidden layer with a few hundred neurons.\n", + "You can reach for this data set above 98% accuracy using two hidden\n", + "layers with the same total amount of neurons, in roughly the same\n", + "amount of training time.\n", "\n", - "As stated earlier, \n", - "an important theorem in studies of neural networks, restated without\n", - "proof here, is the [universal approximation\n", - "theorem](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.441.7873&rep=rep1&type=pdf).\n", - "\n", - "It states that a feed-forward network with a single hidden layer\n", - "containing a finite number of neurons can approximate continuous\n", - "functions on compact subsets of real functions. The theorem thus\n", - "states that simple neural networks can represent a wide variety of\n", - "interesting functions when given appropriate parameters. It is the\n", - "multilayer feedforward architecture itself which gives neural networks\n", - "the potential of being universal approximators." + "For more complex problems, you can gradually ramp up the number of\n", + "hidden layers, until you start overfitting the training set. Very\n", + "complex tasks, such as large image classification or speech\n", + "recognition, typically require networks with dozens of layers and they\n", + "need a huge amount of training data. However, you will rarely have to\n", + "train such networks from scratch: it is much more common to reuse\n", + "parts of a pretrained state-of-the-art network that performs a similar\n", + "task." ] }, { "cell_type": "markdown", - "id": "6500ed58", + "id": "d90316a8", "metadata": { "editable": true }, "source": [ - "## Deriving the back propagation code for a multilayer perceptron model\n", + "## Vanishing gradients\n", "\n", - "As we have seen now in a feed forward network, we can express the final output of our network in terms of basic matrix-vector multiplications.\n", - "The unknowwn quantities are our weights $w_{ij}$ and we need to find an algorithm for changing them so that our errors are as small as possible.\n", - "This leads us to the famous [back propagation algorithm](https://www.nature.com/articles/323533a0).\n", + "The Back propagation algorithm we derived above works by going from\n", + "the output layer to the input layer, propagating the error gradient on\n", + "the way. Once the algorithm has computed the gradient of the cost\n", + "function with regards to each parameter in the network, it uses these\n", + "gradients to update each parameter with a Gradient Descent (GD) step.\n", "\n", - "The questions we want to ask are how do changes in the biases and the\n", - "weights in our network change the cost function and how can we use the\n", - "final output to modify the weights?\n", - "\n", - "To derive these equations let us start with a plain regression problem\n", - "and define our cost function as" + "Unfortunately for us, the gradients often get smaller and smaller as\n", + "the algorithm progresses down to the first hidden layers. As a result,\n", + "the GD update leaves the lower layer connection weights virtually\n", + "unchanged, and training never converges to a good solution. This is\n", + "known in the literature as **the vanishing gradients problem**." ] }, { "cell_type": "markdown", - "id": "703f7235", + "id": "441fe8d9", + "metadata": { + "editable": true + }, + "source": [ + "## Exploding gradients\n", + "\n", + "In other cases, the opposite can happen, namely the the gradients can\n", + "grow bigger and bigger. The result is that many of the layers get\n", + "large updates of the weights the algorithm diverges. This is the\n", + "**exploding gradients problem**, which is mostly encountered in\n", + "recurrent neural networks. More generally, deep neural networks suffer\n", + "from unstable gradients, different layers may learn at widely\n", + "different speeds" + ] + }, + { + "cell_type": "markdown", + "id": "ae55ad1c", + "metadata": { + "editable": true + }, + "source": [ + "## Is the Logistic activation function (Sigmoid) our choice?\n", + "\n", + "Although this unfortunate behavior has been empirically observed for\n", + "quite a while (it was one of the reasons why deep neural networks were\n", + "mostly abandoned for a long time), it is only around 2010 that\n", + "significant progress was made in understanding it.\n", + "\n", + "A paper titled [Understanding the Difficulty of Training Deep\n", + "Feedforward Neural Networks by Xavier Glorot and Yoshua Bengio](http://proceedings.mlr.press/v9/glorot10a.html) found that\n", + "the problems with the popular logistic\n", + "sigmoid activation function and the weight initialization technique\n", + "that was most popular at the time, namely random initialization using\n", + "a normal distribution with a mean of 0 and a standard deviation of\n", + "1." + ] + }, + { + "cell_type": "markdown", + "id": "96bbf798", + "metadata": { + "editable": true + }, + "source": [ + "## Logistic function as the root of problems\n", + "\n", + "They showed that with this activation function and this\n", + "initialization scheme, the variance of the outputs of each layer is\n", + "much greater than the variance of its inputs. Going forward in the\n", + "network, the variance keeps increasing after each layer until the\n", + "activation function saturates at the top layers. This is actually made\n", + "worse by the fact that the logistic function has a mean of 0.5, not 0\n", + "(the hyperbolic tangent function has a mean of 0 and behaves slightly\n", + "better than the logistic function in deep networks)." + ] + }, + { + "cell_type": "markdown", + "id": "4b03e108", + "metadata": { + "editable": true + }, + "source": [ + "## The derivative of the Logistic funtion\n", + "\n", + "Looking at the logistic activation function, when inputs become large\n", + "(negative or positive), the function saturates at 0 or 1, with a\n", + "derivative extremely close to 0. Thus when backpropagation kicks in,\n", + "it has virtually no gradient to propagate back through the network,\n", + "and what little gradient exists keeps getting diluted as\n", + "backpropagation progresses down through the top layers, so there is\n", + "really nothing left for the lower layers.\n", + "\n", + "In their paper, Glorot and Bengio propose a way to significantly\n", + "alleviate this problem. We need the signal to flow properly in both\n", + "directions: in the forward direction when making predictions, and in\n", + "the reverse direction when backpropagating gradients. We don’t want\n", + "the signal to die out, nor do we want it to explode and saturate. For\n", + "the signal to flow properly, the authors argue that we need the\n", + "variance of the outputs of each layer to be equal to the variance of\n", + "its inputs, and we also need the gradients to have equal variance\n", + "before and after flowing through a layer in the reverse direction." + ] + }, + { + "cell_type": "markdown", + "id": "2898691d", + "metadata": { + "editable": true + }, + "source": [ + "## Insights from the paper by Glorot and Bengio\n", + "\n", + "One of the insights in the 2010 paper by Glorot and Bengio was that\n", + "the vanishing/exploding gradients problems were in part due to a poor\n", + "choice of activation function. Until then most people had assumed that\n", + "if Nature had chosen to use roughly sigmoid activation functions in\n", + "biological neurons, they must be an excellent choice. But it turns out\n", + "that other activation functions behave much better in deep neural\n", + "networks, in particular the ReLU activation function, mostly because\n", + "it does not saturate for positive values (and also because it is quite\n", + "fast to compute)." + ] + }, + { + "cell_type": "markdown", + "id": "4ac964f3", + "metadata": { + "editable": true + }, + "source": [ + "## The RELU function family\n", + "\n", + "The ReLU activation function suffers from a problem known as the dying\n", + "ReLUs: during training, some neurons effectively die, meaning they\n", + "stop outputting anything other than 0.\n", + "\n", + "In some cases, you may find that half of your network’s neurons are\n", + "dead, especially if you used a large learning rate. During training,\n", + "if a neuron’s weights get updated such that the weighted sum of the\n", + "neuron’s inputs is negative, it will start outputting 0. When this\n", + "happen, the neuron is unlikely to come back to life since the gradient\n", + "of the ReLU function is 0 when its input is negative." + ] + }, + { + "cell_type": "markdown", + "id": "c18a90e1", + "metadata": { + "editable": true + }, + "source": [ + "## ELU function\n", + "\n", + "To solve this problem, nowadays practitioners use a variant of the\n", + "ReLU function, such as the leaky ReLU discussed above or the so-called\n", + "exponential linear unit (ELU) function" + ] + }, + { + "cell_type": "markdown", + "id": "eed9db84", "metadata": { "editable": true }, "source": [ "$$\n", - "{\\cal C}(\\hat{W}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - t_i\\right)^2,\n", + "ELU(z) = \\left\\{\\begin{array}{cc} \\alpha\\left( \\exp{(z)}-1\\right) & z < 0,\\\\ z & z \\ge 0.\\end{array}\\right.\n", "$$" ] }, { "cell_type": "markdown", - "id": "667ef874", + "id": "b375c182", "metadata": { "editable": true }, "source": [ - "where the $t_i$s are our $n$ targets (the values we want to\n", - "reproduce), while the outputs of the network after having propagated\n", - "all inputs $\\hat{x}$ are given by $y_i$. Below we will demonstrate\n", - "how the basic equations arising from the back propagation algorithm\n", - "can be modified in order to study classification problems with $K$\n", - "classes." - ] - }, - { - "cell_type": "markdown", - "id": "dd53c6c8", - "metadata": { - "editable": true - }, - "source": [ - "## Definitions\n", - "\n", - "With our definition of the targets $\\hat{t}$, the outputs of the\n", - "network $\\hat{y}$ and the inputs $\\hat{x}$ we\n", - "define now the activation $z_j^l$ of node/neuron/unit $j$ of the\n", - "$l$-th layer as a function of the bias, the weights which add up from\n", - "the previous layer $l-1$ and the forward passes/outputs\n", - "$\\hat{a}^{l-1}$ from the previous layer as" - ] - }, - { - "cell_type": "markdown", - "id": "4f58ed9b", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_j^l = \\sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c60762cd", - "metadata": { - "editable": true - }, - "source": [ - "where $b_k^l$ are the biases from layer $l$. Here $M_{l-1}$\n", - "represents the total number of nodes/neurons/units of layer $l-1$. The\n", - "figure here illustrates this equation. We can rewrite this in a more\n", - "compact form as the matrix-vector products we discussed earlier," - ] - }, - { - "cell_type": "markdown", - "id": "5c1c5162", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\hat{z}^l = \\left(\\hat{W}^l\\right)^T\\hat{a}^{l-1}+\\hat{b}^l.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "080b6f9a", - "metadata": { - "editable": true - }, - "source": [ - "With the activation values $\\hat{z}^l$ we can in turn define the\n", - "output of layer $l$ as $\\hat{a}^l = f(\\hat{z}^l)$ where $f$ is our\n", - "activation function. In the examples here we will use the sigmoid\n", - "function discussed in our logistic regression lectures. We will also use the same activation function $f$ for all layers\n", - "and their nodes. It means we have" - ] - }, - { - "cell_type": "markdown", - "id": "12e261bb", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "a_j^l = f(z_j^l) = \\frac{1}{1+\\exp{-(z_j^l)}}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "49a48c09", - "metadata": { - "editable": true - }, - "source": [ - "## Derivatives and the chain rule\n", - "\n", - "From the definition of the activation $z_j^l$ we have" - ] - }, - { - "cell_type": "markdown", - "id": "6dc08f48", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial z_j^l}{\\partial w_{ij}^l} = a_i^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "b8211d41", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "96822eda", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial z_j^l}{\\partial a_i^{l-1}} = w_{ji}^l.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f0b1660f", - "metadata": { - "editable": true - }, - "source": [ - "With our definition of the activation function we have that (note that this function depends only on $z_j^l$)" - ] - }, - { - "cell_type": "markdown", - "id": "df85f033", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial a_j^l}{\\partial z_j^{l}} = a_j^l(1-a_j^l)=f(z_j^l)(1-f(z_j^l)).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "ea90d738", - "metadata": { - "editable": true - }, - "source": [ - "## Derivative of the cost function\n", - "\n", - "With these definitions we can now compute the derivative of the cost function in terms of the weights.\n", - "\n", - "Let us specialize to the output layer $l=L$. Our cost function is" - ] - }, - { - "cell_type": "markdown", - "id": "fafb43b4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "{\\cal C}(\\hat{W^L}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - t_i\\right)^2=\\frac{1}{2}\\sum_{i=1}^n\\left(a_i^L - t_i\\right)^2,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "41afcc45", - "metadata": { - "editable": true - }, - "source": [ - "The derivative of this function with respect to the weights is" - ] - }, - { - "cell_type": "markdown", - "id": "aed16939", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\left(a_j^L - t_j\\right)\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "4ece624c", - "metadata": { - "editable": true - }, - "source": [ - "The last partial derivative can easily be computed and reads (by applying the chain rule)" - ] - }, - { - "cell_type": "markdown", - "id": "7fbf4fe4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}} = \\frac{\\partial a_j^L}{\\partial z_{j}^{L}}\\frac{\\partial z_j^L}{\\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "dba0e4a4", - "metadata": { - "editable": true - }, - "source": [ - "## Bringing it together, first back propagation equation\n", - "\n", - "We have thus" - ] - }, - { - "cell_type": "markdown", - "id": "c32147af", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\left(a_j^L - t_j\\right)a_j^L(1-a_j^L)a_k^{L-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "4b6176c8", - "metadata": { - "editable": true - }, - "source": [ - "Defining" - ] - }, - { - "cell_type": "markdown", - "id": "b87747a4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = a_j^L(1-a_j^L)\\left(a_j^L - t_j\\right) = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "1547289e", - "metadata": { - "editable": true - }, - "source": [ - "and using the Hadamard product of two vectors we can write this as" - ] - }, - { - "cell_type": "markdown", - "id": "ef9854e4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\hat{\\delta}^L = f'(\\hat{z}^L)\\circ\\frac{\\partial {\\cal C}}{\\partial (\\hat{a}^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c9ce87bb", - "metadata": { - "editable": true - }, - "source": [ - "This is an important expression. The second term on the right handside\n", - "measures how fast the cost function is changing as a function of the $j$th\n", - "output activation. If, for example, the cost function doesn't depend\n", - "much on a particular output node $j$, then $\\delta_j^L$ will be small,\n", - "which is what we would expect. The first term on the right, measures\n", - "how fast the activation function $f$ is changing at a given activation\n", - "value $z_j^L$.\n", - "\n", - "Notice that everything in the above equations is easily computed. In\n", - "particular, we compute $z_j^L$ while computing the behaviour of the\n", - "network, and it is only a small additional overhead to compute\n", - "$f'(z^L_j)$. The exact form of the derivative with respect to the\n", - "output depends on the form of the cost function.\n", - "However, provided the cost function is known there should be little\n", - "trouble in calculating" - ] - }, - { - "cell_type": "markdown", - "id": "5b74b869", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "42b1eab9", - "metadata": { - "editable": true - }, - "source": [ - "With the definition of $\\delta_j^L$ we have a more compact definition of the derivative of the cost function in terms of the weights, namely" - ] - }, - { - "cell_type": "markdown", - "id": "27331743", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8f1b672f", - "metadata": { - "editable": true - }, - "source": [ - "## Derivatives in terms of $z_j^L$\n", - "\n", - "It is also easy to see that our previous equation can be written as" - ] - }, - { - "cell_type": "markdown", - "id": "543a0ba2", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L =\\frac{\\partial {\\cal C}}{\\partial z_j^L}= \\frac{\\partial {\\cal C}}{\\partial a_j^L}\\frac{\\partial a_j^L}{\\partial z_j^L},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "628ee133", - "metadata": { - "editable": true - }, - "source": [ - "which can also be interpreted as the partial derivative of the cost function with respect to the biases $b_j^L$, namely" - ] - }, - { - "cell_type": "markdown", - "id": "94f361e5", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L}\\frac{\\partial b_j^L}{\\partial z_j^L}=\\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "13e5c5d5", - "metadata": { - "editable": true - }, - "source": [ - "That is, the error $\\delta_j^L$ is exactly equal to the rate of change of the cost function as a function of the bias." - ] - }, - { - "cell_type": "markdown", - "id": "4887a3d7", - "metadata": { - "editable": true - }, - "source": [ - "## Bringing it together\n", - "\n", - "We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are\n", - "\n", - "**The starting equations.**" - ] - }, - { - "cell_type": "markdown", - "id": "8f4d75dd", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1},\n", - "\\label{_auto8} \\tag{13}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "69864347", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "e654f179", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", - "\\label{_auto9} \\tag{14}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f650a917", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "b8169c55", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", - "\\label{_auto10} \\tag{15}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "5567d66c", - "metadata": { - "editable": true - }, - "source": [ - "An interesting consequence of the above equations is that when the\n", - "activation $a_k^{L-1}$ is small, the gradient term, that is the\n", - "derivative of the cost function with respect to the weights, will also\n", - "tend to be small. We say then that the weight learns slowly, meaning\n", - "that it changes slowly when we minimize the weights via say gradient\n", - "descent. In this case we say the system learns slowly.\n", - "\n", - "Another interesting feature is that is when the activation function,\n", - "represented by the sigmoid function here, is rather flat when we move towards\n", - "its end values $0$ and $1$ (see the above Python codes). In these\n", - "cases, the derivatives of the activation function will also be close\n", - "to zero, meaning again that the gradients will be small and the\n", - "network learns slowly again.\n", - "\n", - "We need a fourth equation and we are set. We are going to propagate\n", - "backwards in order to the determine the weights and biases. In order\n", - "to do so we need to represent the error in the layer before the final\n", - "one $L-1$ in terms of the errors in the final output layer." - ] - }, - { - "cell_type": "markdown", - "id": "f5c09470", - "metadata": { - "editable": true - }, - "source": [ - "## Final back propagating equation\n", - "\n", - "We have that (replacing $L$ with a general layer $l$)" - ] - }, - { - "cell_type": "markdown", - "id": "d66ef5ca", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\frac{\\partial {\\cal C}}{\\partial z_j^l}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e96004a2", - "metadata": { - "editable": true - }, - "source": [ - "We want to express this in terms of the equations for layer $l+1$. Using the chain rule and summing over all $k$ entries we have" - ] - }, - { - "cell_type": "markdown", - "id": "0ee94485", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\sum_k \\frac{\\partial {\\cal C}}{\\partial z_k^{l+1}}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}}=\\sum_k \\delta_k^{l+1}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "1c2ac190", - "metadata": { - "editable": true - }, - "source": [ - "and recalling that" - ] - }, - { - "cell_type": "markdown", - "id": "f89f9c76", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_j^{l+1} = \\sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f8293787", - "metadata": { - "editable": true - }, - "source": [ - "with $M_l$ being the number of nodes in layer $l$, we obtain" - ] - }, - { - "cell_type": "markdown", - "id": "a2914db3", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "297a2622", - "metadata": { - "editable": true - }, - "source": [ - "This is our final equation.\n", - "\n", - "We are now ready to set up the algorithm for back propagation and learning the weights and biases." - ] - }, - { - "cell_type": "markdown", - "id": "c952f57b", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\hat{x}$ and the activations\n", - "$\\hat{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\hat{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\hat{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\hat{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\hat{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "37d4f242", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "ff2e732a", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "97a96714", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "3ee8ad1b", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "c4d2d1a1", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "d412dae3", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "64129a91", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "681d8bd9", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\boldsymbol{x}$ and the activations\n", - "$\\boldsymbol{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\boldsymbol{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\boldsymbol{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\boldsymbol{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\boldsymbol{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "62904d70", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bb5b2dde", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "51828c66", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c4124232", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "80791bf2", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "107737c9", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "720ad834", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "6854da89", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations derived discussed above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\boldsymbol{x}$ and the activations\n", - "$\\boldsymbol{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\boldsymbol{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\boldsymbol{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\boldsymbol{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\boldsymbol{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "b5c0c6c7", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "43403932", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "08f3064e", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f5d698a4", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "3ae56fb5", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "b822ca59", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e0593696", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "c77a2a17", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up a Multi-layer perceptron model for classification\n", - "\n", - "We are now gong to develop an example based on the MNIST data\n", - "base. This is a classification problem and we need to use our\n", - "cross-entropy function we discussed in connection with logistic\n", - "regression. The cross-entropy defines our cost function for the\n", - "classificaton problems with neural networks.\n", - "\n", - "In binary classification with two classes $(0, 1)$ we define the\n", - "logistic/sigmoid function as the probability that a particular input\n", - "is in class $0$ or $1$. This is possible because the logistic\n", - "function takes any input from the real numbers and inputs a number\n", - "between 0 and 1, and can therefore be interpreted as a probability. It\n", - "also has other nice properties, such as a derivative that is simple to\n", - "calculate.\n", - "\n", - "For an input $\\boldsymbol{a}$ from the hidden layer, the probability that the input $\\boldsymbol{x}$\n", - "is in class 0 or 1 is just. We let $\\theta$ represent the unknown weights and biases to be adjusted by our equations). The variable $x$\n", - "represents our activation values $z$. We have" - ] - }, - { - "cell_type": "markdown", - "id": "093f5d87", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y = 0 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) = \\frac{1}{1 + \\exp{(- \\boldsymbol{x}})} ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7bd03f69", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "fe5226a0", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y = 1 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) = 1 - P(y = 0 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "45f1532a", - "metadata": { - "editable": true - }, - "source": [ - "where $y \\in \\{0, 1\\}$ and $\\boldsymbol{\\theta}$ represents the weights and biases\n", - "of our network." - ] - }, - { - "cell_type": "markdown", - "id": "1b07418e", - "metadata": { - "editable": true - }, - "source": [ - "## Defining the cost function\n", - "\n", - "Our cost function is given as (see the Logistic regression lectures)" - ] - }, - { - "cell_type": "markdown", - "id": "c7f5232f", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\theta}) = - \\ln P(\\mathcal{D} \\mid \\boldsymbol{\\theta}) = - \\sum_{i=1}^n\n", - "y_i \\ln[P(y_i = 0)] + (1 - y_i) \\ln [1 - P(y_i = 0)] = \\sum_{i=1}^n \\mathcal{L}_i(\\boldsymbol{\\theta}) .\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e1af7b47", - "metadata": { - "editable": true - }, - "source": [ - "This last equality means that we can interpret our *cost* function as a sum over the *loss* function\n", - "for each point in the dataset $\\mathcal{L}_i(\\boldsymbol{\\theta})$. \n", - "The negative sign is just so that we can think about our algorithm as minimizing a positive number, rather\n", - "than maximizing a negative number. \n", - "\n", - "In *multiclass* classification it is common to treat each integer label as a so called *one-hot* vector: \n", - "\n", - "$y = 5 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,$ and\n", - "\n", - "$y = 1 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,$ \n", - "\n", - "i.e. a binary bit string of length $C$, where $C = 10$ is the number of classes in the MNIST dataset (numbers from $0$ to $9$).. \n", - "\n", - "If $\\boldsymbol{x}_i$ is the $i$-th input (image), $y_{ic}$ refers to the $c$-th component of the $i$-th\n", - "output vector $\\boldsymbol{y}_i$. \n", - "The probability of $\\boldsymbol{x}_i$ being in class $c$ will be given by the softmax function:" - ] - }, - { - "cell_type": "markdown", - "id": "db469d35", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y_{ic} = 1 \\mid \\boldsymbol{x}_i, \\boldsymbol{\\theta}) = \\frac{\\exp{((\\boldsymbol{a}_i^{hidden})^T \\boldsymbol{w}_c)}}\n", - "{\\sum_{c'=0}^{C-1} \\exp{((\\boldsymbol{a}_i^{hidden})^T \\boldsymbol{w}_{c'})}} ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "deb48962", - "metadata": { - "editable": true - }, - "source": [ - "which reduces to the logistic function in the binary case. \n", - "The likelihood of this $C$-class classifier\n", - "is now given as:" - ] - }, - { - "cell_type": "markdown", - "id": "36443e39", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(\\mathcal{D} \\mid \\boldsymbol{\\theta}) = \\prod_{i=1}^n \\prod_{c=0}^{C-1} [P(y_{ic} = 1)]^{y_{ic}} .\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8076d9fa", - "metadata": { - "editable": true - }, - "source": [ - "Again we take the negative log-likelihood to define our cost function:" - ] - }, - { - "cell_type": "markdown", - "id": "292dad0a", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\theta}) = - \\log{P(\\mathcal{D} \\mid \\boldsymbol{\\theta})}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7803b746", - "metadata": { - "editable": true - }, - "source": [ - "See the logistic regression lectures for a full definition of the cost function.\n", - "\n", - "The back propagation equations need now only a small change, namely the definition of a new cost function. We are thus ready to use the same equations as before!" - ] - }, - { - "cell_type": "markdown", - "id": "a71f1366", - "metadata": { - "editable": true - }, - "source": [ - "## Example: binary classification problem\n", - "\n", - "As an example of the above, relevant for project 2 as well, let us consider a binary class. As discussed in our logistic regression lectures, we defined a cost function in terms of the parameters $\\beta$ as" - ] - }, - { - "cell_type": "markdown", - "id": "25efb288", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\beta}) = - \\sum_{i=1}^n \\left(y_i\\log{p(y_i \\vert x_i,\\boldsymbol{\\beta})}+(1-y_i)\\log{1-p(y_i \\vert x_i,\\boldsymbol{\\beta})}\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "6192694f", - "metadata": { - "editable": true - }, - "source": [ - "where we had defined the logistic (sigmoid) function" - ] - }, - { - "cell_type": "markdown", - "id": "f6786106", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "p(y_i =1\\vert x_i,\\boldsymbol{\\beta})=\\frac{\\exp{(\\beta_0+\\beta_1 x_i)}}{1+\\exp{(\\beta_0+\\beta_1 x_i)}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "be663cac", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "a6953973", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "p(y_i =0\\vert x_i,\\boldsymbol{\\beta})=1-p(y_i =1\\vert x_i,\\boldsymbol{\\beta}).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "de08816b", - "metadata": { - "editable": true - }, - "source": [ - "The parameters $\\boldsymbol{\\beta}$ were defined using a minimization method like gradient descent or Newton-Raphson's method. \n", - "\n", - "Now we replace $x_i$ with the activation $z_i^l$ for a given layer $l$ and the outputs as $y_i=a_i^l=f(z_i^l)$, with $z_i^l$ now being a function of the weights $w_{ij}^l$ and biases $b_i^l$. \n", - "We have then" - ] - }, - { - "cell_type": "markdown", - "id": "d9b14b33", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "a_i^l = y_i = \\frac{\\exp{(z_i^l)}}{1+\\exp{(z_i^l)}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8072c452", - "metadata": { - "editable": true - }, - "source": [ - "with" - ] - }, - { - "cell_type": "markdown", - "id": "34a5cb25", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_i^l = \\sum_{j}w_{ij}^l a_j^{l-1}+b_i^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "833dc972", - "metadata": { - "editable": true - }, - "source": [ - "where the superscript $l-1$ indicates that these are the outputs from layer $l-1$.\n", - "Our cost function at the final layer $l=L$ is now" - ] - }, - { - "cell_type": "markdown", - "id": "3c52b850", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{W}) = - \\sum_{i=1}^n \\left(t_i\\log{a_i^L}+(1-t_i)\\log{(1-a_i^L)}\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "01c24d99", - "metadata": { - "editable": true - }, - "source": [ - "where we have defined the targets $t_i$. The derivatives of the cost function with respect to the output $a_i^L$ are then easily calculated and we get" - ] - }, - { - "cell_type": "markdown", - "id": "692fbd5a", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial \\mathcal{C}(\\boldsymbol{W})}{\\partial a_i^L} = \\frac{a_i^L-t_i}{a_i^L(1-a_i^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "cdd8c203", - "metadata": { - "editable": true - }, - "source": [ - "In case we use another activation function than the logistic one, we need to evaluate other derivatives." - ] - }, - { - "cell_type": "markdown", - "id": "1e7eba9c", - "metadata": { - "editable": true - }, - "source": [ - "## The Softmax function\n", - "In case we employ the more general case given by the Softmax equation, we need to evaluate the derivative of the activation function with respect to the activation $z_i^l$, that is we need" - ] - }, - { - "cell_type": "markdown", - "id": "8ca62ded", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial f(z_i^l)}{\\partial w_{jk}^l} =\n", - "\\frac{\\partial f(z_i^l)}{\\partial z_j^l} \\frac{\\partial z_j^l}{\\partial w_{jk}^l}= \\frac{\\partial f(z_i^l)}{\\partial z_j^l}a_k^{l-1}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "479d6d33", - "metadata": { - "editable": true - }, - "source": [ - "For the Softmax function we have" - ] - }, - { - "cell_type": "markdown", - "id": "3a63ba14", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "f(z_i^l) = \\frac{\\exp{(z_i^l)}}{\\sum_{m=1}^K\\exp{(z_m^l)}}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bed10528", - "metadata": { - "editable": true - }, - "source": [ - "Its derivative with respect to $z_j^l$ gives" - ] - }, - { - "cell_type": "markdown", - "id": "6a77ac39", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial f(z_i^l)}{\\partial z_j^l}= f(z_i^l)\\left(\\delta_{ij}-f(z_j^l)\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7fd16de8", - "metadata": { - "editable": true - }, - "source": [ - "which in case of the simply binary model reduces to having $i=j$." - ] - }, - { - "cell_type": "markdown", - "id": "a598757e", - "metadata": { - "editable": true - }, - "source": [ - "## Developing a code for doing neural networks with back propagation\n", - "\n", - "One can identify a set of key steps when using neural networks to solve supervised learning problems: \n", - "\n", - "1. Collect and pre-process data \n", - "\n", - "2. Define model and architecture \n", - "\n", - "3. Choose cost function and optimizer \n", - "\n", - "4. Train the model \n", - "\n", - "5. Evaluate model performance on test data \n", - "\n", - "6. Adjust hyperparameters (if necessary, network architecture)" - ] - }, - { - "cell_type": "markdown", - "id": "0dc69031", - "metadata": { - "editable": true - }, - "source": [ - "## Collect and pre-process data\n", - "\n", - "Here we will be using the MNIST dataset, which is readily available through the **scikit-learn**\n", - "package. You may also find it for example [here](http://yann.lecun.com/exdb/mnist/). \n", - "The *MNIST* (Modified National Institute of Standards and Technology) database is a large database\n", - "of handwritten digits that is commonly used for training various image processing systems. \n", - "The MNIST dataset consists of 70 000 images of size $28\\times 28$ pixels, each labeled from 0 to 9. \n", - "The scikit-learn dataset we will use consists of a selection of 1797 images of size $8\\times 8$ collected and processed from this database. \n", - "\n", - "To feed data into a feed-forward neural network we need to represent\n", - "the inputs as a design/feature matrix $X = (n_{inputs}, n_{features})$. Each\n", - "row represents an *input*, in this case a handwritten digit, and\n", - "each column represents a *feature*, in this case a pixel. The\n", - "correct answers, also known as *labels* or *targets* are\n", - "represented as a 1D array of integers \n", - "$Y = (n_{inputs}) = (5, 3, 1, 8,...)$.\n", - "\n", - "As an example, say we want to build a neural network using supervised learning to predict Body-Mass Index (BMI) from\n", - "measurements of height (in m) \n", - "and weight (in kg). If we have measurements of 5 people the design/feature matrix could be for example: \n", - "\n", - "$$ X = \\begin{bmatrix}\n", - "1.85 & 81\\\\\n", - "1.71 & 65\\\\\n", - "1.95 & 103\\\\\n", - "1.55 & 42\\\\\n", - "1.63 & 56\n", - "\\end{bmatrix} ,$$ \n", - "\n", - "and the targets would be: \n", - "\n", - "$$ Y = (23.7, 22.2, 27.1, 17.5, 21.1) $$ \n", - "\n", - "Since each input image is a 2D matrix, we need to flatten the image\n", - "(i.e. \"unravel\" the 2D matrix into a 1D array) to turn the data into a\n", - "design/feature matrix. This means we lose all spatial information in the\n", - "image, such as locality and translational invariance. More complicated\n", - "architectures such as Convolutional Neural Networks can take advantage\n", - "of such information, and are most commonly applied when analyzing\n", - "images." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "d7c49d9c", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "inputs = (n_inputs, pixel_width, pixel_height) = (1797, 8, 8)\n", - "labels = (n_inputs) = (1797,)\n", - "X = (n_inputs, n_features) = (1797, 64)\n" - ] - }, - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAA7YAAADICAYAAADcOn20AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAQx0lEQVR4nO3dbWydZRkH8OuMjklYaEHMxla3ji46/KBdiItodB2oEUVXDNMYois6QgLCkKkhEGwHGDCaWIxODY510SUuJmSdZr4AdjUmxPBWEhaNjlBEzSYOOl+SbQwfPxhqN9Y68G7rdc7vl/QDZz3/c5+T6z7P899zOKtVVVUFAAAAJDVrphcAAAAA/wvFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgtYYptv39/VGr1eLhhx8ukler1eLTn/50kazxmb29va/6/nv37o2Pf/zjsWjRojjttNOivb09brjhhjhw4EC5RZJSvc9/b29v1Gq1CX++//3vF10r+dgD9kAjq/f5f+aZZ+LSSy+Nc889N04//fRobm6O5cuXx9e//vU4evRo0XWSj/lvHE0zvQDKePbZZ+Ntb3tbnHHGGXHbbbfFokWL4rHHHouenp4YHByMRx55JGbNapi/x6DBrFu3Lt73vve97PYrr7wynnzyyRP+GdQTe4BG9o9//CPOOOOMuOWWW2LRokVx5MiR2LVrV1x77bUxPDwc3/nOd2Z6iTBlzP9/KLZ1YmBgIA4cOBDbt2+Piy66KCIiVq1aFYcPH46bbropHn/88Vi+fPkMrxKmRmtra7S2th5z28jISOzZsycuv/zyaGlpmZmFwTSxB2hky5Yti61btx5z28UXXxx//vOfY+vWrfGNb3wj5syZM0Org6ll/v/DJbxxDh06FBs2bIiOjo5obm6Os846Ky644IIYGBiY8D7f/va34w1veEPMmTMn3vSmN53w41779u2Lq666KlpbW+PUU0+NJUuWxMaNG4t+PGD27NkREdHc3HzM7S+dzLzmNa8p9ljUp8zzfyL33HNPVFUV69atm9LHoX7YAzSyepv/iIjXve51MWvWrDjllFOm/LHIzfzXB1dsxzl8+HA899xz8dnPfjYWLlwYR44cifvvvz8+/OEPx5YtW+ITn/jEMb+/c+fOGBwcjFtvvTVOP/302LRpU3zsYx+LpqamuOyyyyLi3wO9YsWKmDVrVnzhC1+I9vb2ePDBB+P222+PkZGR2LJly6Rramtri4h//837ZLq6umLRokWxYcOG2LRpUyxevDgeffTRuPPOO+ODH/xgnHfeea/6daExZJ7/4/3zn/+M/v7+WLp0aaxcufIV3ZfGZQ/QyOph/quqihdffDH+9re/xc9+9rPo7++PDRs2RFOT010mZ/7rRNUgtmzZUkVE9dBDD530fY4ePVq98MIL1ac+9alq+fLlx/xZRFSnnXZatW/fvmN+f9myZdXSpUvHbrvqqququXPnVk8//fQx9//KV75SRUS1Z8+eYzJ7enqO+b329vaqvb39pNb7pz/9qbrggguqiBj7WbNmTXXo0KGTfcrUqUaY//F+/OMfVxFR3XHHHa/4vtQne4BG1ijzf8cdd4yd/9Rqtermm28+6ftSv8x/4/BR5OP84Ac/iHe84x0xd+7caGpqitmzZ8fmzZvj17/+9ct+96KLLop58+aN/fcpp5wSH/3oR2Pv3r3xhz/8ISIifvSjH8WqVatiwYIFcfTo0bGfiy++OCIihoaGJl3P3r17Y+/evf913c8//3ysXr06/vrXv8a2bdviF7/4RWzatCl++ctfxoc+9KGG+1Y0Xp2s83+8zZs3R1NTU3R3d7/i+9LY7AEaWfb57+7ujoceeih++tOfxuc///n48pe/HNdee+1J35/GZv7za6Br0//dvffeGx/5yEdizZo18bnPfS7mz58fTU1N8c1vfjPuueeel/3+/PnzJ7ztwIED0draGvv3748f/vCHY/8P7PH+8pe/FFn7l770pRgeHo6nn346zjnnnIiIeOc73xnLli2LCy+8MLZt2xZr164t8ljUp8zzf3zmzp074wMf+MAJ1wgTsQdoZPUw//Pnzx9bw3vf+94488wz48Ybb4xPfvKTvkCTSZn/+qDYjvO9730vlixZEtu3b49arTZ2++HDh0/4+/v27Zvwtte+9rUREXH22WfHm9/85vjiF794wowFCxb8r8uOiIjh4eFYuHDhWKl9yVvf+taIiHjiiSeKPA71K/P8j/fd7343jhw54gtzeMXsARpZvcz/eCtWrIiIiN/+9rcNc2LPq2P+64NiO06tVotTTz31mIHet2/fhN+I9sADD8T+/fvHPorw4osvxvbt26O9vX3sn1245JJLYteuXdHe3h5nnnnmlK19wYIF8cADD8Qf//jHWLhw4djtDz74YETEy/4ZCDhe5vkfb/PmzbFgwYKxj/rAybIHaGT1Mv/jDQ4ORkTE0qVLp/2xycX814eGK7Y///nPT/jtYu9///vjkksuiXvvvTeuvvrquOyyy+KZZ56J2267Lc4555z43e9+97L7nH322XHhhRfGLbfcMvaNaL/5zW+O+brvW2+9Ne677754+9vfHtddd1288Y1vjEOHDsXIyEjs2rUrvvWtb01aOl8axv/2Gftrrrkmtm3bFu95z3vixhtvjNe//vXxxBNPxO233x7z5s2Lyy+//CRfIepZvc7/S371q1/Fnj174qabbmqor7fn5NkDNLJ6nf+enp7Yv39/vOtd74qFCxfG6Oho/OQnP4m777471qxZE+eff/5JvkLUM/PfAGb626umy0vfiDbRz1NPPVVVVVXdeeedVVtbWzVnzpzqvPPOq+6+++6qp6enOv6liojqmmuuqTZt2lS1t7dXs2fPrpYtW1Zt27btZY/97LPPVtddd121ZMmSavbs2dVZZ51VnX/++dXNN99c/f3vfz8m8/hvRFu8eHG1ePHik3qOjz76aHXppZdWra2t1Zw5c6pzzz23WrduXfX73//+Fb1W1J9GmP+qqqorr7yyqtVq1ZNPPnnS96Ex2AM0snqf/507d1bvfve7q3nz5lVNTU3V3LlzqxUrVlRf+9rXqhdeeOEVv17UF/PfOGpVVVWlyzIAAABMF//cDwAAAKkptgAAAKSm2AIAAJCaYgsAAEBqii0AAACpKbYAAACkptgCAACQWtNML6CU/v7+onm9vb1F81paWormRUT09fUVzevs7Cyax/TZvXt30bzS+2nHjh1F8yIiDh48WDRvcHCwaJ79NL0GBgaK5q1fv75o3lQove/b2tqK5jGxkZGRonmlzwdKHwNKv19HRDQ3NxfNGx4eLppnP01udHS0aN7/+x4o/XwjzOyJuGILAABAaootAAAAqSm2AAAApKbYAgAAkJpiCwAAQGqKLQAAAKkptgAAAKSm2AIAAJCaYgsAAEBqii0AAACpKbYAAACkptgCAACQmmILAABAaootAAAAqSm2AAAApKbYAgAAkJpiCwAAQGqKLQAAAKk1zdQD7969u2jeFVdcUTRv9erVRfNaWlqK5kVEdHV1Fc0bHR0tmsf0uf7664vmlZ6F7u7uonkREXfddVfRvKnYo0xsZGSkaF7p98MMduzYUTSv9PsIE/t/f623bt1aNG9wcLBoXkT5Y4BzoOlV+vUu/X5Y+phSen0REf39/UXzent7i+bNBFdsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgNcUWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUalVVVTPxwNdff33RvJGRkaJ5O3bsKJrX2dlZNC8ioqWlpWhe6efM9Ck9/6Vna2hoqGheRMTatWuL5o2OjhbNY3r19fUVzevo6Ciat2rVqqJ5ERErV64smrd79+6iefCS0ud8ERHDw8NF88w/U2kqekDp41Tp4+hMcMUWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgNcUWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEitaaYeuK2trWjeyMhI0bze3t6ieUNDQ0XzIiIee+yx4pnkNDo6WjSv9H7q6ekpmhcR0dLSUjSv9HMu/R7H5Lq7u4vmlT4GTIXSx5XSzznDa8j06OjoKJ7Z399fNK/0cbT0MYrJlT6Gd3V1Fc2bCn19fTO9hP87rtgCAACQmmILAABAaootAAAAqSm2AAAApKbYAgAAkJpiCwAAQGqKLQAAAKkptgAAAKSm2AIAAJCaYgsAAEBqii0AAACpKbYAAACkptgCAACQmmILAABAaootAAAAqSm2AAAApKbYAgAAkJpiCwAAQGqKLQAAAKnVqqqqZnoRJXR0dBTNe/zxx4vmrV27tmheRER/f3/xTKbHwMBA0byurq6ieY2op6enaF5vb2/RvHozPDxcNK+zs7No3sGDB4vmTYXSx5XSM9vW1lY0D8YrPV+lj6N9fX1F85hcIx5TtmzZUjSvu7u7aN5McMUWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgNcUWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACC1WlVV1UwvooSOjo6ZXsKkWlpaimeWfs59fX1F85jY7t27i+bt2LGjaN7w8HDRvJGRkaJ5EeXXOBV7lImV3gOrVq0qmlfa6tWri2eW3veQSWdn50wvYVKl3+Pqzejo6EwvYVKlzwmmYl5Ln1tNxbnadHPFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgNcUWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABIrWmmF1BKS0tL0bzOzs6ieb29vUXzIso/59JrLL2+elJ6vg4ePFg0r7+/v2heV1dX0bwI85Vd6T2wfv36onl33XVX0bwrrriiaB6MNzAwUDRv8eLFRfOGh4eL5k1F5lScpzGxoaGhonk9PT1F8zZu3Fg0r7u7u2heRPnjyujoaNG8mThPc8UWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgNcUWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEitaaYXUMpnPvOZonldXV1F8zZu3Fg0LyJi9erVRfNaWlqK5jF9nn/++aJ5Bw8eLJrX3d1dNA+m2lve8paieaXfr2G8r371q0XzhoaGiuY1NzcXzYsof1xxnJpeK1euLJrX2dlZNK/0nhodHS2aFxGxfv36onn10ANcsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgNcUWAACA1BRbAAAAUlNsAQAASE2xBQAAIDXFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgNcUWAACA1BRbAAAAUqtVVVXN9CIAAADg1XLFFgAAgNQUWwAAAFJTbAEAAEhNsQUAACA1xRYAAIDUFFsAAABSU2wBAABITbEFAAAgNcUWAACA1P4F8SqxxH5w1EMAAAAASUVORK5CYII=", - "text/plain": [ - "
    " - ] - }, - "metadata": { - "filenames": { - "image/png": "/Users/mhjensen/Teaching/MachineLearning/doc/LectureNotes/_build/jupyter_execute/week41_176_1.png" - } - }, - "output_type": "display_data" - } - ], - "source": [ - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn import datasets\n", - "\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# display images in notebook\n", - "%matplotlib inline\n", - "plt.rcParams['figure.figsize'] = (12,12)\n", - "\n", - "\n", - "# download MNIST dataset\n", - "digits = datasets.load_digits()\n", - "\n", - "# define inputs and labels\n", - "inputs = digits.images\n", - "labels = digits.target\n", - "\n", - "print(\"inputs = (n_inputs, pixel_width, pixel_height) = \" + str(inputs.shape))\n", - "print(\"labels = (n_inputs) = \" + str(labels.shape))\n", - "\n", - "\n", - "# flatten the image\n", - "# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64\n", - "n_inputs = len(inputs)\n", - "inputs = inputs.reshape(n_inputs, -1)\n", - "print(\"X = (n_inputs, n_features) = \" + str(inputs.shape))\n", - "\n", - "\n", - "# choose some random images to display\n", - "indices = np.arange(n_inputs)\n", - "random_indices = np.random.choice(indices, size=5)\n", - "\n", - "for i, image in enumerate(digits.images[random_indices]):\n", - " plt.subplot(1, 5, i+1)\n", - " plt.axis('off')\n", - " plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n", - " plt.title(\"Label: %d\" % digits.target[random_indices[i]])\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "672723bb", - "metadata": { - "editable": true - }, - "source": [ - "## Train and test datasets\n", - "\n", - "Performing analysis before partitioning the dataset is a major error, that can lead to incorrect conclusions. \n", - "\n", - "We will reserve $80 \\%$ of our dataset for training and $20 \\%$ for testing. \n", - "\n", - "It is important that the train and test datasets are drawn randomly from our dataset, to ensure\n", - "no bias in the sampling. \n", - "Say you are taking measurements of weather data to predict the weather in the coming 5 days.\n", - "You don't want to train your model on measurements taken from the hours 00.00 to 12.00, and then test it on data\n", - "collected from 12.00 to 24.00." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "3b0db869", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Number of training images: 1437\n", - "Number of test images: 360\n" - ] - } - ], - "source": [ - "from sklearn.model_selection import train_test_split\n", - "\n", - "# one-liner from scikit-learn library\n", - "train_size = 0.8\n", - "test_size = 1 - train_size\n", - "X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,\n", - " test_size=test_size)\n", - "\n", - "# equivalently in numpy\n", - "def train_test_split_numpy(inputs, labels, train_size, test_size):\n", - " n_inputs = len(inputs)\n", - " inputs_shuffled = inputs.copy()\n", - " labels_shuffled = labels.copy()\n", - " \n", - " np.random.shuffle(inputs_shuffled)\n", - " np.random.shuffle(labels_shuffled)\n", - " \n", - " train_end = int(n_inputs*train_size)\n", - " X_train, X_test = inputs_shuffled[:train_end], inputs_shuffled[train_end:]\n", - " Y_train, Y_test = labels_shuffled[:train_end], labels_shuffled[train_end:]\n", - " \n", - " return X_train, X_test, Y_train, Y_test\n", - "\n", - "#X_train, X_test, Y_train, Y_test = train_test_split_numpy(inputs, labels, train_size, test_size)\n", - "\n", - "print(\"Number of training images: \" + str(len(X_train)))\n", - "print(\"Number of test images: \" + str(len(X_test)))" - ] - }, - { - "cell_type": "markdown", - "id": "a52c7acf", - "metadata": { - "editable": true - }, - "source": [ - "## Define model and architecture\n", - "\n", - "Our simple feed-forward neural network will consist of an *input* layer, a single *hidden* layer and an *output* layer. The activation $y$ of each neuron is a weighted sum of inputs, passed through an activation function. In case of the simple perceptron model we have \n", - "\n", - "$$ z = \\sum_{i=1}^n w_i a_i ,$$\n", - "\n", - "$$ y = f(z) ,$$\n", - "\n", - "where $f$ is the activation function, $a_i$ represents input from neuron $i$ in the preceding layer\n", - "and $w_i$ is the weight to input $i$. \n", - "The activation of the neurons in the input layer is just the features (e.g. a pixel value). \n", - "\n", - "The simplest activation function for a neuron is the *Heaviside* function:\n", - "\n", - "$$ f(z) = \n", - "\\begin{cases}\n", - "1, & z > 0\\\\\n", - "0, & \\text{otherwise}\n", - "\\end{cases}\n", - "$$\n", - "\n", - "A feed-forward neural network with this activation is known as a *perceptron*. \n", - "For a binary classifier (i.e. two classes, 0 or 1, dog or not-dog) we can also use this in our output layer. \n", - "This activation can be generalized to $k$ classes (using e.g. the *one-against-all* strategy), \n", - "and we call these architectures *multiclass perceptrons*. \n", - "\n", - "However, it is now common to use the terms Single Layer Perceptron (SLP) (1 hidden layer) and \n", - "Multilayer Perceptron (MLP) (2 or more hidden layers) to refer to feed-forward neural networks with any activation function. \n", - "\n", - "Typical choices for activation functions include the sigmoid function, hyperbolic tangent, and Rectified Linear Unit (ReLU). \n", - "We will be using the sigmoid function $\\sigma(x)$: \n", - "\n", - "$$ f(x) = \\sigma(x) = \\frac{1}{1 + e^{-x}} ,$$\n", - "\n", - "which is inspired by probability theory (see logistic regression) and was most commonly used until about 2011. See the discussion below concerning other activation functions." - ] - }, - { - "cell_type": "markdown", - "id": "f1ef08f4", - "metadata": { - "editable": true - }, - "source": [ - "## Layers\n", - "\n", - "* Input \n", - "\n", - "Since each input image has 8x8 = 64 pixels or features, we have an input layer of 64 neurons. \n", - "\n", - "* Hidden layer\n", - "\n", - "We will use 50 neurons in the hidden layer receiving input from the neurons in the input layer. \n", - "Since each neuron in the hidden layer is connected to the 64 inputs we have 64x50 = 3200 weights to the hidden layer. \n", - "\n", - "* Output\n", - "\n", - "If we were building a binary classifier, it would be sufficient with a single neuron in the output layer,\n", - "which could output 0 or 1 according to the Heaviside function. This would be an example of a *hard* classifier, meaning it outputs the class of the input directly. However, if we are dealing with noisy data it is often beneficial to use a *soft* classifier, which outputs the probability of being in class 0 or 1. \n", - "\n", - "For a soft binary classifier, we could use a single neuron and interpret the output as either being the probability of being in class 0 or the probability of being in class 1. Alternatively we could use 2 neurons, and interpret each neuron as the probability of being in each class. \n", - "\n", - "Since we are doing multiclass classification, with 10 categories, it is natural to use 10 neurons in the output layer. We number the neurons $j = 0,1,...,9$. The activation of each output neuron $j$ will be according to the *softmax* function: \n", - "\n", - "$$ P(\\text{class $j$} \\mid \\text{input $\\boldsymbol{a}$}) = \\frac{\\exp{(\\boldsymbol{a}^T \\boldsymbol{w}_j)}}\n", - "{\\sum_{c=0}^{9} \\exp{(\\boldsymbol{a}^T \\boldsymbol{w}_c)}} ,$$ \n", - "\n", - "i.e. each neuron $j$ outputs the probability of being in class $j$ given an input from the hidden layer $\\boldsymbol{a}$, with $\\boldsymbol{w}_j$ the weights of neuron $j$ to the inputs. \n", - "The denominator is a normalization factor to ensure the outputs (probabilities) sum up to 1. \n", - "The exponent is just the weighted sum of inputs as before: \n", - "\n", - "$$ z_j = \\sum_{i=1}^n w_ {ij} a_i+b_j.$$ \n", - "\n", - "Since each neuron in the output layer is connected to the 50 inputs from the hidden layer we have 50x10 = 500\n", - "weights to the output layer." - ] - }, - { - "cell_type": "markdown", - "id": "867b3b89", - "metadata": { - "editable": true - }, - "source": [ - "## Weights and biases\n", - "\n", - "Typically weights are initialized with small values distributed around zero, drawn from a uniform\n", - "or normal distribution. Setting all weights to zero means all neurons give the same output, making the network useless. \n", - "\n", - "Adding a bias value to the weighted sum of inputs allows the neural network to represent a greater range\n", - "of values. Without it, any input with the value 0 will be mapped to zero (before being passed through the activation). The bias unit has an output of 1, and a weight to each neuron $j$, $b_j$: \n", - "\n", - "$$ z_j = \\sum_{i=1}^n w_ {ij} a_i + b_j.$$ \n", - "\n", - "The bias weights $\\boldsymbol{b}$ are often initialized to zero, but a small value like $0.01$ ensures all neurons have some output which can be backpropagated in the first training cycle." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "8ec462da", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# building our neural network\n", - "\n", - "n_inputs, n_features = X_train.shape\n", - "n_hidden_neurons = 50\n", - "n_categories = 10\n", - "\n", - "# we make the weights normally distributed using numpy.random.randn\n", - "\n", - "# weights and bias in the hidden layer\n", - "hidden_weights = np.random.randn(n_features, n_hidden_neurons)\n", - "hidden_bias = np.zeros(n_hidden_neurons) + 0.01\n", - "\n", - "# weights and bias in the output layer\n", - "output_weights = np.random.randn(n_hidden_neurons, n_categories)\n", - "output_bias = np.zeros(n_categories) + 0.01" - ] - }, - { - "cell_type": "markdown", - "id": "cf228009", - "metadata": { - "editable": true - }, - "source": [ - "## Feed-forward pass\n", - "\n", - "Denote $F$ the number of features, $H$ the number of hidden neurons and $C$ the number of categories. \n", - "For each input image we calculate a weighted sum of input features (pixel values) to each neuron $j$ in the hidden layer $l$: \n", - "\n", - "$$ z_{j}^{l} = \\sum_{i=1}^{F} w_{ij}^{l} x_i + b_{j}^{l},$$\n", - "\n", - "this is then passed through our activation function \n", - "\n", - "$$ a_{j}^{l} = f(z_{j}^{l}) .$$ \n", - "\n", - "We calculate a weighted sum of inputs (activations in the hidden layer) to each neuron $j$ in the output layer: \n", - "\n", - "$$ z_{j}^{L} = \\sum_{i=1}^{H} w_{ij}^{L} a_{i}^{l} + b_{j}^{L}.$$ \n", - "\n", - "Finally we calculate the output of neuron $j$ in the output layer using the softmax function: \n", - "\n", - "$$ a_{j}^{L} = \\frac{\\exp{(z_j^{L})}}\n", - "{\\sum_{c=0}^{C-1} \\exp{(z_c^{L})}} .$$" - ] - }, - { - "cell_type": "markdown", - "id": "c57ea8b9", - "metadata": { - "editable": true - }, - "source": [ - "## Matrix multiplications\n", - "\n", - "Since our data has the dimensions $X = (n_{inputs}, n_{features})$ and our weights to the hidden\n", - "layer have the dimensions \n", - "$W_{hidden} = (n_{features}, n_{hidden})$,\n", - "we can easily feed the network all our training data in one go by taking the matrix product \n", - "\n", - "$$ X W^{h} = (n_{inputs}, n_{hidden}),$$ \n", - "\n", - "and obtain a matrix that holds the weighted sum of inputs to the hidden layer\n", - "for each input image and each hidden neuron. \n", - "We also add the bias to obtain a matrix of weighted sums to the hidden layer $Z^{h}$: \n", - "\n", - "$$ \\boldsymbol{z}^{l} = \\boldsymbol{X} \\boldsymbol{W}^{l} + \\boldsymbol{b}^{l} ,$$\n", - "\n", - "meaning the same bias (1D array with size equal number of hidden neurons) is added to each input image. \n", - "This is then passed through the activation: \n", - "\n", - "$$ \\boldsymbol{a}^{l} = f(\\boldsymbol{z}^l) .$$ \n", - "\n", - "This is fed to the output layer: \n", - "\n", - "$$ \\boldsymbol{z}^{L} = \\boldsymbol{a}^{L} \\boldsymbol{W}^{L} + \\boldsymbol{b}^{L} .$$\n", - "\n", - "Finally we receive our output values for each image and each category by passing it through the softmax function: \n", - "\n", - "$$ output = softmax (\\boldsymbol{z}^{L}) = (n_{inputs}, n_{categories}) .$$" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "9c286c15", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "probabilities = (n_inputs, n_categories) = (1437, 10)\n", - "probability that image 0 is in category 0,1,2,...,9 = \n", - "[5.41511965e-04 2.17174962e-03 8.84355903e-03 1.44970586e-03\n", - " 1.10378326e-04 5.08318298e-09 2.03256632e-04 1.92507116e-03\n", - " 9.84443254e-01 3.11507992e-04]\n", - "probabilities sum up to: 1.0\n", - "\n", - "predictions = (n_inputs) = (1437,)\n", - "prediction for image 0: 8\n", - "correct label for image 0: 6\n" - ] - } - ], - "source": [ - "# setup the feed-forward pass, subscript h = hidden layer\n", - "\n", - "def sigmoid(x):\n", - " return 1/(1 + np.exp(-x))\n", - "\n", - "def feed_forward(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " \n", - " return probabilities\n", - "\n", - "probabilities = feed_forward(X_train)\n", - "print(\"probabilities = (n_inputs, n_categories) = \" + str(probabilities.shape))\n", - "print(\"probability that image 0 is in category 0,1,2,...,9 = \\n\" + str(probabilities[0]))\n", - "print(\"probabilities sum up to: \" + str(probabilities[0].sum()))\n", - "print()\n", - "\n", - "# we obtain a prediction by taking the class with the highest likelihood\n", - "def predict(X):\n", - " probabilities = feed_forward(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - "predictions = predict(X_train)\n", - "print(\"predictions = (n_inputs) = \" + str(predictions.shape))\n", - "print(\"prediction for image 0: \" + str(predictions[0]))\n", - "print(\"correct label for image 0: \" + str(Y_train[0]))" - ] - }, - { - "cell_type": "markdown", - "id": "a6cf75c3", - "metadata": { - "editable": true - }, - "source": [ - "## Choose cost function and optimizer\n", - "\n", - "To measure how well our neural network is doing we need to introduce a cost function. \n", - "We will call the function that gives the error of a single sample output the *loss* function, and the function\n", - "that gives the total error of our network across all samples the *cost* function.\n", - "A typical choice for multiclass classification is the *cross-entropy* loss, also known as the negative log likelihood. \n", - "\n", - "In *multiclass* classification it is common to treat each integer label as a so called *one-hot* vector: \n", - "\n", - "$$ y = 5 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,$$ \n", - "\n", - "$$ y = 1 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,$$ \n", - "\n", - "i.e. a binary bit string of length $C$, where $C = 10$ is the number of classes in the MNIST dataset. \n", - "\n", - "Let $y_{ic}$ denote the $c$-th component of the $i$-th one-hot vector. \n", - "We define the cost function $\\mathcal{C}$ as a sum over the cross-entropy loss for each point $\\boldsymbol{x}_i$ in the dataset.\n", - "\n", - "In the one-hot representation only one of the terms in the loss function is non-zero, namely the\n", - "probability of the correct category $c'$ \n", - "(i.e. the category $c'$ such that $y_{ic'} = 1$). This means that the cross entropy loss only punishes you for how wrong\n", - "you got the correct label. The probability of category $c$ is given by the softmax function. The vector $\\boldsymbol{\\theta}$ represents the parameters of our network, i.e. all the weights and biases." - ] - }, - { - "cell_type": "markdown", - "id": "e69ffdc8", - "metadata": { - "editable": true - }, - "source": [ - "## Optimizing the cost function\n", - "\n", - "The network is trained by finding the weights and biases that minimize the cost function. One of the most widely used classes of methods is *gradient descent* and its generalizations. The idea behind gradient descent\n", - "is simply to adjust the weights in the direction where the gradient of the cost function is large and negative. This ensures we flow toward a *local* minimum of the cost function. \n", - "Each parameter $\\theta$ is iteratively adjusted according to the rule \n", - "\n", - "$$ \\theta_{i+1} = \\theta_i - \\eta \\nabla \\mathcal{C}(\\theta_i) ,$$\n", - "\n", - "where $\\eta$ is known as the *learning rate*, which controls how big a step we take towards the minimum. \n", - "This update can be repeated for any number of iterations, or until we are satisfied with the result. \n", - "\n", - "A simple and effective improvement is a variant called *Batch Gradient Descent*. \n", - "Instead of calculating the gradient on the whole dataset, we calculate an approximation of the gradient\n", - "on a subset of the data called a *minibatch*. \n", - "If there are $N$ data points and we have a minibatch size of $M$, the total number of batches\n", - "is $N/M$. \n", - "We denote each minibatch $B_k$, with $k = 1, 2,...,N/M$. The gradient then becomes: \n", - "\n", - "$$ \\nabla \\mathcal{C}(\\theta) = \\frac{1}{N} \\sum_{i=1}^N \\nabla \\mathcal{L}_i(\\theta) \\quad \\rightarrow \\quad\n", - "\\frac{1}{M} \\sum_{i \\in B_k} \\nabla \\mathcal{L}_i(\\theta) ,$$\n", - "\n", - "i.e. instead of averaging the loss over the entire dataset, we average over a minibatch. \n", - "\n", - "This has two important benefits: \n", - "1. Introducing stochasticity decreases the chance that the algorithm becomes stuck in a local minima. \n", - "\n", - "2. It significantly speeds up the calculation, since we do not have to use the entire dataset to calculate the gradient. \n", - "\n", - "The various optmization methods, with codes and algorithms, are discussed in our lectures on [Gradient descent approaches](https://compphysics.github.io/MachineLearning/doc/pub/Splines/html/Splines-bs.html)." - ] - }, - { - "cell_type": "markdown", - "id": "ef19d1e0", - "metadata": { - "editable": true - }, - "source": [ - "## Regularization\n", - "\n", - "It is common to add an extra term to the cost function, proportional\n", - "to the size of the weights. This is equivalent to constraining the\n", - "size of the weights, so that they do not grow out of control.\n", - "Constraining the size of the weights means that the weights cannot\n", - "grow arbitrarily large to fit the training data, and in this way\n", - "reduces *overfitting*.\n", - "\n", - "We will measure the size of the weights using the so called *L2-norm*, meaning our cost function becomes: \n", - "\n", - "$$ \\mathcal{C}(\\theta) = \\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}_i(\\theta) \\quad \\rightarrow \\quad\n", - "\\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}_i(\\theta) + \\lambda \\lvert \\lvert \\boldsymbol{w} \\rvert \\rvert_2^2 \n", - "= \\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}(\\theta) + \\lambda \\sum_{ij} w_{ij}^2,$$ \n", + "## Which activation function should we use?\n", "\n", - "i.e. we sum up all the weights squared. The factor $\\lambda$ is known as a regularization parameter.\n", + "In general it seems that the ELU activation function is better than\n", + "the leaky ReLU function (and its variants), which is better than\n", + "ReLU. ReLU performs better than $\\tanh$ which in turn performs better\n", + "than the logistic function.\n", "\n", - "In order to train the model, we need to calculate the derivative of\n", - "the cost function with respect to every bias and weight in the\n", - "network. In total our network has $(64 + 1)\\times 50=3250$ weights in\n", - "the hidden layer and $(50 + 1)\\times 10=510$ weights to the output\n", - "layer ($+1$ for the bias), and the gradient must be calculated for\n", - "every parameter. We use the *backpropagation* algorithm discussed\n", - "above. This is a clever use of the chain rule that allows us to\n", - "calculate the gradient efficently." + "If runtime performance is an issue, then you may opt for the leaky\n", + "ReLU function over the ELU function If you don’t want to tweak yet\n", + "another hyperparameter, you may just use the default $\\alpha$ of\n", + "$0.01$ for the leaky ReLU, and $1$ for ELU. If you have spare time and\n", + "computing power, you can use cross-validation or bootstrap to evaluate\n", + "other activation functions." ] }, { "cell_type": "markdown", - "id": "d93c5dfb", - "metadata": { - "editable": true - }, - "source": [ - "## Matrix multiplication\n", - "\n", - "To more efficently train our network these equations are implemented using matrix operations. \n", - "The error in the output layer is calculated simply as, with $\\boldsymbol{t}$ being our targets, \n", - "\n", - "$$ \\delta_L = \\boldsymbol{t} - \\boldsymbol{y} = (n_{inputs}, n_{categories}) .$$ \n", - "\n", - "The gradient for the output weights is calculated as \n", - "\n", - "$$ \\nabla W_{L} = \\boldsymbol{a}^T \\delta_L = (n_{hidden}, n_{categories}) ,$$\n", - "\n", - "where $\\boldsymbol{a} = (n_{inputs}, n_{hidden})$. This simply means that we are summing up the gradients for each input. \n", - "Since we are going backwards we have to transpose the activation matrix. \n", - "\n", - "The gradient with respect to the output bias is then \n", - "\n", - "$$ \\nabla \\boldsymbol{b}_{L} = \\sum_{i=1}^{n_{inputs}} \\delta_L = (n_{categories}) .$$ \n", - "\n", - "The error in the hidden layer is \n", - "\n", - "$$ \\Delta_h = \\delta_L W_{L}^T \\circ f'(z_{h}) = \\delta_L W_{L}^T \\circ a_{h} \\circ (1 - a_{h}) = (n_{inputs}, n_{hidden}) ,$$ \n", - "\n", - "where $f'(a_{h})$ is the derivative of the activation in the hidden layer. The matrix products mean\n", - "that we are summing up the products for each neuron in the output layer. The symbol $\\circ$ denotes\n", - "the *Hadamard product*, meaning element-wise multiplication. \n", - "\n", - "This again gives us the gradients in the hidden layer: \n", - "\n", - "$$ \\nabla W_{h} = X^T \\delta_h = (n_{features}, n_{hidden}) ,$$ \n", - "\n", - "$$ \\nabla b_{h} = \\sum_{i=1}^{n_{inputs}} \\delta_h = (n_{hidden}) .$$" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "0a62b82a", + "id": "edb42800", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Old accuracy on training data: 0.1440501043841336\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "New accuracy on training data: 0.09951287404314545\n" - ] - } - ], "source": [ - "# to categorical turns our integer vector into a onehot representation\n", - "from sklearn.metrics import accuracy_score\n", + "## More on activation functions, output layers\n", "\n", - "# one-hot in numpy\n", - "def to_categorical_numpy(integer_vector):\n", - " n_inputs = len(integer_vector)\n", - " n_categories = np.max(integer_vector) + 1\n", - " onehot_vector = np.zeros((n_inputs, n_categories))\n", - " onehot_vector[range(n_inputs), integer_vector] = 1\n", - " \n", - " return onehot_vector\n", + "In most cases you can use the ReLU activation function in the hidden\n", + "layers (or one of its variants).\n", "\n", - "#Y_train_onehot, Y_test_onehot = to_categorical(Y_train), to_categorical(Y_test)\n", - "Y_train_onehot, Y_test_onehot = to_categorical_numpy(Y_train), to_categorical_numpy(Y_test)\n", + "It is a bit faster to compute than other activation functions, and the\n", + "gradient descent optimization does in general not get stuck.\n", "\n", - "def feed_forward_train(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " \n", - " # for backpropagation need activations in hidden and output layers\n", - " return a_h, probabilities\n", + "**For the output layer:**\n", "\n", - "def backpropagation(X, Y):\n", - " a_h, probabilities = feed_forward_train(X)\n", - " \n", - " # error in the output layer\n", - " error_output = probabilities - Y\n", - " # error in the hidden layer\n", - " error_hidden = np.matmul(error_output, output_weights.T) * a_h * (1 - a_h)\n", - " \n", - " # gradients for the output layer\n", - " output_weights_gradient = np.matmul(a_h.T, error_output)\n", - " output_bias_gradient = np.sum(error_output, axis=0)\n", - " \n", - " # gradient for the hidden layer\n", - " hidden_weights_gradient = np.matmul(X.T, error_hidden)\n", - " hidden_bias_gradient = np.sum(error_hidden, axis=0)\n", + "* For classification the softmax activation function is generally a good choice for classification tasks (when the classes are mutually exclusive).\n", "\n", - " return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient\n", - "\n", - "print(\"Old accuracy on training data: \" + str(accuracy_score(predict(X_train), Y_train)))\n", - "\n", - "eta = 0.01\n", - "lmbd = 0.01\n", - "for i in range(1000):\n", - " # calculate gradients\n", - " dWo, dBo, dWh, dBh = backpropagation(X_train, Y_train_onehot)\n", - " \n", - " # regularization term gradients\n", - " dWo += lmbd * output_weights\n", - " dWh += lmbd * hidden_weights\n", - " \n", - " # update weights and biases\n", - " output_weights -= eta * dWo\n", - " output_bias -= eta * dBo\n", - " hidden_weights -= eta * dWh\n", - " hidden_bias -= eta * dBh\n", - "\n", - "print(\"New accuracy on training data: \" + str(accuracy_score(predict(X_train), Y_train)))" + "* For regression tasks, you can simply use no activation function at all." ] }, { "cell_type": "markdown", - "id": "b666f091", + "id": "1a8fafc0", "metadata": { "editable": true }, "source": [ - "## Improving performance\n", - "\n", - "As we can see the network does not seem to be learning at all. It seems to be just guessing the label for each image. \n", - "In order to obtain a network that does something useful, we will have to do a bit more work. \n", + "## Batch Normalization\n", "\n", - "The choice of *hyperparameters* such as learning rate and regularization parameter is hugely influential for the performance of the network. Typically a *grid-search* is performed, wherein we test different hyperparameters separated by orders of magnitude. For example we could test the learning rates $\\eta = 10^{-6}, 10^{-5},...,10^{-1}$ with different regularization parameters $\\lambda = 10^{-6},...,10^{-0}$. \n", + "Batch Normalization aims to address the vanishing/exploding gradients\n", + "problems, and more generally the problem that the distribution of each\n", + "layer’s inputs changes during training, as the parameters of the\n", + "previous layers change.\n", "\n", - "Next, we haven't implemented minibatching yet, which introduces stochasticity and is though to act as an important regularizer on the weights. We call a feed-forward + backward pass with a minibatch an *iteration*, and a full training period\n", - "going through the entire dataset ($n/M$ batches) an *epoch*.\n", - "\n", - "If this does not improve network performance, you may want to consider altering the network architecture, adding more neurons or hidden layers. \n", - "Andrew Ng goes through some of these considerations in this [video](https://youtu.be/F1ka6a13S9I). You can find a summary of the video [here](https://kevinzakka.github.io/2016/09/26/applying-deep-learning/)." + "The technique consists of adding an operation in the model just before\n", + "the activation function of each layer, simply zero-centering and\n", + "normalizing the inputs, then scaling and shifting the result using two\n", + "new parameters per layer (one for scaling, the other for shifting). In\n", + "other words, this operation lets the model learn the optimal scale and\n", + "mean of the inputs for each layer. In order to zero-center and\n", + "normalize the inputs, the algorithm needs to estimate the inputs’ mean\n", + "and standard deviation. It does so by evaluating the mean and standard\n", + "deviation of the inputs over the current mini-batch, from this the\n", + "name batch normalization." ] }, { "cell_type": "markdown", - "id": "79055893", - "metadata": { - "editable": true - }, - "source": [ - "## Full object-oriented implementation\n", - "\n", - "It is very natural to think of the network as an object, with specific instances of the network\n", - "being realizations of this object with different hyperparameters. An implementation using Python classes provides a clean structure and interface, and the full implementation of our neural network is given below." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "85af4a1c", + "id": "feef1d4d", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "class NeuralNetwork:\n", - " def __init__(\n", - " self,\n", - " X_data,\n", - " Y_data,\n", - " n_hidden_neurons=50,\n", - " n_categories=10,\n", - " epochs=10,\n", - " batch_size=100,\n", - " eta=0.1,\n", - " lmbd=0.0):\n", - "\n", - " self.X_data_full = X_data\n", - " self.Y_data_full = Y_data\n", - "\n", - " self.n_inputs = X_data.shape[0]\n", - " self.n_features = X_data.shape[1]\n", - " self.n_hidden_neurons = n_hidden_neurons\n", - " self.n_categories = n_categories\n", - "\n", - " self.epochs = epochs\n", - " self.batch_size = batch_size\n", - " self.iterations = self.n_inputs // self.batch_size\n", - " self.eta = eta\n", - " self.lmbd = lmbd\n", - "\n", - " self.create_biases_and_weights()\n", - "\n", - " def create_biases_and_weights(self):\n", - " self.hidden_weights = np.random.randn(self.n_features, self.n_hidden_neurons)\n", - " self.hidden_bias = np.zeros(self.n_hidden_neurons) + 0.01\n", - "\n", - " self.output_weights = np.random.randn(self.n_hidden_neurons, self.n_categories)\n", - " self.output_bias = np.zeros(self.n_categories) + 0.01\n", - "\n", - " def feed_forward(self):\n", - " # feed-forward for training\n", - " self.z_h = np.matmul(self.X_data, self.hidden_weights) + self.hidden_bias\n", - " self.a_h = sigmoid(self.z_h)\n", - "\n", - " self.z_o = np.matmul(self.a_h, self.output_weights) + self.output_bias\n", - "\n", - " exp_term = np.exp(self.z_o)\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - "\n", - " def feed_forward_out(self, X):\n", - " # feed-forward for output\n", - " z_h = np.matmul(X, self.hidden_weights) + self.hidden_bias\n", - " a_h = sigmoid(z_h)\n", - "\n", - " z_o = np.matmul(a_h, self.output_weights) + self.output_bias\n", - " \n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " return probabilities\n", + "## Dropout\n", "\n", - " def backpropagation(self):\n", - " error_output = self.probabilities - self.Y_data\n", - " error_hidden = np.matmul(error_output, self.output_weights.T) * self.a_h * (1 - self.a_h)\n", + "It is a fairly simple algorithm: at every training step, every neuron\n", + "(including the input neurons but excluding the output neurons) has a\n", + "probability $p$ of being temporarily dropped out, meaning it will be\n", + "entirely ignored during this training step, but it may be active\n", + "during the next step.\n", "\n", - " self.output_weights_gradient = np.matmul(self.a_h.T, error_output)\n", - " self.output_bias_gradient = np.sum(error_output, axis=0)\n", - "\n", - " self.hidden_weights_gradient = np.matmul(self.X_data.T, error_hidden)\n", - " self.hidden_bias_gradient = np.sum(error_hidden, axis=0)\n", - "\n", - " if self.lmbd > 0.0:\n", - " self.output_weights_gradient += self.lmbd * self.output_weights\n", - " self.hidden_weights_gradient += self.lmbd * self.hidden_weights\n", - "\n", - " self.output_weights -= self.eta * self.output_weights_gradient\n", - " self.output_bias -= self.eta * self.output_bias_gradient\n", - " self.hidden_weights -= self.eta * self.hidden_weights_gradient\n", - " self.hidden_bias -= self.eta * self.hidden_bias_gradient\n", - "\n", - " def predict(self, X):\n", - " probabilities = self.feed_forward_out(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - " def predict_probabilities(self, X):\n", - " probabilities = self.feed_forward_out(X)\n", - " return probabilities\n", - "\n", - " def train(self):\n", - " data_indices = np.arange(self.n_inputs)\n", - "\n", - " for i in range(self.epochs):\n", - " for j in range(self.iterations):\n", - " # pick datapoints with replacement\n", - " chosen_datapoints = np.random.choice(\n", - " data_indices, size=self.batch_size, replace=False\n", - " )\n", - "\n", - " # minibatch training data\n", - " self.X_data = self.X_data_full[chosen_datapoints]\n", - " self.Y_data = self.Y_data_full[chosen_datapoints]\n", - "\n", - " self.feed_forward()\n", - " self.backpropagation()" + "The hyperparameter $p$ is called the dropout rate, and it is typically\n", + "set to 50%. After training, the neurons are not dropped anymore. It\n", + "is viewed as one of the most popular regularization techniques." ] }, { "cell_type": "markdown", - "id": "d0ef37e8", - "metadata": { - "editable": true - }, - "source": [ - "## Evaluate model performance on test data\n", - "\n", - "To measure the performance of our network we evaluate how well it does it data it has never seen before, i.e. the test data. \n", - "We measure the performance of the network using the *accuracy* score. \n", - "The accuracy is as you would expect just the number of images correctly labeled divided by the total number of images. A perfect classifier will have an accuracy score of $1$. \n", - "\n", - "$$ \\text{Accuracy} = \\frac{\\sum_{i=1}^n I(\\tilde{y}_i = y_i)}{n} ,$$ \n", - "\n", - "where $I$ is the indicator function, $1$ if $\\tilde{y}_i = y_i$ and $0$ otherwise." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "d2891643", + "id": "9428c225", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Accuracy score on test set: 0.9444444444444444\n" - ] - } - ], "source": [ - "epochs = 100\n", - "batch_size = 100\n", - "\n", - "dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,\n", - " n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)\n", - "dnn.train()\n", - "test_predict = dnn.predict(X_test)\n", + "## Gradient Clipping\n", "\n", - "# accuracy score from scikit library\n", - "print(\"Accuracy score on test set: \", accuracy_score(Y_test, test_predict))\n", - "\n", - "# equivalent in numpy\n", - "def accuracy_score_numpy(Y_test, Y_pred):\n", - " return np.sum(Y_test == Y_pred) / len(Y_test)\n", - "\n", - "#print(\"Accuracy score on test set: \", accuracy_score_numpy(Y_test, test_predict))" - ] - }, - { - "cell_type": "markdown", - "id": "5c91c8fc", - "metadata": { - "editable": true - }, - "source": [ - "## Adjust hyperparameters\n", + "A popular technique to lessen the exploding gradients problem is to\n", + "simply clip the gradients during backpropagation so that they never\n", + "exceed some threshold (this is mostly useful for recurrent neural\n", + "networks).\n", "\n", - "We now perform a grid search to find the optimal hyperparameters for the network. \n", - "Note that we are only using 1 layer with 50 neurons, and human performance is estimated to be around $98\\%$ ($2\\%$ error rate)." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "c245d23d", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1e-05\n", - "Lambda = 1e-05\n", - "Accuracy score on test set: 0.11666666666666667\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1e-05\n", - "Lambda = 0.0001\n", - "Accuracy score on test set: 0.20833333333333334\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1e-05\n", - "Lambda = 0.001\n", - "Accuracy score on test set: 0.12222222222222222\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1e-05\n", - "Lambda = 0.01\n", - "Accuracy score on test set: 0.14722222222222223\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1e-05\n", - "Lambda = 0.1\n", - "Accuracy score on test set: 0.17777777777777778\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1e-05\n", - "Lambda = 1.0\n", - "Accuracy score on test set: 0.16111111111111112\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1e-05\n", - "Lambda = 10.0\n", - "Accuracy score on test set: 0.20277777777777778\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.0001\n", - "Lambda = 1e-05\n", - "Accuracy score on test set: 0.5305555555555556\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.0001\n", - "Lambda = 0.0001\n", - "Accuracy score on test set: 0.5944444444444444\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.0001\n", - "Lambda = 0.001\n", - "Accuracy score on test set: 0.5888888888888889\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.0001\n", - "Lambda = 0.01\n", - "Accuracy score on test set: 0.6111111111111112\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.0001\n", - "Lambda = 0.1\n", - "Accuracy score on test set: 0.5222222222222223\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.0001\n", - "Lambda = 1.0\n", - "Accuracy score on test set: 0.5555555555555556\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.0001\n", - "Lambda = 10.0\n", - "Accuracy score on test set: 0.8055555555555556\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.001\n", - "Lambda = 1e-05\n", - "Accuracy score on test set: 0.85\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.001\n", - "Lambda = 0.0001\n", - "Accuracy score on test set: 0.85\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.001\n", - "Lambda = 0.001\n", - "Accuracy score on test set: 0.875\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.001\n", - "Lambda = 0.01\n", - "Accuracy score on test set: 0.8666666666666667\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.001\n", - "Lambda = 0.1\n", - "Accuracy score on test set: 0.8638888888888889\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.001\n", - "Lambda = 1.0\n", - "Accuracy score on test set: 0.9555555555555556\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.001\n", - "Lambda = 10.0\n", - "Accuracy score on test set: 0.925\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.01\n", - "Lambda = 1e-05\n", - "Accuracy score on test set: 0.9472222222222222\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.01\n", - "Lambda = 0.0001\n", - "Accuracy score on test set: 0.9277777777777778\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.01\n", - "Lambda = 0.001\n", - "Accuracy score on test set: 0.9472222222222222\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.01\n", - "Lambda = 0.01\n", - "Accuracy score on test set: 0.9305555555555556\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.01\n", - "Lambda = 0.1\n", - "Accuracy score on test set: 0.9555555555555556\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.01\n", - "Lambda = 1.0\n", - "Accuracy score on test set: 0.7694444444444445\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.01\n", - "Lambda = 10.0\n", - "Accuracy score on test set: 0.19166666666666668\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.1\n", - "Lambda = 1e-05\n", - "Accuracy score on test set: 0.10555555555555556\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.1\n", - "Lambda = 0.0001\n", - "Accuracy score on test set: 0.08611111111111111\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.1\n", - "Lambda = 0.001\n", - "Accuracy score on test set: 0.10555555555555556\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.1\n", - "Lambda = 0.01\n", - "Accuracy score on test set: 0.08888888888888889\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.1\n", - "Lambda = 0.1\n", - "Accuracy score on test set: 0.08611111111111111\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.1\n", - "Lambda = 1.0\n", - "Accuracy score on test set: 0.08888888888888889\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 0.1\n", - "Lambda = 10.0\n", - "Accuracy score on test set: 0.09166666666666666\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1.0\n", - "Lambda = 1e-05\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1.0\n", - "Lambda = 0.0001\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1.0\n", - "Lambda = 0.001\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1.0\n", - "Lambda = 0.01\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1.0\n", - "Lambda = 0.1\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1.0\n", - "Lambda = 1.0\n", - "Accuracy score on test set: 0.10555555555555556\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 1.0\n", - "Lambda = 10.0\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 10.0\n", - "Lambda = 1e-05\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 10.0\n", - "Lambda = 0.0001\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 10.0\n", - "Lambda = 0.001\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Learning rate = 10.0\n", - "Lambda = 0.01\n", - "Accuracy score on test set: 0.07777777777777778\n", - "\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/953065564.py:4: RuntimeWarning: overflow encountered in exp\n", - " return 1/(1 + np.exp(-x))\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:43: RuntimeWarning: overflow encountered in exp\n", - " exp_term = np.exp(self.z_o)\n", - "/var/folders/td/3yk470mj5p931p9dtkk0y6jw0000gn/T/ipykernel_12588/1630775253.py:44: RuntimeWarning: invalid value encountered in true_divide\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n" - ] - }, - { - "ename": "KeyboardInterrupt", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[12], line 11\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m j, lmbd \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(lmbd_vals):\n\u001b[1;32m 9\u001b[0m dnn \u001b[38;5;241m=\u001b[39m NeuralNetwork(X_train, Y_train_onehot, eta\u001b[38;5;241m=\u001b[39meta, lmbd\u001b[38;5;241m=\u001b[39mlmbd, epochs\u001b[38;5;241m=\u001b[39mepochs, batch_size\u001b[38;5;241m=\u001b[39mbatch_size,\n\u001b[1;32m 10\u001b[0m n_hidden_neurons\u001b[38;5;241m=\u001b[39mn_hidden_neurons, n_categories\u001b[38;5;241m=\u001b[39mn_categories)\n\u001b[0;32m---> 11\u001b[0m \u001b[43mdnn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtrain\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 13\u001b[0m DNN_numpy[i][j] \u001b[38;5;241m=\u001b[39m dnn\n\u001b[1;32m 15\u001b[0m test_predict \u001b[38;5;241m=\u001b[39m dnn\u001b[38;5;241m.\u001b[39mpredict(X_test)\n", - "Cell \u001b[0;32mIn[10], line 99\u001b[0m, in \u001b[0;36mNeuralNetwork.train\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mY_data \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mY_data_full[chosen_datapoints]\n\u001b[1;32m 98\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfeed_forward()\n\u001b[0;32m---> 99\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackpropagation\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "Cell \u001b[0;32mIn[10], line 64\u001b[0m, in \u001b[0;36mNeuralNetwork.backpropagation\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 61\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_weights_gradient \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mmatmul(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39ma_h\u001b[38;5;241m.\u001b[39mT, error_output)\n\u001b[1;32m 62\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_bias_gradient \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39msum(error_output, axis\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m)\n\u001b[0;32m---> 64\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhidden_weights_gradient \u001b[38;5;241m=\u001b[39m \u001b[43mnp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmatmul\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mX_data\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mT\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43merror_hidden\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 65\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhidden_bias_gradient \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39msum(error_hidden, axis\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m)\n\u001b[1;32m 67\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlmbd \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0.0\u001b[39m:\n", - "\u001b[0;31mKeyboardInterrupt\u001b[0m: " - ] - } - ], - "source": [ - "eta_vals = np.logspace(-5, 1, 7)\n", - "lmbd_vals = np.logspace(-5, 1, 7)\n", - "# store the models for later use\n", - "DNN_numpy = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", + "This technique is called Gradient Clipping.\n", "\n", - "# grid search\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,\n", - " n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)\n", - " dnn.train()\n", - " \n", - " DNN_numpy[i][j] = dnn\n", - " \n", - " test_predict = dnn.predict(X_test)\n", - " \n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on test set: \", accuracy_score(Y_test, test_predict))\n", - " print()" + "In general however, Batch\n", + "Normalization is preferred." ] }, { "cell_type": "markdown", - "id": "ea3be61a", - "metadata": { - "editable": true - }, - "source": [ - "## Visualization" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "d26e1748", + "id": "504b21ae", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "# visual representation of grid search\n", - "# uses seaborn heatmap, you can also do this with matplotlib imshow\n", - "import seaborn as sns\n", - "\n", - "sns.set()\n", - "\n", - "train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_numpy[i][j]\n", - " \n", - " train_pred = dnn.predict(X_train) \n", - " test_pred = dnn.predict(X_test)\n", - "\n", - " train_accuracy[i][j] = accuracy_score(Y_train, train_pred)\n", - " test_accuracy[i][j] = accuracy_score(Y_test, test_pred)\n", + "## A top-down perspective on Neural networks\n", "\n", - " \n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Training Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()\n", + "The first thing we would like to do is divide the data into two or\n", + "three parts. A training set, a validation or dev (development) set,\n", + "and a test set. The test set is the data on which we want to make\n", + "predictions. The dev set is a subset of the training data we use to\n", + "check how well we are doing out-of-sample, after training the model on\n", + "the training dataset. We use the validation error as a proxy for the\n", + "test error in order to make tweaks to our model. It is crucial that we\n", + "do not use any of the test data to train the algorithm. This is a\n", + "cardinal sin in ML. Then:\n", "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "572f3f4b", - "metadata": { - "editable": true - }, - "source": [ - "## scikit-learn implementation\n", + "1. Estimate optimal error rate\n", "\n", - "**scikit-learn** focuses more\n", - "on traditional machine learning methods, such as regression,\n", - "clustering, decision trees, etc. As such, it has only two types of\n", - "neural networks: Multi Layer Perceptron outputting continuous values,\n", - "*MPLRegressor*, and Multi Layer Perceptron outputting labels,\n", - "*MLPClassifier*. We will see how simple it is to use these classes.\n", - "\n", - "**scikit-learn** implements a few improvements from our neural network,\n", - "such as early stopping, a varying learning rate, different\n", - "optimization methods, etc. We would therefore expect a better\n", - "performance overall." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "fdb38053", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "from sklearn.neural_network import MLPClassifier\n", - "# store models for later use\n", - "DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", + "2. Minimize underfitting (bias) on training data set.\n", "\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic',\n", - " alpha=lmbd, learning_rate_init=eta, max_iter=epochs)\n", - " dnn.fit(X_train, Y_train)\n", - " \n", - " DNN_scikit[i][j] = dnn\n", - " \n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on test set: \", dnn.score(X_test, Y_test))\n", - " print()" + "3. Make sure you are not overfitting." ] }, { "cell_type": "markdown", - "id": "5fc3dd13", + "id": "c51837a9", "metadata": { "editable": true }, "source": [ - "## Visualization" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "cd9e4505", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# optional\n", - "# visual representation of grid search\n", - "# uses seaborn heatmap, could probably do this in matplotlib\n", - "import seaborn as sns\n", - "\n", - "sns.set()\n", + "## More top-down perspectives\n", "\n", - "train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", + "If the validation and test sets are drawn from the same distributions,\n", + "then a good performance on the validation set should lead to similarly\n", + "good performance on the test set. \n", "\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_scikit[i][j]\n", - " \n", - " train_pred = dnn.predict(X_train) \n", - " test_pred = dnn.predict(X_test)\n", - "\n", - " train_accuracy[i][j] = accuracy_score(Y_train, train_pred)\n", - " test_accuracy[i][j] = accuracy_score(Y_test, test_pred)\n", - "\n", - " \n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Training Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()\n", - "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" + "However, sometimes\n", + "the training data and test data differ in subtle ways because, for\n", + "example, they are collected using slightly different methods, or\n", + "because it is cheaper to collect data in one way versus another. In\n", + "this case, there can be a mismatch between the training and test\n", + "data. This can lead to the neural network overfitting these small\n", + "differences between the test and training sets, and a poor performance\n", + "on the test set despite having a good performance on the validation\n", + "set. To rectify this, Andrew Ng suggests making two validation or dev\n", + "sets, one constructed from the training data and one constructed from\n", + "the test data. The difference between the performance of the algorithm\n", + "on these two validation sets quantifies the train-test mismatch. This\n", + "can serve as another important diagnostic when using DNNs for\n", + "supervised learning." ] }, { "cell_type": "markdown", - "id": "30d61094", + "id": "a7357657", "metadata": { "editable": true }, "source": [ - "## Testing our code for the XOR, OR and AND gates\n", - "\n", - "Last week we discussed three different types of gates, the so-called\n", - "XOR, the OR and the AND gates. Their inputs and outputs can be\n", - "summarized using the following tables, first for the OR gate with\n", - "inputs $x_1$ and $x_2$ and outputs $y$:\n", + "## Limitations of supervised learning with deep networks\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 1
    1 0 1
    1 1 1
    " + "Like all statistical methods, supervised learning using neural\n", + "networks has important limitations. This is especially important when\n", + "one seeks to apply these methods, especially to physics problems. Like\n", + "all tools, DNNs are not a universal solution. Often, the same or\n", + "better performance on a task can be achieved by using a few\n", + "hand-engineered features (or even a collection of random\n", + "features)." ] }, { "cell_type": "markdown", - "id": "9b4cd63f", + "id": "e92c8a84", "metadata": { "editable": true }, "source": [ - "## The AND and XOR Gates\n", + "## Limitations of NNs\n", "\n", - "The AND gate is defined as\n", + "Here we list some of the important limitations of supervised neural network based models. \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 0
    1 0 0
    1 1 1
    \n", - "\n", - "And finally we have the XOR gate\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 1
    1 0 1
    1 1 0
    " - ] - }, - { - "cell_type": "markdown", - "id": "1a2bd6f1", - "metadata": { - "editable": true - }, - "source": [ - "## Representing the Data Sets\n", + "* **Need labeled data**. All supervised learning methods, DNNs for supervised learning require labeled data. Often, labeled data is harder to acquire than unlabeled data (e.g. one must pay for human experts to label images).\n", "\n", - "Our design matrix is defined by the input values $x_1$ and $x_2$. Since we have four possible outputs, our design matrix reads" - ] - }, - { - "cell_type": "markdown", - "id": "a569e669", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\boldsymbol{X}=\\begin{bmatrix} 0 & 0 \\\\\n", - " 0 & 1 \\\\\n", - "\t\t 1 & 0 \\\\\n", - "\t\t 1 & 1 \\end{bmatrix},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "51363b82", - "metadata": { - "editable": true - }, - "source": [ - "while the vector of outputs is $\\boldsymbol{y}^T=[0,1,1,0]$ for the XOR gate, $\\boldsymbol{y}^T=[0,0,0,1]$ for the AND gate and $\\boldsymbol{y}^T=[0,1,1,1]$ for the OR gate." + "* **Supervised neural networks are extremely data intensive.** DNNs are data hungry. They perform best when data is plentiful. This is doubly so for supervised methods where the data must also be labeled. The utility of DNNs is extremely limited if data is hard to acquire or the datasets are small (hundreds to a few thousand samples). In this case, the performance of other methods that utilize hand-engineered features can exceed that of DNNs." ] }, { "cell_type": "markdown", - "id": "e4172d21", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Neural Network\n", - "\n", - "We define first our design matrix and the various output vectors for the different gates." - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "b8640651", + "id": "793aee7d", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "\"\"\"\n", - "Simple code that tests XOR, OR and AND gates with linear regression\n", - "\"\"\"\n", - "\n", - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn import datasets\n", - "\n", - "def sigmoid(x):\n", - " return 1/(1 + np.exp(-x))\n", + "## Homogeneous data\n", "\n", - "def feed_forward(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " probabilities = sigmoid(z_o)\n", - " return probabilities\n", - "\n", - "# we obtain a prediction by taking the class with the highest likelihood\n", - "def predict(X):\n", - " probabilities = feed_forward(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# Design matrix\n", - "X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64)\n", - "\n", - "# The XOR gate\n", - "yXOR = np.array( [ 0, 1 ,1, 0])\n", - "# The OR gate\n", - "yOR = np.array( [ 0, 1 ,1, 1])\n", - "# The AND gate\n", - "yAND = np.array( [ 0, 0 ,0, 1])\n", - "\n", - "# Defining the neural network\n", - "n_inputs, n_features = X.shape\n", - "n_hidden_neurons = 2\n", - "n_categories = 2\n", - "n_features = 2\n", - "\n", - "# we make the weights normally distributed using numpy.random.randn\n", - "\n", - "# weights and bias in the hidden layer\n", - "hidden_weights = np.random.randn(n_features, n_hidden_neurons)\n", - "hidden_bias = np.zeros(n_hidden_neurons) + 0.01\n", - "\n", - "# weights and bias in the output layer\n", - "output_weights = np.random.randn(n_hidden_neurons, n_categories)\n", - "output_bias = np.zeros(n_categories) + 0.01\n", - "\n", - "probabilities = feed_forward(X)\n", - "print(probabilities)\n", - "\n", - "\n", - "predictions = predict(X)\n", - "print(predictions)" - ] - }, - { - "cell_type": "markdown", - "id": "f6b2c036", - "metadata": { - "editable": true - }, - "source": [ - "Not an impressive result, but this was our first forward pass with randomly assigned weights. Let us now add the full network with the back-propagation algorithm discussed above." + "* **Homogeneous data.** Almost all DNNs deal with homogeneous data of one type. It is very hard to design architectures that mix and match data types (i.e. some continuous variables, some discrete variables, some time series). In applications beyond images, video, and language, this is often what is required. In contrast, ensemble models like random forests or gradient-boosted trees have no difficulty handling mixed data types." ] }, { "cell_type": "markdown", - "id": "49fdf701", - "metadata": { - "editable": true - }, - "source": [ - "## The Code using Scikit-Learn" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "45dae979", + "id": "739960d6", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn.neural_network import MLPClassifier\n", - "from sklearn.metrics import accuracy_score\n", - "import seaborn as sns\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# Design matrix\n", - "X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64)\n", - "\n", - "# The XOR gate\n", - "yXOR = np.array( [ 0, 1 ,1, 0])\n", - "# The OR gate\n", - "yOR = np.array( [ 0, 1 ,1, 1])\n", - "# The AND gate\n", - "yAND = np.array( [ 0, 0 ,0, 1])\n", - "\n", - "# Defining the neural network\n", - "n_inputs, n_features = X.shape\n", - "n_hidden_neurons = 2\n", - "n_categories = 2\n", - "n_features = 2\n", - "\n", - "eta_vals = np.logspace(-5, 1, 7)\n", - "lmbd_vals = np.logspace(-5, 1, 7)\n", - "# store models for later use\n", - "DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", - "epochs = 100\n", - "\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic',\n", - " alpha=lmbd, learning_rate_init=eta, max_iter=epochs)\n", - " dnn.fit(X, yXOR)\n", - " DNN_scikit[i][j] = dnn\n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on data set: \", dnn.score(X, yXOR))\n", - " print()\n", + "## More limitations\n", "\n", - "sns.set()\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_scikit[i][j]\n", - " test_pred = dnn.predict(X)\n", - " test_accuracy[i][j] = accuracy_score(yXOR, test_pred)\n", + "* **Many problems are not about prediction.** In natural science we are often interested in learning something about the underlying distribution that generates the data. In this case, it is often difficult to cast these ideas in a supervised learning setting. While the problems are related, it is possible to make good predictions with a *wrong* model. The model might or might not be useful for understanding the underlying science.\n", "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" + "Some of these remarks are particular to DNNs, others are shared by all supervised learning methods. This motivates the use of unsupervised methods which in part circumvent these problems." ] } ], diff --git a/doc/LectureNotes/_build/jupyter_execute/week41.py b/doc/LectureNotes/_build/jupyter_execute/week41.py index d2edf7cf2..f62db3e3a 100644 --- a/doc/LectureNotes/_build/jupyter_execute/week41.py +++ b/doc/LectureNotes/_build/jupyter_execute/week41.py @@ -347,218 +347,1285 @@ FFNN.predict_proba(X) print(f"Test set accuracy with Feed Forward Neural Network for XOR gate:{FFNN.score(X, yXOR)}") -# ## Mathematical model +# ## Mathematics of deep learning # -# The output $y$ is produced via the activation function $f$ +# **Two recent books online.** +# +# 1. [The Modern Mathematics of Deep Learning, by Julius Berner, Philipp Grohs, Gitta Kutyniok, Philipp Petersen](https://arxiv.org/abs/2105.04026), published as [Mathematical Aspects of Deep Learning, pp. 1-111. Cambridge University Press, 2022](https://doi.org/10.1017/9781009025096.002) +# +# 2. [Mathematical Introduction to Deep Learning: Methods, Implementations, and Theory, Arnulf Jentzen, Benno Kuckuck, Philippe von Wurstemberger](https://doi.org/10.48550/arXiv.2310.20360) + +# ## Reminder on books with hands-on material and codes +# * [Sebastian Rashcka et al, Machine learning with Sickit-Learn and PyTorch](https://sebastianraschka.com/blog/2022/ml-pytorch-book.html) + +# ## Reading recommendations +# +# 1. Rashkca et al., chapter 11, jupyter-notebook sent separately, from [GitHub](https://github.com/rasbt/machine-learning-book) +# +# 2. Goodfellow et al, chapter 6 and 7 contain most of the neural network background. + +# ## Mathematics of deep learning and neural networks +# +# Neural networks, in its so-called feed-forward form, where each +# iterations contains a feed-forward stage and a back-propgagation +# stage, consist of series of affine matrix-matrix and matrix-vector +# multiplications. The unknown parameters (the so-called biases and +# weights which deternine the architecture of a neural network), are +# uptaded iteratively using the so-called back-propagation algorithm. +# This algorithm corresponds to the so-called reverse mode of +# automatic differentation. + +# ## Basics of an NN +# +# A neural network consists of a series of hidden layers, in addition to +# the input and output layers. Each layer $l$ has a set of parameters +# $\boldsymbol{\Theta}^{(l)}=(\boldsymbol{W}^{(l)},\boldsymbol{b}^{(l)})$ which are related to the +# parameters in other layers through a series of affine transformations, +# for a standard NN these are matrix-matrix and matrix-vector +# multiplications. For all layers we will simply use a collective variable $\boldsymbol{\Theta}$. +# +# It consist of two basic steps: +# 1. a feed forward stage which takes a given input and produces a final output which is compared with the target values through our cost/loss function. +# +# 2. a back-propagation state where the unknown parameters $\boldsymbol{\Theta}$ are updated through the optimization of the their gradients. The expressions for the gradients are obtained via the chain rule, starting from the derivative of the cost/function. +# +# These two steps make up one iteration. This iterative process is continued till we reach an eventual stopping criterion. + +# ## Overarching view of a neural network +# +# The architecture of a neural network defines our model. This model +# aims at describing some function $f(\boldsymbol{x}$ which represents +# some final result (outputs or tagrget values) given a specific inpput +# $\boldsymbol{x}$. Note that here $\boldsymbol{y}$ and $\boldsymbol{x}$ are not limited to be +# vectors. +# +# The architecture consists of +# 1. An input and an output layer where the input layer is defined by the inputs $\boldsymbol{x}$. The output layer produces the model ouput $\boldsymbol{\tilde{y}}$ which is compared with the target value $\boldsymbol{y}$ +# +# 2. A given number of hidden layers and neurons/nodes/units for each layer (this may vary) +# +# 3. A given activation function $\sigma(\boldsymbol{z})$ with arguments $\boldsymbol{z}$ to be defined below. The activation functions may differ from layer to layer. +# +# 4. The last layer, normally called **output** layer has normally an activation function tailored to the specific problem +# +# 5. Finally we define a so-called cost or loss function which is used to gauge the quality of our model. + +# ## The optimization problem +# +# The cost function is a function of the unknown parameters +# $\boldsymbol{\Theta}$ where the latter is a container for all possible +# parameters needed to define a neural network +# +# If we are dealing with a regression task a typical cost/loss function +# is the mean squared error # $$ -# y = f\left(\sum_{i=1}^n w_ix_i + b_i\right) = f(z), +# C(\boldsymbol{\Theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}. # $$ -# This function receives $x_i$ as inputs. -# Here the activation $z=(\sum_{i=1}^n w_ix_i+b_i)$. -# In an FFNN of such neurons, the *inputs* $x_i$ are the *outputs* of -# the neurons in the preceding layer. Furthermore, an MLP is -# fully-connected, which means that each neuron receives a weighted sum -# of the outputs of *all* neurons in the previous layer. +# This function represents one of many possible ways to define +# the so-called cost function. Note that here we have assumed a linear dependence in terms of the paramters $\boldsymbol{\Theta}$. This is in general not the case. -# ## Mathematical model +# ## Parameters of neural networks +# For neural networks the parameters +# $\boldsymbol{\Theta}$ are given by the so-called weights and biases (to be +# defined below). # -# First, for each node $i$ in the first hidden layer, we calculate a weighted sum $z_i^1$ of the input coordinates $x_j$, +# The weights are given by matrix elements $w_{ij}^{(l)}$ where the +# superscript indicates the layer number. The biases are typically given +# by vector elements representing each single node of a given layer, +# that is $b_j^{(l)}$. + +# ## Other ingredients of a neural network +# +# Having defined the architecture of a neural network, the optimization +# of the cost function with respect to the parameters $\boldsymbol{\Theta}$, +# involves the calculations of gradients and their optimization. The +# gradients represent the derivatives of a multidimensional object and +# are often approximated by various gradient methods, including +# 1. various quasi-Newton methods, +# +# 2. plain gradient descent (GD) with a constant learning rate $\eta$, +# +# 3. GD with momentum and other approximations to the learning rates such as +# +# * Adapative gradient (ADAgrad) +# +# * Root mean-square propagation (RMSprop) +# +# * Adaptive gradient with momentum (ADAM) and many other +# +# 4. Stochastic gradient descent and various families of learning rate approximations + +# ## Other parameters +# +# In addition to the above, there are often additional hyperparamaters +# which are included in the setup of a neural network. These will be +# discussed below. + +# ## Universal approximation theorem +# +# The universal approximation theorem plays a central role in deep +# learning. [Cybenko (1989)](https://link.springer.com/article/10.1007/BF02551274) showed +# the following: +# +# Let $\sigma$ be any continuous sigmoidal function such that + +# $$ +# \sigma(z) = \left\{\begin{array}{cc} 1 & z\rightarrow \infty\\ 0 & z \rightarrow -\infty \end{array}\right. +# $$ + +# Given a continuous and deterministic function $F(\boldsymbol{x})$ on the unit +# cube in $d$-dimensions $F\in [0,1]^d$, $x\in [0,1]^d$ and a parameter +# $\epsilon >0$, there is a one-layer (hidden) neural network +# $f(\boldsymbol{x};\boldsymbol{\Theta})$ with $\boldsymbol{\Theta}=(\boldsymbol{W},\boldsymbol{b})$ and $\boldsymbol{W}\in +# \mathbb{R}^{m\times n}$ and $\boldsymbol{b}\in \mathbb{R}^{n}$, for which + +# $$ +# \vert F(\boldsymbol{x})-f(\boldsymbol{x};\boldsymbol{\Theta})\vert < \epsilon \hspace{0.1cm} \forall \boldsymbol{x}\in[0,1]^d. +# $$ + +# ## Some parallels from real analysis +# +# For those of you familiar with for example the [Stone-Weierstrass +# theorem](https://en.wikipedia.org/wiki/Stone%E2%80%93Weierstrass_theorem) +# for polynomial approximations or the convergence criterion for Fourier +# series, there are similarities in the derivation of the proof for +# neural networks. + +# ## The approximation theorem in words +# +# **Any continuous function $y=F(\boldsymbol{x})$ supported on the unit cube in +# $d$-dimensions can be approximated by a one-layer sigmoidal network to +# arbitrary accuracy.** +# +# [Hornik (1991)](https://www.sciencedirect.com/science/article/abs/pii/089360809190009T) extended the theorem by letting any non-constant, bounded activation function to be included using that the expectation value + +# $$ +# \mathbb{E}[\vert F(\boldsymbol{x})\vert^2] =\int_{\boldsymbol{x}\in D} \vert F(\boldsymbol{x})\vert^2p(\boldsymbol{x})d\boldsymbol{x} < \infty. +# $$ + +# Then we have + +# $$ +# \mathbb{E}[\vert F(\boldsymbol{x})-f(\boldsymbol{x};\boldsymbol{\Theta})\vert^2] =\int_{\boldsymbol{x}\in D} \vert F(\boldsymbol{x})-f(\boldsymbol{x};\boldsymbol{\Theta})\vert^2p(\boldsymbol{x})d\boldsymbol{x} < \epsilon. +# $$ + +# ## More on the general approximation theorem +# +# None of the proofs give any insight into the relation between the +# number of of hidden layers and nodes and the approximation error +# $\epsilon$, nor the magnitudes of $\boldsymbol{W}$ and $\boldsymbol{b}$. +# +# Neural networks (NNs) have what we may call a kind of universality no matter what function we want to compute. +# +# It does not mean that an NN can be used to exactly compute any function. Rather, we get an approximation that is as good as we want. + +# ## Class of functions we can approximate +# +# The class of functions that can be approximated are the continuous ones. +# If the function $F(\boldsymbol{x})$ is discontinuous, it won't in general be possible to approximate it. However, an NN may still give an approximation even if we fail in some points. + +# ## Setting up the equations for a neural network +# +# The questions we want to ask are how do changes in the biases and the +# weights in our network change the cost function and how can we use the +# final output to modify the weights and biases? +# +# To derive these equations let us start with a plain regression problem +# and define our cost function as + +# $$ +# {\cal C}(\boldsymbol{\Theta}) = \frac{1}{2}\sum_{i=1}^n\left(y_i - \tilde{y}_i\right)^2, +# $$ + +# where the $y_i$s are our $n$ targets (the values we want to +# reproduce), while the outputs of the network after having propagated +# all inputs $\boldsymbol{x}$ are given by $\boldsymbol{\tilde{y}}_i$. + +# ## Layout of a neural network with three hidden layers +# +# +# +# +#

    Figure 1:

    +# + +# ## Definitions +# +# With our definition of the targets $\boldsymbol{y}$, the outputs of the +# network $\boldsymbol{\tilde{y}}$ and the inputs $\boldsymbol{x}$ we +# define now the activation $z_j^l$ of node/neuron/unit $j$ of the +# $l$-th layer as a function of the bias, the weights which add up from +# the previous layer $l-1$ and the forward passes/outputs +# $\hat{a}^{l-1}$ from the previous layer as + +# $$ +# z_j^l = \sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l, +# $$ + +# where $b_k^l$ are the biases from layer $l$. Here $M_{l-1}$ +# represents the total number of nodes/neurons/units of layer $l-1$. The +# figure in the whiteboard notes illustrates this equation. We can rewrite this in a more +# compact form as the matrix-vector products we discussed earlier, + +# $$ +# \hat{z}^l = \left(\hat{W}^l\right)^T\hat{a}^{l-1}+\hat{b}^l. +# $$ + +# ## Inputs to the activation function +# +# With the activation values $\boldsymbol{z}^l$ we can in turn define the +# output of layer $l$ as $\boldsymbol{a}^l = f(\boldsymbol{z}^l)$ where $f$ is our +# activation function. In the examples here we will use the sigmoid +# function discussed in our logistic regression lectures. We will also use the same activation function $f$ for all layers +# and their nodes. It means we have + +# $$ +# a_j^l = \sigma(z_j^l) = \frac{1}{1+\exp{-(z_j^l)}}. +# $$ + +# ## Derivatives and the chain rule +# +# From the definition of the activation $z_j^l$ we have + +# $$ +# \frac{\partial z_j^l}{\partial w_{ij}^l} = a_i^{l-1}, +# $$ + +# and + +# $$ +# \frac{\partial z_j^l}{\partial a_i^{l-1}} = w_{ji}^l. +# $$ + +# With our definition of the activation function we have that (note that this function depends only on $z_j^l$) + +# $$ +# \frac{\partial a_j^l}{\partial z_j^{l}} = a_j^l(1-a_j^l)=\sigma(z_j^l)(1-\sigma(z_j^l)). +# $$ + +# ## Derivative of the cost function +# +# With these definitions we can now compute the derivative of the cost function in terms of the weights. +# +# Let us specialize to the output layer $l=L$. Our cost function is + +# $$ +# {\cal C}(\boldsymbol{\Theta}^L) = \frac{1}{2}\sum_{i=1}^n\left(y_i - \tilde{y}_i\right)^2=\frac{1}{2}\sum_{i=1}^n\left(a_i^L - y_i\right)^2, +# $$ + +# The derivative of this function with respect to the weights is + +# $$ +# \frac{\partial{\cal C}(\boldsymbol{\Theta}^L)}{\partial w_{jk}^L} = \left(a_j^L - y_j\right)\frac{\partial a_j^L}{\partial w_{jk}^{L}}, +# $$ + +# The last partial derivative can easily be computed and reads (by applying the chain rule) + +# $$ +# \frac{\partial a_j^L}{\partial w_{jk}^{L}} = \frac{\partial a_j^L}{\partial z_{j}^{L}}\frac{\partial z_j^L}{\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1}. +# $$ + +# ## Simpler examples first, and automatic differentiation +# +# In order to understand the back propagation algorithm and its +# derivation (an implementation of the chain rule), let us first digress +# with some simple examples. These examples are also meant to motivate +# the link with back propagation and [automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation). + +# ## Reminder on the chain rule and gradients +# +# If we have a multivariate function $f(x,y)$ where $x=x(t)$ and $y=y(t)$ are functions of a variable $t$, we have that the gradient of $f$ with respect to $t$ (without the explicit unit vector components) + +# $$ +# \frac{df}{dt} = \begin{bmatrix}\frac{\partial f}{\partial x} & \frac{\partial f}{\partial y} \end{bmatrix} \begin{bmatrix}\frac{\partial x}{\partial t} \\ \frac{\partial y}{\partial t} \end{bmatrix}=\frac{\partial f}{\partial x} \frac{\partial x}{\partial t} +\frac{\partial f}{\partial y} \frac{\partial y}{\partial t}. +# $$ + +# ## Multivariable functions +# +# If we have a multivariate function $f(x,y)$ where $x=x(t,s)$ and $y=y(t,s)$ are functions of the variables $t$ and $s$, we have that the partial derivatives + +# $$ +# \frac{\partial f}{\partial s}=\frac{\partial f}{\partial x}\frac{\partial x}{\partial s}+\frac{\partial f}{\partial y}\frac{\partial y}{\partial s}, +# $$ + +# and + +# $$ +# \frac{\partial f}{\partial t}=\frac{\partial f}{\partial x}\frac{\partial x}{\partial t}+\frac{\partial f}{\partial y}\frac{\partial y}{\partial t}. +# $$ + +# the gradient of $f$ with respect to $t$ and $s$ (without the explicit unit vector components) + +# $$ +# \frac{df}{d(s,t)} = \begin{bmatrix}\frac{\partial f}{\partial x} & \frac{\partial f}{\partial y} \end{bmatrix} \begin{bmatrix}\frac{\partial x}{\partial s} &\frac{\partial x}{\partial t} \\ \frac{\partial y}{\partial s} & \frac{\partial y}{\partial t} \end{bmatrix}. +# $$ + +# ## Automatic differentiation through examples +# +# A great introduction to automatic differentiation is given by Baydin et al., see . +# +# Automatic differentiation is a represented by a repeated application +# of the chain rule on well-known functions and allows for the +# calculation of derivatives to numerical precision. It is not the same +# as the calculation of symbolic derivatives via for example SymPy, nor +# does it use approximative formulae based on Taylor-expansions of a +# function around a given value. The latter are error prone due to +# truncation errors and values of the step size $\Delta$. + +# ## Simple example +# +# Our first example is rather simple, + +# $$ +# f(x) =\exp{x^2}, +# $$ + +# with derivative + +# $$ +# f'(x) =2x\exp{x^2}. +# $$ + +# We can use SymPy to extract the pertinent lines of Python code through the following simple example + +# In[4]: + + +from __future__ import division +from sympy import * +x = symbols('x') +expr = exp(x*x) +simplify(expr) +derivative = diff(expr,x) +print(python(expr)) +print(python(derivative)) + + +# ## Smarter way of evaluating the above function +# If we study this function, we note that we can reduce the number of operations by introducing an intermediate variable + +# $$ +# a = x^2, +# $$ + +# leading to + +# $$ +# f(x) = f(a(x)) = b= \exp{a}. +# $$ + +# We now assume that all operations can be counted in terms of equal +# floating point operations. This means that in order to calculate +# $f(x)$ we need first to square $x$ and then compute the exponential. We +# have thus two floating point operations only. + +# ## Reducing the number of operations +# +# With the introduction of a precalculated quantity $a$ and thereby $f(x)$ we have that the derivative can be written as + +# $$ +# f'(x) = 2xb, +# $$ + +# which reduces the number of operations from four in the orginal +# expression to two. This means that if we need to compute $f(x)$ and +# its derivative (a common task in optimizations), we have reduced the +# number of operations from six to four in total. +# +# **Note** that the usage of a symbolic software like SymPy does not +# include such simplifications and the calculations of the function and +# the derivatives yield in general more floating point operations. + +# ## Chain rule, forward and reverse modes +# +# In the above example we have introduced the variables $a$ and $b$, and our function is + +# $$ +# f(x) = f(a(x)) = b= \exp{a}, +# $$ + +# with $a=x^2$. We can decompose the derivative of $f$ with respect to $x$ as + +# $$ +# \frac{df}{dx}=\frac{df}{db}\frac{db}{da}\frac{da}{dx}. +# $$ + +# We note that since $b=f(x)$ that + +# $$ +# \frac{df}{db}=1, +# $$ + +# leading to + +# $$ +# \frac{df}{dx}=\frac{db}{da}\frac{da}{dx}=2x\exp{x^2}, +# $$ + +# as before. + +# ## Forward and reverse modes +# +# We have that + +# $$ +# \frac{df}{dx}=\frac{df}{db}\frac{db}{da}\frac{da}{dx}, +# $$ + +# which we can rewrite either as + +# $$ +# \frac{df}{dx}=\left[\frac{df}{db}\frac{db}{da}\right]\frac{da}{dx}, +# $$ + +# or + +# $$ +# \frac{df}{dx}=\frac{df}{db}\left[\frac{db}{da}\frac{da}{dx}\right]. +# $$ + +# The first expression is called reverse mode (or back propagation) +# since we start by evaluating the derivatives at the end point and then +# propagate backwards. This is the standard way of evaluating +# derivatives (gradients) when optimizing the parameters of a neural +# network. In the context of deep learning this is computationally +# more efficient since the output of a neural network consists of either +# one or some few other output variables. +# +# The second equation defines the so-called **forward mode**. + +# ## More complicated function +# +# We increase our ambitions and introduce a slightly more complicated function + +# $$ +# f(x) =\sqrt{x^2+exp{x^2}}, +# $$ + +# with derivative + +# $$ +# f'(x) =\frac{x(1+\exp{x^2})}{\sqrt{x^2+exp{x^2}}}. +# $$ + +# The corresponding SymPy code reads + +# In[5]: + + +from __future__ import division +from sympy import * +x = symbols('x') +expr = sqrt(x*x+exp(x*x)) +simplify(expr) +derivative = diff(expr,x) +print(python(expr)) +print(python(derivative)) + + +# ## Counting the number of floating point operations +# +# A simple count of operations shows that we need five operations for +# the function itself and ten for the derivative. Fifteen operations in total if we wish to proceed with the above codes. +# +# Can we reduce this to +# say half the number of operations? + +# ## Defining intermediate operations +# +# We can indeed reduce the number of operation to half of those listed in the brute force approach above. +# We define the following quantities + +# $$ +# a = x^2, +# $$ + +# and + +# $$ +# b = \exp{x^2} = \exp{a}, +# $$ + +# and + +# $$ +# c= a+b, +# $$ + +# and + +# $$ +# d=f(x)=\sqrt{c}. +# $$ + +# ## New expression for the derivative +# +# With these definitions we obtain the following partial derivatives + +# $$ +# \frac{\partial a}{\partial x} = 2x, +# $$ + +# and + +# $$ +# \frac{\partial b}{\partial a} = \exp{a}, +# $$ + +# and + +# $$ +# \frac{\partial c}{\partial a} = 1, +# $$ + +# and + +# $$ +# \frac{\partial c}{\partial b} = 1, +# $$ + +# and + +# $$ +# \frac{\partial d}{\partial c} = \frac{1}{2\sqrt{c}}, +# $$ + +# and finally + +# $$ +# \frac{\partial f}{\partial d} = 1. +# $$ + +# ## Final derivatives +# Our final derivatives are thus + +# $$ +# \frac{\partial f}{\partial c} = \frac{\partial f}{\partial d} \frac{\partial d}{\partial c} = \frac{1}{2\sqrt{c}}, +# $$ + +# $$ +# \frac{\partial f}{\partial b} = \frac{\partial f}{\partial c} \frac{\partial c}{\partial b} = \frac{1}{2\sqrt{c}}, +# $$ + +# $$ +# \frac{\partial f}{\partial a} = \frac{\partial f}{\partial c} \frac{\partial c}{\partial a}+ +# \frac{\partial f}{\partial b} \frac{\partial b}{\partial a} = \frac{1+\exp{a}}{2\sqrt{c}}, +# $$ + +# and finally + +# $$ +# \frac{\partial f}{\partial x} = \frac{\partial f}{\partial a} \frac{\partial a}{\partial x} = \frac{x(1+\exp{a})}{\sqrt{c}}, +# $$ + +# which is just + +# $$ +# \frac{\partial f}{\partial x} = \frac{x(1+b)}{d}, +# $$ + +# and requires only three operations if we can reuse all intermediate variables. + +# ## In general not this simple +# +# In general, see the generalization below, unless we can obtain simple +# analytical expressions which we can simplify further, the final +# implementation of automatic differentiation involves repeated +# calculations (and thereby operations) of derivatives of elementary +# functions. + +# ## Automatic differentiation +# +# We can make this example more formal. Automatic differentiation is a +# formalization of the previous example (see graph). +# +# We define $\boldsymbol{x}\in x_1,\dots, x_l$ input variables to a given function $f(\boldsymbol{x})$ and $x_{l+1},\dots, x_L$ intermediate variables. +# +# In the above example we have only one input variable, $l=1$ and four intermediate variables, that is + +# $$ +# \begin{bmatrix} x_1=x & x_2 = x^2=a & x_3 =\exp{a}= b & x_4=c=a+b & x_5 = \sqrt{c}=d \end{bmatrix}. +# $$ + +# Furthemore, for $i=l+1, \dots, L$ (here $i=2,3,4,5$ and $f=x_L=d$), we +# define the elementary functions $g_i(x_{Pa(x_i)})$ where $x_{Pa(x_i)}$ are the parent nodes of the variable $x_i$. +# +# In our case, we have for example for $x_3=g_3(x_{Pa(x_i)})=\exp{a}$, that $g_3=\exp{()}$ and $x_{Pa(x_3)}=a$. + +# ## Chain rule +# +# We can now compute the gradients by back-propagating the derivatives using the chain rule. +# We have defined + +# $$ +# \frac{\partial f}{\partial x_L} = 1, +# $$ + +# which allows us to find the derivatives of the various variables $x_i$ as + +# $$ +# \frac{\partial f}{\partial x_i} = \sum_{x_j:x_i\in Pa(x_j)}\frac{\partial f}{\partial x_j} \frac{\partial x_j}{\partial x_i}=\sum_{x_j:x_i\in Pa(x_j)}\frac{\partial f}{\partial x_j} \frac{\partial g_j}{\partial x_i}. +# $$ + +# Whenever we have a function which can be expressed as a computation +# graph and the various functions can be expressed in terms of +# elementary functions that are differentiable, then automatic +# differentiation works. The functions may not need to be elementary +# functions, they could also be computer programs, although not all +# programs can be automatically differentiated. + +# ## First network example, simple percepetron with one input +# +# As yet another example we define now a simple perceptron model with +# all quantities given by scalars. We consider only one input variable +# $x$ and one target value $y$. We define an activation function +# $\sigma_1$ which takes as input + +# $$ +# z_1 = w_1x+b_1, +# $$ + +# where $w_1$ is the weight and $b_1$ is the bias. These are the +# parameters we want to optimize. The output is $a_1=\sigma(z_1)$ (see +# graph from whiteboard notes). This output is then fed into the +# **cost/loss** function, which we here for the sake of simplicity just +# define as the squared error + +# $$ +# C(x;w_1,b_1)=\frac{1}{2}(a_1-y)^2. +# $$ + +# ## Layout of a simple neural network with no hidden layer +# +# +# +# +#

    Figure 1:

    +# + +# ## Optimizing the parameters +# +# In setting up the feed forward and back propagation parts of the +# algorithm, we need now the derivative of the various variables we want +# to train. +# +# We need + +# $$ +# \frac{\partial C}{\partial w_1} \hspace{0.1cm}\mathrm{and}\hspace{0.1cm}\frac{\partial C}{\partial b_1}. +# $$ + +# Using the chain rule we find + +# $$ +# \frac{\partial C}{\partial w_1}=\frac{\partial C}{\partial a_1}\frac{\partial a_1}{\partial z_1}\frac{\partial z_1}{\partial w_1}=(a_1-y)\sigma_1'x, +# $$ + +# and + +# $$ +# \frac{\partial C}{\partial b_1}=\frac{\partial C}{\partial a_1}\frac{\partial a_1}{\partial z_1}\frac{\partial z_1}{\partial b_1}=(a_1-y)\sigma_1', +# $$ + +# which we later will just define as + +# $$ +# \frac{\partial C}{\partial a_1}\frac{\partial a_1}{\partial z_1}=\delta_1. +# $$ + +# ## Adding a hidden layer +# +# We change our simple model to (see graph) +# a network with just one hidden layer but with scalar variables only. +# +# Our output variable changes to $a_2$ and $a_1$ is now the output from the hidden node and $a_0=x$. +# We have then + +# $$ +# z_1 = w_1a_0+b_1 \hspace{0.1cm} \wedge a_1 = \sigma_1(z_1), +# $$ + +# $$ +# z_2 = w_2a_1+b_2 \hspace{0.1cm} \wedge a_2 = \sigma_2(z_2), +# $$ + +# and the cost function + +# $$ +# C(x;\boldsymbol{\Theta})=\frac{1}{2}(a_2-y)^2, +# $$ + +# with $\boldsymbol{\Theta}=[w_1,w_2,b_1,b_2]$. + +# ## Layout of a simple neural network with one hidden layer +# +# +# +# +#

    Figure 1:

    +# + +# ## The derivatives +# +# The derivatives are now, using the chain rule again + +# $$ +# \frac{\partial C}{\partial w_2}=\frac{\partial C}{\partial a_2}\frac{\partial a_2}{\partial z_2}\frac{\partial z_2}{\partial w_2}=(a_2-y)\sigma_2'a_1=\delta_2a_1, +# $$ + +# $$ +# \frac{\partial C}{\partial b_2}=\frac{\partial C}{\partial a_2}\frac{\partial a_2}{\partial z_2}\frac{\partial z_2}{\partial b_2}=(a_2-y)\sigma_2'=\delta_2, +# $$ + +# $$ +# \frac{\partial C}{\partial w_1}=\frac{\partial C}{\partial a_2}\frac{\partial a_2}{\partial z_2}\frac{\partial z_2}{\partial a_1}\frac{\partial a_1}{\partial z_1}\frac{\partial z_1}{\partial w_1}=(a_2-y)\sigma_2'a_1\sigma_1'a_0, +# $$ + +# $$ +# \frac{\partial C}{\partial b_1}=\frac{\partial C}{\partial a_2}\frac{\partial a_2}{\partial z_2}\frac{\partial z_2}{\partial a_1}\frac{\partial a_1}{\partial z_1}\frac{\partial z_1}{\partial b_1}=(a_2-y)\sigma_2'\sigma_1'=\delta_1. +# $$ + +# Can you generalize this to more than one hidden layer? + +# ## Important observations +# +# From the above equations we see that the derivatives of the activation +# functions play a central role. If they vanish, the training may +# stop. This is called the vanishing gradient problem, see discussions below. If they become +# large, the parameters $w_i$ and $b_i$ may simply go to infinity. This +# is referenced as the exploding gradient problem. + +# ## The training +# +# The training of the parameters is done through various gradient descent approximations with + +# $$ +# w_{i}\leftarrow w_{i}- \eta \delta_i a_{i-1}, +# $$ + +# and + +# $$ +# b_i \leftarrow b_i-\eta \delta_i, +# $$ + +# with $\eta$ is the learning rate. +# +# One iteration consists of one feed forward step and one back-propagation step. Each back-propagation step does one update of the parameters $\boldsymbol{\Theta}$. +# +# For the first hidden layer $a_{i-1}=a_0=x$ for this simple model. + +# ## Code example +# +# The code here implements the above model with one hidden layer and +# scalar variables for the same function we studied in the previous +# example. The code is however set up so that we can add multiple +# inputs $x$ and target values $y$. Note also that we have the +# possibility of defining a feature matrix $\boldsymbol{X}$ with more than just +# one column for the input values. This will turn useful in our next example. We have also defined matrices and vectors for all of our operations although it is not necessary here. + +# In[6]: + + +import numpy as np +# We use the Sigmoid function as activation function +def sigmoid(z): + return 1.0/(1.0+np.exp(-z)) + +def forwardpropagation(x): + # weighted sum of inputs to the hidden layer + z_1 = np.matmul(x, w_1) + b_1 + # activation in the hidden layer + a_1 = sigmoid(z_1) + # weighted sum of inputs to the output layer + z_2 = np.matmul(a_1, w_2) + b_2 + a_2 = z_2 + return a_1, a_2 + +def backpropagation(x, y): + a_1, a_2 = forwardpropagation(x) + # parameter delta for the output layer, note that a_2=z_2 and its derivative wrt z_2 is just 1 + delta_2 = a_2 - y + print(0.5*((a_2-y)**2)) + # delta for the hidden layer + delta_1 = np.matmul(delta_2, w_2.T) * a_1 * (1 - a_1) + # gradients for the output layer + output_weights_gradient = np.matmul(a_1.T, delta_2) + output_bias_gradient = np.sum(delta_2, axis=0) + # gradient for the hidden layer + hidden_weights_gradient = np.matmul(x.T, delta_1) + hidden_bias_gradient = np.sum(delta_1, axis=0) + return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient + + +# ensure the same random numbers appear every time +np.random.seed(0) +# Input variable +x = np.array([4.0],dtype=np.float64) +# Target values +y = 2*x+1.0 + +# Defining the neural network, only scalars here +n_inputs = x.shape +n_features = 1 +n_hidden_neurons = 1 +n_outputs = 1 + +# Initialize the network +# weights and bias in the hidden layer +w_1 = np.random.randn(n_features, n_hidden_neurons) +b_1 = np.zeros(n_hidden_neurons) + 0.01 + +# weights and bias in the output layer +w_2 = np.random.randn(n_hidden_neurons, n_outputs) +b_2 = np.zeros(n_outputs) + 0.01 + +eta = 0.1 +for i in range(50): + # calculate gradients + derivW2, derivB2, derivW1, derivB1 = backpropagation(x, y) + # update weights and biases + w_2 -= eta * derivW2 + b_2 -= eta * derivB2 + w_1 -= eta * derivW1 + b_1 -= eta * derivB1 + + +# We see that after some few iterations (the results do depend on the learning rate however), we get an error which is rather small. + +# ## Exercise 1: Including more data +# +# Try to increase the amount of input and +# target/output data. Try also to perform calculations for more values +# of the learning rates. Feel free to add either hyperparameters with an +# $l_1$ norm or an $l_2$ norm and discuss your results. +# Discuss your results as functions of the amount of training data and various learning rates. +# +# **Challenge:** Try to change the activation functions and replace the hard-coded analytical expressions with automatic derivation via either **autograd** or **JAX**. + +# ## Simple neural network and the back propagation equations +# +# Let us now try to increase our level of ambition and attempt at setting +# up the equations for a neural network with two input nodes, one hidden +# layer with two hidden nodes and one output layer with one output node/neuron only (see graph).. +# +# We need to define the following parameters and variables with the input layer (layer $(0)$) +# where we label the nodes $x_0$ and $x_1$ + +# $$ +# x_0 = a_0^{(0)} \wedge x_1 = a_1^{(0)}. +# $$ + +# The hidden layer (layer $(1)$) has nodes which yield the outputs $a_0^{(1)}$ and $a_1^{(1)}$) with weight $\boldsymbol{w}$ and bias $\boldsymbol{b}$ parameters + +# $$ +# w_{ij}^{(1)}=\left\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)}\right\} \wedge b^{(1)}=\left\{b_0^{(1)},b_1^{(1)}\right\}. +# $$ + +# ## Layout of a simple neural network with two input nodes, one hidden layer and one output node +# +# +# +# +#

    Figure 1:

    +# + +# ## The ouput layer +# +# Finally, we have the ouput layer given by layer label $(2)$ with output $a^{(2)}$ and weights and biases to be determined given by the variables + +# $$ +# w_{i}^{(2)}=\left\{w_{0}^{(2)},w_{1}^{(2)}\right\} \wedge b^{(2)}. +# $$ + +# Our output is $\tilde{y}=a^{(2)}$ and we define a generic cost function $C(a^{(2)},y;\boldsymbol{\Theta})$ where $y$ is the target value (a scalar here). +# The parameters we need to optimize are given by + +# $$ +# \boldsymbol{\Theta}=\left\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)},w_{0}^{(2)},w_{1}^{(2)},b_0^{(1)},b_1^{(1)},b^{(2)}\right\}. +# $$ + +# ## Compact expressions +# +# We can define the inputs to the activation functions for the various layers in terms of various matrix-vector multiplications and vector additions. +# The inputs to the first hidden layer are + +# $$ +# \begin{bmatrix}z_0^{(1)} \\ z_1^{(1)} \end{bmatrix}=\begin{bmatrix}w_{00}^{(1)} & w_{01}^{(1)}\\ w_{10}^{(1)} &w_{11}^{(1)} \end{bmatrix}\begin{bmatrix}a_0^{(0)} \\ a_1^{(0)} \end{bmatrix}+\begin{bmatrix}b_0^{(1)} \\ b_1^{(1)} \end{bmatrix}, +# $$ + +# with outputs + +# $$ +# \begin{bmatrix}a_0^{(1)} \\ a_1^{(1)} \end{bmatrix}=\begin{bmatrix}\sigma^{(1)}(z_0^{(1)}) \\ \sigma^{(1)}(z_1^{(1)}) \end{bmatrix}. +# $$ + +# ## Output layer +# +# For the final output layer we have the inputs to the final activation function + +# $$ +# z^{(2)} = w_{0}^{(2)}a_0^{(1)} +w_{1}^{(2)}a_1^{(1)}+b^{(2)}, +# $$ + +# resulting in the output + +# $$ +# a^{(2)}=\sigma^{(2)}(z^{(2)}). +# $$ + +# ## Explicit derivatives +# +# In total we have nine parameters which we need to train. Using the +# chain rule (or just the back-propagation algorithm) we can find all +# derivatives. Since we will use automatic differentiation in reverse +# mode, we start with the derivatives of the cost function with respect +# to the parameters of the output layer, namely + +# $$ +# \frac{\partial C}{\partial w_{i}^{(2)}}=\frac{\partial C}{\partial a^{(2)}}\frac{\partial a^{(2)}}{\partial z^{(2)}}\frac{\partial z^{(2)}}{\partial w_{i}^{(2)}}=\delta^{(2)}a_i^{(1)}, +# $$ + +# with + +# $$ +# \delta^{(2)}=\frac{\partial C}{\partial a^{(2)}}\frac{\partial a^{(2)}}{\partial z^{(2)}} +# $$ + +# and finally + +# $$ +# \frac{\partial C}{\partial b^{(2)}}=\frac{\partial C}{\partial a^{(2)}}\frac{\partial a^{(2)}}{\partial z^{(2)}}\frac{\partial z^{(2)}}{\partial b^{(2)}}=\delta^{(2)}. +# $$ + +# ## Derivatives of the hidden layer +# +# Using the chain rule we have the following expressions for say one of the weight parameters (it is easy to generalize to the other weight parameters) + +# $$ +# \frac{\partial C}{\partial w_{00}^{(1)}}=\frac{\partial C}{\partial a^{(2)}}\frac{\partial a^{(2)}}{\partial z^{(2)}} +# \frac{\partial z^{(2)}}{\partial z_0^{(1)}}\frac{\partial z_0^{(1)}}{\partial w_{00}^{(1)}}= \delta^{(2)}\frac{\partial z^{(2)}}{\partial z_0^{(1)}}\frac{\partial z_0^{(1)}}{\partial w_{00}^{(1)}}, +# $$ + +# which, noting that + +# $$ +# z^{(2)} =w_0^{(2)}a_0^{(1)}+w_1^{(2)}a_1^{(1)}+b^{(2)}, +# $$ + +# allows us to rewrite + +# $$ +# \frac{\partial z^{(2)}}{\partial z_0^{(1)}}\frac{\partial z_0^{(1)}}{\partial w_{00}^{(1)}}=w_0^{(2)}\frac{\partial a_0^{(1)}}{\partial z_0^{(1)}}a_0^{(1)}. +# $$ + +# ## Final expression +# Defining + +# $$ +# \delta_0^{(1)}=w_0^{(2)}\frac{\partial a_0^{(1)}}{\partial z_0^{(1)}}\delta^{(2)}, +# $$ + +# we have + +# $$ +# \frac{\partial C}{\partial w_{00}^{(1)}}=\delta_0^{(1)}a_0^{(1)}. +# $$ + +# Similarly, we obtain + +# $$ +# \frac{\partial C}{\partial w_{01}^{(1)}}=\delta_0^{(1)}a_1^{(1)}. +# $$ + +# ## Completing the list +# +# Similarly, we find + +# $$ +# \frac{\partial C}{\partial w_{10}^{(1)}}=\delta_1^{(1)}a_0^{(1)}, +# $$ + +# and + +# $$ +# \frac{\partial C}{\partial w_{11}^{(1)}}=\delta_1^{(1)}a_1^{(1)}, +# $$ + +# where we have defined + +# $$ +# \delta_1^{(1)}=w_1^{(2)}\frac{\partial a_1^{(1)}}{\partial z_1^{(1)}}\delta^{(2)}. +# $$ + +# ## Final expressions for the biases of the hidden layer +# +# For the sake of completeness, we list the derivatives of the biases, which are + +# $$ +# \frac{\partial C}{\partial b_{0}^{(1)}}=\delta_0^{(1)}, +# $$ + +# and + +# $$ +# \frac{\partial C}{\partial b_{1}^{(1)}}=\delta_1^{(1)}. +# $$ + +# As we will see below, these expressions can be generalized in a more compact form. + +# ## Gradient expressions +# +# For this specific model, with just one output node and two hidden +# nodes, the gradient descent equations take the following form for output layer + +# $$ +# w_{i}^{(2)}\leftarrow w_{i}^{(2)}- \eta \delta^{(2)} a_{i}^{(1)}, +# $$ + +# and + +# $$ +# b^{(2)} \leftarrow b^{(2)}-\eta \delta^{(2)}, +# $$ + +# and + +# $$ +# w_{ij}^{(1)}\leftarrow w_{ij}^{(1)}- \eta \delta_{i}^{(1)} a_{j}^{(0)}, +# $$ + +# and + +# $$ +# b_{i}^{(1)} \leftarrow b_{i}^{(1)}-\eta \delta_{i}^{(1)}, +# $$ + +# where $\eta$ is the learning rate. + +# ## Exercise 2: Extended program +# +# We extend our simple code to a function which depends on two variable $x_0$ and $x_1$, that is + +# $$ +# y=f(x_0,x_1)=x_0^2+3x_0x_1+x_1^2+5. +# $$ + +# We feed our network with $n=100$ entries $x_0$ and $x_1$. We have thus two features represented by these variable and an input matrix/design matrix $\boldsymbol{X}\in \mathbf{R}^{n\times 2}$ + +# $$ +# \boldsymbol{X}=\begin{bmatrix} x_{00} & x_{01} \\ x_{00} & x_{01} \\ x_{10} & x_{11} \\ x_{20} & x_{21} \\ \dots & \dots \\ \dots & \dots \\ x_{n-20} & x_{n-21} \\ x_{n-10} & x_{n-11} \end{bmatrix}. +# $$ + +# Write a code, based on the previous code examples, which takes as input these data and fit the above function. +# You can extend your code to include automatic differentiation. +# +# With these examples, we are now ready to embark upon the writing of more a general code for neural networks. + +# ## Getting serious, the back propagation equations for a neural network +# +# Now it is time to move away from one node in each layer only. Our inputs are also represented either by several inputs. +# +# We have thus + +# $$ +# \frac{\partial{\cal C}((\boldsymbol{\Theta}^L)}{\partial w_{jk}^L} = \left(a_j^L - y_j\right)a_j^L(1-a_j^L)a_k^{L-1}, +# $$ + +# Defining + +# $$ +# \delta_j^L = a_j^L(1-a_j^L)\left(a_j^L - y_j\right) = \sigma'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}, +# $$ + +# and using the Hadamard product of two vectors we can write this as + +# $$ +# \boldsymbol{\delta}^L = \sigma'(\hat{z}^L)\circ\frac{\partial {\cal C}}{\partial (\boldsymbol{a}^L)}. +# $$ + +# ## Analyzing the last results +# +# This is an important expression. The second term on the right handside +# measures how fast the cost function is changing as a function of the $j$th +# output activation. If, for example, the cost function doesn't depend +# much on a particular output node $j$, then $\delta_j^L$ will be small, +# which is what we would expect. The first term on the right, measures +# how fast the activation function $f$ is changing at a given activation +# value $z_j^L$. + +# ## More considerations +# +# Notice that everything in the above equations is easily computed. In +# particular, we compute $z_j^L$ while computing the behaviour of the +# network, and it is only a small additional overhead to compute +# $\sigma'(z^L_j)$. The exact form of the derivative with respect to the +# output depends on the form of the cost function. +# However, provided the cost function is known there should be little +# trouble in calculating + +# $$ +# \frac{\partial {\cal C}}{\partial (a_j^L)} +# $$ + +# With the definition of $\delta_j^L$ we have a more compact definition of the derivative of the cost function in terms of the weights, namely + +# $$ +# \frac{\partial{\cal C}}{\partial w_{jk}^L} = \delta_j^La_k^{L-1}. +# $$ + +# ## Derivatives in terms of $z_j^L$ +# +# It is also easy to see that our previous equation can be written as + +# $$ +# \delta_j^L =\frac{\partial {\cal C}}{\partial z_j^L}= \frac{\partial {\cal C}}{\partial a_j^L}\frac{\partial a_j^L}{\partial z_j^L}, +# $$ + +# which can also be interpreted as the partial derivative of the cost function with respect to the biases $b_j^L$, namely + +# $$ +# \delta_j^L = \frac{\partial {\cal C}}{\partial b_j^L}\frac{\partial b_j^L}{\partial z_j^L}=\frac{\partial {\cal C}}{\partial b_j^L}, +# $$ + +# That is, the error $\delta_j^L$ is exactly equal to the rate of change of the cost function as a function of the bias. + +# ## Bringing it together +# +# We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are # #
    # # $$ -# \begin{equation} z_i^1 = \sum_{j=1}^{M} w_{ij}^1 x_j + b_i^1 +# \begin{equation} +# \frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \delta_j^La_k^{L-1}, # \label{_auto1} \tag{2} # \end{equation} # $$ -# Here $b_i$ is the so-called bias which is normally needed in -# case of zero activation weights or inputs. How to fix the biases and -# the weights will be discussed below. The value of $z_i^1$ is the -# argument to the activation function $f_i$ of each node $i$, The -# variable $M$ stands for all possible inputs to a given node $i$ in the -# first layer. We define the output $y_i^1$ of all neurons in layer 1 as - -# -#
    -# -# $$ -# \begin{equation} -# y_i^1 = f(z_i^1) = f\left(\sum_{j=1}^M w_{ij}^1 x_j + b_i^1\right) -# \label{outputLayer1} \tag{3} -# \end{equation} -# $$ - -# where we assume that all nodes in the same layer have identical -# activation functions, hence the notation $f$. In general, we could assume in the more general case that different layers have different activation functions. -# In this case we would identify these functions with a superscript $l$ for the $l$-th layer, - -# -#
    -# -# $$ -# \begin{equation} -# y_i^l = f^l(u_i^l) = f^l\left(\sum_{j=1}^{N_{l-1}} w_{ij}^l y_j^{l-1} + b_i^l\right) -# \label{generalLayer} \tag{4} -# \end{equation} -# $$ - -# where $N_l$ is the number of nodes in layer $l$. When the output of -# all the nodes in the first hidden layer are computed, the values of -# the subsequent layer can be calculated and so forth until the output -# is obtained. - -# ## Mathematical model -# -# The output of neuron $i$ in layer 2 is thus, +# and # #
    # # $$ # \begin{equation} -# y_i^2 = f^2\left(\sum_{j=1}^N w_{ij}^2 y_j^1 + b_i^2\right) -# \label{_auto2} \tag{5} +# \delta_j^L = \sigma'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}, +# \label{_auto2} \tag{3} # \end{equation} # $$ -# -#
    -# -# $$ -# \begin{equation} -# = f^2\left[\sum_{j=1}^N w_{ij}^2f^1\left(\sum_{k=1}^M w_{jk}^1 x_k + b_j^1\right) + b_i^2\right] -# \label{outputLayer2} \tag{6} -# \end{equation} -# $$ - -# where we have substituted $y_k^1$ with the inputs $x_k$. Finally, the ANN output reads +# and # #
    # # $$ # \begin{equation} -# y_i^3 = f^3\left(\sum_{j=1}^N w_{ij}^3 y_j^2 + b_i^3\right) -# \label{_auto3} \tag{7} +# \delta_j^L = \frac{\partial {\cal C}}{\partial b_j^L}, +# \label{_auto3} \tag{4} # \end{equation} # $$ -# -#
    +# ## Final back propagating equation # +# We have that (replacing $L$ with a general layer $l$) + # $$ -# \begin{equation} -# = f_3\left[\sum_{j} w_{ij}^3 f^2\left(\sum_{k} w_{jk}^2 f^1\left(\sum_{m} w_{km}^1 x_m + b_k^1\right) + b_j^2\right) -# + b_1^3\right] -# \label{_auto4} \tag{8} -# \end{equation} +# \delta_j^l =\frac{\partial {\cal C}}{\partial z_j^l}. # $$ -# ## Mathematical model -# -# We can generalize this expression to an MLP with $l$ hidden -# layers. The complete functional form is, +# We want to express this in terms of the equations for layer $l+1$. -# -#
    +# ## Using the chain rule and summing over all $k$ entries # +# We obtain + # $$ -# \begin{equation} -# y^{l+1}_i = f^{l+1}\left[\!\sum_{j=1}^{N_l} w_{ij}^3 f^l\left(\sum_{k=1}^{N_{l-1}}w_{jk}^{l-1}\left(\dots f^1\left(\sum_{n=1}^{N_0} w_{mn}^1 x_n+ b_m^1\right)\dots\right)+b_k^2\right)+b_1^3\right] -# \label{completeNN} \tag{9} -# \end{equation} +# \delta_j^l =\sum_k \frac{\partial {\cal C}}{\partial z_k^{l+1}}\frac{\partial z_k^{l+1}}{\partial z_j^{l}}=\sum_k \delta_k^{l+1}\frac{\partial z_k^{l+1}}{\partial z_j^{l}}, # $$ -# which illustrates a basic property of MLPs: The only independent -# variables are the input values $x_n$. +# and recalling that -# ## Mathematical model -# -# This confirms that an MLP, despite its quite convoluted mathematical -# form, is nothing more than an analytic function, specifically a -# mapping of real-valued vectors $\hat{x} \in \mathbb{R}^n \rightarrow -# \hat{y} \in \mathbb{R}^m$. -# -# Furthermore, the flexibility and universality of an MLP can be -# illustrated by realizing that the expression is essentially a nested -# sum of scaled activation functions of the form - -# -#
    -# # $$ -# \begin{equation} -# f(x) = c_1 f(c_2 x + c_3) + c_4 -# \label{_auto5} \tag{10} -# \end{equation} +# z_j^{l+1} = \sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1}, # $$ -# where the parameters $c_i$ are weights and biases. By adjusting these -# parameters, the activation functions can be shifted up and down or -# left and right, change slope or be rescaled which is the key to the -# flexibility of a neural network. +# with $M_l$ being the number of nodes in layer $l$, we obtain -# ### Matrix-vector notation -# -# We can introduce a more convenient notation for the activations in an A NN. -# -# Additionally, we can represent the biases and activations -# as layer-wise column vectors $\hat{b}_l$ and $\hat{y}_l$, so that the $i$-th element of each vector -# is the bias $b_i^l$ and activation $y_i^l$ of node $i$ in layer $l$ respectively. -# -# We have that $\mathrm{W}_l$ is an $N_{l-1} \times N_l$ matrix, while $\hat{b}_l$ and $\hat{y}_l$ are $N_l \times 1$ column vectors. -# With this notation, the sum becomes a matrix-vector multiplication, and we can write -# the equation for the activations of hidden layer 2 (assuming three nodes for simplicity) as - -# -#
    -# # $$ -# \begin{equation} -# \hat{y}_2 = f_2(\mathrm{W}_2 \hat{y}_{1} + \hat{b}_{2}) = -# f_2\left(\left[\begin{array}{ccc} -# w^2_{11} &w^2_{12} &w^2_{13} \\ -# w^2_{21} &w^2_{22} &w^2_{23} \\ -# w^2_{31} &w^2_{32} &w^2_{33} \\ -# \end{array} \right] \cdot -# \left[\begin{array}{c} -# y^1_1 \\ -# y^1_2 \\ -# y^1_3 \\ -# \end{array}\right] + -# \left[\begin{array}{c} -# b^2_1 \\ -# b^2_2 \\ -# b^2_3 \\ -# \end{array}\right]\right). -# \label{_auto6} \tag{11} -# \end{equation} +# \delta_j^l =\sum_k \delta_k^{l+1}w_{kj}^{l+1}\sigma'(z_j^l), # $$ -# ### Matrix-vector notation and activation +# This is our final equation. # -# The activation of node $i$ in layer 2 is +# We are now ready to set up the algorithm for back propagation and learning the weights and biases. -# -#
    +# ## Setting up the back propagation algorithm # +# The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm. +# +# **First**, we set up the input data $\hat{x}$ and the activations +# $\hat{z}_1$ of the input layer and compute the activation function and +# the pertinent outputs $\hat{a}^1$. +# +# **Secondly**, we perform then the feed forward till we reach the output +# layer and compute all $\hat{z}_l$ of the input layer and compute the +# activation function and the pertinent outputs $\hat{a}^l$ for +# $l=1,2,3,\dots,L$. +# +# **Notation**: The first hidden layer has $l=1$ as label and the final output layer has $l=L$. + +# ## Setting up the back propagation algorithm, part 2 +# +# Thereafter we compute the ouput error $\hat{\delta}^L$ by computing all + # $$ -# \begin{equation} -# y^2_i = f_2\Bigr(w^2_{i1}y^1_1 + w^2_{i2}y^1_2 + w^2_{i3}y^1_3 + b^2_i\Bigr) = -# f_2\left(\sum_{j=1}^3 w^2_{ij} y_j^1 + b^2_i\right). -# \label{_auto7} \tag{12} -# \end{equation} +# \delta_j^L = \sigma'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}. # $$ -# This is not just a convenient and compact notation, but also a useful -# and intuitive way to think about MLPs: The output is calculated by a -# series of matrix-vector multiplications and vector additions that are -# used as input to the activation functions. For each operation -# $\mathrm{W}_l \hat{y}_{l-1}$ we move forward one layer. +# Then we compute the back propagate error for each $l=L-1,L-2,\dots,1$ as + +# $$ +# \delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}\sigma'(z_j^l). +# $$ + +# ## Setting up the Back propagation algorithm, part 3 +# +# Finally, we update the weights and the biases using gradient descent +# for each $l=L-1,L-2,\dots,1$ and update the weights and biases +# according to the rules + +# $$ +# w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, +# $$ + +# $$ +# b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, +# $$ + +# with $\eta$ being the learning rate. + +# ## Updating the gradients +# +# With the back propagate error for each $l=L-1,L-2,\dots,1$ as + +# $$ +# \delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}sigma'(z_j^l), +# $$ + +# we update the weights and the biases using gradient descent for each $l=L-1,L-2,\dots,1$ and update the weights and biases according to the rules + +# $$ +# w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, +# $$ + +# $$ +# b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, +# $$ # ### Activation functions # @@ -604,7 +1671,7 @@ print(f"Test set accuracy with Feed Forward Neural Network for XOR gate:{FFNN.s # tangent performs better than the sigmoid for training MLPs. has # become the most popular for *deep neural networks* -# In[4]: +# In[7]: """The sigmoid function (or the logistic curve) is a @@ -680,1592 +1747,283 @@ ax.set_title('Rectified linear unit') plt.show() -# ## The multilayer perceptron (MLP) +# ## Fine-tuning neural network hyperparameters +# +# The flexibility of neural networks is also one of their main +# drawbacks: there are many hyperparameters to tweak. Not only can you +# use any imaginable network topology (how neurons/nodes are +# interconnected), but even in a simple FFNN you can change the number +# of layers, the number of neurons per layer, the type of activation +# function to use in each layer, the weight initialization logic, the +# stochastic gradient optmized and much more. How do you know what +# combination of hyperparameters is the best for your task? +# +# * You can use grid search with cross-validation to find the right hyperparameters. +# +# However,since there are many hyperparameters to tune, and since +# training a neural network on a large dataset takes a lot of time, you +# will only be able to explore a tiny part of the hyperparameter space. +# +# * You can use randomized search. +# +# * Or use tools like [Oscar](http://oscar.calldesk.ai/), which implements more complex algorithms to help you find a good set of hyperparameters quickly. + +# ## Hidden layers +# +# For many problems you can start with just one or two hidden layers and +# it will work just fine. For the MNIST data set you ca easily get a +# high accuracy using just one hidden layer with a few hundred neurons. +# You can reach for this data set above 98% accuracy using two hidden +# layers with the same total amount of neurons, in roughly the same +# amount of training time. +# +# For more complex problems, you can gradually ramp up the number of +# hidden layers, until you start overfitting the training set. Very +# complex tasks, such as large image classification or speech +# recognition, typically require networks with dozens of layers and they +# need a huge amount of training data. However, you will rarely have to +# train such networks from scratch: it is much more common to reuse +# parts of a pretrained state-of-the-art network that performs a similar +# task. + +# ## Vanishing gradients +# +# The Back propagation algorithm we derived above works by going from +# the output layer to the input layer, propagating the error gradient on +# the way. Once the algorithm has computed the gradient of the cost +# function with regards to each parameter in the network, it uses these +# gradients to update each parameter with a Gradient Descent (GD) step. +# +# Unfortunately for us, the gradients often get smaller and smaller as +# the algorithm progresses down to the first hidden layers. As a result, +# the GD update leaves the lower layer connection weights virtually +# unchanged, and training never converges to a good solution. This is +# known in the literature as **the vanishing gradients problem**. + +# ## Exploding gradients +# +# In other cases, the opposite can happen, namely the the gradients can +# grow bigger and bigger. The result is that many of the layers get +# large updates of the weights the algorithm diverges. This is the +# **exploding gradients problem**, which is mostly encountered in +# recurrent neural networks. More generally, deep neural networks suffer +# from unstable gradients, different layers may learn at widely +# different speeds + +# ## Is the Logistic activation function (Sigmoid) our choice? +# +# Although this unfortunate behavior has been empirically observed for +# quite a while (it was one of the reasons why deep neural networks were +# mostly abandoned for a long time), it is only around 2010 that +# significant progress was made in understanding it. +# +# A paper titled [Understanding the Difficulty of Training Deep +# Feedforward Neural Networks by Xavier Glorot and Yoshua Bengio](http://proceedings.mlr.press/v9/glorot10a.html) found that +# the problems with the popular logistic +# sigmoid activation function and the weight initialization technique +# that was most popular at the time, namely random initialization using +# a normal distribution with a mean of 0 and a standard deviation of +# 1. + +# ## Logistic function as the root of problems +# +# They showed that with this activation function and this +# initialization scheme, the variance of the outputs of each layer is +# much greater than the variance of its inputs. Going forward in the +# network, the variance keeps increasing after each layer until the +# activation function saturates at the top layers. This is actually made +# worse by the fact that the logistic function has a mean of 0.5, not 0 +# (the hyperbolic tangent function has a mean of 0 and behaves slightly +# better than the logistic function in deep networks). + +# ## The derivative of the Logistic funtion +# +# Looking at the logistic activation function, when inputs become large +# (negative or positive), the function saturates at 0 or 1, with a +# derivative extremely close to 0. Thus when backpropagation kicks in, +# it has virtually no gradient to propagate back through the network, +# and what little gradient exists keeps getting diluted as +# backpropagation progresses down through the top layers, so there is +# really nothing left for the lower layers. +# +# In their paper, Glorot and Bengio propose a way to significantly +# alleviate this problem. We need the signal to flow properly in both +# directions: in the forward direction when making predictions, and in +# the reverse direction when backpropagating gradients. We don’t want +# the signal to die out, nor do we want it to explode and saturate. For +# the signal to flow properly, the authors argue that we need the +# variance of the outputs of each layer to be equal to the variance of +# its inputs, and we also need the gradients to have equal variance +# before and after flowing through a layer in the reverse direction. + +# ## Insights from the paper by Glorot and Bengio +# +# One of the insights in the 2010 paper by Glorot and Bengio was that +# the vanishing/exploding gradients problems were in part due to a poor +# choice of activation function. Until then most people had assumed that +# if Nature had chosen to use roughly sigmoid activation functions in +# biological neurons, they must be an excellent choice. But it turns out +# that other activation functions behave much better in deep neural +# networks, in particular the ReLU activation function, mostly because +# it does not saturate for positive values (and also because it is quite +# fast to compute). + +# ## The RELU function family +# +# The ReLU activation function suffers from a problem known as the dying +# ReLUs: during training, some neurons effectively die, meaning they +# stop outputting anything other than 0. +# +# In some cases, you may find that half of your network’s neurons are +# dead, especially if you used a large learning rate. During training, +# if a neuron’s weights get updated such that the weighted sum of the +# neuron’s inputs is negative, it will start outputting 0. When this +# happen, the neuron is unlikely to come back to life since the gradient +# of the ReLU function is 0 when its input is negative. + +# ## ELU function +# +# To solve this problem, nowadays practitioners use a variant of the +# ReLU function, such as the leaky ReLU discussed above or the so-called +# exponential linear unit (ELU) function + +# $$ +# ELU(z) = \left\{\begin{array}{cc} \alpha\left( \exp{(z)}-1\right) & z < 0,\\ z & z \ge 0.\end{array}\right. +# $$ + +# ## Which activation function should we use? +# +# In general it seems that the ELU activation function is better than +# the leaky ReLU function (and its variants), which is better than +# ReLU. ReLU performs better than $\tanh$ which in turn performs better +# than the logistic function. +# +# If runtime performance is an issue, then you may opt for the leaky +# ReLU function over the ELU function If you don’t want to tweak yet +# another hyperparameter, you may just use the default $\alpha$ of +# $0.01$ for the leaky ReLU, and $1$ for ELU. If you have spare time and +# computing power, you can use cross-validation or bootstrap to evaluate +# other activation functions. + +# ## More on activation functions, output layers +# +# In most cases you can use the ReLU activation function in the hidden +# layers (or one of its variants). +# +# It is a bit faster to compute than other activation functions, and the +# gradient descent optimization does in general not get stuck. +# +# **For the output layer:** +# +# * For classification the softmax activation function is generally a good choice for classification tasks (when the classes are mutually exclusive). +# +# * For regression tasks, you can simply use no activation function at all. + +# ## Batch Normalization # -# The multilayer perceptron is a very popular, and easy to implement approach, to deep learning. It consists of -# 1. A neural network with one or more layers of nodes between the input and the output nodes. +# Batch Normalization aims to address the vanishing/exploding gradients +# problems, and more generally the problem that the distribution of each +# layer’s inputs changes during training, as the parameters of the +# previous layers change. # -# 2. The multilayer network structure, or architecture, or topology, consists of an input layer, one or more hidden layers, and one output layer. -# -# 3. The input nodes pass values to the first hidden layer, its nodes pass the information on to the second and so on till we reach the output layer. -# -# As a convention it is normal to call a network with one layer of input units, one layer of hidden -# units and one layer of output units as a two-layer network. A network with two layers of hidden units is called a three-layer network etc etc. -# -# For an MLP network there is no direct connection between the output nodes/neurons/units and the input nodes/neurons/units. -# Hereafter we will call the various entities of a layer for nodes. -# There are also no connections within a single layer. -# -# The number of input nodes does not need to equal the number of output -# nodes. This applies also to the hidden layers. Each layer may have its -# own number of nodes and activation functions. -# -# The hidden layers have their name from the fact that they are not -# linked to observables and as we will see below when we define the -# so-called activation $\hat{z}$, we can think of this as a basis -# expansion of the original inputs $\hat{x}$. The difference however -# between neural networks and say linear regression is that now these -# basis functions (which will correspond to the weights in the network) -# are learned from data. This results in an important difference between -# neural networks and deep learning approaches on one side and methods -# like logistic regression or linear regression and their modifications on the other side. - -# ## From one to many layers, the universal approximation theorem -# -# A neural network with only one layer, what we called the simple -# perceptron, is best suited if we have a standard binary model with -# clear (linear) boundaries between the outcomes. As such it could -# equally well be replaced by standard linear regression or logistic -# regression. Networks with one or more hidden layers approximate -# systems with more complex boundaries. -# -# As stated earlier, -# an important theorem in studies of neural networks, restated without -# proof here, is the [universal approximation -# theorem](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.441.7873&rep=rep1&type=pdf). -# -# It states that a feed-forward network with a single hidden layer -# containing a finite number of neurons can approximate continuous -# functions on compact subsets of real functions. The theorem thus -# states that simple neural networks can represent a wide variety of -# interesting functions when given appropriate parameters. It is the -# multilayer feedforward architecture itself which gives neural networks -# the potential of being universal approximators. - -# ## Deriving the back propagation code for a multilayer perceptron model -# -# As we have seen now in a feed forward network, we can express the final output of our network in terms of basic matrix-vector multiplications. -# The unknowwn quantities are our weights $w_{ij}$ and we need to find an algorithm for changing them so that our errors are as small as possible. -# This leads us to the famous [back propagation algorithm](https://www.nature.com/articles/323533a0). -# -# The questions we want to ask are how do changes in the biases and the -# weights in our network change the cost function and how can we use the -# final output to modify the weights? -# -# To derive these equations let us start with a plain regression problem -# and define our cost function as - -# $$ -# {\cal C}(\hat{W}) = \frac{1}{2}\sum_{i=1}^n\left(y_i - t_i\right)^2, -# $$ - -# where the $t_i$s are our $n$ targets (the values we want to -# reproduce), while the outputs of the network after having propagated -# all inputs $\hat{x}$ are given by $y_i$. Below we will demonstrate -# how the basic equations arising from the back propagation algorithm -# can be modified in order to study classification problems with $K$ -# classes. - -# ## Definitions -# -# With our definition of the targets $\hat{t}$, the outputs of the -# network $\hat{y}$ and the inputs $\hat{x}$ we -# define now the activation $z_j^l$ of node/neuron/unit $j$ of the -# $l$-th layer as a function of the bias, the weights which add up from -# the previous layer $l-1$ and the forward passes/outputs -# $\hat{a}^{l-1}$ from the previous layer as - -# $$ -# z_j^l = \sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l, -# $$ - -# where $b_k^l$ are the biases from layer $l$. Here $M_{l-1}$ -# represents the total number of nodes/neurons/units of layer $l-1$. The -# figure here illustrates this equation. We can rewrite this in a more -# compact form as the matrix-vector products we discussed earlier, - -# $$ -# \hat{z}^l = \left(\hat{W}^l\right)^T\hat{a}^{l-1}+\hat{b}^l. -# $$ - -# With the activation values $\hat{z}^l$ we can in turn define the -# output of layer $l$ as $\hat{a}^l = f(\hat{z}^l)$ where $f$ is our -# activation function. In the examples here we will use the sigmoid -# function discussed in our logistic regression lectures. We will also use the same activation function $f$ for all layers -# and their nodes. It means we have - -# $$ -# a_j^l = f(z_j^l) = \frac{1}{1+\exp{-(z_j^l)}}. -# $$ - -# ## Derivatives and the chain rule -# -# From the definition of the activation $z_j^l$ we have - -# $$ -# \frac{\partial z_j^l}{\partial w_{ij}^l} = a_i^{l-1}, -# $$ - -# and - -# $$ -# \frac{\partial z_j^l}{\partial a_i^{l-1}} = w_{ji}^l. -# $$ - -# With our definition of the activation function we have that (note that this function depends only on $z_j^l$) - -# $$ -# \frac{\partial a_j^l}{\partial z_j^{l}} = a_j^l(1-a_j^l)=f(z_j^l)(1-f(z_j^l)). -# $$ - -# ## Derivative of the cost function -# -# With these definitions we can now compute the derivative of the cost function in terms of the weights. -# -# Let us specialize to the output layer $l=L$. Our cost function is - -# $$ -# {\cal C}(\hat{W^L}) = \frac{1}{2}\sum_{i=1}^n\left(y_i - t_i\right)^2=\frac{1}{2}\sum_{i=1}^n\left(a_i^L - t_i\right)^2, -# $$ - -# The derivative of this function with respect to the weights is - -# $$ -# \frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \left(a_j^L - t_j\right)\frac{\partial a_j^L}{\partial w_{jk}^{L}}, -# $$ - -# The last partial derivative can easily be computed and reads (by applying the chain rule) - -# $$ -# \frac{\partial a_j^L}{\partial w_{jk}^{L}} = \frac{\partial a_j^L}{\partial z_{j}^{L}}\frac{\partial z_j^L}{\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1}, -# $$ - -# ## Bringing it together, first back propagation equation -# -# We have thus - -# $$ -# \frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \left(a_j^L - t_j\right)a_j^L(1-a_j^L)a_k^{L-1}, -# $$ - -# Defining - -# $$ -# \delta_j^L = a_j^L(1-a_j^L)\left(a_j^L - t_j\right) = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}, -# $$ - -# and using the Hadamard product of two vectors we can write this as - -# $$ -# \hat{\delta}^L = f'(\hat{z}^L)\circ\frac{\partial {\cal C}}{\partial (\hat{a}^L)}. -# $$ - -# This is an important expression. The second term on the right handside -# measures how fast the cost function is changing as a function of the $j$th -# output activation. If, for example, the cost function doesn't depend -# much on a particular output node $j$, then $\delta_j^L$ will be small, -# which is what we would expect. The first term on the right, measures -# how fast the activation function $f$ is changing at a given activation -# value $z_j^L$. -# -# Notice that everything in the above equations is easily computed. In -# particular, we compute $z_j^L$ while computing the behaviour of the -# network, and it is only a small additional overhead to compute -# $f'(z^L_j)$. The exact form of the derivative with respect to the -# output depends on the form of the cost function. -# However, provided the cost function is known there should be little -# trouble in calculating - -# $$ -# \frac{\partial {\cal C}}{\partial (a_j^L)} -# $$ - -# With the definition of $\delta_j^L$ we have a more compact definition of the derivative of the cost function in terms of the weights, namely - -# $$ -# \frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \delta_j^La_k^{L-1}. -# $$ - -# ## Derivatives in terms of $z_j^L$ -# -# It is also easy to see that our previous equation can be written as - -# $$ -# \delta_j^L =\frac{\partial {\cal C}}{\partial z_j^L}= \frac{\partial {\cal C}}{\partial a_j^L}\frac{\partial a_j^L}{\partial z_j^L}, -# $$ - -# which can also be interpreted as the partial derivative of the cost function with respect to the biases $b_j^L$, namely - -# $$ -# \delta_j^L = \frac{\partial {\cal C}}{\partial b_j^L}\frac{\partial b_j^L}{\partial z_j^L}=\frac{\partial {\cal C}}{\partial b_j^L}, -# $$ - -# That is, the error $\delta_j^L$ is exactly equal to the rate of change of the cost function as a function of the bias. - -# ## Bringing it together -# -# We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are -# -# **The starting equations.** - -# -#
    -# -# $$ -# \begin{equation} -# \frac{\partial{\cal C}(\hat{W^L})}{\partial w_{jk}^L} = \delta_j^La_k^{L-1}, -# \label{_auto8} \tag{13} -# \end{equation} -# $$ - -# and - -# -#
    -# -# $$ -# \begin{equation} -# \delta_j^L = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}, -# \label{_auto9} \tag{14} -# \end{equation} -# $$ - -# and - -# -#
    -# -# $$ -# \begin{equation} -# \delta_j^L = \frac{\partial {\cal C}}{\partial b_j^L}, -# \label{_auto10} \tag{15} -# \end{equation} -# $$ - -# An interesting consequence of the above equations is that when the -# activation $a_k^{L-1}$ is small, the gradient term, that is the -# derivative of the cost function with respect to the weights, will also -# tend to be small. We say then that the weight learns slowly, meaning -# that it changes slowly when we minimize the weights via say gradient -# descent. In this case we say the system learns slowly. -# -# Another interesting feature is that is when the activation function, -# represented by the sigmoid function here, is rather flat when we move towards -# its end values $0$ and $1$ (see the above Python codes). In these -# cases, the derivatives of the activation function will also be close -# to zero, meaning again that the gradients will be small and the -# network learns slowly again. -# -# We need a fourth equation and we are set. We are going to propagate -# backwards in order to the determine the weights and biases. In order -# to do so we need to represent the error in the layer before the final -# one $L-1$ in terms of the errors in the final output layer. - -# ## Final back propagating equation -# -# We have that (replacing $L$ with a general layer $l$) - -# $$ -# \delta_j^l =\frac{\partial {\cal C}}{\partial z_j^l}. -# $$ - -# We want to express this in terms of the equations for layer $l+1$. Using the chain rule and summing over all $k$ entries we have - -# $$ -# \delta_j^l =\sum_k \frac{\partial {\cal C}}{\partial z_k^{l+1}}\frac{\partial z_k^{l+1}}{\partial z_j^{l}}=\sum_k \delta_k^{l+1}\frac{\partial z_k^{l+1}}{\partial z_j^{l}}, -# $$ - -# and recalling that - -# $$ -# z_j^{l+1} = \sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1}, -# $$ - -# with $M_l$ being the number of nodes in layer $l$, we obtain - -# $$ -# \delta_j^l =\sum_k \delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l), -# $$ - -# This is our final equation. -# -# We are now ready to set up the algorithm for back propagation and learning the weights and biases. - -# ## Setting up the Back propagation algorithm -# -# The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm. -# -# First, we set up the input data $\hat{x}$ and the activations -# $\hat{z}_1$ of the input layer and compute the activation function and -# the pertinent outputs $\hat{a}^1$. -# -# Secondly, we perform then the feed forward till we reach the output -# layer and compute all $\hat{z}_l$ of the input layer and compute the -# activation function and the pertinent outputs $\hat{a}^l$ for -# $l=2,3,\dots,L$. -# -# Thereafter we compute the ouput error $\hat{\delta}^L$ by computing all - -# $$ -# \delta_j^L = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}. -# $$ - -# Then we compute the back propagate error for each $l=L-1,L-2,\dots,2$ as - -# $$ -# \delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l). -# $$ - -# Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\dots,2$ and update the weights and biases according to the rules - -# $$ -# w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, -# $$ - -# $$ -# b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, -# $$ - -# The parameter $\eta$ is the learning parameter discussed in connection with the gradient descent methods. -# Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training. - -# ## Setting up the Back propagation algorithm -# -# The four equations above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm. -# -# First, we set up the input data $\boldsymbol{x}$ and the activations -# $\boldsymbol{z}_1$ of the input layer and compute the activation function and -# the pertinent outputs $\boldsymbol{a}^1$. -# -# Secondly, we perform then the feed forward till we reach the output -# layer and compute all $\boldsymbol{z}_l$ of the input layer and compute the -# activation function and the pertinent outputs $\boldsymbol{a}^l$ for -# $l=2,3,\dots,L$. -# -# Thereafter we compute the ouput error $\boldsymbol{\delta}^L$ by computing all - -# $$ -# \delta_j^L = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}. -# $$ - -# Then we compute the back propagate error for each $l=L-1,L-2,\dots,2$ as - -# $$ -# \delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l). -# $$ - -# Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\dots,2$ and update the weights and biases according to the rules - -# $$ -# w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, -# $$ - -# $$ -# b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, -# $$ - -# The parameter $\eta$ is the learning parameter discussed in connection with the gradient descent methods. -# Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training. - -# ## Setting up the Back propagation algorithm -# -# The four equations derived discussed above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm. -# -# First, we set up the input data $\boldsymbol{x}$ and the activations -# $\boldsymbol{z}_1$ of the input layer and compute the activation function and -# the pertinent outputs $\boldsymbol{a}^1$. -# -# Secondly, we perform then the feed forward till we reach the output -# layer and compute all $\boldsymbol{z}_l$ of the input layer and compute the -# activation function and the pertinent outputs $\boldsymbol{a}^l$ for -# $l=2,3,\dots,L$. -# -# Thereafter we compute the ouput error $\boldsymbol{\delta}^L$ by computing all - -# $$ -# \delta_j^L = f'(z_j^L)\frac{\partial {\cal C}}{\partial (a_j^L)}. -# $$ - -# Then we compute the back propagate error for each $l=L-1,L-2,\dots,2$ as - -# $$ -# \delta_j^l = \sum_k \delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l). -# $$ - -# Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\dots,2$ and update the weights and biases according to the rules - -# $$ -# w_{jk}^l\leftarrow = w_{jk}^l- \eta \delta_j^la_k^{l-1}, -# $$ - -# $$ -# b_j^l \leftarrow b_j^l-\eta \frac{\partial {\cal C}}{\partial b_j^l}=b_j^l-\eta \delta_j^l, -# $$ - -# The parameter $\eta$ is the learning parameter discussed in connection with the gradient descent methods. -# Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training. - -# ## Setting up a Multi-layer perceptron model for classification -# -# We are now gong to develop an example based on the MNIST data -# base. This is a classification problem and we need to use our -# cross-entropy function we discussed in connection with logistic -# regression. The cross-entropy defines our cost function for the -# classificaton problems with neural networks. -# -# In binary classification with two classes $(0, 1)$ we define the -# logistic/sigmoid function as the probability that a particular input -# is in class $0$ or $1$. This is possible because the logistic -# function takes any input from the real numbers and inputs a number -# between 0 and 1, and can therefore be interpreted as a probability. It -# also has other nice properties, such as a derivative that is simple to -# calculate. -# -# For an input $\boldsymbol{a}$ from the hidden layer, the probability that the input $\boldsymbol{x}$ -# is in class 0 or 1 is just. We let $\theta$ represent the unknown weights and biases to be adjusted by our equations). The variable $x$ -# represents our activation values $z$. We have - -# $$ -# P(y = 0 \mid \boldsymbol{x}, \boldsymbol{\theta}) = \frac{1}{1 + \exp{(- \boldsymbol{x}})} , -# $$ - -# and - -# $$ -# P(y = 1 \mid \boldsymbol{x}, \boldsymbol{\theta}) = 1 - P(y = 0 \mid \boldsymbol{x}, \boldsymbol{\theta}) , -# $$ - -# where $y \in \{0, 1\}$ and $\boldsymbol{\theta}$ represents the weights and biases -# of our network. - -# ## Defining the cost function -# -# Our cost function is given as (see the Logistic regression lectures) - -# $$ -# \mathcal{C}(\boldsymbol{\theta}) = - \ln P(\mathcal{D} \mid \boldsymbol{\theta}) = - \sum_{i=1}^n -# y_i \ln[P(y_i = 0)] + (1 - y_i) \ln [1 - P(y_i = 0)] = \sum_{i=1}^n \mathcal{L}_i(\boldsymbol{\theta}) . -# $$ - -# This last equality means that we can interpret our *cost* function as a sum over the *loss* function -# for each point in the dataset $\mathcal{L}_i(\boldsymbol{\theta})$. -# The negative sign is just so that we can think about our algorithm as minimizing a positive number, rather -# than maximizing a negative number. -# -# In *multiclass* classification it is common to treat each integer label as a so called *one-hot* vector: -# -# $y = 5 \quad \rightarrow \quad \boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,$ and -# -# $y = 1 \quad \rightarrow \quad \boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,$ -# -# i.e. a binary bit string of length $C$, where $C = 10$ is the number of classes in the MNIST dataset (numbers from $0$ to $9$).. -# -# If $\boldsymbol{x}_i$ is the $i$-th input (image), $y_{ic}$ refers to the $c$-th component of the $i$-th -# output vector $\boldsymbol{y}_i$. -# The probability of $\boldsymbol{x}_i$ being in class $c$ will be given by the softmax function: - -# $$ -# P(y_{ic} = 1 \mid \boldsymbol{x}_i, \boldsymbol{\theta}) = \frac{\exp{((\boldsymbol{a}_i^{hidden})^T \boldsymbol{w}_c)}} -# {\sum_{c'=0}^{C-1} \exp{((\boldsymbol{a}_i^{hidden})^T \boldsymbol{w}_{c'})}} , -# $$ - -# which reduces to the logistic function in the binary case. -# The likelihood of this $C$-class classifier -# is now given as: - -# $$ -# P(\mathcal{D} \mid \boldsymbol{\theta}) = \prod_{i=1}^n \prod_{c=0}^{C-1} [P(y_{ic} = 1)]^{y_{ic}} . -# $$ - -# Again we take the negative log-likelihood to define our cost function: - -# $$ -# \mathcal{C}(\boldsymbol{\theta}) = - \log{P(\mathcal{D} \mid \boldsymbol{\theta})}. -# $$ - -# See the logistic regression lectures for a full definition of the cost function. -# -# The back propagation equations need now only a small change, namely the definition of a new cost function. We are thus ready to use the same equations as before! - -# ## Example: binary classification problem -# -# As an example of the above, relevant for project 2 as well, let us consider a binary class. As discussed in our logistic regression lectures, we defined a cost function in terms of the parameters $\beta$ as - -# $$ -# \mathcal{C}(\boldsymbol{\beta}) = - \sum_{i=1}^n \left(y_i\log{p(y_i \vert x_i,\boldsymbol{\beta})}+(1-y_i)\log{1-p(y_i \vert x_i,\boldsymbol{\beta})}\right), -# $$ - -# where we had defined the logistic (sigmoid) function - -# $$ -# p(y_i =1\vert x_i,\boldsymbol{\beta})=\frac{\exp{(\beta_0+\beta_1 x_i)}}{1+\exp{(\beta_0+\beta_1 x_i)}}, -# $$ - -# and - -# $$ -# p(y_i =0\vert x_i,\boldsymbol{\beta})=1-p(y_i =1\vert x_i,\boldsymbol{\beta}). -# $$ - -# The parameters $\boldsymbol{\beta}$ were defined using a minimization method like gradient descent or Newton-Raphson's method. -# -# Now we replace $x_i$ with the activation $z_i^l$ for a given layer $l$ and the outputs as $y_i=a_i^l=f(z_i^l)$, with $z_i^l$ now being a function of the weights $w_{ij}^l$ and biases $b_i^l$. -# We have then - -# $$ -# a_i^l = y_i = \frac{\exp{(z_i^l)}}{1+\exp{(z_i^l)}}, -# $$ - -# with - -# $$ -# z_i^l = \sum_{j}w_{ij}^l a_j^{l-1}+b_i^l, -# $$ - -# where the superscript $l-1$ indicates that these are the outputs from layer $l-1$. -# Our cost function at the final layer $l=L$ is now - -# $$ -# \mathcal{C}(\boldsymbol{W}) = - \sum_{i=1}^n \left(t_i\log{a_i^L}+(1-t_i)\log{(1-a_i^L)}\right), -# $$ - -# where we have defined the targets $t_i$. The derivatives of the cost function with respect to the output $a_i^L$ are then easily calculated and we get - -# $$ -# \frac{\partial \mathcal{C}(\boldsymbol{W})}{\partial a_i^L} = \frac{a_i^L-t_i}{a_i^L(1-a_i^L)}. -# $$ - -# In case we use another activation function than the logistic one, we need to evaluate other derivatives. - -# ## The Softmax function -# In case we employ the more general case given by the Softmax equation, we need to evaluate the derivative of the activation function with respect to the activation $z_i^l$, that is we need - -# $$ -# \frac{\partial f(z_i^l)}{\partial w_{jk}^l} = -# \frac{\partial f(z_i^l)}{\partial z_j^l} \frac{\partial z_j^l}{\partial w_{jk}^l}= \frac{\partial f(z_i^l)}{\partial z_j^l}a_k^{l-1}. -# $$ - -# For the Softmax function we have - -# $$ -# f(z_i^l) = \frac{\exp{(z_i^l)}}{\sum_{m=1}^K\exp{(z_m^l)}}. -# $$ - -# Its derivative with respect to $z_j^l$ gives - -# $$ -# \frac{\partial f(z_i^l)}{\partial z_j^l}= f(z_i^l)\left(\delta_{ij}-f(z_j^l)\right), -# $$ - -# which in case of the simply binary model reduces to having $i=j$. - -# ## Developing a code for doing neural networks with back propagation -# -# One can identify a set of key steps when using neural networks to solve supervised learning problems: -# -# 1. Collect and pre-process data -# -# 2. Define model and architecture -# -# 3. Choose cost function and optimizer -# -# 4. Train the model -# -# 5. Evaluate model performance on test data -# -# 6. Adjust hyperparameters (if necessary, network architecture) - -# ## Collect and pre-process data -# -# Here we will be using the MNIST dataset, which is readily available through the **scikit-learn** -# package. You may also find it for example [here](http://yann.lecun.com/exdb/mnist/). -# The *MNIST* (Modified National Institute of Standards and Technology) database is a large database -# of handwritten digits that is commonly used for training various image processing systems. -# The MNIST dataset consists of 70 000 images of size $28\times 28$ pixels, each labeled from 0 to 9. -# The scikit-learn dataset we will use consists of a selection of 1797 images of size $8\times 8$ collected and processed from this database. -# -# To feed data into a feed-forward neural network we need to represent -# the inputs as a design/feature matrix $X = (n_{inputs}, n_{features})$. Each -# row represents an *input*, in this case a handwritten digit, and -# each column represents a *feature*, in this case a pixel. The -# correct answers, also known as *labels* or *targets* are -# represented as a 1D array of integers -# $Y = (n_{inputs}) = (5, 3, 1, 8,...)$. -# -# As an example, say we want to build a neural network using supervised learning to predict Body-Mass Index (BMI) from -# measurements of height (in m) -# and weight (in kg). If we have measurements of 5 people the design/feature matrix could be for example: -# -# $$ X = \begin{bmatrix} -# 1.85 & 81\\ -# 1.71 & 65\\ -# 1.95 & 103\\ -# 1.55 & 42\\ -# 1.63 & 56 -# \end{bmatrix} ,$$ -# -# and the targets would be: -# -# $$ Y = (23.7, 22.2, 27.1, 17.5, 21.1) $$ -# -# Since each input image is a 2D matrix, we need to flatten the image -# (i.e. "unravel" the 2D matrix into a 1D array) to turn the data into a -# design/feature matrix. This means we lose all spatial information in the -# image, such as locality and translational invariance. More complicated -# architectures such as Convolutional Neural Networks can take advantage -# of such information, and are most commonly applied when analyzing -# images. - -# In[5]: - - -# import necessary packages -import numpy as np -import matplotlib.pyplot as plt -from sklearn import datasets - - -# ensure the same random numbers appear every time -np.random.seed(0) - -# display images in notebook -get_ipython().run_line_magic('matplotlib', 'inline') -plt.rcParams['figure.figsize'] = (12,12) - - -# download MNIST dataset -digits = datasets.load_digits() - -# define inputs and labels -inputs = digits.images -labels = digits.target - -print("inputs = (n_inputs, pixel_width, pixel_height) = " + str(inputs.shape)) -print("labels = (n_inputs) = " + str(labels.shape)) - - -# flatten the image -# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64 -n_inputs = len(inputs) -inputs = inputs.reshape(n_inputs, -1) -print("X = (n_inputs, n_features) = " + str(inputs.shape)) - - -# choose some random images to display -indices = np.arange(n_inputs) -random_indices = np.random.choice(indices, size=5) - -for i, image in enumerate(digits.images[random_indices]): - plt.subplot(1, 5, i+1) - plt.axis('off') - plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest') - plt.title("Label: %d" % digits.target[random_indices[i]]) -plt.show() - - -# ## Train and test datasets -# -# Performing analysis before partitioning the dataset is a major error, that can lead to incorrect conclusions. -# -# We will reserve $80 \%$ of our dataset for training and $20 \%$ for testing. -# -# It is important that the train and test datasets are drawn randomly from our dataset, to ensure -# no bias in the sampling. -# Say you are taking measurements of weather data to predict the weather in the coming 5 days. -# You don't want to train your model on measurements taken from the hours 00.00 to 12.00, and then test it on data -# collected from 12.00 to 24.00. - -# In[6]: - - -from sklearn.model_selection import train_test_split - -# one-liner from scikit-learn library -train_size = 0.8 -test_size = 1 - train_size -X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size, - test_size=test_size) - -# equivalently in numpy -def train_test_split_numpy(inputs, labels, train_size, test_size): - n_inputs = len(inputs) - inputs_shuffled = inputs.copy() - labels_shuffled = labels.copy() - - np.random.shuffle(inputs_shuffled) - np.random.shuffle(labels_shuffled) - - train_end = int(n_inputs*train_size) - X_train, X_test = inputs_shuffled[:train_end], inputs_shuffled[train_end:] - Y_train, Y_test = labels_shuffled[:train_end], labels_shuffled[train_end:] - - return X_train, X_test, Y_train, Y_test - -#X_train, X_test, Y_train, Y_test = train_test_split_numpy(inputs, labels, train_size, test_size) - -print("Number of training images: " + str(len(X_train))) -print("Number of test images: " + str(len(X_test))) - - -# ## Define model and architecture -# -# Our simple feed-forward neural network will consist of an *input* layer, a single *hidden* layer and an *output* layer. The activation $y$ of each neuron is a weighted sum of inputs, passed through an activation function. In case of the simple perceptron model we have -# -# $$ z = \sum_{i=1}^n w_i a_i ,$$ -# -# $$ y = f(z) ,$$ -# -# where $f$ is the activation function, $a_i$ represents input from neuron $i$ in the preceding layer -# and $w_i$ is the weight to input $i$. -# The activation of the neurons in the input layer is just the features (e.g. a pixel value). -# -# The simplest activation function for a neuron is the *Heaviside* function: -# -# $$ f(z) = -# \begin{cases} -# 1, & z > 0\\ -# 0, & \text{otherwise} -# \end{cases} -# $$ -# -# A feed-forward neural network with this activation is known as a *perceptron*. -# For a binary classifier (i.e. two classes, 0 or 1, dog or not-dog) we can also use this in our output layer. -# This activation can be generalized to $k$ classes (using e.g. the *one-against-all* strategy), -# and we call these architectures *multiclass perceptrons*. -# -# However, it is now common to use the terms Single Layer Perceptron (SLP) (1 hidden layer) and -# Multilayer Perceptron (MLP) (2 or more hidden layers) to refer to feed-forward neural networks with any activation function. -# -# Typical choices for activation functions include the sigmoid function, hyperbolic tangent, and Rectified Linear Unit (ReLU). -# We will be using the sigmoid function $\sigma(x)$: -# -# $$ f(x) = \sigma(x) = \frac{1}{1 + e^{-x}} ,$$ -# -# which is inspired by probability theory (see logistic regression) and was most commonly used until about 2011. See the discussion below concerning other activation functions. - -# ## Layers -# -# * Input -# -# Since each input image has 8x8 = 64 pixels or features, we have an input layer of 64 neurons. -# -# * Hidden layer -# -# We will use 50 neurons in the hidden layer receiving input from the neurons in the input layer. -# Since each neuron in the hidden layer is connected to the 64 inputs we have 64x50 = 3200 weights to the hidden layer. -# -# * Output -# -# If we were building a binary classifier, it would be sufficient with a single neuron in the output layer, -# which could output 0 or 1 according to the Heaviside function. This would be an example of a *hard* classifier, meaning it outputs the class of the input directly. However, if we are dealing with noisy data it is often beneficial to use a *soft* classifier, which outputs the probability of being in class 0 or 1. -# -# For a soft binary classifier, we could use a single neuron and interpret the output as either being the probability of being in class 0 or the probability of being in class 1. Alternatively we could use 2 neurons, and interpret each neuron as the probability of being in each class. -# -# Since we are doing multiclass classification, with 10 categories, it is natural to use 10 neurons in the output layer. We number the neurons $j = 0,1,...,9$. The activation of each output neuron $j$ will be according to the *softmax* function: -# -# $$ P(\text{class $j$} \mid \text{input $\boldsymbol{a}$}) = \frac{\exp{(\boldsymbol{a}^T \boldsymbol{w}_j)}} -# {\sum_{c=0}^{9} \exp{(\boldsymbol{a}^T \boldsymbol{w}_c)}} ,$$ -# -# i.e. each neuron $j$ outputs the probability of being in class $j$ given an input from the hidden layer $\boldsymbol{a}$, with $\boldsymbol{w}_j$ the weights of neuron $j$ to the inputs. -# The denominator is a normalization factor to ensure the outputs (probabilities) sum up to 1. -# The exponent is just the weighted sum of inputs as before: -# -# $$ z_j = \sum_{i=1}^n w_ {ij} a_i+b_j.$$ -# -# Since each neuron in the output layer is connected to the 50 inputs from the hidden layer we have 50x10 = 500 -# weights to the output layer. - -# ## Weights and biases -# -# Typically weights are initialized with small values distributed around zero, drawn from a uniform -# or normal distribution. Setting all weights to zero means all neurons give the same output, making the network useless. -# -# Adding a bias value to the weighted sum of inputs allows the neural network to represent a greater range -# of values. Without it, any input with the value 0 will be mapped to zero (before being passed through the activation). The bias unit has an output of 1, and a weight to each neuron $j$, $b_j$: -# -# $$ z_j = \sum_{i=1}^n w_ {ij} a_i + b_j.$$ -# -# The bias weights $\boldsymbol{b}$ are often initialized to zero, but a small value like $0.01$ ensures all neurons have some output which can be backpropagated in the first training cycle. - -# In[7]: - - -# building our neural network - -n_inputs, n_features = X_train.shape -n_hidden_neurons = 50 -n_categories = 10 - -# we make the weights normally distributed using numpy.random.randn - -# weights and bias in the hidden layer -hidden_weights = np.random.randn(n_features, n_hidden_neurons) -hidden_bias = np.zeros(n_hidden_neurons) + 0.01 - -# weights and bias in the output layer -output_weights = np.random.randn(n_hidden_neurons, n_categories) -output_bias = np.zeros(n_categories) + 0.01 - - -# ## Feed-forward pass -# -# Denote $F$ the number of features, $H$ the number of hidden neurons and $C$ the number of categories. -# For each input image we calculate a weighted sum of input features (pixel values) to each neuron $j$ in the hidden layer $l$: -# -# $$ z_{j}^{l} = \sum_{i=1}^{F} w_{ij}^{l} x_i + b_{j}^{l},$$ -# -# this is then passed through our activation function -# -# $$ a_{j}^{l} = f(z_{j}^{l}) .$$ -# -# We calculate a weighted sum of inputs (activations in the hidden layer) to each neuron $j$ in the output layer: -# -# $$ z_{j}^{L} = \sum_{i=1}^{H} w_{ij}^{L} a_{i}^{l} + b_{j}^{L}.$$ -# -# Finally we calculate the output of neuron $j$ in the output layer using the softmax function: -# -# $$ a_{j}^{L} = \frac{\exp{(z_j^{L})}} -# {\sum_{c=0}^{C-1} \exp{(z_c^{L})}} .$$ - -# ## Matrix multiplications -# -# Since our data has the dimensions $X = (n_{inputs}, n_{features})$ and our weights to the hidden -# layer have the dimensions -# $W_{hidden} = (n_{features}, n_{hidden})$, -# we can easily feed the network all our training data in one go by taking the matrix product -# -# $$ X W^{h} = (n_{inputs}, n_{hidden}),$$ -# -# and obtain a matrix that holds the weighted sum of inputs to the hidden layer -# for each input image and each hidden neuron. -# We also add the bias to obtain a matrix of weighted sums to the hidden layer $Z^{h}$: -# -# $$ \boldsymbol{z}^{l} = \boldsymbol{X} \boldsymbol{W}^{l} + \boldsymbol{b}^{l} ,$$ -# -# meaning the same bias (1D array with size equal number of hidden neurons) is added to each input image. -# This is then passed through the activation: -# -# $$ \boldsymbol{a}^{l} = f(\boldsymbol{z}^l) .$$ -# -# This is fed to the output layer: -# -# $$ \boldsymbol{z}^{L} = \boldsymbol{a}^{L} \boldsymbol{W}^{L} + \boldsymbol{b}^{L} .$$ -# -# Finally we receive our output values for each image and each category by passing it through the softmax function: -# -# $$ output = softmax (\boldsymbol{z}^{L}) = (n_{inputs}, n_{categories}) .$$ - -# In[8]: - - -# setup the feed-forward pass, subscript h = hidden layer +# The technique consists of adding an operation in the model just before +# the activation function of each layer, simply zero-centering and +# normalizing the inputs, then scaling and shifting the result using two +# new parameters per layer (one for scaling, the other for shifting). In +# other words, this operation lets the model learn the optimal scale and +# mean of the inputs for each layer. In order to zero-center and +# normalize the inputs, the algorithm needs to estimate the inputs’ mean +# and standard deviation. It does so by evaluating the mean and standard +# deviation of the inputs over the current mini-batch, from this the +# name batch normalization. -def sigmoid(x): - return 1/(1 + np.exp(-x)) - -def feed_forward(X): - # weighted sum of inputs to the hidden layer - z_h = np.matmul(X, hidden_weights) + hidden_bias - # activation in the hidden layer - a_h = sigmoid(z_h) - - # weighted sum of inputs to the output layer - z_o = np.matmul(a_h, output_weights) + output_bias - # softmax output - # axis 0 holds each input and axis 1 the probabilities of each category - exp_term = np.exp(z_o) - probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True) - - return probabilities - -probabilities = feed_forward(X_train) -print("probabilities = (n_inputs, n_categories) = " + str(probabilities.shape)) -print("probability that image 0 is in category 0,1,2,...,9 = \n" + str(probabilities[0])) -print("probabilities sum up to: " + str(probabilities[0].sum())) -print() - -# we obtain a prediction by taking the class with the highest likelihood -def predict(X): - probabilities = feed_forward(X) - return np.argmax(probabilities, axis=1) - -predictions = predict(X_train) -print("predictions = (n_inputs) = " + str(predictions.shape)) -print("prediction for image 0: " + str(predictions[0])) -print("correct label for image 0: " + str(Y_train[0])) - - -# ## Choose cost function and optimizer -# -# To measure how well our neural network is doing we need to introduce a cost function. -# We will call the function that gives the error of a single sample output the *loss* function, and the function -# that gives the total error of our network across all samples the *cost* function. -# A typical choice for multiclass classification is the *cross-entropy* loss, also known as the negative log likelihood. -# -# In *multiclass* classification it is common to treat each integer label as a so called *one-hot* vector: -# -# $$ y = 5 \quad \rightarrow \quad \boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,$$ -# -# $$ y = 1 \quad \rightarrow \quad \boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,$$ -# -# i.e. a binary bit string of length $C$, where $C = 10$ is the number of classes in the MNIST dataset. -# -# Let $y_{ic}$ denote the $c$-th component of the $i$-th one-hot vector. -# We define the cost function $\mathcal{C}$ as a sum over the cross-entropy loss for each point $\boldsymbol{x}_i$ in the dataset. -# -# In the one-hot representation only one of the terms in the loss function is non-zero, namely the -# probability of the correct category $c'$ -# (i.e. the category $c'$ such that $y_{ic'} = 1$). This means that the cross entropy loss only punishes you for how wrong -# you got the correct label. The probability of category $c$ is given by the softmax function. The vector $\boldsymbol{\theta}$ represents the parameters of our network, i.e. all the weights and biases. - -# ## Optimizing the cost function -# -# The network is trained by finding the weights and biases that minimize the cost function. One of the most widely used classes of methods is *gradient descent* and its generalizations. The idea behind gradient descent -# is simply to adjust the weights in the direction where the gradient of the cost function is large and negative. This ensures we flow toward a *local* minimum of the cost function. -# Each parameter $\theta$ is iteratively adjusted according to the rule -# -# $$ \theta_{i+1} = \theta_i - \eta \nabla \mathcal{C}(\theta_i) ,$$ +# ## Dropout # -# where $\eta$ is known as the *learning rate*, which controls how big a step we take towards the minimum. -# This update can be repeated for any number of iterations, or until we are satisfied with the result. +# It is a fairly simple algorithm: at every training step, every neuron +# (including the input neurons but excluding the output neurons) has a +# probability $p$ of being temporarily dropped out, meaning it will be +# entirely ignored during this training step, but it may be active +# during the next step. # -# A simple and effective improvement is a variant called *Batch Gradient Descent*. -# Instead of calculating the gradient on the whole dataset, we calculate an approximation of the gradient -# on a subset of the data called a *minibatch*. -# If there are $N$ data points and we have a minibatch size of $M$, the total number of batches -# is $N/M$. -# We denote each minibatch $B_k$, with $k = 1, 2,...,N/M$. The gradient then becomes: -# -# $$ \nabla \mathcal{C}(\theta) = \frac{1}{N} \sum_{i=1}^N \nabla \mathcal{L}_i(\theta) \quad \rightarrow \quad -# \frac{1}{M} \sum_{i \in B_k} \nabla \mathcal{L}_i(\theta) ,$$ -# -# i.e. instead of averaging the loss over the entire dataset, we average over a minibatch. -# -# This has two important benefits: -# 1. Introducing stochasticity decreases the chance that the algorithm becomes stuck in a local minima. -# -# 2. It significantly speeds up the calculation, since we do not have to use the entire dataset to calculate the gradient. -# -# The various optmization methods, with codes and algorithms, are discussed in our lectures on [Gradient descent approaches](https://compphysics.github.io/MachineLearning/doc/pub/Splines/html/Splines-bs.html). - -# ## Regularization -# -# It is common to add an extra term to the cost function, proportional -# to the size of the weights. This is equivalent to constraining the -# size of the weights, so that they do not grow out of control. -# Constraining the size of the weights means that the weights cannot -# grow arbitrarily large to fit the training data, and in this way -# reduces *overfitting*. -# -# We will measure the size of the weights using the so called *L2-norm*, meaning our cost function becomes: -# -# $$ \mathcal{C}(\theta) = \frac{1}{N} \sum_{i=1}^N \mathcal{L}_i(\theta) \quad \rightarrow \quad -# \frac{1}{N} \sum_{i=1}^N \mathcal{L}_i(\theta) + \lambda \lvert \lvert \boldsymbol{w} \rvert \rvert_2^2 -# = \frac{1}{N} \sum_{i=1}^N \mathcal{L}(\theta) + \lambda \sum_{ij} w_{ij}^2,$$ -# -# i.e. we sum up all the weights squared. The factor $\lambda$ is known as a regularization parameter. -# -# In order to train the model, we need to calculate the derivative of -# the cost function with respect to every bias and weight in the -# network. In total our network has $(64 + 1)\times 50=3250$ weights in -# the hidden layer and $(50 + 1)\times 10=510$ weights to the output -# layer ($+1$ for the bias), and the gradient must be calculated for -# every parameter. We use the *backpropagation* algorithm discussed -# above. This is a clever use of the chain rule that allows us to -# calculate the gradient efficently. +# The hyperparameter $p$ is called the dropout rate, and it is typically +# set to 50%. After training, the neurons are not dropped anymore. It +# is viewed as one of the most popular regularization techniques. -# ## Matrix multiplication -# -# To more efficently train our network these equations are implemented using matrix operations. -# The error in the output layer is calculated simply as, with $\boldsymbol{t}$ being our targets, -# -# $$ \delta_L = \boldsymbol{t} - \boldsymbol{y} = (n_{inputs}, n_{categories}) .$$ -# -# The gradient for the output weights is calculated as -# -# $$ \nabla W_{L} = \boldsymbol{a}^T \delta_L = (n_{hidden}, n_{categories}) ,$$ -# -# where $\boldsymbol{a} = (n_{inputs}, n_{hidden})$. This simply means that we are summing up the gradients for each input. -# Since we are going backwards we have to transpose the activation matrix. +# ## Gradient Clipping # -# The gradient with respect to the output bias is then +# A popular technique to lessen the exploding gradients problem is to +# simply clip the gradients during backpropagation so that they never +# exceed some threshold (this is mostly useful for recurrent neural +# networks). # -# $$ \nabla \boldsymbol{b}_{L} = \sum_{i=1}^{n_{inputs}} \delta_L = (n_{categories}) .$$ +# This technique is called Gradient Clipping. # -# The error in the hidden layer is -# -# $$ \Delta_h = \delta_L W_{L}^T \circ f'(z_{h}) = \delta_L W_{L}^T \circ a_{h} \circ (1 - a_{h}) = (n_{inputs}, n_{hidden}) ,$$ -# -# where $f'(a_{h})$ is the derivative of the activation in the hidden layer. The matrix products mean -# that we are summing up the products for each neuron in the output layer. The symbol $\circ$ denotes -# the *Hadamard product*, meaning element-wise multiplication. -# -# This again gives us the gradients in the hidden layer: -# -# $$ \nabla W_{h} = X^T \delta_h = (n_{features}, n_{hidden}) ,$$ -# -# $$ \nabla b_{h} = \sum_{i=1}^{n_{inputs}} \delta_h = (n_{hidden}) .$$ - -# In[9]: - - -# to categorical turns our integer vector into a onehot representation -from sklearn.metrics import accuracy_score - -# one-hot in numpy -def to_categorical_numpy(integer_vector): - n_inputs = len(integer_vector) - n_categories = np.max(integer_vector) + 1 - onehot_vector = np.zeros((n_inputs, n_categories)) - onehot_vector[range(n_inputs), integer_vector] = 1 - - return onehot_vector - -#Y_train_onehot, Y_test_onehot = to_categorical(Y_train), to_categorical(Y_test) -Y_train_onehot, Y_test_onehot = to_categorical_numpy(Y_train), to_categorical_numpy(Y_test) - -def feed_forward_train(X): - # weighted sum of inputs to the hidden layer - z_h = np.matmul(X, hidden_weights) + hidden_bias - # activation in the hidden layer - a_h = sigmoid(z_h) - - # weighted sum of inputs to the output layer - z_o = np.matmul(a_h, output_weights) + output_bias - # softmax output - # axis 0 holds each input and axis 1 the probabilities of each category - exp_term = np.exp(z_o) - probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True) - - # for backpropagation need activations in hidden and output layers - return a_h, probabilities - -def backpropagation(X, Y): - a_h, probabilities = feed_forward_train(X) - - # error in the output layer - error_output = probabilities - Y - # error in the hidden layer - error_hidden = np.matmul(error_output, output_weights.T) * a_h * (1 - a_h) - - # gradients for the output layer - output_weights_gradient = np.matmul(a_h.T, error_output) - output_bias_gradient = np.sum(error_output, axis=0) - - # gradient for the hidden layer - hidden_weights_gradient = np.matmul(X.T, error_hidden) - hidden_bias_gradient = np.sum(error_hidden, axis=0) - - return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient - -print("Old accuracy on training data: " + str(accuracy_score(predict(X_train), Y_train))) - -eta = 0.01 -lmbd = 0.01 -for i in range(1000): - # calculate gradients - dWo, dBo, dWh, dBh = backpropagation(X_train, Y_train_onehot) - - # regularization term gradients - dWo += lmbd * output_weights - dWh += lmbd * hidden_weights - - # update weights and biases - output_weights -= eta * dWo - output_bias -= eta * dBo - hidden_weights -= eta * dWh - hidden_bias -= eta * dBh - -print("New accuracy on training data: " + str(accuracy_score(predict(X_train), Y_train))) +# In general however, Batch +# Normalization is preferred. - -# ## Improving performance -# -# As we can see the network does not seem to be learning at all. It seems to be just guessing the label for each image. -# In order to obtain a network that does something useful, we will have to do a bit more work. +# ## A top-down perspective on Neural networks # -# The choice of *hyperparameters* such as learning rate and regularization parameter is hugely influential for the performance of the network. Typically a *grid-search* is performed, wherein we test different hyperparameters separated by orders of magnitude. For example we could test the learning rates $\eta = 10^{-6}, 10^{-5},...,10^{-1}$ with different regularization parameters $\lambda = 10^{-6},...,10^{-0}$. +# The first thing we would like to do is divide the data into two or +# three parts. A training set, a validation or dev (development) set, +# and a test set. The test set is the data on which we want to make +# predictions. The dev set is a subset of the training data we use to +# check how well we are doing out-of-sample, after training the model on +# the training dataset. We use the validation error as a proxy for the +# test error in order to make tweaks to our model. It is crucial that we +# do not use any of the test data to train the algorithm. This is a +# cardinal sin in ML. Then: # -# Next, we haven't implemented minibatching yet, which introduces stochasticity and is though to act as an important regularizer on the weights. We call a feed-forward + backward pass with a minibatch an *iteration*, and a full training period -# going through the entire dataset ($n/M$ batches) an *epoch*. +# 1. Estimate optimal error rate # -# If this does not improve network performance, you may want to consider altering the network architecture, adding more neurons or hidden layers. -# Andrew Ng goes through some of these considerations in this [video](https://youtu.be/F1ka6a13S9I). You can find a summary of the video [here](https://kevinzakka.github.io/2016/09/26/applying-deep-learning/). - -# ## Full object-oriented implementation +# 2. Minimize underfitting (bias) on training data set. # -# It is very natural to think of the network as an object, with specific instances of the network -# being realizations of this object with different hyperparameters. An implementation using Python classes provides a clean structure and interface, and the full implementation of our neural network is given below. - -# In[10]: - - -class NeuralNetwork: - def __init__( - self, - X_data, - Y_data, - n_hidden_neurons=50, - n_categories=10, - epochs=10, - batch_size=100, - eta=0.1, - lmbd=0.0): - - self.X_data_full = X_data - self.Y_data_full = Y_data - - self.n_inputs = X_data.shape[0] - self.n_features = X_data.shape[1] - self.n_hidden_neurons = n_hidden_neurons - self.n_categories = n_categories - - self.epochs = epochs - self.batch_size = batch_size - self.iterations = self.n_inputs // self.batch_size - self.eta = eta - self.lmbd = lmbd - - self.create_biases_and_weights() - - def create_biases_and_weights(self): - self.hidden_weights = np.random.randn(self.n_features, self.n_hidden_neurons) - self.hidden_bias = np.zeros(self.n_hidden_neurons) + 0.01 - - self.output_weights = np.random.randn(self.n_hidden_neurons, self.n_categories) - self.output_bias = np.zeros(self.n_categories) + 0.01 - - def feed_forward(self): - # feed-forward for training - self.z_h = np.matmul(self.X_data, self.hidden_weights) + self.hidden_bias - self.a_h = sigmoid(self.z_h) - - self.z_o = np.matmul(self.a_h, self.output_weights) + self.output_bias - - exp_term = np.exp(self.z_o) - self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True) - - def feed_forward_out(self, X): - # feed-forward for output - z_h = np.matmul(X, self.hidden_weights) + self.hidden_bias - a_h = sigmoid(z_h) +# 3. Make sure you are not overfitting. - z_o = np.matmul(a_h, self.output_weights) + self.output_bias - - exp_term = np.exp(z_o) - probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True) - return probabilities - - def backpropagation(self): - error_output = self.probabilities - self.Y_data - error_hidden = np.matmul(error_output, self.output_weights.T) * self.a_h * (1 - self.a_h) - - self.output_weights_gradient = np.matmul(self.a_h.T, error_output) - self.output_bias_gradient = np.sum(error_output, axis=0) - - self.hidden_weights_gradient = np.matmul(self.X_data.T, error_hidden) - self.hidden_bias_gradient = np.sum(error_hidden, axis=0) - - if self.lmbd > 0.0: - self.output_weights_gradient += self.lmbd * self.output_weights - self.hidden_weights_gradient += self.lmbd * self.hidden_weights - - self.output_weights -= self.eta * self.output_weights_gradient - self.output_bias -= self.eta * self.output_bias_gradient - self.hidden_weights -= self.eta * self.hidden_weights_gradient - self.hidden_bias -= self.eta * self.hidden_bias_gradient - - def predict(self, X): - probabilities = self.feed_forward_out(X) - return np.argmax(probabilities, axis=1) - - def predict_probabilities(self, X): - probabilities = self.feed_forward_out(X) - return probabilities - - def train(self): - data_indices = np.arange(self.n_inputs) - - for i in range(self.epochs): - for j in range(self.iterations): - # pick datapoints with replacement - chosen_datapoints = np.random.choice( - data_indices, size=self.batch_size, replace=False - ) - - # minibatch training data - self.X_data = self.X_data_full[chosen_datapoints] - self.Y_data = self.Y_data_full[chosen_datapoints] - - self.feed_forward() - self.backpropagation() - - -# ## Evaluate model performance on test data -# -# To measure the performance of our network we evaluate how well it does it data it has never seen before, i.e. the test data. -# We measure the performance of the network using the *accuracy* score. -# The accuracy is as you would expect just the number of images correctly labeled divided by the total number of images. A perfect classifier will have an accuracy score of $1$. +# ## More top-down perspectives # -# $$ \text{Accuracy} = \frac{\sum_{i=1}^n I(\tilde{y}_i = y_i)}{n} ,$$ +# If the validation and test sets are drawn from the same distributions, +# then a good performance on the validation set should lead to similarly +# good performance on the test set. # -# where $I$ is the indicator function, $1$ if $\tilde{y}_i = y_i$ and $0$ otherwise. - -# In[11]: - +# However, sometimes +# the training data and test data differ in subtle ways because, for +# example, they are collected using slightly different methods, or +# because it is cheaper to collect data in one way versus another. In +# this case, there can be a mismatch between the training and test +# data. This can lead to the neural network overfitting these small +# differences between the test and training sets, and a poor performance +# on the test set despite having a good performance on the validation +# set. To rectify this, Andrew Ng suggests making two validation or dev +# sets, one constructed from the training data and one constructed from +# the test data. The difference between the performance of the algorithm +# on these two validation sets quantifies the train-test mismatch. This +# can serve as another important diagnostic when using DNNs for +# supervised learning. -epochs = 100 -batch_size = 100 - -dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size, - n_hidden_neurons=n_hidden_neurons, n_categories=n_categories) -dnn.train() -test_predict = dnn.predict(X_test) - -# accuracy score from scikit library -print("Accuracy score on test set: ", accuracy_score(Y_test, test_predict)) - -# equivalent in numpy -def accuracy_score_numpy(Y_test, Y_pred): - return np.sum(Y_test == Y_pred) / len(Y_test) - -#print("Accuracy score on test set: ", accuracy_score_numpy(Y_test, test_predict)) - - -# ## Adjust hyperparameters +# ## Limitations of supervised learning with deep networks # -# We now perform a grid search to find the optimal hyperparameters for the network. -# Note that we are only using 1 layer with 50 neurons, and human performance is estimated to be around $98\%$ ($2\%$ error rate). - -# In[12]: - - -eta_vals = np.logspace(-5, 1, 7) -lmbd_vals = np.logspace(-5, 1, 7) -# store the models for later use -DNN_numpy = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object) - -# grid search -for i, eta in enumerate(eta_vals): - for j, lmbd in enumerate(lmbd_vals): - dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size, - n_hidden_neurons=n_hidden_neurons, n_categories=n_categories) - dnn.train() - - DNN_numpy[i][j] = dnn - - test_predict = dnn.predict(X_test) - - print("Learning rate = ", eta) - print("Lambda = ", lmbd) - print("Accuracy score on test set: ", accuracy_score(Y_test, test_predict)) - print() - - -# ## Visualization - -# In[13]: - - -# visual representation of grid search -# uses seaborn heatmap, you can also do this with matplotlib imshow -import seaborn as sns - -sns.set() +# Like all statistical methods, supervised learning using neural +# networks has important limitations. This is especially important when +# one seeks to apply these methods, especially to physics problems. Like +# all tools, DNNs are not a universal solution. Often, the same or +# better performance on a task can be achieved by using a few +# hand-engineered features (or even a collection of random +# features). -train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals))) -test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals))) - -for i in range(len(eta_vals)): - for j in range(len(lmbd_vals)): - dnn = DNN_numpy[i][j] - - train_pred = dnn.predict(X_train) - test_pred = dnn.predict(X_test) - - train_accuracy[i][j] = accuracy_score(Y_train, train_pred) - test_accuracy[i][j] = accuracy_score(Y_test, test_pred) - - -fig, ax = plt.subplots(figsize = (10, 10)) -sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis") -ax.set_title("Training Accuracy") -ax.set_ylabel("$\eta$") -ax.set_xlabel("$\lambda$") -plt.show() - -fig, ax = plt.subplots(figsize = (10, 10)) -sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis") -ax.set_title("Test Accuracy") -ax.set_ylabel("$\eta$") -ax.set_xlabel("$\lambda$") -plt.show() - - -# ## scikit-learn implementation +# ## Limitations of NNs # -# **scikit-learn** focuses more -# on traditional machine learning methods, such as regression, -# clustering, decision trees, etc. As such, it has only two types of -# neural networks: Multi Layer Perceptron outputting continuous values, -# *MPLRegressor*, and Multi Layer Perceptron outputting labels, -# *MLPClassifier*. We will see how simple it is to use these classes. -# -# **scikit-learn** implements a few improvements from our neural network, -# such as early stopping, a varying learning rate, different -# optimization methods, etc. We would therefore expect a better -# performance overall. - -# In[14]: - - -from sklearn.neural_network import MLPClassifier -# store models for later use -DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object) - -for i, eta in enumerate(eta_vals): - for j, lmbd in enumerate(lmbd_vals): - dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic', - alpha=lmbd, learning_rate_init=eta, max_iter=epochs) - dnn.fit(X_train, Y_train) - - DNN_scikit[i][j] = dnn - - print("Learning rate = ", eta) - print("Lambda = ", lmbd) - print("Accuracy score on test set: ", dnn.score(X_test, Y_test)) - print() - - -# ## Visualization - -# In[15]: - - -# optional -# visual representation of grid search -# uses seaborn heatmap, could probably do this in matplotlib -import seaborn as sns - -sns.set() - -train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals))) -test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals))) - -for i in range(len(eta_vals)): - for j in range(len(lmbd_vals)): - dnn = DNN_scikit[i][j] - - train_pred = dnn.predict(X_train) - test_pred = dnn.predict(X_test) - - train_accuracy[i][j] = accuracy_score(Y_train, train_pred) - test_accuracy[i][j] = accuracy_score(Y_test, test_pred) - - -fig, ax = plt.subplots(figsize = (10, 10)) -sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis") -ax.set_title("Training Accuracy") -ax.set_ylabel("$\eta$") -ax.set_xlabel("$\lambda$") -plt.show() - -fig, ax = plt.subplots(figsize = (10, 10)) -sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis") -ax.set_title("Test Accuracy") -ax.set_ylabel("$\eta$") -ax.set_xlabel("$\lambda$") -plt.show() - - -# ## Testing our code for the XOR, OR and AND gates +# Here we list some of the important limitations of supervised neural network based models. # -# Last week we discussed three different types of gates, the so-called -# XOR, the OR and the AND gates. Their inputs and outputs can be -# summarized using the following tables, first for the OR gate with -# inputs $x_1$ and $x_2$ and outputs $y$: +# * **Need labeled data**. All supervised learning methods, DNNs for supervised learning require labeled data. Often, labeled data is harder to acquire than unlabeled data (e.g. one must pay for human experts to label images). # -# -# -# -# -# -# -# -# -# -# -#
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 1
    1 0 1
    1 1 1
    +# * **Supervised neural networks are extremely data intensive.** DNNs are data hungry. They perform best when data is plentiful. This is doubly so for supervised methods where the data must also be labeled. The utility of DNNs is extremely limited if data is hard to acquire or the datasets are small (hundreds to a few thousand samples). In this case, the performance of other methods that utilize hand-engineered features can exceed that of DNNs. -# ## The AND and XOR Gates +# ## Homogeneous data # -# The AND gate is defined as -# -# -# -# -# -# -# -# -# -# -# -#
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 0
    1 0 0
    1 1 1
    -# -# And finally we have the XOR gate -# -# -# -# -# -# -# -# -# -# -# -#
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 1
    1 0 1
    1 1 0
    +# * **Homogeneous data.** Almost all DNNs deal with homogeneous data of one type. It is very hard to design architectures that mix and match data types (i.e. some continuous variables, some discrete variables, some time series). In applications beyond images, video, and language, this is often what is required. In contrast, ensemble models like random forests or gradient-boosted trees have no difficulty handling mixed data types. -# ## Representing the Data Sets +# ## More limitations # -# Our design matrix is defined by the input values $x_1$ and $x_2$. Since we have four possible outputs, our design matrix reads - -# $$ -# \boldsymbol{X}=\begin{bmatrix} 0 & 0 \\ -# 0 & 1 \\ -# 1 & 0 \\ -# 1 & 1 \end{bmatrix}, -# $$ - -# while the vector of outputs is $\boldsymbol{y}^T=[0,1,1,0]$ for the XOR gate, $\boldsymbol{y}^T=[0,0,0,1]$ for the AND gate and $\boldsymbol{y}^T=[0,1,1,1]$ for the OR gate. - -# ## Setting up the Neural Network +# * **Many problems are not about prediction.** In natural science we are often interested in learning something about the underlying distribution that generates the data. In this case, it is often difficult to cast these ideas in a supervised learning setting. While the problems are related, it is possible to make good predictions with a *wrong* model. The model might or might not be useful for understanding the underlying science. # -# We define first our design matrix and the various output vectors for the different gates. - -# In[16]: - - -""" -Simple code that tests XOR, OR and AND gates with linear regression -""" - -# import necessary packages -import numpy as np -import matplotlib.pyplot as plt -from sklearn import datasets - -def sigmoid(x): - return 1/(1 + np.exp(-x)) - -def feed_forward(X): - # weighted sum of inputs to the hidden layer - z_h = np.matmul(X, hidden_weights) + hidden_bias - # activation in the hidden layer - a_h = sigmoid(z_h) - - # weighted sum of inputs to the output layer - z_o = np.matmul(a_h, output_weights) + output_bias - # softmax output - # axis 0 holds each input and axis 1 the probabilities of each category - probabilities = sigmoid(z_o) - return probabilities - -# we obtain a prediction by taking the class with the highest likelihood -def predict(X): - probabilities = feed_forward(X) - return np.argmax(probabilities, axis=1) - -# ensure the same random numbers appear every time -np.random.seed(0) - -# Design matrix -X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64) - -# The XOR gate -yXOR = np.array( [ 0, 1 ,1, 0]) -# The OR gate -yOR = np.array( [ 0, 1 ,1, 1]) -# The AND gate -yAND = np.array( [ 0, 0 ,0, 1]) - -# Defining the neural network -n_inputs, n_features = X.shape -n_hidden_neurons = 2 -n_categories = 2 -n_features = 2 - -# we make the weights normally distributed using numpy.random.randn - -# weights and bias in the hidden layer -hidden_weights = np.random.randn(n_features, n_hidden_neurons) -hidden_bias = np.zeros(n_hidden_neurons) + 0.01 - -# weights and bias in the output layer -output_weights = np.random.randn(n_hidden_neurons, n_categories) -output_bias = np.zeros(n_categories) + 0.01 - -probabilities = feed_forward(X) -print(probabilities) - - -predictions = predict(X) -print(predictions) - - -# Not an impressive result, but this was our first forward pass with randomly assigned weights. Let us now add the full network with the back-propagation algorithm discussed above. - -# ## The Code using Scikit-Learn - -# In[17]: - - -# import necessary packages -import numpy as np -import matplotlib.pyplot as plt -from sklearn.neural_network import MLPClassifier -from sklearn.metrics import accuracy_score -import seaborn as sns - -# ensure the same random numbers appear every time -np.random.seed(0) - -# Design matrix -X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64) - -# The XOR gate -yXOR = np.array( [ 0, 1 ,1, 0]) -# The OR gate -yOR = np.array( [ 0, 1 ,1, 1]) -# The AND gate -yAND = np.array( [ 0, 0 ,0, 1]) - -# Defining the neural network -n_inputs, n_features = X.shape -n_hidden_neurons = 2 -n_categories = 2 -n_features = 2 - -eta_vals = np.logspace(-5, 1, 7) -lmbd_vals = np.logspace(-5, 1, 7) -# store models for later use -DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object) -epochs = 100 - -for i, eta in enumerate(eta_vals): - for j, lmbd in enumerate(lmbd_vals): - dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic', - alpha=lmbd, learning_rate_init=eta, max_iter=epochs) - dnn.fit(X, yXOR) - DNN_scikit[i][j] = dnn - print("Learning rate = ", eta) - print("Lambda = ", lmbd) - print("Accuracy score on data set: ", dnn.score(X, yXOR)) - print() - -sns.set() -test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals))) -for i in range(len(eta_vals)): - for j in range(len(lmbd_vals)): - dnn = DNN_scikit[i][j] - test_pred = dnn.predict(X) - test_accuracy[i][j] = accuracy_score(yXOR, test_pred) - -fig, ax = plt.subplots(figsize = (10, 10)) -sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis") -ax.set_title("Test Accuracy") -ax.set_ylabel("$\eta$") -ax.set_xlabel("$\lambda$") -plt.show() - +# Some of these remarks are particular to DNNs, others are shared by all supervised learning methods. This motivates the use of unsupervised methods which in part circumvent these problems. diff --git a/doc/LectureNotes/_build/jupyter_execute/week41_304_0.png b/doc/LectureNotes/_build/jupyter_execute/week41_304_0.png new file mode 100644 index 000000000..492df86d6 Binary files /dev/null and b/doc/LectureNotes/_build/jupyter_execute/week41_304_0.png differ diff --git a/doc/LectureNotes/_build/jupyter_execute/week41_304_1.png b/doc/LectureNotes/_build/jupyter_execute/week41_304_1.png new file mode 100644 index 000000000..90948aee6 Binary files /dev/null and b/doc/LectureNotes/_build/jupyter_execute/week41_304_1.png differ diff --git a/doc/LectureNotes/_build/jupyter_execute/week41_304_2.png b/doc/LectureNotes/_build/jupyter_execute/week41_304_2.png new file mode 100644 index 000000000..a76574b3e Binary files /dev/null and b/doc/LectureNotes/_build/jupyter_execute/week41_304_2.png differ diff --git a/doc/LectureNotes/_build/jupyter_execute/week41_304_3.png b/doc/LectureNotes/_build/jupyter_execute/week41_304_3.png new file mode 100644 index 000000000..fc2c8902f Binary files /dev/null and b/doc/LectureNotes/_build/jupyter_execute/week41_304_3.png differ diff --git a/doc/LectureNotes/week41.ipynb b/doc/LectureNotes/week41.ipynb index 3def9b7f3..5f563d4fd 100644 --- a/doc/LectureNotes/week41.ipynb +++ b/doc/LectureNotes/week41.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "4fed6eef", + "id": "4411828b", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "6a758aaa", + "id": "c234e82d", "metadata": { "editable": true }, @@ -27,7 +27,7 @@ }, { "cell_type": "markdown", - "id": "7436d60f", + "id": "e602572c", "metadata": { "editable": true }, @@ -37,7 +37,7 @@ }, { "cell_type": "markdown", - "id": "4a06fa29", + "id": "8c040a6e", "metadata": { "editable": true }, @@ -70,7 +70,7 @@ }, { "cell_type": "markdown", - "id": "c77f547a", + "id": "d7c3f47c", "metadata": { "editable": true }, @@ -87,7 +87,7 @@ }, { "cell_type": "markdown", - "id": "a1ba6a50", + "id": "ee26bc0e", "metadata": { "editable": true }, @@ -97,7 +97,7 @@ }, { "cell_type": "markdown", - "id": "9ef418c8", + "id": "604a7680", "metadata": { "editable": true }, @@ -115,7 +115,7 @@ }, { "cell_type": "markdown", - "id": "b58ec2e6", + "id": "df00fb0e", "metadata": { "editable": true }, @@ -139,7 +139,7 @@ }, { "cell_type": "markdown", - "id": "7d1b99e3", + "id": "b60314ed", "metadata": { "editable": true }, @@ -157,7 +157,7 @@ }, { "cell_type": "markdown", - "id": "367512fa", + "id": "9d2e1d85", "metadata": { "editable": true }, @@ -197,7 +197,7 @@ }, { "cell_type": "markdown", - "id": "3d79cfce", + "id": "c6af91e7", "metadata": { "editable": true }, @@ -226,7 +226,7 @@ }, { "cell_type": "markdown", - "id": "cbcafcdc", + "id": "1b2b8e1c", "metadata": { "editable": true }, @@ -247,7 +247,7 @@ }, { "cell_type": "markdown", - "id": "1ab04b48", + "id": "db4860d5", "metadata": { "editable": true }, @@ -276,7 +276,7 @@ }, { "cell_type": "markdown", - "id": "e4cf80b3", + "id": "4c21c5ca", "metadata": { "editable": true }, @@ -297,7 +297,7 @@ }, { "cell_type": "markdown", - "id": "f27655c6", + "id": "4314d49c", "metadata": { "editable": true }, @@ -318,7 +318,7 @@ }, { "cell_type": "markdown", - "id": "fa00e7d8", + "id": "94acdaed", "metadata": { "editable": true }, @@ -335,7 +335,7 @@ }, { "cell_type": "markdown", - "id": "7b05bd13", + "id": "5c342880", "metadata": { "editable": true }, @@ -356,7 +356,7 @@ }, { "cell_type": "markdown", - "id": "3600caa3", + "id": "f8e04154", "metadata": { "editable": true }, @@ -372,7 +372,7 @@ }, { "cell_type": "markdown", - "id": "99af52bb", + "id": "80e11a79", "metadata": { "editable": true }, @@ -389,7 +389,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "04ecfb00", + "id": "60cf9550", "metadata": { "collapsed": false, "editable": true @@ -430,7 +430,7 @@ }, { "cell_type": "markdown", - "id": "0026adeb", + "id": "72e221bf", "metadata": { "editable": true }, @@ -440,7 +440,7 @@ }, { "cell_type": "markdown", - "id": "e23f3056", + "id": "67d0709a", "metadata": { "editable": true }, @@ -451,7 +451,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "a30fe879", + "id": "4afcb37f", "metadata": { "collapsed": false, "editable": true @@ -513,7 +513,7 @@ }, { "cell_type": "markdown", - "id": "7773ba9d", + "id": "ac931e42", "metadata": { "editable": true }, @@ -523,7 +523,7 @@ }, { "cell_type": "markdown", - "id": "4a85ef26", + "id": "e5455ad8", "metadata": { "editable": true }, @@ -534,7 +534,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "2f8dd9ef", + "id": "cfbed3e7", "metadata": { "collapsed": false, "editable": true @@ -554,58 +554,3097 @@ }, { "cell_type": "markdown", - "id": "5b0fb3ff", + "id": "a619dfb2", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", + "## Mathematics of deep learning\n", "\n", - "The output $y$ is produced via the activation function $f$" + "**Two recent books online.**\n", + "\n", + "1. [The Modern Mathematics of Deep Learning, by Julius Berner, Philipp Grohs, Gitta Kutyniok, Philipp Petersen](https://arxiv.org/abs/2105.04026), published as [Mathematical Aspects of Deep Learning, pp. 1-111. Cambridge University Press, 2022](https://doi.org/10.1017/9781009025096.002)\n", + "\n", + "2. [Mathematical Introduction to Deep Learning: Methods, Implementations, and Theory, Arnulf Jentzen, Benno Kuckuck, Philippe von Wurstemberger](https://doi.org/10.48550/arXiv.2310.20360)" ] }, { "cell_type": "markdown", - "id": "f5c984c2", + "id": "2cc88c73", + "metadata": { + "editable": true + }, + "source": [ + "## Reminder on books with hands-on material and codes\n", + "* [Sebastian Rashcka et al, Machine learning with Sickit-Learn and PyTorch](https://sebastianraschka.com/blog/2022/ml-pytorch-book.html)" + ] + }, + { + "cell_type": "markdown", + "id": "233d2972", + "metadata": { + "editable": true + }, + "source": [ + "## Reading recommendations\n", + "\n", + "1. Rashkca et al., chapter 11, jupyter-notebook sent separately, from [GitHub](https://github.com/rasbt/machine-learning-book)\n", + "\n", + "2. Goodfellow et al, chapter 6 and 7 contain most of the neural network background." + ] + }, + { + "cell_type": "markdown", + "id": "27cc80b0", + "metadata": { + "editable": true + }, + "source": [ + "## Mathematics of deep learning and neural networks\n", + "\n", + "Neural networks, in its so-called feed-forward form, where each\n", + "iterations contains a feed-forward stage and a back-propgagation\n", + "stage, consist of series of affine matrix-matrix and matrix-vector\n", + "multiplications. The unknown parameters (the so-called biases and\n", + "weights which deternine the architecture of a neural network), are\n", + "uptaded iteratively using the so-called back-propagation algorithm.\n", + "This algorithm corresponds to the so-called reverse mode of \n", + "automatic differentation." + ] + }, + { + "cell_type": "markdown", + "id": "ea3a3c02", + "metadata": { + "editable": true + }, + "source": [ + "## Basics of an NN\n", + "\n", + "A neural network consists of a series of hidden layers, in addition to\n", + "the input and output layers. Each layer $l$ has a set of parameters\n", + "$\\boldsymbol{\\Theta}^{(l)}=(\\boldsymbol{W}^{(l)},\\boldsymbol{b}^{(l)})$ which are related to the\n", + "parameters in other layers through a series of affine transformations,\n", + "for a standard NN these are matrix-matrix and matrix-vector\n", + "multiplications. For all layers we will simply use a collective variable $\\boldsymbol{\\Theta}$.\n", + "\n", + "It consist of two basic steps:\n", + "1. a feed forward stage which takes a given input and produces a final output which is compared with the target values through our cost/loss function.\n", + "\n", + "2. a back-propagation state where the unknown parameters $\\boldsymbol{\\Theta}$ are updated through the optimization of the their gradients. The expressions for the gradients are obtained via the chain rule, starting from the derivative of the cost/function.\n", + "\n", + "These two steps make up one iteration. This iterative process is continued till we reach an eventual stopping criterion." + ] + }, + { + "cell_type": "markdown", + "id": "502d4ad7", + "metadata": { + "editable": true + }, + "source": [ + "## Overarching view of a neural network\n", + "\n", + "The architecture of a neural network defines our model. This model\n", + "aims at describing some function $f(\\boldsymbol{x}$ which represents\n", + "some final result (outputs or tagrget values) given a specific inpput\n", + "$\\boldsymbol{x}$. Note that here $\\boldsymbol{y}$ and $\\boldsymbol{x}$ are not limited to be\n", + "vectors.\n", + "\n", + "The architecture consists of\n", + "1. An input and an output layer where the input layer is defined by the inputs $\\boldsymbol{x}$. The output layer produces the model ouput $\\boldsymbol{\\tilde{y}}$ which is compared with the target value $\\boldsymbol{y}$\n", + "\n", + "2. A given number of hidden layers and neurons/nodes/units for each layer (this may vary)\n", + "\n", + "3. A given activation function $\\sigma(\\boldsymbol{z})$ with arguments $\\boldsymbol{z}$ to be defined below. The activation functions may differ from layer to layer.\n", + "\n", + "4. The last layer, normally called **output** layer has normally an activation function tailored to the specific problem\n", + "\n", + "5. Finally we define a so-called cost or loss function which is used to gauge the quality of our model." + ] + }, + { + "cell_type": "markdown", + "id": "9182519a", + "metadata": { + "editable": true + }, + "source": [ + "## The optimization problem\n", + "\n", + "The cost function is a function of the unknown parameters\n", + "$\\boldsymbol{\\Theta}$ where the latter is a container for all possible\n", + "parameters needed to define a neural network\n", + "\n", + "If we are dealing with a regression task a typical cost/loss function\n", + "is the mean squared error" + ] + }, + { + "cell_type": "markdown", + "id": "15b78cfd", "metadata": { "editable": true }, "source": [ "$$\n", - "y = f\\left(\\sum_{i=1}^n w_ix_i + b_i\\right) = f(z),\n", + "C(\\boldsymbol{\\Theta})=\\frac{1}{n}\\left\\{\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\theta}\\right)^T\\left(\\boldsymbol{y}-\\boldsymbol{X}\\boldsymbol{\\theta}\\right)\\right\\}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "9743f4cb", + "id": "093b77f1", "metadata": { "editable": true }, "source": [ - "This function receives $x_i$ as inputs.\n", - "Here the activation $z=(\\sum_{i=1}^n w_ix_i+b_i)$. \n", - "In an FFNN of such neurons, the *inputs* $x_i$ are the *outputs* of\n", - "the neurons in the preceding layer. Furthermore, an MLP is\n", - "fully-connected, which means that each neuron receives a weighted sum\n", - "of the outputs of *all* neurons in the previous layer." + "This function represents one of many possible ways to define\n", + "the so-called cost function. Note that here we have assumed a linear dependence in terms of the paramters $\\boldsymbol{\\Theta}$. This is in general not the case." ] }, { "cell_type": "markdown", - "id": "e89c3e3f", + "id": "b6c8a224", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", + "## Parameters of neural networks\n", + "For neural networks the parameters\n", + "$\\boldsymbol{\\Theta}$ are given by the so-called weights and biases (to be\n", + "defined below).\n", "\n", - "First, for each node $i$ in the first hidden layer, we calculate a weighted sum $z_i^1$ of the input coordinates $x_j$," + "The weights are given by matrix elements $w_{ij}^{(l)}$ where the\n", + "superscript indicates the layer number. The biases are typically given\n", + "by vector elements representing each single node of a given layer,\n", + "that is $b_j^{(l)}$." ] }, { "cell_type": "markdown", - "id": "21c83fef", + "id": "f30d7e81", + "metadata": { + "editable": true + }, + "source": [ + "## Other ingredients of a neural network\n", + "\n", + "Having defined the architecture of a neural network, the optimization\n", + "of the cost function with respect to the parameters $\\boldsymbol{\\Theta}$,\n", + "involves the calculations of gradients and their optimization. The\n", + "gradients represent the derivatives of a multidimensional object and\n", + "are often approximated by various gradient methods, including\n", + "1. various quasi-Newton methods,\n", + "\n", + "2. plain gradient descent (GD) with a constant learning rate $\\eta$,\n", + "\n", + "3. GD with momentum and other approximations to the learning rates such as\n", + "\n", + " * Adapative gradient (ADAgrad)\n", + "\n", + " * Root mean-square propagation (RMSprop)\n", + "\n", + " * Adaptive gradient with momentum (ADAM) and many other\n", + "\n", + "4. Stochastic gradient descent and various families of learning rate approximations" + ] + }, + { + "cell_type": "markdown", + "id": "5089007e", + "metadata": { + "editable": true + }, + "source": [ + "## Other parameters\n", + "\n", + "In addition to the above, there are often additional hyperparamaters\n", + "which are included in the setup of a neural network. These will be\n", + "discussed below." + ] + }, + { + "cell_type": "markdown", + "id": "3f9eedcb", + "metadata": { + "editable": true + }, + "source": [ + "## Universal approximation theorem\n", + "\n", + "The universal approximation theorem plays a central role in deep\n", + "learning. [Cybenko (1989)](https://link.springer.com/article/10.1007/BF02551274) showed\n", + "the following:\n", + "\n", + "Let $\\sigma$ be any continuous sigmoidal function such that" + ] + }, + { + "cell_type": "markdown", + "id": "ac052134", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\sigma(z) = \\left\\{\\begin{array}{cc} 1 & z\\rightarrow \\infty\\\\ 0 & z \\rightarrow -\\infty \\end{array}\\right.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c0e639b1", + "metadata": { + "editable": true + }, + "source": [ + "Given a continuous and deterministic function $F(\\boldsymbol{x})$ on the unit\n", + "cube in $d$-dimensions $F\\in [0,1]^d$, $x\\in [0,1]^d$ and a parameter\n", + "$\\epsilon >0$, there is a one-layer (hidden) neural network\n", + "$f(\\boldsymbol{x};\\boldsymbol{\\Theta})$ with $\\boldsymbol{\\Theta}=(\\boldsymbol{W},\\boldsymbol{b})$ and $\\boldsymbol{W}\\in\n", + "\\mathbb{R}^{m\\times n}$ and $\\boldsymbol{b}\\in \\mathbb{R}^{n}$, for which" + ] + }, + { + "cell_type": "markdown", + "id": "6d2878d4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert < \\epsilon \\hspace{0.1cm} \\forall \\boldsymbol{x}\\in[0,1]^d.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dbb5133d", + "metadata": { + "editable": true + }, + "source": [ + "## Some parallels from real analysis\n", + "\n", + "For those of you familiar with for example the [Stone-Weierstrass\n", + "theorem](https://en.wikipedia.org/wiki/Stone%E2%80%93Weierstrass_theorem)\n", + "for polynomial approximations or the convergence criterion for Fourier\n", + "series, there are similarities in the derivation of the proof for\n", + "neural networks." + ] + }, + { + "cell_type": "markdown", + "id": "0da134a5", + "metadata": { + "editable": true + }, + "source": [ + "## The approximation theorem in words\n", + "\n", + "**Any continuous function $y=F(\\boldsymbol{x})$ supported on the unit cube in\n", + "$d$-dimensions can be approximated by a one-layer sigmoidal network to\n", + "arbitrary accuracy.**\n", + "\n", + "[Hornik (1991)](https://www.sciencedirect.com/science/article/abs/pii/089360809190009T) extended the theorem by letting any non-constant, bounded activation function to be included using that the expectation value" + ] + }, + { + "cell_type": "markdown", + "id": "5346e8a0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathbb{E}[\\vert F(\\boldsymbol{x})\\vert^2] =\\int_{\\boldsymbol{x}\\in D} \\vert F(\\boldsymbol{x})\\vert^2p(\\boldsymbol{x})d\\boldsymbol{x} < \\infty.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "36737d10", + "metadata": { + "editable": true + }, + "source": [ + "Then we have" + ] + }, + { + "cell_type": "markdown", + "id": "d81b95ba", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\mathbb{E}[\\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert^2] =\\int_{\\boldsymbol{x}\\in D} \\vert F(\\boldsymbol{x})-f(\\boldsymbol{x};\\boldsymbol{\\Theta})\\vert^2p(\\boldsymbol{x})d\\boldsymbol{x} < \\epsilon.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8432cac2", + "metadata": { + "editable": true + }, + "source": [ + "## More on the general approximation theorem\n", + "\n", + "None of the proofs give any insight into the relation between the\n", + "number of of hidden layers and nodes and the approximation error\n", + "$\\epsilon$, nor the magnitudes of $\\boldsymbol{W}$ and $\\boldsymbol{b}$.\n", + "\n", + "Neural networks (NNs) have what we may call a kind of universality no matter what function we want to compute.\n", + "\n", + "It does not mean that an NN can be used to exactly compute any function. Rather, we get an approximation that is as good as we want." + ] + }, + { + "cell_type": "markdown", + "id": "04d4d751", + "metadata": { + "editable": true + }, + "source": [ + "## Class of functions we can approximate\n", + "\n", + "The class of functions that can be approximated are the continuous ones.\n", + "If the function $F(\\boldsymbol{x})$ is discontinuous, it won't in general be possible to approximate it. However, an NN may still give an approximation even if we fail in some points." + ] + }, + { + "cell_type": "markdown", + "id": "df8f957e", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the equations for a neural network\n", + "\n", + "The questions we want to ask are how do changes in the biases and the\n", + "weights in our network change the cost function and how can we use the\n", + "final output to modify the weights and biases?\n", + "\n", + "To derive these equations let us start with a plain regression problem\n", + "and define our cost function as" + ] + }, + { + "cell_type": "markdown", + "id": "0fc51d93", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\cal C}(\\boldsymbol{\\Theta}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - \\tilde{y}_i\\right)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "fc372df4", + "metadata": { + "editable": true + }, + "source": [ + "where the $y_i$s are our $n$ targets (the values we want to\n", + "reproduce), while the outputs of the network after having propagated\n", + "all inputs $\\boldsymbol{x}$ are given by $\\boldsymbol{\\tilde{y}}_i$." + ] + }, + { + "cell_type": "markdown", + "id": "e1cbafd1", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a neural network with three hidden layers\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "aadba1e0", + "metadata": { + "editable": true + }, + "source": [ + "## Definitions\n", + "\n", + "With our definition of the targets $\\boldsymbol{y}$, the outputs of the\n", + "network $\\boldsymbol{\\tilde{y}}$ and the inputs $\\boldsymbol{x}$ we\n", + "define now the activation $z_j^l$ of node/neuron/unit $j$ of the\n", + "$l$-th layer as a function of the bias, the weights which add up from\n", + "the previous layer $l-1$ and the forward passes/outputs\n", + "$\\hat{a}^{l-1}$ from the previous layer as" + ] + }, + { + "cell_type": "markdown", + "id": "4f0a354f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_j^l = \\sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5b489754", + "metadata": { + "editable": true + }, + "source": [ + "where $b_k^l$ are the biases from layer $l$. Here $M_{l-1}$\n", + "represents the total number of nodes/neurons/units of layer $l-1$. The\n", + "figure in the whiteboard notes illustrates this equation. We can rewrite this in a more\n", + "compact form as the matrix-vector products we discussed earlier," + ] + }, + { + "cell_type": "markdown", + "id": "109a6626", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\hat{z}^l = \\left(\\hat{W}^l\\right)^T\\hat{a}^{l-1}+\\hat{b}^l.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d075c31b", + "metadata": { + "editable": true + }, + "source": [ + "## Inputs to the activation function\n", + "\n", + "With the activation values $\\boldsymbol{z}^l$ we can in turn define the\n", + "output of layer $l$ as $\\boldsymbol{a}^l = f(\\boldsymbol{z}^l)$ where $f$ is our\n", + "activation function. In the examples here we will use the sigmoid\n", + "function discussed in our logistic regression lectures. We will also use the same activation function $f$ for all layers\n", + "and their nodes. It means we have" + ] + }, + { + "cell_type": "markdown", + "id": "ea32a509", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a_j^l = \\sigma(z_j^l) = \\frac{1}{1+\\exp{-(z_j^l)}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8ac36725", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives and the chain rule\n", + "\n", + "From the definition of the activation $z_j^l$ we have" + ] + }, + { + "cell_type": "markdown", + "id": "f3600e09", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z_j^l}{\\partial w_{ij}^l} = a_i^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3e537038", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "34b99ae7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z_j^l}{\\partial a_i^{l-1}} = w_{ji}^l.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e4faa2f2", + "metadata": { + "editable": true + }, + "source": [ + "With our definition of the activation function we have that (note that this function depends only on $z_j^l$)" + ] + }, + { + "cell_type": "markdown", + "id": "b4243031", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a_j^l}{\\partial z_j^{l}} = a_j^l(1-a_j^l)=\\sigma(z_j^l)(1-\\sigma(z_j^l)).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b528c44c", + "metadata": { + "editable": true + }, + "source": [ + "## Derivative of the cost function\n", + "\n", + "With these definitions we can now compute the derivative of the cost function in terms of the weights.\n", + "\n", + "Let us specialize to the output layer $l=L$. Our cost function is" + ] + }, + { + "cell_type": "markdown", + "id": "602e81ab", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "{\\cal C}(\\boldsymbol{\\Theta}^L) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - \\tilde{y}_i\\right)^2=\\frac{1}{2}\\sum_{i=1}^n\\left(a_i^L - y_i\\right)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4ac5e382", + "metadata": { + "editable": true + }, + "source": [ + "The derivative of this function with respect to the weights is" + ] + }, + { + "cell_type": "markdown", + "id": "02edfab2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}(\\boldsymbol{\\Theta}^L)}{\\partial w_{jk}^L} = \\left(a_j^L - y_j\\right)\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "02fffe9d", + "metadata": { + "editable": true + }, + "source": [ + "The last partial derivative can easily be computed and reads (by applying the chain rule)" + ] + }, + { + "cell_type": "markdown", + "id": "f4d679cc", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}} = \\frac{\\partial a_j^L}{\\partial z_{j}^{L}}\\frac{\\partial z_j^L}{\\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3638d432", + "metadata": { + "editable": true + }, + "source": [ + "## Simpler examples first, and automatic differentiation\n", + "\n", + "In order to understand the back propagation algorithm and its\n", + "derivation (an implementation of the chain rule), let us first digress\n", + "with some simple examples. These examples are also meant to motivate\n", + "the link with back propagation and [automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation)." + ] + }, + { + "cell_type": "markdown", + "id": "d3039347", + "metadata": { + "editable": true + }, + "source": [ + "## Reminder on the chain rule and gradients\n", + "\n", + "If we have a multivariate function $f(x,y)$ where $x=x(t)$ and $y=y(t)$ are functions of a variable $t$, we have that the gradient of $f$ with respect to $t$ (without the explicit unit vector components)" + ] + }, + { + "cell_type": "markdown", + "id": "f48bfb76", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dt} = \\begin{bmatrix}\\frac{\\partial f}{\\partial x} & \\frac{\\partial f}{\\partial y} \\end{bmatrix} \\begin{bmatrix}\\frac{\\partial x}{\\partial t} \\\\ \\frac{\\partial y}{\\partial t} \\end{bmatrix}=\\frac{\\partial f}{\\partial x} \\frac{\\partial x}{\\partial t} +\\frac{\\partial f}{\\partial y} \\frac{\\partial y}{\\partial t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "63176c54", + "metadata": { + "editable": true + }, + "source": [ + "## Multivariable functions\n", + "\n", + "If we have a multivariate function $f(x,y)$ where $x=x(t,s)$ and $y=y(t,s)$ are functions of the variables $t$ and $s$, we have that the partial derivatives" + ] + }, + { + "cell_type": "markdown", + "id": "f966f6f1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial s}=\\frac{\\partial f}{\\partial x}\\frac{\\partial x}{\\partial s}+\\frac{\\partial f}{\\partial y}\\frac{\\partial y}{\\partial s},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b0a5a64e", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "fedfd000", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial t}=\\frac{\\partial f}{\\partial x}\\frac{\\partial x}{\\partial t}+\\frac{\\partial f}{\\partial y}\\frac{\\partial y}{\\partial t}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "49281876", + "metadata": { + "editable": true + }, + "source": [ + "the gradient of $f$ with respect to $t$ and $s$ (without the explicit unit vector components)" + ] + }, + { + "cell_type": "markdown", + "id": "78dc9b72", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{d(s,t)} = \\begin{bmatrix}\\frac{\\partial f}{\\partial x} & \\frac{\\partial f}{\\partial y} \\end{bmatrix} \\begin{bmatrix}\\frac{\\partial x}{\\partial s} &\\frac{\\partial x}{\\partial t} \\\\ \\frac{\\partial y}{\\partial s} & \\frac{\\partial y}{\\partial t} \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "bf854510", + "metadata": { + "editable": true + }, + "source": [ + "## Automatic differentiation through examples\n", + "\n", + "A great introduction to automatic differentiation is given by Baydin et al., see .\n", + "\n", + "Automatic differentiation is a represented by a repeated application\n", + "of the chain rule on well-known functions and allows for the\n", + "calculation of derivatives to numerical precision. It is not the same\n", + "as the calculation of symbolic derivatives via for example SymPy, nor\n", + "does it use approximative formulae based on Taylor-expansions of a\n", + "function around a given value. The latter are error prone due to\n", + "truncation errors and values of the step size $\\Delta$." + ] + }, + { + "cell_type": "markdown", + "id": "35771431", + "metadata": { + "editable": true + }, + "source": [ + "## Simple example\n", + "\n", + "Our first example is rather simple," + ] + }, + { + "cell_type": "markdown", + "id": "6570ba80", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) =\\exp{x^2},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c30b4d72", + "metadata": { + "editable": true + }, + "source": [ + "with derivative" + ] + }, + { + "cell_type": "markdown", + "id": "183d5f0b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) =2x\\exp{x^2}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "b2363c0a", + "metadata": { + "editable": true + }, + "source": [ + "We can use SymPy to extract the pertinent lines of Python code through the following simple example" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "0b51ea21", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "from __future__ import division\n", + "from sympy import *\n", + "x = symbols('x')\n", + "expr = exp(x*x)\n", + "simplify(expr)\n", + "derivative = diff(expr,x)\n", + "print(python(expr))\n", + "print(python(derivative))" + ] + }, + { + "cell_type": "markdown", + "id": "07e24343", + "metadata": { + "editable": true + }, + "source": [ + "## Smarter way of evaluating the above function\n", + "If we study this function, we note that we can reduce the number of operations by introducing an intermediate variable" + ] + }, + { + "cell_type": "markdown", + "id": "1337dd0f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a = x^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a7589947", + "metadata": { + "editable": true + }, + "source": [ + "leading to" + ] + }, + { + "cell_type": "markdown", + "id": "3586c972", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) = f(a(x)) = b= \\exp{a}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0ac52a19", + "metadata": { + "editable": true + }, + "source": [ + "We now assume that all operations can be counted in terms of equal\n", + "floating point operations. This means that in order to calculate\n", + "$f(x)$ we need first to square $x$ and then compute the exponential. We\n", + "have thus two floating point operations only." + ] + }, + { + "cell_type": "markdown", + "id": "18b67b7b", + "metadata": { + "editable": true + }, + "source": [ + "## Reducing the number of operations\n", + "\n", + "With the introduction of a precalculated quantity $a$ and thereby $f(x)$ we have that the derivative can be written as" + ] + }, + { + "cell_type": "markdown", + "id": "75f72d6b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) = 2xb,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ff72bef0", + "metadata": { + "editable": true + }, + "source": [ + "which reduces the number of operations from four in the orginal\n", + "expression to two. This means that if we need to compute $f(x)$ and\n", + "its derivative (a common task in optimizations), we have reduced the\n", + "number of operations from six to four in total.\n", + "\n", + "**Note** that the usage of a symbolic software like SymPy does not\n", + "include such simplifications and the calculations of the function and\n", + "the derivatives yield in general more floating point operations." + ] + }, + { + "cell_type": "markdown", + "id": "ef55737f", + "metadata": { + "editable": true + }, + "source": [ + "## Chain rule, forward and reverse modes\n", + "\n", + "In the above example we have introduced the variables $a$ and $b$, and our function is" + ] + }, + { + "cell_type": "markdown", + "id": "35ab7175", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) = f(a(x)) = b= \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "edc79b33", + "metadata": { + "editable": true + }, + "source": [ + "with $a=x^2$. We can decompose the derivative of $f$ with respect to $x$ as" + ] + }, + { + "cell_type": "markdown", + "id": "4dc12ed8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\frac{db}{da}\\frac{da}{dx}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "bc945b59", + "metadata": { + "editable": true + }, + "source": [ + "We note that since $b=f(x)$ that" + ] + }, + { + "cell_type": "markdown", + "id": "68eac5d0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{db}=1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6ea49d77", + "metadata": { + "editable": true + }, + "source": [ + "leading to" + ] + }, + { + "cell_type": "markdown", + "id": "4a65d6fd", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{db}{da}\\frac{da}{dx}=2x\\exp{x^2},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c66da8ef", + "metadata": { + "editable": true + }, + "source": [ + "as before." + ] + }, + { + "cell_type": "markdown", + "id": "b055e013", + "metadata": { + "editable": true + }, + "source": [ + "## Forward and reverse modes\n", + "\n", + "We have that" + ] + }, + { + "cell_type": "markdown", + "id": "006ef4f0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\frac{db}{da}\\frac{da}{dx},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "99fd1e13", + "metadata": { + "editable": true + }, + "source": [ + "which we can rewrite either as" + ] + }, + { + "cell_type": "markdown", + "id": "d711ba8b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\left[\\frac{df}{db}\\frac{db}{da}\\right]\\frac{da}{dx},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "394f38fd", + "metadata": { + "editable": true + }, + "source": [ + "or" + ] + }, + { + "cell_type": "markdown", + "id": "2f589cea", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{df}{dx}=\\frac{df}{db}\\left[\\frac{db}{da}\\frac{da}{dx}\\right].\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "783c3588", + "metadata": { + "editable": true + }, + "source": [ + "The first expression is called reverse mode (or back propagation)\n", + "since we start by evaluating the derivatives at the end point and then\n", + "propagate backwards. This is the standard way of evaluating\n", + "derivatives (gradients) when optimizing the parameters of a neural\n", + "network. In the context of deep learning this is computationally\n", + "more efficient since the output of a neural network consists of either\n", + "one or some few other output variables.\n", + "\n", + "The second equation defines the so-called **forward mode**." + ] + }, + { + "cell_type": "markdown", + "id": "d1627f43", + "metadata": { + "editable": true + }, + "source": [ + "## More complicated function\n", + "\n", + "We increase our ambitions and introduce a slightly more complicated function" + ] + }, + { + "cell_type": "markdown", + "id": "53035043", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f(x) =\\sqrt{x^2+exp{x^2}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f3293e4c", + "metadata": { + "editable": true + }, + "source": [ + "with derivative" + ] + }, + { + "cell_type": "markdown", + "id": "b6087529", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "f'(x) =\\frac{x(1+\\exp{x^2})}{\\sqrt{x^2+exp{x^2}}}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "9a91562c", + "metadata": { + "editable": true + }, + "source": [ + "The corresponding SymPy code reads" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "49153549", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "from __future__ import division\n", + "from sympy import *\n", + "x = symbols('x')\n", + "expr = sqrt(x*x+exp(x*x))\n", + "simplify(expr)\n", + "derivative = diff(expr,x)\n", + "print(python(expr))\n", + "print(python(derivative))" + ] + }, + { + "cell_type": "markdown", + "id": "3f8e08c9", + "metadata": { + "editable": true + }, + "source": [ + "## Counting the number of floating point operations\n", + "\n", + "A simple count of operations shows that we need five operations for\n", + "the function itself and ten for the derivative. Fifteen operations in total if we wish to proceed with the above codes.\n", + "\n", + "Can we reduce this to\n", + "say half the number of operations?" + ] + }, + { + "cell_type": "markdown", + "id": "9479dadf", + "metadata": { + "editable": true + }, + "source": [ + "## Defining intermediate operations\n", + "\n", + "We can indeed reduce the number of operation to half of those listed in the brute force approach above.\n", + "We define the following quantities" + ] + }, + { + "cell_type": "markdown", + "id": "9e5f867e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a = x^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "21ee2a8a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "e09cf187", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b = \\exp{x^2} = \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c999c36b", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "8fbf66c6", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "c= a+b,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dd11cc6a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "69e9e950", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "d=f(x)=\\sqrt{c}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "970b6167", + "metadata": { + "editable": true + }, + "source": [ + "## New expression for the derivative\n", + "\n", + "With these definitions we obtain the following partial derivatives" + ] + }, + { + "cell_type": "markdown", + "id": "5655fa59", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial a}{\\partial x} = 2x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1c8a1f68", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "edaf4340", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial b}{\\partial a} = \\exp{a},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f39563ef", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "c3fad1fe", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial c}{\\partial a} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2f26318c", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "75e08a4f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial c}{\\partial b} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "2729f6dc", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "7ccfc31a", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial d}{\\partial c} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1e39402f", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "a8313c23", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial d} = 1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "64f5a96d", + "metadata": { + "editable": true + }, + "source": [ + "## Final derivatives\n", + "Our final derivatives are thus" + ] + }, + { + "cell_type": "markdown", + "id": "e087f8b8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial c} = \\frac{\\partial f}{\\partial d} \\frac{\\partial d}{\\partial c} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ab9adb45", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial b} = \\frac{\\partial f}{\\partial c} \\frac{\\partial c}{\\partial b} = \\frac{1}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e7125560", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial a} = \\frac{\\partial f}{\\partial c} \\frac{\\partial c}{\\partial a}+\n", + "\\frac{\\partial f}{\\partial b} \\frac{\\partial b}{\\partial a} = \\frac{1+\\exp{a}}{2\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6c4ad559", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "b42e32a4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x} = \\frac{\\partial f}{\\partial a} \\frac{\\partial a}{\\partial x} = \\frac{x(1+\\exp{a})}{\\sqrt{c}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "40de97ba", + "metadata": { + "editable": true + }, + "source": [ + "which is just" + ] + }, + { + "cell_type": "markdown", + "id": "22d0d252", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x} = \\frac{x(1+b)}{d},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "be68a064", + "metadata": { + "editable": true + }, + "source": [ + "and requires only three operations if we can reuse all intermediate variables." + ] + }, + { + "cell_type": "markdown", + "id": "ed92fb3c", + "metadata": { + "editable": true + }, + "source": [ + "## In general not this simple\n", + "\n", + "In general, see the generalization below, unless we can obtain simple\n", + "analytical expressions which we can simplify further, the final\n", + "implementation of automatic differentiation involves repeated\n", + "calculations (and thereby operations) of derivatives of elementary\n", + "functions." + ] + }, + { + "cell_type": "markdown", + "id": "b565b39a", + "metadata": { + "editable": true + }, + "source": [ + "## Automatic differentiation\n", + "\n", + "We can make this example more formal. Automatic differentiation is a\n", + "formalization of the previous example (see graph).\n", + "\n", + "We define $\\boldsymbol{x}\\in x_1,\\dots, x_l$ input variables to a given function $f(\\boldsymbol{x})$ and $x_{l+1},\\dots, x_L$ intermediate variables.\n", + "\n", + "In the above example we have only one input variable, $l=1$ and four intermediate variables, that is" + ] + }, + { + "cell_type": "markdown", + "id": "587ae22d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix} x_1=x & x_2 = x^2=a & x_3 =\\exp{a}= b & x_4=c=a+b & x_5 = \\sqrt{c}=d \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a54b74ca", + "metadata": { + "editable": true + }, + "source": [ + "Furthemore, for $i=l+1, \\dots, L$ (here $i=2,3,4,5$ and $f=x_L=d$), we\n", + "define the elementary functions $g_i(x_{Pa(x_i)})$ where $x_{Pa(x_i)}$ are the parent nodes of the variable $x_i$.\n", + "\n", + "In our case, we have for example for $x_3=g_3(x_{Pa(x_i)})=\\exp{a}$, that $g_3=\\exp{()}$ and $x_{Pa(x_3)}=a$." + ] + }, + { + "cell_type": "markdown", + "id": "bcfc076a", + "metadata": { + "editable": true + }, + "source": [ + "## Chain rule\n", + "\n", + "We can now compute the gradients by back-propagating the derivatives using the chain rule.\n", + "We have defined" + ] + }, + { + "cell_type": "markdown", + "id": "b4194098", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x_L} = 1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "acc7030d", + "metadata": { + "editable": true + }, + "source": [ + "which allows us to find the derivatives of the various variables $x_i$ as" + ] + }, + { + "cell_type": "markdown", + "id": "02f92f41", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial f}{\\partial x_i} = \\sum_{x_j:x_i\\in Pa(x_j)}\\frac{\\partial f}{\\partial x_j} \\frac{\\partial x_j}{\\partial x_i}=\\sum_{x_j:x_i\\in Pa(x_j)}\\frac{\\partial f}{\\partial x_j} \\frac{\\partial g_j}{\\partial x_i}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5541dfd1", + "metadata": { + "editable": true + }, + "source": [ + "Whenever we have a function which can be expressed as a computation\n", + "graph and the various functions can be expressed in terms of\n", + "elementary functions that are differentiable, then automatic\n", + "differentiation works. The functions may not need to be elementary\n", + "functions, they could also be computer programs, although not all\n", + "programs can be automatically differentiated." + ] + }, + { + "cell_type": "markdown", + "id": "f73cf263", + "metadata": { + "editable": true + }, + "source": [ + "## First network example, simple percepetron with one input\n", + "\n", + "As yet another example we define now a simple perceptron model with\n", + "all quantities given by scalars. We consider only one input variable\n", + "$x$ and one target value $y$. We define an activation function\n", + "$\\sigma_1$ which takes as input" + ] + }, + { + "cell_type": "markdown", + "id": "4b8722cb", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_1 = w_1x+b_1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a604334f", + "metadata": { + "editable": true + }, + "source": [ + "where $w_1$ is the weight and $b_1$ is the bias. These are the\n", + "parameters we want to optimize. The output is $a_1=\\sigma(z_1)$ (see\n", + "graph from whiteboard notes). This output is then fed into the\n", + "**cost/loss** function, which we here for the sake of simplicity just\n", + "define as the squared error" + ] + }, + { + "cell_type": "markdown", + "id": "0017f42e", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(x;w_1,b_1)=\\frac{1}{2}(a_1-y)^2.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8c47d806", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with no hidden layer\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "df503def", + "metadata": { + "editable": true + }, + "source": [ + "## Optimizing the parameters\n", + "\n", + "In setting up the feed forward and back propagation parts of the\n", + "algorithm, we need now the derivative of the various variables we want\n", + "to train.\n", + "\n", + "We need" + ] + }, + { + "cell_type": "markdown", + "id": "bdc97982", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1} \\hspace{0.1cm}\\mathrm{and}\\hspace{0.1cm}\\frac{\\partial C}{\\partial b_1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "42716985", + "metadata": { + "editable": true + }, + "source": [ + "Using the chain rule we find" + ] + }, + { + "cell_type": "markdown", + "id": "6df9aa60", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1}=\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial w_1}=(a_1-y)\\sigma_1'x,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "30f9e077", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "77e9d494", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_1}=\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial b_1}=(a_1-y)\\sigma_1',\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "1136c644", + "metadata": { + "editable": true + }, + "source": [ + "which we later will just define as" + ] + }, + { + "cell_type": "markdown", + "id": "b9f253ba", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}=\\delta_1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "14d41c44", + "metadata": { + "editable": true + }, + "source": [ + "## Adding a hidden layer\n", + "\n", + "We change our simple model to (see graph)\n", + "a network with just one hidden layer but with scalar variables only.\n", + "\n", + "Our output variable changes to $a_2$ and $a_1$ is now the output from the hidden node and $a_0=x$.\n", + "We have then" + ] + }, + { + "cell_type": "markdown", + "id": "d7c607f5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_1 = w_1a_0+b_1 \\hspace{0.1cm} \\wedge a_1 = \\sigma_1(z_1),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "609e28e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z_2 = w_2a_1+b_2 \\hspace{0.1cm} \\wedge a_2 = \\sigma_2(z_2),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "494580d5", + "metadata": { + "editable": true + }, + "source": [ + "and the cost function" + ] + }, + { + "cell_type": "markdown", + "id": "03665a6f", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "C(x;\\boldsymbol{\\Theta})=\\frac{1}{2}(a_2-y)^2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "911b5d2c", + "metadata": { + "editable": true + }, + "source": [ + "with $\\boldsymbol{\\Theta}=[w_1,w_2,b_1,b_2]$." + ] + }, + { + "cell_type": "markdown", + "id": "91e4f869", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with one hidden layer\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "43efdd27", + "metadata": { + "editable": true + }, + "source": [ + "## The derivatives\n", + "\n", + "The derivatives are now, using the chain rule again" + ] + }, + { + "cell_type": "markdown", + "id": "25d99018", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_2}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial w_2}=(a_2-y)\\sigma_2'a_1=\\delta_2a_1,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6924f790", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_2}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial b_2}=(a_2-y)\\sigma_2'=\\delta_2,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f457fe37", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_1}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial w_1}=(a_2-y)\\sigma_2'a_1\\sigma_1'a_0,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "81e40678", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_1}=\\frac{\\partial C}{\\partial a_2}\\frac{\\partial a_2}{\\partial z_2}\\frac{\\partial z_2}{\\partial a_1}\\frac{\\partial a_1}{\\partial z_1}\\frac{\\partial z_1}{\\partial b_1}=(a_2-y)\\sigma_2'\\sigma_1'=\\delta_1.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c954b1f9", + "metadata": { + "editable": true + }, + "source": [ + "Can you generalize this to more than one hidden layer?" + ] + }, + { + "cell_type": "markdown", + "id": "87d10fa3", + "metadata": { + "editable": true + }, + "source": [ + "## Important observations\n", + "\n", + "From the above equations we see that the derivatives of the activation\n", + "functions play a central role. If they vanish, the training may\n", + "stop. This is called the vanishing gradient problem, see discussions below. If they become\n", + "large, the parameters $w_i$ and $b_i$ may simply go to infinity. This\n", + "is referenced as the exploding gradient problem." + ] + }, + { + "cell_type": "markdown", + "id": "c20ef010", + "metadata": { + "editable": true + }, + "source": [ + "## The training\n", + "\n", + "The training of the parameters is done through various gradient descent approximations with" + ] + }, + { + "cell_type": "markdown", + "id": "e9de19ea", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}\\leftarrow w_{i}- \\eta \\delta_i a_{i-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3487e8b8", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "7baa62bc", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_i \\leftarrow b_i-\\eta \\delta_i,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a3c1590a", + "metadata": { + "editable": true + }, + "source": [ + "with $\\eta$ is the learning rate.\n", + "\n", + "One iteration consists of one feed forward step and one back-propagation step. Each back-propagation step does one update of the parameters $\\boldsymbol{\\Theta}$.\n", + "\n", + "For the first hidden layer $a_{i-1}=a_0=x$ for this simple model." + ] + }, + { + "cell_type": "markdown", + "id": "3c3dc625", + "metadata": { + "editable": true + }, + "source": [ + "## Code example\n", + "\n", + "The code here implements the above model with one hidden layer and\n", + "scalar variables for the same function we studied in the previous\n", + "example. The code is however set up so that we can add multiple\n", + "inputs $x$ and target values $y$. Note also that we have the\n", + "possibility of defining a feature matrix $\\boldsymbol{X}$ with more than just\n", + "one column for the input values. This will turn useful in our next example. We have also defined matrices and vectors for all of our operations although it is not necessary here." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "e9fb1fc9", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "# We use the Sigmoid function as activation function\n", + "def sigmoid(z):\n", + " return 1.0/(1.0+np.exp(-z))\n", + "\n", + "def forwardpropagation(x):\n", + " # weighted sum of inputs to the hidden layer\n", + " z_1 = np.matmul(x, w_1) + b_1\n", + " # activation in the hidden layer\n", + " a_1 = sigmoid(z_1)\n", + " # weighted sum of inputs to the output layer\n", + " z_2 = np.matmul(a_1, w_2) + b_2\n", + " a_2 = z_2\n", + " return a_1, a_2\n", + "\n", + "def backpropagation(x, y):\n", + " a_1, a_2 = forwardpropagation(x)\n", + " # parameter delta for the output layer, note that a_2=z_2 and its derivative wrt z_2 is just 1\n", + " delta_2 = a_2 - y\n", + " print(0.5*((a_2-y)**2))\n", + " # delta for the hidden layer\n", + " delta_1 = np.matmul(delta_2, w_2.T) * a_1 * (1 - a_1)\n", + " # gradients for the output layer\n", + " output_weights_gradient = np.matmul(a_1.T, delta_2)\n", + " output_bias_gradient = np.sum(delta_2, axis=0)\n", + " # gradient for the hidden layer\n", + " hidden_weights_gradient = np.matmul(x.T, delta_1)\n", + " hidden_bias_gradient = np.sum(delta_1, axis=0)\n", + " return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient\n", + "\n", + "\n", + "# ensure the same random numbers appear every time\n", + "np.random.seed(0)\n", + "# Input variable\n", + "x = np.array([4.0],dtype=np.float64)\n", + "# Target values\n", + "y = 2*x+1.0 \n", + "\n", + "# Defining the neural network, only scalars here\n", + "n_inputs = x.shape\n", + "n_features = 1\n", + "n_hidden_neurons = 1\n", + "n_outputs = 1\n", + "\n", + "# Initialize the network\n", + "# weights and bias in the hidden layer\n", + "w_1 = np.random.randn(n_features, n_hidden_neurons)\n", + "b_1 = np.zeros(n_hidden_neurons) + 0.01\n", + "\n", + "# weights and bias in the output layer\n", + "w_2 = np.random.randn(n_hidden_neurons, n_outputs)\n", + "b_2 = np.zeros(n_outputs) + 0.01\n", + "\n", + "eta = 0.1\n", + "for i in range(50):\n", + " # calculate gradients\n", + " derivW2, derivB2, derivW1, derivB1 = backpropagation(x, y)\n", + " # update weights and biases\n", + " w_2 -= eta * derivW2\n", + " b_2 -= eta * derivB2\n", + " w_1 -= eta * derivW1\n", + " b_1 -= eta * derivB1" + ] + }, + { + "cell_type": "markdown", + "id": "351debb8", + "metadata": { + "editable": true + }, + "source": [ + "We see that after some few iterations (the results do depend on the learning rate however), we get an error which is rather small." + ] + }, + { + "cell_type": "markdown", + "id": "c6579e36", + "metadata": { + "editable": true + }, + "source": [ + "## Exercise 1: Including more data\n", + "\n", + "Try to increase the amount of input and\n", + "target/output data. Try also to perform calculations for more values\n", + "of the learning rates. Feel free to add either hyperparameters with an\n", + "$l_1$ norm or an $l_2$ norm and discuss your results.\n", + "Discuss your results as functions of the amount of training data and various learning rates.\n", + "\n", + "**Challenge:** Try to change the activation functions and replace the hard-coded analytical expressions with automatic derivation via either **autograd** or **JAX**." + ] + }, + { + "cell_type": "markdown", + "id": "2c80a4b1", + "metadata": { + "editable": true + }, + "source": [ + "## Simple neural network and the back propagation equations\n", + "\n", + "Let us now try to increase our level of ambition and attempt at setting \n", + "up the equations for a neural network with two input nodes, one hidden\n", + "layer with two hidden nodes and one output layer with one output node/neuron only (see graph)..\n", + "\n", + "We need to define the following parameters and variables with the input layer (layer $(0)$) \n", + "where we label the nodes $x_0$ and $x_1$" + ] + }, + { + "cell_type": "markdown", + "id": "c834edc8", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "x_0 = a_0^{(0)} \\wedge x_1 = a_1^{(0)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "79bd199b", + "metadata": { + "editable": true + }, + "source": [ + "The hidden layer (layer $(1)$) has nodes which yield the outputs $a_0^{(1)}$ and $a_1^{(1)}$) with weight $\\boldsymbol{w}$ and bias $\\boldsymbol{b}$ parameters" + ] + }, + { + "cell_type": "markdown", + "id": "0a856855", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{ij}^{(1)}=\\left\\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)}\\right\\} \\wedge b^{(1)}=\\left\\{b_0^{(1)},b_1^{(1)}\\right\\}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "54280198", + "metadata": { + "editable": true + }, + "source": [ + "## Layout of a simple neural network with two input nodes, one hidden layer and one output node\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "b2cee09c", + "metadata": { + "editable": true + }, + "source": [ + "## The ouput layer\n", + "\n", + "Finally, we have the ouput layer given by layer label $(2)$ with output $a^{(2)}$ and weights and biases to be determined given by the variables" + ] + }, + { + "cell_type": "markdown", + "id": "710131c9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}^{(2)}=\\left\\{w_{0}^{(2)},w_{1}^{(2)}\\right\\} \\wedge b^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "cd8b54e5", + "metadata": { + "editable": true + }, + "source": [ + "Our output is $\\tilde{y}=a^{(2)}$ and we define a generic cost function $C(a^{(2)},y;\\boldsymbol{\\Theta})$ where $y$ is the target value (a scalar here).\n", + "The parameters we need to optimize are given by" + ] + }, + { + "cell_type": "markdown", + "id": "8998ad11", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{\\Theta}=\\left\\{w_{00}^{(1)},w_{01}^{(1)},w_{10}^{(1)},w_{11}^{(1)},w_{0}^{(2)},w_{1}^{(2)},b_0^{(1)},b_1^{(1)},b^{(2)}\\right\\}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7d430cf7", + "metadata": { + "editable": true + }, + "source": [ + "## Compact expressions\n", + "\n", + "We can define the inputs to the activation functions for the various layers in terms of various matrix-vector multiplications and vector additions.\n", + "The inputs to the first hidden layer are" + ] + }, + { + "cell_type": "markdown", + "id": "9b5a6c95", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix}z_0^{(1)} \\\\ z_1^{(1)} \\end{bmatrix}=\\begin{bmatrix}w_{00}^{(1)} & w_{01}^{(1)}\\\\ w_{10}^{(1)} &w_{11}^{(1)} \\end{bmatrix}\\begin{bmatrix}a_0^{(0)} \\\\ a_1^{(0)} \\end{bmatrix}+\\begin{bmatrix}b_0^{(1)} \\\\ b_1^{(1)} \\end{bmatrix},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "31d044d8", + "metadata": { + "editable": true + }, + "source": [ + "with outputs" + ] + }, + { + "cell_type": "markdown", + "id": "f5125cb7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\begin{bmatrix}a_0^{(1)} \\\\ a_1^{(1)} \\end{bmatrix}=\\begin{bmatrix}\\sigma^{(1)}(z_0^{(1)}) \\\\ \\sigma^{(1)}(z_1^{(1)}) \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0eed1fab", + "metadata": { + "editable": true + }, + "source": [ + "## Output layer\n", + "\n", + "For the final output layer we have the inputs to the final activation function" + ] + }, + { + "cell_type": "markdown", + "id": "9a9811d2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z^{(2)} = w_{0}^{(2)}a_0^{(1)} +w_{1}^{(2)}a_1^{(1)}+b^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "98bf5097", + "metadata": { + "editable": true + }, + "source": [ + "resulting in the output" + ] + }, + { + "cell_type": "markdown", + "id": "e749c895", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "a^{(2)}=\\sigma^{(2)}(z^{(2)}).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "ea6692ce", + "metadata": { + "editable": true + }, + "source": [ + "## Explicit derivatives\n", + "\n", + "In total we have nine parameters which we need to train. Using the\n", + "chain rule (or just the back-propagation algorithm) we can find all\n", + "derivatives. Since we will use automatic differentiation in reverse\n", + "mode, we start with the derivatives of the cost function with respect\n", + "to the parameters of the output layer, namely" + ] + }, + { + "cell_type": "markdown", + "id": "bf74eae4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{i}^{(2)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\\frac{\\partial z^{(2)}}{\\partial w_{i}^{(2)}}=\\delta^{(2)}a_i^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "d590dc50", + "metadata": { + "editable": true + }, + "source": [ + "with" + ] + }, + { + "cell_type": "markdown", + "id": "eb0b8e3c", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta^{(2)}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7928cd11", + "metadata": { + "editable": true + }, + "source": [ + "and finally" + ] + }, + { + "cell_type": "markdown", + "id": "8fc852e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b^{(2)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\\frac{\\partial z^{(2)}}{\\partial b^{(2)}}=\\delta^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "634713ba", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives of the hidden layer\n", + "\n", + "Using the chain rule we have the following expressions for say one of the weight parameters (it is easy to generalize to the other weight parameters)" + ] + }, + { + "cell_type": "markdown", + "id": "0f6ca3e6", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{00}^{(1)}}=\\frac{\\partial C}{\\partial a^{(2)}}\\frac{\\partial a^{(2)}}{\\partial z^{(2)}}\n", + "\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}}= \\delta^{(2)}\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3b54e63f", + "metadata": { + "editable": true + }, + "source": [ + "which, noting that" + ] + }, + { + "cell_type": "markdown", + "id": "a69c61ff", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "z^{(2)} =w_0^{(2)}a_0^{(1)}+w_1^{(2)}a_1^{(1)}+b^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "a73b8fe2", + "metadata": { + "editable": true + }, + "source": [ + "allows us to rewrite" + ] + }, + { + "cell_type": "markdown", + "id": "093c845d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial z^{(2)}}{\\partial z_0^{(1)}}\\frac{\\partial z_0^{(1)}}{\\partial w_{00}^{(1)}}=w_0^{(2)}\\frac{\\partial a_0^{(1)}}{\\partial z_0^{(1)}}a_0^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dcd12209", + "metadata": { + "editable": true + }, + "source": [ + "## Final expression\n", + "Defining" + ] + }, + { + "cell_type": "markdown", + "id": "5d5e8985", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_0^{(1)}=w_0^{(2)}\\frac{\\partial a_0^{(1)}}{\\partial z_0^{(1)}}\\delta^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "506f74bf", + "metadata": { + "editable": true + }, + "source": [ + "we have" + ] + }, + { + "cell_type": "markdown", + "id": "b474afaa", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{00}^{(1)}}=\\delta_0^{(1)}a_0^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "7d14d370", + "metadata": { + "editable": true + }, + "source": [ + "Similarly, we obtain" + ] + }, + { + "cell_type": "markdown", + "id": "ca679e05", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{01}^{(1)}}=\\delta_0^{(1)}a_1^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "251a03fd", + "metadata": { + "editable": true + }, + "source": [ + "## Completing the list\n", + "\n", + "Similarly, we find" + ] + }, + { + "cell_type": "markdown", + "id": "b7575ec0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{10}^{(1)}}=\\delta_1^{(1)}a_0^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "02453de3", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "4e989854", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial w_{11}^{(1)}}=\\delta_1^{(1)}a_1^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "05a25565", + "metadata": { + "editable": true + }, + "source": [ + "where we have defined" + ] + }, + { + "cell_type": "markdown", + "id": "d9e571d7", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_1^{(1)}=w_1^{(2)}\\frac{\\partial a_1^{(1)}}{\\partial z_1^{(1)}}\\delta^{(2)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "f96632e9", + "metadata": { + "editable": true + }, + "source": [ + "## Final expressions for the biases of the hidden layer\n", + "\n", + "For the sake of completeness, we list the derivatives of the biases, which are" + ] + }, + { + "cell_type": "markdown", + "id": "e15002e0", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_{0}^{(1)}}=\\delta_0^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8c683755", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "da56a290", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial C}{\\partial b_{1}^{(1)}}=\\delta_1^{(1)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "e42a9d6c", + "metadata": { + "editable": true + }, + "source": [ + "As we will see below, these expressions can be generalized in a more compact form." + ] + }, + { + "cell_type": "markdown", + "id": "21dd6563", + "metadata": { + "editable": true + }, + "source": [ + "## Gradient expressions\n", + "\n", + "For this specific model, with just one output node and two hidden\n", + "nodes, the gradient descent equations take the following form for output layer" + ] + }, + { + "cell_type": "markdown", + "id": "67fc0189", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{i}^{(2)}\\leftarrow w_{i}^{(2)}- \\eta \\delta^{(2)} a_{i}^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "daddd95e", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "5bf8af85", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b^{(2)} \\leftarrow b^{(2)}-\\eta \\delta^{(2)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5a72ea0a", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "edd32da2", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{ij}^{(1)}\\leftarrow w_{ij}^{(1)}- \\eta \\delta_{i}^{(1)} a_{j}^{(0)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "75c31af5", + "metadata": { + "editable": true + }, + "source": [ + "and" + ] + }, + { + "cell_type": "markdown", + "id": "c037d92b", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_{i}^{(1)} \\leftarrow b_{i}^{(1)}-\\eta \\delta_{i}^{(1)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "5937fd51", + "metadata": { + "editable": true + }, + "source": [ + "where $\\eta$ is the learning rate." + ] + }, + { + "cell_type": "markdown", + "id": "3f0f6cd3", + "metadata": { + "editable": true + }, + "source": [ + "## Exercise 2: Extended program\n", + "\n", + "We extend our simple code to a function which depends on two variable $x_0$ and $x_1$, that is" + ] + }, + { + "cell_type": "markdown", + "id": "057366c1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "y=f(x_0,x_1)=x_0^2+3x_0x_1+x_1^2+5.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "293fa11b", + "metadata": { + "editable": true + }, + "source": [ + "We feed our network with $n=100$ entries $x_0$ and $x_1$. We have thus two features represented by these variable and an input matrix/design matrix $\\boldsymbol{X}\\in \\mathbf{R}^{n\\times 2}$" + ] + }, + { + "cell_type": "markdown", + "id": "d652c45d", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{X}=\\begin{bmatrix} x_{00} & x_{01} \\\\ x_{00} & x_{01} \\\\ x_{10} & x_{11} \\\\ x_{20} & x_{21} \\\\ \\dots & \\dots \\\\ \\dots & \\dots \\\\ x_{n-20} & x_{n-21} \\\\ x_{n-10} & x_{n-11} \\end{bmatrix}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8ca9d167", + "metadata": { + "editable": true + }, + "source": [ + "Write a code, based on the previous code examples, which takes as input these data and fit the above function.\n", + "You can extend your code to include automatic differentiation.\n", + "\n", + "With these examples, we are now ready to embark upon the writing of more a general code for neural networks." + ] + }, + { + "cell_type": "markdown", + "id": "8fed1e03", + "metadata": { + "editable": true + }, + "source": [ + "## Getting serious, the back propagation equations for a neural network\n", + "\n", + "Now it is time to move away from one node in each layer only. Our inputs are also represented either by several inputs.\n", + "\n", + "We have thus" + ] + }, + { + "cell_type": "markdown", + "id": "6394a2a5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}((\\boldsymbol{\\Theta}^L)}{\\partial w_{jk}^L} = \\left(a_j^L - y_j\\right)a_j^L(1-a_j^L)a_k^{L-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "c2e22893", + "metadata": { + "editable": true + }, + "source": [ + "Defining" + ] + }, + { + "cell_type": "markdown", + "id": "5e054d69", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L = a_j^L(1-a_j^L)\\left(a_j^L - y_j\\right) = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dd5f9a8d", + "metadata": { + "editable": true + }, + "source": [ + "and using the Hadamard product of two vectors we can write this as" + ] + }, + { + "cell_type": "markdown", + "id": "ff6e8f86", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\boldsymbol{\\delta}^L = \\sigma'(\\hat{z}^L)\\circ\\frac{\\partial {\\cal C}}{\\partial (\\boldsymbol{a}^L)}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "6e186667", + "metadata": { + "editable": true + }, + "source": [ + "## Analyzing the last results\n", + "\n", + "This is an important expression. The second term on the right handside\n", + "measures how fast the cost function is changing as a function of the $j$th\n", + "output activation. If, for example, the cost function doesn't depend\n", + "much on a particular output node $j$, then $\\delta_j^L$ will be small,\n", + "which is what we would expect. The first term on the right, measures\n", + "how fast the activation function $f$ is changing at a given activation\n", + "value $z_j^L$." + ] + }, + { + "cell_type": "markdown", + "id": "0e0a514f", + "metadata": { + "editable": true + }, + "source": [ + "## More considerations\n", + "\n", + "Notice that everything in the above equations is easily computed. In\n", + "particular, we compute $z_j^L$ while computing the behaviour of the\n", + "network, and it is only a small additional overhead to compute\n", + "$\\sigma'(z^L_j)$. The exact form of the derivative with respect to the\n", + "output depends on the form of the cost function.\n", + "However, provided the cost function is known there should be little\n", + "trouble in calculating" + ] + }, + { + "cell_type": "markdown", + "id": "e8259ee9", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3c817881", + "metadata": { + "editable": true + }, + "source": [ + "With the definition of $\\delta_j^L$ we have a more compact definition of the derivative of the cost function in terms of the weights, namely" + ] + }, + { + "cell_type": "markdown", + "id": "0f3e5b1c", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\frac{\\partial{\\cal C}}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1}.\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "4e14ef60", + "metadata": { + "editable": true + }, + "source": [ + "## Derivatives in terms of $z_j^L$\n", + "\n", + "It is also easy to see that our previous equation can be written as" + ] + }, + { + "cell_type": "markdown", + "id": "886fbebf", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L =\\frac{\\partial {\\cal C}}{\\partial z_j^L}= \\frac{\\partial {\\cal C}}{\\partial a_j^L}\\frac{\\partial a_j^L}{\\partial z_j^L},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "16d62157", + "metadata": { + "editable": true + }, + "source": [ + "which can also be interpreted as the partial derivative of the cost function with respect to the biases $b_j^L$, namely" + ] + }, + { + "cell_type": "markdown", + "id": "4a81d6b5", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L}\\frac{\\partial b_j^L}{\\partial z_j^L}=\\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "0bcee50c", + "metadata": { + "editable": true + }, + "source": [ + "That is, the error $\\delta_j^L$ is exactly equal to the rate of change of the cost function as a function of the bias." + ] + }, + { + "cell_type": "markdown", + "id": "0ed7f7a0", + "metadata": { + "editable": true + }, + "source": [ + "## Bringing it together\n", + "\n", + "We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are" + ] + }, + { + "cell_type": "markdown", + "id": "a502b908", "metadata": { "editable": true }, @@ -614,7 +3653,8 @@ "
    \n", "\n", "$$\n", - "\\begin{equation} z_i^1 = \\sum_{j=1}^{M} w_{ij}^1 x_j + b_i^1\n", + "\\begin{equation}\n", + "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1},\n", "\\label{_auto1} \\tag{2}\n", "\\end{equation}\n", "$$" @@ -622,95 +3662,17 @@ }, { "cell_type": "markdown", - "id": "3267338f", + "id": "fa4de05b", "metadata": { "editable": true }, "source": [ - "Here $b_i$ is the so-called bias which is normally needed in\n", - "case of zero activation weights or inputs. How to fix the biases and\n", - "the weights will be discussed below. The value of $z_i^1$ is the\n", - "argument to the activation function $f_i$ of each node $i$, The\n", - "variable $M$ stands for all possible inputs to a given node $i$ in the\n", - "first layer. We define the output $y_i^1$ of all neurons in layer 1 as" + "and" ] }, { "cell_type": "markdown", - "id": "04a1a613", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - " y_i^1 = f(z_i^1) = f\\left(\\sum_{j=1}^M w_{ij}^1 x_j + b_i^1\\right)\n", - "\\label{outputLayer1} \\tag{3}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bc8b70e2", - "metadata": { - "editable": true - }, - "source": [ - "where we assume that all nodes in the same layer have identical\n", - "activation functions, hence the notation $f$. In general, we could assume in the more general case that different layers have different activation functions.\n", - "In this case we would identify these functions with a superscript $l$ for the $l$-th layer," - ] - }, - { - "cell_type": "markdown", - "id": "10686541", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - " y_i^l = f^l(u_i^l) = f^l\\left(\\sum_{j=1}^{N_{l-1}} w_{ij}^l y_j^{l-1} + b_i^l\\right)\n", - "\\label{generalLayer} \\tag{4}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "a92cdf36", - "metadata": { - "editable": true - }, - "source": [ - "where $N_l$ is the number of nodes in layer $l$. When the output of\n", - "all the nodes in the first hidden layer are computed, the values of\n", - "the subsequent layer can be calculated and so forth until the output\n", - "is obtained." - ] - }, - { - "cell_type": "markdown", - "id": "74dcfa13", - "metadata": { - "editable": true - }, - "source": [ - "## Mathematical model\n", - "\n", - "The output of neuron $i$ in layer 2 is thus," - ] - }, - { - "cell_type": "markdown", - "id": "0147afef", + "id": "cea42eaf", "metadata": { "editable": true }, @@ -720,43 +3682,25 @@ "\n", "$$\n", "\\begin{equation}\n", - " y_i^2 = f^2\\left(\\sum_{j=1}^N w_{ij}^2 y_j^1 + b_i^2\\right) \n", - "\\label{_auto2} \\tag{5}\n", + "\\delta_j^L = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", + "\\label{_auto2} \\tag{3}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "4a4d5b2e", + "id": "d04fa6e6", "metadata": { "editable": true }, "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation} \n", - " = f^2\\left[\\sum_{j=1}^N w_{ij}^2f^1\\left(\\sum_{k=1}^M w_{jk}^1 x_k + b_j^1\\right) + b_i^2\\right]\n", - "\\label{outputLayer2} \\tag{6}\n", - "\\end{equation}\n", - "$$" + "and" ] }, { "cell_type": "markdown", - "id": "31742756", - "metadata": { - "editable": true - }, - "source": [ - "where we have substituted $y_k^1$ with the inputs $x_k$. Finally, the ANN output reads" - ] - }, - { - "cell_type": "markdown", - "id": "123af90c", + "id": "8716ad2e", "metadata": { "editable": true }, @@ -766,224 +3710,304 @@ "\n", "$$\n", "\\begin{equation}\n", - " y_i^3 = f^3\\left(\\sum_{j=1}^N w_{ij}^3 y_j^2 + b_i^3\\right) \n", - "\\label{_auto3} \\tag{7}\n", + "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", + "\\label{_auto3} \\tag{4}\n", "\\end{equation}\n", "$$" ] }, { "cell_type": "markdown", - "id": "aeb7cc95", + "id": "f64753b2", "metadata": { "editable": true }, "source": [ - "\n", - "
    \n", + "## Final back propagating equation\n", "\n", + "We have that (replacing $L$ with a general layer $l$)" + ] + }, + { + "cell_type": "markdown", + "id": "4ad6d6d3", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation} \n", - " = f_3\\left[\\sum_{j} w_{ij}^3 f^2\\left(\\sum_{k} w_{jk}^2 f^1\\left(\\sum_{m} w_{km}^1 x_m + b_k^1\\right) + b_j^2\\right)\n", - " + b_1^3\\right]\n", - "\\label{_auto4} \\tag{8}\n", - "\\end{equation}\n", + "\\delta_j^l =\\frac{\\partial {\\cal C}}{\\partial z_j^l}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "3ab7d88c", + "id": "a8d42ee3", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", - "\n", - "We can generalize this expression to an MLP with $l$ hidden\n", - "layers. The complete functional form is," + "We want to express this in terms of the equations for layer $l+1$." ] }, { "cell_type": "markdown", - "id": "9b07f5bb", + "id": "0628c4b8", "metadata": { "editable": true }, "source": [ - "\n", - "
    \n", + "## Using the chain rule and summing over all $k$ entries\n", "\n", + "We obtain" + ] + }, + { + "cell_type": "markdown", + "id": "0868f3d3", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation}\n", - "y^{l+1}_i = f^{l+1}\\left[\\!\\sum_{j=1}^{N_l} w_{ij}^3 f^l\\left(\\sum_{k=1}^{N_{l-1}}w_{jk}^{l-1}\\left(\\dots f^1\\left(\\sum_{n=1}^{N_0} w_{mn}^1 x_n+ b_m^1\\right)\\dots\\right)+b_k^2\\right)+b_1^3\\right] \n", - "\\label{completeNN} \\tag{9}\n", - "\\end{equation}\n", + "\\delta_j^l =\\sum_k \\frac{\\partial {\\cal C}}{\\partial z_k^{l+1}}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}}=\\sum_k \\delta_k^{l+1}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}},\n", "$$" ] }, { "cell_type": "markdown", - "id": "e9b4beb5", + "id": "89190c24", "metadata": { "editable": true }, "source": [ - "which illustrates a basic property of MLPs: The only independent\n", - "variables are the input values $x_n$." + "and recalling that" ] }, { "cell_type": "markdown", - "id": "57213d71", + "id": "96af414a", "metadata": { "editable": true }, "source": [ - "## Mathematical model\n", - "\n", - "This confirms that an MLP, despite its quite convoluted mathematical\n", - "form, is nothing more than an analytic function, specifically a\n", - "mapping of real-valued vectors $\\hat{x} \\in \\mathbb{R}^n \\rightarrow\n", - "\\hat{y} \\in \\mathbb{R}^m$.\n", - "\n", - "Furthermore, the flexibility and universality of an MLP can be\n", - "illustrated by realizing that the expression is essentially a nested\n", - "sum of scaled activation functions of the form" - ] - }, - { - "cell_type": "markdown", - "id": "85dc952c", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", "$$\n", - "\\begin{equation}\n", - " f(x) = c_1 f(c_2 x + c_3) + c_4\n", - "\\label{_auto5} \\tag{10}\n", - "\\end{equation}\n", + "z_j^{l+1} = \\sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1},\n", "$$" ] }, { "cell_type": "markdown", - "id": "4a67580f", + "id": "fe790abf", "metadata": { "editable": true }, "source": [ - "where the parameters $c_i$ are weights and biases. By adjusting these\n", - "parameters, the activation functions can be shifted up and down or\n", - "left and right, change slope or be rescaled which is the key to the\n", - "flexibility of a neural network." + "with $M_l$ being the number of nodes in layer $l$, we obtain" ] }, { "cell_type": "markdown", - "id": "19f79e3c", + "id": "ece1f6fe", "metadata": { "editable": true }, "source": [ - "### Matrix-vector notation\n", - "\n", - "We can introduce a more convenient notation for the activations in an A NN. \n", - "\n", - "Additionally, we can represent the biases and activations\n", - "as layer-wise column vectors $\\hat{b}_l$ and $\\hat{y}_l$, so that the $i$-th element of each vector \n", - "is the bias $b_i^l$ and activation $y_i^l$ of node $i$ in layer $l$ respectively. \n", - "\n", - "We have that $\\mathrm{W}_l$ is an $N_{l-1} \\times N_l$ matrix, while $\\hat{b}_l$ and $\\hat{y}_l$ are $N_l \\times 1$ column vectors. \n", - "With this notation, the sum becomes a matrix-vector multiplication, and we can write\n", - "the equation for the activations of hidden layer 2 (assuming three nodes for simplicity) as" - ] - }, - { - "cell_type": "markdown", - "id": "e350b83c", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", "$$\n", - "\\begin{equation}\n", - " \\hat{y}_2 = f_2(\\mathrm{W}_2 \\hat{y}_{1} + \\hat{b}_{2}) = \n", - " f_2\\left(\\left[\\begin{array}{ccc}\n", - " w^2_{11} &w^2_{12} &w^2_{13} \\\\\n", - " w^2_{21} &w^2_{22} &w^2_{23} \\\\\n", - " w^2_{31} &w^2_{32} &w^2_{33} \\\\\n", - " \\end{array} \\right] \\cdot\n", - " \\left[\\begin{array}{c}\n", - " y^1_1 \\\\\n", - " y^1_2 \\\\\n", - " y^1_3 \\\\\n", - " \\end{array}\\right] + \n", - " \\left[\\begin{array}{c}\n", - " b^2_1 \\\\\n", - " b^2_2 \\\\\n", - " b^2_3 \\\\\n", - " \\end{array}\\right]\\right).\n", - "\\label{_auto6} \\tag{11}\n", - "\\end{equation}\n", + "\\delta_j^l =\\sum_k \\delta_k^{l+1}w_{kj}^{l+1}\\sigma'(z_j^l),\n", "$$" ] }, { "cell_type": "markdown", - "id": "3b64eaf6", + "id": "9cafdde6", "metadata": { "editable": true }, "source": [ - "### Matrix-vector notation and activation\n", + "This is our final equation.\n", "\n", - "The activation of node $i$ in layer 2 is" + "We are now ready to set up the algorithm for back propagation and learning the weights and biases." ] }, { "cell_type": "markdown", - "id": "dc8ca05e", + "id": "0766f482", "metadata": { "editable": true }, "source": [ - "\n", - "
    \n", + "## Setting up the back propagation algorithm\n", "\n", + "The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", + "\n", + "**First**, we set up the input data $\\hat{x}$ and the activations\n", + "$\\hat{z}_1$ of the input layer and compute the activation function and\n", + "the pertinent outputs $\\hat{a}^1$.\n", + "\n", + "**Secondly**, we perform then the feed forward till we reach the output\n", + "layer and compute all $\\hat{z}_l$ of the input layer and compute the\n", + "activation function and the pertinent outputs $\\hat{a}^l$ for\n", + "$l=1,2,3,\\dots,L$.\n", + "\n", + "**Notation**: The first hidden layer has $l=1$ as label and the final output layer has $l=L$." + ] + }, + { + "cell_type": "markdown", + "id": "e29ae382", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the back propagation algorithm, part 2\n", + "\n", + "Thereafter we compute the ouput error $\\hat{\\delta}^L$ by computing all" + ] + }, + { + "cell_type": "markdown", + "id": "518b6578", + "metadata": { + "editable": true + }, + "source": [ "$$\n", - "\\begin{equation}\n", - " y^2_i = f_2\\Bigr(w^2_{i1}y^1_1 + w^2_{i2}y^1_2 + w^2_{i3}y^1_3 + b^2_i\\Bigr) = \n", - " f_2\\left(\\sum_{j=1}^3 w^2_{ij} y_j^1 + b^2_i\\right).\n", - "\\label{_auto7} \\tag{12}\n", - "\\end{equation}\n", + "\\delta_j^L = \\sigma'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", "$$" ] }, { "cell_type": "markdown", - "id": "079a6c4b", + "id": "4f804851", "metadata": { "editable": true }, "source": [ - "This is not just a convenient and compact notation, but also a useful\n", - "and intuitive way to think about MLPs: The output is calculated by a\n", - "series of matrix-vector multiplications and vector additions that are\n", - "used as input to the activation functions. For each operation\n", - "$\\mathrm{W}_l \\hat{y}_{l-1}$ we move forward one layer." + "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,1$ as" ] }, { "cell_type": "markdown", - "id": "3498dab8", + "id": "359aae81", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}\\sigma'(z_j^l).\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "70123228", + "metadata": { + "editable": true + }, + "source": [ + "## Setting up the Back propagation algorithm, part 3\n", + "\n", + "Finally, we update the weights and the biases using gradient descent\n", + "for each $l=L-1,L-2,\\dots,1$ and update the weights and biases\n", + "according to the rules" + ] + }, + { + "cell_type": "markdown", + "id": "2df5a3de", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "8081e4e4", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "3c40603c", + "metadata": { + "editable": true + }, + "source": [ + "with $\\eta$ being the learning rate." + ] + }, + { + "cell_type": "markdown", + "id": "26de0b47", + "metadata": { + "editable": true + }, + "source": [ + "## Updating the gradients\n", + "\n", + "With the back propagate error for each $l=L-1,L-2,\\dots,1$ as" + ] + }, + { + "cell_type": "markdown", + "id": "a172a64a", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}sigma'(z_j^l),\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "dfd6fc88", + "metadata": { + "editable": true + }, + "source": [ + "we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,1$ and update the weights and biases according to the rules" + ] + }, + { + "cell_type": "markdown", + "id": "a7df4398", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "cfd24fc1", + "metadata": { + "editable": true + }, + "source": [ + "$$\n", + "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", + "$$" + ] + }, + { + "cell_type": "markdown", + "id": "869c3364", "metadata": { "editable": true }, @@ -1006,7 +4030,7 @@ }, { "cell_type": "markdown", - "id": "c0b93415", + "id": "91102a3c", "metadata": { "editable": true }, @@ -1025,7 +4049,7 @@ }, { "cell_type": "markdown", - "id": "74a5d31d", + "id": "9609f422", "metadata": { "editable": true }, @@ -1037,7 +4061,7 @@ }, { "cell_type": "markdown", - "id": "539998aa", + "id": "cdd8d562", "metadata": { "editable": true }, @@ -1047,7 +4071,7 @@ }, { "cell_type": "markdown", - "id": "e4b4b760", + "id": "118a47f2", "metadata": { "editable": true }, @@ -1059,7 +4083,7 @@ }, { "cell_type": "markdown", - "id": "b98e352b", + "id": "5d6387b5", "metadata": { "editable": true }, @@ -1075,8 +4099,8 @@ }, { "cell_type": "code", - "execution_count": 4, - "id": "9f6ead02", + "execution_count": 7, + "id": "33449cca", "metadata": { "collapsed": false, "editable": true @@ -1158,2811 +4182,459 @@ }, { "cell_type": "markdown", - "id": "95f54888", + "id": "e8fafa8a", "metadata": { "editable": true }, "source": [ - "## The multilayer perceptron (MLP)\n", + "## Fine-tuning neural network hyperparameters\n", "\n", - "The multilayer perceptron is a very popular, and easy to implement approach, to deep learning. It consists of\n", - "1. A neural network with one or more layers of nodes between the input and the output nodes.\n", + "The flexibility of neural networks is also one of their main\n", + "drawbacks: there are many hyperparameters to tweak. Not only can you\n", + "use any imaginable network topology (how neurons/nodes are\n", + "interconnected), but even in a simple FFNN you can change the number\n", + "of layers, the number of neurons per layer, the type of activation\n", + "function to use in each layer, the weight initialization logic, the\n", + "stochastic gradient optmized and much more. How do you know what\n", + "combination of hyperparameters is the best for your task?\n", "\n", - "2. The multilayer network structure, or architecture, or topology, consists of an input layer, one or more hidden layers, and one output layer.\n", + "* You can use grid search with cross-validation to find the right hyperparameters.\n", "\n", - "3. The input nodes pass values to the first hidden layer, its nodes pass the information on to the second and so on till we reach the output layer.\n", + "However,since there are many hyperparameters to tune, and since\n", + "training a neural network on a large dataset takes a lot of time, you\n", + "will only be able to explore a tiny part of the hyperparameter space.\n", "\n", - "As a convention it is normal to call a network with one layer of input units, one layer of hidden\n", - "units and one layer of output units as a two-layer network. A network with two layers of hidden units is called a three-layer network etc etc.\n", + "* You can use randomized search.\n", "\n", - "For an MLP network there is no direct connection between the output nodes/neurons/units and the input nodes/neurons/units.\n", - "Hereafter we will call the various entities of a layer for nodes.\n", - "There are also no connections within a single layer.\n", - "\n", - "The number of input nodes does not need to equal the number of output\n", - "nodes. This applies also to the hidden layers. Each layer may have its\n", - "own number of nodes and activation functions.\n", - "\n", - "The hidden layers have their name from the fact that they are not\n", - "linked to observables and as we will see below when we define the\n", - "so-called activation $\\hat{z}$, we can think of this as a basis\n", - "expansion of the original inputs $\\hat{x}$. The difference however\n", - "between neural networks and say linear regression is that now these\n", - "basis functions (which will correspond to the weights in the network)\n", - "are learned from data. This results in an important difference between\n", - "neural networks and deep learning approaches on one side and methods\n", - "like logistic regression or linear regression and their modifications on the other side." + "* Or use tools like [Oscar](http://oscar.calldesk.ai/), which implements more complex algorithms to help you find a good set of hyperparameters quickly." ] }, { "cell_type": "markdown", - "id": "91bf2419", + "id": "00965f5d", "metadata": { "editable": true }, "source": [ - "## From one to many layers, the universal approximation theorem\n", + "## Hidden layers\n", "\n", - "A neural network with only one layer, what we called the simple\n", - "perceptron, is best suited if we have a standard binary model with\n", - "clear (linear) boundaries between the outcomes. As such it could\n", - "equally well be replaced by standard linear regression or logistic\n", - "regression. Networks with one or more hidden layers approximate\n", - "systems with more complex boundaries.\n", + "For many problems you can start with just one or two hidden layers and\n", + "it will work just fine. For the MNIST data set you ca easily get a\n", + "high accuracy using just one hidden layer with a few hundred neurons.\n", + "You can reach for this data set above 98% accuracy using two hidden\n", + "layers with the same total amount of neurons, in roughly the same\n", + "amount of training time.\n", "\n", - "As stated earlier, \n", - "an important theorem in studies of neural networks, restated without\n", - "proof here, is the [universal approximation\n", - "theorem](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.441.7873&rep=rep1&type=pdf).\n", - "\n", - "It states that a feed-forward network with a single hidden layer\n", - "containing a finite number of neurons can approximate continuous\n", - "functions on compact subsets of real functions. The theorem thus\n", - "states that simple neural networks can represent a wide variety of\n", - "interesting functions when given appropriate parameters. It is the\n", - "multilayer feedforward architecture itself which gives neural networks\n", - "the potential of being universal approximators." + "For more complex problems, you can gradually ramp up the number of\n", + "hidden layers, until you start overfitting the training set. Very\n", + "complex tasks, such as large image classification or speech\n", + "recognition, typically require networks with dozens of layers and they\n", + "need a huge amount of training data. However, you will rarely have to\n", + "train such networks from scratch: it is much more common to reuse\n", + "parts of a pretrained state-of-the-art network that performs a similar\n", + "task." ] }, { "cell_type": "markdown", - "id": "6500ed58", + "id": "d90316a8", "metadata": { "editable": true }, "source": [ - "## Deriving the back propagation code for a multilayer perceptron model\n", + "## Vanishing gradients\n", "\n", - "As we have seen now in a feed forward network, we can express the final output of our network in terms of basic matrix-vector multiplications.\n", - "The unknowwn quantities are our weights $w_{ij}$ and we need to find an algorithm for changing them so that our errors are as small as possible.\n", - "This leads us to the famous [back propagation algorithm](https://www.nature.com/articles/323533a0).\n", + "The Back propagation algorithm we derived above works by going from\n", + "the output layer to the input layer, propagating the error gradient on\n", + "the way. Once the algorithm has computed the gradient of the cost\n", + "function with regards to each parameter in the network, it uses these\n", + "gradients to update each parameter with a Gradient Descent (GD) step.\n", "\n", - "The questions we want to ask are how do changes in the biases and the\n", - "weights in our network change the cost function and how can we use the\n", - "final output to modify the weights?\n", - "\n", - "To derive these equations let us start with a plain regression problem\n", - "and define our cost function as" + "Unfortunately for us, the gradients often get smaller and smaller as\n", + "the algorithm progresses down to the first hidden layers. As a result,\n", + "the GD update leaves the lower layer connection weights virtually\n", + "unchanged, and training never converges to a good solution. This is\n", + "known in the literature as **the vanishing gradients problem**." ] }, { "cell_type": "markdown", - "id": "703f7235", + "id": "441fe8d9", + "metadata": { + "editable": true + }, + "source": [ + "## Exploding gradients\n", + "\n", + "In other cases, the opposite can happen, namely the the gradients can\n", + "grow bigger and bigger. The result is that many of the layers get\n", + "large updates of the weights the algorithm diverges. This is the\n", + "**exploding gradients problem**, which is mostly encountered in\n", + "recurrent neural networks. More generally, deep neural networks suffer\n", + "from unstable gradients, different layers may learn at widely\n", + "different speeds" + ] + }, + { + "cell_type": "markdown", + "id": "ae55ad1c", + "metadata": { + "editable": true + }, + "source": [ + "## Is the Logistic activation function (Sigmoid) our choice?\n", + "\n", + "Although this unfortunate behavior has been empirically observed for\n", + "quite a while (it was one of the reasons why deep neural networks were\n", + "mostly abandoned for a long time), it is only around 2010 that\n", + "significant progress was made in understanding it.\n", + "\n", + "A paper titled [Understanding the Difficulty of Training Deep\n", + "Feedforward Neural Networks by Xavier Glorot and Yoshua Bengio](http://proceedings.mlr.press/v9/glorot10a.html) found that\n", + "the problems with the popular logistic\n", + "sigmoid activation function and the weight initialization technique\n", + "that was most popular at the time, namely random initialization using\n", + "a normal distribution with a mean of 0 and a standard deviation of\n", + "1." + ] + }, + { + "cell_type": "markdown", + "id": "96bbf798", + "metadata": { + "editable": true + }, + "source": [ + "## Logistic function as the root of problems\n", + "\n", + "They showed that with this activation function and this\n", + "initialization scheme, the variance of the outputs of each layer is\n", + "much greater than the variance of its inputs. Going forward in the\n", + "network, the variance keeps increasing after each layer until the\n", + "activation function saturates at the top layers. This is actually made\n", + "worse by the fact that the logistic function has a mean of 0.5, not 0\n", + "(the hyperbolic tangent function has a mean of 0 and behaves slightly\n", + "better than the logistic function in deep networks)." + ] + }, + { + "cell_type": "markdown", + "id": "4b03e108", + "metadata": { + "editable": true + }, + "source": [ + "## The derivative of the Logistic funtion\n", + "\n", + "Looking at the logistic activation function, when inputs become large\n", + "(negative or positive), the function saturates at 0 or 1, with a\n", + "derivative extremely close to 0. Thus when backpropagation kicks in,\n", + "it has virtually no gradient to propagate back through the network,\n", + "and what little gradient exists keeps getting diluted as\n", + "backpropagation progresses down through the top layers, so there is\n", + "really nothing left for the lower layers.\n", + "\n", + "In their paper, Glorot and Bengio propose a way to significantly\n", + "alleviate this problem. We need the signal to flow properly in both\n", + "directions: in the forward direction when making predictions, and in\n", + "the reverse direction when backpropagating gradients. We don’t want\n", + "the signal to die out, nor do we want it to explode and saturate. For\n", + "the signal to flow properly, the authors argue that we need the\n", + "variance of the outputs of each layer to be equal to the variance of\n", + "its inputs, and we also need the gradients to have equal variance\n", + "before and after flowing through a layer in the reverse direction." + ] + }, + { + "cell_type": "markdown", + "id": "2898691d", + "metadata": { + "editable": true + }, + "source": [ + "## Insights from the paper by Glorot and Bengio\n", + "\n", + "One of the insights in the 2010 paper by Glorot and Bengio was that\n", + "the vanishing/exploding gradients problems were in part due to a poor\n", + "choice of activation function. Until then most people had assumed that\n", + "if Nature had chosen to use roughly sigmoid activation functions in\n", + "biological neurons, they must be an excellent choice. But it turns out\n", + "that other activation functions behave much better in deep neural\n", + "networks, in particular the ReLU activation function, mostly because\n", + "it does not saturate for positive values (and also because it is quite\n", + "fast to compute)." + ] + }, + { + "cell_type": "markdown", + "id": "4ac964f3", + "metadata": { + "editable": true + }, + "source": [ + "## The RELU function family\n", + "\n", + "The ReLU activation function suffers from a problem known as the dying\n", + "ReLUs: during training, some neurons effectively die, meaning they\n", + "stop outputting anything other than 0.\n", + "\n", + "In some cases, you may find that half of your network’s neurons are\n", + "dead, especially if you used a large learning rate. During training,\n", + "if a neuron’s weights get updated such that the weighted sum of the\n", + "neuron’s inputs is negative, it will start outputting 0. When this\n", + "happen, the neuron is unlikely to come back to life since the gradient\n", + "of the ReLU function is 0 when its input is negative." + ] + }, + { + "cell_type": "markdown", + "id": "c18a90e1", + "metadata": { + "editable": true + }, + "source": [ + "## ELU function\n", + "\n", + "To solve this problem, nowadays practitioners use a variant of the\n", + "ReLU function, such as the leaky ReLU discussed above or the so-called\n", + "exponential linear unit (ELU) function" + ] + }, + { + "cell_type": "markdown", + "id": "eed9db84", "metadata": { "editable": true }, "source": [ "$$\n", - "{\\cal C}(\\hat{W}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - t_i\\right)^2,\n", + "ELU(z) = \\left\\{\\begin{array}{cc} \\alpha\\left( \\exp{(z)}-1\\right) & z < 0,\\\\ z & z \\ge 0.\\end{array}\\right.\n", "$$" ] }, { "cell_type": "markdown", - "id": "667ef874", + "id": "b375c182", "metadata": { "editable": true }, "source": [ - "where the $t_i$s are our $n$ targets (the values we want to\n", - "reproduce), while the outputs of the network after having propagated\n", - "all inputs $\\hat{x}$ are given by $y_i$. Below we will demonstrate\n", - "how the basic equations arising from the back propagation algorithm\n", - "can be modified in order to study classification problems with $K$\n", - "classes." - ] - }, - { - "cell_type": "markdown", - "id": "dd53c6c8", - "metadata": { - "editable": true - }, - "source": [ - "## Definitions\n", - "\n", - "With our definition of the targets $\\hat{t}$, the outputs of the\n", - "network $\\hat{y}$ and the inputs $\\hat{x}$ we\n", - "define now the activation $z_j^l$ of node/neuron/unit $j$ of the\n", - "$l$-th layer as a function of the bias, the weights which add up from\n", - "the previous layer $l-1$ and the forward passes/outputs\n", - "$\\hat{a}^{l-1}$ from the previous layer as" - ] - }, - { - "cell_type": "markdown", - "id": "4f58ed9b", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_j^l = \\sum_{i=1}^{M_{l-1}}w_{ij}^la_i^{l-1}+b_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c60762cd", - "metadata": { - "editable": true - }, - "source": [ - "where $b_k^l$ are the biases from layer $l$. Here $M_{l-1}$\n", - "represents the total number of nodes/neurons/units of layer $l-1$. The\n", - "figure here illustrates this equation. We can rewrite this in a more\n", - "compact form as the matrix-vector products we discussed earlier," - ] - }, - { - "cell_type": "markdown", - "id": "5c1c5162", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\hat{z}^l = \\left(\\hat{W}^l\\right)^T\\hat{a}^{l-1}+\\hat{b}^l.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "080b6f9a", - "metadata": { - "editable": true - }, - "source": [ - "With the activation values $\\hat{z}^l$ we can in turn define the\n", - "output of layer $l$ as $\\hat{a}^l = f(\\hat{z}^l)$ where $f$ is our\n", - "activation function. In the examples here we will use the sigmoid\n", - "function discussed in our logistic regression lectures. We will also use the same activation function $f$ for all layers\n", - "and their nodes. It means we have" - ] - }, - { - "cell_type": "markdown", - "id": "12e261bb", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "a_j^l = f(z_j^l) = \\frac{1}{1+\\exp{-(z_j^l)}}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "49a48c09", - "metadata": { - "editable": true - }, - "source": [ - "## Derivatives and the chain rule\n", - "\n", - "From the definition of the activation $z_j^l$ we have" - ] - }, - { - "cell_type": "markdown", - "id": "6dc08f48", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial z_j^l}{\\partial w_{ij}^l} = a_i^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "b8211d41", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "96822eda", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial z_j^l}{\\partial a_i^{l-1}} = w_{ji}^l.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f0b1660f", - "metadata": { - "editable": true - }, - "source": [ - "With our definition of the activation function we have that (note that this function depends only on $z_j^l$)" - ] - }, - { - "cell_type": "markdown", - "id": "df85f033", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial a_j^l}{\\partial z_j^{l}} = a_j^l(1-a_j^l)=f(z_j^l)(1-f(z_j^l)).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "ea90d738", - "metadata": { - "editable": true - }, - "source": [ - "## Derivative of the cost function\n", - "\n", - "With these definitions we can now compute the derivative of the cost function in terms of the weights.\n", - "\n", - "Let us specialize to the output layer $l=L$. Our cost function is" - ] - }, - { - "cell_type": "markdown", - "id": "fafb43b4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "{\\cal C}(\\hat{W^L}) = \\frac{1}{2}\\sum_{i=1}^n\\left(y_i - t_i\\right)^2=\\frac{1}{2}\\sum_{i=1}^n\\left(a_i^L - t_i\\right)^2,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "41afcc45", - "metadata": { - "editable": true - }, - "source": [ - "The derivative of this function with respect to the weights is" - ] - }, - { - "cell_type": "markdown", - "id": "aed16939", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\left(a_j^L - t_j\\right)\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "4ece624c", - "metadata": { - "editable": true - }, - "source": [ - "The last partial derivative can easily be computed and reads (by applying the chain rule)" - ] - }, - { - "cell_type": "markdown", - "id": "7fbf4fe4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial a_j^L}{\\partial w_{jk}^{L}} = \\frac{\\partial a_j^L}{\\partial z_{j}^{L}}\\frac{\\partial z_j^L}{\\partial w_{jk}^{L}}=a_j^L(1-a_j^L)a_k^{L-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "dba0e4a4", - "metadata": { - "editable": true - }, - "source": [ - "## Bringing it together, first back propagation equation\n", - "\n", - "We have thus" - ] - }, - { - "cell_type": "markdown", - "id": "c32147af", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\left(a_j^L - t_j\\right)a_j^L(1-a_j^L)a_k^{L-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "4b6176c8", - "metadata": { - "editable": true - }, - "source": [ - "Defining" - ] - }, - { - "cell_type": "markdown", - "id": "b87747a4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = a_j^L(1-a_j^L)\\left(a_j^L - t_j\\right) = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "1547289e", - "metadata": { - "editable": true - }, - "source": [ - "and using the Hadamard product of two vectors we can write this as" - ] - }, - { - "cell_type": "markdown", - "id": "ef9854e4", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\hat{\\delta}^L = f'(\\hat{z}^L)\\circ\\frac{\\partial {\\cal C}}{\\partial (\\hat{a}^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c9ce87bb", - "metadata": { - "editable": true - }, - "source": [ - "This is an important expression. The second term on the right handside\n", - "measures how fast the cost function is changing as a function of the $j$th\n", - "output activation. If, for example, the cost function doesn't depend\n", - "much on a particular output node $j$, then $\\delta_j^L$ will be small,\n", - "which is what we would expect. The first term on the right, measures\n", - "how fast the activation function $f$ is changing at a given activation\n", - "value $z_j^L$.\n", - "\n", - "Notice that everything in the above equations is easily computed. In\n", - "particular, we compute $z_j^L$ while computing the behaviour of the\n", - "network, and it is only a small additional overhead to compute\n", - "$f'(z^L_j)$. The exact form of the derivative with respect to the\n", - "output depends on the form of the cost function.\n", - "However, provided the cost function is known there should be little\n", - "trouble in calculating" - ] - }, - { - "cell_type": "markdown", - "id": "5b74b869", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "42b1eab9", - "metadata": { - "editable": true - }, - "source": [ - "With the definition of $\\delta_j^L$ we have a more compact definition of the derivative of the cost function in terms of the weights, namely" - ] - }, - { - "cell_type": "markdown", - "id": "27331743", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8f1b672f", - "metadata": { - "editable": true - }, - "source": [ - "## Derivatives in terms of $z_j^L$\n", - "\n", - "It is also easy to see that our previous equation can be written as" - ] - }, - { - "cell_type": "markdown", - "id": "543a0ba2", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L =\\frac{\\partial {\\cal C}}{\\partial z_j^L}= \\frac{\\partial {\\cal C}}{\\partial a_j^L}\\frac{\\partial a_j^L}{\\partial z_j^L},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "628ee133", - "metadata": { - "editable": true - }, - "source": [ - "which can also be interpreted as the partial derivative of the cost function with respect to the biases $b_j^L$, namely" - ] - }, - { - "cell_type": "markdown", - "id": "94f361e5", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L}\\frac{\\partial b_j^L}{\\partial z_j^L}=\\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "13e5c5d5", - "metadata": { - "editable": true - }, - "source": [ - "That is, the error $\\delta_j^L$ is exactly equal to the rate of change of the cost function as a function of the bias." - ] - }, - { - "cell_type": "markdown", - "id": "4887a3d7", - "metadata": { - "editable": true - }, - "source": [ - "## Bringing it together\n", - "\n", - "We have now three equations that are essential for the computations of the derivatives of the cost function at the output layer. These equations are needed to start the algorithm and they are\n", - "\n", - "**The starting equations.**" - ] - }, - { - "cell_type": "markdown", - "id": "8f4d75dd", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\frac{\\partial{\\cal C}(\\hat{W^L})}{\\partial w_{jk}^L} = \\delta_j^La_k^{L-1},\n", - "\\label{_auto8} \\tag{13}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "69864347", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "e654f179", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)},\n", - "\\label{_auto9} \\tag{14}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f650a917", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "b8169c55", - "metadata": { - "editable": true - }, - "source": [ - "\n", - "
    \n", - "\n", - "$$\n", - "\\begin{equation}\n", - "\\delta_j^L = \\frac{\\partial {\\cal C}}{\\partial b_j^L},\n", - "\\label{_auto10} \\tag{15}\n", - "\\end{equation}\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "5567d66c", - "metadata": { - "editable": true - }, - "source": [ - "An interesting consequence of the above equations is that when the\n", - "activation $a_k^{L-1}$ is small, the gradient term, that is the\n", - "derivative of the cost function with respect to the weights, will also\n", - "tend to be small. We say then that the weight learns slowly, meaning\n", - "that it changes slowly when we minimize the weights via say gradient\n", - "descent. In this case we say the system learns slowly.\n", - "\n", - "Another interesting feature is that is when the activation function,\n", - "represented by the sigmoid function here, is rather flat when we move towards\n", - "its end values $0$ and $1$ (see the above Python codes). In these\n", - "cases, the derivatives of the activation function will also be close\n", - "to zero, meaning again that the gradients will be small and the\n", - "network learns slowly again.\n", - "\n", - "We need a fourth equation and we are set. We are going to propagate\n", - "backwards in order to the determine the weights and biases. In order\n", - "to do so we need to represent the error in the layer before the final\n", - "one $L-1$ in terms of the errors in the final output layer." - ] - }, - { - "cell_type": "markdown", - "id": "f5c09470", - "metadata": { - "editable": true - }, - "source": [ - "## Final back propagating equation\n", - "\n", - "We have that (replacing $L$ with a general layer $l$)" - ] - }, - { - "cell_type": "markdown", - "id": "d66ef5ca", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\frac{\\partial {\\cal C}}{\\partial z_j^l}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e96004a2", - "metadata": { - "editable": true - }, - "source": [ - "We want to express this in terms of the equations for layer $l+1$. Using the chain rule and summing over all $k$ entries we have" - ] - }, - { - "cell_type": "markdown", - "id": "0ee94485", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\sum_k \\frac{\\partial {\\cal C}}{\\partial z_k^{l+1}}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}}=\\sum_k \\delta_k^{l+1}\\frac{\\partial z_k^{l+1}}{\\partial z_j^{l}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "1c2ac190", - "metadata": { - "editable": true - }, - "source": [ - "and recalling that" - ] - }, - { - "cell_type": "markdown", - "id": "f89f9c76", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_j^{l+1} = \\sum_{i=1}^{M_{l}}w_{ij}^{l+1}a_i^{l}+b_j^{l+1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f8293787", - "metadata": { - "editable": true - }, - "source": [ - "with $M_l$ being the number of nodes in layer $l$, we obtain" - ] - }, - { - "cell_type": "markdown", - "id": "a2914db3", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l =\\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "297a2622", - "metadata": { - "editable": true - }, - "source": [ - "This is our final equation.\n", - "\n", - "We are now ready to set up the algorithm for back propagation and learning the weights and biases." - ] - }, - { - "cell_type": "markdown", - "id": "c952f57b", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\hat{x}$ and the activations\n", - "$\\hat{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\hat{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\hat{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\hat{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\hat{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "37d4f242", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "ff2e732a", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "97a96714", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "3ee8ad1b", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "c4d2d1a1", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "d412dae3", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "64129a91", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "681d8bd9", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\boldsymbol{x}$ and the activations\n", - "$\\boldsymbol{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\boldsymbol{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\boldsymbol{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\boldsymbol{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\boldsymbol{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "62904d70", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bb5b2dde", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "51828c66", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "c4124232", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "80791bf2", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "107737c9", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "720ad834", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "6854da89", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Back propagation algorithm\n", - "\n", - "The four equations derived discussed above provide us with a way of computing the gradient of the cost function. Let us write this out in the form of an algorithm.\n", - "\n", - "First, we set up the input data $\\boldsymbol{x}$ and the activations\n", - "$\\boldsymbol{z}_1$ of the input layer and compute the activation function and\n", - "the pertinent outputs $\\boldsymbol{a}^1$.\n", - "\n", - "Secondly, we perform then the feed forward till we reach the output\n", - "layer and compute all $\\boldsymbol{z}_l$ of the input layer and compute the\n", - "activation function and the pertinent outputs $\\boldsymbol{a}^l$ for\n", - "$l=2,3,\\dots,L$.\n", - "\n", - "Thereafter we compute the ouput error $\\boldsymbol{\\delta}^L$ by computing all" - ] - }, - { - "cell_type": "markdown", - "id": "b5c0c6c7", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^L = f'(z_j^L)\\frac{\\partial {\\cal C}}{\\partial (a_j^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "43403932", - "metadata": { - "editable": true - }, - "source": [ - "Then we compute the back propagate error for each $l=L-1,L-2,\\dots,2$ as" - ] - }, - { - "cell_type": "markdown", - "id": "08f3064e", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\delta_j^l = \\sum_k \\delta_k^{l+1}w_{kj}^{l+1}f'(z_j^l).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "f5d698a4", - "metadata": { - "editable": true - }, - "source": [ - "Finally, we update the weights and the biases using gradient descent for each $l=L-1,L-2,\\dots,2$ and update the weights and biases according to the rules" - ] - }, - { - "cell_type": "markdown", - "id": "3ae56fb5", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "w_{jk}^l\\leftarrow = w_{jk}^l- \\eta \\delta_j^la_k^{l-1},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "b822ca59", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "b_j^l \\leftarrow b_j^l-\\eta \\frac{\\partial {\\cal C}}{\\partial b_j^l}=b_j^l-\\eta \\delta_j^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e0593696", - "metadata": { - "editable": true - }, - "source": [ - "The parameter $\\eta$ is the learning parameter discussed in connection with the gradient descent methods.\n", - "Here it is convenient to use stochastic gradient descent (see the examples below) with mini-batches with an outer loop that steps through multiple epochs of training." - ] - }, - { - "cell_type": "markdown", - "id": "c77a2a17", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up a Multi-layer perceptron model for classification\n", - "\n", - "We are now gong to develop an example based on the MNIST data\n", - "base. This is a classification problem and we need to use our\n", - "cross-entropy function we discussed in connection with logistic\n", - "regression. The cross-entropy defines our cost function for the\n", - "classificaton problems with neural networks.\n", - "\n", - "In binary classification with two classes $(0, 1)$ we define the\n", - "logistic/sigmoid function as the probability that a particular input\n", - "is in class $0$ or $1$. This is possible because the logistic\n", - "function takes any input from the real numbers and inputs a number\n", - "between 0 and 1, and can therefore be interpreted as a probability. It\n", - "also has other nice properties, such as a derivative that is simple to\n", - "calculate.\n", - "\n", - "For an input $\\boldsymbol{a}$ from the hidden layer, the probability that the input $\\boldsymbol{x}$\n", - "is in class 0 or 1 is just. We let $\\theta$ represent the unknown weights and biases to be adjusted by our equations). The variable $x$\n", - "represents our activation values $z$. We have" - ] - }, - { - "cell_type": "markdown", - "id": "093f5d87", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y = 0 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) = \\frac{1}{1 + \\exp{(- \\boldsymbol{x}})} ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7bd03f69", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "fe5226a0", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y = 1 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) = 1 - P(y = 0 \\mid \\boldsymbol{x}, \\boldsymbol{\\theta}) ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "45f1532a", - "metadata": { - "editable": true - }, - "source": [ - "where $y \\in \\{0, 1\\}$ and $\\boldsymbol{\\theta}$ represents the weights and biases\n", - "of our network." - ] - }, - { - "cell_type": "markdown", - "id": "1b07418e", - "metadata": { - "editable": true - }, - "source": [ - "## Defining the cost function\n", - "\n", - "Our cost function is given as (see the Logistic regression lectures)" - ] - }, - { - "cell_type": "markdown", - "id": "c7f5232f", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\theta}) = - \\ln P(\\mathcal{D} \\mid \\boldsymbol{\\theta}) = - \\sum_{i=1}^n\n", - "y_i \\ln[P(y_i = 0)] + (1 - y_i) \\ln [1 - P(y_i = 0)] = \\sum_{i=1}^n \\mathcal{L}_i(\\boldsymbol{\\theta}) .\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "e1af7b47", - "metadata": { - "editable": true - }, - "source": [ - "This last equality means that we can interpret our *cost* function as a sum over the *loss* function\n", - "for each point in the dataset $\\mathcal{L}_i(\\boldsymbol{\\theta})$. \n", - "The negative sign is just so that we can think about our algorithm as minimizing a positive number, rather\n", - "than maximizing a negative number. \n", - "\n", - "In *multiclass* classification it is common to treat each integer label as a so called *one-hot* vector: \n", - "\n", - "$y = 5 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,$ and\n", - "\n", - "$y = 1 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,$ \n", - "\n", - "i.e. a binary bit string of length $C$, where $C = 10$ is the number of classes in the MNIST dataset (numbers from $0$ to $9$).. \n", - "\n", - "If $\\boldsymbol{x}_i$ is the $i$-th input (image), $y_{ic}$ refers to the $c$-th component of the $i$-th\n", - "output vector $\\boldsymbol{y}_i$. \n", - "The probability of $\\boldsymbol{x}_i$ being in class $c$ will be given by the softmax function:" - ] - }, - { - "cell_type": "markdown", - "id": "db469d35", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(y_{ic} = 1 \\mid \\boldsymbol{x}_i, \\boldsymbol{\\theta}) = \\frac{\\exp{((\\boldsymbol{a}_i^{hidden})^T \\boldsymbol{w}_c)}}\n", - "{\\sum_{c'=0}^{C-1} \\exp{((\\boldsymbol{a}_i^{hidden})^T \\boldsymbol{w}_{c'})}} ,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "deb48962", - "metadata": { - "editable": true - }, - "source": [ - "which reduces to the logistic function in the binary case. \n", - "The likelihood of this $C$-class classifier\n", - "is now given as:" - ] - }, - { - "cell_type": "markdown", - "id": "36443e39", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "P(\\mathcal{D} \\mid \\boldsymbol{\\theta}) = \\prod_{i=1}^n \\prod_{c=0}^{C-1} [P(y_{ic} = 1)]^{y_{ic}} .\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8076d9fa", - "metadata": { - "editable": true - }, - "source": [ - "Again we take the negative log-likelihood to define our cost function:" - ] - }, - { - "cell_type": "markdown", - "id": "292dad0a", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\theta}) = - \\log{P(\\mathcal{D} \\mid \\boldsymbol{\\theta})}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7803b746", - "metadata": { - "editable": true - }, - "source": [ - "See the logistic regression lectures for a full definition of the cost function.\n", - "\n", - "The back propagation equations need now only a small change, namely the definition of a new cost function. We are thus ready to use the same equations as before!" - ] - }, - { - "cell_type": "markdown", - "id": "a71f1366", - "metadata": { - "editable": true - }, - "source": [ - "## Example: binary classification problem\n", - "\n", - "As an example of the above, relevant for project 2 as well, let us consider a binary class. As discussed in our logistic regression lectures, we defined a cost function in terms of the parameters $\\beta$ as" - ] - }, - { - "cell_type": "markdown", - "id": "25efb288", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{\\beta}) = - \\sum_{i=1}^n \\left(y_i\\log{p(y_i \\vert x_i,\\boldsymbol{\\beta})}+(1-y_i)\\log{1-p(y_i \\vert x_i,\\boldsymbol{\\beta})}\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "6192694f", - "metadata": { - "editable": true - }, - "source": [ - "where we had defined the logistic (sigmoid) function" - ] - }, - { - "cell_type": "markdown", - "id": "f6786106", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "p(y_i =1\\vert x_i,\\boldsymbol{\\beta})=\\frac{\\exp{(\\beta_0+\\beta_1 x_i)}}{1+\\exp{(\\beta_0+\\beta_1 x_i)}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "be663cac", - "metadata": { - "editable": true - }, - "source": [ - "and" - ] - }, - { - "cell_type": "markdown", - "id": "a6953973", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "p(y_i =0\\vert x_i,\\boldsymbol{\\beta})=1-p(y_i =1\\vert x_i,\\boldsymbol{\\beta}).\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "de08816b", - "metadata": { - "editable": true - }, - "source": [ - "The parameters $\\boldsymbol{\\beta}$ were defined using a minimization method like gradient descent or Newton-Raphson's method. \n", - "\n", - "Now we replace $x_i$ with the activation $z_i^l$ for a given layer $l$ and the outputs as $y_i=a_i^l=f(z_i^l)$, with $z_i^l$ now being a function of the weights $w_{ij}^l$ and biases $b_i^l$. \n", - "We have then" - ] - }, - { - "cell_type": "markdown", - "id": "d9b14b33", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "a_i^l = y_i = \\frac{\\exp{(z_i^l)}}{1+\\exp{(z_i^l)}},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "8072c452", - "metadata": { - "editable": true - }, - "source": [ - "with" - ] - }, - { - "cell_type": "markdown", - "id": "34a5cb25", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "z_i^l = \\sum_{j}w_{ij}^l a_j^{l-1}+b_i^l,\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "833dc972", - "metadata": { - "editable": true - }, - "source": [ - "where the superscript $l-1$ indicates that these are the outputs from layer $l-1$.\n", - "Our cost function at the final layer $l=L$ is now" - ] - }, - { - "cell_type": "markdown", - "id": "3c52b850", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\mathcal{C}(\\boldsymbol{W}) = - \\sum_{i=1}^n \\left(t_i\\log{a_i^L}+(1-t_i)\\log{(1-a_i^L)}\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "01c24d99", - "metadata": { - "editable": true - }, - "source": [ - "where we have defined the targets $t_i$. The derivatives of the cost function with respect to the output $a_i^L$ are then easily calculated and we get" - ] - }, - { - "cell_type": "markdown", - "id": "692fbd5a", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial \\mathcal{C}(\\boldsymbol{W})}{\\partial a_i^L} = \\frac{a_i^L-t_i}{a_i^L(1-a_i^L)}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "cdd8c203", - "metadata": { - "editable": true - }, - "source": [ - "In case we use another activation function than the logistic one, we need to evaluate other derivatives." - ] - }, - { - "cell_type": "markdown", - "id": "1e7eba9c", - "metadata": { - "editable": true - }, - "source": [ - "## The Softmax function\n", - "In case we employ the more general case given by the Softmax equation, we need to evaluate the derivative of the activation function with respect to the activation $z_i^l$, that is we need" - ] - }, - { - "cell_type": "markdown", - "id": "8ca62ded", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial f(z_i^l)}{\\partial w_{jk}^l} =\n", - "\\frac{\\partial f(z_i^l)}{\\partial z_j^l} \\frac{\\partial z_j^l}{\\partial w_{jk}^l}= \\frac{\\partial f(z_i^l)}{\\partial z_j^l}a_k^{l-1}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "479d6d33", - "metadata": { - "editable": true - }, - "source": [ - "For the Softmax function we have" - ] - }, - { - "cell_type": "markdown", - "id": "3a63ba14", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "f(z_i^l) = \\frac{\\exp{(z_i^l)}}{\\sum_{m=1}^K\\exp{(z_m^l)}}.\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "bed10528", - "metadata": { - "editable": true - }, - "source": [ - "Its derivative with respect to $z_j^l$ gives" - ] - }, - { - "cell_type": "markdown", - "id": "6a77ac39", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\frac{\\partial f(z_i^l)}{\\partial z_j^l}= f(z_i^l)\\left(\\delta_{ij}-f(z_j^l)\\right),\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "7fd16de8", - "metadata": { - "editable": true - }, - "source": [ - "which in case of the simply binary model reduces to having $i=j$." - ] - }, - { - "cell_type": "markdown", - "id": "a598757e", - "metadata": { - "editable": true - }, - "source": [ - "## Developing a code for doing neural networks with back propagation\n", - "\n", - "One can identify a set of key steps when using neural networks to solve supervised learning problems: \n", - "\n", - "1. Collect and pre-process data \n", - "\n", - "2. Define model and architecture \n", - "\n", - "3. Choose cost function and optimizer \n", - "\n", - "4. Train the model \n", - "\n", - "5. Evaluate model performance on test data \n", - "\n", - "6. Adjust hyperparameters (if necessary, network architecture)" - ] - }, - { - "cell_type": "markdown", - "id": "0dc69031", - "metadata": { - "editable": true - }, - "source": [ - "## Collect and pre-process data\n", - "\n", - "Here we will be using the MNIST dataset, which is readily available through the **scikit-learn**\n", - "package. You may also find it for example [here](http://yann.lecun.com/exdb/mnist/). \n", - "The *MNIST* (Modified National Institute of Standards and Technology) database is a large database\n", - "of handwritten digits that is commonly used for training various image processing systems. \n", - "The MNIST dataset consists of 70 000 images of size $28\\times 28$ pixels, each labeled from 0 to 9. \n", - "The scikit-learn dataset we will use consists of a selection of 1797 images of size $8\\times 8$ collected and processed from this database. \n", - "\n", - "To feed data into a feed-forward neural network we need to represent\n", - "the inputs as a design/feature matrix $X = (n_{inputs}, n_{features})$. Each\n", - "row represents an *input*, in this case a handwritten digit, and\n", - "each column represents a *feature*, in this case a pixel. The\n", - "correct answers, also known as *labels* or *targets* are\n", - "represented as a 1D array of integers \n", - "$Y = (n_{inputs}) = (5, 3, 1, 8,...)$.\n", - "\n", - "As an example, say we want to build a neural network using supervised learning to predict Body-Mass Index (BMI) from\n", - "measurements of height (in m) \n", - "and weight (in kg). If we have measurements of 5 people the design/feature matrix could be for example: \n", - "\n", - "$$ X = \\begin{bmatrix}\n", - "1.85 & 81\\\\\n", - "1.71 & 65\\\\\n", - "1.95 & 103\\\\\n", - "1.55 & 42\\\\\n", - "1.63 & 56\n", - "\\end{bmatrix} ,$$ \n", - "\n", - "and the targets would be: \n", - "\n", - "$$ Y = (23.7, 22.2, 27.1, 17.5, 21.1) $$ \n", - "\n", - "Since each input image is a 2D matrix, we need to flatten the image\n", - "(i.e. \"unravel\" the 2D matrix into a 1D array) to turn the data into a\n", - "design/feature matrix. This means we lose all spatial information in the\n", - "image, such as locality and translational invariance. More complicated\n", - "architectures such as Convolutional Neural Networks can take advantage\n", - "of such information, and are most commonly applied when analyzing\n", - "images." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "d7c49d9c", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn import datasets\n", - "\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# display images in notebook\n", - "%matplotlib inline\n", - "plt.rcParams['figure.figsize'] = (12,12)\n", - "\n", - "\n", - "# download MNIST dataset\n", - "digits = datasets.load_digits()\n", - "\n", - "# define inputs and labels\n", - "inputs = digits.images\n", - "labels = digits.target\n", - "\n", - "print(\"inputs = (n_inputs, pixel_width, pixel_height) = \" + str(inputs.shape))\n", - "print(\"labels = (n_inputs) = \" + str(labels.shape))\n", - "\n", - "\n", - "# flatten the image\n", - "# the value -1 means dimension is inferred from the remaining dimensions: 8x8 = 64\n", - "n_inputs = len(inputs)\n", - "inputs = inputs.reshape(n_inputs, -1)\n", - "print(\"X = (n_inputs, n_features) = \" + str(inputs.shape))\n", - "\n", - "\n", - "# choose some random images to display\n", - "indices = np.arange(n_inputs)\n", - "random_indices = np.random.choice(indices, size=5)\n", - "\n", - "for i, image in enumerate(digits.images[random_indices]):\n", - " plt.subplot(1, 5, i+1)\n", - " plt.axis('off')\n", - " plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n", - " plt.title(\"Label: %d\" % digits.target[random_indices[i]])\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "672723bb", - "metadata": { - "editable": true - }, - "source": [ - "## Train and test datasets\n", - "\n", - "Performing analysis before partitioning the dataset is a major error, that can lead to incorrect conclusions. \n", - "\n", - "We will reserve $80 \\%$ of our dataset for training and $20 \\%$ for testing. \n", - "\n", - "It is important that the train and test datasets are drawn randomly from our dataset, to ensure\n", - "no bias in the sampling. \n", - "Say you are taking measurements of weather data to predict the weather in the coming 5 days.\n", - "You don't want to train your model on measurements taken from the hours 00.00 to 12.00, and then test it on data\n", - "collected from 12.00 to 24.00." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "3b0db869", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "from sklearn.model_selection import train_test_split\n", - "\n", - "# one-liner from scikit-learn library\n", - "train_size = 0.8\n", - "test_size = 1 - train_size\n", - "X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,\n", - " test_size=test_size)\n", - "\n", - "# equivalently in numpy\n", - "def train_test_split_numpy(inputs, labels, train_size, test_size):\n", - " n_inputs = len(inputs)\n", - " inputs_shuffled = inputs.copy()\n", - " labels_shuffled = labels.copy()\n", - " \n", - " np.random.shuffle(inputs_shuffled)\n", - " np.random.shuffle(labels_shuffled)\n", - " \n", - " train_end = int(n_inputs*train_size)\n", - " X_train, X_test = inputs_shuffled[:train_end], inputs_shuffled[train_end:]\n", - " Y_train, Y_test = labels_shuffled[:train_end], labels_shuffled[train_end:]\n", - " \n", - " return X_train, X_test, Y_train, Y_test\n", - "\n", - "#X_train, X_test, Y_train, Y_test = train_test_split_numpy(inputs, labels, train_size, test_size)\n", - "\n", - "print(\"Number of training images: \" + str(len(X_train)))\n", - "print(\"Number of test images: \" + str(len(X_test)))" - ] - }, - { - "cell_type": "markdown", - "id": "a52c7acf", - "metadata": { - "editable": true - }, - "source": [ - "## Define model and architecture\n", - "\n", - "Our simple feed-forward neural network will consist of an *input* layer, a single *hidden* layer and an *output* layer. The activation $y$ of each neuron is a weighted sum of inputs, passed through an activation function. In case of the simple perceptron model we have \n", - "\n", - "$$ z = \\sum_{i=1}^n w_i a_i ,$$\n", - "\n", - "$$ y = f(z) ,$$\n", - "\n", - "where $f$ is the activation function, $a_i$ represents input from neuron $i$ in the preceding layer\n", - "and $w_i$ is the weight to input $i$. \n", - "The activation of the neurons in the input layer is just the features (e.g. a pixel value). \n", - "\n", - "The simplest activation function for a neuron is the *Heaviside* function:\n", - "\n", - "$$ f(z) = \n", - "\\begin{cases}\n", - "1, & z > 0\\\\\n", - "0, & \\text{otherwise}\n", - "\\end{cases}\n", - "$$\n", - "\n", - "A feed-forward neural network with this activation is known as a *perceptron*. \n", - "For a binary classifier (i.e. two classes, 0 or 1, dog or not-dog) we can also use this in our output layer. \n", - "This activation can be generalized to $k$ classes (using e.g. the *one-against-all* strategy), \n", - "and we call these architectures *multiclass perceptrons*. \n", - "\n", - "However, it is now common to use the terms Single Layer Perceptron (SLP) (1 hidden layer) and \n", - "Multilayer Perceptron (MLP) (2 or more hidden layers) to refer to feed-forward neural networks with any activation function. \n", - "\n", - "Typical choices for activation functions include the sigmoid function, hyperbolic tangent, and Rectified Linear Unit (ReLU). \n", - "We will be using the sigmoid function $\\sigma(x)$: \n", - "\n", - "$$ f(x) = \\sigma(x) = \\frac{1}{1 + e^{-x}} ,$$\n", - "\n", - "which is inspired by probability theory (see logistic regression) and was most commonly used until about 2011. See the discussion below concerning other activation functions." - ] - }, - { - "cell_type": "markdown", - "id": "f1ef08f4", - "metadata": { - "editable": true - }, - "source": [ - "## Layers\n", - "\n", - "* Input \n", - "\n", - "Since each input image has 8x8 = 64 pixels or features, we have an input layer of 64 neurons. \n", - "\n", - "* Hidden layer\n", - "\n", - "We will use 50 neurons in the hidden layer receiving input from the neurons in the input layer. \n", - "Since each neuron in the hidden layer is connected to the 64 inputs we have 64x50 = 3200 weights to the hidden layer. \n", - "\n", - "* Output\n", - "\n", - "If we were building a binary classifier, it would be sufficient with a single neuron in the output layer,\n", - "which could output 0 or 1 according to the Heaviside function. This would be an example of a *hard* classifier, meaning it outputs the class of the input directly. However, if we are dealing with noisy data it is often beneficial to use a *soft* classifier, which outputs the probability of being in class 0 or 1. \n", - "\n", - "For a soft binary classifier, we could use a single neuron and interpret the output as either being the probability of being in class 0 or the probability of being in class 1. Alternatively we could use 2 neurons, and interpret each neuron as the probability of being in each class. \n", - "\n", - "Since we are doing multiclass classification, with 10 categories, it is natural to use 10 neurons in the output layer. We number the neurons $j = 0,1,...,9$. The activation of each output neuron $j$ will be according to the *softmax* function: \n", - "\n", - "$$ P(\\text{class $j$} \\mid \\text{input $\\boldsymbol{a}$}) = \\frac{\\exp{(\\boldsymbol{a}^T \\boldsymbol{w}_j)}}\n", - "{\\sum_{c=0}^{9} \\exp{(\\boldsymbol{a}^T \\boldsymbol{w}_c)}} ,$$ \n", - "\n", - "i.e. each neuron $j$ outputs the probability of being in class $j$ given an input from the hidden layer $\\boldsymbol{a}$, with $\\boldsymbol{w}_j$ the weights of neuron $j$ to the inputs. \n", - "The denominator is a normalization factor to ensure the outputs (probabilities) sum up to 1. \n", - "The exponent is just the weighted sum of inputs as before: \n", - "\n", - "$$ z_j = \\sum_{i=1}^n w_ {ij} a_i+b_j.$$ \n", - "\n", - "Since each neuron in the output layer is connected to the 50 inputs from the hidden layer we have 50x10 = 500\n", - "weights to the output layer." - ] - }, - { - "cell_type": "markdown", - "id": "867b3b89", - "metadata": { - "editable": true - }, - "source": [ - "## Weights and biases\n", - "\n", - "Typically weights are initialized with small values distributed around zero, drawn from a uniform\n", - "or normal distribution. Setting all weights to zero means all neurons give the same output, making the network useless. \n", - "\n", - "Adding a bias value to the weighted sum of inputs allows the neural network to represent a greater range\n", - "of values. Without it, any input with the value 0 will be mapped to zero (before being passed through the activation). The bias unit has an output of 1, and a weight to each neuron $j$, $b_j$: \n", - "\n", - "$$ z_j = \\sum_{i=1}^n w_ {ij} a_i + b_j.$$ \n", - "\n", - "The bias weights $\\boldsymbol{b}$ are often initialized to zero, but a small value like $0.01$ ensures all neurons have some output which can be backpropagated in the first training cycle." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "8ec462da", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# building our neural network\n", - "\n", - "n_inputs, n_features = X_train.shape\n", - "n_hidden_neurons = 50\n", - "n_categories = 10\n", - "\n", - "# we make the weights normally distributed using numpy.random.randn\n", - "\n", - "# weights and bias in the hidden layer\n", - "hidden_weights = np.random.randn(n_features, n_hidden_neurons)\n", - "hidden_bias = np.zeros(n_hidden_neurons) + 0.01\n", - "\n", - "# weights and bias in the output layer\n", - "output_weights = np.random.randn(n_hidden_neurons, n_categories)\n", - "output_bias = np.zeros(n_categories) + 0.01" - ] - }, - { - "cell_type": "markdown", - "id": "cf228009", - "metadata": { - "editable": true - }, - "source": [ - "## Feed-forward pass\n", - "\n", - "Denote $F$ the number of features, $H$ the number of hidden neurons and $C$ the number of categories. \n", - "For each input image we calculate a weighted sum of input features (pixel values) to each neuron $j$ in the hidden layer $l$: \n", - "\n", - "$$ z_{j}^{l} = \\sum_{i=1}^{F} w_{ij}^{l} x_i + b_{j}^{l},$$\n", - "\n", - "this is then passed through our activation function \n", - "\n", - "$$ a_{j}^{l} = f(z_{j}^{l}) .$$ \n", - "\n", - "We calculate a weighted sum of inputs (activations in the hidden layer) to each neuron $j$ in the output layer: \n", - "\n", - "$$ z_{j}^{L} = \\sum_{i=1}^{H} w_{ij}^{L} a_{i}^{l} + b_{j}^{L}.$$ \n", - "\n", - "Finally we calculate the output of neuron $j$ in the output layer using the softmax function: \n", - "\n", - "$$ a_{j}^{L} = \\frac{\\exp{(z_j^{L})}}\n", - "{\\sum_{c=0}^{C-1} \\exp{(z_c^{L})}} .$$" - ] - }, - { - "cell_type": "markdown", - "id": "c57ea8b9", - "metadata": { - "editable": true - }, - "source": [ - "## Matrix multiplications\n", - "\n", - "Since our data has the dimensions $X = (n_{inputs}, n_{features})$ and our weights to the hidden\n", - "layer have the dimensions \n", - "$W_{hidden} = (n_{features}, n_{hidden})$,\n", - "we can easily feed the network all our training data in one go by taking the matrix product \n", - "\n", - "$$ X W^{h} = (n_{inputs}, n_{hidden}),$$ \n", - "\n", - "and obtain a matrix that holds the weighted sum of inputs to the hidden layer\n", - "for each input image and each hidden neuron. \n", - "We also add the bias to obtain a matrix of weighted sums to the hidden layer $Z^{h}$: \n", - "\n", - "$$ \\boldsymbol{z}^{l} = \\boldsymbol{X} \\boldsymbol{W}^{l} + \\boldsymbol{b}^{l} ,$$\n", - "\n", - "meaning the same bias (1D array with size equal number of hidden neurons) is added to each input image. \n", - "This is then passed through the activation: \n", - "\n", - "$$ \\boldsymbol{a}^{l} = f(\\boldsymbol{z}^l) .$$ \n", - "\n", - "This is fed to the output layer: \n", - "\n", - "$$ \\boldsymbol{z}^{L} = \\boldsymbol{a}^{L} \\boldsymbol{W}^{L} + \\boldsymbol{b}^{L} .$$\n", - "\n", - "Finally we receive our output values for each image and each category by passing it through the softmax function: \n", - "\n", - "$$ output = softmax (\\boldsymbol{z}^{L}) = (n_{inputs}, n_{categories}) .$$" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "9c286c15", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# setup the feed-forward pass, subscript h = hidden layer\n", - "\n", - "def sigmoid(x):\n", - " return 1/(1 + np.exp(-x))\n", - "\n", - "def feed_forward(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " \n", - " return probabilities\n", - "\n", - "probabilities = feed_forward(X_train)\n", - "print(\"probabilities = (n_inputs, n_categories) = \" + str(probabilities.shape))\n", - "print(\"probability that image 0 is in category 0,1,2,...,9 = \\n\" + str(probabilities[0]))\n", - "print(\"probabilities sum up to: \" + str(probabilities[0].sum()))\n", - "print()\n", - "\n", - "# we obtain a prediction by taking the class with the highest likelihood\n", - "def predict(X):\n", - " probabilities = feed_forward(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - "predictions = predict(X_train)\n", - "print(\"predictions = (n_inputs) = \" + str(predictions.shape))\n", - "print(\"prediction for image 0: \" + str(predictions[0]))\n", - "print(\"correct label for image 0: \" + str(Y_train[0]))" - ] - }, - { - "cell_type": "markdown", - "id": "a6cf75c3", - "metadata": { - "editable": true - }, - "source": [ - "## Choose cost function and optimizer\n", - "\n", - "To measure how well our neural network is doing we need to introduce a cost function. \n", - "We will call the function that gives the error of a single sample output the *loss* function, and the function\n", - "that gives the total error of our network across all samples the *cost* function.\n", - "A typical choice for multiclass classification is the *cross-entropy* loss, also known as the negative log likelihood. \n", - "\n", - "In *multiclass* classification it is common to treat each integer label as a so called *one-hot* vector: \n", - "\n", - "$$ y = 5 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 0, 0, 0, 0, 1, 0, 0, 0, 0) ,$$ \n", - "\n", - "$$ y = 1 \\quad \\rightarrow \\quad \\boldsymbol{y} = (0, 1, 0, 0, 0, 0, 0, 0, 0, 0) ,$$ \n", - "\n", - "i.e. a binary bit string of length $C$, where $C = 10$ is the number of classes in the MNIST dataset. \n", - "\n", - "Let $y_{ic}$ denote the $c$-th component of the $i$-th one-hot vector. \n", - "We define the cost function $\\mathcal{C}$ as a sum over the cross-entropy loss for each point $\\boldsymbol{x}_i$ in the dataset.\n", - "\n", - "In the one-hot representation only one of the terms in the loss function is non-zero, namely the\n", - "probability of the correct category $c'$ \n", - "(i.e. the category $c'$ such that $y_{ic'} = 1$). This means that the cross entropy loss only punishes you for how wrong\n", - "you got the correct label. The probability of category $c$ is given by the softmax function. The vector $\\boldsymbol{\\theta}$ represents the parameters of our network, i.e. all the weights and biases." - ] - }, - { - "cell_type": "markdown", - "id": "e69ffdc8", - "metadata": { - "editable": true - }, - "source": [ - "## Optimizing the cost function\n", - "\n", - "The network is trained by finding the weights and biases that minimize the cost function. One of the most widely used classes of methods is *gradient descent* and its generalizations. The idea behind gradient descent\n", - "is simply to adjust the weights in the direction where the gradient of the cost function is large and negative. This ensures we flow toward a *local* minimum of the cost function. \n", - "Each parameter $\\theta$ is iteratively adjusted according to the rule \n", - "\n", - "$$ \\theta_{i+1} = \\theta_i - \\eta \\nabla \\mathcal{C}(\\theta_i) ,$$\n", - "\n", - "where $\\eta$ is known as the *learning rate*, which controls how big a step we take towards the minimum. \n", - "This update can be repeated for any number of iterations, or until we are satisfied with the result. \n", - "\n", - "A simple and effective improvement is a variant called *Batch Gradient Descent*. \n", - "Instead of calculating the gradient on the whole dataset, we calculate an approximation of the gradient\n", - "on a subset of the data called a *minibatch*. \n", - "If there are $N$ data points and we have a minibatch size of $M$, the total number of batches\n", - "is $N/M$. \n", - "We denote each minibatch $B_k$, with $k = 1, 2,...,N/M$. The gradient then becomes: \n", - "\n", - "$$ \\nabla \\mathcal{C}(\\theta) = \\frac{1}{N} \\sum_{i=1}^N \\nabla \\mathcal{L}_i(\\theta) \\quad \\rightarrow \\quad\n", - "\\frac{1}{M} \\sum_{i \\in B_k} \\nabla \\mathcal{L}_i(\\theta) ,$$\n", - "\n", - "i.e. instead of averaging the loss over the entire dataset, we average over a minibatch. \n", - "\n", - "This has two important benefits: \n", - "1. Introducing stochasticity decreases the chance that the algorithm becomes stuck in a local minima. \n", - "\n", - "2. It significantly speeds up the calculation, since we do not have to use the entire dataset to calculate the gradient. \n", - "\n", - "The various optmization methods, with codes and algorithms, are discussed in our lectures on [Gradient descent approaches](https://compphysics.github.io/MachineLearning/doc/pub/Splines/html/Splines-bs.html)." - ] - }, - { - "cell_type": "markdown", - "id": "ef19d1e0", - "metadata": { - "editable": true - }, - "source": [ - "## Regularization\n", - "\n", - "It is common to add an extra term to the cost function, proportional\n", - "to the size of the weights. This is equivalent to constraining the\n", - "size of the weights, so that they do not grow out of control.\n", - "Constraining the size of the weights means that the weights cannot\n", - "grow arbitrarily large to fit the training data, and in this way\n", - "reduces *overfitting*.\n", - "\n", - "We will measure the size of the weights using the so called *L2-norm*, meaning our cost function becomes: \n", - "\n", - "$$ \\mathcal{C}(\\theta) = \\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}_i(\\theta) \\quad \\rightarrow \\quad\n", - "\\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}_i(\\theta) + \\lambda \\lvert \\lvert \\boldsymbol{w} \\rvert \\rvert_2^2 \n", - "= \\frac{1}{N} \\sum_{i=1}^N \\mathcal{L}(\\theta) + \\lambda \\sum_{ij} w_{ij}^2,$$ \n", + "## Which activation function should we use?\n", "\n", - "i.e. we sum up all the weights squared. The factor $\\lambda$ is known as a regularization parameter.\n", + "In general it seems that the ELU activation function is better than\n", + "the leaky ReLU function (and its variants), which is better than\n", + "ReLU. ReLU performs better than $\\tanh$ which in turn performs better\n", + "than the logistic function.\n", "\n", - "In order to train the model, we need to calculate the derivative of\n", - "the cost function with respect to every bias and weight in the\n", - "network. In total our network has $(64 + 1)\\times 50=3250$ weights in\n", - "the hidden layer and $(50 + 1)\\times 10=510$ weights to the output\n", - "layer ($+1$ for the bias), and the gradient must be calculated for\n", - "every parameter. We use the *backpropagation* algorithm discussed\n", - "above. This is a clever use of the chain rule that allows us to\n", - "calculate the gradient efficently." + "If runtime performance is an issue, then you may opt for the leaky\n", + "ReLU function over the ELU function If you don’t want to tweak yet\n", + "another hyperparameter, you may just use the default $\\alpha$ of\n", + "$0.01$ for the leaky ReLU, and $1$ for ELU. If you have spare time and\n", + "computing power, you can use cross-validation or bootstrap to evaluate\n", + "other activation functions." ] }, { "cell_type": "markdown", - "id": "d93c5dfb", - "metadata": { - "editable": true - }, - "source": [ - "## Matrix multiplication\n", - "\n", - "To more efficently train our network these equations are implemented using matrix operations. \n", - "The error in the output layer is calculated simply as, with $\\boldsymbol{t}$ being our targets, \n", - "\n", - "$$ \\delta_L = \\boldsymbol{t} - \\boldsymbol{y} = (n_{inputs}, n_{categories}) .$$ \n", - "\n", - "The gradient for the output weights is calculated as \n", - "\n", - "$$ \\nabla W_{L} = \\boldsymbol{a}^T \\delta_L = (n_{hidden}, n_{categories}) ,$$\n", - "\n", - "where $\\boldsymbol{a} = (n_{inputs}, n_{hidden})$. This simply means that we are summing up the gradients for each input. \n", - "Since we are going backwards we have to transpose the activation matrix. \n", - "\n", - "The gradient with respect to the output bias is then \n", - "\n", - "$$ \\nabla \\boldsymbol{b}_{L} = \\sum_{i=1}^{n_{inputs}} \\delta_L = (n_{categories}) .$$ \n", - "\n", - "The error in the hidden layer is \n", - "\n", - "$$ \\Delta_h = \\delta_L W_{L}^T \\circ f'(z_{h}) = \\delta_L W_{L}^T \\circ a_{h} \\circ (1 - a_{h}) = (n_{inputs}, n_{hidden}) ,$$ \n", - "\n", - "where $f'(a_{h})$ is the derivative of the activation in the hidden layer. The matrix products mean\n", - "that we are summing up the products for each neuron in the output layer. The symbol $\\circ$ denotes\n", - "the *Hadamard product*, meaning element-wise multiplication. \n", - "\n", - "This again gives us the gradients in the hidden layer: \n", - "\n", - "$$ \\nabla W_{h} = X^T \\delta_h = (n_{features}, n_{hidden}) ,$$ \n", - "\n", - "$$ \\nabla b_{h} = \\sum_{i=1}^{n_{inputs}} \\delta_h = (n_{hidden}) .$$" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "0a62b82a", + "id": "edb42800", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "# to categorical turns our integer vector into a onehot representation\n", - "from sklearn.metrics import accuracy_score\n", + "## More on activation functions, output layers\n", "\n", - "# one-hot in numpy\n", - "def to_categorical_numpy(integer_vector):\n", - " n_inputs = len(integer_vector)\n", - " n_categories = np.max(integer_vector) + 1\n", - " onehot_vector = np.zeros((n_inputs, n_categories))\n", - " onehot_vector[range(n_inputs), integer_vector] = 1\n", - " \n", - " return onehot_vector\n", + "In most cases you can use the ReLU activation function in the hidden\n", + "layers (or one of its variants).\n", "\n", - "#Y_train_onehot, Y_test_onehot = to_categorical(Y_train), to_categorical(Y_test)\n", - "Y_train_onehot, Y_test_onehot = to_categorical_numpy(Y_train), to_categorical_numpy(Y_test)\n", + "It is a bit faster to compute than other activation functions, and the\n", + "gradient descent optimization does in general not get stuck.\n", "\n", - "def feed_forward_train(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " \n", - " # for backpropagation need activations in hidden and output layers\n", - " return a_h, probabilities\n", + "**For the output layer:**\n", "\n", - "def backpropagation(X, Y):\n", - " a_h, probabilities = feed_forward_train(X)\n", - " \n", - " # error in the output layer\n", - " error_output = probabilities - Y\n", - " # error in the hidden layer\n", - " error_hidden = np.matmul(error_output, output_weights.T) * a_h * (1 - a_h)\n", - " \n", - " # gradients for the output layer\n", - " output_weights_gradient = np.matmul(a_h.T, error_output)\n", - " output_bias_gradient = np.sum(error_output, axis=0)\n", - " \n", - " # gradient for the hidden layer\n", - " hidden_weights_gradient = np.matmul(X.T, error_hidden)\n", - " hidden_bias_gradient = np.sum(error_hidden, axis=0)\n", + "* For classification the softmax activation function is generally a good choice for classification tasks (when the classes are mutually exclusive).\n", "\n", - " return output_weights_gradient, output_bias_gradient, hidden_weights_gradient, hidden_bias_gradient\n", - "\n", - "print(\"Old accuracy on training data: \" + str(accuracy_score(predict(X_train), Y_train)))\n", - "\n", - "eta = 0.01\n", - "lmbd = 0.01\n", - "for i in range(1000):\n", - " # calculate gradients\n", - " dWo, dBo, dWh, dBh = backpropagation(X_train, Y_train_onehot)\n", - " \n", - " # regularization term gradients\n", - " dWo += lmbd * output_weights\n", - " dWh += lmbd * hidden_weights\n", - " \n", - " # update weights and biases\n", - " output_weights -= eta * dWo\n", - " output_bias -= eta * dBo\n", - " hidden_weights -= eta * dWh\n", - " hidden_bias -= eta * dBh\n", - "\n", - "print(\"New accuracy on training data: \" + str(accuracy_score(predict(X_train), Y_train)))" + "* For regression tasks, you can simply use no activation function at all." ] }, { "cell_type": "markdown", - "id": "b666f091", + "id": "1a8fafc0", "metadata": { "editable": true }, "source": [ - "## Improving performance\n", - "\n", - "As we can see the network does not seem to be learning at all. It seems to be just guessing the label for each image. \n", - "In order to obtain a network that does something useful, we will have to do a bit more work. \n", + "## Batch Normalization\n", "\n", - "The choice of *hyperparameters* such as learning rate and regularization parameter is hugely influential for the performance of the network. Typically a *grid-search* is performed, wherein we test different hyperparameters separated by orders of magnitude. For example we could test the learning rates $\\eta = 10^{-6}, 10^{-5},...,10^{-1}$ with different regularization parameters $\\lambda = 10^{-6},...,10^{-0}$. \n", + "Batch Normalization aims to address the vanishing/exploding gradients\n", + "problems, and more generally the problem that the distribution of each\n", + "layer’s inputs changes during training, as the parameters of the\n", + "previous layers change.\n", "\n", - "Next, we haven't implemented minibatching yet, which introduces stochasticity and is though to act as an important regularizer on the weights. We call a feed-forward + backward pass with a minibatch an *iteration*, and a full training period\n", - "going through the entire dataset ($n/M$ batches) an *epoch*.\n", - "\n", - "If this does not improve network performance, you may want to consider altering the network architecture, adding more neurons or hidden layers. \n", - "Andrew Ng goes through some of these considerations in this [video](https://youtu.be/F1ka6a13S9I). You can find a summary of the video [here](https://kevinzakka.github.io/2016/09/26/applying-deep-learning/)." + "The technique consists of adding an operation in the model just before\n", + "the activation function of each layer, simply zero-centering and\n", + "normalizing the inputs, then scaling and shifting the result using two\n", + "new parameters per layer (one for scaling, the other for shifting). In\n", + "other words, this operation lets the model learn the optimal scale and\n", + "mean of the inputs for each layer. In order to zero-center and\n", + "normalize the inputs, the algorithm needs to estimate the inputs’ mean\n", + "and standard deviation. It does so by evaluating the mean and standard\n", + "deviation of the inputs over the current mini-batch, from this the\n", + "name batch normalization." ] }, { "cell_type": "markdown", - "id": "79055893", - "metadata": { - "editable": true - }, - "source": [ - "## Full object-oriented implementation\n", - "\n", - "It is very natural to think of the network as an object, with specific instances of the network\n", - "being realizations of this object with different hyperparameters. An implementation using Python classes provides a clean structure and interface, and the full implementation of our neural network is given below." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "85af4a1c", + "id": "feef1d4d", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "class NeuralNetwork:\n", - " def __init__(\n", - " self,\n", - " X_data,\n", - " Y_data,\n", - " n_hidden_neurons=50,\n", - " n_categories=10,\n", - " epochs=10,\n", - " batch_size=100,\n", - " eta=0.1,\n", - " lmbd=0.0):\n", - "\n", - " self.X_data_full = X_data\n", - " self.Y_data_full = Y_data\n", - "\n", - " self.n_inputs = X_data.shape[0]\n", - " self.n_features = X_data.shape[1]\n", - " self.n_hidden_neurons = n_hidden_neurons\n", - " self.n_categories = n_categories\n", - "\n", - " self.epochs = epochs\n", - " self.batch_size = batch_size\n", - " self.iterations = self.n_inputs // self.batch_size\n", - " self.eta = eta\n", - " self.lmbd = lmbd\n", - "\n", - " self.create_biases_and_weights()\n", - "\n", - " def create_biases_and_weights(self):\n", - " self.hidden_weights = np.random.randn(self.n_features, self.n_hidden_neurons)\n", - " self.hidden_bias = np.zeros(self.n_hidden_neurons) + 0.01\n", - "\n", - " self.output_weights = np.random.randn(self.n_hidden_neurons, self.n_categories)\n", - " self.output_bias = np.zeros(self.n_categories) + 0.01\n", - "\n", - " def feed_forward(self):\n", - " # feed-forward for training\n", - " self.z_h = np.matmul(self.X_data, self.hidden_weights) + self.hidden_bias\n", - " self.a_h = sigmoid(self.z_h)\n", - "\n", - " self.z_o = np.matmul(self.a_h, self.output_weights) + self.output_bias\n", - "\n", - " exp_term = np.exp(self.z_o)\n", - " self.probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - "\n", - " def feed_forward_out(self, X):\n", - " # feed-forward for output\n", - " z_h = np.matmul(X, self.hidden_weights) + self.hidden_bias\n", - " a_h = sigmoid(z_h)\n", - "\n", - " z_o = np.matmul(a_h, self.output_weights) + self.output_bias\n", - " \n", - " exp_term = np.exp(z_o)\n", - " probabilities = exp_term / np.sum(exp_term, axis=1, keepdims=True)\n", - " return probabilities\n", + "## Dropout\n", "\n", - " def backpropagation(self):\n", - " error_output = self.probabilities - self.Y_data\n", - " error_hidden = np.matmul(error_output, self.output_weights.T) * self.a_h * (1 - self.a_h)\n", + "It is a fairly simple algorithm: at every training step, every neuron\n", + "(including the input neurons but excluding the output neurons) has a\n", + "probability $p$ of being temporarily dropped out, meaning it will be\n", + "entirely ignored during this training step, but it may be active\n", + "during the next step.\n", "\n", - " self.output_weights_gradient = np.matmul(self.a_h.T, error_output)\n", - " self.output_bias_gradient = np.sum(error_output, axis=0)\n", - "\n", - " self.hidden_weights_gradient = np.matmul(self.X_data.T, error_hidden)\n", - " self.hidden_bias_gradient = np.sum(error_hidden, axis=0)\n", - "\n", - " if self.lmbd > 0.0:\n", - " self.output_weights_gradient += self.lmbd * self.output_weights\n", - " self.hidden_weights_gradient += self.lmbd * self.hidden_weights\n", - "\n", - " self.output_weights -= self.eta * self.output_weights_gradient\n", - " self.output_bias -= self.eta * self.output_bias_gradient\n", - " self.hidden_weights -= self.eta * self.hidden_weights_gradient\n", - " self.hidden_bias -= self.eta * self.hidden_bias_gradient\n", - "\n", - " def predict(self, X):\n", - " probabilities = self.feed_forward_out(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - " def predict_probabilities(self, X):\n", - " probabilities = self.feed_forward_out(X)\n", - " return probabilities\n", - "\n", - " def train(self):\n", - " data_indices = np.arange(self.n_inputs)\n", - "\n", - " for i in range(self.epochs):\n", - " for j in range(self.iterations):\n", - " # pick datapoints with replacement\n", - " chosen_datapoints = np.random.choice(\n", - " data_indices, size=self.batch_size, replace=False\n", - " )\n", - "\n", - " # minibatch training data\n", - " self.X_data = self.X_data_full[chosen_datapoints]\n", - " self.Y_data = self.Y_data_full[chosen_datapoints]\n", - "\n", - " self.feed_forward()\n", - " self.backpropagation()" + "The hyperparameter $p$ is called the dropout rate, and it is typically\n", + "set to 50%. After training, the neurons are not dropped anymore. It\n", + "is viewed as one of the most popular regularization techniques." ] }, { "cell_type": "markdown", - "id": "d0ef37e8", - "metadata": { - "editable": true - }, - "source": [ - "## Evaluate model performance on test data\n", - "\n", - "To measure the performance of our network we evaluate how well it does it data it has never seen before, i.e. the test data. \n", - "We measure the performance of the network using the *accuracy* score. \n", - "The accuracy is as you would expect just the number of images correctly labeled divided by the total number of images. A perfect classifier will have an accuracy score of $1$. \n", - "\n", - "$$ \\text{Accuracy} = \\frac{\\sum_{i=1}^n I(\\tilde{y}_i = y_i)}{n} ,$$ \n", - "\n", - "where $I$ is the indicator function, $1$ if $\\tilde{y}_i = y_i$ and $0$ otherwise." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "d2891643", + "id": "9428c225", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "epochs = 100\n", - "batch_size = 100\n", - "\n", - "dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,\n", - " n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)\n", - "dnn.train()\n", - "test_predict = dnn.predict(X_test)\n", + "## Gradient Clipping\n", "\n", - "# accuracy score from scikit library\n", - "print(\"Accuracy score on test set: \", accuracy_score(Y_test, test_predict))\n", - "\n", - "# equivalent in numpy\n", - "def accuracy_score_numpy(Y_test, Y_pred):\n", - " return np.sum(Y_test == Y_pred) / len(Y_test)\n", - "\n", - "#print(\"Accuracy score on test set: \", accuracy_score_numpy(Y_test, test_predict))" - ] - }, - { - "cell_type": "markdown", - "id": "5c91c8fc", - "metadata": { - "editable": true - }, - "source": [ - "## Adjust hyperparameters\n", + "A popular technique to lessen the exploding gradients problem is to\n", + "simply clip the gradients during backpropagation so that they never\n", + "exceed some threshold (this is mostly useful for recurrent neural\n", + "networks).\n", "\n", - "We now perform a grid search to find the optimal hyperparameters for the network. \n", - "Note that we are only using 1 layer with 50 neurons, and human performance is estimated to be around $98\\%$ ($2\\%$ error rate)." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "c245d23d", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "eta_vals = np.logspace(-5, 1, 7)\n", - "lmbd_vals = np.logspace(-5, 1, 7)\n", - "# store the models for later use\n", - "DNN_numpy = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", + "This technique is called Gradient Clipping.\n", "\n", - "# grid search\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = NeuralNetwork(X_train, Y_train_onehot, eta=eta, lmbd=lmbd, epochs=epochs, batch_size=batch_size,\n", - " n_hidden_neurons=n_hidden_neurons, n_categories=n_categories)\n", - " dnn.train()\n", - " \n", - " DNN_numpy[i][j] = dnn\n", - " \n", - " test_predict = dnn.predict(X_test)\n", - " \n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on test set: \", accuracy_score(Y_test, test_predict))\n", - " print()" + "In general however, Batch\n", + "Normalization is preferred." ] }, { "cell_type": "markdown", - "id": "ea3be61a", - "metadata": { - "editable": true - }, - "source": [ - "## Visualization" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "d26e1748", + "id": "504b21ae", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "# visual representation of grid search\n", - "# uses seaborn heatmap, you can also do this with matplotlib imshow\n", - "import seaborn as sns\n", - "\n", - "sns.set()\n", - "\n", - "train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_numpy[i][j]\n", - " \n", - " train_pred = dnn.predict(X_train) \n", - " test_pred = dnn.predict(X_test)\n", - "\n", - " train_accuracy[i][j] = accuracy_score(Y_train, train_pred)\n", - " test_accuracy[i][j] = accuracy_score(Y_test, test_pred)\n", + "## A top-down perspective on Neural networks\n", "\n", - " \n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Training Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()\n", + "The first thing we would like to do is divide the data into two or\n", + "three parts. A training set, a validation or dev (development) set,\n", + "and a test set. The test set is the data on which we want to make\n", + "predictions. The dev set is a subset of the training data we use to\n", + "check how well we are doing out-of-sample, after training the model on\n", + "the training dataset. We use the validation error as a proxy for the\n", + "test error in order to make tweaks to our model. It is crucial that we\n", + "do not use any of the test data to train the algorithm. This is a\n", + "cardinal sin in ML. Then:\n", "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "572f3f4b", - "metadata": { - "editable": true - }, - "source": [ - "## scikit-learn implementation\n", + "1. Estimate optimal error rate\n", "\n", - "**scikit-learn** focuses more\n", - "on traditional machine learning methods, such as regression,\n", - "clustering, decision trees, etc. As such, it has only two types of\n", - "neural networks: Multi Layer Perceptron outputting continuous values,\n", - "*MPLRegressor*, and Multi Layer Perceptron outputting labels,\n", - "*MLPClassifier*. We will see how simple it is to use these classes.\n", - "\n", - "**scikit-learn** implements a few improvements from our neural network,\n", - "such as early stopping, a varying learning rate, different\n", - "optimization methods, etc. We would therefore expect a better\n", - "performance overall." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "fdb38053", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "from sklearn.neural_network import MLPClassifier\n", - "# store models for later use\n", - "DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", + "2. Minimize underfitting (bias) on training data set.\n", "\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic',\n", - " alpha=lmbd, learning_rate_init=eta, max_iter=epochs)\n", - " dnn.fit(X_train, Y_train)\n", - " \n", - " DNN_scikit[i][j] = dnn\n", - " \n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on test set: \", dnn.score(X_test, Y_test))\n", - " print()" + "3. Make sure you are not overfitting." ] }, { "cell_type": "markdown", - "id": "5fc3dd13", + "id": "c51837a9", "metadata": { "editable": true }, "source": [ - "## Visualization" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "cd9e4505", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# optional\n", - "# visual representation of grid search\n", - "# uses seaborn heatmap, could probably do this in matplotlib\n", - "import seaborn as sns\n", - "\n", - "sns.set()\n", + "## More top-down perspectives\n", "\n", - "train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", + "If the validation and test sets are drawn from the same distributions,\n", + "then a good performance on the validation set should lead to similarly\n", + "good performance on the test set. \n", "\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_scikit[i][j]\n", - " \n", - " train_pred = dnn.predict(X_train) \n", - " test_pred = dnn.predict(X_test)\n", - "\n", - " train_accuracy[i][j] = accuracy_score(Y_train, train_pred)\n", - " test_accuracy[i][j] = accuracy_score(Y_test, test_pred)\n", - "\n", - " \n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Training Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()\n", - "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" + "However, sometimes\n", + "the training data and test data differ in subtle ways because, for\n", + "example, they are collected using slightly different methods, or\n", + "because it is cheaper to collect data in one way versus another. In\n", + "this case, there can be a mismatch between the training and test\n", + "data. This can lead to the neural network overfitting these small\n", + "differences between the test and training sets, and a poor performance\n", + "on the test set despite having a good performance on the validation\n", + "set. To rectify this, Andrew Ng suggests making two validation or dev\n", + "sets, one constructed from the training data and one constructed from\n", + "the test data. The difference between the performance of the algorithm\n", + "on these two validation sets quantifies the train-test mismatch. This\n", + "can serve as another important diagnostic when using DNNs for\n", + "supervised learning." ] }, { "cell_type": "markdown", - "id": "30d61094", + "id": "a7357657", "metadata": { "editable": true }, "source": [ - "## Testing our code for the XOR, OR and AND gates\n", - "\n", - "Last week we discussed three different types of gates, the so-called\n", - "XOR, the OR and the AND gates. Their inputs and outputs can be\n", - "summarized using the following tables, first for the OR gate with\n", - "inputs $x_1$ and $x_2$ and outputs $y$:\n", + "## Limitations of supervised learning with deep networks\n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 1
    1 0 1
    1 1 1
    " + "Like all statistical methods, supervised learning using neural\n", + "networks has important limitations. This is especially important when\n", + "one seeks to apply these methods, especially to physics problems. Like\n", + "all tools, DNNs are not a universal solution. Often, the same or\n", + "better performance on a task can be achieved by using a few\n", + "hand-engineered features (or even a collection of random\n", + "features)." ] }, { "cell_type": "markdown", - "id": "9b4cd63f", + "id": "e92c8a84", "metadata": { "editable": true }, "source": [ - "## The AND and XOR Gates\n", + "## Limitations of NNs\n", "\n", - "The AND gate is defined as\n", + "Here we list some of the important limitations of supervised neural network based models. \n", "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 0
    1 0 0
    1 1 1
    \n", - "\n", - "And finally we have the XOR gate\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "
    $x_1$ $x_2$ $y$
    0 0 0
    0 1 1
    1 0 1
    1 1 0
    " - ] - }, - { - "cell_type": "markdown", - "id": "1a2bd6f1", - "metadata": { - "editable": true - }, - "source": [ - "## Representing the Data Sets\n", + "* **Need labeled data**. All supervised learning methods, DNNs for supervised learning require labeled data. Often, labeled data is harder to acquire than unlabeled data (e.g. one must pay for human experts to label images).\n", "\n", - "Our design matrix is defined by the input values $x_1$ and $x_2$. Since we have four possible outputs, our design matrix reads" - ] - }, - { - "cell_type": "markdown", - "id": "a569e669", - "metadata": { - "editable": true - }, - "source": [ - "$$\n", - "\\boldsymbol{X}=\\begin{bmatrix} 0 & 0 \\\\\n", - " 0 & 1 \\\\\n", - "\t\t 1 & 0 \\\\\n", - "\t\t 1 & 1 \\end{bmatrix},\n", - "$$" - ] - }, - { - "cell_type": "markdown", - "id": "51363b82", - "metadata": { - "editable": true - }, - "source": [ - "while the vector of outputs is $\\boldsymbol{y}^T=[0,1,1,0]$ for the XOR gate, $\\boldsymbol{y}^T=[0,0,0,1]$ for the AND gate and $\\boldsymbol{y}^T=[0,1,1,1]$ for the OR gate." + "* **Supervised neural networks are extremely data intensive.** DNNs are data hungry. They perform best when data is plentiful. This is doubly so for supervised methods where the data must also be labeled. The utility of DNNs is extremely limited if data is hard to acquire or the datasets are small (hundreds to a few thousand samples). In this case, the performance of other methods that utilize hand-engineered features can exceed that of DNNs." ] }, { "cell_type": "markdown", - "id": "e4172d21", - "metadata": { - "editable": true - }, - "source": [ - "## Setting up the Neural Network\n", - "\n", - "We define first our design matrix and the various output vectors for the different gates." - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "b8640651", + "id": "793aee7d", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "\"\"\"\n", - "Simple code that tests XOR, OR and AND gates with linear regression\n", - "\"\"\"\n", - "\n", - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn import datasets\n", - "\n", - "def sigmoid(x):\n", - " return 1/(1 + np.exp(-x))\n", + "## Homogeneous data\n", "\n", - "def feed_forward(X):\n", - " # weighted sum of inputs to the hidden layer\n", - " z_h = np.matmul(X, hidden_weights) + hidden_bias\n", - " # activation in the hidden layer\n", - " a_h = sigmoid(z_h)\n", - " \n", - " # weighted sum of inputs to the output layer\n", - " z_o = np.matmul(a_h, output_weights) + output_bias\n", - " # softmax output\n", - " # axis 0 holds each input and axis 1 the probabilities of each category\n", - " probabilities = sigmoid(z_o)\n", - " return probabilities\n", - "\n", - "# we obtain a prediction by taking the class with the highest likelihood\n", - "def predict(X):\n", - " probabilities = feed_forward(X)\n", - " return np.argmax(probabilities, axis=1)\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# Design matrix\n", - "X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64)\n", - "\n", - "# The XOR gate\n", - "yXOR = np.array( [ 0, 1 ,1, 0])\n", - "# The OR gate\n", - "yOR = np.array( [ 0, 1 ,1, 1])\n", - "# The AND gate\n", - "yAND = np.array( [ 0, 0 ,0, 1])\n", - "\n", - "# Defining the neural network\n", - "n_inputs, n_features = X.shape\n", - "n_hidden_neurons = 2\n", - "n_categories = 2\n", - "n_features = 2\n", - "\n", - "# we make the weights normally distributed using numpy.random.randn\n", - "\n", - "# weights and bias in the hidden layer\n", - "hidden_weights = np.random.randn(n_features, n_hidden_neurons)\n", - "hidden_bias = np.zeros(n_hidden_neurons) + 0.01\n", - "\n", - "# weights and bias in the output layer\n", - "output_weights = np.random.randn(n_hidden_neurons, n_categories)\n", - "output_bias = np.zeros(n_categories) + 0.01\n", - "\n", - "probabilities = feed_forward(X)\n", - "print(probabilities)\n", - "\n", - "\n", - "predictions = predict(X)\n", - "print(predictions)" - ] - }, - { - "cell_type": "markdown", - "id": "f6b2c036", - "metadata": { - "editable": true - }, - "source": [ - "Not an impressive result, but this was our first forward pass with randomly assigned weights. Let us now add the full network with the back-propagation algorithm discussed above." + "* **Homogeneous data.** Almost all DNNs deal with homogeneous data of one type. It is very hard to design architectures that mix and match data types (i.e. some continuous variables, some discrete variables, some time series). In applications beyond images, video, and language, this is often what is required. In contrast, ensemble models like random forests or gradient-boosted trees have no difficulty handling mixed data types." ] }, { "cell_type": "markdown", - "id": "49fdf701", - "metadata": { - "editable": true - }, - "source": [ - "## The Code using Scikit-Learn" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "45dae979", + "id": "739960d6", "metadata": { - "collapsed": false, "editable": true }, - "outputs": [], "source": [ - "# import necessary packages\n", - "import numpy as np\n", - "import matplotlib.pyplot as plt\n", - "from sklearn.neural_network import MLPClassifier\n", - "from sklearn.metrics import accuracy_score\n", - "import seaborn as sns\n", - "\n", - "# ensure the same random numbers appear every time\n", - "np.random.seed(0)\n", - "\n", - "# Design matrix\n", - "X = np.array([ [0, 0], [0, 1], [1, 0],[1, 1]],dtype=np.float64)\n", - "\n", - "# The XOR gate\n", - "yXOR = np.array( [ 0, 1 ,1, 0])\n", - "# The OR gate\n", - "yOR = np.array( [ 0, 1 ,1, 1])\n", - "# The AND gate\n", - "yAND = np.array( [ 0, 0 ,0, 1])\n", - "\n", - "# Defining the neural network\n", - "n_inputs, n_features = X.shape\n", - "n_hidden_neurons = 2\n", - "n_categories = 2\n", - "n_features = 2\n", - "\n", - "eta_vals = np.logspace(-5, 1, 7)\n", - "lmbd_vals = np.logspace(-5, 1, 7)\n", - "# store models for later use\n", - "DNN_scikit = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n", - "epochs = 100\n", - "\n", - "for i, eta in enumerate(eta_vals):\n", - " for j, lmbd in enumerate(lmbd_vals):\n", - " dnn = MLPClassifier(hidden_layer_sizes=(n_hidden_neurons), activation='logistic',\n", - " alpha=lmbd, learning_rate_init=eta, max_iter=epochs)\n", - " dnn.fit(X, yXOR)\n", - " DNN_scikit[i][j] = dnn\n", - " print(\"Learning rate = \", eta)\n", - " print(\"Lambda = \", lmbd)\n", - " print(\"Accuracy score on data set: \", dnn.score(X, yXOR))\n", - " print()\n", + "## More limitations\n", "\n", - "sns.set()\n", - "test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n", - "for i in range(len(eta_vals)):\n", - " for j in range(len(lmbd_vals)):\n", - " dnn = DNN_scikit[i][j]\n", - " test_pred = dnn.predict(X)\n", - " test_accuracy[i][j] = accuracy_score(yXOR, test_pred)\n", + "* **Many problems are not about prediction.** In natural science we are often interested in learning something about the underlying distribution that generates the data. In this case, it is often difficult to cast these ideas in a supervised learning setting. While the problems are related, it is possible to make good predictions with a *wrong* model. The model might or might not be useful for understanding the underlying science.\n", "\n", - "fig, ax = plt.subplots(figsize = (10, 10))\n", - "sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n", - "ax.set_title(\"Test Accuracy\")\n", - "ax.set_ylabel(\"$\\eta$\")\n", - "ax.set_xlabel(\"$\\lambda$\")\n", - "plt.show()" + "Some of these remarks are particular to DNNs, others are shared by all supervised learning methods. This motivates the use of unsupervised methods which in part circumvent these problems." ] } ],