diff --git a/doc/pub/week40/html/._week40-bs009.html b/doc/pub/week40/html/._week40-bs009.html index 027146370..605b857bf 100644 --- a/doc/pub/week40/html/._week40-bs009.html +++ b/doc/pub/week40/html/._week40-bs009.html @@ -315,7 +315,7 @@ MathJax.Hub.Config({
import numpy as np 
 
 n = 100 #100 datapoints 
-M = 5   #size of each minibatch
+M = 5   #size of each mini-batche
 m = int(n/M) #number of minibatches
 n_epochs = 10 #number of epochs
 
diff --git a/doc/pub/week40/html/._week40-bs011.html b/doc/pub/week40/html/._week40-bs011.html
index 1e0c6c9d1..4f579826b 100644
--- a/doc/pub/week40/html/._week40-bs011.html
+++ b/doc/pub/week40/html/._week40-bs011.html
@@ -352,6 +352,9 @@ j = 0
 
 print("gamma_j after %d epochs: %g" % (n_epochs,gamma_j))
 
+

+We note that we have defined several hyperparameters. These are now the number of epochs, the number of mini-batches and the parameters \( t_0 \) and \( t_1 \). +

diff --git a/doc/pub/week40/html/._week40-bs012.html b/doc/pub/week40/html/._week40-bs012.html index d9ee67aa9..efcfdd25b 100644 --- a/doc/pub/week40/html/._week40-bs012.html +++ b/doc/pub/week40/html/._week40-bs012.html @@ -319,9 +319,9 @@ MathJax.Hub.Config({ import matplotlib.pyplot as plt from sklearn.linear_model import SGDRegressor -m = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +n = 100 +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) X = np.c_[np.ones((m,1)), x] theta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y) @@ -339,7 +339,7 @@ Niterations = 1 for iter in range(Niterations): - gradients = 2.0/m*X.T @ ((X @ theta)-y) + gradients = 2.0/n*X.T @ ((X @ theta)-y) theta -= eta*gradients print("theta from own gd") print(theta) @@ -351,7 +351,7 @@ ypredict2 = Xnew= 50 -M = 10 #size of each minibatch +M = 5 #size of each minibatch m = int(n/M) #number of minibatches t0, t1 = 5, 50 def learning_schedule(t): @@ -364,7 +364,7 @@ theta = np.= np.random.randint(m) xi = X[random_index:random_index+1] yi = y[random_index:random_index+1] - gradients = 2 * xi.T @ ((xi @ theta)-yi) + gradients = (2.0/m) * xi.T @ ((xi @ theta)-yi) eta = learning_schedule(epoch*m+i) theta = theta - eta*gradients print("theta from own sdg") diff --git a/doc/pub/week40/html/week40-reveal.html b/doc/pub/week40/html/week40-reveal.html index fb792e0fb..0cee2bee7 100644 --- a/doc/pub/week40/html/week40-reveal.html +++ b/doc/pub/week40/html/week40-reveal.html @@ -330,7 +330,7 @@ the number of minibatches, as exemplified in the code below.

import numpy as np 
 
 n = 100 #100 datapoints 
-M = 5   #size of each minibatch
+M = 5   #size of each mini-batche
 m = int(n/M) #number of minibatches
 n_epochs = 10 #number of epochs
 
@@ -418,6 +418,8 @@ j = 0
 
 print("gamma_j after %d epochs: %g" % (n_epochs,gamma_j))
 
+

+We note that we have defined several hyperparameters. These are now the number of epochs, the number of mini-batches and the parameters \( t_0 \) and \( t_1 \). @@ -434,9 +436,9 @@ j = 0 import matplotlib.pyplot as plt from sklearn.linear_model import SGDRegressor -m = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +n = 100 +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) X = np.c_[np.ones((m,1)), x] theta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y) @@ -454,7 +456,7 @@ Niterations = 1000 for iter in range(Niterations): - gradients = 2.0/m*X.T @ ((X @ theta)-y) + gradients = 2.0/n*X.T @ ((X @ theta)-y) theta -= eta*gradients print("theta from own gd") print(theta) @@ -466,7 +468,7 @@ ypredict2 = Xnew.dot(theta_linreg) n_epochs = 50 -M = 10 #size of each minibatch +M = 5 #size of each minibatch m = int(n/M) #number of minibatches t0, t1 = 5, 50 def learning_schedule(t): @@ -479,7 +481,7 @@ theta = np.random.randn(2,1] yi = y[random_index:random_index+1] - gradients = 2 * xi.T @ ((xi @ theta)-yi) + gradients = (2.0/m) * xi.T @ ((xi @ theta)-yi) eta = learning_schedule(epoch*m+i) theta = theta - eta*gradients print("theta from own sdg") diff --git a/doc/pub/week40/html/week40-solarized.html b/doc/pub/week40/html/week40-solarized.html index 3dc71d254..2ad884dd5 100644 --- a/doc/pub/week40/html/week40-solarized.html +++ b/doc/pub/week40/html/week40-solarized.html @@ -421,7 +421,7 @@ the number of minibatches, as exemplified in the code below.

