From 8e3008673d695b563b45d2f209cdc11d02d65d27 Mon Sep 17 00:00:00 2001 From: Youcef Rahal Date: Sat, 3 Feb 2024 13:47:32 -0500 Subject: [PATCH 1/4] Fix minor typos in 6_1_Line_Search.ipynb and 6_2_Gradient_Descent.ipynb --- Notebooks/Chap06/6_1_Line_Search.ipynb | 11 +++++------ Notebooks/Chap06/6_2_Gradient_Descent.ipynb | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Notebooks/Chap06/6_1_Line_Search.ipynb b/Notebooks/Chap06/6_1_Line_Search.ipynb index c6efb74..821381e 100644 --- a/Notebooks/Chap06/6_1_Line_Search.ipynb +++ b/Notebooks/Chap06/6_1_Line_Search.ipynb @@ -113,7 +113,7 @@ " b = 0.33\n", " c = 0.66\n", " d = 1.0\n", - " n_iter =0;\n", + " n_iter = 0\n", "\n", " # While we haven't found the minimum closely enough\n", " while np.abs(b-c) > thresh and n_iter < max_iter:\n", @@ -131,8 +131,7 @@ "\n", " print('Iter %d, a=%3.3f, b=%3.3f, c=%3.3f, d=%3.3f'%(n_iter, a,b,c,d))\n", "\n", - " # Rule #1 If the HEIGHT at point A is less the HEIGHT at points B, C, and D then halve values of B, C, and D\n", - " # i.e. bring them closer to the original point\n", + " # Rule #1 If the HEIGHT at point A is less than the HEIGHT at points B, C, and D then halve values of B, C, and D\n", " # i.e. bring them closer to the original point\n", " # TODO REPLACE THE BLOCK OF CODE BELOW WITH THIS RULE\n", " if (0):\n", @@ -140,7 +139,7 @@ "\n", "\n", " # Rule #2 If the HEIGHT at point b is less than the HEIGHT at point c then\n", - " # then point d becomes point c, and\n", + " # point d becomes point c, and\n", " # point b becomes 1/3 between a and new d\n", " # point c becomes 2/3 between a and new d\n", " # TODO REPLACE THE BLOCK OF CODE BELOW WITH THIS RULE\n", @@ -148,7 +147,7 @@ " continue;\n", "\n", " # Rule #3 If the HEIGHT at point c is less than the HEIGHT at point b then\n", - " # then point a becomes point b, and\n", + " # point a becomes point b, and\n", " # point b becomes 1/3 between new a and d\n", " # point c becomes 2/3 between new a and d\n", " # TODO REPLACE THE BLOCK OF CODE BELOW WITH THIS RULE\n", @@ -190,4 +189,4 @@ "outputs": [] } ] -} \ No newline at end of file +} diff --git a/Notebooks/Chap06/6_2_Gradient_Descent.ipynb b/Notebooks/Chap06/6_2_Gradient_Descent.ipynb index fb8cd60..b75364a 100644 --- a/Notebooks/Chap06/6_2_Gradient_Descent.ipynb +++ b/Notebooks/Chap06/6_2_Gradient_Descent.ipynb @@ -117,7 +117,7 @@ "id": "QU5mdGvpTtEG" }, "source": [ - "Now lets create compute the sum of squares loss for the training data" + "Now let's compute the sum of squares loss for the training data" ] }, { @@ -341,7 +341,7 @@ " continue;\n", "\n", " # Rule #2 If point b is less than point c then\n", - " # then point d becomes point c, and\n", + " # point d becomes point c, and\n", " # point b becomes 1/3 between a and new d\n", " # point c becomes 2/3 between a and new d\n", " if lossb < lossc:\n", @@ -351,7 +351,7 @@ " continue\n", "\n", " # Rule #2 If point c is less than point b then\n", - " # then point a becomes point b, and\n", + " # point a becomes point b, and\n", " # point b becomes 1/3 between new a and d\n", " # point c becomes 2/3 between new a and d\n", " a = b\n", From 732fc6f0b747eb17e89ac3efa00a8f44b0af2fdb Mon Sep 17 00:00:00 2001 From: Youcef Rahal Date: Tue, 6 Feb 2024 20:48:25 -0500 Subject: [PATCH 2/4] Fix issues typos in 6_3_Stochastic_Gradient_Descent.ipynb --- Notebooks/Chap06/6_2_Gradient_Descent.ipynb | 2 +- .../Chap06/6_3_Stochastic_Gradient_Descent.ipynb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Notebooks/Chap06/6_2_Gradient_Descent.ipynb b/Notebooks/Chap06/6_2_Gradient_Descent.ipynb index b75364a..d21991e 100644 --- a/Notebooks/Chap06/6_2_Gradient_Descent.ipynb +++ b/Notebooks/Chap06/6_2_Gradient_Descent.ipynb @@ -317,7 +317,7 @@ " b = 0.33 * max_dist\n", " c = 0.66 * max_dist\n", " d = 1.0 * max_dist\n", - " n_iter =0;\n", + " n_iter = 0\n", "\n", " # While we haven't found the minimum closely enough\n", " while np.abs(b-c) > thresh and n_iter < max_iter:\n", diff --git a/Notebooks/Chap06/6_3_Stochastic_Gradient_Descent.ipynb b/Notebooks/Chap06/6_3_Stochastic_Gradient_Descent.ipynb index 30ae779..51b5055 100644 --- a/Notebooks/Chap06/6_3_Stochastic_Gradient_Descent.ipynb +++ b/Notebooks/Chap06/6_3_Stochastic_Gradient_Descent.ipynb @@ -53,7 +53,7 @@ }, "outputs": [], "source": [ - "# Let's create our training data 30 pairs {x_i, y_i}\n", + "# Let's create our training data of 30 pairs {x_i, y_i}\n", "# We'll try to fit the Gabor model to these data\n", "data = np.array([[-1.920e+00,-1.422e+01,1.490e+00,-1.940e+00,-2.389e+00,-5.090e+00,\n", " -8.861e+00,3.578e+00,-6.010e+00,-6.995e+00,3.634e+00,8.743e-01,\n", @@ -128,7 +128,7 @@ "id": "QU5mdGvpTtEG" }, "source": [ - "Now lets create compute the sum of squares loss for the training data" + "Now let's compute the sum of squares loss for the training data" ] }, { @@ -198,7 +198,7 @@ " b = np.floor(my_colormap_vals_dec - r * 256 *256 - g * 256)\n", " my_colormap = ListedColormap(np.vstack((r,g,b)).transpose()/255.0)\n", "\n", - " # Make grid of intercept/slope values to plot\n", + " # Make grid of offset/frequency values to plot\n", " offsets_mesh, freqs_mesh = np.meshgrid(np.arange(-10,10.0,0.1), np.arange(2.5,22.5,0.1))\n", " loss_mesh = np.zeros_like(freqs_mesh)\n", " # Compute loss for every set of parameters\n", @@ -343,7 +343,7 @@ " b = 0.33 * max_dist\n", " c = 0.66 * max_dist\n", " d = 1.0 * max_dist\n", - " n_iter =0;\n", + " n_iter = 0\n", "\n", " # While we haven't found the minimum closely enough\n", " while np.abs(b-c) > thresh and n_iter < max_iter:\n", @@ -367,7 +367,7 @@ " continue;\n", "\n", " # Rule #2 If point b is less than point c then\n", - " # then point d becomes point c, and\n", + " # point d becomes point c, and\n", " # point b becomes 1/3 between a and new d\n", " # point c becomes 2/3 between a and new d\n", " if lossb < lossc:\n", @@ -377,7 +377,7 @@ " continue\n", "\n", " # Rule #2 If point c is less than point b then\n", - " # then point a becomes point b, and\n", + " # point a becomes point b, and\n", " # point b becomes 1/3 between new a and d\n", " # point c becomes 2/3 between new a and d\n", " a = b\n", From 6e76cb9b961640151f62eaced6b33ae2197ab668 Mon Sep 17 00:00:00 2001 From: Youcef Rahal Date: Wed, 7 Feb 2024 20:17:49 -0500 Subject: [PATCH 3/4] Fix typos in 6_4_Momentum.ipynb --- Notebooks/Chap06/6_4_Momentum.ipynb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Notebooks/Chap06/6_4_Momentum.ipynb b/Notebooks/Chap06/6_4_Momentum.ipynb index de38182..e7f7c9d 100644 --- a/Notebooks/Chap06/6_4_Momentum.ipynb +++ b/Notebooks/Chap06/6_4_Momentum.ipynb @@ -61,7 +61,7 @@ { "cell_type": "code", "source": [ - "# Let's create our training data 30 pairs {x_i, y_i}\n", + "# Let's create our training data of 30 pairs {x_i, y_i}\n", "# We'll try to fit the Gabor model to these data\n", "data = np.array([[-1.920e+00,-1.422e+01,1.490e+00,-1.940e+00,-2.389e+00,-5.090e+00,\n", " -8.861e+00,3.578e+00,-6.010e+00,-6.995e+00,3.634e+00,8.743e-01,\n", @@ -137,7 +137,7 @@ { "cell_type": "markdown", "source": [ - "Now lets compute the sum of squares loss for the training data and plot the loss function" + "Now let's compute the sum of squares loss for the training data and plot the loss function" ], "metadata": { "id": "QU5mdGvpTtEG" @@ -160,7 +160,7 @@ " b = np.floor(my_colormap_vals_dec - r * 256 *256 - g * 256)\n", " my_colormap = ListedColormap(np.vstack((r,g,b)).transpose()/255.0)\n", "\n", - " # Make grid of intercept/slope values to plot\n", + " # Make grid of offset/frequency values to plot\n", " offsets_mesh, freqs_mesh = np.meshgrid(np.arange(-10,10.0,0.1), np.arange(2.5,22.5,0.1))\n", " loss_mesh = np.zeros_like(freqs_mesh)\n", " # Compute loss for every set of parameters\n", @@ -365,7 +365,6 @@ "\n", " # Update the parameters\n", " phi_all[:,c_step+1:c_step+2] = phi_all[:,c_step:c_step+1] - alpha * momentum\n", - " # Measure loss and draw model every 8th step\n", "\n", "loss = compute_loss(data[0,:], data[1,:], model, phi_all[:,c_step+1:c_step+2])\n", "draw_model(data,model,phi_all[:,c_step+1], \"Iteration %d, loss = %f\"%(c_step+1,loss))\n", @@ -387,4 +386,4 @@ } } ] -} \ No newline at end of file +} From 435971e3e2bf30ef79e71c41ce78bd9823bfcc6e Mon Sep 17 00:00:00 2001 From: Youcef Rahal Date: Fri, 9 Feb 2024 03:55:11 -0500 Subject: [PATCH 4/4] Fix typos in 6_5_Adam.ipynb --- Notebooks/Chap06/6_5_Adam.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Notebooks/Chap06/6_5_Adam.ipynb b/Notebooks/Chap06/6_5_Adam.ipynb index e9ef3c7..279a2e5 100644 --- a/Notebooks/Chap06/6_5_Adam.ipynb +++ b/Notebooks/Chap06/6_5_Adam.ipynb @@ -110,7 +110,7 @@ " ax.plot(opt_path[0,:], opt_path[1,:],'-', color='#a0d9d3ff')\n", " ax.plot(opt_path[0,:], opt_path[1,:],'.', color='#a0d9d3ff',markersize=10)\n", " ax.set_xlabel(\"$\\phi_{0}$\")\n", - " ax.set_ylabel(\"$\\phi_1}$\")\n", + " ax.set_ylabel(\"$\\phi_{1}$\")\n", " plt.show()" ], "metadata": { @@ -169,7 +169,7 @@ { "cell_type": "markdown", "source": [ - "Because the function changes much faster in $\\phi_1$ than in $\\phi_0$, there is no great step size to choose. If we set the step size so that it makes sensible progress in the $\\phi_1$, then it takes many iterations to converge. If we set the step size tso that we make sensible progress in the $\\phi_{0}$ direction, then the path oscillates in the $\\phi_1$ direction. \n", + "Because the function changes much faster in $\\phi_1$ than in $\\phi_0$, there is no great step size to choose. If we set the step size so that it makes sensible progress in the $\\phi_1$ direction, then it takes many iterations to converge. If we set the step size so that we make sensible progress in the $\\phi_{0}$ direction, then the path oscillates in the $\\phi_1$ direction. \n", "\n", "This motivates Adam. At the core of Adam is the idea that we should just determine which way is downhill along each axis (i.e. left/right for $\\phi_0$ or up/down for $\\phi_1$) and move a fixed distance in that direction." ], @@ -285,4 +285,4 @@ "outputs": [] } ] -} \ No newline at end of file +}