diff --git a/notebooks/ShallowNN/LinearRegions_Answers.ipynb b/notebooks/ShallowNN/LinearRegions_Answers.ipynb index 491d113..732cdba 100644 --- a/notebooks/ShallowNN/LinearRegions_Answers.ipynb +++ b/notebooks/ShallowNN/LinearRegions_Answers.ipynb @@ -4,7 +4,7 @@ "metadata": { "colab": { "provenance": [], - "authorship_tag": "ABX9TyOq8T2wOrCjh5hFtI51OCMX", + "authorship_tag": "ABX9TyNzwsksM8IfDPg9DEiV++cL", "include_colab_link": true }, "kernelspec": { @@ -29,13 +29,22 @@ { "cell_type": "markdown", "source": [ - "# **Notebook 3.3 -- Shallow network regions**\n", + "" + ], + "metadata": { + "id": "aRLqypzfFfJJ" + } + }, + { + "cell_type": "markdown", + "source": [ + "# **Linear regions**\n", "\n", - "The purpose of this notebook is to compute the maximum possible number of linear regions as seen in figure 3.9 of the book.\n", + "The purpose of this notebook is to compute the maximum possible number of linear regions for shallow networks with different numbers of hidden units and parameters.\n", "\n", - "Work through the cells below, running each cell in turn. In various places you will see the words \"TO DO\". Follow the instructions at these places and write code to complete the functions. There are also questions interspersed in the text.\n", + "You can save a local copy of this notebook in your Google account and work through it in Colab (recommended) or you can download the notebook and run it locally using Jupyter notebook or similar.\n", "\n", - "Contact me at udlbookmail@gmail.com if you find any mistakes or have any suggestions." + "Contact me at iclimbtreesmail@gmail.com if you find any mistakes or have any suggestions." ], "metadata": { "id": "DCTC8fQ6cp-n" @@ -54,7 +63,7 @@ "metadata": { "id": "W3C1ZA1gcpq_" }, - "execution_count": null, + "execution_count": 1, "outputs": [] }, { @@ -71,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "id": "4UQ2n0RWcgOb" }, @@ -103,9 +112,9 @@ "base_uri": "https://localhost:8080/" }, "id": "AqSUfuJDigN9", - "outputId": "61be2ce7-7d38-4eab-8cae-1ec410702a3a" + "outputId": "1a4b51c9-7f76-48e8-a8a5-7060da16e358" }, - "execution_count": null, + "execution_count": 4, "outputs": [ { "output_type": "stream", @@ -128,9 +137,9 @@ "base_uri": "https://localhost:8080/" }, "id": "krNKPV9gjCu-", - "outputId": "21b472e5-f0d2-4794-a155-d9d3a3faaf2e" + "outputId": "156e1ec4-9146-4235-90f3-29c35dbddf3a" }, - "execution_count": null, + "execution_count": 5, "outputs": [ { "output_type": "stream", @@ -153,9 +162,9 @@ "base_uri": "https://localhost:8080/" }, "id": "7g4j7OXaSniQ", - "outputId": "70e4e022-5485-41e6-fce6-e0536669ed8a" + "outputId": "ba9dbaf9-2af9-42e1-f253-7f473a11ed29" }, - "execution_count": null, + "execution_count": 6, "outputs": [ { "output_type": "stream", @@ -178,9 +187,9 @@ "base_uri": "https://localhost:8080/" }, "id": "OfgVQzHBfgI7", - "outputId": "19c72b90-ddfe-42ba-c725-16b4bde97c3f" + "outputId": "be3ac953-cad6-45b0-cc7c-749415a6e586" }, - "execution_count": null, + "execution_count": 7, "outputs": [ { "output_type": "stream", @@ -194,9 +203,7 @@ { "cell_type": "markdown", "source": [ - "This works but there is a complication. If the number of hidden units $D$ is fewer than the number of input dimensions $D_i$ , the formula will fail. When this is the case, there are just $2^D$ regions (see figure 3.10 to understand why).\n", - "\n", - "Let's demonstrate this:" + "This works but there may be a complication. If the number of hidden units $D$ is fewer than the number of input dimensions $D_i$ , the formula may fail, depending on how you implemented it (it will work with Math.comb(). In this degenerate case, there are just $2^D$ regions." ], "metadata": { "id": "rk1a2LqGkO9u" @@ -205,10 +212,13 @@ { "cell_type": "code", "source": [ - "# Show that calculation fails when $D_i < D$\n", + "# Test calculation when $D_i < D$\n", + "# If it fails, then rewrite your function number_regions() to cope with this degenerate case\n", "try:\n", - " N = number_regions(10, 8)\n", - " print(f\"Di=10, D=8, Number of regions = {int(N)}, True value = 256\")\n", + " D_i = 10\n", + " D = 8\n", + " N = number_regions(D_i, D)\n", + " print(f\"Di={int(D_i)}, D={int(D)}, Number of regions = {int(N)}, True value = 256\")\n", "except Exception as error:\n", " print(\"An exception occurred:\", error)\n" ], @@ -217,9 +227,9 @@ "base_uri": "https://localhost:8080/" }, "id": "uq5IeAZTkIMg", - "outputId": "908f3d89-585c-4f45-f88d-386be37f3ea2" + "outputId": "01fd40a5-50d7-442e-ca00-23e27652dc76" }, - "execution_count": null, + "execution_count": 20, "outputs": [ { "output_type": "stream", @@ -233,36 +243,8 @@ { "cell_type": "code", "source": [ - "# Let's do the calculation properly when D