Created using Colab
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"provenance": [],
|
||||
"authorship_tag": "ABX9TyO2DaD75p+LGi7WgvTzjrk1",
|
||||
"include_colab_link": true
|
||||
},
|
||||
"kernelspec": {
|
||||
@@ -31,7 +30,7 @@
|
||||
"source": [
|
||||
"# **Notebook 4.3 Deep neural networks**\n",
|
||||
"\n",
|
||||
"This network investigates converting neural networks to matrix form.\n",
|
||||
"This notebook investigates converting neural networks to matrix form.\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 make predictions about what is going to happen or write code to complete the functions.\n",
|
||||
"\n",
|
||||
@@ -150,7 +149,7 @@
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"source": [
|
||||
"Now we'll define the same neural network, but this time, we will use matrix form. When you get this right, it will draw the same plot as above."
|
||||
"Now we'll define the same neural network, but this time, we will use matrix form as in equation 4.15. When you get this right, it will draw the same plot as above."
|
||||
],
|
||||
"metadata": {
|
||||
"id": "XCJqo_AjfAra"
|
||||
@@ -176,8 +175,8 @@
|
||||
"n1_in_mat = np.reshape(n1_in,(n_dim_in,n_data))\n",
|
||||
"\n",
|
||||
"# This runs the network for ALL of the inputs, x at once so we can draw graph\n",
|
||||
"h1 = ReLU(np.matmul(beta_0,np.ones((1,n_data))) + np.matmul(Omega_0,n1_in_mat))\n",
|
||||
"n1_out = np.matmul(beta_1,np.ones((1,n_data))) + np.matmul(Omega_1,h1)\n",
|
||||
"h1 = ReLU(beta_0 + np.matmul(Omega_0,n1_in_mat))\n",
|
||||
"n1_out = beta_1 + np.matmul(Omega_1,h1)\n",
|
||||
"\n",
|
||||
"# Draw the network and check that it looks the same as the non-matrix case\n",
|
||||
"plot_neural(n1_in, n1_out)"
|
||||
@@ -247,9 +246,9 @@
|
||||
"n1_in_mat = np.reshape(n1_in,(n_dim_in,n_data))\n",
|
||||
"\n",
|
||||
"# This runs the network for ALL of the inputs, x at once so we can draw graph (hence extra np.ones term)\n",
|
||||
"h1 = ReLU(np.matmul(beta_0,np.ones((1,n_data))) + np.matmul(Omega_0,n1_in_mat))\n",
|
||||
"h2 = ReLU(np.matmul(beta_1,np.ones((1,n_data))) + np.matmul(Omega_1,h1))\n",
|
||||
"n1_out = np.matmul(beta_2,np.ones((1,n_data))) + np.matmul(Omega_2,h2)\n",
|
||||
"h1 = ReLU(beta_0 + np.matmul(Omega_0,n1_in_mat))\n",
|
||||
"h2 = ReLU(beta_1 + np.matmul(Omega_1,h1))\n",
|
||||
"n1_out = beta_2 + np.matmul(Omega_2,h2)\n",
|
||||
"\n",
|
||||
"# Draw the network and check that it looks the same as the non-matrix version\n",
|
||||
"plot_neural(n1_in, n1_out)"
|
||||
@@ -291,10 +290,10 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"# If you set the parameters to the correct sizes, the following code will run\n",
|
||||
"h1 = ReLU(np.matmul(beta_0,np.ones((1,n_data))) + np.matmul(Omega_0,x));\n",
|
||||
"h2 = ReLU(np.matmul(beta_1,np.ones((1,n_data))) + np.matmul(Omega_1,h1));\n",
|
||||
"h3 = ReLU(np.matmul(beta_2,np.ones((1,n_data))) + np.matmul(Omega_2,h2));\n",
|
||||
"y = np.matmul(beta_3,np.ones((1,n_data))) + np.matmul(Omega_3,h3)\n",
|
||||
"h1 = ReLU(beta_0 + np.matmul(Omega_0,x));\n",
|
||||
"h2 = ReLU(beta_1 + np.matmul(Omega_1,h1));\n",
|
||||
"h3 = ReLU(beta_2 + np.matmul(Omega_2,h2));\n",
|
||||
"y = beta_3 + np.matmul(Omega_3,h3)\n",
|
||||
"\n",
|
||||
"if h1.shape[0] is not D_1 or h1.shape[1] is not n_data:\n",
|
||||
" print(\"h1 is wrong shape\")\n",
|
||||
|
||||
Reference in New Issue
Block a user