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({ @@ -232,7 +295,7 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

-

Sep 29, 2020

+

Sep 25, 2021


@@ -268,13 +331,13 @@ MathJax.Hub.Config({

- © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
diff --git a/doc/pub/week39/html/week39-reveal.html b/doc/pub/week39/html/week39-reveal.html index ccb9a33c1..2797742cb 100644 --- a/doc/pub/week39/html/week39-reveal.html +++ b/doc/pub/week39/html/week39-reveal.html @@ -1,7 +1,7 @@ - + @@ -13,7 +13,7 @@ - + @@ -76,10 +76,10 @@ document.getElementsByTagName( 'head' )[0].appendChild( link ); .reveal .alert-block > p, .alert-block > ul {margin-bottom:1em} /*.reveal .alert li {margin-top: 1em}*/ .reveal .alert-block p+p {margin-top:5px} - /*.reveal .alert-notice { background-image: url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_notice.png); } - .reveal .alert-summary { background-image:url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_summary.png); } - .reveal .alert-warning { background-image: url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_warning.png); } - .reveal .alert-question {background-image:url(http://hplgit.github.io/doconce/bundled/html_images/small_gray_question.png); } */ + /*.reveal .alert-notice { background-image: url(https://hplgit.github.io/doconce/bundled/html_images/small_gray_notice.png); } + .reveal .alert-summary { background-image:url(https://hplgit.github.io/doconce/bundled/html_images/small_gray_summary.png); } + .reveal .alert-warning { background-image: url(https://hplgit.github.io/doconce/bundled/html_images/small_gray_warning.png); } + .reveal .alert-question {background-image:url(https://hplgit.github.io/doconce/bundled/html_images/small_gray_question.png); } */ @@ -148,42 +148,41 @@ MathJax.Hub.Config({
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

 
-

Sep 29, 2020

+

Sep 25, 2021


- © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
-

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

Overview Video, why do we care about gradient methods? - -

-Video of Lecture and link to handwritten notes.

-

Optimization, the central part of any Machine Learning algortithm

+

Optimization, the central part of any Machine Learning algortithm

Almost every problem in machine learning and data science starts with @@ -198,7 +197,7 @@ some approximative/numerical method to compute the minimum.

-

Revisiting our Logistic Regression case

+

Revisiting our Logistic Regression case

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

-

The equations to solve

+

The equations to solve

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.

-

Solving using Newton-Raphson's method

+

Solving using Newton-Raphson's method

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

-

Brief reminder on Newton-Raphson's method

+

Brief reminder on Newton-Raphson's method

Let us quickly remind ourselves how we derive the above method. @@ -299,7 +298,7 @@ normally discourage the use of this method.

-

The equations

+

The equations

The Newton-Raphson formula consists geometrically of extending the @@ -343,7 +342,7 @@ $$

-

Simple geometric interpretation

+

Simple geometric interpretation

The above is Newton-Raphson's method. It has a simple geometric @@ -361,7 +360,7 @@ vanishes, then Newton-Raphson may fail totally

-

Extending to more than one variable

+

Extending to more than one variable

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

-

Steepest descent

+

Steepest descent

The basic idea of gradient descent is @@ -452,7 +451,7 @@ we are always moving towards smaller function values, i.e a minimum.

-

More on Steepest descent

+

More on Steepest descent

The previous observation is the basis of the method of steepest @@ -473,7 +472,7 @@ the learning rate within the context of Machine Learning.

-

The ideal

+

The ideal

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 sensitiveness of the gradient descent

+

The sensitiveness of the gradient descent

The gradient descent method @@ -518,7 +517,7 @@ randomness. One such method is that of Stochastic Gradient Descent

-

Convex functions

+

Convex functions

Ideally we want our cost/loss function to be convex(concave). @@ -538,7 +537,7 @@ regular polygons (triangles, rectangles, pentagons, etc...).

-

Convex function

+

Convex function

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

 
@@ -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

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.

-Second order condition. +Second order condition

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

-

More on convex functions

+

More on convex functions

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:

-Any minimum is global for convex functions. +Any minimum is global for convex functions

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

-

Some simple problems

+

Some simple problems

  1. Show that \( f(x)=x^2 \) is convex for \( x \in \mathbb{R} \) using the definition of convexity. Hint: If you re-write the definition, \( f \) is convex if the following holds for all \( x,y \in D_f \) and any \( \lambda \in [0,1] \) $\lambda f(x)+(1-\lambda)f(y)-f(\lambda x + (1-\lambda) y ) \geq 0$.
  2. @@ -646,15 +645,12 @@ Using the definition of convexity, try to show that a function satisfying the pr
    -

    Friday September 25

    - -

    -Video of Lecture and link to handwritten notes. +

    Friday October 1

    -

    Standard steepest descent

    +

    Standard steepest descent

    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 \).

    -

    Gradient method

    +

    Gradient method

    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

    -

    Steepest descent method

    +

    Steepest descent method

    We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). @@ -740,7 +736,7 @@ instead.

    -

    Steepest descent method

    +

    Steepest descent method

    @@ -773,7 +769,7 @@ and

    -

    Final expressions

    +

    Final expressions

    @@ -825,12 +821,12 @@ $$

    -

    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])]
     
    @@ -865,7 +861,7 @@ Find guesses

    -

    x = guesses[-1]
    +
    x = guesses[-1]
     s = -df(x)
     

    @@ -873,7 +869,7 @@ Run it!

    -

    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

    @@ -928,7 +924,7 @@ this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s

    -

    Conjugate gradient method

    +

    Conjugate gradient method

    @@ -947,7 +943,7 @@ which is zero unless \( i=j \).

    -

    Conjugate gradient method

    +

    Conjugate gradient method

    @@ -977,7 +973,7 @@ $$

    -

    Conjugate gradient method

    +

    Conjugate gradient method

    @@ -1014,7 +1010,7 @@ $$

    -

    Conjugate gradient method and iterations

    +

    Conjugate gradient method and iterations

    @@ -1051,7 +1047,7 @@ instead.

    -

    Conjugate gradient method

    +

    Conjugate gradient method

    @@ -1084,7 +1080,7 @@ hence the name conjugate gradient method.

    -

    Conjugate gradient method

    +

    Conjugate gradient method

    @@ -1116,7 +1112,7 @@ $$

    -

    Conjugate gradient method

    +

    Conjugate gradient method

    @@ -1161,7 +1157,7 @@ $$

    -

    Revisiting our first homework

    +

    Revisiting our first homework

    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

    -

    x = 2*np.random.rand(m,1)
    +
    x = 2*np.random.rand(m,1)
     y = 4+3*x+np.random.randn(m,1)
     

    @@ -1203,7 +1199,7 @@ $$

    -

    Gradient descent example

    +

    Gradient descent example

    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.

    -

    The derivative of the cost/loss function

    +

    The derivative of the cost/loss function

    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.

    -

    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

    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

    -

    Gradient Descent Example

    +

    Gradient Descent Example

    Here our simple 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

    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 @@ $$

    -

    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

    • Gradient descent (GD) finds local minima of our function. Since the GD algorithm is deterministic, if it converges, it will converge to a local minimum of our cost/loss/risk function. Because in ML we are often dealing with extremely rugged landscapes with many local minima, this can lead to poor performance.
    • @@ -1467,7 +1463,7 @@ plt.show()
      -

      Stochastic Gradient Descent

      +

      Stochastic Gradient Descent

      Stochastic gradient descent (SGD) and variants thereof address some of @@ -1487,7 +1483,7 @@ $$

      -

      Computation of gradients

      +

      Computation of gradients

      This in turn means that the gradient can be @@ -1509,7 +1505,7 @@ minibatches. We denote these minibatches by \( B_k \) where

      -

      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

      Thus a gradient descent step now looks like @@ -1556,12 +1552,12 @@ the number of minibatches, as exemplified in the code below.

      -

      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?

      A natural question is when do we stop the search for a new minimum? @@ -1605,7 +1601,7 @@ gave the lowest value.

      -

      Slightly different approach

      +

      Slightly different approach

      Another approach is to let the step length \( \gamma_j \) depend on the @@ -1627,7 +1623,7 @@ function.

      -

      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 @@
       
       
       
       
      -
      +
       
       
       
       Week 39: Optimization and  Gradient Methods
       
       
      -
      -
      +
      +
       
       
       
      @@ -48,10 +48,10 @@ pre {
       .alert-block > p, .alert-block > ul {margin-bottom:1em}
       .alert li {margin-top: 1em}
       .alert-block p+p {margin-top:5px}
      -.alert-notice { background-image: url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_yellow_notice.png); }
      -.alert-summary  { background-image:url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_yellow_summary.png); }
      -.alert-warning { background-image: url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_yellow_warning.png); }
      -.alert-question {background-image:url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_yellow_question.png); }
      +.alert-notice { background-image: url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_yellow_notice.png); }
      +.alert-summary  { background-image:url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_yellow_summary.png); }
      +.alert-warning { background-image: url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_yellow_warning.png); }
      +.alert-question {background-image:url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_yellow_question.png); }
       
       div { text-align: justify; text-justify: inter-word; }
       
      @@ -61,74 +61,137 @@ div { text-align: justify; text-justify: inter-word; }
       
       
       
       
      @@ -170,35 +233,34 @@ MathJax.Hub.Config({
       
      [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

      -

      Sep 29, 2020

      +

      Sep 25, 2021












      -

      Plan for week 39

      +

      Plan for week 39

      • Thursday: Repetition of Logistic regression equations and discussion of Gradient methods
      • Friday: Stochastic Gradient descent with examples and automatic differeantion
      • +
      • Reading recommendations:
      -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

      Overview Video, why do we care about gradient methods? -

      -Video of Lecture and link to handwritten notes. -











      -

      Optimization, the central part of any Machine Learning algortithm

      +

      Optimization, the central part of any Machine Learning algortithm

      Almost every problem in machine learning and data science starts with @@ -213,7 +275,7 @@ some approximative/numerical method to compute the minimum.











      -

      Revisiting our Logistic Regression case

      +

      Revisiting our Logistic Regression case

      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











      -

      The equations to solve

      +

      The equations to solve

      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.











      -

      Solving using Newton-Raphson's method

      +

      Solving using Newton-Raphson's method

      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











      -

      Brief reminder on Newton-Raphson's method

      +

      Brief reminder on Newton-Raphson's method

      Let us quickly remind ourselves how we derive the above method. @@ -304,7 +366,7 @@ normally discourage the use of this method.











      -

      The equations

      +

      The equations

      The Newton-Raphson formula consists geometrically of extending the @@ -340,7 +402,7 @@ $$











      -

      Simple geometric interpretation

      +

      Simple geometric interpretation

      The above is Newton-Raphson's method. It has a simple geometric @@ -358,7 +420,7 @@ vanishes, then Newton-Raphson may fail totally











      -

      Extending to more than one variable

      +

      Extending to more than one variable

      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











      -

      Steepest descent

      +

      Steepest descent

      The basic idea of gradient descent is @@ -437,7 +499,7 @@ we are always moving towards smaller function values, i.e a minimum.

      -

      More on Steepest descent

      +

      More on Steepest descent

      The previous observation is the basis of the method of steepest @@ -456,7 +518,7 @@ the learning rate within the context of Machine Learning.

      -

      The ideal

      +

      The ideal

      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 sensitiveness of the gradient descent

      +

      The sensitiveness of the gradient descent

      The gradient descent method @@ -501,7 +563,7 @@ randomness. One such method is that of Stochastic Gradient Descent

      -

      Convex functions

      +

      Convex functions

      Ideally we want our cost/loss function to be convex(concave). @@ -521,7 +583,7 @@ regular polygons (triangles, rectangles, pentagons, etc...).











      -

      Convex function

      +

      Convex function

      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...).











      -

      Conditions on convex functions

      +

      Conditions on convex functions

      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.

      -Second order condition. +Second order condition

      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











      -

      More on convex functions

      +

      More on convex functions

      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:

      -Any minimum is global for convex functions. +Any minimum is global for convex functions

      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











      -

      Some simple problems

      +

      Some simple problems

      1. Show that \( f(x)=x^2 \) is convex for \( x \in \mathbb{R} \) using the definition of convexity. Hint: If you re-write the definition, \( f \) is convex if the following holds for all \( x,y \in D_f \) and any \( \lambda \in [0,1] \) $\lambda f(x)+(1-\lambda)f(y)-f(\lambda x + (1-\lambda) y ) \geq 0$.
      2. @@ -628,15 +690,12 @@ Using the definition of convexity, try to show that a function satisfying the pr











        -

        Friday September 25

        - -

        -Video of Lecture and link to handwritten notes. +

        Friday October 1











        -

        Standard steepest descent

        +

        Standard steepest descent

        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 \).











        -

        Gradient method

        +

        Gradient method

        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











        -

        Steepest descent method

        +

        Steepest descent method

        We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). @@ -712,7 +771,7 @@ instead.











        -

        Steepest descent method

        +

        Steepest descent method

        @@ -742,7 +801,7 @@ and











        -

        Final expressions

        +

        Final expressions

        @@ -785,12 +844,12 @@ $$











        -

        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])]
         
        @@ -825,7 +884,7 @@ Find guesses

        -

        x = guesses[-1]
        +
        x = guesses[-1]
         s = -df(x)
         

        @@ -833,7 +892,7 @@ Run it!

        -

        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

        @@ -884,7 +943,7 @@ this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s











        -

        Conjugate gradient method

        +

        Conjugate gradient method

        @@ -902,7 +961,7 @@ which is zero unless \( i=j \).











        -

        Conjugate gradient method

        +

        Conjugate gradient method

        @@ -929,7 +988,7 @@ $$











        -

        Conjugate gradient method

        +

        Conjugate gradient method

        @@ -961,7 +1020,7 @@ $$











        -

        Conjugate gradient method and iterations

        +

        Conjugate gradient method and iterations

        @@ -997,7 +1056,7 @@ instead.











        -

        Conjugate gradient method

        +

        Conjugate gradient method

        @@ -1027,7 +1086,7 @@ hence the name conjugate gradient method.











        -

        Conjugate gradient method

        +

        Conjugate gradient method

        @@ -1056,7 +1115,7 @@ $$











        -

        Conjugate gradient method

        +

        Conjugate gradient method

        @@ -1094,7 +1153,7 @@ $$

        -

        Revisiting our first homework

        +

        Revisiting our first homework

        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

        -

        x = 2*np.random.rand(m,1)
        +
        x = 2*np.random.rand(m,1)
         y = 4+3*x+np.random.randn(m,1)
         

        @@ -1131,7 +1190,7 @@ $$

        -

        Gradient descent example

        +

        Gradient descent example

        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.











        -

        The derivative of the cost/loss function

        +

        The derivative of the cost/loss function

        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.











        -

        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

        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











        -

        Gradient Descent Example

        +

        Gradient Descent Example

        Here our simple 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

        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 @@ $$











        -

        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

        • Gradient descent (GD) finds local minima of our function. Since the GD algorithm is deterministic, if it converges, it will converge to a local minimum of our cost/loss/risk function. Because in ML we are often dealing with extremely rugged landscapes with many local minima, this can lead to poor performance.
        • @@ -1375,7 +1434,7 @@ plt.show()









          -

          Stochastic Gradient Descent

          +

          Stochastic Gradient Descent

          Stochastic gradient descent (SGD) and variants thereof address some of @@ -1393,7 +1452,7 @@ $$











          -

          Computation of gradients

          +

          Computation of gradients

          This in turn means that the gradient can be @@ -1413,7 +1472,7 @@ minibatches. We denote these minibatches by \( B_k \) where











          -

          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

          Thus a gradient descent step now looks like @@ -1456,12 +1515,12 @@ the number of minibatches, as exemplified in the code below.











          -

          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?

          A natural question is when do we stop the search for a new minimum? @@ -1505,7 +1564,7 @@ gave the lowest value.











          -

          Slightly different approach

          +

          Slightly different approach

          Another approach is to let the step length \( \gamma_j \) depend on the @@ -1525,7 +1584,7 @@ function.

          -

          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()
           
           
           
          - © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
          diff --git a/doc/pub/week39/html/week39.html b/doc/pub/week39/html/week39.html index 81ca3ad56..727aeabc3 100644 --- a/doc/pub/week39/html/week39.html +++ b/doc/pub/week39/html/week39.html @@ -1,11 +1,11 @@ - + @@ -53,10 +53,10 @@ hr.figure { border: 0; width: 80%; border-bottom: 1px solid #aaa} .alert-block > p, .alert-block > ul {margin-bottom:1em} .alert li {margin-top: 1em} .alert-block p+p {margin-top:5px} -.alert-notice { background-image: url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_notice.png); } -.alert-summary { background-image:url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_summary.png); } -.alert-warning { background-image: url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_warning.png); } -.alert-question {background-image:url(https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_images/small_gray_question.png); } +.alert-notice { background-image: url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_gray_notice.png); } +.alert-summary { background-image:url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_gray_summary.png); } +.alert-warning { background-image: url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_gray_warning.png); } +.alert-question {background-image:url(https://cdn.rawgit.com/doconce/doconce/master/bundled/html_images/small_gray_question.png); } div { text-align: justify; text-justify: inter-word; } @@ -66,74 +66,137 @@ div { text-align: justify; text-justify: inter-word; } @@ -175,35 +238,34 @@ MathJax.Hub.Config({
          [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

          -

          Sep 29, 2020

          +

          Sep 25, 2021












          -

          Plan for week 39

          +

          Plan for week 39

          • Thursday: Repetition of Logistic regression equations and discussion of Gradient methods
          • Friday: Stochastic Gradient descent with examples and automatic differeantion
          • +
          • Reading recommendations:
          -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

          Overview Video, why do we care about gradient methods? -

          -Video of Lecture and link to handwritten notes. -











          -

          Optimization, the central part of any Machine Learning algortithm

          +

          Optimization, the central part of any Machine Learning algortithm

          Almost every problem in machine learning and data science starts with @@ -218,7 +280,7 @@ some approximative/numerical method to compute the minimum.











          -

          Revisiting our Logistic Regression case

          +

          Revisiting our Logistic Regression case

          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











          -

          The equations to solve

          +

          The equations to solve

          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.











          -

          Solving using Newton-Raphson's method

          +

          Solving using Newton-Raphson's method

          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











          -

          Brief reminder on Newton-Raphson's method

          +

          Brief reminder on Newton-Raphson's method

          Let us quickly remind ourselves how we derive the above method. @@ -309,7 +371,7 @@ normally discourage the use of this method.











          -

          The equations

          +

          The equations

          The Newton-Raphson formula consists geometrically of extending the @@ -345,7 +407,7 @@ $$











          -

          Simple geometric interpretation

          +

          Simple geometric interpretation

          The above is Newton-Raphson's method. It has a simple geometric @@ -363,7 +425,7 @@ vanishes, then Newton-Raphson may fail totally











          -

          Extending to more than one variable

          +

          Extending to more than one variable

          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











          -

          Steepest descent

          +

          Steepest descent

          The basic idea of gradient descent is @@ -442,7 +504,7 @@ we are always moving towards smaller function values, i.e a minimum.

          -

          More on Steepest descent

          +

          More on Steepest descent

          The previous observation is the basis of the method of steepest @@ -461,7 +523,7 @@ the learning rate within the context of Machine Learning.

          -

          The ideal

          +

          The ideal

          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 sensitiveness of the gradient descent

          +

          The sensitiveness of the gradient descent

          The gradient descent method @@ -506,7 +568,7 @@ randomness. One such method is that of Stochastic Gradient Descent

          -

          Convex functions

          +

          Convex functions

          Ideally we want our cost/loss function to be convex(concave). @@ -526,7 +588,7 @@ regular polygons (triangles, rectangles, pentagons, etc...).











          -

          Convex function

          +

          Convex function

          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...).











          -

          Conditions on convex functions

          +

          Conditions on convex functions

          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.

          -Second order condition. +Second order condition

          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











          -

          More on convex functions

          +

          More on convex functions

          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:

          -Any minimum is global for convex functions. +Any minimum is global for convex functions

          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











          -

          Some simple problems

          +

          Some simple problems

          1. Show that \( f(x)=x^2 \) is convex for \( x \in \mathbb{R} \) using the definition of convexity. Hint: If you re-write the definition, \( f \) is convex if the following holds for all \( x,y \in D_f \) and any \( \lambda \in [0,1] \) $\lambda f(x)+(1-\lambda)f(y)-f(\lambda x + (1-\lambda) y ) \geq 0$.
          2. @@ -633,15 +695,12 @@ Using the definition of convexity, try to show that a function satisfying the pr











            -

            Friday September 25

            - -

            -Video of Lecture and link to handwritten notes. +

            Friday October 1











            -

            Standard steepest descent

            +

            Standard steepest descent

            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 \).











            -

            Gradient method

            +

            Gradient method

            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











            -

            Steepest descent method

            +

            Steepest descent method

            We denote the initial guess for \( \boldsymbol{x} \) as \( \boldsymbol{x}_0 \). @@ -717,7 +776,7 @@ instead.











            -

            Steepest descent method

            +

            Steepest descent method

            @@ -747,7 +806,7 @@ and











            -

            Final expressions

            +

            Final expressions

            @@ -790,12 +849,12 @@ $$











            -

            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])]
             
            @@ -830,7 +889,7 @@ Find guesses

            -

            x = guesses[-1]
            +
            x = guesses[-1]
             s = -df(x)
             

            @@ -838,7 +897,7 @@ Run it!

            -

            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

            @@ -889,7 +948,7 @@ this inner product. Being conjugate is a symmetric relation: if \( \boldsymbol{s











            -

            Conjugate gradient method

            +

            Conjugate gradient method

            @@ -907,7 +966,7 @@ which is zero unless \( i=j \).











            -

            Conjugate gradient method

            +

            Conjugate gradient method

            @@ -934,7 +993,7 @@ $$











            -

            Conjugate gradient method

            +

            Conjugate gradient method

            @@ -966,7 +1025,7 @@ $$











            -

            Conjugate gradient method and iterations

            +

            Conjugate gradient method and iterations

            @@ -1002,7 +1061,7 @@ instead.











            -

            Conjugate gradient method

            +

            Conjugate gradient method

            @@ -1032,7 +1091,7 @@ hence the name conjugate gradient method.











            -

            Conjugate gradient method

            +

            Conjugate gradient method

            @@ -1061,7 +1120,7 @@ $$











            -

            Conjugate gradient method

            +

            Conjugate gradient method

            @@ -1099,7 +1158,7 @@ $$

            -

            Revisiting our first homework

            +

            Revisiting our first homework

            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

            -

            x = 2*np.random.rand(m,1)
            +
            x = 2*np.random.rand(m,1)
             y = 4+3*x+np.random.randn(m,1)
             

            @@ -1136,7 +1195,7 @@ $$

            -

            Gradient descent example

            +

            Gradient descent example

            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.











            -

            The derivative of the cost/loss function

            +

            The derivative of the cost/loss function

            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.











            -

            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

            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











            -

            Gradient Descent Example

            +

            Gradient Descent Example

            Here our simple 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

            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 @@ $$











            -

            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

            • Gradient descent (GD) finds local minima of our function. Since the GD algorithm is deterministic, if it converges, it will converge to a local minimum of our cost/loss/risk function. Because in ML we are often dealing with extremely rugged landscapes with many local minima, this can lead to poor performance.
            • @@ -1380,7 +1439,7 @@ plt.show()









              -

              Stochastic Gradient Descent

              +

              Stochastic Gradient Descent

              Stochastic gradient descent (SGD) and variants thereof address some of @@ -1398,7 +1457,7 @@ $$











              -

              Computation of gradients

              +

              Computation of gradients

              This in turn means that the gradient can be @@ -1418,7 +1477,7 @@ minibatches. We denote these minibatches by \( B_k \) where











              -

              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

              Thus a gradient descent step now looks like @@ -1461,12 +1520,12 @@ the number of minibatches, as exemplified in the code below.











              -

              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?

              A natural question is when do we stop the search for a new minimum? @@ -1510,7 +1569,7 @@ gave the lowest value.











              -

              Slightly different approach

              +

              Slightly different approach

              Another approach is to let the step length \( \gamma_j \) depend on the @@ -1530,7 +1589,7 @@ function.

              -

              import numpy as np 
              +
              import numpy as np 
               
               def step_length(t,t0,t1):
                   return t0/(t+t1)
              @@ -1558,12 +1617,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
              @@ -1637,7 +1696,7 @@ plt.show()
               
               
               
              - © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
              diff --git a/doc/pub/week39/ipynb/ipynb-week39-src.tar.gz b/doc/pub/week39/ipynb/ipynb-week39-src.tar.gz index f21822d9f..3bc88f1ac 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 a0ae7110f..d5d27c80b 100644 --- a/doc/pub/week39/ipynb/week39.ipynb +++ b/doc/pub/week39/ipynb/week39.ipynb @@ -10,9 +10,9 @@ " \n", "**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n", "\n", - "Date: **Sep 29, 2020**\n", + "Date: **Sep 25, 2021**\n", "\n", - "Copyright 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", + "Copyright 1999-2021, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n", "\n", "\n", "\n", @@ -22,14 +22,15 @@ "\n", "* Friday: Stochastic Gradient descent with examples and automatic differeantion\n", "\n", - "Reading suggestions for both days: [Aurelien Geron's chapter 4](https://github.com/CompPhysics/MachineLearning/blob/master/doc/Textbooks/TensorflowML.pdf) and [Murphy sections 8.3 and 8.5](https://github.com/CompPhysics/MachineLearning/blob/master/doc/Textbooks/MachineLearningMurphy.pdf) \n", + "* Reading recommendations:\n", "\n", - "## Thursday September 24\n", + "See [lecture notes for week 39](https://compphysics.github.io/MachineLearning/doc/web/course.html).\n", + "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.\n", + "\n", + "## Thursday September 30\n", "\n", "[Overview Video, why do we care about gradient methods?](https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h20/forelesningsvideoer/OverarchingAimsWeek39.mp4?vrtx=view-as-webpage)\n", "\n", - "[Video of Lecture](https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember24.mp4?vrtx=view-as-webpage) and [link to handwritten notes](https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember24.pdf).\n", - "\n", "\n", "## Optimization, the central part of any Machine Learning algortithm\n", "\n", @@ -552,9 +553,7 @@ "Using the definition of convexity, try to show that a function satisfying the properties above is convex (the third condition is not needed to show this).\n", "\n", "\n", - "## Friday September 25\n", - "\n", - "[Video of Lecture](https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember25.mp4?vrtx=view-as-webpage) and [link to handwritten notes](https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember25.pdf).\n", + "## Friday October 1\n", "\n", "\n", "## Standard steepest descent\n", @@ -790,9 +789,10 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -829,9 +829,10 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -849,9 +850,10 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -868,9 +870,10 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -892,9 +895,10 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -1270,9 +1274,10 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -1439,9 +1444,10 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -1502,9 +1508,10 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -1588,9 +1595,10 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -1768,9 +1776,10 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -1832,9 +1841,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ @@ -1873,9 +1883,10 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": false, + "editable": true }, "outputs": [], "source": [ diff --git a/doc/src/week39/week39.do.txt b/doc/src/week39/week39.do.txt index d081c843b..37766540d 100644 --- a/doc/src/week39/week39.do.txt +++ b/doc/src/week39/week39.do.txt @@ -9,15 +9,16 @@ DATE: today * Friday: Stochastic Gradient descent with examples and automatic differeantion -Reading suggestions for both days: "Aurelien Geron's chapter 4":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/Textbooks/TensorflowML.pdf" and "Murphy sections 8.3 and 8.5":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/Textbooks/MachineLearningMurphy.pdf" +* Reading recommendations: + +See "lecture notes for week 39":"https://compphysics.github.io/MachineLearning/doc/web/course.html". +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. !split -===== Thursday September 24 ===== +===== Thursday September 30 ===== "Overview Video, why do we care about gradient methods?":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK3155/h20/forelesningsvideoer/OverarchingAimsWeek39.mp4?vrtx=view-as-webpage" -"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember24.mp4?vrtx=view-as-webpage" and "link to handwritten notes":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember24.pdf". - !split ===== Optimization, the central part of any Machine Learning algortithm ===== @@ -391,9 +392,7 @@ Using the definition of convexity, try to show that a function satisfying the pr !split -===== Friday September 25 ===== - -"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember25.mp4?vrtx=view-as-webpage" and "link to handwritten notes":"https://github.com/CompPhysics/MachineLearning/blob/master/doc/HandWrittenNotes/NotesSeptember25.pdf". +===== Friday October 1 ===== !split