diff --git a/doc/pub/week39/html/._week39-bs039.html b/doc/pub/week39/html/._week39-bs039.html index 43aaac74f..81943504e 100644 --- a/doc/pub/week39/html/._week39-bs039.html +++ b/doc/pub/week39/html/._week39-bs039.html @@ -281,11 +281,17 @@ x = 2*np y = 4+3*x+np.random.randn(n,1) X = np.c_[np.ones((n,1)), x] +# Hessian matrix +H = (2.0/n)* X.T @ X +# Get the eigenvalues +EigValues, EigVectors = np.linalg.eig(H) +print(EigValues) + beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y print(beta_linreg) beta = np.random.randn(2,1) -eta = 0.1 +eta = 1.0/np.max(EigValues) Niterations = 1000 for iter in range(Niterations): diff --git a/doc/pub/week39/html/._week39-bs042.html b/doc/pub/week39/html/._week39-bs042.html index 39aa14871..2266b3fd2 100644 --- a/doc/pub/week39/html/._week39-bs042.html +++ b/doc/pub/week39/html/._week39-bs042.html @@ -273,10 +273,10 @@ MathJax.Hub.Config({ # the number of datapoints n = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) -X = np.c_[np.ones((m,1)), x] +X = np.c_[np.ones((n,1)), x] XT_X = X.T @ X #Ridge parameter lambda diff --git a/doc/pub/week39/html/week39-reveal.html b/doc/pub/week39/html/week39-reveal.html index 8810406b8..1c0b2f5a7 100644 --- a/doc/pub/week39/html/week39-reveal.html +++ b/doc/pub/week39/html/week39-reveal.html @@ -1298,11 +1298,17 @@ x = 2*np.random.rand(n,4+3*x+np.random.randn(n,1) X = np.c_[np.ones((n,1)), x] +# Hessian matrix +H = (2.0/n)* X.T @ X +# Get the eigenvalues +EigValues, EigVectors = np.linalg.eig(H) +print(EigValues) + beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y print(beta_linreg) beta = np.random.randn(2,1) -eta = 0.1 +eta = 1.0/np.max(EigValues) Niterations = 1000 for iter in range(Niterations): @@ -1398,10 +1404,10 @@ $$ # the number of datapoints n = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) -X = np.c_[np.ones((m,1)), x] +X = np.c_[np.ones((n,1)), x] XT_X = X.T @ X #Ridge parameter lambda diff --git a/doc/pub/week39/html/week39-solarized.html b/doc/pub/week39/html/week39-solarized.html index aa063743c..c5b459f7c 100644 --- a/doc/pub/week39/html/week39-solarized.html +++ b/doc/pub/week39/html/week39-solarized.html @@ -1244,11 +1244,17 @@ x = 2*np.random.rand(n,4+3*x+np.random.randn(n,1) X = np.c_[np.ones((n,1)), x] +# Hessian matrix +H = (2.0/n)* X.T @ X +# Get the eigenvalues +EigValues, EigVectors = np.linalg.eig(H) +print(EigValues) + beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y print(beta_linreg) beta = np.random.randn(2,1) -eta = 0.1 +eta = 1.0/np.max(EigValues) Niterations = 1000 for iter in range(Niterations): @@ -1336,10 +1342,10 @@ $$ # the number of datapoints n = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) -X = np.c_[np.ones((m,1)), x] +X = np.c_[np.ones((n,1)), x] XT_X = X.T @ X #Ridge parameter lambda diff --git a/doc/pub/week39/html/week39.html b/doc/pub/week39/html/week39.html index 3eaef839d..2867f99c3 100644 --- a/doc/pub/week39/html/week39.html +++ b/doc/pub/week39/html/week39.html @@ -1249,11 +1249,17 @@ x = 2*np y = 4+3*x+np.random.randn(n,1) X = np.c_[np.ones((n,1)), x] +# Hessian matrix +H = (2.0/n)* X.T @ X +# Get the eigenvalues +EigValues, EigVectors = np.linalg.eig(H) +print(EigValues) + beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y print(beta_linreg) beta = np.random.randn(2,1) -eta = 0.1 +eta = 1.0/np.max(EigValues) Niterations = 1000 for iter in range(Niterations): @@ -1341,10 +1347,10 @@ $$ # the number of datapoints n = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) -X = np.c_[np.ones((m,1)), x] +X = np.c_[np.ones((n,1)), x] XT_X = X.T @ X #Ridge parameter lambda diff --git a/doc/pub/week39/ipynb/ipynb-week39-src.tar.gz b/doc/pub/week39/ipynb/ipynb-week39-src.tar.gz index 2892ce6b9..0ba446f7a 100644 Binary files a/doc/pub/week39/ipynb/ipynb-week39-src.tar.gz and b/doc/pub/week39/ipynb/ipynb-week39-src.tar.gz differ diff --git a/doc/pub/week39/ipynb/week39.ipynb b/doc/pub/week39/ipynb/week39.ipynb index 821149be2..ab8fd9e22 100644 --- a/doc/pub/week39/ipynb/week39.ipynb +++ b/doc/pub/week39/ipynb/week39.ipynb @@ -1452,11 +1452,17 @@ "y = 4+3*x+np.random.randn(n,1)\n", "\n", "X = np.c_[np.ones((n,1)), x]\n", + "# Hessian matrix\n", + "H = (2.0/n)* X.T @ X\n", + "# Get the eigenvalues\n", + "EigValues, EigVectors = np.linalg.eig(H)\n", + "print(EigValues)\n", + "\n", "beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y\n", "print(beta_linreg)\n", "beta = np.random.randn(2,1)\n", "\n", - "eta = 0.1\n", + "eta = 1.0/np.max(EigValues)\n", "Niterations = 1000\n", "\n", "for iter in range(Niterations):\n", @@ -1589,10 +1595,10 @@ "\n", "# the number of datapoints\n", "n = 100\n", - "x = 2*np.random.rand(m,1)\n", - "y = 4+3*x+np.random.randn(m,1)\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", + "X = np.c_[np.ones((n,1)), x]\n", "XT_X = X.T @ X\n", "\n", "#Ridge parameter lambda\n", diff --git a/doc/src/week39/week39.do.txt b/doc/src/week39/week39.do.txt index bc99fd2ec..17edab35d 100644 --- a/doc/src/week39/week39.do.txt +++ b/doc/src/week39/week39.do.txt @@ -876,11 +876,17 @@ x = 2*np.random.rand(n,1) y = 4+3*x+np.random.randn(n,1) X = np.c_[np.ones((n,1)), x] +# Hessian matrix +H = (2.0/n)* X.T @ X +# Get the eigenvalues +EigValues, EigVectors = np.linalg.eig(H) +print(EigValues) + beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y print(beta_linreg) beta = np.random.randn(2,1) -eta = 0.1 +eta = 1.0/np.max(EigValues) Niterations = 1000 for iter in range(Niterations): @@ -968,10 +974,10 @@ import sys # the number of datapoints n = 100 -x = 2*np.random.rand(m,1) -y = 4+3*x+np.random.randn(m,1) +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) -X = np.c_[np.ones((m,1)), x] +X = np.c_[np.ones((n,1)), x] XT_X = X.T @ X #Ridge parameter lambda