{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3a825ca3",
   "metadata": {
    "papermill": {
     "duration": 0.054714,
     "end_time": "2022-08-25T20:07:33.291009",
     "exception": false,
     "start_time": "2022-08-25T20:07:33.236295",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "**Important**: The interactive features of this notebook don't work in Kaggle's *Reader* mode. They only work in *Edit* mode. Therefore, before starting reading this, please click \"**Copy & Edit**\" in the top right of this window, then in the menu click *Run* and then *Run all*. Then you'll be able to use all the interactive sliders in this notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "579020e7",
   "metadata": {
    "papermill": {
     "duration": 0.052974,
     "end_time": "2022-08-25T20:07:33.396018",
     "exception": false,
     "start_time": "2022-08-25T20:07:33.343044",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Fitting a function with *gradient descent*"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab5f159d",
   "metadata": {
    "papermill": {
     "duration": 0.050597,
     "end_time": "2022-08-25T20:07:33.498627",
     "exception": false,
     "start_time": "2022-08-25T20:07:33.448030",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "A neural network is just a mathematical function. In the most standard kind of neural network, the function:\n",
    "\n",
    "1. Multiplies each input by a number of values. These values are known as *parameters*\n",
    "1. Adds them up for each group of values\n",
    "1. Replaces the negative numbers with zeros\n",
    "\n",
    "This represents one \"layer\". Then these three steps are repeated, using the outputs of the previous layer as the inputs to the next layer. Initially, the parameters in this function are selected randomly. Therefore a newly created neural network doesn't do anything useful at all -- it's just random!\n",
    "\n",
    "To get the function to \"learn\" to do something useful, we have to change the parameters to make them \"better\" in some way. We do this using *gradient descent*. Let's see how this works..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3f292334",
   "metadata": {
    "_kg_hide-input": true,
    "papermill": {
     "duration": 2.927483,
     "end_time": "2022-08-25T20:07:36.477711",
     "exception": false,
     "start_time": "2022-08-25T20:07:33.550228",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "from ipywidgets import interact\n",
    "from fastai.basics import *\n",
    "\n",
    "plt.rc('figure', dpi=90)\n",
    "\n",
    "def plot_function(f, title=None, min=-2.1, max=2.1, color='r', ylim=None):\n",
    "    x = torch.linspace(min,max, 100)[:,None]\n",
    "    if ylim: plt.ylim(ylim)\n",
    "    plt.plot(x, f(x), color)\n",
    "    if title is not None: plt.title(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f503eec4-46b5-4429-af0a-3c1507211db5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([-2.1000, -2.0576, -2.0152, -1.9727, -1.9303, -1.8879, -1.8455, -1.8030,\n",
      "        -1.7606, -1.7182, -1.6758, -1.6333, -1.5909, -1.5485, -1.5061, -1.4636,\n",
      "        -1.4212, -1.3788, -1.3364, -1.2939, -1.2515, -1.2091, -1.1667, -1.1242,\n",
      "        -1.0818, -1.0394, -0.9970, -0.9545, -0.9121, -0.8697, -0.8273, -0.7848,\n",
      "        -0.7424, -0.7000, -0.6576, -0.6152, -0.5727, -0.5303, -0.4879, -0.4455,\n",
      "        -0.4030, -0.3606, -0.3182, -0.2758, -0.2333, -0.1909, -0.1485, -0.1061,\n",
      "        -0.0636, -0.0212,  0.0212,  0.0636,  0.1061,  0.1485,  0.1909,  0.2333,\n",
      "         0.2758,  0.3182,  0.3606,  0.4030,  0.4455,  0.4879,  0.5303,  0.5727,\n",
      "         0.6152,  0.6576,  0.7000,  0.7424,  0.7848,  0.8273,  0.8697,  0.9121,\n",
      "         0.9545,  0.9970,  1.0394,  1.0818,  1.1242,  1.1667,  1.2091,  1.2515,\n",
      "         1.2939,  1.3364,  1.3788,  1.4212,  1.4636,  1.5061,  1.5485,  1.5909,\n",
      "         1.6333,  1.6758,  1.7182,  1.7606,  1.8030,  1.8455,  1.8879,  1.9303,\n",
      "         1.9727,  2.0152,  2.0576,  2.1000])\n",
      "tensor([[-2.1000],\n",
      "        [-2.0576],\n",
      "        [-2.0152],\n",
      "        [-1.9727],\n",
      "        [-1.9303],\n",
      "        [-1.8879],\n",
      "        [-1.8455],\n",
      "        [-1.8030],\n",
      "        [-1.7606],\n",
      "        [-1.7182],\n",
      "        [-1.6758],\n",
      "        [-1.6333],\n",
      "        [-1.5909],\n",
      "        [-1.5485],\n",
      "        [-1.5061],\n",
      "        [-1.4636],\n",
      "        [-1.4212],\n",
      "        [-1.3788],\n",
      "        [-1.3364],\n",
      "        [-1.2939],\n",
      "        [-1.2515],\n",
      "        [-1.2091],\n",
      "        [-1.1667],\n",
      "        [-1.1242],\n",
      "        [-1.0818],\n",
      "        [-1.0394],\n",
      "        [-0.9970],\n",
      "        [-0.9545],\n",
      "        [-0.9121],\n",
      "        [-0.8697],\n",
      "        [-0.8273],\n",
      "        [-0.7848],\n",
      "        [-0.7424],\n",
      "        [-0.7000],\n",
      "        [-0.6576],\n",
      "        [-0.6152],\n",
      "        [-0.5727],\n",
      "        [-0.5303],\n",
      "        [-0.4879],\n",
      "        [-0.4455],\n",
      "        [-0.4030],\n",
      "        [-0.3606],\n",
      "        [-0.3182],\n",
      "        [-0.2758],\n",
      "        [-0.2333],\n",
      "        [-0.1909],\n",
      "        [-0.1485],\n",
      "        [-0.1061],\n",
      "        [-0.0636],\n",
      "        [-0.0212],\n",
      "        [ 0.0212],\n",
      "        [ 0.0636],\n",
      "        [ 0.1061],\n",
      "        [ 0.1485],\n",
      "        [ 0.1909],\n",
      "        [ 0.2333],\n",
      "        [ 0.2758],\n",
      "        [ 0.3182],\n",
      "        [ 0.3606],\n",
      "        [ 0.4030],\n",
      "        [ 0.4455],\n",
      "        [ 0.4879],\n",
      "        [ 0.5303],\n",
      "        [ 0.5727],\n",
      "        [ 0.6152],\n",
      "        [ 0.6576],\n",
      "        [ 0.7000],\n",
      "        [ 0.7424],\n",
      "        [ 0.7848],\n",
      "        [ 0.8273],\n",
      "        [ 0.8697],\n",
      "        [ 0.9121],\n",
      "        [ 0.9545],\n",
      "        [ 0.9970],\n",
      "        [ 1.0394],\n",
      "        [ 1.0818],\n",
      "        [ 1.1242],\n",
      "        [ 1.1667],\n",
      "        [ 1.2091],\n",
      "        [ 1.2515],\n",
      "        [ 1.2939],\n",
      "        [ 1.3364],\n",
      "        [ 1.3788],\n",
      "        [ 1.4212],\n",
      "        [ 1.4636],\n",
      "        [ 1.5061],\n",
      "        [ 1.5485],\n",
      "        [ 1.5909],\n",
      "        [ 1.6333],\n",
      "        [ 1.6758],\n",
      "        [ 1.7182],\n",
      "        [ 1.7606],\n",
      "        [ 1.8030],\n",
      "        [ 1.8455],\n",
      "        [ 1.8879],\n",
      "        [ 1.9303],\n",
      "        [ 1.9727],\n",
      "        [ 2.0152],\n",
      "        [ 2.0576],\n",
      "        [ 2.1000]])\n"
     ]
    }
   ],
   "source": [
    "# ----- O.S.\n",
    "min = -2.1\n",
    "max = 2.1\n",
    "print(torch.linspace(min,max, 100))\n",
    "print(torch.linspace(min, max, 100)[:, None])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4257b420",
   "metadata": {
    "papermill": {
     "duration": 0.050319,
     "end_time": "2022-08-25T20:07:36.579069",
     "exception": false,
     "start_time": "2022-08-25T20:07:36.528750",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "To learn how gradient descent works, we're going to start by fitting a quadratic, since that's a function most of us are probably more familiar with than a neural network. Here's the quadratic we're going to try to fit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2593774b",
   "metadata": {
    "papermill": {
     "duration": 0.749326,
     "end_time": "2022-08-25T20:07:37.379666",
     "exception": false,
     "start_time": "2022-08-25T20:07:36.630340",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 19784 characters]",
      "text/plain": [
       "<Figure size 576x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def f(x): return 3*x**2 + 2*x + 1\n",
    "\n",
    "plot_function(f, \"$3x^2 + 2x + 1$\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6666634",
   "metadata": {
    "papermill": {
     "duration": 0.053733,
     "end_time": "2022-08-25T20:07:37.488295",
     "exception": false,
     "start_time": "2022-08-25T20:07:37.434562",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "This quadratic is of the form $ax^2+bx+c$, with parameters $a=3$, $b=2$, $c=1$. To make it easier to try out different quadratics for fitting a model to the data we'll create, let's create a function that calculates the value of a point on any quadratic:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "baa04765",
   "metadata": {
    "papermill": {
     "duration": 0.060896,
     "end_time": "2022-08-25T20:07:37.601523",
     "exception": false,
     "start_time": "2022-08-25T20:07:37.540627",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def quad(a, b, c, x): return a*x**2 + b*x + c"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b766ac5c",
   "metadata": {
    "papermill": {
     "duration": 0.052339,
     "end_time": "2022-08-25T20:07:37.705955",
     "exception": false,
     "start_time": "2022-08-25T20:07:37.653616",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "If we fix some particular values of a, b, and c, then we'll have made a quadratic. To fix values passed to a function in python, we use the `partial` function, like so:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "73e48914",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:37.813312Z",
     "iopub.status.busy": "2022-08-25T20:07:37.812714Z",
     "iopub.status.idle": "2022-08-25T20:07:37.817252Z",
     "shell.execute_reply": "2022-08-25T20:07:37.816351Z"
    },
    "papermill": {
     "duration": 0.061101,
     "end_time": "2022-08-25T20:07:37.819613",
     "exception": false,
     "start_time": "2022-08-25T20:07:37.758512",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def mk_quad(a,b,c): return partial(quad, a,b,c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04a3095c",
   "metadata": {
    "papermill": {
     "duration": 0.053165,
     "end_time": "2022-08-25T20:07:37.924738",
     "exception": false,
     "start_time": "2022-08-25T20:07:37.871573",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "So for instance, we can recreate our previous quadratic:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ac501308",
   "metadata": {
    "papermill": {
     "duration": 0.217053,
     "end_time": "2022-08-25T20:07:38.194697",
     "exception": false,
     "start_time": "2022-08-25T20:07:37.977644",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'mk_quad' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[11], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m f2 \u001b[38;5;241m=\u001b[39m \u001b[43mmk_quad\u001b[49m(\u001b[38;5;241m3\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m1\u001b[39m)\n\u001b[1;32m      2\u001b[0m plot_function(f2)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'mk_quad' is not defined"
     ]
    }
   ],
   "source": [
    "f2 = mk_quad(3,2,1)\n",
    "plot_function(f2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd409866",
   "metadata": {
    "papermill": {
     "duration": 0.053255,
     "end_time": "2022-08-25T20:07:38.302893",
     "exception": false,
     "start_time": "2022-08-25T20:07:38.249638",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Now let's simulate making some noisy measurements of our quadratic `f`. We'll then use gradient descent to see if we can recreate the original function from the data.\n",
    "\n",
    "Here's a couple of functions to add some random noise to data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1ad970e9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:38.420964Z",
     "iopub.status.busy": "2022-08-25T20:07:38.420337Z",
     "iopub.status.idle": "2022-08-25T20:07:38.425847Z",
     "shell.execute_reply": "2022-08-25T20:07:38.425170Z"
    },
    "papermill": {
     "duration": 0.065291,
     "end_time": "2022-08-25T20:07:38.428511",
     "exception": false,
     "start_time": "2022-08-25T20:07:38.363220",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def noise(x, scale): return np.random.normal(scale=scale, size=x.shape)\n",
    "def add_noise(x, mult, add): return x * (1+noise(x,mult)) + noise(x,add)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e40b2620",
   "metadata": {
    "papermill": {
     "duration": 0.053241,
     "end_time": "2022-08-25T20:07:38.534864",
     "exception": false,
     "start_time": "2022-08-25T20:07:38.481623",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Let's use the now to create our noisy measurements based on the quadratic above:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0b6ded02",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:38.643829Z",
     "iopub.status.busy": "2022-08-25T20:07:38.643229Z",
     "iopub.status.idle": "2022-08-25T20:07:38.663046Z",
     "shell.execute_reply": "2022-08-25T20:07:38.662166Z"
    },
    "papermill": {
     "duration": 0.077566,
     "end_time": "2022-08-25T20:07:38.665781",
     "exception": false,
     "start_time": "2022-08-25T20:07:38.588215",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "np.random.seed(42)\n",
    "\n",
    "x = torch.linspace(-2, 2, steps=20)[:,None]\n",
    "y = add_noise(f(x), 0.15, 1.5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b4124ee",
   "metadata": {
    "papermill": {
     "duration": 0.053058,
     "end_time": "2022-08-25T20:07:38.774839",
     "exception": false,
     "start_time": "2022-08-25T20:07:38.721781",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Here's the first few values of each of `x` and `y`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3051094d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:38.884832Z",
     "iopub.status.busy": "2022-08-25T20:07:38.884552Z",
     "iopub.status.idle": "2022-08-25T20:07:38.939146Z",
     "shell.execute_reply": "2022-08-25T20:07:38.938247Z"
    },
    "papermill": {
     "duration": 0.111613,
     "end_time": "2022-08-25T20:07:38.941649",
     "exception": false,
     "start_time": "2022-08-25T20:07:38.830036",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([[-2.0000],\n",
       "         [-1.7895],\n",
       "         [-1.5789],\n",
       "         [-1.3684],\n",
       "         [-1.1579]]),\n",
       " tensor([[11.8690],\n",
       "         [ 6.5433],\n",
       "         [ 5.9396],\n",
       "         [ 2.6304],\n",
       "         [ 1.7947]], dtype=torch.float64))"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x[:5],y[:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c8d53d17",
   "metadata": {
    "papermill": {
     "duration": 0.053861,
     "end_time": "2022-08-25T20:07:39.052282",
     "exception": false,
     "start_time": "2022-08-25T20:07:38.998421",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "As you can see, they're *tensors*. A tensor is just like an `array` in numpy (if you're not familiar with numpy, I strongly recommend reading [this great book](https://wesmckinney.com/book/), because it's a critical foundation for nearly all numeric programming in Python. Furthermore, PyTorch, which most researchers use for deep learning, is modeled closely on numpy.) A tensor can be a single number (a *scalar* or *rank-0 tensor*), a list of numbers (a *vector* or *rank-1 tensor*), a table of numbers (a *matrix* or *rank-2 tensor*), a table of tables of numbers (a *rank-3 tensor*), and so forth.\n",
    "\n",
    "We're not going to learn much about our data by just looking at the raw numbers, so let's draw a picture:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "29bed640",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:39.162259Z",
     "iopub.status.busy": "2022-08-25T20:07:39.161887Z",
     "iopub.status.idle": "2022-08-25T20:07:39.371161Z",
     "shell.execute_reply": "2022-08-25T20:07:39.369887Z"
    },
    "papermill": {
     "duration": 0.267753,
     "end_time": "2022-08-25T20:07:39.373934",
     "exception": false,
     "start_time": "2022-08-25T20:07:39.106181",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 9432 characters]\n",
      "text/plain": [
       "<Figure size 540x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x,y);"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70935a05",
   "metadata": {
    "papermill": {
     "duration": 0.054997,
     "end_time": "2022-08-25T20:07:39.485480",
     "exception": false,
     "start_time": "2022-08-25T20:07:39.430483",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "How do we find values of a, b, and c which fit this data? One approach is to try a few values and see what fits. Here's a function which overlays a quadratic on top of our data, along with some sliders to change a, b, and c, and see how it looks:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6f2e3097",
   "metadata": {
    "papermill": {
     "duration": 0.25987,
     "end_time": "2022-08-25T20:07:39.800933",
     "exception": false,
     "start_time": "2022-08-25T20:07:39.541063",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7d974699d3f24b00bca2c356f7f53d6a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=1.1, description='a', max=3.3000000000000003, min=-1.1), FloatSlider(v…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(a=1.1, b=1.1, c=1.1)\n",
    "def plot_quad(a, b, c):\n",
    "    plt.scatter(x,y)\n",
    "    plot_function(mk_quad(a,b,c), ylim=(-3,13))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5746e92a",
   "metadata": {
    "papermill": {
     "duration": 0.057525,
     "end_time": "2022-08-25T20:07:39.916141",
     "exception": false,
     "start_time": "2022-08-25T20:07:39.858616",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "**Reminder**: If the sliders above aren't working for you, that's because the interactive features of this notebook don't work in Kaggle's *Reader* mode. They only work in *Edit* mode. Please click \"**Copy & Edit**\" in the top right of this window, then in the menu click *Run* and then *Run all*. Then you'll be able to use all the interactive sliders in this notebook."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71b0c806",
   "metadata": {
    "papermill": {
     "duration": 0.056913,
     "end_time": "2022-08-25T20:07:40.029870",
     "exception": false,
     "start_time": "2022-08-25T20:07:39.972957",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Try moving slider `a` a bit to the left. Does that look better or worse? How about if you move it a bit to the right? Find out which direction seems to improve the fit of the quadratic to the data, and move the slider a bit in that direction. Next, do the same for slider `b`: first figure out which direction improves the fit, then move it a bit in that direction. Then do the same for `c`.\n",
    "\n",
    "OK, now go back to slider `a` and repeat the process. Do it again for `b` and `c` as well.\n",
    "\n",
    "Did you notice that by going back and doing the sliders a second time that you were able to improve things a bit further? That's an important insight -- it's only after changing `b` and `c`, for instance, that you realise that `a` actually needs some adjustment based on those new values.\n",
    "\n",
    "One thing that's making this tricky is that we don't really have a great sense of whether our fit is really better or worse. It would be easier if we had a numeric measure of that. On easy metric we could use is *mean absolute error* -- which is the distance from each data point to the curve:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "df751d3b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:40.144056Z",
     "iopub.status.busy": "2022-08-25T20:07:40.143468Z",
     "iopub.status.idle": "2022-08-25T20:07:40.148008Z",
     "shell.execute_reply": "2022-08-25T20:07:40.147308Z"
    },
    "papermill": {
     "duration": 0.064344,
     "end_time": "2022-08-25T20:07:40.150158",
     "exception": false,
     "start_time": "2022-08-25T20:07:40.085814",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def mae(preds, acts): return (torch.abs(preds-acts)).mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae8d2a03",
   "metadata": {
    "papermill": {
     "duration": 0.057507,
     "end_time": "2022-08-25T20:07:40.263936",
     "exception": false,
     "start_time": "2022-08-25T20:07:40.206429",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "We'll update our interactive function to print this at the top for us.\n",
    "\n",
    "Use this to repeat the approach we took before to try to find the best fit, but this time just use the value of the metric to decide which direction to move each slider, and how far to move it.\n",
    "\n",
    "This time around, try doing it in the opposite order: `c`, then `b`, then `a`.\n",
    "\n",
    "You'll probably find that you have to go through the set of sliders a couple of times to get the best fit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8ed292c2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:40.379145Z",
     "iopub.status.busy": "2022-08-25T20:07:40.378537Z",
     "iopub.status.idle": "2022-08-25T20:07:40.579146Z",
     "shell.execute_reply": "2022-08-25T20:07:40.578110Z"
    },
    "papermill": {
     "duration": 0.261419,
     "end_time": "2022-08-25T20:07:40.582142",
     "exception": false,
     "start_time": "2022-08-25T20:07:40.320723",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "63d8c4049a1746aca81f59dfd79e399e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=1.1, description='a', max=3.3000000000000003, min=-1.1), FloatSlider(v…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(a=1.1, b=1.1, c=1.1)\n",
    "def plot_quad(a, b, c):\n",
    "    f = mk_quad(a,b,c)\n",
    "    plt.scatter(x,y)\n",
    "    loss = mae(f(x), y)\n",
    "    plot_function(f, ylim=(-3,12), title=f\"MAE: {loss:.2f}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2aeb0e32",
   "metadata": {
    "papermill": {
     "duration": 0.056845,
     "end_time": "2022-08-25T20:07:40.700029",
     "exception": false,
     "start_time": "2022-08-25T20:07:40.643184",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "In a modern neural network we'll often have tens of millions of parameters to fit, or more, and thousands or millions of data points to fit them to. We're not going to be able to do that by moving sliders around! We'll need to automate this process.\n",
    "\n",
    "Thankfully, that turns out to be pretty straightforward. We can use calculus to figure out, for each parameter, whether we should increase or decrease it.\n",
    "\n",
    "Uh oh, calculus! If you haven't touched calculus since school, you might be getting ready to run away at this point. But don't worry, we don't actually need much calculus at all. Just derivatives, which measure the rate of change of a function. We don't even need to calculate them ourselves, because the computer will do it for us! If you've forgotten what a derivitive is, then watch the first three of these fantastic [videos by Professor Dave](https://www.youtube.com/playlist?list=PLybg94GvOJ9ELZEe9s2NXTKr41Yedbw7M). It's only 15 minutes in total, so give it a go! Then come back here and we'll continue on our journey..."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fee30cd8",
   "metadata": {
    "papermill": {
     "duration": 0.057563,
     "end_time": "2022-08-25T20:07:40.816514",
     "exception": false,
     "start_time": "2022-08-25T20:07:40.758951",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Automating gradient descent"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87c8c980",
   "metadata": {
    "papermill": {
     "duration": 0.057092,
     "end_time": "2022-08-25T20:07:40.931523",
     "exception": false,
     "start_time": "2022-08-25T20:07:40.874431",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "The basic idea is this: if we know the *gradient* of our `mae()` function *with respect to* our parameters, `a`, `b`, and `c`, then that means we know how adjusting (for instance) `a` will change the value of `mae()`. If, say, `a` has a *negative* gradient, then we know that increasing `a` will decrease `mae()`. Then we know that's what we need to do, since we trying to make `mae()` as low as possible.\n",
    "\n",
    "So, we find the gradient of `mae()` for each of our parameters, and then adjust our parameters a bit in the *opposite* direction to the sign of the gradient.\n",
    "\n",
    "To do this, first we need a function that takes all the parameters `a`, `b`, and `c` as a single vector input, and returns the value `mae()` based on those parameters:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "99e6873c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:41.048664Z",
     "iopub.status.busy": "2022-08-25T20:07:41.048263Z",
     "iopub.status.idle": "2022-08-25T20:07:41.053708Z",
     "shell.execute_reply": "2022-08-25T20:07:41.052629Z"
    },
    "papermill": {
     "duration": 0.067504,
     "end_time": "2022-08-25T20:07:41.055716",
     "exception": false,
     "start_time": "2022-08-25T20:07:40.988212",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def quad_mae(params):\n",
    "    f = mk_quad(*params)\n",
    "    return mae(f(x), y)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87f7a56d",
   "metadata": {
    "papermill": {
     "duration": 0.056573,
     "end_time": "2022-08-25T20:07:41.168543",
     "exception": false,
     "start_time": "2022-08-25T20:07:41.111970",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Let's try it:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8c24095c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:41.285912Z",
     "iopub.status.busy": "2022-08-25T20:07:41.285610Z",
     "iopub.status.idle": "2022-08-25T20:07:41.291918Z",
     "shell.execute_reply": "2022-08-25T20:07:41.291201Z"
    },
    "papermill": {
     "duration": 0.068561,
     "end_time": "2022-08-25T20:07:41.295489",
     "exception": false,
     "start_time": "2022-08-25T20:07:41.226928",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(2.4219, dtype=torch.float64)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quad_mae([1.1, 1.1, 1.1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "692e01e2",
   "metadata": {
    "papermill": {
     "duration": 0.056523,
     "end_time": "2022-08-25T20:07:41.410468",
     "exception": false,
     "start_time": "2022-08-25T20:07:41.353945",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Yup, that's the same as the starting `mae()` we had in our plot before.\n",
    "\n",
    "We're first going to do exactly the same thing as we did manually -- pick some arbritrary starting point for our parameters. We'll put them all into a single tensor:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e997eb4b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:41.528651Z",
     "iopub.status.busy": "2022-08-25T20:07:41.528347Z",
     "iopub.status.idle": "2022-08-25T20:07:41.532746Z",
     "shell.execute_reply": "2022-08-25T20:07:41.531930Z"
    },
    "papermill": {
     "duration": 0.066122,
     "end_time": "2022-08-25T20:07:41.534953",
     "exception": false,
     "start_time": "2022-08-25T20:07:41.468831",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "abc = torch.tensor([1.1,1.1,1.1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b3e7e72",
   "metadata": {
    "papermill": {
     "duration": 0.056943,
     "end_time": "2022-08-25T20:07:41.653134",
     "exception": false,
     "start_time": "2022-08-25T20:07:41.596191",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "To tell PyTorch that we want it to calculate gradients for these parameters, we need to call `requires_grad_()`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "d0917ae5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:41.772666Z",
     "iopub.status.busy": "2022-08-25T20:07:41.772054Z",
     "iopub.status.idle": "2022-08-25T20:07:41.778111Z",
     "shell.execute_reply": "2022-08-25T20:07:41.777472Z"
    },
    "papermill": {
     "duration": 0.068716,
     "end_time": "2022-08-25T20:07:41.780006",
     "exception": false,
     "start_time": "2022-08-25T20:07:41.711290",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([1.1000, 1.1000, 1.1000], requires_grad=True)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abc.requires_grad_()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac4495e1",
   "metadata": {
    "papermill": {
     "duration": 0.056886,
     "end_time": "2022-08-25T20:07:41.894138",
     "exception": false,
     "start_time": "2022-08-25T20:07:41.837252",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "We can now calculate `mae()`. Generally, when doing gradient descent, the thing we're trying to minimise is called the *loss*:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "503b5f3e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:42.010102Z",
     "iopub.status.busy": "2022-08-25T20:07:42.009476Z",
     "iopub.status.idle": "2022-08-25T20:07:42.018028Z",
     "shell.execute_reply": "2022-08-25T20:07:42.017155Z"
    },
    "papermill": {
     "duration": 0.069517,
     "end_time": "2022-08-25T20:07:42.020405",
     "exception": false,
     "start_time": "2022-08-25T20:07:41.950888",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(2.4219, dtype=torch.float64, grad_fn=<MeanBackward0>)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loss = quad_mae(abc)\n",
    "loss"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6e24654",
   "metadata": {
    "papermill": {
     "duration": 0.05721,
     "end_time": "2022-08-25T20:07:42.136775",
     "exception": false,
     "start_time": "2022-08-25T20:07:42.079565",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "To get PyTorch to now calculate the gradients, we need to call `backward()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5fdbcd8f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:42.261189Z",
     "iopub.status.busy": "2022-08-25T20:07:42.260839Z",
     "iopub.status.idle": "2022-08-25T20:07:42.278941Z",
     "shell.execute_reply": "2022-08-25T20:07:42.277808Z"
    },
    "papermill": {
     "duration": 0.087635,
     "end_time": "2022-08-25T20:07:42.282776",
     "exception": false,
     "start_time": "2022-08-25T20:07:42.195141",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "loss.backward()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca33d7bf",
   "metadata": {
    "papermill": {
     "duration": 0.060017,
     "end_time": "2022-08-25T20:07:42.423013",
     "exception": false,
     "start_time": "2022-08-25T20:07:42.362996",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "The gradients will be stored for us in an attribute called `grad`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "31a80ca2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:42.540364Z",
     "iopub.status.busy": "2022-08-25T20:07:42.540046Z",
     "iopub.status.idle": "2022-08-25T20:07:42.546911Z",
     "shell.execute_reply": "2022-08-25T20:07:42.545989Z"
    },
    "papermill": {
     "duration": 0.068131,
     "end_time": "2022-08-25T20:07:42.549131",
     "exception": false,
     "start_time": "2022-08-25T20:07:42.481000",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([-1.3529, -0.0316, -0.5000])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "abc.grad"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "540c5991",
   "metadata": {
    "papermill": {
     "duration": 0.058756,
     "end_time": "2022-08-25T20:07:42.665593",
     "exception": false,
     "start_time": "2022-08-25T20:07:42.606837",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "According to these gradients, all our parameters are a little low. So let's increase them a bit. If we subtract the gradient, multiplied by a small number, that should improve them a bit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "ebd11e5b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:42.786333Z",
     "iopub.status.busy": "2022-08-25T20:07:42.785688Z",
     "iopub.status.idle": "2022-08-25T20:07:42.794518Z",
     "shell.execute_reply": "2022-08-25T20:07:42.793337Z"
    },
    "papermill": {
     "duration": 0.073371,
     "end_time": "2022-08-25T20:07:42.797430",
     "exception": false,
     "start_time": "2022-08-25T20:07:42.724059",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loss=2.40\n"
     ]
    }
   ],
   "source": [
    "with torch.no_grad():\n",
    "    abc -= abc.grad*0.01\n",
    "    loss = quad_mae(abc)\n",
    "    \n",
    "print(f'loss={loss:.2f}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76eec1c0",
   "metadata": {
    "papermill": {
     "duration": 0.058037,
     "end_time": "2022-08-25T20:07:42.913878",
     "exception": false,
     "start_time": "2022-08-25T20:07:42.855841",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Yes, our loss has gone down!\n",
    "\n",
    "The \"small number\" we multiply is called the *learning rate*, and is the most important *hyper-parameter* to set when training a neural network.\n",
    "\n",
    "BTW, you'll see we had to wrap our calculation of the new parameters in `with torch.no_grad()`. That disables the calculation of gradients for any operations inside that context manager. We have to do that, because `abc -= abc.grad*0.01` isn't actually part of our quadratic model, so we don't want derivitives to include that calculation.\n",
    "\n",
    "We can use a loop to do a few more iterations of this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "cd493774",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:43.035069Z",
     "iopub.status.busy": "2022-08-25T20:07:43.034290Z",
     "iopub.status.idle": "2022-08-25T20:07:43.047020Z",
     "shell.execute_reply": "2022-08-25T20:07:43.046167Z"
    },
    "papermill": {
     "duration": 0.077071,
     "end_time": "2022-08-25T20:07:43.049662",
     "exception": false,
     "start_time": "2022-08-25T20:07:42.972591",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "step=0; loss=2.40\n",
      "step=1; loss=2.36\n",
      "step=2; loss=2.30\n",
      "step=3; loss=2.21\n",
      "step=4; loss=2.11\n",
      "step=5; loss=1.98\n",
      "step=6; loss=1.85\n",
      "step=7; loss=1.72\n",
      "step=8; loss=1.58\n",
      "step=9; loss=1.46\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    loss = quad_mae(abc)\n",
    "    loss.backward()\n",
    "    with torch.no_grad(): abc -= abc.grad*0.01\n",
    "    print(f'step={i}; loss={loss:.2f}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42a2f766",
   "metadata": {
    "papermill": {
     "duration": 0.05823,
     "end_time": "2022-08-25T20:07:43.166115",
     "exception": false,
     "start_time": "2022-08-25T20:07:43.107885",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "As you can see, our loss keeps going down!\n",
    "\n",
    "If you keep running this loop for long enough however, you'll see that the loss eventually starts increasing for a while. That's because once the parameters get close to the correct answer, our parameter updates will jump right over the correct answer! To avoid this, we need to decrease our learning rate as we train. This is done using a *learning rate schedule*, and can be automated in most deep learning frameworks, such as fastai and PyTorch."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b55006fa",
   "metadata": {
    "papermill": {
     "duration": 0.058523,
     "end_time": "2022-08-25T20:07:43.283176",
     "exception": false,
     "start_time": "2022-08-25T20:07:43.224653",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## How a neural network approximates any given function"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71aeaa95",
   "metadata": {
    "papermill": {
     "duration": 0.063582,
     "end_time": "2022-08-25T20:07:43.405325",
     "exception": false,
     "start_time": "2022-08-25T20:07:43.341743",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "But neural nets are much more convenient and powerful than this example showed, because we can learn much more than just a quadratic with them. How does *that* work?\n",
    "\n",
    "The trick is that a neural network is a very expressive function. In fact -- it's [infinitely expressive](https://en.wikipedia.org/wiki/Universal_approximation_theorem). A neural network can approximate any computable function, given enough parameters. A \"computable function\" can cover just about anything you can imagine: understand and translate human speech; paint a picture; diagnose a disease from medical imaging; write an essay; etc...\n",
    "\n",
    "The way a neural network approximates a function actually turns out to be very simple. The key trick is to combine two extremely basic steps:\n",
    "\n",
    "1. Matrix multiplication, which is just multiplying things together and then adding them up\n",
    "1. The function $max(x,0)$, which simply replaces all negative numbers with zero.\n",
    "\n",
    "In PyTorch, the function $max(x,0)$ is written as `np.clip(x,0)`. The combination of a linear function and this *max()* is called a *rectified linear function*, and it can be implemented like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "412da407",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:43.525106Z",
     "iopub.status.busy": "2022-08-25T20:07:43.524628Z",
     "iopub.status.idle": "2022-08-25T20:07:43.529663Z",
     "shell.execute_reply": "2022-08-25T20:07:43.528738Z"
    },
    "papermill": {
     "duration": 0.067748,
     "end_time": "2022-08-25T20:07:43.532001",
     "exception": false,
     "start_time": "2022-08-25T20:07:43.464253",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def rectified_linear(m,b,x):\n",
    "    y = m*x+b\n",
    "    return torch.clip(y, 0.)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15315f97",
   "metadata": {
    "papermill": {
     "duration": 0.058296,
     "end_time": "2022-08-25T20:07:43.648566",
     "exception": false,
     "start_time": "2022-08-25T20:07:43.590270",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Here's what it looks like:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "570ab468",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:43.768332Z",
     "iopub.status.busy": "2022-08-25T20:07:43.767616Z",
     "iopub.status.idle": "2022-08-25T20:07:43.920721Z",
     "shell.execute_reply": "2022-08-25T20:07:43.919809Z"
    },
    "papermill": {
     "duration": 0.216463,
     "end_time": "2022-08-25T20:07:43.923331",
     "exception": false,
     "start_time": "2022-08-25T20:07:43.706868",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 12360 characters]\n",
      "text/plain": [
       "<Figure size 540x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_function(partial(rectified_linear, 1,1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0f31c65",
   "metadata": {
    "papermill": {
     "duration": 0.062016,
     "end_time": "2022-08-25T20:07:44.046261",
     "exception": false,
     "start_time": "2022-08-25T20:07:43.984245",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "BTW, instead of `torch.clip(y, 0.)`, we can instead use `F.relu(x)`, which does exactly the same thing. In PyTorch, `F` refers to the `torch.nn.functional` module."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9ec64961",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:44.167767Z",
     "iopub.status.busy": "2022-08-25T20:07:44.167152Z",
     "iopub.status.idle": "2022-08-25T20:07:44.320639Z",
     "shell.execute_reply": "2022-08-25T20:07:44.319555Z"
    },
    "papermill": {
     "duration": 0.217461,
     "end_time": "2022-08-25T20:07:44.323347",
     "exception": false,
     "start_time": "2022-08-25T20:07:44.105886",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 12360 characters]\n",
      "text/plain": [
       "<Figure size 540x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import torch.nn.functional as F\n",
    "def rectified_linear2(m,b,x): return F.relu(m*x+b)\n",
    "plot_function(partial(rectified_linear2, 1,1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "546b3360",
   "metadata": {
    "papermill": {
     "duration": 0.062441,
     "end_time": "2022-08-25T20:07:44.446586",
     "exception": false,
     "start_time": "2022-08-25T20:07:44.384145",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "To understand how this function works, try using this interactive version to play around with the parameters `m` and `b`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "32d1b66e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:44.573708Z",
     "iopub.status.busy": "2022-08-25T20:07:44.573014Z",
     "iopub.status.idle": "2022-08-25T20:07:44.736021Z",
     "shell.execute_reply": "2022-08-25T20:07:44.734530Z"
    },
    "papermill": {
     "duration": 0.230874,
     "end_time": "2022-08-25T20:07:44.740440",
     "exception": false,
     "start_time": "2022-08-25T20:07:44.509566",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5a95997c90d54f3485a0188c269db968",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=1.5, description='m', max=4.5, min=-1.5), FloatSlider(value=1.5, descr…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@interact(m=1.5, b=1.5)\n",
    "def plot_relu(m, b):\n",
    "    plot_function(partial(rectified_linear, m,b), ylim=(-1,4))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8585a90",
   "metadata": {
    "papermill": {
     "duration": 0.062979,
     "end_time": "2022-08-25T20:07:44.876951",
     "exception": false,
     "start_time": "2022-08-25T20:07:44.813972",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "As you see, `m` changes the slope, and `b` changes where the \"hook\" appears. This function doesn't do much on its own, but look what happens when we add two of them together:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "3b480ece",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2022-08-25T20:07:45.003167Z",
     "iopub.status.busy": "2022-08-25T20:07:45.002676Z",
     "iopub.status.idle": "2022-08-25T20:07:45.257292Z",
     "shell.execute_reply": "2022-08-25T20:07:45.256304Z"
    },
    "papermill": {
     "duration": 0.322162,
     "end_time": "2022-08-25T20:07:45.259898",
     "exception": false,
     "start_time": "2022-08-25T20:07:44.937736",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b1f9d605473b42a6b897864fe5e8d75d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=-1.5, description='m1', max=1.5, min=-4.5), FloatSlider(value=-1.5, de…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def double_relu(m1,b1,m2,b2,x):\n",
    "    return rectified_linear(m1,b1,x) + rectified_linear(m2,b2,x)\n",
    "\n",
    "@interact(m1=-1.5, b1=-1.5, m2=1.5, b2=1.5)\n",
    "def plot_double_relu(m1, b1, m2, b2):\n",
    "    plot_function(partial(double_relu, m1,b1,m2,b2), ylim=(-1,6))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "189ddba9",
   "metadata": {
    "papermill": {
     "duration": 0.06207,
     "end_time": "2022-08-25T20:07:45.384783",
     "exception": false,
     "start_time": "2022-08-25T20:07:45.322713",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "If you play around with that for a while, you notice something quite profound: with enough of these rectified linear functions added together, you could approximate any function with a single input, to whatever accuracy you like! Any time the function doesn't quite match, you can just add a few more additions to the mix to make it a bit closer. As an experiment, perhaps you'd like to try creating your own `plot_triple_relu` interactive function, and maybe even include the scatter plot of our data from before, to see how close you can get?\n",
    "\n",
    "This exact same approach can be expanded to functions of 2, 3, or more parameters."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "59eb8223",
   "metadata": {
    "papermill": {
     "duration": 0.061546,
     "end_time": "2022-08-25T20:07:45.508441",
     "exception": false,
     "start_time": "2022-08-25T20:07:45.446895",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## How to recognise an owl"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "22016a2e",
   "metadata": {
    "papermill": {
     "duration": 0.062896,
     "end_time": "2022-08-25T20:07:45.632618",
     "exception": false,
     "start_time": "2022-08-25T20:07:45.569722",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "OK great, we've created a nifty little example showing that we can drawing squiggly lines that go through some points. So what?\n",
    "\n",
    "Well... the truth is that actually drawing squiggly lines (or planes, or high-dimensional hyperplanes...) through some points is literally *all that deep learning does*! If your data points are, say, the RGB values of pixels in photos of owls, then you can create an owl-recogniser model by following the exact steps above.\n",
    "\n",
    "This may, at first, sound about as useful as the classic \"how to draw an owl\" guide:"
   ]
  },
  {
   "attachments": {
    "c66592d3-c997-4c72-aed4-2dea579b96e1.png": {
     "image/png": "[encoded data, 287840 characters]"
    }
   },
   "cell_type": "markdown",
   "id": "d80f352a",
   "metadata": {
    "papermill": {
     "duration": 0.062224,
     "end_time": "2022-08-25T20:07:45.757225",
     "exception": false,
     "start_time": "2022-08-25T20:07:45.695001",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "![image.png](attachment:c66592d3-c997-4c72-aed4-2dea579b96e1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea696932",
   "metadata": {
    "papermill": {
     "duration": 0.061443,
     "end_time": "2022-08-25T20:07:45.884322",
     "exception": false,
     "start_time": "2022-08-25T20:07:45.822879",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Students often ask me at this point \"OK Jeremy, but how do neural nets *actually work*\". But at a foundational level, there is no \"step 2\". We're done -- the above steps will, given enough time and enough data, create (for example) an owl recogniser, if you feed in enough owls (and non-owls).\n",
    "\n",
    "The devil, I guess, is in the \"given enough time and enough data\" part of the above sentence. There's a *lot* of tweaks we can make to reduce both of these things. For instance, instead of running our calculations on a normal CPU, as we've done above, we could do thousands of them simultaneously by taking advantage of a GPU. We could greatly reduce the amount of computation and data needed by using a convolution instead of a matrix multiplication, which basically means skipping over a bunch of the multiplications and additions for bits that you'd guess won't be important. We could make things much faster if, instead of starting with random parameters, we start with parameters of someone else's model that does something similar to what we want (this is called *transfer learning*).\n",
    "\n",
    "And, of course, there's lots of helpful software out there to do this stuff for you without too much fuss. Like, say, [fastai](https://docs.fast.ai).\n",
    "\n",
    "Learning these things is what we teach in our [course](https://course.fast.ai), which, like everything we make, is totally free. So if you're interested in learning more, do check it out!"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e97e11b3",
   "metadata": {
    "papermill": {
     "duration": 0.061744,
     "end_time": "2022-08-25T20:07:46.007428",
     "exception": false,
     "start_time": "2022-08-25T20:07:45.945684",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "As always, if you enjoyed this notebook, please upvote it to help others find it, and to encourage me to write more. If you upvote it, be careful you don't accidentally upvote your copy that's created when you click \"Copy & Edit\" -- you can find my original at [this link](https://www.kaggle.com/code/jhoward/how-does-a-neural-net-really-work)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6ca74e0",
   "metadata": {
    "papermill": {
     "duration": 0.061323,
     "end_time": "2022-08-25T20:07:46.130052",
     "exception": false,
     "start_time": "2022-08-25T20:07:46.068729",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 24.478653,
   "end_time": "2022-08-25T20:07:47.316654",
   "environment_variables": {},
   "exception": null,
   "input_path": "__notebook__.ipynb",
   "output_path": "__notebook__.ipynb",
   "parameters": {},
   "start_time": "2022-08-25T20:07:22.838001",
   "version": "2.3.4"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {
     "047448df85ff458fae024e80b07f52b7": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "06ed31ded81d4a81a58b5f64df393aed": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "0ae400dce73a456880e14358b485acd6": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "160b4213858d4ed59cd2fc29d743532f": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "1ec0006ea87141eba6b31259c8a27278": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "m1",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_06ed31ded81d4a81a58b5f64df393aed",
       "max": 1.5,
       "min": -4.5,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_dac6cfed65f14423bfc5e10f56c40d93",
       "value": -1.5
      }
     },
     "1fa6ffcba5bf4ed5b156407247c674e6": {
      "model_module": "@jupyter-widgets/output",
      "model_module_version": "1.0.0",
      "model_name": "OutputModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/output",
       "_model_module_version": "1.0.0",
       "_model_name": "OutputModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/output",
       "_view_module_version": "1.0.0",
       "_view_name": "OutputView",
       "layout": "IPY_MODEL_635fc5b32ed34503a10d3a3746645421",
       "msg_id": "",
       "outputs": [
        {
         "data": {
          "image/png": "[encoded data, 13404 characters]\n",
          "text/plain": "<Figure size 540x360 with 1 Axes>"
         },
         "metadata": {
          "needs_background": "light"
         },
         "output_type": "display_data"
        }
       ]
      }
     },
     "2193e35abd0b4864a2973f8383e7c8af": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "m",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_b268e6c4a51245f9b25377c2d11b45d9",
       "max": 4.5,
       "min": -1.5,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_4edbbf32cd6f488b9f8320163c15c9a0",
       "value": 1.5
      }
     },
     "2f3dfed7b1c948f187e62ad1edcf1a47": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "2f97254dd29a440b99748acb514104c7": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "31b51b7912a7430093714847f79d6510": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "a",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_047448df85ff458fae024e80b07f52b7",
       "max": 3.3000000000000003,
       "min": -1.1,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_5bd537ec026b4284aeccabcc60c71f9a",
       "value": 1.1
      }
     },
     "33a4d8a5453849e98a903365b7972a13": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "38da57b137214461bc6dd50b2875cf10": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "3a18f662232849c195519e89f2f2afc5": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "3d0fe90e14194622bfd103d86fd6188a": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "3e180d93a0464bf9b02ede014b756d90": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "VBoxModel",
      "state": {
       "_dom_classes": [
        "widget-interact"
       ],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "VBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "VBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_caeb428a915d49d39d6cad488655d19c",
        "IPY_MODEL_9f551acbb01243d68f6f4b828da53c67",
        "IPY_MODEL_e8e488da9d4c4d499964e957990b2c93",
        "IPY_MODEL_1fa6ffcba5bf4ed5b156407247c674e6"
       ],
       "layout": "IPY_MODEL_9e69a2220fd34b8e82c242222a6e5c94"
      }
     },
     "415b223406f042359022fadf91e316d1": {
      "model_module": "@jupyter-widgets/output",
      "model_module_version": "1.0.0",
      "model_name": "OutputModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/output",
       "_model_module_version": "1.0.0",
       "_model_name": "OutputModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/output",
       "_view_module_version": "1.0.0",
       "_view_name": "OutputView",
       "layout": "IPY_MODEL_2f3dfed7b1c948f187e62ad1edcf1a47",
       "msg_id": "",
       "outputs": [
        {
         "data": {
          "image/png": "[encoded data, 15272 characters]\n",
          "text/plain": "<Figure size 540x360 with 1 Axes>"
         },
         "metadata": {
          "needs_background": "light"
         },
         "output_type": "display_data"
        }
       ]
      }
     },
     "4edbbf32cd6f488b9f8320163c15c9a0": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "5345689157f8488bb319057298557e03": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "5a6e9e7d202740a9ad90c81e36ad4ea5": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "5a95997c90d54f3485a0188c269db968": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "VBoxModel",
      "state": {
       "_dom_classes": [
        "widget-interact"
       ],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "VBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "VBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_2193e35abd0b4864a2973f8383e7c8af",
        "IPY_MODEL_aacbd739e70d444eb50272489d225230",
        "IPY_MODEL_667f08be6b744c888f1ab4c2242563d3"
       ],
       "layout": "IPY_MODEL_5a6e9e7d202740a9ad90c81e36ad4ea5"
      }
     },
     "5bd537ec026b4284aeccabcc60c71f9a": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "635fc5b32ed34503a10d3a3746645421": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "63d8c4049a1746aca81f59dfd79e399e": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "VBoxModel",
      "state": {
       "_dom_classes": [
        "widget-interact"
       ],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "VBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "VBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_31b51b7912a7430093714847f79d6510",
        "IPY_MODEL_732ef943dbd04219b5757ee038af5d21",
        "IPY_MODEL_cebb7358f49c475691a3e8d1cf3a1472",
        "IPY_MODEL_415b223406f042359022fadf91e316d1"
       ],
       "layout": "IPY_MODEL_160b4213858d4ed59cd2fc29d743532f"
      }
     },
     "667f08be6b744c888f1ab4c2242563d3": {
      "model_module": "@jupyter-widgets/output",
      "model_module_version": "1.0.0",
      "model_name": "OutputModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/output",
       "_model_module_version": "1.0.0",
       "_model_name": "OutputModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/output",
       "_view_module_version": "1.0.0",
       "_view_name": "OutputView",
       "layout": "IPY_MODEL_a4623a31093f413b8c3c8e3790533497",
       "msg_id": "",
       "outputs": [
        {
         "data": {
          "image/png": "[encoded data, 8140 characters]\n",
          "text/plain": "<Figure size 540x360 with 1 Axes>"
         },
         "metadata": {
          "needs_background": "light"
         },
         "output_type": "display_data"
        }
       ]
      }
     },
     "67ad1674c8854f2a84f6c0324a7d6670": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "6a59e76c97f548318d016f6ba95068d0": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "732ef943dbd04219b5757ee038af5d21": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "b",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_3d0fe90e14194622bfd103d86fd6188a",
       "max": 3.3000000000000003,
       "min": -1.1,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_bfe1018a6e8543978e1d5423465db68c",
       "value": 1.1
      }
     },
     "7bc9f505b1284cb48e635b829d9fa631": {
      "model_module": "@jupyter-widgets/output",
      "model_module_version": "1.0.0",
      "model_name": "OutputModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/output",
       "_model_module_version": "1.0.0",
       "_model_name": "OutputModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/output",
       "_view_module_version": "1.0.0",
       "_view_name": "OutputView",
       "layout": "IPY_MODEL_b9f69cde590246cb81da87ed8b3b3237",
       "msg_id": "",
       "outputs": [
        {
         "data": {
          "image/png": "[encoded data, 10432 characters]\n",
          "text/plain": "<Figure size 540x360 with 1 Axes>"
         },
         "metadata": {
          "needs_background": "light"
         },
         "output_type": "display_data"
        }
       ]
      }
     },
     "7eca316e516e4feda361aa1a0a351ba9": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "8542b48d5b9e49c58a1994d4c2f9ce12": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "8ace134e135347669e8c1d6fc94a68ed": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "m2",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_38da57b137214461bc6dd50b2875cf10",
       "max": 4.5,
       "min": -1.5,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_91cd167451bc4c348ac5da79584c0d91",
       "value": 1.5
      }
     },
     "8cd2fa5ca39f4c5b812d7b9dd04b5e69": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "91cd167451bc4c348ac5da79584c0d91": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "99d51ae0adbc4398864f14229221705d": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "9e69a2220fd34b8e82c242222a6e5c94": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "9f551acbb01243d68f6f4b828da53c67": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "b",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_c2c06796e43a4694bb1ea360b46514af",
       "max": 3.3000000000000003,
       "min": -1.1,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_8cd2fa5ca39f4c5b812d7b9dd04b5e69",
       "value": 1.1
      }
     },
     "a4623a31093f413b8c3c8e3790533497": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "aacbd739e70d444eb50272489d225230": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "b",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_33a4d8a5453849e98a903365b7972a13",
       "max": 4.5,
       "min": -1.5,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_5345689157f8488bb319057298557e03",
       "value": 1.5
      }
     },
     "b1f9d605473b42a6b897864fe5e8d75d": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "VBoxModel",
      "state": {
       "_dom_classes": [
        "widget-interact"
       ],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "VBoxModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "VBoxView",
       "box_style": "",
       "children": [
        "IPY_MODEL_1ec0006ea87141eba6b31259c8a27278",
        "IPY_MODEL_d5c28a0e60b843bc8e9f0144e1f56e94",
        "IPY_MODEL_8ace134e135347669e8c1d6fc94a68ed",
        "IPY_MODEL_b4ddbf2c94414c3797daa09ae5f97ba0",
        "IPY_MODEL_7bc9f505b1284cb48e635b829d9fa631"
       ],
       "layout": "IPY_MODEL_6a59e76c97f548318d016f6ba95068d0"
      }
     },
     "b268e6c4a51245f9b25377c2d11b45d9": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "b4ddbf2c94414c3797daa09ae5f97ba0": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "b2",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_3a18f662232849c195519e89f2f2afc5",
       "max": 4.5,
       "min": -1.5,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_67ad1674c8854f2a84f6c0324a7d6670",
       "value": 1.5
      }
     },
     "b9f69cde590246cb81da87ed8b3b3237": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "bfe1018a6e8543978e1d5423465db68c": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "c2c06796e43a4694bb1ea360b46514af": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "c8e9fb88c06d47d59f53d33e6b6b1d9c": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "caeb428a915d49d39d6cad488655d19c": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "a",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_d5af0e27eb3d4fc1a7968ff62d2c080b",
       "max": 3.3000000000000003,
       "min": -1.1,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_7eca316e516e4feda361aa1a0a351ba9",
       "value": 1.1
      }
     },
     "cebb7358f49c475691a3e8d1cf3a1472": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "c",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_cf8284fe61144817abcc1867f9019844",
       "max": 3.3000000000000003,
       "min": -1.1,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_2f97254dd29a440b99748acb514104c7",
       "value": 1.1
      }
     },
     "cf8284fe61144817abcc1867f9019844": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "d5af0e27eb3d4fc1a7968ff62d2c080b": {
      "model_module": "@jupyter-widgets/base",
      "model_module_version": "1.2.0",
      "model_name": "LayoutModel",
      "state": {
       "_model_module": "@jupyter-widgets/base",
       "_model_module_version": "1.2.0",
       "_model_name": "LayoutModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "LayoutView",
       "align_content": null,
       "align_items": null,
       "align_self": null,
       "border": null,
       "bottom": null,
       "display": null,
       "flex": null,
       "flex_flow": null,
       "grid_area": null,
       "grid_auto_columns": null,
       "grid_auto_flow": null,
       "grid_auto_rows": null,
       "grid_column": null,
       "grid_gap": null,
       "grid_row": null,
       "grid_template_areas": null,
       "grid_template_columns": null,
       "grid_template_rows": null,
       "height": null,
       "justify_content": null,
       "justify_items": null,
       "left": null,
       "margin": null,
       "max_height": null,
       "max_width": null,
       "min_height": null,
       "min_width": null,
       "object_fit": null,
       "object_position": null,
       "order": null,
       "overflow": null,
       "overflow_x": null,
       "overflow_y": null,
       "padding": null,
       "right": null,
       "top": null,
       "visibility": null,
       "width": null
      }
     },
     "d5c28a0e60b843bc8e9f0144e1f56e94": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "b1",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_0ae400dce73a456880e14358b485acd6",
       "max": 1.5,
       "min": -4.5,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_c8e9fb88c06d47d59f53d33e6b6b1d9c",
       "value": -1.5
      }
     },
     "dac6cfed65f14423bfc5e10f56c40d93": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "SliderStyleModel",
      "state": {
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "SliderStyleModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/base",
       "_view_module_version": "1.2.0",
       "_view_name": "StyleView",
       "description_width": "",
       "handle_color": null
      }
     },
     "e8e488da9d4c4d499964e957990b2c93": {
      "model_module": "@jupyter-widgets/controls",
      "model_module_version": "1.5.0",
      "model_name": "FloatSliderModel",
      "state": {
       "_dom_classes": [],
       "_model_module": "@jupyter-widgets/controls",
       "_model_module_version": "1.5.0",
       "_model_name": "FloatSliderModel",
       "_view_count": null,
       "_view_module": "@jupyter-widgets/controls",
       "_view_module_version": "1.5.0",
       "_view_name": "FloatSliderView",
       "continuous_update": true,
       "description": "c",
       "description_tooltip": null,
       "disabled": false,
       "layout": "IPY_MODEL_8542b48d5b9e49c58a1994d4c2f9ce12",
       "max": 3.3000000000000003,
       "min": -1.1,
       "orientation": "horizontal",
       "readout": true,
       "readout_format": ".2f",
       "step": 0.1,
       "style": "IPY_MODEL_99d51ae0adbc4398864f14229221705d",
       "value": 1.1
      }
     }
    },
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