import numpy as np 
 
 n = 100 #100 datapoints 
-M = 5   #size of each minibatch
+M = 5   #size of each mini-batche
 m = int(n/M) #number of minibatches
 n_epochs = 10 #number of epochs
 
@@ -507,6 +507,9 @@ j = 0
 
 print("gamma_j after %d epochs: %g" % (n_epochs,gamma_j))
 
+

+We note that we have defined several hyperparameters. These are now the number of epochs, the number of mini-batches and the parameters \( t_0 \) and \( t_1 \). +











@@ -522,9 +525,9 @@ j = 0 import matplotlib.pyplot as plt from sklearn.linear_model import SGDRegressor -m = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +n = 100 +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) X = np.c_[np.ones((m,1)), x] theta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y) @@ -542,7 +545,7 @@ Niterations = 1000 for iter in range(Niterations): - gradients = 2.0/m*X.T @ ((X @ theta)-y) + gradients = 2.0/n*X.T @ ((X @ theta)-y) theta -= eta*gradients print("theta from own gd") print(theta) @@ -554,7 +557,7 @@ ypredict2 = Xnew.dot(theta_linreg) n_epochs = 50 -M = 10 #size of each minibatch +M = 5 #size of each minibatch m = int(n/M) #number of minibatches t0, t1 = 5, 50 def learning_schedule(t): @@ -567,7 +570,7 @@ theta = np.random.randn(2,1] yi = y[random_index:random_index+1] - gradients = 2 * xi.T @ ((xi @ theta)-yi) + gradients = (2.0/m) * xi.T @ ((xi @ theta)-yi) eta = learning_schedule(epoch*m+i) theta = theta - eta*gradients print("theta from own sdg") diff --git a/doc/pub/week40/html/week40.html b/doc/pub/week40/html/week40.html index 28bbf6902..0bb83f2fb 100644 --- a/doc/pub/week40/html/week40.html +++ b/doc/pub/week40/html/week40.html @@ -426,7 +426,7 @@ the number of minibatches, as exemplified in the code below.

import numpy as np 
 
 n = 100 #100 datapoints 
-M = 5   #size of each minibatch
+M = 5   #size of each mini-batche
 m = int(n/M) #number of minibatches
 n_epochs = 10 #number of epochs
 
@@ -512,6 +512,9 @@ j = 0
 
 print("gamma_j after %d epochs: %g" % (n_epochs,gamma_j))
 
+

+We note that we have defined several hyperparameters. These are now the number of epochs, the number of mini-batches and the parameters \( t_0 \) and \( t_1 \). +











