diff --git a/doc/pub/week39/html/week39-bs.html b/doc/pub/week39/html/week39-bs.html index 011e4abdf..8da1f374f 100644 --- a/doc/pub/week39/html/week39-bs.html +++ b/doc/pub/week39/html/week39-bs.html @@ -253,6 +253,11 @@ doconce format html week39.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'similar-second-order-function-now-problem-but-now-with-adagrad'), + ('RMSprop for adaptive learning rate with Stochastic Gradient ' + 'Descent', + 2, + None, + 'rmsprop-for-adaptive-learning-rate-with-stochastic-gradient-descent'), ('And Logistic Regression', 2, None, 'and-logistic-regression'), ('Introducing "JAX":"https://jax.readthedocs.io/en/latest/"', 2, @@ -375,9 +380,10 @@ MathJax.Hub.Config({
  • Including Stochastic Gradient Descent with Autograd
  • Same code but now with momentum gradient descent
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • And Logistic Regression
  • -
  • Introducing "JAX":"https://jax.readthedocs.io/en/latest/"
  • -
  • Weekend challenge
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And Logistic Regression
  • +
  • Introducing "JAX":"https://jax.readthedocs.io/en/latest/"
  • +
  • Weekend challenge
  • @@ -432,7 +438,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 86
  • +
  • 87
  • »
  • diff --git a/doc/pub/week39/html/week39-reveal.html b/doc/pub/week39/html/week39-reveal.html index 4c46ed246..612a3d1a6 100644 --- a/doc/pub/week39/html/week39-reveal.html +++ b/doc/pub/week39/html/week39-reveal.html @@ -3565,6 +3565,89 @@ delta = 1e-8

    Running this code we note an almost perfect agreement with the results from matrix inversion.

    +
    +

    RMSprop for adaptive learning rate with Stochastic Gradient Descent

    + + +
    +
    +
    +
    +
    +
    # Using Autograd to calculate gradients using RMSprop  and Stochastic Gradient descent
    +# OLS example
    +from random import random, seed
    +import numpy as np
    +import autograd.numpy as np
    +import matplotlib.pyplot as plt
    +from autograd import grad
    +
    +# Note change from previous example
    +def CostOLS(y,X,theta):
    +    return np.sum((y-X @ theta)**2)
    +
    +n = 10000
    +x = np.random.rand(n,1)
    +y = 2.0+3*x +4*x*x# +np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x, x*x]
    +XT_X = X.T @ X
    +theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
    +print("Own inversion")
    +print(theta_linreg)
    +
    +
    +# Note that we request the derivative wrt third argument (theta, 2 here)
    +training_gradient = grad(CostOLS,2)
    +# Define parameters for Stochastic Gradient Descent
    +n_epochs = 50
    +M = 5   #size of each minibatch
    +m = int(n/M) #number of minibatches
    +# Guess for unknown parameters theta
    +theta = np.random.randn(3,1)
    +
    +# Value for learning rate
    +eta = 0.01
    +# Value for parameter rho
    +rho = 0.99
    +# Including AdaGrad parameter to avoid possible division by zero
    +delta  = 1e-8
    +for epoch in range(n_epochs):
    +    Giter = np.zeros(shape=(3,3))
    +    for i in range(m):
    +        random_index = M*np.random.randint(m)
    +        xi = X[random_index:random_index+M]
    +        yi = y[random_index:random_index+M]
    +        gradients = (1.0/M)*training_gradient(yi, xi, theta)
    +	# Previous value for the outer product of gradients
    +        Previous = Giter
    +	# Accumulated gradient
    +        Giter +=gradients @ gradients.T
    +	# Scaling with rho the new and the previous results
    +        Gnew = (rho*Previous+(1-rho)*Giter)
    +	# Taking the diagonal only and inverting
    +        Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Gnew)))]
    +	# Hadamard product
    +        update = np.multiply(Ginverse,gradients)
    +        theta -= update
    +print("theta from own RMSprop")
    +print(theta)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    And Logistic Regression

    diff --git a/doc/pub/week39/html/week39-solarized.html b/doc/pub/week39/html/week39-solarized.html index 57730e30e..5eceeedf7 100644 --- a/doc/pub/week39/html/week39-solarized.html +++ b/doc/pub/week39/html/week39-solarized.html @@ -280,6 +280,11 @@ div.toc p,a { 2, None, 'similar-second-order-function-now-problem-but-now-with-adagrad'), + ('RMSprop for adaptive learning rate with Stochastic Gradient ' + 'Descent', + 2, + None, + 'rmsprop-for-adaptive-learning-rate-with-stochastic-gradient-descent'), ('And Logistic Regression', 2, None, 'and-logistic-regression'), ('Introducing "JAX":"https://jax.readthedocs.io/en/latest/"', 2, @@ -3492,6 +3497,89 @@ delta = 1e-8

    Running this code we note an almost perfect agreement with the results from matrix inversion.

    +









    +

    RMSprop for adaptive learning rate with Stochastic Gradient Descent

    + + +
    +
    +
    +
    +
    +
    # Using Autograd to calculate gradients using RMSprop  and Stochastic Gradient descent
    +# OLS example
    +from random import random, seed
    +import numpy as np
    +import autograd.numpy as np
    +import matplotlib.pyplot as plt
    +from autograd import grad
    +
    +# Note change from previous example
    +def CostOLS(y,X,theta):
    +    return np.sum((y-X @ theta)**2)
    +
    +n = 10000
    +x = np.random.rand(n,1)
    +y = 2.0+3*x +4*x*x# +np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x, x*x]
    +XT_X = X.T @ X
    +theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
    +print("Own inversion")
    +print(theta_linreg)
    +
    +
    +# Note that we request the derivative wrt third argument (theta, 2 here)
    +training_gradient = grad(CostOLS,2)
    +# Define parameters for Stochastic Gradient Descent
    +n_epochs = 50
    +M = 5   #size of each minibatch
    +m = int(n/M) #number of minibatches
    +# Guess for unknown parameters theta
    +theta = np.random.randn(3,1)
    +
    +# Value for learning rate
    +eta = 0.01
    +# Value for parameter rho
    +rho = 0.99
    +# Including AdaGrad parameter to avoid possible division by zero
    +delta  = 1e-8
    +for epoch in range(n_epochs):
    +    Giter = np.zeros(shape=(3,3))
    +    for i in range(m):
    +        random_index = M*np.random.randint(m)
    +        xi = X[random_index:random_index+M]
    +        yi = y[random_index:random_index+M]
    +        gradients = (1.0/M)*training_gradient(yi, xi, theta)
    +	# Previous value for the outer product of gradients
    +        Previous = Giter
    +	# Accumulated gradient
    +        Giter +=gradients @ gradients.T
    +	# Scaling with rho the new and the previous results
    +        Gnew = (rho*Previous+(1-rho)*Giter)
    +	# Taking the diagonal only and inverting
    +        Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Gnew)))]
    +	# Hadamard product
    +        update = np.multiply(Ginverse,gradients)
    +        theta -= update
    +print("theta from own RMSprop")
    +print(theta)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +









    And Logistic Regression

    diff --git a/doc/pub/week39/html/week39.html b/doc/pub/week39/html/week39.html index 511b312c4..7f1b69db8 100644 --- a/doc/pub/week39/html/week39.html +++ b/doc/pub/week39/html/week39.html @@ -357,6 +357,11 @@ div.toc p,a { 2, None, 'similar-second-order-function-now-problem-but-now-with-adagrad'), + ('RMSprop for adaptive learning rate with Stochastic Gradient ' + 'Descent', + 2, + None, + 'rmsprop-for-adaptive-learning-rate-with-stochastic-gradient-descent'), ('And Logistic Regression', 2, None, 'and-logistic-regression'), ('Introducing "JAX":"https://jax.readthedocs.io/en/latest/"', 2, @@ -3569,6 +3574,89 @@ delta = 1e-8Running this code we note an almost perfect agreement with the results from matrix inversion.

    +









    +

    RMSprop for adaptive learning rate with Stochastic Gradient Descent

    + + +
    +
    +
    +
    +
    +
    # Using Autograd to calculate gradients using RMSprop  and Stochastic Gradient descent
    +# OLS example
    +from random import random, seed
    +import numpy as np
    +import autograd.numpy as np
    +import matplotlib.pyplot as plt
    +from autograd import grad
    +
    +# Note change from previous example
    +def CostOLS(y,X,theta):
    +    return np.sum((y-X @ theta)**2)
    +
    +n = 10000
    +x = np.random.rand(n,1)
    +y = 2.0+3*x +4*x*x# +np.random.randn(n,1)
    +
    +X = np.c_[np.ones((n,1)), x, x*x]
    +XT_X = X.T @ X
    +theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
    +print("Own inversion")
    +print(theta_linreg)
    +
    +
    +# Note that we request the derivative wrt third argument (theta, 2 here)
    +training_gradient = grad(CostOLS,2)
    +# Define parameters for Stochastic Gradient Descent
    +n_epochs = 50
    +M = 5   #size of each minibatch
    +m = int(n/M) #number of minibatches
    +# Guess for unknown parameters theta
    +theta = np.random.randn(3,1)
    +
    +# Value for learning rate
    +eta = 0.01
    +# Value for parameter rho
    +rho = 0.99
    +# Including AdaGrad parameter to avoid possible division by zero
    +delta  = 1e-8
    +for epoch in range(n_epochs):
    +    Giter = np.zeros(shape=(3,3))
    +    for i in range(m):
    +        random_index = M*np.random.randint(m)
    +        xi = X[random_index:random_index+M]
    +        yi = y[random_index:random_index+M]
    +        gradients = (1.0/M)*training_gradient(yi, xi, theta)
    +	# Previous value for the outer product of gradients
    +        Previous = Giter
    +	# Accumulated gradient
    +        Giter +=gradients @ gradients.T
    +	# Scaling with rho the new and the previous results
    +        Gnew = (rho*Previous+(1-rho)*Giter)
    +	# Taking the diagonal only and inverting
    +        Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Gnew)))]
    +	# Hadamard product
    +        update = np.multiply(Ginverse,gradients)
    +        theta -= update
    +print("theta from own RMSprop")
    +print(theta)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +









    And Logistic Regression

    diff --git a/doc/pub/week39/ipynb/ipynb-week39-src.tar.gz b/doc/pub/week39/ipynb/ipynb-week39-src.tar.gz index 09221a7db..d0530ffbe 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 6120e7b51..10aeb280c 100644 --- a/doc/pub/week39/ipynb/week39.ipynb +++ b/doc/pub/week39/ipynb/week39.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "e24bca62", + "id": "831ab16c", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "e9d046e5", + "id": "1a89a1bf", "metadata": { "editable": true }, @@ -29,7 +29,7 @@ }, { "cell_type": "markdown", - "id": "a42fc301", + "id": "a48d4553", "metadata": { "editable": true }, @@ -55,7 +55,7 @@ }, { "cell_type": "markdown", - "id": "86a444d3", + "id": "b76fe6e1", "metadata": { "editable": true }, @@ -76,7 +76,7 @@ }, { "cell_type": "markdown", - "id": "18c198a7", + "id": "8efd7af4", "metadata": { "editable": true }, @@ -93,7 +93,7 @@ }, { "cell_type": "markdown", - "id": "a78a7971", + "id": "46208ba4", "metadata": { "editable": true }, @@ -108,7 +108,7 @@ }, { "cell_type": "markdown", - "id": "5f7ba8f7", + "id": "a2d78f95", "metadata": { "editable": true }, @@ -118,7 +118,7 @@ }, { "cell_type": "markdown", - "id": "7c688cd4", + "id": "6089b10e", "metadata": { "editable": true }, @@ -134,7 +134,7 @@ }, { "cell_type": "markdown", - "id": "f8d89f53", + "id": "7d1ae41a", "metadata": { "editable": true }, @@ -146,7 +146,7 @@ }, { "cell_type": "markdown", - "id": "6520ed2c", + "id": "d132fa52", "metadata": { "editable": true }, @@ -157,7 +157,7 @@ }, { "cell_type": "markdown", - "id": "d4eceb89", + "id": "b56b1ac3", "metadata": { "editable": true }, @@ -169,7 +169,7 @@ }, { "cell_type": "markdown", - "id": "d329b027", + "id": "466913e9", "metadata": { "editable": true }, @@ -179,7 +179,7 @@ }, { "cell_type": "markdown", - "id": "3e676963", + "id": "30c1f3cc", "metadata": { "editable": true }, @@ -193,7 +193,7 @@ }, { "cell_type": "markdown", - "id": "c1c25a40", + "id": "09c04703", "metadata": { "editable": true }, @@ -205,7 +205,7 @@ }, { "cell_type": "markdown", - "id": "49a9b988", + "id": "99eea598", "metadata": { "editable": true }, @@ -215,7 +215,7 @@ }, { "cell_type": "markdown", - "id": "9ff443da", + "id": "7604810b", "metadata": { "editable": true }, @@ -227,7 +227,7 @@ }, { "cell_type": "markdown", - "id": "478c51a9", + "id": "44b47354", "metadata": { "editable": true }, @@ -239,7 +239,7 @@ }, { "cell_type": "markdown", - "id": "4584f036", + "id": "1190ad62", "metadata": { "editable": true }, @@ -259,7 +259,7 @@ }, { "cell_type": "markdown", - "id": "0713a4c6", + "id": "abf9f046", "metadata": { "editable": true }, @@ -275,7 +275,7 @@ }, { "cell_type": "markdown", - "id": "564a1130", + "id": "4b991659", "metadata": { "editable": true }, @@ -291,7 +291,7 @@ }, { "cell_type": "markdown", - "id": "523c58c6", + "id": "fa285a83", "metadata": { "editable": true }, @@ -302,7 +302,7 @@ }, { "cell_type": "markdown", - "id": "89e62fe1", + "id": "2163d473", "metadata": { "editable": true }, @@ -314,7 +314,7 @@ }, { "cell_type": "markdown", - "id": "83c6b223", + "id": "d7edfa0e", "metadata": { "editable": true }, @@ -324,7 +324,7 @@ }, { "cell_type": "markdown", - "id": "596fc91e", + "id": "650aea98", "metadata": { "editable": true }, @@ -336,7 +336,7 @@ }, { "cell_type": "markdown", - "id": "8aea8c22", + "id": "136077c3", "metadata": { "editable": true }, @@ -346,7 +346,7 @@ }, { "cell_type": "markdown", - "id": "ebd738c5", + "id": "6100b858", "metadata": { "editable": true }, @@ -358,7 +358,7 @@ }, { "cell_type": "markdown", - "id": "cbade8a1", + "id": "09d246f7", "metadata": { "editable": true }, @@ -380,7 +380,7 @@ }, { "cell_type": "markdown", - "id": "54284f78", + "id": "cf082864", "metadata": { "editable": true }, @@ -393,7 +393,7 @@ }, { "cell_type": "markdown", - "id": "05e8bd6c", + "id": "a83bd82a", "metadata": { "editable": true }, @@ -406,7 +406,7 @@ }, { "cell_type": "markdown", - "id": "75eb8466", + "id": "04bc02b4", "metadata": { "editable": true }, @@ -416,7 +416,7 @@ }, { "cell_type": "markdown", - "id": "8c3a8a36", + "id": "c34bc1b5", "metadata": { "editable": true }, @@ -434,7 +434,7 @@ }, { "cell_type": "markdown", - "id": "0d7ef225", + "id": "c1a8421b", "metadata": { "editable": true }, @@ -444,7 +444,7 @@ }, { "cell_type": "markdown", - "id": "314d130a", + "id": "3b9ae588", "metadata": { "editable": true }, @@ -459,7 +459,7 @@ }, { "cell_type": "markdown", - "id": "d16e653c", + "id": "c83b53c3", "metadata": { "editable": true }, @@ -469,7 +469,7 @@ }, { "cell_type": "markdown", - "id": "8e0d1824", + "id": "4e116635", "metadata": { "editable": true }, @@ -483,7 +483,7 @@ }, { "cell_type": "markdown", - "id": "060c713d", + "id": "519b8461", "metadata": { "editable": true }, @@ -493,7 +493,7 @@ }, { "cell_type": "markdown", - "id": "c6af6eb4", + "id": "175a09e1", "metadata": { "editable": true }, @@ -507,7 +507,7 @@ }, { "cell_type": "markdown", - "id": "78b1b1a2", + "id": "fc897577", "metadata": { "editable": true }, @@ -522,7 +522,7 @@ }, { "cell_type": "markdown", - "id": "0cdc4f21", + "id": "dd88592c", "metadata": { "editable": true }, @@ -539,7 +539,7 @@ }, { "cell_type": "markdown", - "id": "f1abab41", + "id": "7f0c3e7d", "metadata": { "editable": true }, @@ -551,7 +551,7 @@ }, { "cell_type": "markdown", - "id": "9edac1f7", + "id": "f4f75ab5", "metadata": { "editable": true }, @@ -565,7 +565,7 @@ }, { "cell_type": "markdown", - "id": "d70a9f7a", + "id": "7872bbf4", "metadata": { "editable": true }, @@ -580,7 +580,7 @@ }, { "cell_type": "markdown", - "id": "68089b45", + "id": "9dc53b5c", "metadata": { "editable": true }, @@ -592,7 +592,7 @@ }, { "cell_type": "markdown", - "id": "2a3ac951", + "id": "d14ffd8a", "metadata": { "editable": true }, @@ -603,7 +603,7 @@ }, { "cell_type": "markdown", - "id": "5fa04a8c", + "id": "51d0991d", "metadata": { "editable": true }, @@ -631,7 +631,7 @@ }, { "cell_type": "markdown", - "id": "a0b7d4f5", + "id": "f8f5d523", "metadata": { "editable": true }, @@ -653,7 +653,7 @@ }, { "cell_type": "markdown", - "id": "09df91da", + "id": "bd56a953", "metadata": { "editable": true }, @@ -675,7 +675,7 @@ }, { "cell_type": "markdown", - "id": "ffdbe770", + "id": "da048fc7", "metadata": { "editable": true }, @@ -687,7 +687,7 @@ }, { "cell_type": "markdown", - "id": "5e8f7025", + "id": "1fa9515a", "metadata": { "editable": true }, @@ -724,7 +724,7 @@ }, { "cell_type": "markdown", - "id": "034bba01", + "id": "4603676b", "metadata": { "editable": true }, @@ -752,7 +752,7 @@ }, { "cell_type": "markdown", - "id": "2c6e6d8e", + "id": "a1034044", "metadata": { "editable": true }, @@ -782,7 +782,7 @@ }, { "cell_type": "markdown", - "id": "df7481e8", + "id": "81655e20", "metadata": { "editable": true }, @@ -802,7 +802,7 @@ }, { "cell_type": "markdown", - "id": "8ef11a23", + "id": "4db9bda7", "metadata": { "editable": true }, @@ -814,7 +814,7 @@ }, { "cell_type": "markdown", - "id": "de4dd468", + "id": "3e840e3a", "metadata": { "editable": true }, @@ -824,7 +824,7 @@ }, { "cell_type": "markdown", - "id": "a2024839", + "id": "600e0070", "metadata": { "editable": true }, @@ -836,7 +836,7 @@ }, { "cell_type": "markdown", - "id": "eb954cfc", + "id": "d2fe45d9", "metadata": { "editable": true }, @@ -848,7 +848,7 @@ }, { "cell_type": "markdown", - "id": "f2873926", + "id": "faed650b", "metadata": { "editable": true }, @@ -860,7 +860,7 @@ }, { "cell_type": "markdown", - "id": "408639fb", + "id": "0561cb94", "metadata": { "editable": true }, @@ -872,7 +872,7 @@ }, { "cell_type": "markdown", - "id": "ad2e03f0", + "id": "e5a243bf", "metadata": { "editable": true }, @@ -883,7 +883,7 @@ }, { "cell_type": "markdown", - "id": "c4f86219", + "id": "b96eac4e", "metadata": { "editable": true }, @@ -896,7 +896,7 @@ }, { "cell_type": "markdown", - "id": "4e634352", + "id": "f5b81f53", "metadata": { "editable": true }, @@ -908,7 +908,7 @@ }, { "cell_type": "markdown", - "id": "fce2a84a", + "id": "9d6f7709", "metadata": { "editable": true }, @@ -918,7 +918,7 @@ }, { "cell_type": "markdown", - "id": "bb1c0818", + "id": "d1719061", "metadata": { "editable": true }, @@ -930,7 +930,7 @@ }, { "cell_type": "markdown", - "id": "28191eb6", + "id": "baa11a7a", "metadata": { "editable": true }, @@ -940,7 +940,7 @@ }, { "cell_type": "markdown", - "id": "efb36ffb", + "id": "b46fb88b", "metadata": { "editable": true }, @@ -951,7 +951,7 @@ }, { "cell_type": "markdown", - "id": "cbb54980", + "id": "ecd6c1c0", "metadata": { "editable": true }, @@ -963,7 +963,7 @@ }, { "cell_type": "markdown", - "id": "02f3a580", + "id": "759598fd", "metadata": { "editable": true }, @@ -975,7 +975,7 @@ }, { "cell_type": "markdown", - "id": "e74d016a", + "id": "0486631f", "metadata": { "editable": true }, @@ -987,7 +987,7 @@ }, { "cell_type": "markdown", - "id": "b221f8cd", + "id": "86721e06", "metadata": { "editable": true }, @@ -998,7 +998,7 @@ }, { "cell_type": "markdown", - "id": "d1fcda0e", + "id": "fe4f0621", "metadata": { "editable": true }, @@ -1009,7 +1009,7 @@ }, { "cell_type": "markdown", - "id": "5e580524", + "id": "93aa0a1b", "metadata": { "editable": true }, @@ -1021,7 +1021,7 @@ }, { "cell_type": "markdown", - "id": "b18d9941", + "id": "e3db98cd", "metadata": { "editable": true }, @@ -1031,7 +1031,7 @@ }, { "cell_type": "markdown", - "id": "ddfb86f1", + "id": "01fe93a3", "metadata": { "editable": true }, @@ -1043,7 +1043,7 @@ }, { "cell_type": "markdown", - "id": "c15c0c1e", + "id": "03c84175", "metadata": { "editable": true }, @@ -1053,7 +1053,7 @@ }, { "cell_type": "markdown", - "id": "1e70c362", + "id": "8179368d", "metadata": { "editable": true }, @@ -1065,7 +1065,7 @@ }, { "cell_type": "markdown", - "id": "eda47934", + "id": "dd73dfbe", "metadata": { "editable": true }, @@ -1075,7 +1075,7 @@ }, { "cell_type": "markdown", - "id": "a8807ca8", + "id": "572abe34", "metadata": { "editable": true }, @@ -1087,7 +1087,7 @@ }, { "cell_type": "markdown", - "id": "797d70a7", + "id": "c89821cc", "metadata": { "editable": true }, @@ -1097,7 +1097,7 @@ }, { "cell_type": "markdown", - "id": "91253590", + "id": "5a690582", "metadata": { "editable": true }, @@ -1109,7 +1109,7 @@ }, { "cell_type": "markdown", - "id": "bb586698", + "id": "0abad81b", "metadata": { "editable": true }, @@ -1120,7 +1120,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "c99ffffe", + "id": "f6a032e9", "metadata": { "collapsed": false, "editable": true @@ -1153,7 +1153,7 @@ }, { "cell_type": "markdown", - "id": "23383c7d", + "id": "77b7155c", "metadata": { "editable": true }, @@ -1164,7 +1164,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "c0bf99b8", + "id": "28f56acb", "metadata": { "collapsed": false, "editable": true @@ -1178,7 +1178,7 @@ }, { "cell_type": "markdown", - "id": "2073d43c", + "id": "609d822d", "metadata": { "editable": true }, @@ -1189,7 +1189,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "098e1651", + "id": "bbfb7f41", "metadata": { "collapsed": false, "editable": true @@ -1202,7 +1202,7 @@ }, { "cell_type": "markdown", - "id": "8f3c24d6", + "id": "651bc36e", "metadata": { "editable": true }, @@ -1213,7 +1213,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "b53b03db", + "id": "bca365f4", "metadata": { "collapsed": false, "editable": true @@ -1231,7 +1231,7 @@ }, { "cell_type": "markdown", - "id": "65e9016f", + "id": "a7e8c4e3", "metadata": { "editable": true }, @@ -1242,7 +1242,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "90a32f75", + "id": "ae10a006", "metadata": { "collapsed": false, "editable": true @@ -1257,7 +1257,7 @@ }, { "cell_type": "markdown", - "id": "6ecc0eaf", + "id": "1f64a7d9", "metadata": { "editable": true }, @@ -1267,7 +1267,7 @@ }, { "cell_type": "markdown", - "id": "391ea54c", + "id": "50bef8bb", "metadata": { "editable": true }, @@ -1281,7 +1281,7 @@ }, { "cell_type": "markdown", - "id": "0f827f59", + "id": "ebf2dcec", "metadata": { "editable": true }, @@ -1293,7 +1293,7 @@ }, { "cell_type": "markdown", - "id": "8d85252f", + "id": "e4ce5a29", "metadata": { "editable": true }, @@ -1304,7 +1304,7 @@ }, { "cell_type": "markdown", - "id": "4b962c6a", + "id": "dddd83fc", "metadata": { "editable": true }, @@ -1316,7 +1316,7 @@ }, { "cell_type": "markdown", - "id": "836212de", + "id": "b1be09ba", "metadata": { "editable": true }, @@ -1327,7 +1327,7 @@ }, { "cell_type": "markdown", - "id": "c86350b5", + "id": "35b17982", "metadata": { "editable": true }, @@ -1338,7 +1338,7 @@ }, { "cell_type": "markdown", - "id": "5303838b", + "id": "56f8f452", "metadata": { "editable": true }, @@ -1350,7 +1350,7 @@ }, { "cell_type": "markdown", - "id": "a61193cf", + "id": "c840acb5", "metadata": { "editable": true }, @@ -1360,7 +1360,7 @@ }, { "cell_type": "markdown", - "id": "9acdaf47", + "id": "8aabb73e", "metadata": { "editable": true }, @@ -1372,7 +1372,7 @@ }, { "cell_type": "markdown", - "id": "86d52ca2", + "id": "cd71a3b6", "metadata": { "editable": true }, @@ -1384,7 +1384,7 @@ }, { "cell_type": "markdown", - "id": "8818bb65", + "id": "2fbf4ca3", "metadata": { "editable": true }, @@ -1396,7 +1396,7 @@ }, { "cell_type": "markdown", - "id": "974957b1", + "id": "0682ff5b", "metadata": { "editable": true }, @@ -1408,7 +1408,7 @@ }, { "cell_type": "markdown", - "id": "0974b834", + "id": "dea76841", "metadata": { "editable": true }, @@ -1419,7 +1419,7 @@ }, { "cell_type": "markdown", - "id": "9f4062b2", + "id": "7210c491", "metadata": { "editable": true }, @@ -1431,7 +1431,7 @@ }, { "cell_type": "markdown", - "id": "d3ba22b1", + "id": "d70fad2e", "metadata": { "editable": true }, @@ -1441,7 +1441,7 @@ }, { "cell_type": "markdown", - "id": "17f98074", + "id": "9d31a2dc", "metadata": { "editable": true }, @@ -1453,7 +1453,7 @@ }, { "cell_type": "markdown", - "id": "02eb7c67", + "id": "bce0c379", "metadata": { "editable": true }, @@ -1463,7 +1463,7 @@ }, { "cell_type": "markdown", - "id": "6b6e2535", + "id": "3f0f29b1", "metadata": { "editable": true }, @@ -1475,7 +1475,7 @@ }, { "cell_type": "markdown", - "id": "581e48c0", + "id": "6f8d45e4", "metadata": { "editable": true }, @@ -1495,7 +1495,7 @@ }, { "cell_type": "markdown", - "id": "8d80d39f", + "id": "164f114d", "metadata": { "editable": true }, @@ -1507,7 +1507,7 @@ }, { "cell_type": "markdown", - "id": "c85bf481", + "id": "6168a5fa", "metadata": { "editable": true }, @@ -1517,7 +1517,7 @@ }, { "cell_type": "markdown", - "id": "4d752584", + "id": "084ad8db", "metadata": { "editable": true }, @@ -1529,7 +1529,7 @@ }, { "cell_type": "markdown", - "id": "d0c84272", + "id": "e1883221", "metadata": { "editable": true }, @@ -1539,7 +1539,7 @@ }, { "cell_type": "markdown", - "id": "faff592c", + "id": "075a780a", "metadata": { "editable": true }, @@ -1550,7 +1550,7 @@ }, { "cell_type": "markdown", - "id": "fa4879d1", + "id": "91c1abb6", "metadata": { "editable": true }, @@ -1562,7 +1562,7 @@ }, { "cell_type": "markdown", - "id": "4b823ab8", + "id": "7005733a", "metadata": { "editable": true }, @@ -1574,7 +1574,7 @@ }, { "cell_type": "markdown", - "id": "ed317a38", + "id": "3865bead", "metadata": { "editable": true }, @@ -1586,7 +1586,7 @@ }, { "cell_type": "markdown", - "id": "d1ef8688", + "id": "6953c5f9", "metadata": { "editable": true }, @@ -1599,7 +1599,7 @@ }, { "cell_type": "markdown", - "id": "968986eb", + "id": "f234b054", "metadata": { "editable": true }, @@ -1610,7 +1610,7 @@ }, { "cell_type": "markdown", - "id": "e984713c", + "id": "e84398d8", "metadata": { "editable": true }, @@ -1622,7 +1622,7 @@ }, { "cell_type": "markdown", - "id": "ffe69df7", + "id": "0de3dca1", "metadata": { "editable": true }, @@ -1638,7 +1638,7 @@ }, { "cell_type": "markdown", - "id": "dd86af7f", + "id": "216fb6c6", "metadata": { "editable": true }, @@ -1650,7 +1650,7 @@ }, { "cell_type": "markdown", - "id": "8ba70f4e", + "id": "f614bb20", "metadata": { "editable": true }, @@ -1661,7 +1661,7 @@ }, { "cell_type": "markdown", - "id": "8031d92b", + "id": "9c78ff37", "metadata": { "editable": true }, @@ -1673,7 +1673,7 @@ }, { "cell_type": "markdown", - "id": "b2ec51f3", + "id": "c39b751a", "metadata": { "editable": true }, @@ -1683,7 +1683,7 @@ }, { "cell_type": "markdown", - "id": "85c0b7b4", + "id": "2d1e7293", "metadata": { "editable": true }, @@ -1695,7 +1695,7 @@ }, { "cell_type": "markdown", - "id": "38aad522", + "id": "5f73e45c", "metadata": { "editable": true }, @@ -1705,7 +1705,7 @@ }, { "cell_type": "markdown", - "id": "ecf1a239", + "id": "685cb5be", "metadata": { "editable": true }, @@ -1717,7 +1717,7 @@ }, { "cell_type": "markdown", - "id": "7b32860c", + "id": "60937263", "metadata": { "editable": true }, @@ -1727,7 +1727,7 @@ }, { "cell_type": "markdown", - "id": "f024d4eb", + "id": "d3a9ed73", "metadata": { "editable": true }, @@ -1739,7 +1739,7 @@ }, { "cell_type": "markdown", - "id": "8a8bc39c", + "id": "2241adf9", "metadata": { "editable": true }, @@ -1763,7 +1763,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "500755fd", + "id": "77cabb13", "metadata": { "collapsed": false, "editable": true @@ -1776,7 +1776,7 @@ }, { "cell_type": "markdown", - "id": "181dc8d0", + "id": "8c1860a9", "metadata": { "editable": true }, @@ -1787,7 +1787,7 @@ }, { "cell_type": "markdown", - "id": "33fdef1d", + "id": "5f48be08", "metadata": { "editable": true }, @@ -1799,7 +1799,7 @@ }, { "cell_type": "markdown", - "id": "1488d4ed", + "id": "8cf4e546", "metadata": { "editable": true }, @@ -1809,7 +1809,7 @@ }, { "cell_type": "markdown", - "id": "b60cb10a", + "id": "b5139d61", "metadata": { "editable": true }, @@ -1821,7 +1821,7 @@ }, { "cell_type": "markdown", - "id": "10455f35", + "id": "81ccbcdb", "metadata": { "editable": true }, @@ -1835,7 +1835,7 @@ }, { "cell_type": "markdown", - "id": "0e7097e1", + "id": "d6159d58", "metadata": { "editable": true }, @@ -1851,7 +1851,7 @@ }, { "cell_type": "markdown", - "id": "c337500f", + "id": "9b504eb5", "metadata": { "editable": true }, @@ -1861,7 +1861,7 @@ }, { "cell_type": "markdown", - "id": "539a67c8", + "id": "2524eb92", "metadata": { "editable": true }, @@ -1873,7 +1873,7 @@ }, { "cell_type": "markdown", - "id": "bac485c6", + "id": "eebbdaac", "metadata": { "editable": true }, @@ -1883,7 +1883,7 @@ }, { "cell_type": "markdown", - "id": "66ac2ee5", + "id": "5dd05bbd", "metadata": { "editable": true }, @@ -1895,7 +1895,7 @@ }, { "cell_type": "markdown", - "id": "d0fa5500", + "id": "d7a0de59", "metadata": { "editable": true }, @@ -1909,7 +1909,7 @@ }, { "cell_type": "markdown", - "id": "a0f49a4d", + "id": "6b27fc77", "metadata": { "editable": true }, @@ -1919,7 +1919,7 @@ }, { "cell_type": "markdown", - "id": "0d6b270c", + "id": "5aa8a7fd", "metadata": { "editable": true }, @@ -1930,7 +1930,7 @@ }, { "cell_type": "markdown", - "id": "e296a37d", + "id": "e3d47199", "metadata": { "editable": true }, @@ -1945,7 +1945,7 @@ }, { "cell_type": "markdown", - "id": "f182250d", + "id": "c2824b7e", "metadata": { "editable": true }, @@ -1955,7 +1955,7 @@ }, { "cell_type": "markdown", - "id": "fbedfc1a", + "id": "a514ed13", "metadata": { "editable": true }, @@ -1967,7 +1967,7 @@ }, { "cell_type": "markdown", - "id": "a903fc25", + "id": "b262f130", "metadata": { "editable": true }, @@ -1979,7 +1979,7 @@ }, { "cell_type": "markdown", - "id": "0457e928", + "id": "a3058264", "metadata": { "editable": true }, @@ -1994,7 +1994,7 @@ }, { "cell_type": "markdown", - "id": "9bbfc263", + "id": "d5ddb569", "metadata": { "editable": true }, @@ -2007,7 +2007,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "c39e3e8b", + "id": "70d399eb", "metadata": { "collapsed": false, "editable": true @@ -2064,7 +2064,7 @@ }, { "cell_type": "markdown", - "id": "72247c35", + "id": "e3d8f7df", "metadata": { "editable": true }, @@ -2075,7 +2075,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "61003ccc", + "id": "8a1ba802", "metadata": { "collapsed": false, "editable": true @@ -2102,7 +2102,7 @@ }, { "cell_type": "markdown", - "id": "8168d80a", + "id": "48eda1cc", "metadata": { "editable": true }, @@ -2114,7 +2114,7 @@ }, { "cell_type": "markdown", - "id": "946a7392", + "id": "abf2a3dd", "metadata": { "editable": true }, @@ -2126,7 +2126,7 @@ }, { "cell_type": "markdown", - "id": "47969ccc", + "id": "719e68d8", "metadata": { "editable": true }, @@ -2136,7 +2136,7 @@ }, { "cell_type": "markdown", - "id": "efdf37a2", + "id": "1597f251", "metadata": { "editable": true }, @@ -2150,7 +2150,7 @@ }, { "cell_type": "markdown", - "id": "480c4e6a", + "id": "5dde41b4", "metadata": { "editable": true }, @@ -2160,7 +2160,7 @@ }, { "cell_type": "markdown", - "id": "fc4e15ae", + "id": "982b0a69", "metadata": { "editable": true }, @@ -2172,7 +2172,7 @@ }, { "cell_type": "markdown", - "id": "1d7d09cd", + "id": "16b0fb72", "metadata": { "editable": true }, @@ -2183,7 +2183,7 @@ }, { "cell_type": "markdown", - "id": "5194a928", + "id": "8c3e10f3", "metadata": { "editable": true }, @@ -2198,7 +2198,7 @@ }, { "cell_type": "markdown", - "id": "f50f65e6", + "id": "b643d525", "metadata": { "editable": true }, @@ -2212,7 +2212,7 @@ }, { "cell_type": "markdown", - "id": "d0903aad", + "id": "ad4765f6", "metadata": { "editable": true }, @@ -2223,7 +2223,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "f77d8aec", + "id": "da0f3027", "metadata": { "collapsed": false, "editable": true @@ -2284,7 +2284,7 @@ }, { "cell_type": "markdown", - "id": "eb135b12", + "id": "8e118b9d", "metadata": { "editable": true }, @@ -2306,7 +2306,7 @@ }, { "cell_type": "markdown", - "id": "76ccfd64", + "id": "43e561d4", "metadata": { "editable": true }, @@ -2319,7 +2319,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "3106ae68", + "id": "be29dc07", "metadata": { "collapsed": false, "editable": true @@ -2385,7 +2385,7 @@ }, { "cell_type": "markdown", - "id": "4a09ca84", + "id": "22fdea1b", "metadata": { "editable": true }, @@ -2396,7 +2396,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "afdc854d", + "id": "27b0632b", "metadata": { "collapsed": false, "editable": true @@ -2470,7 +2470,7 @@ }, { "cell_type": "markdown", - "id": "187eefc1", + "id": "2a6267ce", "metadata": { "editable": true }, @@ -2482,7 +2482,7 @@ }, { "cell_type": "markdown", - "id": "6dd22999", + "id": "1a10c6d4", "metadata": { "editable": true }, @@ -2503,7 +2503,7 @@ }, { "cell_type": "markdown", - "id": "1c21e598", + "id": "3c68aebd", "metadata": { "editable": true }, @@ -2535,7 +2535,7 @@ }, { "cell_type": "markdown", - "id": "55a20c5d", + "id": "8283d20b", "metadata": { "editable": true }, @@ -2552,7 +2552,7 @@ }, { "cell_type": "markdown", - "id": "f5966077", + "id": "fbdca45c", "metadata": { "editable": true }, @@ -2565,7 +2565,7 @@ }, { "cell_type": "markdown", - "id": "e2ce9ab8", + "id": "f1f1f068", "metadata": { "editable": true }, @@ -2578,7 +2578,7 @@ }, { "cell_type": "markdown", - "id": "d9333453", + "id": "66a52755", "metadata": { "editable": true }, @@ -2591,7 +2591,7 @@ }, { "cell_type": "markdown", - "id": "ef1ee4d3", + "id": "f47e74f0", "metadata": { "editable": true }, @@ -2605,7 +2605,7 @@ }, { "cell_type": "markdown", - "id": "09390a19", + "id": "0aeadf13", "metadata": { "editable": true }, @@ -2627,7 +2627,7 @@ }, { "cell_type": "markdown", - "id": "b75555e1", + "id": "49d99f49", "metadata": { "editable": true }, @@ -2642,7 +2642,7 @@ }, { "cell_type": "markdown", - "id": "b29e4d92", + "id": "959a2b24", "metadata": { "editable": true }, @@ -2654,7 +2654,7 @@ }, { "cell_type": "markdown", - "id": "43c24131", + "id": "affa536f", "metadata": { "editable": true }, @@ -2667,7 +2667,7 @@ }, { "cell_type": "markdown", - "id": "f5bcccfe", + "id": "bcfde5f4", "metadata": { "editable": true }, @@ -2681,7 +2681,7 @@ }, { "cell_type": "markdown", - "id": "5c2a21d3", + "id": "f308a718", "metadata": { "editable": true }, @@ -2692,7 +2692,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "f6c39f8d", + "id": "b31d32cd", "metadata": { "collapsed": false, "editable": true @@ -2717,7 +2717,7 @@ }, { "cell_type": "markdown", - "id": "0dc5d595", + "id": "228dae78", "metadata": { "editable": true }, @@ -2733,7 +2733,7 @@ }, { "cell_type": "markdown", - "id": "b72fbc30", + "id": "31c0b03e", "metadata": { "editable": true }, @@ -2754,7 +2754,7 @@ }, { "cell_type": "markdown", - "id": "35db732b", + "id": "32b211da", "metadata": { "editable": true }, @@ -2774,7 +2774,7 @@ }, { "cell_type": "markdown", - "id": "705c8d83", + "id": "f794af58", "metadata": { "editable": true }, @@ -2793,7 +2793,7 @@ { "cell_type": "code", "execution_count": 13, - "id": "d30150f7", + "id": "72c1bec2", "metadata": { "collapsed": false, "editable": true @@ -2828,7 +2828,7 @@ }, { "cell_type": "markdown", - "id": "a5fab6e0", + "id": "611a188b", "metadata": { "editable": true }, @@ -2841,7 +2841,7 @@ { "cell_type": "code", "execution_count": 14, - "id": "a00269ad", + "id": "7be674cb", "metadata": { "collapsed": false, "editable": true @@ -2918,7 +2918,7 @@ }, { "cell_type": "markdown", - "id": "1c87e8f8", + "id": "3525ebc9", "metadata": { "editable": true }, @@ -2933,7 +2933,7 @@ }, { "cell_type": "markdown", - "id": "0a059042", + "id": "72f723b6", "metadata": { "editable": true }, @@ -2948,7 +2948,7 @@ }, { "cell_type": "markdown", - "id": "6390a129", + "id": "16ac1388", "metadata": { "editable": true }, @@ -2960,7 +2960,7 @@ }, { "cell_type": "markdown", - "id": "819f92b8", + "id": "08d79365", "metadata": { "editable": true }, @@ -2978,7 +2978,7 @@ }, { "cell_type": "markdown", - "id": "f00de63c", + "id": "ffdb814c", "metadata": { "editable": true }, @@ -2997,7 +2997,7 @@ }, { "cell_type": "markdown", - "id": "2b7f4f9b", + "id": "5e114fda", "metadata": { "editable": true }, @@ -3009,7 +3009,7 @@ }, { "cell_type": "markdown", - "id": "9204976e", + "id": "8293d9ba", "metadata": { "editable": true }, @@ -3019,7 +3019,7 @@ }, { "cell_type": "markdown", - "id": "29e64510", + "id": "de7d6799", "metadata": { "editable": true }, @@ -3035,7 +3035,7 @@ }, { "cell_type": "markdown", - "id": "a4ddeb6b", + "id": "ba2bc11b", "metadata": { "editable": true }, @@ -3047,7 +3047,7 @@ }, { "cell_type": "markdown", - "id": "72f692f0", + "id": "08adfe31", "metadata": { "editable": true }, @@ -3057,7 +3057,7 @@ }, { "cell_type": "markdown", - "id": "8f41eeba", + "id": "5f9de2b1", "metadata": { "editable": true }, @@ -3069,7 +3069,7 @@ }, { "cell_type": "markdown", - "id": "bc96de6b", + "id": "cbd227bd", "metadata": { "editable": true }, @@ -3079,7 +3079,7 @@ }, { "cell_type": "markdown", - "id": "c9cf2f01", + "id": "a6eac778", "metadata": { "editable": true }, @@ -3091,7 +3091,7 @@ }, { "cell_type": "markdown", - "id": "5fc6491d", + "id": "1a81ccb9", "metadata": { "editable": true }, @@ -3107,7 +3107,7 @@ }, { "cell_type": "markdown", - "id": "fc566a20", + "id": "ff8d8514", "metadata": { "editable": true }, @@ -3119,7 +3119,7 @@ }, { "cell_type": "markdown", - "id": "890fa973", + "id": "64ca1cbe", "metadata": { "editable": true }, @@ -3152,7 +3152,7 @@ }, { "cell_type": "markdown", - "id": "e958e4c2", + "id": "000a6174", "metadata": { "editable": true }, @@ -3164,7 +3164,7 @@ }, { "cell_type": "markdown", - "id": "277711eb", + "id": "91c16167", "metadata": { "editable": true }, @@ -3182,7 +3182,7 @@ }, { "cell_type": "markdown", - "id": "efc50ab5", + "id": "44a6513e", "metadata": { "editable": true }, @@ -3192,7 +3192,7 @@ }, { "cell_type": "markdown", - "id": "a5abcf0b", + "id": "4d3f46ab", "metadata": { "editable": true }, @@ -3223,7 +3223,7 @@ }, { "cell_type": "markdown", - "id": "972eeee6", + "id": "3ab65226", "metadata": { "editable": true }, @@ -3238,7 +3238,7 @@ }, { "cell_type": "markdown", - "id": "f3e5aef6", + "id": "63af5a3d", "metadata": { "editable": true }, @@ -3256,7 +3256,7 @@ }, { "cell_type": "markdown", - "id": "0fba3e6a", + "id": "aa72ec54", "metadata": { "editable": true }, @@ -3268,7 +3268,7 @@ }, { "cell_type": "markdown", - "id": "53a91982", + "id": "d20282e6", "metadata": { "editable": true }, @@ -3280,7 +3280,7 @@ }, { "cell_type": "markdown", - "id": "50547f38", + "id": "a23484c9", "metadata": { "editable": true }, @@ -3298,7 +3298,7 @@ }, { "cell_type": "markdown", - "id": "86fe9ed3", + "id": "c6fdd601", "metadata": { "editable": true }, @@ -3321,7 +3321,7 @@ }, { "cell_type": "markdown", - "id": "7cd27183", + "id": "922c7fbd", "metadata": { "editable": true }, @@ -3339,7 +3339,7 @@ }, { "cell_type": "markdown", - "id": "ab967150", + "id": "e5c76084", "metadata": { "editable": true }, @@ -3351,7 +3351,7 @@ }, { "cell_type": "markdown", - "id": "5c70db98", + "id": "6ace1786", "metadata": { "editable": true }, @@ -3363,7 +3363,7 @@ }, { "cell_type": "markdown", - "id": "0503bdfd", + "id": "0b4a86ec", "metadata": { "editable": true }, @@ -3375,7 +3375,7 @@ }, { "cell_type": "markdown", - "id": "88165a6f", + "id": "c6d9336a", "metadata": { "editable": true }, @@ -3387,7 +3387,7 @@ }, { "cell_type": "markdown", - "id": "d295a6ac", + "id": "4cbddf1a", "metadata": { "editable": true }, @@ -3399,7 +3399,7 @@ }, { "cell_type": "markdown", - "id": "405ccb0a", + "id": "8a666e9f", "metadata": { "editable": true }, @@ -3416,7 +3416,7 @@ }, { "cell_type": "markdown", - "id": "15512517", + "id": "a4cccc1e", "metadata": { "editable": true }, @@ -3435,7 +3435,7 @@ }, { "cell_type": "markdown", - "id": "9f3fe2ce", + "id": "15812461", "metadata": { "editable": true }, @@ -3447,7 +3447,7 @@ }, { "cell_type": "markdown", - "id": "fe96771f", + "id": "3e5cc6d5", "metadata": { "editable": true }, @@ -3467,7 +3467,7 @@ }, { "cell_type": "markdown", - "id": "380ee721", + "id": "eda86286", "metadata": { "editable": true }, @@ -3505,7 +3505,7 @@ }, { "cell_type": "markdown", - "id": "f6648761", + "id": "be3e7165", "metadata": { "editable": true }, @@ -3517,7 +3517,7 @@ }, { "cell_type": "markdown", - "id": "df6b487a", + "id": "26ca3832", "metadata": { "editable": true }, @@ -3527,7 +3527,7 @@ }, { "cell_type": "markdown", - "id": "cd355c9d", + "id": "7474a5bc", "metadata": { "editable": true }, @@ -3539,7 +3539,7 @@ }, { "cell_type": "markdown", - "id": "ffb3aed8", + "id": "b893478c", "metadata": { "editable": true }, @@ -3550,7 +3550,7 @@ { "cell_type": "code", "execution_count": 15, - "id": "c01acfbf", + "id": "3d148b31", "metadata": { "collapsed": false, "editable": true @@ -3595,7 +3595,7 @@ }, { "cell_type": "markdown", - "id": "bdd7abde", + "id": "00451e68", "metadata": { "editable": true }, @@ -3612,7 +3612,7 @@ { "cell_type": "code", "execution_count": 16, - "id": "898937c9", + "id": "28053212", "metadata": { "collapsed": false, "editable": true @@ -3640,7 +3640,7 @@ }, { "cell_type": "markdown", - "id": "3b343ba9", + "id": "ed2f8b44", "metadata": { "editable": true }, @@ -3655,7 +3655,7 @@ { "cell_type": "code", "execution_count": 17, - "id": "334ce966", + "id": "ad29df73", "metadata": { "collapsed": false, "editable": true @@ -3699,7 +3699,7 @@ }, { "cell_type": "markdown", - "id": "8b661c94", + "id": "0819f320", "metadata": { "editable": true }, @@ -3709,7 +3709,7 @@ }, { "cell_type": "markdown", - "id": "f6778038", + "id": "1d7ccac2", "metadata": { "editable": true }, @@ -3720,7 +3720,7 @@ { "cell_type": "code", "execution_count": 18, - "id": "13700fa8", + "id": "bb9e4228", "metadata": { "collapsed": false, "editable": true @@ -3748,7 +3748,7 @@ }, { "cell_type": "markdown", - "id": "daa46b77", + "id": "be4e6d99", "metadata": { "editable": true }, @@ -3763,7 +3763,7 @@ }, { "cell_type": "markdown", - "id": "9d975664", + "id": "ba08cf51", "metadata": { "editable": true }, @@ -3774,7 +3774,7 @@ { "cell_type": "code", "execution_count": 19, - "id": "2256de07", + "id": "2d175328", "metadata": { "collapsed": false, "editable": true @@ -3802,7 +3802,7 @@ }, { "cell_type": "markdown", - "id": "4a6deaaf", + "id": "aff28e3a", "metadata": { "editable": true }, @@ -3813,7 +3813,7 @@ { "cell_type": "code", "execution_count": 20, - "id": "76ab0823", + "id": "edabb1dd", "metadata": { "collapsed": false, "editable": true @@ -3838,7 +3838,7 @@ }, { "cell_type": "markdown", - "id": "c7e1ff75", + "id": "af563ee3", "metadata": { "editable": true }, @@ -3849,7 +3849,7 @@ { "cell_type": "code", "execution_count": 21, - "id": "9b7bc7ac", + "id": "ac3ad080", "metadata": { "collapsed": false, "editable": true @@ -3885,7 +3885,7 @@ { "cell_type": "code", "execution_count": 22, - "id": "f48ea612", + "id": "a5beeab6", "metadata": { "collapsed": false, "editable": true @@ -3905,7 +3905,7 @@ }, { "cell_type": "markdown", - "id": "41d0c6f4", + "id": "528ba061", "metadata": { "editable": true }, @@ -3916,7 +3916,7 @@ { "cell_type": "code", "execution_count": 23, - "id": "96932b44", + "id": "8237c400", "metadata": { "collapsed": false, "editable": true @@ -3954,7 +3954,7 @@ }, { "cell_type": "markdown", - "id": "9f7eae7b", + "id": "94a469eb", "metadata": { "editable": true }, @@ -3964,7 +3964,7 @@ }, { "cell_type": "markdown", - "id": "5441446f", + "id": "53771be6", "metadata": { "editable": true }, @@ -3978,7 +3978,7 @@ { "cell_type": "code", "execution_count": 24, - "id": "810cd2a6", + "id": "22df1bf3", "metadata": { "collapsed": false, "editable": true @@ -4000,7 +4000,7 @@ }, { "cell_type": "markdown", - "id": "3699391b", + "id": "a5ca665d", "metadata": { "editable": true }, @@ -4010,7 +4010,7 @@ }, { "cell_type": "markdown", - "id": "2db124a4", + "id": "8c6ab4ca", "metadata": { "editable": true }, @@ -4021,7 +4021,7 @@ { "cell_type": "code", "execution_count": 25, - "id": "3c3b74ba", + "id": "66cdb9e9", "metadata": { "collapsed": false, "editable": true @@ -4043,7 +4043,7 @@ }, { "cell_type": "markdown", - "id": "37817c30", + "id": "a99da8ee", "metadata": { "editable": true }, @@ -4056,7 +4056,7 @@ { "cell_type": "code", "execution_count": 26, - "id": "d8e9ea75", + "id": "4190a01e", "metadata": { "collapsed": false, "editable": true @@ -4081,7 +4081,7 @@ }, { "cell_type": "markdown", - "id": "64351a6b", + "id": "ce7085b3", "metadata": { "editable": true }, @@ -4093,7 +4093,7 @@ { "cell_type": "code", "execution_count": 27, - "id": "b61840f6", + "id": "bd35ddaa", "metadata": { "collapsed": false, "editable": true @@ -4108,7 +4108,7 @@ }, { "cell_type": "markdown", - "id": "d87544e5", + "id": "d35d2531", "metadata": { "editable": true }, @@ -4123,7 +4123,7 @@ { "cell_type": "code", "execution_count": 28, - "id": "0b8b13c8", + "id": "5163580e", "metadata": { "collapsed": false, "editable": true @@ -4183,7 +4183,7 @@ }, { "cell_type": "markdown", - "id": "7e0cfb4d", + "id": "4068063b", "metadata": { "editable": true }, @@ -4194,7 +4194,7 @@ { "cell_type": "code", "execution_count": 29, - "id": "2ba6e4bb", + "id": "86743170", "metadata": { "collapsed": false, "editable": true @@ -4258,7 +4258,7 @@ }, { "cell_type": "markdown", - "id": "671d74e3", + "id": "ca006785", "metadata": { "editable": true }, @@ -4269,7 +4269,7 @@ { "cell_type": "code", "execution_count": 30, - "id": "d282ba32", + "id": "99c1bf17", "metadata": { "collapsed": false, "editable": true @@ -4318,7 +4318,7 @@ }, { "cell_type": "markdown", - "id": "5504a30b", + "id": "b6e354fb", "metadata": { "editable": true }, @@ -4330,7 +4330,7 @@ { "cell_type": "code", "execution_count": 31, - "id": "3e36d821", + "id": "92100e28", "metadata": { "collapsed": false, "editable": true @@ -4414,7 +4414,7 @@ }, { "cell_type": "markdown", - "id": "8115b858", + "id": "04a93f00", "metadata": { "editable": true }, @@ -4425,7 +4425,7 @@ { "cell_type": "code", "execution_count": 32, - "id": "b4346837", + "id": "cf2d793b", "metadata": { "collapsed": false, "editable": true @@ -4503,7 +4503,7 @@ }, { "cell_type": "markdown", - "id": "944be76d", + "id": "54ff0cfd", "metadata": { "editable": true }, @@ -4514,7 +4514,7 @@ { "cell_type": "code", "execution_count": 33, - "id": "2bd8357a", + "id": "bc5fc421", "metadata": { "collapsed": false, "editable": true @@ -4578,7 +4578,7 @@ }, { "cell_type": "markdown", - "id": "8069cc8c", + "id": "5a4e61b4", "metadata": { "editable": true }, @@ -4588,7 +4588,87 @@ }, { "cell_type": "markdown", - "id": "990df1f5", + "id": "c06228d6", + "metadata": { + "editable": true + }, + "source": [ + "## RMSprop for adaptive learning rate with Stochastic Gradient Descent" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "ad77ac5d", + "metadata": { + "collapsed": false, + "editable": true + }, + "outputs": [], + "source": [ + "# Using Autograd to calculate gradients using RMSprop and Stochastic Gradient descent\n", + "# OLS example\n", + "from random import random, seed\n", + "import numpy as np\n", + "import autograd.numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from autograd import grad\n", + "\n", + "# Note change from previous example\n", + "def CostOLS(y,X,theta):\n", + " return np.sum((y-X @ theta)**2)\n", + "\n", + "n = 10000\n", + "x = np.random.rand(n,1)\n", + "y = 2.0+3*x +4*x*x# +np.random.randn(n,1)\n", + "\n", + "X = np.c_[np.ones((n,1)), x, x*x]\n", + "XT_X = X.T @ X\n", + "theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)\n", + "print(\"Own inversion\")\n", + "print(theta_linreg)\n", + "\n", + "\n", + "# Note that we request the derivative wrt third argument (theta, 2 here)\n", + "training_gradient = grad(CostOLS,2)\n", + "# Define parameters for Stochastic Gradient Descent\n", + "n_epochs = 50\n", + "M = 5 #size of each minibatch\n", + "m = int(n/M) #number of minibatches\n", + "# Guess for unknown parameters theta\n", + "theta = np.random.randn(3,1)\n", + "\n", + "# Value for learning rate\n", + "eta = 0.01\n", + "# Value for parameter rho\n", + "rho = 0.99\n", + "# Including AdaGrad parameter to avoid possible division by zero\n", + "delta = 1e-8\n", + "for epoch in range(n_epochs):\n", + " Giter = np.zeros(shape=(3,3))\n", + " for i in range(m):\n", + " random_index = M*np.random.randint(m)\n", + " xi = X[random_index:random_index+M]\n", + " yi = y[random_index:random_index+M]\n", + " gradients = (1.0/M)*training_gradient(yi, xi, theta)\n", + "\t# Previous value for the outer product of gradients\n", + " Previous = Giter\n", + "\t# Accumulated gradient\n", + " Giter +=gradients @ gradients.T\n", + "\t# Scaling with rho the new and the previous results\n", + " Gnew = (rho*Previous+(1-rho)*Giter)\n", + "\t# Taking the diagonal only and inverting\n", + " Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Gnew)))]\n", + "\t# Hadamard product\n", + " update = np.multiply(Ginverse,gradients)\n", + " theta -= update\n", + "print(\"theta from own RMSprop\")\n", + "print(theta)" + ] + }, + { + "cell_type": "markdown", + "id": "3840836c", "metadata": { "editable": true }, @@ -4598,8 +4678,8 @@ }, { "cell_type": "code", - "execution_count": 34, - "id": "ce42a59a", + "execution_count": 35, + "id": "b340e498", "metadata": { "collapsed": false, "editable": true @@ -4643,7 +4723,7 @@ }, { "cell_type": "markdown", - "id": "d4e18db5", + "id": "71a25972", "metadata": { "editable": true }, @@ -4661,8 +4741,8 @@ }, { "cell_type": "code", - "execution_count": 35, - "id": "2fe09a96", + "execution_count": 36, + "id": "a5b15751", "metadata": { "collapsed": false, "editable": true @@ -4682,7 +4762,7 @@ }, { "cell_type": "markdown", - "id": "c1960c06", + "id": "ab953a89", "metadata": { "editable": true }, diff --git a/doc/src/week39/adagrad.py b/doc/src/week39/adagrad.py deleted file mode 100644 index e072281a3..000000000 --- a/doc/src/week39/adagrad.py +++ /dev/null @@ -1,31 +0,0 @@ -# Using Autograd to calculate gradients using AdaGrad and Stochastic Gradient descent -# OLS example -from random import random, seed -import numpy as np -import autograd.numpy as np -import matplotlib.pyplot as plt - -n = 10000 -x = np.random.rand(n,1) -y = 4*x+3*x*x -# Setting up Design matrix -X = np.c_[np.ones((n,1)), x, x*x] -XTX = X.T @ X -XTy = X.T @ y -theta_linreg = np.linalg.pinv(XTX) @ (XTy) -print("Own inversion") -print(theta_linreg) - - -beta = np.random.randn(3,1) -eta = 0.01 -delta = 1e-8 -Niterations = 10000 -Giter = np.zeros(shape=(3,3)) -for iter in range(Niterations): - gradient = (2.0/n)*(XTX @ beta - XTy) - Giter +=gradient @ gradient.T - Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Giter)))] - beta -= np.multiply(Ginverse,gradient) - -print("Optimal parameters with AdaGrad",beta) diff --git a/doc/src/week39/adagradSGD.py b/doc/src/week39/adagradSGD.py index 157638fc8..4aa6688cd 100644 --- a/doc/src/week39/adagradSGD.py +++ b/doc/src/week39/adagradSGD.py @@ -43,11 +43,6 @@ for epoch in range(n_epochs): gradients = (1.0/M)*training_gradient(yi, xi, theta) Giter +=gradients @ gradients.T Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Giter)))] - - # calculate squared gradient by Hadamard multiplication -# r += (gradients*gradients) -# r = np.sum(gradients*gradients) - # compute update update = np.multiply(Ginverse,gradients) theta -= update print("theta from own AdaGrad") diff --git a/doc/src/week39/codes/adagradSGD.py b/doc/src/week39/codes/adagradSGD.py new file mode 100644 index 000000000..4aa6688cd --- /dev/null +++ b/doc/src/week39/codes/adagradSGD.py @@ -0,0 +1,50 @@ +# Using Autograd to calculate gradients using AdaGrad and Stochastic Gradient descent +# OLS example +from random import random, seed +import numpy as np +import autograd.numpy as np +import matplotlib.pyplot as plt +from autograd import grad + +# Note change from previous example +def CostOLS(y,X,theta): + return np.sum((y-X @ theta)**2) + +n = 10000 +x = np.random.rand(n,1) +y = 2.0+3*x +4*x*x# +np.random.randn(n,1) + +X = np.c_[np.ones((n,1)), x, x*x] +XT_X = X.T @ X +theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y) +print("Own inversion") +print(theta_linreg) + + +# Note that we request the derivative wrt third argument (theta, 2 here) +training_gradient = grad(CostOLS,2) +# Define parameters for Stochastic Gradient Descent +n_epochs = 50 +M = 5 #size of each minibatch +m = int(n/M) #number of minibatches +# Guess for unknown parameters theta +theta = np.random.randn(3,1) + +# Value for learning rate +eta = 0.01 +# Including AdaGrad parameter to avoid possible division by zero +delta = 1e-8 +for epoch in range(n_epochs): + Giter = np.zeros(shape=(3,3)) + for i in range(m): + random_index = M*np.random.randint(m) + xi = X[random_index:random_index+M] + yi = y[random_index:random_index+M] + gradients = (1.0/M)*training_gradient(yi, xi, theta) + Giter +=gradients @ gradients.T + Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Giter)))] + update = np.multiply(Ginverse,gradients) + theta -= update +print("theta from own AdaGrad") +print(theta) + diff --git a/doc/src/week39/codes/rmspronoplot.py b/doc/src/week39/codes/rmspronoplot.py new file mode 100644 index 000000000..eda585e25 --- /dev/null +++ b/doc/src/week39/codes/rmspronoplot.py @@ -0,0 +1,52 @@ +# Using Autograd to calculate gradients using AdaGrad and Stochastic Gradient descent +# OLS example +from random import random, seed +import numpy as np +import autograd.numpy as np +import matplotlib.pyplot as plt +from autograd import grad + +# Note change from previous example +def CostOLS(y,X,theta): + return np.sum((y-X @ theta)**2) + +n = 10000 +x = np.random.rand(n,1) +y = 2.0+3*x +4*x*x# +np.random.randn(n,1) + +X = np.c_[np.ones((n,1)), x, x*x] +XT_X = X.T @ X +theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y) +print("Own inversion") +print(theta_linreg) + + +# Note that we request the derivative wrt third argument (theta, 2 here) +training_gradient = grad(CostOLS,2) +# Define parameters for Stochastic Gradient Descent +n_epochs = 50 +M = 5 #size of each minibatch +m = int(n/M) #number of minibatches +# Guess for unknown parameters theta +theta = np.random.randn(3,1) + +# Value for learning rate +eta = 0.01 +rho = 0.99 +# Including AdaGrad parameter to avoid possible division by zero +delta = 1e-8 +for epoch in range(n_epochs): + Giter = np.zeros(shape=(3,3)) + for i in range(m): + random_index = M*np.random.randint(m) + xi = X[random_index:random_index+M] + yi = y[random_index:random_index+M] + gradients = (1.0/M)*training_gradient(yi, xi, theta) + Previous = Giter + Giter +=gradients @ gradients.T + Gnew = (rho*Previous+(1-rho)*Giter) + Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Gnew)))] + update = np.multiply(Ginverse,gradients) + theta -= update +print("theta from own AdaGrad") +print(theta) diff --git a/doc/src/week39/rmsprop.py b/doc/src/week39/rmsprop.py new file mode 100644 index 000000000..eda585e25 --- /dev/null +++ b/doc/src/week39/rmsprop.py @@ -0,0 +1,52 @@ +# Using Autograd to calculate gradients using AdaGrad and Stochastic Gradient descent +# OLS example +from random import random, seed +import numpy as np +import autograd.numpy as np +import matplotlib.pyplot as plt +from autograd import grad + +# Note change from previous example +def CostOLS(y,X,theta): + return np.sum((y-X @ theta)**2) + +n = 10000 +x = np.random.rand(n,1) +y = 2.0+3*x +4*x*x# +np.random.randn(n,1) + +X = np.c_[np.ones((n,1)), x, x*x] +XT_X = X.T @ X +theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y) +print("Own inversion") +print(theta_linreg) + + +# Note that we request the derivative wrt third argument (theta, 2 here) +training_gradient = grad(CostOLS,2) +# Define parameters for Stochastic Gradient Descent +n_epochs = 50 +M = 5 #size of each minibatch +m = int(n/M) #number of minibatches +# Guess for unknown parameters theta +theta = np.random.randn(3,1) + +# Value for learning rate +eta = 0.01 +rho = 0.99 +# Including AdaGrad parameter to avoid possible division by zero +delta = 1e-8 +for epoch in range(n_epochs): + Giter = np.zeros(shape=(3,3)) + for i in range(m): + random_index = M*np.random.randint(m) + xi = X[random_index:random_index+M] + yi = y[random_index:random_index+M] + gradients = (1.0/M)*training_gradient(yi, xi, theta) + Previous = Giter + Giter +=gradients @ gradients.T + Gnew = (rho*Previous+(1-rho)*Giter) + Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Gnew)))] + update = np.multiply(Ginverse,gradients) + theta -= update +print("theta from own AdaGrad") +print(theta) diff --git a/doc/src/week39/week39.do.txt b/doc/src/week39/week39.do.txt index 786fa02c9..d0c197d2c 100644 --- a/doc/src/week39/week39.do.txt +++ b/doc/src/week39/week39.do.txt @@ -2491,6 +2491,70 @@ print(theta) Running this code we note an almost perfect agreement with the results from matrix inversion. +!split +===== RMSprop for adaptive learning rate with Stochastic Gradient Descent ===== +!bc pycod +# Using Autograd to calculate gradients using RMSprop and Stochastic Gradient descent +# OLS example +from random import random, seed +import numpy as np +import autograd.numpy as np +import matplotlib.pyplot as plt +from autograd import grad + +# Note change from previous example +def CostOLS(y,X,theta): + return np.sum((y-X @ theta)**2) + +n = 10000 +x = np.random.rand(n,1) +y = 2.0+3*x +4*x*x# +np.random.randn(n,1) + +X = np.c_[np.ones((n,1)), x, x*x] +XT_X = X.T @ X +theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y) +print("Own inversion") +print(theta_linreg) + + +# Note that we request the derivative wrt third argument (theta, 2 here) +training_gradient = grad(CostOLS,2) +# Define parameters for Stochastic Gradient Descent +n_epochs = 50 +M = 5 #size of each minibatch +m = int(n/M) #number of minibatches +# Guess for unknown parameters theta +theta = np.random.randn(3,1) + +# Value for learning rate +eta = 0.01 +# Value for parameter rho +rho = 0.99 +# Including AdaGrad parameter to avoid possible division by zero +delta = 1e-8 +for epoch in range(n_epochs): + Giter = np.zeros(shape=(3,3)) + for i in range(m): + random_index = M*np.random.randint(m) + xi = X[random_index:random_index+M] + yi = y[random_index:random_index+M] + gradients = (1.0/M)*training_gradient(yi, xi, theta) + # Previous value for the outer product of gradients + Previous = Giter + # Accumulated gradient + Giter +=gradients @ gradients.T + # Scaling with rho the new and the previous results + Gnew = (rho*Previous+(1-rho)*Giter) + # Taking the diagonal only and inverting + Ginverse = np.c_[eta/(delta+np.sqrt(np.diagonal(Gnew)))] + # Hadamard product + update = np.multiply(Ginverse,gradients) + theta -= update +print("theta from own RMSprop") +print(theta) +!ec + + !split ===== And Logistic Regression =====