Compare commits

..

12 Commits

Author SHA1 Message Date
udlbook
33197fde36 Add files via upload 2024-11-21 16:45:29 -05:00
udlbook
6d425c04d4 Update 3_3_Shallow_Network_Regions.ipynb 2024-11-18 15:33:42 -05:00
udlbook
57c95132d3 Created using Colab 2024-11-12 17:11:44 -05:00
udlbook
2b0ac95740 Created using Colab 2024-11-08 12:31:21 -05:00
udlbook
d5f198f2d8 Add files via upload 2024-11-04 15:25:38 -05:00
udlbook
4edd8c923d Add files via upload 2024-10-30 16:51:41 -04:00
udlbook
3801b8d52d Created using Colab 2024-10-24 16:45:43 -04:00
udlbook
dc6b346bda Created using Colab 2024-10-24 16:43:14 -04:00
udlbook
5eb264540d Created using Colab 2024-10-24 16:40:27 -04:00
udlbook
7ba844f2b5 Created using Colab 2024-10-24 16:04:27 -04:00
udlbook
d101aa428b Merge pull request #236 from aleksandrskoselevs/patch-1
Update 13_4_Graph_Attention_Networks.ipynb
2024-10-15 17:24:40 -04:00
aleksandrskoselevs
8c6e40daee Update 13_4_Graph_Attention_Networks.ipynb
`phi` is defined in the book as a column vector
2024-10-11 10:54:05 +02:00
8 changed files with 116 additions and 21 deletions

View File