@@ -527,9 +530,9 @@ j = 0 import matplotlib.pyplot as plt from sklearn.linear_model import SGDRegressor -m = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +n = 100 +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) X = np.c_[np.ones((m,1)), x] theta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y) @@ -547,7 +550,7 @@ Niterations = 1 for iter in range(Niterations): - gradients = 2.0/m*X.T @ ((X @ theta)-y) + gradients = 2.0/n*X.T @ ((X @ theta)-y) theta -= eta*gradients print("theta from own gd") print(theta) @@ -559,7 +562,7 @@ ypredict2 = Xnew= 50 -M = 10 #size of each minibatch +M = 5 #size of each minibatch m = int(n/M) #number of minibatches t0, t1 = 5, 50 def learning_schedule(t): @@ -572,7 +575,7 @@ theta = np.= np.random.randint(m) xi = X[random_index:random_index+1] yi = y[random_index:random_index+1] - gradients = 2 * xi.T @ ((xi @ theta)-yi) + gradients = (2.0/m) * xi.T @ ((xi @ theta)-yi) eta = learning_schedule(epoch*m+i) theta = theta - eta*gradients print("theta from own sdg") diff --git a/doc/pub/week40/ipynb/ipynb-week40-src.tar.gz b/doc/pub/week40/ipynb/ipynb-week40-src.tar.gz index 6732a6591..e1c7ba345 100644 Binary files a/doc/pub/week40/ipynb/ipynb-week40-src.tar.gz and b/doc/pub/week40/ipynb/ipynb-week40-src.tar.gz differ diff --git a/doc/pub/week40/ipynb/week40.ipynb b/doc/pub/week40/ipynb/week40.ipynb index 8b3a99eba..4e1233143 100644 --- a/doc/pub/week40/ipynb/week40.ipynb +++ b/doc/pub/week40/ipynb/week40.ipynb @@ -195,7 +195,7 @@ "import numpy as np \n", "\n", "n = 100 #100 datapoints \n", - "M = 5 #size of each minibatch\n", + "M = 5 #size of each mini-batche\n", "m = int(n/M) #number of minibatches\n", "n_epochs = 10 #number of epochs\n", "\n", @@ -287,6 +287,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "We note that we have defined several hyperparameters. These are now the number of epochs, the number of mini-batches and the parameters $t_0$ and $t_1$.\n", + "\n", + "\n", "## Program for stochastic gradient" ] }, @@ -308,9 +311,9 @@ "import matplotlib.pyplot as plt\n", "from sklearn.linear_model import SGDRegressor\n", "\n", - "m = 100\n", - "x = 2*np.random.rand(m,1)\n", - "y = 4+3*x+np.random.randn(m,1)\n", + "n = 100\n", + "x = 2*np.random.rand(n,1)\n", + "y = 4+3*x+np.random.randn(n,1)\n", "\n", "X = np.c_[np.ones((m,1)), x]\n", "theta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y)\n", @@ -328,7 +331,7 @@ "\n", "\n", "for iter in range(Niterations):\n", - " gradients = 2.0/m*X.T @ ((X @ theta)-y)\n", + " gradients = 2.0/n*X.T @ ((X @ theta)-y)\n", " theta -= eta*gradients\n", "print(\"theta from own gd\")\n", "print(theta)\n", @@ -340,7 +343,7 @@ "\n", "\n", "n_epochs = 50\n", - "M = 10 #size of each minibatch\n", + "M = 5 #size of each minibatch\n", "m = int(n/M) #number of minibatches\n", "t0, t1 = 5, 50\n", "def learning_schedule(t):\n", @@ -353,7 +356,7 @@ " random_index = np.random.randint(m)\n", " xi = X[random_index:random_index+1]\n", " yi = y[random_index:random_index+1]\n", - " gradients = 2 * xi.T @ ((xi @ theta)-yi)\n", + " gradients = (2.0/m) * xi.T @ ((xi @ theta)-yi)\n", " eta = learning_schedule(epoch*m+i)\n", " theta = theta - eta*gradients\n", "print(\"theta from own sdg\")\n", diff --git a/doc/src/week40/week40.do.txt b/doc/src/week40/week40.do.txt index 3cd4c5974..cc16ff576 100644 --- a/doc/src/week40/week40.do.txt +++ b/doc/src/week40/week40.do.txt @@ -144,7 +144,7 @@ the number of minibatches, as exemplified in the code below. import numpy as np n = 100 #100 datapoints -M = 5 #size of each minibatch +M = 5 #size of each mini-batche m = int(n/M) #number of minibatches n_epochs = 10 #number of epochs @@ -222,7 +222,7 @@ print("gamma_j after %d epochs: %g" % (n_epochs,gamma_j)) !ec - +We note that we have defined several hyperparameters. These are now the number of epochs, the number of mini-batches and the parameters $t_0$ and $t_1$. !split @@ -236,9 +236,9 @@ import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import SGDRegressor -m = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +n = 100 +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) X = np.c_[np.ones((m,1)), x] theta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y) @@ -256,7 +256,7 @@ Niterations = 1000 for iter in range(Niterations): - gradients = 2.0/m*X.T @ ((X @ theta)-y) + gradients = 2.0/n*X.T @ ((X @ theta)-y) theta -= eta*gradients print("theta from own gd") print(theta) @@ -268,7 +268,7 @@ ypredict2 = Xnew.dot(theta_linreg) n_epochs = 50 -M = 10 #size of each minibatch +M = 5 #size of each minibatch m = int(n/M) #number of minibatches t0, t1 = 5, 50 def learning_schedule(t): @@ -281,7 +281,7 @@ for epoch in range(n_epochs): random_index = np.random.randint(m) xi = X[random_index:random_index+1] yi = y[random_index:random_index+1] - gradients = 2 * xi.T @ ((xi @ theta)-yi) + gradients = (2.0/m) * xi.T @ ((xi @ theta)-yi) eta = learning_schedule(epoch*m+i) theta = theta - eta*gradients print("theta from own sdg")