From 0dab750863d86fa7ebcc81caba590d56549a47da Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Thu, 7 Oct 2021 08:56:03 +0200 Subject: [PATCH] update --- doc/pub/week40/html/._week40-bs009.html | 2 +- doc/pub/week40/html/._week40-bs011.html | 3 +++ doc/pub/week40/html/._week40-bs012.html | 12 ++++++------ doc/pub/week40/html/week40-reveal.html | 16 +++++++++------- doc/pub/week40/html/week40-solarized.html | 17 ++++++++++------- doc/pub/week40/html/week40.html | 17 ++++++++++------- doc/pub/week40/ipynb/ipynb-week40-src.tar.gz | Bin 33808 -> 33808 bytes doc/pub/week40/ipynb/week40.ipynb | 17 ++++++++++------- doc/src/week40/week40.do.txt | 16 ++++++++-------- 9 files changed, 57 insertions(+), 43 deletions(-) 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 6732a65919700760174c461fb7e5e77ac1503abf..e1c7ba345deac7249463b2f930ae9fdf07f60066 100644 GIT binary patch delta 17 YcmbQx!8D1Qjci;k05kgq!~g&Q delta 17 YcmbQx!8D