@@ -4,7 +4,6 @@
"metadata": { "metadata": {
"colab": { "colab": {
"provenance": [], "provenance": [],
"authorship_tag": "ABX9TyNioITtfAcfxEfM3UOfQyb9",
"include_colab_link": true "include_colab_link": true
}, },
"kernelspec": { "kernelspec": {
@@ -62,7 +61,7 @@
"source": [ "source": [
"The number of regions $N$ created by a shallow neural network with $D_i$ inputs and $D$ hidden units is given by Zaslavsky's formula:\n", "The number of regions $N$ created by a shallow neural network with $D_i$ inputs and $D$ hidden units is given by Zaslavsky's formula:\n",
"\n", "\n",
"\\begin{equation}N = \\sum_{j=0}^{D_{i}}\\binom{D}{j}=\\sum_{j=0}^{D_{i}} \\frac{D!}{(D-j)!j!} \\end{equation} <br>\n", "\\begin{equation}N = \\sum_{j=0}^{D_{i}}\\binom{D}{j}=\\sum_{j=0}^{D_{i}} \\frac{D!}{(D-j)!j!} \\end{equation} \n",
"\n" "\n"
], ],
"metadata": { "metadata": {
@@ -221,7 +220,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"# Now let's plot the graph from figure 3.9a (takes ~1min)\n", "# Now let's plot the graph from figure 3.9b (takes ~1min)\n",
"dims = np.array([1,5,10,50,100])\n", "dims = np.array([1,5,10,50,100])\n",
"regions = np.zeros((dims.shape[0], 200))\n", "regions = np.zeros((dims.shape[0], 200))\n",
"params = np.zeros((dims.shape[0], 200))\n", "params = np.zeros((dims.shape[0], 200))\n",

View File

@@ -4,7 +4,6 @@
"metadata": { "metadata": {
"colab": { "colab": {
"provenance": [], "provenance": [],
"authorship_tag": "ABX9TyM2kkHLr00J4Jeypw41sTkQ",
"include_colab_link": true "include_colab_link": true
}, },
"kernelspec": { "kernelspec": {
@@ -230,8 +229,8 @@
"# We'll need the indicator function\n", "# We'll need the indicator function\n",
"def indicator_function(x):\n", "def indicator_function(x):\n",
" x_in = np.array(x)\n", " x_in = np.array(x)\n",
" x_in[x_in>=0] = 1\n", " x_in[x_in>0] = 1\n",
" x_in[x_in<0] = 0\n", " x_in[x_in<=0] = 0\n",
" return x_in\n", " return x_in\n",
"\n", "\n",
"# Main backward pass routine\n", "# Main backward pass routine\n",

View File

@@ -4,7 +4,7 @@
"metadata": { "metadata": {
"colab": { "colab": {
"provenance": [], "provenance": [],
"authorship_tag": "ABX9TyNELb86uz5qbhEKH81UqFKT", "authorship_tag": "ABX9TyORZF8xy4X1yf4oRhRq8Rtm",
"include_colab_link": true "include_colab_link": true
}, },
"kernelspec": { "kernelspec": {
@@ -72,8 +72,12 @@
"# even before you make changes.\n", "# even before you make changes.\n",
"batch_size_train = 64\n", "batch_size_train = 64\n",
"batch_size_test = 1000\n", "batch_size_test = 1000\n",
"\n",
"# TODO Change this directory to point towards an existing directory\n",
"myDir = '/files/'\n",
"\n",
"train_loader = torch.utils.data.DataLoader(\n", "train_loader = torch.utils.data.DataLoader(\n",
" torchvision.datasets.MNIST('/files/', train=True, download=True,\n", " torchvision.datasets.MNIST(myDir, train=True, download=True,\n",
" transform=torchvision.transforms.Compose([\n", " transform=torchvision.transforms.Compose([\n",
" torchvision.transforms.ToTensor(),\n", " torchvision.transforms.ToTensor(),\n",
" torchvision.transforms.Normalize(\n", " torchvision.transforms.Normalize(\n",
@@ -82,7 +86,7 @@
" batch_size=batch_size_train, shuffle=True)\n", " batch_size=batch_size_train, shuffle=True)\n",
"\n", "\n",
"test_loader = torch.utils.data.DataLoader(\n", "test_loader = torch.utils.data.DataLoader(\n",
" torchvision.datasets.MNIST('/files/', train=False, download=True,\n", " torchvision.datasets.MNIST(myDir, train=False, download=True,\n",
" transform=torchvision.transforms.Compose([\n", " transform=torchvision.transforms.Compose([\n",
" torchvision.transforms.ToTensor(),\n", " torchvision.transforms.ToTensor(),\n",
" torchvision.transforms.Normalize(\n", " torchvision.transforms.Normalize(\n",
@@ -96,15 +100,6 @@
"execution_count": null, "execution_count": null,
"outputs": [] "outputs": []
}, },
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "YGwbxJDEm88i"
},
"execution_count": null,
"outputs": []
},
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [

View File

@@ -109,7 +109,7 @@
"# Choose random values for the parameters\n", "# Choose random values for the parameters\n",
"omega = np.random.normal(size=(D,D))\n", "omega = np.random.normal(size=(D,D))\n",
"beta = np.random.normal(size=(D,1))\n", "beta = np.random.normal(size=(D,1))\n",
"phi = np.random.normal(size=(1,2*D))" "phi = np.random.normal(size=(2*D,1))"
], ],
"metadata": { "metadata": {
"id": "79TSK7oLMobe" "id": "79TSK7oLMobe"

View File

@@ -0,0 +1,51 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyM1pe3HkxLrjbeKezq1MlM5",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/udlbook/udlbook/blob/main/Trees/LinearRegression_LeastSquares.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Least Squares Loss"
],
"metadata": {
"id": "uORlKyPv02ge"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bbF6SE_F0tU8"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
}
]
}

View File

@@ -0,0 +1,51 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyMIJ9DpOBppPZXAJ5wms6s8",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/udlbook/udlbook/blob/main/Trees/LinearRegression_LossFunction.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Loss function"
],
"metadata": {
"id": "uORlKyPv02ge"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "bbF6SE_F0tU8"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
}
]
}

Binary file not shown.

Binary file not shown.