diff --git a/doc/pub/week39/html/week39-bs.html b/doc/pub/week39/html/week39-bs.html index c182b812c..875b934cb 100644 --- a/doc/pub/week39/html/week39-bs.html +++ b/doc/pub/week39/html/week39-bs.html @@ -1,11 +1,11 @@
- + @@ -41,74 +41,137 @@ Automatically generated HTML file from DocOnce source @@ -146,58 +209,58 @@ MathJax.Hub.Config({-
@@ -268,13 +331,13 @@ MathJax.Hub.Config({
-
-Reading suggestions for both days: Aurelien Geron's chapter 4 and Murphy sections 8.3 and 8.5 +See lecture notes for week 39. +For a good discussion on gradient methods, see Goodfellow et al section 4.3-4.5 and chapter 8. We will come back to the latter chapter in our discussion of Neural networks as well.
Almost every problem in machine learning and data science starts with
@@ -198,7 +197,7 @@ some approximative/numerical method to compute the minimum.
In our discussion on Logistic Regression we studied the
@@ -222,7 +221,7 @@ where \( \boldsymbol{\beta} \) are the weights we wish to extract from data, in
Our compact equations used a definition of a vector \( \boldsymbol{y} \) with \( n \)
@@ -252,7 +251,7 @@ This defines what is called the Hessian matrix.
If we can set up these equations, Newton-Raphson's iterative method is normally the method of choice. It requires however that we can compute in an efficient way the matrices that define the first and second derivatives.
@@ -282,7 +281,7 @@ If we can compute these matrices, in particular the Hessian, the above is often
Let us quickly remind ourselves how we derive the above method.
@@ -299,7 +298,7 @@ normally discourage the use of this method.
The Newton-Raphson formula consists geometrically of extending the
@@ -343,7 +342,7 @@ $$
The above is Newton-Raphson's method. It has a simple geometric
@@ -361,7 +360,7 @@ vanishes, then Newton-Raphson may fail totally
Newton's method can be generalized to systems of several non-linear equations
@@ -426,7 +425,7 @@ more than two non-linear equations. In our case, the Jacobian matrix is given by
The basic idea of gradient descent is
@@ -452,7 +451,7 @@ we are always moving towards smaller function values, i.e a minimum.
The previous observation is the basis of the method of steepest
@@ -473,7 +472,7 @@ the learning rate within the context of Machine Learning.
Ideally the sequence \( \{\mathbf{x}_k \}_{k=0} \) converges to a global
@@ -499,7 +498,7 @@ Note that the gradient is a function of \( \mathbf{x} =
The gradient descent method
@@ -518,7 +517,7 @@ randomness. One such method is that of Stochastic Gradient Descent
Ideally we want our cost/loss function to be convex(concave).
@@ -538,7 +537,7 @@ regular polygons (triangles, rectangles, pentagons, etc...).
Convex function: Let \( X \subset \mathbb{R}^n \) be a convex set. Assume that the function \( f: X \rightarrow \mathbb{R} \) is continuous, then \( f \) is said to be convex if
In the following we state first and second-order conditions which
@@ -558,7 +557,7 @@ details and proofs we refer to:
-First order condition.
+First order condition
Suppose \( f \) is differentiable (i.e \( \nabla f(x) \) is well defined for
all \( x \) in the domain of \( f \)). Then \( f \) is convex if and only if \( D_f \)
@@ -574,7 +573,7 @@ note that it is always below the graph.
Assume that \( f \) is twice
differentiable, i.e the Hessian matrix exists at each point in
@@ -590,7 +589,7 @@ This condition is particularly useful since it gives us an procedure for determi
The next result is of great importance to us and the reason why we are
@@ -606,7 +605,7 @@ is convex the following result provides invaluable information:
Consider the problem of finding \( x \in \mathbb{R}^n \) such that \( f(x) \)
is minimal, where \( f \) is convex and differentiable. Then, any point
@@ -619,7 +618,7 @@ This result means that if we know that the cost/loss function is convex and we a
-Video of Lecture and link to handwritten notes.
+
Before we proceed, we would like to discuss the approach called the
@@ -694,7 +690,7 @@ When we have found the exact solution, \( \boldsymbol{r}=0 \).
The residual is zero when we reach the minimum of the quadratic equation
@@ -713,7 +709,7 @@ symmetric. This defines also the Hessian and we want it to be positive definit
We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \).
@@ -740,7 +736,7 @@ instead.
@@ -773,7 +769,7 @@ and
@@ -825,12 +821,12 @@ $$
-
-
-
@@ -873,7 +869,7 @@ Run it!
-
-
@@ -928,7 +924,7 @@ this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s
@@ -947,7 +943,7 @@ which is zero unless \( i=j \).
@@ -977,7 +973,7 @@ $$
@@ -1014,7 +1010,7 @@ $$
@@ -1051,7 +1047,7 @@ instead.
@@ -1084,7 +1080,7 @@ hence the name conjugate gradient method.
@@ -1116,7 +1112,7 @@ $$
@@ -1161,7 +1157,7 @@ $$
We will use linear regression as a case study for the gradient descent
@@ -1181,7 +1177,7 @@ We revisit an example similar to what we had in the first homework set. We had a
-
@@ -1203,7 +1199,7 @@ $$
Let \( \mathbf{y} = (y_1,\cdots,y_n)^T \), \( \mathbf{\boldsymbol{y}} = (\boldsymbol{y}_1,\cdots,\boldsymbol{y}_n)^T \) and \( \beta = (\beta_0, \beta_1)^T \)
@@ -1232,7 +1228,7 @@ and we want to find \( \beta \) such that \( C(\beta) \) is minimized.
Computing \( \partial C(\beta) / \partial \beta_0 \) and \( \partial C(\beta) / \partial \beta_1 \) we can show that the gradient can be written as
@@ -1249,7 +1245,7 @@ where \( X \) is the design matrix defined above.
We can now write a program that minimizes \( C(\beta) \) using the gradient descent method with a constant learning rate \( \gamma \) according to
@@ -1287,14 +1283,14 @@ And finally we can compare our solution for \( \beta \) with the analytic result
Here our simple example
-
-
We have also discussed Ridge regression where the loss function contains a regularized term given by the \( L_2 \) norm of \( \beta \),
@@ -1401,11 +1397,11 @@ $$
-
Stochastic gradient descent (SGD) and variants thereof address some of
@@ -1487,7 +1483,7 @@ $$
This in turn means that the gradient can be
@@ -1509,7 +1505,7 @@ minibatches. We denote these minibatches by \( B_k \) where
Thus a gradient descent step now looks like
@@ -1556,12 +1552,12 @@ the number of minibatches, as exemplified in the code below.
-
A natural question is when do we stop the search for a new minimum?
@@ -1605,7 +1601,7 @@ gave the lowest value.
Another approach is to let the step length \( \gamma_j \) depend on the
@@ -1627,7 +1623,7 @@ function.
-
-
-
Overview Video, why do we care about gradient methods?
-
-Video of Lecture and link to handwritten notes.
-
Almost every problem in machine learning and data science starts with
@@ -213,7 +275,7 @@ some approximative/numerical method to compute the minimum.
In our discussion on Logistic Regression we studied the
@@ -235,7 +297,7 @@ where \( \boldsymbol{\beta} \) are the weights we wish to extract from data, in
Our compact equations used a definition of a vector \( \boldsymbol{y} \) with \( n \)
@@ -261,7 +323,7 @@ This defines what is called the Hessian matrix.
If we can set up these equations, Newton-Raphson's iterative method is normally the method of choice. It requires however that we can compute in an efficient way the matrices that define the first and second derivatives.
@@ -287,7 +349,7 @@ If we can compute these matrices, in particular the Hessian, the above is often
Let us quickly remind ourselves how we derive the above method.
@@ -304,7 +366,7 @@ normally discourage the use of this method.
The Newton-Raphson formula consists geometrically of extending the
@@ -340,7 +402,7 @@ $$
The above is Newton-Raphson's method. It has a simple geometric
@@ -358,7 +420,7 @@ vanishes, then Newton-Raphson may fail totally
Newton's method can be generalized to systems of several non-linear equations
@@ -413,7 +475,7 @@ more than two non-linear equations. In our case, the Jacobian matrix is given by
The basic idea of gradient descent is
@@ -437,7 +499,7 @@ we are always moving towards smaller function values, i.e a minimum.
-
The previous observation is the basis of the method of steepest
@@ -456,7 +518,7 @@ the learning rate within the context of Machine Learning.
-
Ideally the sequence \( \{\mathbf{x}_k \}_{k=0} \) converges to a global
@@ -482,7 +544,7 @@ Note that the gradient is a function of \( \mathbf{x} =
-
The gradient descent method
@@ -501,7 +563,7 @@ randomness. One such method is that of Stochastic Gradient Descent
-
Ideally we want our cost/loss function to be convex(concave).
@@ -521,7 +583,7 @@ regular polygons (triangles, rectangles, pentagons, etc...).
Convex function: Let \( X \subset \mathbb{R}^n \) be a convex set. Assume that the function \( f: X \rightarrow \mathbb{R} \) is continuous, then \( f \) is said to be convex if $$f(tx_1 + (1-t)x_2) \leq tf(x_1) + (1-t)f(x_2) $$ for all \( x_1, x_2 \in X \) and for all \( t \in [0,1] \). If \( \leq \) is replaced with a strict inequaltiy in the definition, we demand \( x_1 \neq x_2 \) and \( t\in(0,1) \) then \( f \) is said to be strictly convex. For a single variable function, convexity means that if you draw a straight line connecting \( f(x_1) \) and \( f(x_2) \), the value of the function on the interval \( [x_1,x_2] \) is always below the line as illustrated below.
@@ -529,7 +591,7 @@ regular polygons (triangles, rectangles, pentagons, etc...).
In the following we state first and second-order conditions which
@@ -539,7 +601,7 @@ details and proofs we refer to:
-First order condition.
+First order condition
Suppose \( f \) is differentiable (i.e \( \nabla f(x) \) is well defined for
all \( x \) in the domain of \( f \)). Then \( f \) is convex if and only if \( D_f \)
@@ -554,7 +616,7 @@ note that it is always below the graph.
Assume that \( f \) is twice
differentiable, i.e the Hessian matrix exists at each point in
@@ -571,7 +633,7 @@ This condition is particularly useful since it gives us an procedure for determi
The next result is of great importance to us and the reason why we are
@@ -587,7 +649,7 @@ is convex the following result provides invaluable information:
Consider the problem of finding \( x \in \mathbb{R}^n \) such that \( f(x) \)
is minimal, where \( f \) is convex and differentiable. Then, any point
@@ -601,7 +663,7 @@ This result means that if we know that the cost/loss function is convex and we a
-Video of Lecture and link to handwritten notes.
+
Before we proceed, we would like to discuss the approach called the
@@ -672,7 +731,7 @@ When we have found the exact solution, \( \boldsymbol{r}=0 \).
The residual is zero when we reach the minimum of the quadratic equation
@@ -689,7 +748,7 @@ symmetric. This defines also the Hessian and we want it to be positive definit
We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \).
@@ -712,7 +771,7 @@ instead.
@@ -742,7 +801,7 @@ and
@@ -785,12 +844,12 @@ $$
-
-
-
@@ -833,7 +892,7 @@ Run it!
-
-
@@ -884,7 +943,7 @@ this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s
@@ -902,7 +961,7 @@ which is zero unless \( i=j \).
@@ -929,7 +988,7 @@ $$
@@ -961,7 +1020,7 @@ $$
@@ -997,7 +1056,7 @@ instead.
@@ -1027,7 +1086,7 @@ hence the name conjugate gradient method.
@@ -1056,7 +1115,7 @@ $$
@@ -1094,7 +1153,7 @@ $$
-
We will use linear regression as a case study for the gradient descent
@@ -1113,7 +1172,7 @@ We revisit an example similar to what we had in the first homework set. We had a
-
@@ -1131,7 +1190,7 @@ $$
-
Let \( \mathbf{y} = (y_1,\cdots,y_n)^T \), \( \mathbf{\boldsymbol{y}} = (\boldsymbol{y}_1,\cdots,\boldsymbol{y}_n)^T \) and \( \beta = (\beta_0, \beta_1)^T \)
@@ -1156,7 +1215,7 @@ and we want to find \( \beta \) such that \( C(\beta) \) is minimized.
Computing \( \partial C(\beta) / \partial \beta_0 \) and \( \partial C(\beta) / \partial \beta_1 \) we can show that the gradient can be written as
@@ -1171,7 +1230,7 @@ where \( X \) is the design matrix defined above.
We can now write a program that minimizes \( C(\beta) \) using the gradient descent method with a constant learning rate \( \gamma \) according to
@@ -1205,14 +1264,14 @@ And finally we can compare our solution for \( \beta \) with the analytic result
Here our simple example
-
-
-
We have also discussed Ridge regression where the loss function contains a regularized term given by the \( L_2 \) norm of \( \beta \),
@@ -1311,11 +1370,11 @@ $$
-
Stochastic gradient descent (SGD) and variants thereof address some of
@@ -1393,7 +1452,7 @@ $$
This in turn means that the gradient can be
@@ -1413,7 +1472,7 @@ minibatches. We denote these minibatches by \( B_k \) where
Thus a gradient descent step now looks like
@@ -1456,12 +1515,12 @@ the number of minibatches, as exemplified in the code below.
-
A natural question is when do we stop the search for a new minimum?
@@ -1505,7 +1564,7 @@ gave the lowest value.
Another approach is to let the step length \( \gamma_j \) depend on the
@@ -1525,7 +1584,7 @@ function.
-
-
-
Overview Video, why do we care about gradient methods?
-
-Video of Lecture and link to handwritten notes.
-
Almost every problem in machine learning and data science starts with
@@ -218,7 +280,7 @@ some approximative/numerical method to compute the minimum.
In our discussion on Logistic Regression we studied the
@@ -240,7 +302,7 @@ where \( \boldsymbol{\beta} \) are the weights we wish to extract from data, in
Our compact equations used a definition of a vector \( \boldsymbol{y} \) with \( n \)
@@ -266,7 +328,7 @@ This defines what is called the Hessian matrix.
If we can set up these equations, Newton-Raphson's iterative method is normally the method of choice. It requires however that we can compute in an efficient way the matrices that define the first and second derivatives.
@@ -292,7 +354,7 @@ If we can compute these matrices, in particular the Hessian, the above is often
Let us quickly remind ourselves how we derive the above method.
@@ -309,7 +371,7 @@ normally discourage the use of this method.
The Newton-Raphson formula consists geometrically of extending the
@@ -345,7 +407,7 @@ $$
The above is Newton-Raphson's method. It has a simple geometric
@@ -363,7 +425,7 @@ vanishes, then Newton-Raphson may fail totally
Newton's method can be generalized to systems of several non-linear equations
@@ -418,7 +480,7 @@ more than two non-linear equations. In our case, the Jacobian matrix is given by
The basic idea of gradient descent is
@@ -442,7 +504,7 @@ we are always moving towards smaller function values, i.e a minimum.
-
The previous observation is the basis of the method of steepest
@@ -461,7 +523,7 @@ the learning rate within the context of Machine Learning.
-
Ideally the sequence \( \{\mathbf{x}_k \}_{k=0} \) converges to a global
@@ -487,7 +549,7 @@ Note that the gradient is a function of \( \mathbf{x} =
-
The gradient descent method
@@ -506,7 +568,7 @@ randomness. One such method is that of Stochastic Gradient Descent
-
Ideally we want our cost/loss function to be convex(concave).
@@ -526,7 +588,7 @@ regular polygons (triangles, rectangles, pentagons, etc...).
Convex function: Let \( X \subset \mathbb{R}^n \) be a convex set. Assume that the function \( f: X \rightarrow \mathbb{R} \) is continuous, then \( f \) is said to be convex if $$f(tx_1 + (1-t)x_2) \leq tf(x_1) + (1-t)f(x_2) $$ for all \( x_1, x_2 \in X \) and for all \( t \in [0,1] \). If \( \leq \) is replaced with a strict inequaltiy in the definition, we demand \( x_1 \neq x_2 \) and \( t\in(0,1) \) then \( f \) is said to be strictly convex. For a single variable function, convexity means that if you draw a straight line connecting \( f(x_1) \) and \( f(x_2) \), the value of the function on the interval \( [x_1,x_2] \) is always below the line as illustrated below.
@@ -534,7 +596,7 @@ regular polygons (triangles, rectangles, pentagons, etc...).
In the following we state first and second-order conditions which
@@ -544,7 +606,7 @@ details and proofs we refer to:
-First order condition.
+First order condition
Suppose \( f \) is differentiable (i.e \( \nabla f(x) \) is well defined for
all \( x \) in the domain of \( f \)). Then \( f \) is convex if and only if \( D_f \)
@@ -559,7 +621,7 @@ note that it is always below the graph.
Assume that \( f \) is twice
differentiable, i.e the Hessian matrix exists at each point in
@@ -576,7 +638,7 @@ This condition is particularly useful since it gives us an procedure for determi
The next result is of great importance to us and the reason why we are
@@ -592,7 +654,7 @@ is convex the following result provides invaluable information:
Consider the problem of finding \( x \in \mathbb{R}^n \) such that \( f(x) \)
is minimal, where \( f \) is convex and differentiable. Then, any point
@@ -606,7 +668,7 @@ This result means that if we know that the cost/loss function is convex and we a
-Video of Lecture and link to handwritten notes.
+
Before we proceed, we would like to discuss the approach called the
@@ -677,7 +736,7 @@ When we have found the exact solution, \( \boldsymbol{r}=0 \).
The residual is zero when we reach the minimum of the quadratic equation
@@ -694,7 +753,7 @@ symmetric. This defines also the Hessian and we want it to be positive definit
We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \).
@@ -717,7 +776,7 @@ instead.
@@ -747,7 +806,7 @@ and
@@ -790,12 +849,12 @@ $$
-
-
-
@@ -838,7 +897,7 @@ Run it!
-
-
@@ -889,7 +948,7 @@ this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s
@@ -907,7 +966,7 @@ which is zero unless \( i=j \).
@@ -934,7 +993,7 @@ $$
@@ -966,7 +1025,7 @@ $$
@@ -1002,7 +1061,7 @@ instead.
@@ -1032,7 +1091,7 @@ hence the name conjugate gradient method.
@@ -1061,7 +1120,7 @@ $$
@@ -1099,7 +1158,7 @@ $$
-
We will use linear regression as a case study for the gradient descent
@@ -1118,7 +1177,7 @@ We revisit an example similar to what we had in the first homework set. We had a
-
@@ -1136,7 +1195,7 @@ $$
-
Let \( \mathbf{y} = (y_1,\cdots,y_n)^T \), \( \mathbf{\boldsymbol{y}} = (\boldsymbol{y}_1,\cdots,\boldsymbol{y}_n)^T \) and \( \beta = (\beta_0, \beta_1)^T \)
@@ -1161,7 +1220,7 @@ and we want to find \( \beta \) such that \( C(\beta) \) is minimized.
Computing \( \partial C(\beta) / \partial \beta_0 \) and \( \partial C(\beta) / \partial \beta_1 \) we can show that the gradient can be written as
@@ -1176,7 +1235,7 @@ where \( X \) is the design matrix defined above.
We can now write a program that minimizes \( C(\beta) \) using the gradient descent method with a constant learning rate \( \gamma \) according to
@@ -1210,14 +1269,14 @@ And finally we can compare our solution for \( \beta \) with the analytic result
Here our simple example
-
-
-
We have also discussed Ridge regression where the loss function contains a regularized term given by the \( L_2 \) norm of \( \beta \),
@@ -1316,11 +1375,11 @@ $$
-
Stochastic gradient descent (SGD) and variants thereof address some of
@@ -1398,7 +1457,7 @@ $$
This in turn means that the gradient can be
@@ -1418,7 +1477,7 @@ minibatches. We denote these minibatches by \( B_k \) where
Thus a gradient descent step now looks like
@@ -1461,12 +1520,12 @@ the number of minibatches, as exemplified in the code below.
-
A natural question is when do we stop the search for a new minimum?
@@ -1510,7 +1569,7 @@ gave the lowest value.
Another approach is to let the step length \( \gamma_j \) depend on the
@@ -1530,7 +1589,7 @@ function.
-Revisiting our Logistic Regression case
+Revisiting our Logistic Regression case
The equations to solve
+The equations to solve
Solving using Newton-Raphson's method
+Solving using Newton-Raphson's method
Brief reminder on Newton-Raphson's method
+Brief reminder on Newton-Raphson's method
The equations
+The equations
Simple geometric interpretation
+Simple geometric interpretation
Extending to more than one variable
+Extending to more than one variable
Steepest descent
+Steepest descent
More on Steepest descent
+More on Steepest descent
The ideal
+The ideal
The sensitiveness of the gradient descent
+The sensitiveness of the gradient descent
Convex functions
+Convex functions
Convex function
+Convex function
@@ -548,7 +547,7 @@ $$f(tx_1 + (1-t)x_2) \leq tf(x_1) + (1-t)f(x_2) $$
Conditions on convex functions
+Conditions on convex functions
More on convex functions
+More on convex functions
Some simple problems
+Some simple problems
Friday September 25
-
-Friday October 1
Standard steepest descent
+Standard steepest descent
Gradient method
+Gradient method
Steepest descent method
+Steepest descent method
Steepest descent method
+Steepest descent method
Final expressions
+Final expressions
Steepest descent example
+Steepest descent example
import numpy as np
+
import numpy as np
import numpy.linalg as la
import scipy.optimize as sopt
@@ -856,7 +852,7 @@ And then as countor plot
pt.axis("equal")
+
pt.axis("equal")
pt.contour(xmesh, ymesh, fmesh)
guesses = [np.array([2, 2./5])]
x = guesses[-1]
+
x = guesses[-1]
s = -df(x)
def f1d(alpha):
+
def f1d(alpha):
return f(x + alpha*s)
alpha_opt = sopt.golden(f1d)
@@ -886,7 +882,7 @@ What happened?
pt.axis("equal")
+
pt.axis("equal")
pt.contour(xmesh, ymesh, fmesh, 50)
it_array = np.array(guesses)
pt.plot(it_array.T[0], it_array.T[1], "x-")
@@ -895,7 +891,7 @@ pt.plot(it_array.T[0], it_array.T[
-
Conjugate gradient method
+Conjugate gradient method
Conjugate gradient method
+Conjugate gradient method
Conjugate gradient method
+Conjugate gradient method
Conjugate gradient method
+Conjugate gradient method
Conjugate gradient method and iterations
+Conjugate gradient method and iterations
Conjugate gradient method
+Conjugate gradient method
Conjugate gradient method
+Conjugate gradient method
Conjugate gradient method
+Conjugate gradient method
Revisiting our first homework
+Revisiting our first homework
x = 2*np.random.rand(m,1)
+
x = 2*np.random.rand(m,1)
y = 4+3*x+np.random.randn(m,1)
Gradient descent example
+Gradient descent example
The derivative of the cost/loss function
+The derivative of the cost/loss function
The Hessian matrix
+The Hessian matrix
The Hessian matrix of \( C(\beta) \) is given by
$$
@@ -1265,7 +1261,7 @@ This result implies that \( C(\beta) \) is a convex function since the matrix \(
Simple program
+Simple program
Gradient Descent Example
+Gradient Descent Example
# Importing various packages
+
# Importing various packages
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
@@ -1344,12 +1340,12 @@ plt.show()
And a corresponding example using scikit-learn
+And a corresponding example using scikit-learn
# Importing various packages
+
# Importing various packages
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
@@ -1370,7 +1366,7 @@ sgdreg.fit(x,y.ravel())
Gradient descent and Ridge
+Gradient descent and Ridge
Program example for gradient descent with Ridge Regression
+Program example for gradient descent with Ridge Regression
from random import random, seed
+
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
@@ -1453,7 +1449,7 @@ plt.show()
Using gradient descent methods, limitations
+Using gradient descent methods, limitations
Stochastic Gradient Descent
+Stochastic Gradient Descent
Computation of gradients
+Computation of gradients
SGD example
+SGD example
As an example, suppose we have \( 10 \) data points \( (\mathbf{x}_1,\cdots, \mathbf{x}_{10}) \)
and we choose to have \( M=5 \) minibathces,
then each minibatch contains two data points. In particular we have
@@ -1535,7 +1531,7 @@ $$
The gradient step
+The gradient step
Simple example code
+Simple example code
import numpy as np
+
import numpy as np
n = 100 #100 datapoints
M = 5 #size of each minibatch
@@ -1588,7 +1584,7 @@ all \( n \) datapoints.
When do we stop?
+When do we stop?
Slightly different approach
+Slightly different approach
import numpy as np
+
import numpy as np
def step_length(t,t0,t1):
return t0/(t+t1)
@@ -1656,12 +1652,12 @@ j = 0
Program for stochastic gradient
+Program for stochastic gradient
# Importing various packages
+
# Importing various packages
from math import exp, sqrt
from random import random, seed
import numpy as np
diff --git a/doc/pub/week39/html/week39-solarized.html b/doc/pub/week39/html/week39-solarized.html
index 9ca6c0da4..74c599f9d 100644
--- a/doc/pub/week39/html/week39-solarized.html
+++ b/doc/pub/week39/html/week39-solarized.html
@@ -1,19 +1,19 @@
-
+
Sep 29, 2020
Sep 25, 2021
-Plan for week 39
+Plan for week 39
-Reading suggestions for both days: Aurelien Geron's chapter 4 and Murphy sections 8.3 and 8.5
+See lecture notes for week 39.
+For a good discussion on gradient methods, see Goodfellow et al section 4.3-4.5 and chapter 8. We will come back to the latter chapter in our discussion of Neural networks as well.
-Thursday September 24
+Thursday September 30
-Optimization, the central part of any Machine Learning algortithm
+Optimization, the central part of any Machine Learning algortithm
-Revisiting our Logistic Regression case
+Revisiting our Logistic Regression case
-The equations to solve
+The equations to solve
-Solving using Newton-Raphson's method
+Solving using Newton-Raphson's method
-Brief reminder on Newton-Raphson's method
+Brief reminder on Newton-Raphson's method
-The equations
+The equations
-Simple geometric interpretation
+Simple geometric interpretation
-Extending to more than one variable
+Extending to more than one variable
-Steepest descent
+Steepest descent
More on Steepest descent
+More on Steepest descent
The ideal
+The ideal
The sensitiveness of the gradient descent
+The sensitiveness of the gradient descent
Convex functions
+Convex functions
-Convex function
+Convex function
-Conditions on convex functions
+Conditions on convex functions
-More on convex functions
+More on convex functions
-Some simple problems
+Some simple problems
-Friday September 25
-
-Friday October 1
-Standard steepest descent
+Standard steepest descent
-Gradient method
+Gradient method
-Steepest descent method
+Steepest descent method
-Steepest descent method
+Steepest descent method
-Final expressions
+Final expressions
-Steepest descent example
+Steepest descent example
import numpy as np
+
import numpy as np
import numpy.linalg as la
import scipy.optimize as sopt
@@ -816,7 +875,7 @@ And then as countor plot
pt.axis("equal")
+
pt.axis("equal")
pt.contour(xmesh, ymesh, fmesh)
guesses = [np.array([2, 2./5])]
x = guesses[-1]
+
x = guesses[-1]
s = -df(x)
def f1d(alpha):
+
def f1d(alpha):
return f(x + alpha*s)
alpha_opt = sopt.golden(f1d)
@@ -846,7 +905,7 @@ What happened?
pt.axis("equal")
+
pt.axis("equal")
pt.contour(xmesh, ymesh, fmesh, 50)
it_array = np.array(guesses)
pt.plot(it_array.T[0], it_array.T[1], "x-")
@@ -854,7 +913,7 @@ pt.plot(it_array.T[0], it_array.T[
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method and iterations
+Conjugate gradient method and iterations
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
Revisiting our first homework
+Revisiting our first homework
x = 2*np.random.rand(m,1)
+
x = 2*np.random.rand(m,1)
y = 4+3*x+np.random.randn(m,1)
Gradient descent example
+Gradient descent example
-The derivative of the cost/loss function
+The derivative of the cost/loss function
-The Hessian matrix
+The Hessian matrix
The Hessian matrix of \( C(\beta) \) is given by
$$
\boldsymbol{H} \equiv \begin{bmatrix}
@@ -1185,7 +1244,7 @@ This result implies that \( C(\beta) \) is a convex function since the matrix \(
-Simple program
+Simple program
-Gradient Descent Example
+Gradient Descent Example
# Importing various packages
+
# Importing various packages
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
@@ -1261,12 +1320,12 @@ plt.show()
-And a corresponding example using scikit-learn
+And a corresponding example using scikit-learn
# Importing various packages
+
# Importing various packages
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
@@ -1286,7 +1345,7 @@ sgdreg.fit(x,y.ravel())
Gradient descent and Ridge
+Gradient descent and Ridge
-Program example for gradient descent with Ridge Regression
+Program example for gradient descent with Ridge Regression
from random import random, seed
+
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
@@ -1362,7 +1421,7 @@ plt.show()
-Using gradient descent methods, limitations
+Using gradient descent methods, limitations
-Stochastic Gradient Descent
+Stochastic Gradient Descent
-Computation of gradients
+Computation of gradients
-SGD example
+SGD example
As an example, suppose we have \( 10 \) data points \( (\mathbf{x}_1,\cdots, \mathbf{x}_{10}) \)
and we choose to have \( M=5 \) minibathces,
then each minibatch contains two data points. In particular we have
@@ -1437,7 +1496,7 @@ $$
-The gradient step
+The gradient step
-Simple example code
+Simple example code
import numpy as np
+
import numpy as np
n = 100 #100 datapoints
M = 5 #size of each minibatch
@@ -1488,7 +1547,7 @@ all \( n \) datapoints.
-When do we stop?
+When do we stop?
-Slightly different approach
+Slightly different approach
import numpy as np
+
import numpy as np
def step_length(t,t0,t1):
return t0/(t+t1)
@@ -1553,12 +1612,12 @@ j = 0
-Program for stochastic gradient
+Program for stochastic gradient
# Importing various packages
+
# Importing various packages
from math import exp, sqrt
from random import random, seed
import numpy as np
@@ -1632,7 +1691,7 @@ plt.show()
Sep 29, 2020
Sep 25, 2021
-Plan for week 39
+Plan for week 39
-Reading suggestions for both days: Aurelien Geron's chapter 4 and Murphy sections 8.3 and 8.5
+See lecture notes for week 39.
+For a good discussion on gradient methods, see Goodfellow et al section 4.3-4.5 and chapter 8. We will come back to the latter chapter in our discussion of Neural networks as well.
-Thursday September 24
+Thursday September 30
-Optimization, the central part of any Machine Learning algortithm
+Optimization, the central part of any Machine Learning algortithm
-Revisiting our Logistic Regression case
+Revisiting our Logistic Regression case
-The equations to solve
+The equations to solve
-Solving using Newton-Raphson's method
+Solving using Newton-Raphson's method
-Brief reminder on Newton-Raphson's method
+Brief reminder on Newton-Raphson's method
-The equations
+The equations
-Simple geometric interpretation
+Simple geometric interpretation
-Extending to more than one variable
+Extending to more than one variable
-Steepest descent
+Steepest descent
More on Steepest descent
+More on Steepest descent
The ideal
+The ideal
The sensitiveness of the gradient descent
+The sensitiveness of the gradient descent
Convex functions
+Convex functions
-Convex function
+Convex function
-Conditions on convex functions
+Conditions on convex functions
-More on convex functions
+More on convex functions
-Some simple problems
+Some simple problems
-Friday September 25
-
-Friday October 1
-Standard steepest descent
+Standard steepest descent
-Gradient method
+Gradient method
-Steepest descent method
+Steepest descent method
-Steepest descent method
+Steepest descent method
-Final expressions
+Final expressions
-Steepest descent example
+Steepest descent example
import numpy as np
+
import numpy as np
import numpy.linalg as la
import scipy.optimize as sopt
@@ -821,7 +880,7 @@ And then as countor plot
pt.axis("equal")
+
pt.axis("equal")
pt.contour(xmesh, ymesh, fmesh)
guesses = [np.array([2, 2./5])]
x = guesses[-1]
+
x = guesses[-1]
s = -df(x)
def f1d(alpha):
+
def f1d(alpha):
return f(x + alpha*s)
alpha_opt = sopt.golden(f1d)
@@ -851,7 +910,7 @@ What happened?
pt.axis("equal")
+
pt.axis("equal")
pt.contour(xmesh, ymesh, fmesh, 50)
it_array = np.array(guesses)
pt.plot(it_array.T[0], it_array.T[1], "x-")
@@ -859,7 +918,7 @@ pt.plot(it_array
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method and iterations
+Conjugate gradient method and iterations
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
-Conjugate gradient method
+Conjugate gradient method
Revisiting our first homework
+Revisiting our first homework
x = 2*np.random.rand(m,1)
+
x = 2*np.random.rand(m,1)
y = 4+3*x+np.random.randn(m,1)
Gradient descent example
+Gradient descent example
-The derivative of the cost/loss function
+The derivative of the cost/loss function
-The Hessian matrix
+The Hessian matrix
The Hessian matrix of \( C(\beta) \) is given by
$$
\boldsymbol{H} \equiv \begin{bmatrix}
@@ -1190,7 +1249,7 @@ This result implies that \( C(\beta) \) is a convex function since the matrix \(
-Simple program
+Simple program
-Gradient Descent Example
+Gradient Descent Example
# Importing various packages
+
# Importing various packages
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
@@ -1266,12 +1325,12 @@ plt.show()
-And a corresponding example using scikit-learn
+And a corresponding example using scikit-learn
# Importing various packages
+
# Importing various packages
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
@@ -1291,7 +1350,7 @@ sgdreg.fit(x,y.
Gradient descent and Ridge
+Gradient descent and Ridge
-Program example for gradient descent with Ridge Regression
+Program example for gradient descent with Ridge Regression
from random import random, seed
+
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
@@ -1367,7 +1426,7 @@ plt.show()
-Using gradient descent methods, limitations
+Using gradient descent methods, limitations
-Stochastic Gradient Descent
+Stochastic Gradient Descent
-Computation of gradients
+Computation of gradients
-SGD example
+SGD example
As an example, suppose we have \( 10 \) data points \( (\mathbf{x}_1,\cdots, \mathbf{x}_{10}) \)
and we choose to have \( M=5 \) minibathces,
then each minibatch contains two data points. In particular we have
@@ -1442,7 +1501,7 @@ $$
-The gradient step
+The gradient step
-Simple example code
+Simple example code
import numpy as np
+
import numpy as np
n = 100 #100 datapoints
M = 5 #size of each minibatch
@@ -1493,7 +1552,7 @@ all \( n \) datapoints.
-When do we stop?
+When do we stop?
-Slightly different approach
+Slightly different approach