diff --git a/doc/pub/week37/html/._week37-bs000.html b/doc/pub/week37/html/._week37-bs000.html index 541ecc814..cfe72140a 100644 --- a/doc/pub/week37/html/._week37-bs000.html +++ b/doc/pub/week37/html/._week37-bs000.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -300,7 +319,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs001.html b/doc/pub/week37/html/._week37-bs001.html index 3edf27444..8ce33a94c 100644 --- a/doc/pub/week37/html/._week37-bs001.html +++ b/doc/pub/week37/html/._week37-bs001.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -291,7 +310,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs002.html b/doc/pub/week37/html/._week37-bs002.html index f673291cf..56c23018e 100644 --- a/doc/pub/week37/html/._week37-bs002.html +++ b/doc/pub/week37/html/._week37-bs002.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -263,7 +282,7 @@ MathJax.Hub.Config({
      -
    1. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at https://www.deeplearningbook.org/contents/numerical.html and chapter 8.3-8.5 at URL::https://www.deeplearningbook.org/contents/optimization.html"
    2. +
    3. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at https://www.deeplearningbook.org/contents/numerical.html and chapter 8.3-8.5 at https://www.deeplearningbook.org/contents/optimization.html
    4. Rashcka et al, pages 37-44 and pages 278-283 with focus on linear regression.
    5. Video on gradient descent at https://www.youtube.com/watch?v=sDv4f4s2SB8
    6. Video on Stochastic gradient descent at https://www.youtube.com/watch?v=vMh0zPT0tLI
    7. @@ -289,7 +308,7 @@ MathJax.Hub.Config({
    8. 11
    9. 12
    10. ...
    11. -
    12. 46
    13. +
    14. 48
    15. »
    16. diff --git a/doc/pub/week37/html/._week37-bs003.html b/doc/pub/week37/html/._week37-bs003.html index ccb14f2ac..fca95acdf 100644 --- a/doc/pub/week37/html/._week37-bs003.html +++ b/doc/pub/week37/html/._week37-bs003.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    17. Program example for gradient descent with Ridge Regression
    18. Using gradient descent methods, limitations
    19. Improving gradient descent with momentum
    20. -
    21. Same code but now with momentum gradient descent
    22. -
    23. Overview video on Stochastic Gradient Descent
    24. +
    25. Same code but now with momentum gradient descent
    26. +
    27. Overview video on Stochastic Gradient Descent (SGD)
    28. Batches and mini-batches
    29. -
    30. Stochastic Gradient Descent (SGD)
    31. -
    32. Stochastic Gradient Descent
    33. -
    34. Computation of gradients
    35. -
    36. SGD example
    37. -
    38. The gradient step
    39. -
    40. Simple example code
    41. -
    42. When do we stop?
    43. -
    44. Slightly different approach
    45. -
    46. Time decay rate
    47. -
    48. Code with a Number of Minibatches which varies
    49. -
    50. Replace or not
    51. -
    52. Momentum based GD
    53. -
    54. More on momentum based approaches
    55. -
    56. Momentum parameter
    57. -
    58. Second moment of the gradient
    59. -
    60. RMS prop
    61. -
    62. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    63. -
    64. Algorithms and codes for Adagrad, RMSprop and Adam
    65. -
    66. Practical tips
    67. -
    68. Sneaking in automatic differentiation using Autograd
    69. -
    70. Same code but now with momentum gradient descent
    71. -
    72. But none of these can compete with Newton's method
    73. -
    74. Including Stochastic Gradient Descent with Autograd
    75. -
    76. Same code but now with momentum gradient descent
    77. -
    78. Similar (second order function now) problem but now with AdaGrad
    79. -
    80. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    81. -
    82. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    83. -
    84. Material for the lab sessions
    85. +
    86. Pros and cons
    87. +
    88. Convergence rates
    89. +
    90. Accuracy
    91. +
    92. Stochastic Gradient Descent (SGD)
    93. +
    94. Stochastic Gradient Descent
    95. +
    96. Computation of gradients
    97. +
    98. SGD example
    99. +
    100. The gradient step
    101. +
    102. Simple example code
    103. +
    104. When do we stop?
    105. +
    106. Slightly different approach
    107. +
    108. Time decay rate
    109. +
    110. Code with a Number of Minibatches which varies
    111. +
    112. Replace or not
    113. +
    114. Momentum based GD
    115. +
    116. More on momentum based approaches
    117. +
    118. Momentum parameter
    119. +
    120. Second moment of the gradient
    121. +
    122. RMS prop
    123. +
    124. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    125. +
    126. Algorithms and codes for Adagrad, RMSprop and Adam
    127. +
    128. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    129. +
    130. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    131. +
    132. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    133. +
    134. Practical tips
    135. +
    136. Sneaking in auotmatic differentiation using Autograd
    137. +
    138. Same code but now with momentum gradient descent
    139. +
    140. Including Stochastic Gradient Descent with Autograd
    141. +
    142. Same code but now with momentum gradient descent
    143. +
    144. Similar (second order function now) problem but now with AdaGrad
    145. +
    146. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    147. +
    148. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    149. +
    150. Material for the lab sessions
    151. @@ -278,7 +297,7 @@ MathJax.Hub.Config({
    152. 12
    153. 13
    154. ...
    155. -
    156. 46
    157. +
    158. 48
    159. »
    160. diff --git a/doc/pub/week37/html/._week37-bs004.html b/doc/pub/week37/html/._week37-bs004.html index 5136d1a63..db8020187 100644 --- a/doc/pub/week37/html/._week37-bs004.html +++ b/doc/pub/week37/html/._week37-bs004.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    161. Program example for gradient descent with Ridge Regression
    162. Using gradient descent methods, limitations
    163. Improving gradient descent with momentum
    164. -
    165. Same code but now with momentum gradient descent
    166. -
    167. Overview video on Stochastic Gradient Descent
    168. +
    169. Same code but now with momentum gradient descent
    170. +
    171. Overview video on Stochastic Gradient Descent (SGD)
    172. Batches and mini-batches
    173. -
    174. Stochastic Gradient Descent (SGD)
    175. -
    176. Stochastic Gradient Descent
    177. -
    178. Computation of gradients
    179. -
    180. SGD example
    181. -
    182. The gradient step
    183. -
    184. Simple example code
    185. -
    186. When do we stop?
    187. -
    188. Slightly different approach
    189. -
    190. Time decay rate
    191. -
    192. Code with a Number of Minibatches which varies
    193. -
    194. Replace or not
    195. -
    196. Momentum based GD
    197. -
    198. More on momentum based approaches
    199. -
    200. Momentum parameter
    201. -
    202. Second moment of the gradient
    203. -
    204. RMS prop
    205. -
    206. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    207. -
    208. Algorithms and codes for Adagrad, RMSprop and Adam
    209. -
    210. Practical tips
    211. -
    212. Sneaking in automatic differentiation using Autograd
    213. -
    214. Same code but now with momentum gradient descent
    215. -
    216. But none of these can compete with Newton's method
    217. -
    218. Including Stochastic Gradient Descent with Autograd
    219. -
    220. Same code but now with momentum gradient descent
    221. -
    222. Similar (second order function now) problem but now with AdaGrad
    223. -
    224. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    225. -
    226. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    227. -
    228. Material for the lab sessions
    229. +
    230. Pros and cons
    231. +
    232. Convergence rates
    233. +
    234. Accuracy
    235. +
    236. Stochastic Gradient Descent (SGD)
    237. +
    238. Stochastic Gradient Descent
    239. +
    240. Computation of gradients
    241. +
    242. SGD example
    243. +
    244. The gradient step
    245. +
    246. Simple example code
    247. +
    248. When do we stop?
    249. +
    250. Slightly different approach
    251. +
    252. Time decay rate
    253. +
    254. Code with a Number of Minibatches which varies
    255. +
    256. Replace or not
    257. +
    258. Momentum based GD
    259. +
    260. More on momentum based approaches
    261. +
    262. Momentum parameter
    263. +
    264. Second moment of the gradient
    265. +
    266. RMS prop
    267. +
    268. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    269. +
    270. Algorithms and codes for Adagrad, RMSprop and Adam
    271. +
    272. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    273. +
    274. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    275. +
    276. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    277. +
    278. Practical tips
    279. +
    280. Sneaking in auotmatic differentiation using Autograd
    281. +
    282. Same code but now with momentum gradient descent
    283. +
    284. Including Stochastic Gradient Descent with Autograd
    285. +
    286. Same code but now with momentum gradient descent
    287. +
    288. Similar (second order function now) problem but now with AdaGrad
    289. +
    290. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    291. +
    292. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    293. +
    294. Material for the lab sessions
    295. @@ -329,7 +348,7 @@ $$
    296. 13
    297. 14
    298. ...
    299. -
    300. 46
    301. +
    302. 48
    303. »
    304. diff --git a/doc/pub/week37/html/._week37-bs005.html b/doc/pub/week37/html/._week37-bs005.html index a2b3478ab..beec70c4e 100644 --- a/doc/pub/week37/html/._week37-bs005.html +++ b/doc/pub/week37/html/._week37-bs005.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    305. Program example for gradient descent with Ridge Regression
    306. Using gradient descent methods, limitations
    307. Improving gradient descent with momentum
    308. -
    309. Same code but now with momentum gradient descent
    310. -
    311. Overview video on Stochastic Gradient Descent
    312. +
    313. Same code but now with momentum gradient descent
    314. +
    315. Overview video on Stochastic Gradient Descent (SGD)
    316. Batches and mini-batches
    317. -
    318. Stochastic Gradient Descent (SGD)
    319. -
    320. Stochastic Gradient Descent
    321. -
    322. Computation of gradients
    323. -
    324. SGD example
    325. -
    326. The gradient step
    327. -
    328. Simple example code
    329. -
    330. When do we stop?
    331. -
    332. Slightly different approach
    333. -
    334. Time decay rate
    335. -
    336. Code with a Number of Minibatches which varies
    337. -
    338. Replace or not
    339. -
    340. Momentum based GD
    341. -
    342. More on momentum based approaches
    343. -
    344. Momentum parameter
    345. -
    346. Second moment of the gradient
    347. -
    348. RMS prop
    349. -
    350. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    351. -
    352. Algorithms and codes for Adagrad, RMSprop and Adam
    353. -
    354. Practical tips
    355. -
    356. Sneaking in automatic differentiation using Autograd
    357. -
    358. Same code but now with momentum gradient descent
    359. -
    360. But none of these can compete with Newton's method
    361. -
    362. Including Stochastic Gradient Descent with Autograd
    363. -
    364. Same code but now with momentum gradient descent
    365. -
    366. Similar (second order function now) problem but now with AdaGrad
    367. -
    368. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    369. -
    370. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    371. -
    372. Material for the lab sessions
    373. +
    374. Pros and cons
    375. +
    376. Convergence rates
    377. +
    378. Accuracy
    379. +
    380. Stochastic Gradient Descent (SGD)
    381. +
    382. Stochastic Gradient Descent
    383. +
    384. Computation of gradients
    385. +
    386. SGD example
    387. +
    388. The gradient step
    389. +
    390. Simple example code
    391. +
    392. When do we stop?
    393. +
    394. Slightly different approach
    395. +
    396. Time decay rate
    397. +
    398. Code with a Number of Minibatches which varies
    399. +
    400. Replace or not
    401. +
    402. Momentum based GD
    403. +
    404. More on momentum based approaches
    405. +
    406. Momentum parameter
    407. +
    408. Second moment of the gradient
    409. +
    410. RMS prop
    411. +
    412. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    413. +
    414. Algorithms and codes for Adagrad, RMSprop and Adam
    415. +
    416. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    417. +
    418. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    419. +
    420. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    421. +
    422. Practical tips
    423. +
    424. Sneaking in auotmatic differentiation using Autograd
    425. +
    426. Same code but now with momentum gradient descent
    427. +
    428. Including Stochastic Gradient Descent with Autograd
    429. +
    430. Same code but now with momentum gradient descent
    431. +
    432. Similar (second order function now) problem but now with AdaGrad
    433. +
    434. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    435. +
    436. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    437. +
    438. Material for the lab sessions
    439. @@ -298,7 +317,7 @@ $$
    440. 14
    441. 15
    442. ...
    443. -
    444. 46
    445. +
    446. 48
    447. »
    448. diff --git a/doc/pub/week37/html/._week37-bs006.html b/doc/pub/week37/html/._week37-bs006.html index f42693ebf..e8de7baf5 100644 --- a/doc/pub/week37/html/._week37-bs006.html +++ b/doc/pub/week37/html/._week37-bs006.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    449. Program example for gradient descent with Ridge Regression
    450. Using gradient descent methods, limitations
    451. Improving gradient descent with momentum
    452. -
    453. Same code but now with momentum gradient descent
    454. -
    455. Overview video on Stochastic Gradient Descent
    456. +
    457. Same code but now with momentum gradient descent
    458. +
    459. Overview video on Stochastic Gradient Descent (SGD)
    460. Batches and mini-batches
    461. -
    462. Stochastic Gradient Descent (SGD)
    463. -
    464. Stochastic Gradient Descent
    465. -
    466. Computation of gradients
    467. -
    468. SGD example
    469. -
    470. The gradient step
    471. -
    472. Simple example code
    473. -
    474. When do we stop?
    475. -
    476. Slightly different approach
    477. -
    478. Time decay rate
    479. -
    480. Code with a Number of Minibatches which varies
    481. -
    482. Replace or not
    483. -
    484. Momentum based GD
    485. -
    486. More on momentum based approaches
    487. -
    488. Momentum parameter
    489. -
    490. Second moment of the gradient
    491. -
    492. RMS prop
    493. -
    494. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    495. -
    496. Algorithms and codes for Adagrad, RMSprop and Adam
    497. -
    498. Practical tips
    499. -
    500. Sneaking in automatic differentiation using Autograd
    501. -
    502. Same code but now with momentum gradient descent
    503. -
    504. But none of these can compete with Newton's method
    505. -
    506. Including Stochastic Gradient Descent with Autograd
    507. -
    508. Same code but now with momentum gradient descent
    509. -
    510. Similar (second order function now) problem but now with AdaGrad
    511. -
    512. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    513. -
    514. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    515. -
    516. Material for the lab sessions
    517. +
    518. Pros and cons
    519. +
    520. Convergence rates
    521. +
    522. Accuracy
    523. +
    524. Stochastic Gradient Descent (SGD)
    525. +
    526. Stochastic Gradient Descent
    527. +
    528. Computation of gradients
    529. +
    530. SGD example
    531. +
    532. The gradient step
    533. +
    534. Simple example code
    535. +
    536. When do we stop?
    537. +
    538. Slightly different approach
    539. +
    540. Time decay rate
    541. +
    542. Code with a Number of Minibatches which varies
    543. +
    544. Replace or not
    545. +
    546. Momentum based GD
    547. +
    548. More on momentum based approaches
    549. +
    550. Momentum parameter
    551. +
    552. Second moment of the gradient
    553. +
    554. RMS prop
    555. +
    556. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    557. +
    558. Algorithms and codes for Adagrad, RMSprop and Adam
    559. +
    560. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    561. +
    562. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    563. +
    564. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    565. +
    566. Practical tips
    567. +
    568. Sneaking in auotmatic differentiation using Autograd
    569. +
    570. Same code but now with momentum gradient descent
    571. +
    572. Including Stochastic Gradient Descent with Autograd
    573. +
    574. Same code but now with momentum gradient descent
    575. +
    576. Similar (second order function now) problem but now with AdaGrad
    577. +
    578. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    579. +
    580. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    581. +
    582. Material for the lab sessions
    583. @@ -290,7 +309,7 @@ $$
    584. 15
    585. 16
    586. ...
    587. -
    588. 46
    589. +
    590. 48
    591. »
    592. diff --git a/doc/pub/week37/html/._week37-bs007.html b/doc/pub/week37/html/._week37-bs007.html index 71994bda6..b6b3a1230 100644 --- a/doc/pub/week37/html/._week37-bs007.html +++ b/doc/pub/week37/html/._week37-bs007.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    593. Program example for gradient descent with Ridge Regression
    594. Using gradient descent methods, limitations
    595. Improving gradient descent with momentum
    596. -
    597. Same code but now with momentum gradient descent
    598. -
    599. Overview video on Stochastic Gradient Descent
    600. +
    601. Same code but now with momentum gradient descent
    602. +
    603. Overview video on Stochastic Gradient Descent (SGD)
    604. Batches and mini-batches
    605. -
    606. Stochastic Gradient Descent (SGD)
    607. -
    608. Stochastic Gradient Descent
    609. -
    610. Computation of gradients
    611. -
    612. SGD example
    613. -
    614. The gradient step
    615. -
    616. Simple example code
    617. -
    618. When do we stop?
    619. -
    620. Slightly different approach
    621. -
    622. Time decay rate
    623. -
    624. Code with a Number of Minibatches which varies
    625. -
    626. Replace or not
    627. -
    628. Momentum based GD
    629. -
    630. More on momentum based approaches
    631. -
    632. Momentum parameter
    633. -
    634. Second moment of the gradient
    635. -
    636. RMS prop
    637. -
    638. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    639. -
    640. Algorithms and codes for Adagrad, RMSprop and Adam
    641. -
    642. Practical tips
    643. -
    644. Sneaking in automatic differentiation using Autograd
    645. -
    646. Same code but now with momentum gradient descent
    647. -
    648. But none of these can compete with Newton's method
    649. -
    650. Including Stochastic Gradient Descent with Autograd
    651. -
    652. Same code but now with momentum gradient descent
    653. -
    654. Similar (second order function now) problem but now with AdaGrad
    655. -
    656. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    657. -
    658. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    659. -
    660. Material for the lab sessions
    661. +
    662. Pros and cons
    663. +
    664. Convergence rates
    665. +
    666. Accuracy
    667. +
    668. Stochastic Gradient Descent (SGD)
    669. +
    670. Stochastic Gradient Descent
    671. +
    672. Computation of gradients
    673. +
    674. SGD example
    675. +
    676. The gradient step
    677. +
    678. Simple example code
    679. +
    680. When do we stop?
    681. +
    682. Slightly different approach
    683. +
    684. Time decay rate
    685. +
    686. Code with a Number of Minibatches which varies
    687. +
    688. Replace or not
    689. +
    690. Momentum based GD
    691. +
    692. More on momentum based approaches
    693. +
    694. Momentum parameter
    695. +
    696. Second moment of the gradient
    697. +
    698. RMS prop
    699. +
    700. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    701. +
    702. Algorithms and codes for Adagrad, RMSprop and Adam
    703. +
    704. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    705. +
    706. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    707. +
    708. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    709. +
    710. Practical tips
    711. +
    712. Sneaking in auotmatic differentiation using Autograd
    713. +
    714. Same code but now with momentum gradient descent
    715. +
    716. Including Stochastic Gradient Descent with Autograd
    717. +
    718. Same code but now with momentum gradient descent
    719. +
    720. Similar (second order function now) problem but now with AdaGrad
    721. +
    722. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    723. +
    724. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    725. +
    726. Material for the lab sessions
    727. @@ -291,7 +310,7 @@ $$
    728. 16
    729. 17
    730. ...
    731. -
    732. 46
    733. +
    734. 48
    735. »
    736. diff --git a/doc/pub/week37/html/._week37-bs008.html b/doc/pub/week37/html/._week37-bs008.html index 4cc405564..67e684b22 100644 --- a/doc/pub/week37/html/._week37-bs008.html +++ b/doc/pub/week37/html/._week37-bs008.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    737. Program example for gradient descent with Ridge Regression
    738. Using gradient descent methods, limitations
    739. Improving gradient descent with momentum
    740. -
    741. Same code but now with momentum gradient descent
    742. -
    743. Overview video on Stochastic Gradient Descent
    744. +
    745. Same code but now with momentum gradient descent
    746. +
    747. Overview video on Stochastic Gradient Descent (SGD)
    748. Batches and mini-batches
    749. -
    750. Stochastic Gradient Descent (SGD)
    751. -
    752. Stochastic Gradient Descent
    753. -
    754. Computation of gradients
    755. -
    756. SGD example
    757. -
    758. The gradient step
    759. -
    760. Simple example code
    761. -
    762. When do we stop?
    763. -
    764. Slightly different approach
    765. -
    766. Time decay rate
    767. -
    768. Code with a Number of Minibatches which varies
    769. -
    770. Replace or not
    771. -
    772. Momentum based GD
    773. -
    774. More on momentum based approaches
    775. -
    776. Momentum parameter
    777. -
    778. Second moment of the gradient
    779. -
    780. RMS prop
    781. -
    782. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    783. -
    784. Algorithms and codes for Adagrad, RMSprop and Adam
    785. -
    786. Practical tips
    787. -
    788. Sneaking in automatic differentiation using Autograd
    789. -
    790. Same code but now with momentum gradient descent
    791. -
    792. But none of these can compete with Newton's method
    793. -
    794. Including Stochastic Gradient Descent with Autograd
    795. -
    796. Same code but now with momentum gradient descent
    797. -
    798. Similar (second order function now) problem but now with AdaGrad
    799. -
    800. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    801. -
    802. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    803. -
    804. Material for the lab sessions
    805. +
    806. Pros and cons
    807. +
    808. Convergence rates
    809. +
    810. Accuracy
    811. +
    812. Stochastic Gradient Descent (SGD)
    813. +
    814. Stochastic Gradient Descent
    815. +
    816. Computation of gradients
    817. +
    818. SGD example
    819. +
    820. The gradient step
    821. +
    822. Simple example code
    823. +
    824. When do we stop?
    825. +
    826. Slightly different approach
    827. +
    828. Time decay rate
    829. +
    830. Code with a Number of Minibatches which varies
    831. +
    832. Replace or not
    833. +
    834. Momentum based GD
    835. +
    836. More on momentum based approaches
    837. +
    838. Momentum parameter
    839. +
    840. Second moment of the gradient
    841. +
    842. RMS prop
    843. +
    844. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    845. +
    846. Algorithms and codes for Adagrad, RMSprop and Adam
    847. +
    848. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    849. +
    850. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    851. +
    852. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    853. +
    854. Practical tips
    855. +
    856. Sneaking in auotmatic differentiation using Autograd
    857. +
    858. Same code but now with momentum gradient descent
    859. +
    860. Including Stochastic Gradient Descent with Autograd
    861. +
    862. Same code but now with momentum gradient descent
    863. +
    864. Similar (second order function now) problem but now with AdaGrad
    865. +
    866. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    867. +
    868. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    869. +
    870. Material for the lab sessions
    871. @@ -297,7 +316,7 @@ when \( ||\nabla_\theta C(\theta_k) || \leq \epsilon = 10^{-8} \). Note that
    872. 17
    873. 18
    874. ...
    875. -
    876. 46
    877. +
    878. 48
    879. »
    880. diff --git a/doc/pub/week37/html/._week37-bs009.html b/doc/pub/week37/html/._week37-bs009.html index df9f8f43e..65ab5bed9 100644 --- a/doc/pub/week37/html/._week37-bs009.html +++ b/doc/pub/week37/html/._week37-bs009.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    881. Program example for gradient descent with Ridge Regression
    882. Using gradient descent methods, limitations
    883. Improving gradient descent with momentum
    884. -
    885. Same code but now with momentum gradient descent
    886. -
    887. Overview video on Stochastic Gradient Descent
    888. +
    889. Same code but now with momentum gradient descent
    890. +
    891. Overview video on Stochastic Gradient Descent (SGD)
    892. Batches and mini-batches
    893. -
    894. Stochastic Gradient Descent (SGD)
    895. -
    896. Stochastic Gradient Descent
    897. -
    898. Computation of gradients
    899. -
    900. SGD example
    901. -
    902. The gradient step
    903. -
    904. Simple example code
    905. -
    906. When do we stop?
    907. -
    908. Slightly different approach
    909. -
    910. Time decay rate
    911. -
    912. Code with a Number of Minibatches which varies
    913. -
    914. Replace or not
    915. -
    916. Momentum based GD
    917. -
    918. More on momentum based approaches
    919. -
    920. Momentum parameter
    921. -
    922. Second moment of the gradient
    923. -
    924. RMS prop
    925. -
    926. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    927. -
    928. Algorithms and codes for Adagrad, RMSprop and Adam
    929. -
    930. Practical tips
    931. -
    932. Sneaking in automatic differentiation using Autograd
    933. -
    934. Same code but now with momentum gradient descent
    935. -
    936. But none of these can compete with Newton's method
    937. -
    938. Including Stochastic Gradient Descent with Autograd
    939. -
    940. Same code but now with momentum gradient descent
    941. -
    942. Similar (second order function now) problem but now with AdaGrad
    943. -
    944. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    945. -
    946. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    947. -
    948. Material for the lab sessions
    949. +
    950. Pros and cons
    951. +
    952. Convergence rates
    953. +
    954. Accuracy
    955. +
    956. Stochastic Gradient Descent (SGD)
    957. +
    958. Stochastic Gradient Descent
    959. +
    960. Computation of gradients
    961. +
    962. SGD example
    963. +
    964. The gradient step
    965. +
    966. Simple example code
    967. +
    968. When do we stop?
    969. +
    970. Slightly different approach
    971. +
    972. Time decay rate
    973. +
    974. Code with a Number of Minibatches which varies
    975. +
    976. Replace or not
    977. +
    978. Momentum based GD
    979. +
    980. More on momentum based approaches
    981. +
    982. Momentum parameter
    983. +
    984. Second moment of the gradient
    985. +
    986. RMS prop
    987. +
    988. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    989. +
    990. Algorithms and codes for Adagrad, RMSprop and Adam
    991. +
    992. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    993. +
    994. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    995. +
    996. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    997. +
    998. Practical tips
    999. +
    1000. Sneaking in auotmatic differentiation using Autograd
    1001. +
    1002. Same code but now with momentum gradient descent
    1003. +
    1004. Including Stochastic Gradient Descent with Autograd
    1005. +
    1006. Same code but now with momentum gradient descent
    1007. +
    1008. Similar (second order function now) problem but now with AdaGrad
    1009. +
    1010. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1011. +
    1012. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1013. +
    1014. Material for the lab sessions
    1015. @@ -353,7 +372,7 @@ plt.show()
    1016. 18
    1017. 19
    1018. ...
    1019. -
    1020. 46
    1021. +
    1022. 48
    1023. »
    1024. diff --git a/doc/pub/week37/html/._week37-bs010.html b/doc/pub/week37/html/._week37-bs010.html index 075aea3b0..26ec2439a 100644 --- a/doc/pub/week37/html/._week37-bs010.html +++ b/doc/pub/week37/html/._week37-bs010.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    1025. Program example for gradient descent with Ridge Regression
    1026. Using gradient descent methods, limitations
    1027. Improving gradient descent with momentum
    1028. -
    1029. Same code but now with momentum gradient descent
    1030. -
    1031. Overview video on Stochastic Gradient Descent
    1032. +
    1033. Same code but now with momentum gradient descent
    1034. +
    1035. Overview video on Stochastic Gradient Descent (SGD)
    1036. Batches and mini-batches
    1037. -
    1038. Stochastic Gradient Descent (SGD)
    1039. -
    1040. Stochastic Gradient Descent
    1041. -
    1042. Computation of gradients
    1043. -
    1044. SGD example
    1045. -
    1046. The gradient step
    1047. -
    1048. Simple example code
    1049. -
    1050. When do we stop?
    1051. -
    1052. Slightly different approach
    1053. -
    1054. Time decay rate
    1055. -
    1056. Code with a Number of Minibatches which varies
    1057. -
    1058. Replace or not
    1059. -
    1060. Momentum based GD
    1061. -
    1062. More on momentum based approaches
    1063. -
    1064. Momentum parameter
    1065. -
    1066. Second moment of the gradient
    1067. -
    1068. RMS prop
    1069. -
    1070. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1071. -
    1072. Algorithms and codes for Adagrad, RMSprop and Adam
    1073. -
    1074. Practical tips
    1075. -
    1076. Sneaking in automatic differentiation using Autograd
    1077. -
    1078. Same code but now with momentum gradient descent
    1079. -
    1080. But none of these can compete with Newton's method
    1081. -
    1082. Including Stochastic Gradient Descent with Autograd
    1083. -
    1084. Same code but now with momentum gradient descent
    1085. -
    1086. Similar (second order function now) problem but now with AdaGrad
    1087. -
    1088. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1089. -
    1090. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1091. -
    1092. Material for the lab sessions
    1093. +
    1094. Pros and cons
    1095. +
    1096. Convergence rates
    1097. +
    1098. Accuracy
    1099. +
    1100. Stochastic Gradient Descent (SGD)
    1101. +
    1102. Stochastic Gradient Descent
    1103. +
    1104. Computation of gradients
    1105. +
    1106. SGD example
    1107. +
    1108. The gradient step
    1109. +
    1110. Simple example code
    1111. +
    1112. When do we stop?
    1113. +
    1114. Slightly different approach
    1115. +
    1116. Time decay rate
    1117. +
    1118. Code with a Number of Minibatches which varies
    1119. +
    1120. Replace or not
    1121. +
    1122. Momentum based GD
    1123. +
    1124. More on momentum based approaches
    1125. +
    1126. Momentum parameter
    1127. +
    1128. Second moment of the gradient
    1129. +
    1130. RMS prop
    1131. +
    1132. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1133. +
    1134. Algorithms and codes for Adagrad, RMSprop and Adam
    1135. +
    1136. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1137. +
    1138. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1139. +
    1140. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1141. +
    1142. Practical tips
    1143. +
    1144. Sneaking in auotmatic differentiation using Autograd
    1145. +
    1146. Same code but now with momentum gradient descent
    1147. +
    1148. Including Stochastic Gradient Descent with Autograd
    1149. +
    1150. Same code but now with momentum gradient descent
    1151. +
    1152. Similar (second order function now) problem but now with AdaGrad
    1153. +
    1154. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1155. +
    1156. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1157. +
    1158. Material for the lab sessions
    1159. @@ -303,7 +322,7 @@ $$
    1160. 19
    1161. 20
    1162. ...
    1163. -
    1164. 46
    1165. +
    1166. 48
    1167. »
    1168. diff --git a/doc/pub/week37/html/._week37-bs011.html b/doc/pub/week37/html/._week37-bs011.html index 87f9fdafa..fb806a5f7 100644 --- a/doc/pub/week37/html/._week37-bs011.html +++ b/doc/pub/week37/html/._week37-bs011.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    1169. Program example for gradient descent with Ridge Regression
    1170. Using gradient descent methods, limitations
    1171. Improving gradient descent with momentum
    1172. -
    1173. Same code but now with momentum gradient descent
    1174. -
    1175. Overview video on Stochastic Gradient Descent
    1176. +
    1177. Same code but now with momentum gradient descent
    1178. +
    1179. Overview video on Stochastic Gradient Descent (SGD)
    1180. Batches and mini-batches
    1181. -
    1182. Stochastic Gradient Descent (SGD)
    1183. -
    1184. Stochastic Gradient Descent
    1185. -
    1186. Computation of gradients
    1187. -
    1188. SGD example
    1189. -
    1190. The gradient step
    1191. -
    1192. Simple example code
    1193. -
    1194. When do we stop?
    1195. -
    1196. Slightly different approach
    1197. -
    1198. Time decay rate
    1199. -
    1200. Code with a Number of Minibatches which varies
    1201. -
    1202. Replace or not
    1203. -
    1204. Momentum based GD
    1205. -
    1206. More on momentum based approaches
    1207. -
    1208. Momentum parameter
    1209. -
    1210. Second moment of the gradient
    1211. -
    1212. RMS prop
    1213. -
    1214. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1215. -
    1216. Algorithms and codes for Adagrad, RMSprop and Adam
    1217. -
    1218. Practical tips
    1219. -
    1220. Sneaking in automatic differentiation using Autograd
    1221. -
    1222. Same code but now with momentum gradient descent
    1223. -
    1224. But none of these can compete with Newton's method
    1225. -
    1226. Including Stochastic Gradient Descent with Autograd
    1227. -
    1228. Same code but now with momentum gradient descent
    1229. -
    1230. Similar (second order function now) problem but now with AdaGrad
    1231. -
    1232. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1233. -
    1234. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1235. -
    1236. Material for the lab sessions
    1237. +
    1238. Pros and cons
    1239. +
    1240. Convergence rates
    1241. +
    1242. Accuracy
    1243. +
    1244. Stochastic Gradient Descent (SGD)
    1245. +
    1246. Stochastic Gradient Descent
    1247. +
    1248. Computation of gradients
    1249. +
    1250. SGD example
    1251. +
    1252. The gradient step
    1253. +
    1254. Simple example code
    1255. +
    1256. When do we stop?
    1257. +
    1258. Slightly different approach
    1259. +
    1260. Time decay rate
    1261. +
    1262. Code with a Number of Minibatches which varies
    1263. +
    1264. Replace or not
    1265. +
    1266. Momentum based GD
    1267. +
    1268. More on momentum based approaches
    1269. +
    1270. Momentum parameter
    1271. +
    1272. Second moment of the gradient
    1273. +
    1274. RMS prop
    1275. +
    1276. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1277. +
    1278. Algorithms and codes for Adagrad, RMSprop and Adam
    1279. +
    1280. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1281. +
    1282. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1283. +
    1284. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1285. +
    1286. Practical tips
    1287. +
    1288. Sneaking in auotmatic differentiation using Autograd
    1289. +
    1290. Same code but now with momentum gradient descent
    1291. +
    1292. Including Stochastic Gradient Descent with Autograd
    1293. +
    1294. Same code but now with momentum gradient descent
    1295. +
    1296. Similar (second order function now) problem but now with AdaGrad
    1297. +
    1298. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1299. +
    1300. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1301. +
    1302. Material for the lab sessions
    1303. @@ -299,7 +318,7 @@ minimum of this function.
    1304. 20
    1305. 21
    1306. ...
    1307. -
    1308. 46
    1309. +
    1310. 48
    1311. »
    1312. diff --git a/doc/pub/week37/html/._week37-bs012.html b/doc/pub/week37/html/._week37-bs012.html index 90213a2d2..7a5311501 100644 --- a/doc/pub/week37/html/._week37-bs012.html +++ b/doc/pub/week37/html/._week37-bs012.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    1313. Program example for gradient descent with Ridge Regression
    1314. Using gradient descent methods, limitations
    1315. Improving gradient descent with momentum
    1316. -
    1317. Same code but now with momentum gradient descent
    1318. -
    1319. Overview video on Stochastic Gradient Descent
    1320. +
    1321. Same code but now with momentum gradient descent
    1322. +
    1323. Overview video on Stochastic Gradient Descent (SGD)
    1324. Batches and mini-batches
    1325. -
    1326. Stochastic Gradient Descent (SGD)
    1327. -
    1328. Stochastic Gradient Descent
    1329. -
    1330. Computation of gradients
    1331. -
    1332. SGD example
    1333. -
    1334. The gradient step
    1335. -
    1336. Simple example code
    1337. -
    1338. When do we stop?
    1339. -
    1340. Slightly different approach
    1341. -
    1342. Time decay rate
    1343. -
    1344. Code with a Number of Minibatches which varies
    1345. -
    1346. Replace or not
    1347. -
    1348. Momentum based GD
    1349. -
    1350. More on momentum based approaches
    1351. -
    1352. Momentum parameter
    1353. -
    1354. Second moment of the gradient
    1355. -
    1356. RMS prop
    1357. -
    1358. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1359. -
    1360. Algorithms and codes for Adagrad, RMSprop and Adam
    1361. -
    1362. Practical tips
    1363. -
    1364. Sneaking in automatic differentiation using Autograd
    1365. -
    1366. Same code but now with momentum gradient descent
    1367. -
    1368. But none of these can compete with Newton's method
    1369. -
    1370. Including Stochastic Gradient Descent with Autograd
    1371. -
    1372. Same code but now with momentum gradient descent
    1373. -
    1374. Similar (second order function now) problem but now with AdaGrad
    1375. -
    1376. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1377. -
    1378. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1379. -
    1380. Material for the lab sessions
    1381. +
    1382. Pros and cons
    1383. +
    1384. Convergence rates
    1385. +
    1386. Accuracy
    1387. +
    1388. Stochastic Gradient Descent (SGD)
    1389. +
    1390. Stochastic Gradient Descent
    1391. +
    1392. Computation of gradients
    1393. +
    1394. SGD example
    1395. +
    1396. The gradient step
    1397. +
    1398. Simple example code
    1399. +
    1400. When do we stop?
    1401. +
    1402. Slightly different approach
    1403. +
    1404. Time decay rate
    1405. +
    1406. Code with a Number of Minibatches which varies
    1407. +
    1408. Replace or not
    1409. +
    1410. Momentum based GD
    1411. +
    1412. More on momentum based approaches
    1413. +
    1414. Momentum parameter
    1415. +
    1416. Second moment of the gradient
    1417. +
    1418. RMS prop
    1419. +
    1420. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1421. +
    1422. Algorithms and codes for Adagrad, RMSprop and Adam
    1423. +
    1424. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1425. +
    1426. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1427. +
    1428. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1429. +
    1430. Practical tips
    1431. +
    1432. Sneaking in auotmatic differentiation using Autograd
    1433. +
    1434. Same code but now with momentum gradient descent
    1435. +
    1436. Including Stochastic Gradient Descent with Autograd
    1437. +
    1438. Same code but now with momentum gradient descent
    1439. +
    1440. Similar (second order function now) problem but now with AdaGrad
    1441. +
    1442. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1443. +
    1444. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1445. +
    1446. Material for the lab sessions
    1447. @@ -357,7 +376,7 @@ plt.show()
    1448. 21
    1449. 22
    1450. ...
    1451. -
    1452. 46
    1453. +
    1454. 48
    1455. »
    1456. diff --git a/doc/pub/week37/html/._week37-bs013.html b/doc/pub/week37/html/._week37-bs013.html index 0a3af037d..e4ea98d20 100644 --- a/doc/pub/week37/html/._week37-bs013.html +++ b/doc/pub/week37/html/._week37-bs013.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    1457. Program example for gradient descent with Ridge Regression
    1458. Using gradient descent methods, limitations
    1459. Improving gradient descent with momentum
    1460. -
    1461. Same code but now with momentum gradient descent
    1462. -
    1463. Overview video on Stochastic Gradient Descent
    1464. +
    1465. Same code but now with momentum gradient descent
    1466. +
    1467. Overview video on Stochastic Gradient Descent (SGD)
    1468. Batches and mini-batches
    1469. -
    1470. Stochastic Gradient Descent (SGD)
    1471. -
    1472. Stochastic Gradient Descent
    1473. -
    1474. Computation of gradients
    1475. -
    1476. SGD example
    1477. -
    1478. The gradient step
    1479. -
    1480. Simple example code
    1481. -
    1482. When do we stop?
    1483. -
    1484. Slightly different approach
    1485. -
    1486. Time decay rate
    1487. -
    1488. Code with a Number of Minibatches which varies
    1489. -
    1490. Replace or not
    1491. -
    1492. Momentum based GD
    1493. -
    1494. More on momentum based approaches
    1495. -
    1496. Momentum parameter
    1497. -
    1498. Second moment of the gradient
    1499. -
    1500. RMS prop
    1501. -
    1502. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1503. -
    1504. Algorithms and codes for Adagrad, RMSprop and Adam
    1505. -
    1506. Practical tips
    1507. -
    1508. Sneaking in automatic differentiation using Autograd
    1509. -
    1510. Same code but now with momentum gradient descent
    1511. -
    1512. But none of these can compete with Newton's method
    1513. -
    1514. Including Stochastic Gradient Descent with Autograd
    1515. -
    1516. Same code but now with momentum gradient descent
    1517. -
    1518. Similar (second order function now) problem but now with AdaGrad
    1519. -
    1520. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1521. -
    1522. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1523. -
    1524. Material for the lab sessions
    1525. +
    1526. Pros and cons
    1527. +
    1528. Convergence rates
    1529. +
    1530. Accuracy
    1531. +
    1532. Stochastic Gradient Descent (SGD)
    1533. +
    1534. Stochastic Gradient Descent
    1535. +
    1536. Computation of gradients
    1537. +
    1538. SGD example
    1539. +
    1540. The gradient step
    1541. +
    1542. Simple example code
    1543. +
    1544. When do we stop?
    1545. +
    1546. Slightly different approach
    1547. +
    1548. Time decay rate
    1549. +
    1550. Code with a Number of Minibatches which varies
    1551. +
    1552. Replace or not
    1553. +
    1554. Momentum based GD
    1555. +
    1556. More on momentum based approaches
    1557. +
    1558. Momentum parameter
    1559. +
    1560. Second moment of the gradient
    1561. +
    1562. RMS prop
    1563. +
    1564. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1565. +
    1566. Algorithms and codes for Adagrad, RMSprop and Adam
    1567. +
    1568. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1569. +
    1570. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1571. +
    1572. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1573. +
    1574. Practical tips
    1575. +
    1576. Sneaking in auotmatic differentiation using Autograd
    1577. +
    1578. Same code but now with momentum gradient descent
    1579. +
    1580. Including Stochastic Gradient Descent with Autograd
    1581. +
    1582. Same code but now with momentum gradient descent
    1583. +
    1584. Similar (second order function now) problem but now with AdaGrad
    1585. +
    1586. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1587. +
    1588. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1589. +
    1590. Material for the lab sessions
    1591. @@ -293,7 +312,7 @@ MathJax.Hub.Config({
    1592. 22
    1593. 23
    1594. ...
    1595. -
    1596. 46
    1597. +
    1598. 48
    1599. »
    1600. diff --git a/doc/pub/week37/html/._week37-bs014.html b/doc/pub/week37/html/._week37-bs014.html index 2d1cd02f8..19d9ba2cd 100644 --- a/doc/pub/week37/html/._week37-bs014.html +++ b/doc/pub/week37/html/._week37-bs014.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    1601. Program example for gradient descent with Ridge Regression
    1602. Using gradient descent methods, limitations
    1603. Improving gradient descent with momentum
    1604. -
    1605. Same code but now with momentum gradient descent
    1606. -
    1607. Overview video on Stochastic Gradient Descent
    1608. +
    1609. Same code but now with momentum gradient descent
    1610. +
    1611. Overview video on Stochastic Gradient Descent (SGD)
    1612. Batches and mini-batches
    1613. -
    1614. Stochastic Gradient Descent (SGD)
    1615. -
    1616. Stochastic Gradient Descent
    1617. -
    1618. Computation of gradients
    1619. -
    1620. SGD example
    1621. -
    1622. The gradient step
    1623. -
    1624. Simple example code
    1625. -
    1626. When do we stop?
    1627. -
    1628. Slightly different approach
    1629. -
    1630. Time decay rate
    1631. -
    1632. Code with a Number of Minibatches which varies
    1633. -
    1634. Replace or not
    1635. -
    1636. Momentum based GD
    1637. -
    1638. More on momentum based approaches
    1639. -
    1640. Momentum parameter
    1641. -
    1642. Second moment of the gradient
    1643. -
    1644. RMS prop
    1645. -
    1646. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1647. -
    1648. Algorithms and codes for Adagrad, RMSprop and Adam
    1649. -
    1650. Practical tips
    1651. -
    1652. Sneaking in automatic differentiation using Autograd
    1653. -
    1654. Same code but now with momentum gradient descent
    1655. -
    1656. But none of these can compete with Newton's method
    1657. -
    1658. Including Stochastic Gradient Descent with Autograd
    1659. -
    1660. Same code but now with momentum gradient descent
    1661. -
    1662. Similar (second order function now) problem but now with AdaGrad
    1663. -
    1664. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1665. -
    1666. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1667. -
    1668. Material for the lab sessions
    1669. +
    1670. Pros and cons
    1671. +
    1672. Convergence rates
    1673. +
    1674. Accuracy
    1675. +
    1676. Stochastic Gradient Descent (SGD)
    1677. +
    1678. Stochastic Gradient Descent
    1679. +
    1680. Computation of gradients
    1681. +
    1682. SGD example
    1683. +
    1684. The gradient step
    1685. +
    1686. Simple example code
    1687. +
    1688. When do we stop?
    1689. +
    1690. Slightly different approach
    1691. +
    1692. Time decay rate
    1693. +
    1694. Code with a Number of Minibatches which varies
    1695. +
    1696. Replace or not
    1697. +
    1698. Momentum based GD
    1699. +
    1700. More on momentum based approaches
    1701. +
    1702. Momentum parameter
    1703. +
    1704. Second moment of the gradient
    1705. +
    1706. RMS prop
    1707. +
    1708. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1709. +
    1710. Algorithms and codes for Adagrad, RMSprop and Adam
    1711. +
    1712. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1713. +
    1714. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1715. +
    1716. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1717. +
    1718. Practical tips
    1719. +
    1720. Sneaking in auotmatic differentiation using Autograd
    1721. +
    1722. Same code but now with momentum gradient descent
    1723. +
    1724. Including Stochastic Gradient Descent with Autograd
    1725. +
    1726. Same code but now with momentum gradient descent
    1727. +
    1728. Similar (second order function now) problem but now with AdaGrad
    1729. +
    1730. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1731. +
    1732. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1733. +
    1734. Material for the lab sessions
    1735. @@ -365,7 +384,7 @@ pyplot.show()
    1736. 23
    1737. 24
    1738. ...
    1739. -
    1740. 46
    1741. +
    1742. 48
    1743. »
    1744. diff --git a/doc/pub/week37/html/._week37-bs015.html b/doc/pub/week37/html/._week37-bs015.html index 39be69329..9df5139ad 100644 --- a/doc/pub/week37/html/._week37-bs015.html +++ b/doc/pub/week37/html/._week37-bs015.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    1745. Program example for gradient descent with Ridge Regression
    1746. Using gradient descent methods, limitations
    1747. Improving gradient descent with momentum
    1748. -
    1749. Same code but now with momentum gradient descent
    1750. -
    1751. Overview video on Stochastic Gradient Descent
    1752. +
    1753. Same code but now with momentum gradient descent
    1754. +
    1755. Overview video on Stochastic Gradient Descent (SGD)
    1756. Batches and mini-batches
    1757. -
    1758. Stochastic Gradient Descent (SGD)
    1759. -
    1760. Stochastic Gradient Descent
    1761. -
    1762. Computation of gradients
    1763. -
    1764. SGD example
    1765. -
    1766. The gradient step
    1767. -
    1768. Simple example code
    1769. -
    1770. When do we stop?
    1771. -
    1772. Slightly different approach
    1773. -
    1774. Time decay rate
    1775. -
    1776. Code with a Number of Minibatches which varies
    1777. -
    1778. Replace or not
    1779. -
    1780. Momentum based GD
    1781. -
    1782. More on momentum based approaches
    1783. -
    1784. Momentum parameter
    1785. -
    1786. Second moment of the gradient
    1787. -
    1788. RMS prop
    1789. -
    1790. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1791. -
    1792. Algorithms and codes for Adagrad, RMSprop and Adam
    1793. -
    1794. Practical tips
    1795. -
    1796. Sneaking in automatic differentiation using Autograd
    1797. -
    1798. Same code but now with momentum gradient descent
    1799. -
    1800. But none of these can compete with Newton's method
    1801. -
    1802. Including Stochastic Gradient Descent with Autograd
    1803. -
    1804. Same code but now with momentum gradient descent
    1805. -
    1806. Similar (second order function now) problem but now with AdaGrad
    1807. -
    1808. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1809. -
    1810. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1811. -
    1812. Material for the lab sessions
    1813. +
    1814. Pros and cons
    1815. +
    1816. Convergence rates
    1817. +
    1818. Accuracy
    1819. +
    1820. Stochastic Gradient Descent (SGD)
    1821. +
    1822. Stochastic Gradient Descent
    1823. +
    1824. Computation of gradients
    1825. +
    1826. SGD example
    1827. +
    1828. The gradient step
    1829. +
    1830. Simple example code
    1831. +
    1832. When do we stop?
    1833. +
    1834. Slightly different approach
    1835. +
    1836. Time decay rate
    1837. +
    1838. Code with a Number of Minibatches which varies
    1839. +
    1840. Replace or not
    1841. +
    1842. Momentum based GD
    1843. +
    1844. More on momentum based approaches
    1845. +
    1846. Momentum parameter
    1847. +
    1848. Second moment of the gradient
    1849. +
    1850. RMS prop
    1851. +
    1852. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1853. +
    1854. Algorithms and codes for Adagrad, RMSprop and Adam
    1855. +
    1856. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1857. +
    1858. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1859. +
    1860. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    1861. +
    1862. Practical tips
    1863. +
    1864. Sneaking in auotmatic differentiation using Autograd
    1865. +
    1866. Same code but now with momentum gradient descent
    1867. +
    1868. Including Stochastic Gradient Descent with Autograd
    1869. +
    1870. Same code but now with momentum gradient descent
    1871. +
    1872. Similar (second order function now) problem but now with AdaGrad
    1873. +
    1874. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1875. +
    1876. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1877. +
    1878. Material for the lab sessions
    1879. @@ -371,7 +390,7 @@ pyplot.show()
    1880. 24
    1881. 25
    1882. ...
    1883. -
    1884. 46
    1885. +
    1886. 48
    1887. »
    1888. diff --git a/doc/pub/week37/html/._week37-bs016.html b/doc/pub/week37/html/._week37-bs016.html index 1b3515b56..13617ec8b 100644 --- a/doc/pub/week37/html/._week37-bs016.html +++ b/doc/pub/week37/html/._week37-bs016.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    1889. Program example for gradient descent with Ridge Regression
    1890. Using gradient descent methods, limitations
    1891. Improving gradient descent with momentum
    1892. -
    1893. Same code but now with momentum gradient descent
    1894. -
    1895. Overview video on Stochastic Gradient Descent
    1896. +
    1897. Same code but now with momentum gradient descent
    1898. +
    1899. Overview video on Stochastic Gradient Descent (SGD)
    1900. Batches and mini-batches
    1901. -
    1902. Stochastic Gradient Descent (SGD)
    1903. -
    1904. Stochastic Gradient Descent
    1905. -
    1906. Computation of gradients
    1907. -
    1908. SGD example
    1909. -
    1910. The gradient step
    1911. -
    1912. Simple example code
    1913. -
    1914. When do we stop?
    1915. -
    1916. Slightly different approach
    1917. -
    1918. Time decay rate
    1919. -
    1920. Code with a Number of Minibatches which varies
    1921. -
    1922. Replace or not
    1923. -
    1924. Momentum based GD
    1925. -
    1926. More on momentum based approaches
    1927. -
    1928. Momentum parameter
    1929. -
    1930. Second moment of the gradient
    1931. -
    1932. RMS prop
    1933. -
    1934. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1935. -
    1936. Algorithms and codes for Adagrad, RMSprop and Adam
    1937. -
    1938. Practical tips
    1939. -
    1940. Sneaking in automatic differentiation using Autograd
    1941. -
    1942. Same code but now with momentum gradient descent
    1943. -
    1944. But none of these can compete with Newton's method
    1945. -
    1946. Including Stochastic Gradient Descent with Autograd
    1947. -
    1948. Same code but now with momentum gradient descent
    1949. -
    1950. Similar (second order function now) problem but now with AdaGrad
    1951. -
    1952. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    1953. -
    1954. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    1955. -
    1956. Material for the lab sessions
    1957. +
    1958. Pros and cons
    1959. +
    1960. Convergence rates
    1961. +
    1962. Accuracy
    1963. +
    1964. Stochastic Gradient Descent (SGD)
    1965. +
    1966. Stochastic Gradient Descent
    1967. +
    1968. Computation of gradients
    1969. +
    1970. SGD example
    1971. +
    1972. The gradient step
    1973. +
    1974. Simple example code
    1975. +
    1976. When do we stop?
    1977. +
    1978. Slightly different approach
    1979. +
    1980. Time decay rate
    1981. +
    1982. Code with a Number of Minibatches which varies
    1983. +
    1984. Replace or not
    1985. +
    1986. Momentum based GD
    1987. +
    1988. More on momentum based approaches
    1989. +
    1990. Momentum parameter
    1991. +
    1992. Second moment of the gradient
    1993. +
    1994. RMS prop
    1995. +
    1996. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    1997. +
    1998. Algorithms and codes for Adagrad, RMSprop and Adam
    1999. +
    2000. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2001. +
    2002. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2003. +
    2004. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2005. +
    2006. Practical tips
    2007. +
    2008. Sneaking in auotmatic differentiation using Autograd
    2009. +
    2010. Same code but now with momentum gradient descent
    2011. +
    2012. Including Stochastic Gradient Descent with Autograd
    2013. +
    2014. Same code but now with momentum gradient descent
    2015. +
    2016. Similar (second order function now) problem but now with AdaGrad
    2017. +
    2018. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2019. +
    2020. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2021. +
    2022. Material for the lab sessions
    2023. @@ -258,10 +277,16 @@ MathJax.Hub.Config({

       

       

       

      -

      Overview video on Stochastic Gradient Descent

      +

      Overview video on Stochastic Gradient Descent (SGD)

      What is Stochastic Gradient Descent +

      There are several reasons for using stochastic gradient descent. Some of these are:

      +
        +
      1. Efficiency: Updates weights more frequently using a single or a small batch of samples, which speeds up convergence.
      2. +
      3. Hopefully avoid Local Minima
      4. +
      5. Memory Usage: Requires less memory compared to computing gradients for the entire dataset.
      6. +

        @@ -287,7 +312,7 @@ MathJax.Hub.Config({
      • 25
      • 26
      • ...
      • -
      • 46
      • +
      • 48
      • »
      diff --git a/doc/pub/week37/html/._week37-bs017.html b/doc/pub/week37/html/._week37-bs017.html index e1882aad3..8dde5e1e5 100644 --- a/doc/pub/week37/html/._week37-bs017.html +++ b/doc/pub/week37/html/._week37-bs017.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    2024. Program example for gradient descent with Ridge Regression
    2025. Using gradient descent methods, limitations
    2026. Improving gradient descent with momentum
    2027. -
    2028. Same code but now with momentum gradient descent
    2029. -
    2030. Overview video on Stochastic Gradient Descent
    2031. +
    2032. Same code but now with momentum gradient descent
    2033. +
    2034. Overview video on Stochastic Gradient Descent (SGD)
    2035. Batches and mini-batches
    2036. -
    2037. Stochastic Gradient Descent (SGD)
    2038. -
    2039. Stochastic Gradient Descent
    2040. -
    2041. Computation of gradients
    2042. -
    2043. SGD example
    2044. -
    2045. The gradient step
    2046. -
    2047. Simple example code
    2048. -
    2049. When do we stop?
    2050. -
    2051. Slightly different approach
    2052. -
    2053. Time decay rate
    2054. -
    2055. Code with a Number of Minibatches which varies
    2056. -
    2057. Replace or not
    2058. -
    2059. Momentum based GD
    2060. -
    2061. More on momentum based approaches
    2062. -
    2063. Momentum parameter
    2064. -
    2065. Second moment of the gradient
    2066. -
    2067. RMS prop
    2068. -
    2069. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2070. -
    2071. Algorithms and codes for Adagrad, RMSprop and Adam
    2072. -
    2073. Practical tips
    2074. -
    2075. Sneaking in automatic differentiation using Autograd
    2076. -
    2077. Same code but now with momentum gradient descent
    2078. -
    2079. But none of these can compete with Newton's method
    2080. -
    2081. Including Stochastic Gradient Descent with Autograd
    2082. -
    2083. Same code but now with momentum gradient descent
    2084. -
    2085. Similar (second order function now) problem but now with AdaGrad
    2086. -
    2087. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2088. -
    2089. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2090. -
    2091. Material for the lab sessions
    2092. +
    2093. Pros and cons
    2094. +
    2095. Convergence rates
    2096. +
    2097. Accuracy
    2098. +
    2099. Stochastic Gradient Descent (SGD)
    2100. +
    2101. Stochastic Gradient Descent
    2102. +
    2103. Computation of gradients
    2104. +
    2105. SGD example
    2106. +
    2107. The gradient step
    2108. +
    2109. Simple example code
    2110. +
    2111. When do we stop?
    2112. +
    2113. Slightly different approach
    2114. +
    2115. Time decay rate
    2116. +
    2117. Code with a Number of Minibatches which varies
    2118. +
    2119. Replace or not
    2120. +
    2121. Momentum based GD
    2122. +
    2123. More on momentum based approaches
    2124. +
    2125. Momentum parameter
    2126. +
    2127. Second moment of the gradient
    2128. +
    2129. RMS prop
    2130. +
    2131. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2132. +
    2133. Algorithms and codes for Adagrad, RMSprop and Adam
    2134. +
    2135. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2136. +
    2137. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2138. +
    2139. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2140. +
    2141. Practical tips
    2142. +
    2143. Sneaking in auotmatic differentiation using Autograd
    2144. +
    2145. Same code but now with momentum gradient descent
    2146. +
    2147. Including Stochastic Gradient Descent with Autograd
    2148. +
    2149. Same code but now with momentum gradient descent
    2150. +
    2151. Similar (second order function now) problem but now with AdaGrad
    2152. +
    2153. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2154. +
    2155. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2156. +
    2157. Material for the lab sessions
    2158. @@ -297,7 +316,7 @@ perform a parameter update.
    2159. 26
    2160. 27
    2161. ...
    2162. -
    2163. 46
    2164. +
    2165. 48
    2166. »
    2167. diff --git a/doc/pub/week37/html/._week37-bs018.html b/doc/pub/week37/html/._week37-bs018.html index a4b654a0b..86155fa0d 100644 --- a/doc/pub/week37/html/._week37-bs018.html +++ b/doc/pub/week37/html/._week37-bs018.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    2168. Program example for gradient descent with Ridge Regression
    2169. Using gradient descent methods, limitations
    2170. Improving gradient descent with momentum
    2171. -
    2172. Same code but now with momentum gradient descent
    2173. -
    2174. Overview video on Stochastic Gradient Descent
    2175. +
    2176. Same code but now with momentum gradient descent
    2177. +
    2178. Overview video on Stochastic Gradient Descent (SGD)
    2179. Batches and mini-batches
    2180. -
    2181. Stochastic Gradient Descent (SGD)
    2182. -
    2183. Stochastic Gradient Descent
    2184. -
    2185. Computation of gradients
    2186. -
    2187. SGD example
    2188. -
    2189. The gradient step
    2190. -
    2191. Simple example code
    2192. -
    2193. When do we stop?
    2194. -
    2195. Slightly different approach
    2196. -
    2197. Time decay rate
    2198. -
    2199. Code with a Number of Minibatches which varies
    2200. -
    2201. Replace or not
    2202. -
    2203. Momentum based GD
    2204. -
    2205. More on momentum based approaches
    2206. -
    2207. Momentum parameter
    2208. -
    2209. Second moment of the gradient
    2210. -
    2211. RMS prop
    2212. -
    2213. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2214. -
    2215. Algorithms and codes for Adagrad, RMSprop and Adam
    2216. -
    2217. Practical tips
    2218. -
    2219. Sneaking in automatic differentiation using Autograd
    2220. -
    2221. Same code but now with momentum gradient descent
    2222. -
    2223. But none of these can compete with Newton's method
    2224. -
    2225. Including Stochastic Gradient Descent with Autograd
    2226. -
    2227. Same code but now with momentum gradient descent
    2228. -
    2229. Similar (second order function now) problem but now with AdaGrad
    2230. -
    2231. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2232. -
    2233. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2234. -
    2235. Material for the lab sessions
    2236. +
    2237. Pros and cons
    2238. +
    2239. Convergence rates
    2240. +
    2241. Accuracy
    2242. +
    2243. Stochastic Gradient Descent (SGD)
    2244. +
    2245. Stochastic Gradient Descent
    2246. +
    2247. Computation of gradients
    2248. +
    2249. SGD example
    2250. +
    2251. The gradient step
    2252. +
    2253. Simple example code
    2254. +
    2255. When do we stop?
    2256. +
    2257. Slightly different approach
    2258. +
    2259. Time decay rate
    2260. +
    2261. Code with a Number of Minibatches which varies
    2262. +
    2263. Replace or not
    2264. +
    2265. Momentum based GD
    2266. +
    2267. More on momentum based approaches
    2268. +
    2269. Momentum parameter
    2270. +
    2271. Second moment of the gradient
    2272. +
    2273. RMS prop
    2274. +
    2275. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2276. +
    2277. Algorithms and codes for Adagrad, RMSprop and Adam
    2278. +
    2279. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2280. +
    2281. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2282. +
    2283. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2284. +
    2285. Practical tips
    2286. +
    2287. Sneaking in auotmatic differentiation using Autograd
    2288. +
    2289. Same code but now with momentum gradient descent
    2290. +
    2291. Including Stochastic Gradient Descent with Autograd
    2292. +
    2293. Same code but now with momentum gradient descent
    2294. +
    2295. Similar (second order function now) problem but now with AdaGrad
    2296. +
    2297. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2298. +
    2299. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2300. +
    2301. Material for the lab sessions
    2302. @@ -258,32 +277,13 @@ MathJax.Hub.Config({

       

       

       

      -

      Stochastic Gradient Descent (SGD)

      - -

      In stochastic gradient descent, the extreme case is the case where we -have only one batch, that is we include the whole data set. -

      - -

      This process is called Stochastic Gradient -Descent (SGD) (or also sometimes on-line gradient descent). This is -relatively less common to see because in practice due to vectorized -code optimizations it can be computationally much more efficient to -evaluate the gradient for 100 examples, than the gradient for one -example 100 times. Even though SGD technically refers to using a -single example at a time to evaluate the gradient, you will hear -people use the term SGD even when referring to mini-batch gradient -descent (i.e. mentions of MGD for “Minibatch Gradient Descent”, or BGD -for “Batch gradient descent” are rare to see), where it is usually -assumed that mini-batches are used. The size of the mini-batch is a -hyperparameter but it is not very common to cross-validate or bootstrap it. It is -usually based on memory constraints (if any), or set to some value, -e.g. 32, 64 or 128. We use powers of 2 in practice because many -vectorized operation implementations work faster when their inputs are -sized in powers of 2. -

      - -

      In our notes with SGD we mean stochastic gradient descent with mini-batches.

      +

      Pros and cons

      +
        +
      1. Speed: SGD is faster than gradient descent because it uses only one training example per iteration, whereas gradient descent requires the entire dataset. This speed advantage becomes more significant as the size of the dataset increases.
      2. +
      3. Convergence: Gradient descent has a more predictable convergence behaviour because it uses the average gradient of the entire dataset. In contrast, SGD’s convergence behaviour can be more erratic due to its random sampling of individual training examples.
      4. +
      5. Memory: Gradient descent requires more memory than SGD because it must store the entire dataset for each iteration. SGD only needs to store the current training example, making it more memory-efficient.
      6. +

        @@ -309,7 +309,7 @@ sized in powers of 2.
      • 27
      • 28
      • ...
      • -
      • 46
      • +
      • 48
      • »
      diff --git a/doc/pub/week37/html/._week37-bs019.html b/doc/pub/week37/html/._week37-bs019.html index ceb6547d6..bd928e866 100644 --- a/doc/pub/week37/html/._week37-bs019.html +++ b/doc/pub/week37/html/._week37-bs019.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    2303. Program example for gradient descent with Ridge Regression
    2304. Using gradient descent methods, limitations
    2305. Improving gradient descent with momentum
    2306. -
    2307. Same code but now with momentum gradient descent
    2308. -
    2309. Overview video on Stochastic Gradient Descent
    2310. +
    2311. Same code but now with momentum gradient descent
    2312. +
    2313. Overview video on Stochastic Gradient Descent (SGD)
    2314. Batches and mini-batches
    2315. -
    2316. Stochastic Gradient Descent (SGD)
    2317. -
    2318. Stochastic Gradient Descent
    2319. -
    2320. Computation of gradients
    2321. -
    2322. SGD example
    2323. -
    2324. The gradient step
    2325. -
    2326. Simple example code
    2327. -
    2328. When do we stop?
    2329. -
    2330. Slightly different approach
    2331. -
    2332. Time decay rate
    2333. -
    2334. Code with a Number of Minibatches which varies
    2335. -
    2336. Replace or not
    2337. -
    2338. Momentum based GD
    2339. -
    2340. More on momentum based approaches
    2341. -
    2342. Momentum parameter
    2343. -
    2344. Second moment of the gradient
    2345. -
    2346. RMS prop
    2347. -
    2348. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2349. -
    2350. Algorithms and codes for Adagrad, RMSprop and Adam
    2351. -
    2352. Practical tips
    2353. -
    2354. Sneaking in automatic differentiation using Autograd
    2355. -
    2356. Same code but now with momentum gradient descent
    2357. -
    2358. But none of these can compete with Newton's method
    2359. -
    2360. Including Stochastic Gradient Descent with Autograd
    2361. -
    2362. Same code but now with momentum gradient descent
    2363. -
    2364. Similar (second order function now) problem but now with AdaGrad
    2365. -
    2366. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2367. -
    2368. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2369. -
    2370. Material for the lab sessions
    2371. +
    2372. Pros and cons
    2373. +
    2374. Convergence rates
    2375. +
    2376. Accuracy
    2377. +
    2378. Stochastic Gradient Descent (SGD)
    2379. +
    2380. Stochastic Gradient Descent
    2381. +
    2382. Computation of gradients
    2383. +
    2384. SGD example
    2385. +
    2386. The gradient step
    2387. +
    2388. Simple example code
    2389. +
    2390. When do we stop?
    2391. +
    2392. Slightly different approach
    2393. +
    2394. Time decay rate
    2395. +
    2396. Code with a Number of Minibatches which varies
    2397. +
    2398. Replace or not
    2399. +
    2400. Momentum based GD
    2401. +
    2402. More on momentum based approaches
    2403. +
    2404. Momentum parameter
    2405. +
    2406. Second moment of the gradient
    2407. +
    2408. RMS prop
    2409. +
    2410. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2411. +
    2412. Algorithms and codes for Adagrad, RMSprop and Adam
    2413. +
    2414. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2415. +
    2416. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2417. +
    2418. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2419. +
    2420. Practical tips
    2421. +
    2422. Sneaking in auotmatic differentiation using Autograd
    2423. +
    2424. Same code but now with momentum gradient descent
    2425. +
    2426. Including Stochastic Gradient Descent with Autograd
    2427. +
    2428. Same code but now with momentum gradient descent
    2429. +
    2430. Similar (second order function now) problem but now with AdaGrad
    2431. +
    2432. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2433. +
    2434. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2435. +
    2436. Material for the lab sessions
    2437. @@ -258,22 +277,12 @@ MathJax.Hub.Config({

       

       

       

      -

      Stochastic Gradient Descent

      - -

      Stochastic gradient descent (SGD) and variants thereof address some of -the shortcomings of the Gradient descent method discussed above. -

      - -

      The underlying idea of SGD comes from the observation that the cost -function, which we want to minimize, can almost always be written as a -sum over \( n \) data points \( \{\mathbf{x}_i\}_{i=1}^n \), -

      -$$ -C(\mathbf{\beta}) = \sum_{i=1}^n c_i(\mathbf{x}_i, -\mathbf{\beta}). -$$ - +

      Convergence rates

      +
        +
      1. Stochastic Gradient Descent has a faster convergence rate due to the use of single training examples in each iteration.
      2. +
      3. Gradient Descent as a slower convergence rate, as it uses the entire dataset for each iteration.
      4. +

      diff --git a/doc/pub/week37/html/._week37-bs020.html b/doc/pub/week37/html/._week37-bs020.html index 75db11f4d..ed9d1f077 100644 --- a/doc/pub/week37/html/._week37-bs020.html +++ b/doc/pub/week37/html/._week37-bs020.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    2438. Program example for gradient descent with Ridge Regression
    2439. Using gradient descent methods, limitations
    2440. Improving gradient descent with momentum
    2441. -
    2442. Same code but now with momentum gradient descent
    2443. -
    2444. Overview video on Stochastic Gradient Descent
    2445. +
    2446. Same code but now with momentum gradient descent
    2447. +
    2448. Overview video on Stochastic Gradient Descent (SGD)
    2449. Batches and mini-batches
    2450. -
    2451. Stochastic Gradient Descent (SGD)
    2452. -
    2453. Stochastic Gradient Descent
    2454. -
    2455. Computation of gradients
    2456. -
    2457. SGD example
    2458. -
    2459. The gradient step
    2460. -
    2461. Simple example code
    2462. -
    2463. When do we stop?
    2464. -
    2465. Slightly different approach
    2466. -
    2467. Time decay rate
    2468. -
    2469. Code with a Number of Minibatches which varies
    2470. -
    2471. Replace or not
    2472. -
    2473. Momentum based GD
    2474. -
    2475. More on momentum based approaches
    2476. -
    2477. Momentum parameter
    2478. -
    2479. Second moment of the gradient
    2480. -
    2481. RMS prop
    2482. -
    2483. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2484. -
    2485. Algorithms and codes for Adagrad, RMSprop and Adam
    2486. -
    2487. Practical tips
    2488. -
    2489. Sneaking in automatic differentiation using Autograd
    2490. -
    2491. Same code but now with momentum gradient descent
    2492. -
    2493. But none of these can compete with Newton's method
    2494. -
    2495. Including Stochastic Gradient Descent with Autograd
    2496. -
    2497. Same code but now with momentum gradient descent
    2498. -
    2499. Similar (second order function now) problem but now with AdaGrad
    2500. -
    2501. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2502. -
    2503. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2504. -
    2505. Material for the lab sessions
    2506. +
    2507. Pros and cons
    2508. +
    2509. Convergence rates
    2510. +
    2511. Accuracy
    2512. +
    2513. Stochastic Gradient Descent (SGD)
    2514. +
    2515. Stochastic Gradient Descent
    2516. +
    2517. Computation of gradients
    2518. +
    2519. SGD example
    2520. +
    2521. The gradient step
    2522. +
    2523. Simple example code
    2524. +
    2525. When do we stop?
    2526. +
    2527. Slightly different approach
    2528. +
    2529. Time decay rate
    2530. +
    2531. Code with a Number of Minibatches which varies
    2532. +
    2533. Replace or not
    2534. +
    2535. Momentum based GD
    2536. +
    2537. More on momentum based approaches
    2538. +
    2539. Momentum parameter
    2540. +
    2541. Second moment of the gradient
    2542. +
    2543. RMS prop
    2544. +
    2545. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2546. +
    2547. Algorithms and codes for Adagrad, RMSprop and Adam
    2548. +
    2549. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2550. +
    2551. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2552. +
    2553. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2554. +
    2555. Practical tips
    2556. +
    2557. Sneaking in auotmatic differentiation using Autograd
    2558. +
    2559. Same code but now with momentum gradient descent
    2560. +
    2561. Including Stochastic Gradient Descent with Autograd
    2562. +
    2563. Same code but now with momentum gradient descent
    2564. +
    2565. Similar (second order function now) problem but now with AdaGrad
    2566. +
    2567. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2568. +
    2569. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2570. +
    2571. Material for the lab sessions
    2572. @@ -258,21 +277,27 @@ MathJax.Hub.Config({

       

       

       

      -

      Computation of gradients

      +

      Accuracy

      -

      This in turn means that the gradient can be -computed as a sum over \( i \)-gradients +

      In general, stochastic Gradient Descent is Less accurate than gradient +descent, as it calculates the gradient on single examples, which may +not accurately represent the overall dataset. Gradient Descent is +more accurate because it uses the average gradient calculated over the +entire dataset.

      -$$ -\nabla_\beta C(\mathbf{\beta}) = \sum_i^n \nabla_\beta c_i(\mathbf{x}_i, -\mathbf{\beta}). -$$ -

      Stochasticity/randomness is introduced by only taking the -gradient on a subset of the data called minibatches. If there are \( n \) -data points and the size of each minibatch is \( M \), there will be \( n/M \) -minibatches. We denote these minibatches by \( B_k \) where -\( k=1,\cdots,n/M \). +

      There are other disadvantages to using SGD. The main drawback is that +its convergence behaviour can be more erratic due to the random +sampling of individual training examples. This can lead to less +accurate results, as the algorithm may not converge to the true +minimum of the cost function. Additionally, the learning rate, which +determines the step size of each update to the model’s parameters, +must be carefully chosen to ensure convergence. +

      + +

      It is however the method of choice in deep learning algorithms where +SGD is often used in combination with other optimization techniques, +such as momentum or adaptive learning rates

      @@ -300,7 +325,7 @@ minibatches. We denote these minibatches by \( B_k \) where

    2573. 29
    2574. 30
    2575. ...
    2576. -
    2577. 46
    2578. +
    2579. 48
    2580. »
    2581. diff --git a/doc/pub/week37/html/._week37-bs021.html b/doc/pub/week37/html/._week37-bs021.html index 4a4d3fe14..3533677e4 100644 --- a/doc/pub/week37/html/._week37-bs021.html +++ b/doc/pub/week37/html/._week37-bs021.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    2582. Program example for gradient descent with Ridge Regression
    2583. Using gradient descent methods, limitations
    2584. Improving gradient descent with momentum
    2585. -
    2586. Same code but now with momentum gradient descent
    2587. -
    2588. Overview video on Stochastic Gradient Descent
    2589. +
    2590. Same code but now with momentum gradient descent
    2591. +
    2592. Overview video on Stochastic Gradient Descent (SGD)
    2593. Batches and mini-batches
    2594. -
    2595. Stochastic Gradient Descent (SGD)
    2596. -
    2597. Stochastic Gradient Descent
    2598. -
    2599. Computation of gradients
    2600. -
    2601. SGD example
    2602. -
    2603. The gradient step
    2604. -
    2605. Simple example code
    2606. -
    2607. When do we stop?
    2608. -
    2609. Slightly different approach
    2610. -
    2611. Time decay rate
    2612. -
    2613. Code with a Number of Minibatches which varies
    2614. -
    2615. Replace or not
    2616. -
    2617. Momentum based GD
    2618. -
    2619. More on momentum based approaches
    2620. -
    2621. Momentum parameter
    2622. -
    2623. Second moment of the gradient
    2624. -
    2625. RMS prop
    2626. -
    2627. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2628. -
    2629. Algorithms and codes for Adagrad, RMSprop and Adam
    2630. -
    2631. Practical tips
    2632. -
    2633. Sneaking in automatic differentiation using Autograd
    2634. -
    2635. Same code but now with momentum gradient descent
    2636. -
    2637. But none of these can compete with Newton's method
    2638. -
    2639. Including Stochastic Gradient Descent with Autograd
    2640. -
    2641. Same code but now with momentum gradient descent
    2642. -
    2643. Similar (second order function now) problem but now with AdaGrad
    2644. -
    2645. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2646. -
    2647. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2648. -
    2649. Material for the lab sessions
    2650. +
    2651. Pros and cons
    2652. +
    2653. Convergence rates
    2654. +
    2655. Accuracy
    2656. +
    2657. Stochastic Gradient Descent (SGD)
    2658. +
    2659. Stochastic Gradient Descent
    2660. +
    2661. Computation of gradients
    2662. +
    2663. SGD example
    2664. +
    2665. The gradient step
    2666. +
    2667. Simple example code
    2668. +
    2669. When do we stop?
    2670. +
    2671. Slightly different approach
    2672. +
    2673. Time decay rate
    2674. +
    2675. Code with a Number of Minibatches which varies
    2676. +
    2677. Replace or not
    2678. +
    2679. Momentum based GD
    2680. +
    2681. More on momentum based approaches
    2682. +
    2683. Momentum parameter
    2684. +
    2685. Second moment of the gradient
    2686. +
    2687. RMS prop
    2688. +
    2689. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2690. +
    2691. Algorithms and codes for Adagrad, RMSprop and Adam
    2692. +
    2693. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2694. +
    2695. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2696. +
    2697. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2698. +
    2699. Practical tips
    2700. +
    2701. Sneaking in auotmatic differentiation using Autograd
    2702. +
    2703. Same code but now with momentum gradient descent
    2704. +
    2705. Including Stochastic Gradient Descent with Autograd
    2706. +
    2707. Same code but now with momentum gradient descent
    2708. +
    2709. Similar (second order function now) problem but now with AdaGrad
    2710. +
    2711. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2712. +
    2713. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2714. +
    2715. Material for the lab sessions
    2716. @@ -258,28 +277,31 @@ MathJax.Hub.Config({

       

       

       

      -

      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 -\( B_1 = (\mathbf{x}_1,\mathbf{x}_2), \cdots, B_5 = -(\mathbf{x}_9,\mathbf{x}_{10}) \). Note that if you choose \( M=1 \) you -have only a single batch with all data points and on the other extreme, -you may choose \( M=n \) resulting in a minibatch for each datapoint, i.e -\( B_k = \mathbf{x}_k \). +

      Stochastic Gradient Descent (SGD)

      + +

      In stochastic gradient descent, the extreme case is the case where we +have only one batch, that is we include the whole data set.

      -

      The idea is now to approximate the gradient by replacing the sum over -all data points with a sum over the data points in one the minibatches -picked at random in each gradient descent step +

      This process is called Stochastic Gradient +Descent (SGD) (or also sometimes on-line gradient descent). This is +relatively less common to see because in practice due to vectorized +code optimizations it can be computationally much more efficient to +evaluate the gradient for 100 examples, than the gradient for one +example 100 times. Even though SGD technically refers to using a +single example at a time to evaluate the gradient, you will hear +people use the term SGD even when referring to mini-batch gradient +descent (i.e. mentions of MGD for “Minibatch Gradient Descent”, or BGD +for “Batch gradient descent” are rare to see), where it is usually +assumed that mini-batches are used. The size of the mini-batch is a +hyperparameter but it is not very common to cross-validate or bootstrap it. It is +usually based on memory constraints (if any), or set to some value, +e.g. 32, 64 or 128. We use powers of 2 in practice because many +vectorized operation implementations work faster when their inputs are +sized in powers of 2.

      -$$ -\nabla_{\beta} -C(\mathbf{\beta}) = \sum_{i=1}^n \nabla_\beta c_i(\mathbf{x}_i, -\mathbf{\beta}) \rightarrow \sum_{i \in B_k}^n \nabla_\beta -c_i(\mathbf{x}_i, \mathbf{\beta}). -$$ +

      In our notes with SGD we mean stochastic gradient descent with mini-batches.

      @@ -306,7 +328,7 @@ $$

    2717. 30
    2718. 31
    2719. ...
    2720. -
    2721. 46
    2722. +
    2723. 48
    2724. »
    2725. diff --git a/doc/pub/week37/html/._week37-bs022.html b/doc/pub/week37/html/._week37-bs022.html index 2921b04c2..e0f11d8cd 100644 --- a/doc/pub/week37/html/._week37-bs022.html +++ b/doc/pub/week37/html/._week37-bs022.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    2726. Program example for gradient descent with Ridge Regression
    2727. Using gradient descent methods, limitations
    2728. Improving gradient descent with momentum
    2729. -
    2730. Same code but now with momentum gradient descent
    2731. -
    2732. Overview video on Stochastic Gradient Descent
    2733. +
    2734. Same code but now with momentum gradient descent
    2735. +
    2736. Overview video on Stochastic Gradient Descent (SGD)
    2737. Batches and mini-batches
    2738. -
    2739. Stochastic Gradient Descent (SGD)
    2740. -
    2741. Stochastic Gradient Descent
    2742. -
    2743. Computation of gradients
    2744. -
    2745. SGD example
    2746. -
    2747. The gradient step
    2748. -
    2749. Simple example code
    2750. -
    2751. When do we stop?
    2752. -
    2753. Slightly different approach
    2754. -
    2755. Time decay rate
    2756. -
    2757. Code with a Number of Minibatches which varies
    2758. -
    2759. Replace or not
    2760. -
    2761. Momentum based GD
    2762. -
    2763. More on momentum based approaches
    2764. -
    2765. Momentum parameter
    2766. -
    2767. Second moment of the gradient
    2768. -
    2769. RMS prop
    2770. -
    2771. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2772. -
    2773. Algorithms and codes for Adagrad, RMSprop and Adam
    2774. -
    2775. Practical tips
    2776. -
    2777. Sneaking in automatic differentiation using Autograd
    2778. -
    2779. Same code but now with momentum gradient descent
    2780. -
    2781. But none of these can compete with Newton's method
    2782. -
    2783. Including Stochastic Gradient Descent with Autograd
    2784. -
    2785. Same code but now with momentum gradient descent
    2786. -
    2787. Similar (second order function now) problem but now with AdaGrad
    2788. -
    2789. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2790. -
    2791. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2792. -
    2793. Material for the lab sessions
    2794. +
    2795. Pros and cons
    2796. +
    2797. Convergence rates
    2798. +
    2799. Accuracy
    2800. +
    2801. Stochastic Gradient Descent (SGD)
    2802. +
    2803. Stochastic Gradient Descent
    2804. +
    2805. Computation of gradients
    2806. +
    2807. SGD example
    2808. +
    2809. The gradient step
    2810. +
    2811. Simple example code
    2812. +
    2813. When do we stop?
    2814. +
    2815. Slightly different approach
    2816. +
    2817. Time decay rate
    2818. +
    2819. Code with a Number of Minibatches which varies
    2820. +
    2821. Replace or not
    2822. +
    2823. Momentum based GD
    2824. +
    2825. More on momentum based approaches
    2826. +
    2827. Momentum parameter
    2828. +
    2829. Second moment of the gradient
    2830. +
    2831. RMS prop
    2832. +
    2833. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2834. +
    2835. Algorithms and codes for Adagrad, RMSprop and Adam
    2836. +
    2837. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2838. +
    2839. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2840. +
    2841. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2842. +
    2843. Practical tips
    2844. +
    2845. Sneaking in auotmatic differentiation using Autograd
    2846. +
    2847. Same code but now with momentum gradient descent
    2848. +
    2849. Including Stochastic Gradient Descent with Autograd
    2850. +
    2851. Same code but now with momentum gradient descent
    2852. +
    2853. Similar (second order function now) problem but now with AdaGrad
    2854. +
    2855. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2856. +
    2857. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2858. +
    2859. Material for the lab sessions
    2860. @@ -258,21 +277,22 @@ MathJax.Hub.Config({

       

       

       

      -

      The gradient step

      +

      Stochastic Gradient Descent

      -

      Thus a gradient descent step now looks like

      -$$ -\beta_{j+1} = \beta_j - \gamma_j \sum_{i \in B_k}^n \nabla_\beta c_i(\mathbf{x}_i, -\mathbf{\beta}) -$$ - -

      where \( k \) is picked at random with equal -probability from \( [1,n/M] \). An iteration over the number of -minibathces (n/M) is commonly referred to as an epoch. Thus it is -typical to choose a number of epochs and for each epoch iterate over -the number of minibatches, as exemplified in the code below. +

      Stochastic gradient descent (SGD) and variants thereof address some of +the shortcomings of the Gradient descent method discussed above.

      +

      The underlying idea of SGD comes from the observation that the cost +function, which we want to minimize, can almost always be written as a +sum over \( n \) data points \( \{\mathbf{x}_i\}_{i=1}^n \), +

      +$$ +C(\mathbf{\beta}) = \sum_{i=1}^n c_i(\mathbf{x}_i, +\mathbf{\beta}). +$$ + +

        @@ -298,7 +318,7 @@ the number of minibatches, as exemplified in the code below.
      • 31
      • 32
      • ...
      • -
      • 46
      • +
      • 48
      • »
      diff --git a/doc/pub/week37/html/._week37-bs023.html b/doc/pub/week37/html/._week37-bs023.html index c65574214..9bbefc25d 100644 --- a/doc/pub/week37/html/._week37-bs023.html +++ b/doc/pub/week37/html/._week37-bs023.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    2861. Program example for gradient descent with Ridge Regression
    2862. Using gradient descent methods, limitations
    2863. Improving gradient descent with momentum
    2864. -
    2865. Same code but now with momentum gradient descent
    2866. -
    2867. Overview video on Stochastic Gradient Descent
    2868. +
    2869. Same code but now with momentum gradient descent
    2870. +
    2871. Overview video on Stochastic Gradient Descent (SGD)
    2872. Batches and mini-batches
    2873. -
    2874. Stochastic Gradient Descent (SGD)
    2875. -
    2876. Stochastic Gradient Descent
    2877. -
    2878. Computation of gradients
    2879. -
    2880. SGD example
    2881. -
    2882. The gradient step
    2883. -
    2884. Simple example code
    2885. -
    2886. When do we stop?
    2887. -
    2888. Slightly different approach
    2889. -
    2890. Time decay rate
    2891. -
    2892. Code with a Number of Minibatches which varies
    2893. -
    2894. Replace or not
    2895. -
    2896. Momentum based GD
    2897. -
    2898. More on momentum based approaches
    2899. -
    2900. Momentum parameter
    2901. -
    2902. Second moment of the gradient
    2903. -
    2904. RMS prop
    2905. -
    2906. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2907. -
    2908. Algorithms and codes for Adagrad, RMSprop and Adam
    2909. -
    2910. Practical tips
    2911. -
    2912. Sneaking in automatic differentiation using Autograd
    2913. -
    2914. Same code but now with momentum gradient descent
    2915. -
    2916. But none of these can compete with Newton's method
    2917. -
    2918. Including Stochastic Gradient Descent with Autograd
    2919. -
    2920. Same code but now with momentum gradient descent
    2921. -
    2922. Similar (second order function now) problem but now with AdaGrad
    2923. -
    2924. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2925. -
    2926. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2927. -
    2928. Material for the lab sessions
    2929. +
    2930. Pros and cons
    2931. +
    2932. Convergence rates
    2933. +
    2934. Accuracy
    2935. +
    2936. Stochastic Gradient Descent (SGD)
    2937. +
    2938. Stochastic Gradient Descent
    2939. +
    2940. Computation of gradients
    2941. +
    2942. SGD example
    2943. +
    2944. The gradient step
    2945. +
    2946. Simple example code
    2947. +
    2948. When do we stop?
    2949. +
    2950. Slightly different approach
    2951. +
    2952. Time decay rate
    2953. +
    2954. Code with a Number of Minibatches which varies
    2955. +
    2956. Replace or not
    2957. +
    2958. Momentum based GD
    2959. +
    2960. More on momentum based approaches
    2961. +
    2962. Momentum parameter
    2963. +
    2964. Second moment of the gradient
    2965. +
    2966. RMS prop
    2967. +
    2968. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    2969. +
    2970. Algorithms and codes for Adagrad, RMSprop and Adam
    2971. +
    2972. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2973. +
    2974. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2975. +
    2976. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    2977. +
    2978. Practical tips
    2979. +
    2980. Sneaking in auotmatic differentiation using Autograd
    2981. +
    2982. Same code but now with momentum gradient descent
    2983. +
    2984. Including Stochastic Gradient Descent with Autograd
    2985. +
    2986. Same code but now with momentum gradient descent
    2987. +
    2988. Similar (second order function now) problem but now with AdaGrad
    2989. +
    2990. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    2991. +
    2992. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    2993. +
    2994. Material for the lab sessions
    2995. @@ -258,51 +277,21 @@ MathJax.Hub.Config({

       

       

       

      -

      Simple example code

      +

      Computation of gradients

      +

      This in turn means that the gradient can be +computed as a sum over \( i \)-gradients +

      +$$ +\nabla_\beta C(\mathbf{\beta}) = \sum_i^n \nabla_\beta c_i(\mathbf{x}_i, +\mathbf{\beta}). +$$ - -
      -
      -
      -
      -
      -
      import numpy as np 
      -
      -n = 100 #100 datapoints 
      -M = 5   #size of each minibatch
      -m = int(n/M) #number of minibatches
      -n_epochs = 10 #number of epochs
      -
      -j = 0
      -for epoch in range(1,n_epochs+1):
      -    for i in range(m):
      -        k = np.random.randint(m) #Pick the k-th minibatch at random
      -        #Compute the gradient using the data in minibatch Bk
      -        #Compute new suggestion for 
      -        j += 1
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      - -

      Taking the gradient only on a subset of the data has two important -benefits. First, it introduces randomness which decreases the chance -that our opmization scheme gets stuck in a local minima. Second, if -the size of the minibatches are small relative to the number of -datapoints (\( M < n \)), the computation of the gradient is much -cheaper since we sum over the datapoints in the \( k-th \) minibatch and not -all \( n \) datapoints. +

      Stochasticity/randomness is introduced by only taking the +gradient on a subset of the data called minibatches. If there are \( n \) +data points and the size of each minibatch is \( M \), there will be \( n/M \) +minibatches. We denote these minibatches by \( B_k \) where +\( k=1,\cdots,n/M \).

      @@ -330,7 +319,7 @@ all \( n \) datapoints.

    2996. 32
    2997. 33
    2998. ...
    2999. -
    3000. 46
    3001. +
    3002. 48
    3003. »
    3004. diff --git a/doc/pub/week37/html/._week37-bs024.html b/doc/pub/week37/html/._week37-bs024.html index 90d0eed4e..8a2f022de 100644 --- a/doc/pub/week37/html/._week37-bs024.html +++ b/doc/pub/week37/html/._week37-bs024.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    3005. Program example for gradient descent with Ridge Regression
    3006. Using gradient descent methods, limitations
    3007. Improving gradient descent with momentum
    3008. -
    3009. Same code but now with momentum gradient descent
    3010. -
    3011. Overview video on Stochastic Gradient Descent
    3012. +
    3013. Same code but now with momentum gradient descent
    3014. +
    3015. Overview video on Stochastic Gradient Descent (SGD)
    3016. Batches and mini-batches
    3017. -
    3018. Stochastic Gradient Descent (SGD)
    3019. -
    3020. Stochastic Gradient Descent
    3021. -
    3022. Computation of gradients
    3023. -
    3024. SGD example
    3025. -
    3026. The gradient step
    3027. -
    3028. Simple example code
    3029. -
    3030. When do we stop?
    3031. -
    3032. Slightly different approach
    3033. -
    3034. Time decay rate
    3035. -
    3036. Code with a Number of Minibatches which varies
    3037. -
    3038. Replace or not
    3039. -
    3040. Momentum based GD
    3041. -
    3042. More on momentum based approaches
    3043. -
    3044. Momentum parameter
    3045. -
    3046. Second moment of the gradient
    3047. -
    3048. RMS prop
    3049. -
    3050. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    3051. -
    3052. Algorithms and codes for Adagrad, RMSprop and Adam
    3053. -
    3054. Practical tips
    3055. -
    3056. Sneaking in automatic differentiation using Autograd
    3057. -
    3058. Same code but now with momentum gradient descent
    3059. -
    3060. But none of these can compete with Newton's method
    3061. -
    3062. Including Stochastic Gradient Descent with Autograd
    3063. -
    3064. Same code but now with momentum gradient descent
    3065. -
    3066. Similar (second order function now) problem but now with AdaGrad
    3067. -
    3068. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    3069. -
    3070. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    3071. -
    3072. Material for the lab sessions
    3073. +
    3074. Pros and cons
    3075. +
    3076. Convergence rates
    3077. +
    3078. Accuracy
    3079. +
    3080. Stochastic Gradient Descent (SGD)
    3081. +
    3082. Stochastic Gradient Descent
    3083. +
    3084. Computation of gradients
    3085. +
    3086. SGD example
    3087. +
    3088. The gradient step
    3089. +
    3090. Simple example code
    3091. +
    3092. When do we stop?
    3093. +
    3094. Slightly different approach
    3095. +
    3096. Time decay rate
    3097. +
    3098. Code with a Number of Minibatches which varies
    3099. +
    3100. Replace or not
    3101. +
    3102. Momentum based GD
    3103. +
    3104. More on momentum based approaches
    3105. +
    3106. Momentum parameter
    3107. +
    3108. Second moment of the gradient
    3109. +
    3110. RMS prop
    3111. +
    3112. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    3113. +
    3114. Algorithms and codes for Adagrad, RMSprop and Adam
    3115. +
    3116. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3117. +
    3118. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3119. +
    3120. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3121. +
    3122. Practical tips
    3123. +
    3124. Sneaking in auotmatic differentiation using Autograd
    3125. +
    3126. Same code but now with momentum gradient descent
    3127. +
    3128. Including Stochastic Gradient Descent with Autograd
    3129. +
    3130. Same code but now with momentum gradient descent
    3131. +
    3132. Similar (second order function now) problem but now with AdaGrad
    3133. +
    3134. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    3135. +
    3136. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    3137. +
    3138. Material for the lab sessions
    3139. @@ -258,20 +277,29 @@ MathJax.Hub.Config({

       

       

       

      -

      When do we stop?

      - -

      A natural question is when do we stop the search for a new minimum? -One possibility is to compute the full gradient after a given number -of epochs and check if the norm of the gradient is smaller than some -threshold and stop if true. However, the condition that the gradient -is zero is valid also for local minima, so this would only tell us -that we are close to a local/global minimum. However, we could also -evaluate the cost function at this point, store the result and -continue the search. If the test kicks in at a later stage we can -compare the values of the cost function and keep the \( \beta \) that -gave the lowest value. +

      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 +\( B_1 = (\mathbf{x}_1,\mathbf{x}_2), \cdots, B_5 = +(\mathbf{x}_9,\mathbf{x}_{10}) \). Note that if you choose \( M=1 \) you +have only a single batch with all data points and on the other extreme, +you may choose \( M=n \) resulting in a minibatch for each datapoint, i.e +\( B_k = \mathbf{x}_k \).

      +

      The idea is now to approximate the gradient by replacing the sum over +all data points with a sum over the data points in one the minibatches +picked at random in each gradient descent step +

      +$$ +\nabla_{\beta} +C(\mathbf{\beta}) = \sum_{i=1}^n \nabla_\beta c_i(\mathbf{x}_i, +\mathbf{\beta}) \rightarrow \sum_{i \in B_k}^n \nabla_\beta +c_i(\mathbf{x}_i, \mathbf{\beta}). +$$ + +

        @@ -297,7 +325,7 @@ gave the lowest value.
      • 33
      • 34
      • ...
      • -
      • 46
      • +
      • 48
      • »
      diff --git a/doc/pub/week37/html/._week37-bs025.html b/doc/pub/week37/html/._week37-bs025.html index f248bb5e5..3d2c765b5 100644 --- a/doc/pub/week37/html/._week37-bs025.html +++ b/doc/pub/week37/html/._week37-bs025.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    3140. Program example for gradient descent with Ridge Regression
    3141. Using gradient descent methods, limitations
    3142. Improving gradient descent with momentum
    3143. -
    3144. Same code but now with momentum gradient descent
    3145. -
    3146. Overview video on Stochastic Gradient Descent
    3147. +
    3148. Same code but now with momentum gradient descent
    3149. +
    3150. Overview video on Stochastic Gradient Descent (SGD)
    3151. Batches and mini-batches
    3152. -
    3153. Stochastic Gradient Descent (SGD)
    3154. -
    3155. Stochastic Gradient Descent
    3156. -
    3157. Computation of gradients
    3158. -
    3159. SGD example
    3160. -
    3161. The gradient step
    3162. -
    3163. Simple example code
    3164. -
    3165. When do we stop?
    3166. -
    3167. Slightly different approach
    3168. -
    3169. Time decay rate
    3170. -
    3171. Code with a Number of Minibatches which varies
    3172. -
    3173. Replace or not
    3174. -
    3175. Momentum based GD
    3176. -
    3177. More on momentum based approaches
    3178. -
    3179. Momentum parameter
    3180. -
    3181. Second moment of the gradient
    3182. -
    3183. RMS prop
    3184. -
    3185. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    3186. -
    3187. Algorithms and codes for Adagrad, RMSprop and Adam
    3188. -
    3189. Practical tips
    3190. -
    3191. Sneaking in automatic differentiation using Autograd
    3192. -
    3193. Same code but now with momentum gradient descent
    3194. -
    3195. But none of these can compete with Newton's method
    3196. -
    3197. Including Stochastic Gradient Descent with Autograd
    3198. -
    3199. Same code but now with momentum gradient descent
    3200. -
    3201. Similar (second order function now) problem but now with AdaGrad
    3202. -
    3203. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    3204. -
    3205. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    3206. -
    3207. Material for the lab sessions
    3208. +
    3209. Pros and cons
    3210. +
    3211. Convergence rates
    3212. +
    3213. Accuracy
    3214. +
    3215. Stochastic Gradient Descent (SGD)
    3216. +
    3217. Stochastic Gradient Descent
    3218. +
    3219. Computation of gradients
    3220. +
    3221. SGD example
    3222. +
    3223. The gradient step
    3224. +
    3225. Simple example code
    3226. +
    3227. When do we stop?
    3228. +
    3229. Slightly different approach
    3230. +
    3231. Time decay rate
    3232. +
    3233. Code with a Number of Minibatches which varies
    3234. +
    3235. Replace or not
    3236. +
    3237. Momentum based GD
    3238. +
    3239. More on momentum based approaches
    3240. +
    3241. Momentum parameter
    3242. +
    3243. Second moment of the gradient
    3244. +
    3245. RMS prop
    3246. +
    3247. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    3248. +
    3249. Algorithms and codes for Adagrad, RMSprop and Adam
    3250. +
    3251. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3252. +
    3253. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3254. +
    3255. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3256. +
    3257. Practical tips
    3258. +
    3259. Sneaking in auotmatic differentiation using Autograd
    3260. +
    3261. Same code but now with momentum gradient descent
    3262. +
    3263. Including Stochastic Gradient Descent with Autograd
    3264. +
    3265. Same code but now with momentum gradient descent
    3266. +
    3267. Similar (second order function now) problem but now with AdaGrad
    3268. +
    3269. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    3270. +
    3271. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    3272. +
    3273. Material for the lab sessions
    3274. @@ -258,17 +277,19 @@ MathJax.Hub.Config({

       

       

       

      -

      Slightly different approach

      +

      The gradient step

      -

      Another approach is to let the step length \( \gamma_j \) depend on the -number of epochs in such a way that it becomes very small after a -reasonable time such that we do not move at all. Such approaches are -also called scaling. There are many such ways to scale the learning -rate -and discussions here. See -also -https://towardsdatascience.com/learning-rate-schedules-and-adaptive-learning-rate-methods-for-deep-learning-2c8f433990d1 -for a discussion of different scaling functions for the learning rate. +

      Thus a gradient descent step now looks like

      +$$ +\beta_{j+1} = \beta_j - \gamma_j \sum_{i \in B_k}^n \nabla_\beta c_i(\mathbf{x}_i, +\mathbf{\beta}) +$$ + +

      where \( k \) is picked at random with equal +probability from \( [1,n/M] \). An iteration over the number of +minibathces (n/M) is commonly referred to as an epoch. Thus it is +typical to choose a number of epochs and for each epoch iterate over +the number of minibatches, as exemplified in the code below.

      @@ -296,7 +317,7 @@ for a discussion of different scaling functions for the learning rate.

    3275. 34
    3276. 35
    3277. ...
    3278. -
    3279. 46
    3280. +
    3281. 48
    3282. »
    3283. diff --git a/doc/pub/week37/html/._week37-bs026.html b/doc/pub/week37/html/._week37-bs026.html index af0e823ac..b7f2f789a 100644 --- a/doc/pub/week37/html/._week37-bs026.html +++ b/doc/pub/week37/html/._week37-bs026.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
    3284. Program example for gradient descent with Ridge Regression
    3285. Using gradient descent methods, limitations
    3286. Improving gradient descent with momentum
    3287. -
    3288. Same code but now with momentum gradient descent
    3289. -
    3290. Overview video on Stochastic Gradient Descent
    3291. +
    3292. Same code but now with momentum gradient descent
    3293. +
    3294. Overview video on Stochastic Gradient Descent (SGD)
    3295. Batches and mini-batches
    3296. -
    3297. Stochastic Gradient Descent (SGD)
    3298. -
    3299. Stochastic Gradient Descent
    3300. -
    3301. Computation of gradients
    3302. -
    3303. SGD example
    3304. -
    3305. The gradient step
    3306. -
    3307. Simple example code
    3308. -
    3309. When do we stop?
    3310. -
    3311. Slightly different approach
    3312. -
    3313. Time decay rate
    3314. -
    3315. Code with a Number of Minibatches which varies
    3316. -
    3317. Replace or not
    3318. -
    3319. Momentum based GD
    3320. -
    3321. More on momentum based approaches
    3322. -
    3323. Momentum parameter
    3324. -
    3325. Second moment of the gradient
    3326. -
    3327. RMS prop
    3328. -
    3329. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    3330. -
    3331. Algorithms and codes for Adagrad, RMSprop and Adam
    3332. -
    3333. Practical tips
    3334. -
    3335. Sneaking in automatic differentiation using Autograd
    3336. -
    3337. Same code but now with momentum gradient descent
    3338. -
    3339. But none of these can compete with Newton's method
    3340. -
    3341. Including Stochastic Gradient Descent with Autograd
    3342. -
    3343. Same code but now with momentum gradient descent
    3344. -
    3345. Similar (second order function now) problem but now with AdaGrad
    3346. -
    3347. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    3348. -
    3349. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    3350. -
    3351. Material for the lab sessions
    3352. +
    3353. Pros and cons
    3354. +
    3355. Convergence rates
    3356. +
    3357. Accuracy
    3358. +
    3359. Stochastic Gradient Descent (SGD)
    3360. +
    3361. Stochastic Gradient Descent
    3362. +
    3363. Computation of gradients
    3364. +
    3365. SGD example
    3366. +
    3367. The gradient step
    3368. +
    3369. Simple example code
    3370. +
    3371. When do we stop?
    3372. +
    3373. Slightly different approach
    3374. +
    3375. Time decay rate
    3376. +
    3377. Code with a Number of Minibatches which varies
    3378. +
    3379. Replace or not
    3380. +
    3381. Momentum based GD
    3382. +
    3383. More on momentum based approaches
    3384. +
    3385. Momentum parameter
    3386. +
    3387. Second moment of the gradient
    3388. +
    3389. RMS prop
    3390. +
    3391. "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
    3392. +
    3393. Algorithms and codes for Adagrad, RMSprop and Adam
    3394. +
    3395. AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3396. +
    3397. RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3398. +
    3399. ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
    3400. +
    3401. Practical tips
    3402. +
    3403. Sneaking in auotmatic differentiation using Autograd
    3404. +
    3405. Same code but now with momentum gradient descent
    3406. +
    3407. Including Stochastic Gradient Descent with Autograd
    3408. +
    3409. Same code but now with momentum gradient descent
    3410. +
    3411. Similar (second order function now) problem but now with AdaGrad
    3412. +
    3413. RMSprop for adaptive learning rate with Stochastic Gradient Descent
    3414. +
    3415. And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
    3416. +
    3417. Material for the lab sessions
    3418. @@ -258,16 +277,7 @@ MathJax.Hub.Config({

       

       

       

      -

      Time decay rate

      - -

      As an example, let \( e = 0,1,2,3,\cdots \) denote the current epoch and let \( t_0, t_1 > 0 \) be two fixed numbers. Furthermore, let \( t = e \cdot m + i \) where \( m \) is the number of minibatches and \( i=0,\cdots,m-1 \). Then the function $$\gamma_j(t; t_0, t_1) = \frac{t_0}{t+t_1} $$ goes to zero as the number of epochs gets large. I.e. we start with a step length \( \gamma_j (0; t_0, t_1) = t_0/t_1 \) which decays in time \( t \).

      - -

      In this way we can fix the number of epochs, compute \( \beta \) and -evaluate the cost function at the end. Repeating the computation will -give a different result since the scheme is random by design. Then we -pick the final \( \beta \) that gives the lowest value of the cost -function. -

      +

      Simple example code

      @@ -278,28 +288,18 @@ function.
      import numpy as np 
       
      -def step_length(t,t0,t1):
      -    return t0/(t+t1)
      -
       n = 100 #100 datapoints 
       M = 5   #size of each minibatch
       m = int(n/M) #number of minibatches
      -n_epochs = 500 #number of epochs
      -t0 = 1.0
      -t1 = 10
      +n_epochs = 10 #number of epochs
       
      -gamma_j = t0/t1
       j = 0
       for epoch in range(1,n_epochs+1):
           for i in range(m):
               k = np.random.randint(m) #Pick the k-th minibatch at random
               #Compute the gradient using the data in minibatch Bk
      -        #Compute new suggestion for beta
      -        t = epoch*m+i
      -        gamma_j = step_length(t,t0,t1)
      +        #Compute new suggestion for 
               j += 1
      -
      -print("gamma_j after %d epochs: %g" % (n_epochs,gamma_j))
       
    @@ -315,6 +315,14 @@ j = 0 +

    Taking the gradient only on a subset of the data has two important +benefits. First, it introduces randomness which decreases the chance +that our opmization scheme gets stuck in a local minima. Second, if +the size of the minibatches are small relative to the number of +datapoints (\( M < n \)), the computation of the gradient is much +cheaper since we sum over the datapoints in the \( k-th \) minibatch and not +all \( n \) datapoints. +

    @@ -341,7 +349,7 @@ j = 0

  • 35
  • 36
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs027.html b/doc/pub/week37/html/._week37-bs027.html index e59a6392a..9a1f03ee5 100644 --- a/doc/pub/week37/html/._week37-bs027.html +++ b/doc/pub/week37/html/._week37-bs027.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,97 +277,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Code with a Number of Minibatches which varies

    - -

    In the code here we vary the number of mini-batches.

    - - -
    -
    -
    -
    -
    -
    # Importing various packages
    -from math import exp, sqrt
    -from random import random, seed
    -import numpy as np
    -import matplotlib.pyplot as plt
    -
    -n = 100
    -x = 2*np.random.rand(n,1)
    -y = 4+3*x+np.random.randn(n,1)
    -
    -X = np.c_[np.ones((n,1)), x]
    -XT_X = X.T @ X
    -theta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y)
    -print("Own inversion")
    -print(theta_linreg)
    -# Hessian matrix
    -H = (2.0/n)* XT_X
    -EigValues, EigVectors = np.linalg.eig(H)
    -print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    -
    -theta = np.random.randn(2,1)
    -eta = 1.0/np.max(EigValues)
    -Niterations = 1000
    -
    -
    -for iter in range(Niterations):
    -    gradients = 2.0/n*X.T @ ((X @ theta)-y)
    -    theta -= eta*gradients
    -print("theta from own gd")
    -print(theta)
    -
    -xnew = np.array([[0],[2]])
    -Xnew = np.c_[np.ones((2,1)), xnew]
    -ypredict = Xnew.dot(theta)
    -ypredict2 = Xnew.dot(theta_linreg)
    -
    -n_epochs = 50
    -M = 5   #size of each minibatch
    -m = int(n/M) #number of minibatches
    -t0, t1 = 5, 50
    -
    -def learning_schedule(t):
    -    return t0/(t+t1)
    -
    -theta = np.random.randn(2,1)
    -
    -for epoch in range(n_epochs):
    -# Can you figure out a better way of setting up the contributions to each batch?
    -    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 = (2.0/M)* xi.T @ ((xi @ theta)-yi)
    -        eta = learning_schedule(epoch*m+i)
    -        theta = theta - eta*gradients
    -print("theta from own sdg")
    -print(theta)
    -
    -plt.plot(xnew, ypredict, "r-")
    -plt.plot(xnew, ypredict2, "b-")
    -plt.plot(x, y ,'ro')
    -plt.axis([0,2.0,0, 15.0])
    -plt.xlabel(r'$x$')
    -plt.ylabel(r'$y$')
    -plt.title(r'Random numbers ')
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    When do we stop?

    +

    A natural question is when do we stop the search for a new minimum? +One possibility is to compute the full gradient after a given number +of epochs and check if the norm of the gradient is smaller than some +threshold and stop if true. However, the condition that the gradient +is zero is valid also for local minima, so this would only tell us +that we are close to a local/global minimum. However, we could also +evaluate the cost function at this point, store the result and +continue the search. If the test kicks in at a later stage we can +compare the values of the cost function and keep the \( \beta \) that +gave the lowest value. +

    @@ -375,7 +316,7 @@ plt.show()

  • 36
  • 37
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs028.html b/doc/pub/week37/html/._week37-bs028.html index abcec5972..e9e33bc93 100644 --- a/doc/pub/week37/html/._week37-bs028.html +++ b/doc/pub/week37/html/._week37-bs028.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,12 +277,17 @@ MathJax.Hub.Config({

     

     

     

    -

    Replace or not

    +

    Slightly different approach

    -

    In the above code, we have use replacement in setting up the -mini-batches. The discussion -here may be -useful. +

    Another approach is to let the step length \( \gamma_j \) depend on the +number of epochs in such a way that it becomes very small after a +reasonable time such that we do not move at all. Such approaches are +also called scaling. There are many such ways to scale the learning +rate +and discussions here. See +also +https://towardsdatascience.com/learning-rate-schedules-and-adaptive-learning-rate-methods-for-deep-learning-2c8f433990d1 +for a discussion of different scaling functions for the learning rate.

    @@ -291,7 +315,7 @@ useful.

  • 37
  • 38
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs029.html b/doc/pub/week37/html/._week37-bs029.html index e085e692b..202ea0fcc 100644 --- a/doc/pub/week37/html/._week37-bs029.html +++ b/doc/pub/week37/html/._week37-bs029.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,39 +277,63 @@ MathJax.Hub.Config({

     

     

     

    -

    Momentum based GD

    +

    Time decay rate

    -

    The stochastic gradient descent (SGD) is almost always used with a -momentum or inertia term that serves as a memory of the direction we -are moving in parameter space. This is typically implemented as -follows +

    As an example, let \( e = 0,1,2,3,\cdots \) denote the current epoch and let \( t_0, t_1 > 0 \) be two fixed numbers. Furthermore, let \( t = e \cdot m + i \) where \( m \) is the number of minibatches and \( i=0,\cdots,m-1 \). Then the function $$\gamma_j(t; t_0, t_1) = \frac{t_0}{t+t_1} $$ goes to zero as the number of epochs gets large. I.e. we start with a step length \( \gamma_j (0; t_0, t_1) = t_0/t_1 \) which decays in time \( t \).

    + +

    In this way we can fix the number of epochs, compute \( \beta \) and +evaluate the cost function at the end. Repeating the computation will +give a different result since the scheme is random by design. Then we +pick the final \( \beta \) that gives the lowest value of the cost +function.

    -$$ -\begin{align} -\mathbf{v}_{t}&=\gamma \mathbf{v}_{t-1}+\eta_{t}\nabla_\theta E(\boldsymbol{\theta}_t) \nonumber \\ -\boldsymbol{\theta}_{t+1}&= \boldsymbol{\theta}_t -\mathbf{v}_{t}, -\tag{1} -\end{align} -$$ -

    where we have introduced a momentum parameter \( \gamma \), with -\( 0\le\gamma\le 1 \), and for brevity we dropped the explicit notation to -indicate the gradient is to be taken over a different mini-batch at -each step. We call this algorithm gradient descent with momentum -(GDM). From these equations, it is clear that \( \mathbf{v}_t \) is a -running average of recently encountered gradients and -\( (1-\gamma)^{-1} \) sets the characteristic time scale for the memory -used in the averaging procedure. Consistent with this, when -\( \gamma=0 \), this just reduces down to ordinary SGD as discussed -earlier. An equivalent way of writing the updates is -

    + +
    +
    +
    +
    +
    +
    import numpy as np 
     
    -$$
    -\Delta \boldsymbol{\theta}_{t+1} = \gamma \Delta \boldsymbol{\theta}_t -\ \eta_{t}\nabla_\theta E(\boldsymbol{\theta}_t),
    -$$
    +def step_length(t,t0,t1):
    +    return t0/(t+t1)
    +
    +n = 100 #100 datapoints 
    +M = 5   #size of each minibatch
    +m = int(n/M) #number of minibatches
    +n_epochs = 500 #number of epochs
    +t0 = 1.0
    +t1 = 10
    +
    +gamma_j = t0/t1
    +j = 0
    +for epoch in range(1,n_epochs+1):
    +    for i in range(m):
    +        k = np.random.randint(m) #Pick the k-th minibatch at random
    +        #Compute the gradient using the data in minibatch Bk
    +        #Compute new suggestion for beta
    +        t = epoch*m+i
    +        gamma_j = step_length(t,t0,t1)
    +        j += 1
    +
    +print("gamma_j after %d epochs: %g" % (n_epochs,gamma_j))
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    where we have defined \( \Delta \boldsymbol{\theta}_{t}= \boldsymbol{\theta}_t-\boldsymbol{\theta}_{t-1} \).

    @@ -317,7 +360,7 @@ $$

  • 38
  • 39
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs030.html b/doc/pub/week37/html/._week37-bs030.html index e149be2ff..4d810a1d2 100644 --- a/doc/pub/week37/html/._week37-bs030.html +++ b/doc/pub/week37/html/._week37-bs030.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,30 +277,96 @@ MathJax.Hub.Config({

     

     

     

    -

    More on momentum based approaches

    +

    Code with a Number of Minibatches which varies

    -

    Let us try to get more intuition from these equations. It is helpful -to consider a simple physical analogy with a particle of mass \( m \) -moving in a viscous medium with drag coefficient \( \mu \) and potential -\( E(\mathbf{w}) \). If we denote the particle's position by \( \mathbf{w} \), -then its motion is described by -

    +

    In the code here we vary the number of mini-batches.

    -$$ -m {d^2 \mathbf{w} \over dt^2} + \mu {d \mathbf{w} \over dt }= -\nabla_w E(\mathbf{w}). -$$ + +
    +
    +
    +
    +
    +
    # Importing various packages
    +from math import exp, sqrt
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
     
    -

    We can discretize this equation in the usual way to get

    +n = 100 +x = 2*np.random.rand(n,1) +y = 4+3*x+np.random.randn(n,1) -$$ -m { \mathbf{w}_{t+\Delta t}-2 \mathbf{w}_{t} +\mathbf{w}_{t-\Delta t} \over (\Delta t)^2}+\mu {\mathbf{w}_{t+\Delta t}- \mathbf{w}_{t} \over \Delta t} = -\nabla_w E(\mathbf{w}). -$$ +X = np.c_[np.ones((n,1)), x] +XT_X = X.T @ X +theta_linreg = np.linalg.inv(X.T @ X) @ (X.T @ y) +print("Own inversion") +print(theta_linreg) +# Hessian matrix +H = (2.0/n)* XT_X +EigValues, EigVectors = np.linalg.eig(H) +print(f"Eigenvalues of Hessian Matrix:{EigValues}") -

    Rearranging this equation, we can rewrite this as

    +theta = np.random.randn(2,1) +eta = 1.0/np.max(EigValues) +Niterations = 1000 -$$ -\Delta \mathbf{w}_{t +\Delta t}= - { (\Delta t)^2 \over m +\mu \Delta t} \nabla_w E(\mathbf{w})+ {m \over m +\mu \Delta t} \Delta \mathbf{w}_t. -$$ + +for iter in range(Niterations): + gradients = 2.0/n*X.T @ ((X @ theta)-y) + theta -= eta*gradients +print("theta from own gd") +print(theta) + +xnew = np.array([[0],[2]]) +Xnew = np.c_[np.ones((2,1)), xnew] +ypredict = Xnew.dot(theta) +ypredict2 = Xnew.dot(theta_linreg) + +n_epochs = 50 +M = 5 #size of each minibatch +m = int(n/M) #number of minibatches +t0, t1 = 5, 50 + +def learning_schedule(t): + return t0/(t+t1) + +theta = np.random.randn(2,1) + +for epoch in range(n_epochs): +# Can you figure out a better way of setting up the contributions to each batch? + 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 = (2.0/M)* xi.T @ ((xi @ theta)-yi) + eta = learning_schedule(epoch*m+i) + theta = theta - eta*gradients +print("theta from own sdg") +print(theta) + +plt.plot(xnew, ypredict, "r-") +plt.plot(xnew, ypredict2, "b-") +plt.plot(x, y ,'ro') +plt.axis([0,2.0,0, 15.0]) +plt.xlabel(r'$x$') +plt.ylabel(r'$y$') +plt.title(r'Random numbers ') +plt.show() +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +

    @@ -309,7 +394,7 @@ $$

  • 39
  • 40
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs031.html b/doc/pub/week37/html/._week37-bs031.html index 1463b079c..58b507ddc 100644 --- a/doc/pub/week37/html/._week37-bs031.html +++ b/doc/pub/week37/html/._week37-bs031.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,58 +277,14 @@ MathJax.Hub.Config({

     

     

     

    -

    Momentum parameter

    +

    Replace or not

    -

    Notice that this equation is identical to previous one if we identify -the position of the particle, \( \mathbf{w} \), with the parameters -\( \boldsymbol{\theta} \). This allows us to identify the momentum -parameter and learning rate with the mass of the particle and the -viscous drag as: +

    In the above code, we have use replacement in setting up the +mini-batches. The discussion +here may be +useful.

    -$$ -\gamma= {m \over m +\mu \Delta t }, \qquad \eta = {(\Delta t)^2 \over m +\mu \Delta t}. -$$ - -

    Thus, as the name suggests, the momentum parameter is proportional to -the mass of the particle and effectively provides inertia. -Furthermore, in the large viscosity/small learning rate limit, our -memory time scales as \( (1-\gamma)^{-1} \approx m/(\mu \Delta t) \). -

    - -

    Why is momentum useful? SGD momentum helps the gradient descent -algorithm gain speed in directions with persistent but small gradients -even in the presence of stochasticity, while suppressing oscillations -in high-curvature directions. This becomes especially important in -situations where the landscape is shallow and flat in some directions -and narrow and steep in others. It has been argued that first-order -methods (with appropriate initial conditions) can perform comparable -to more expensive second order methods, especially in the context of -complex deep learning models. -

    - -

    These beneficial properties of momentum can sometimes become even more -pronounced by using a slight modification of the classical momentum -algorithm called Nesterov Accelerated Gradient (NAG). -

    - -

    In the NAG algorithm, rather than calculating the gradient at the -current parameters, \( \nabla_\theta E(\boldsymbol{\theta}_t) \), one -calculates the gradient at the expected value of the parameters given -our current momentum, \( \nabla_\theta E(\boldsymbol{\theta}_t +\gamma -\mathbf{v}_{t-1}) \). This yields the NAG update rule -

    - -$$ -\begin{align} -\mathbf{v}_{t}&=\gamma \mathbf{v}_{t-1}+\eta_{t}\nabla_\theta E(\boldsymbol{\theta}_t +\gamma \mathbf{v}_{t-1}) \nonumber \\ -\boldsymbol{\theta}_{t+1}&= \boldsymbol{\theta}_t -\mathbf{v}_{t}. -\tag{2} -\end{align} -$$ - -

    One of the major advantages of NAG is that it allows for the use of a larger learning rate than GDM for the same choice of \( \gamma \).

    -

    diff --git a/doc/pub/week37/html/._week37-bs032.html b/doc/pub/week37/html/._week37-bs032.html index 21fd568cf..c368a7e16 100644 --- a/doc/pub/week37/html/._week37-bs032.html +++ b/doc/pub/week37/html/._week37-bs032.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,31 +277,40 @@ MathJax.Hub.Config({

     

     

     

    -

    Second moment of the gradient

    +

    Momentum based GD

    -

    In stochastic gradient descent, with and without momentum, we still -have to specify a schedule for tuning the learning rates \( \eta_t \) -as a function of time. As discussed in the context of Newton's -method, this presents a number of dilemmas. The learning rate is -limited by the steepest direction which can change depending on the -current position in the landscape. To circumvent this problem, ideally -our algorithm would keep track of curvature and take large steps in -shallow, flat directions and small steps in steep, narrow directions. -Second-order methods accomplish this by calculating or approximating -the Hessian and normalizing the learning rate by the -curvature. However, this is very computationally expensive for -extremely large models. Ideally, we would like to be able to -adaptively change the step size to match the landscape without paying -the steep computational price of calculating or approximating -Hessians. +

    The stochastic gradient descent (SGD) is almost always used with a +momentum or inertia term that serves as a memory of the direction we +are moving in parameter space. This is typically implemented as +follows

    -

    Recently, a number of methods have been introduced that accomplish -this by tracking not only the gradient, but also the second moment of -the gradient. These methods include AdaGrad, AdaDelta, Root Mean Squared Propagation (RMS-Prop), and -ADAM. +$$ +\begin{align} +\mathbf{v}_{t}&=\gamma \mathbf{v}_{t-1}+\eta_{t}\nabla_\theta E(\boldsymbol{\theta}_t) \nonumber \\ +\boldsymbol{\theta}_{t+1}&= \boldsymbol{\theta}_t -\mathbf{v}_{t}, +\tag{1} +\end{align} +$$ + +

    where we have introduced a momentum parameter \( \gamma \), with +\( 0\le\gamma\le 1 \), and for brevity we dropped the explicit notation to +indicate the gradient is to be taken over a different mini-batch at +each step. We call this algorithm gradient descent with momentum +(GDM). From these equations, it is clear that \( \mathbf{v}_t \) is a +running average of recently encountered gradients and +\( (1-\gamma)^{-1} \) sets the characteristic time scale for the memory +used in the averaging procedure. Consistent with this, when +\( \gamma=0 \), this just reduces down to ordinary SGD as discussed +earlier. An equivalent way of writing the updates is

    +$$ +\Delta \boldsymbol{\theta}_{t+1} = \gamma \Delta \boldsymbol{\theta}_t -\ \eta_{t}\nabla_\theta E(\boldsymbol{\theta}_t), +$$ + +

    where we have defined \( \Delta \boldsymbol{\theta}_{t}= \boldsymbol{\theta}_t-\boldsymbol{\theta}_{t-1} \).

    +

    diff --git a/doc/pub/week37/html/._week37-bs033.html b/doc/pub/week37/html/._week37-bs033.html index a375fe4c2..e18d330fb 100644 --- a/doc/pub/week37/html/._week37-bs033.html +++ b/doc/pub/week37/html/._week37-bs033.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,33 +277,31 @@ MathJax.Hub.Config({

     

     

     

    -

    RMS prop

    +

    More on momentum based approaches

    -

    In RMS prop, in addition to keeping a running average of the first -moment of the gradient, we also keep track of the second moment -denoted by \( \mathbf{s}_t=\mathbb{E}[\mathbf{g}_t^2] \). The update rule -for RMS prop is given by +

    Let us try to get more intuition from these equations. It is helpful +to consider a simple physical analogy with a particle of mass \( m \) +moving in a viscous medium with drag coefficient \( \mu \) and potential +\( E(\mathbf{w}) \). If we denote the particle's position by \( \mathbf{w} \), +then its motion is described by

    $$ -\begin{align} -\mathbf{g}_t &= \nabla_\theta E(\boldsymbol{\theta}) -\tag{3}\\ -\mathbf{s}_t &=\beta \mathbf{s}_{t-1} +(1-\beta)\mathbf{g}_t^2 \nonumber \\ -\boldsymbol{\theta}_{t+1}&=&\boldsymbol{\theta}_t - \eta_t { \mathbf{g}_t \over \sqrt{\mathbf{s}_t +\epsilon}}, \nonumber -\end{align} +m {d^2 \mathbf{w} \over dt^2} + \mu {d \mathbf{w} \over dt }= -\nabla_w E(\mathbf{w}). +$$ + +

    We can discretize this equation in the usual way to get

    + +$$ +m { \mathbf{w}_{t+\Delta t}-2 \mathbf{w}_{t} +\mathbf{w}_{t-\Delta t} \over (\Delta t)^2}+\mu {\mathbf{w}_{t+\Delta t}- \mathbf{w}_{t} \over \Delta t} = -\nabla_w E(\mathbf{w}). +$$ + +

    Rearranging this equation, we can rewrite this as

    + +$$ +\Delta \mathbf{w}_{t +\Delta t}= - { (\Delta t)^2 \over m +\mu \Delta t} \nabla_w E(\mathbf{w})+ {m \over m +\mu \Delta t} \Delta \mathbf{w}_t. $$ -

    where \( \beta \) controls the averaging time of the second moment and is -typically taken to be about \( \beta=0.9 \), \( \eta_t \) is a learning rate -typically chosen to be \( 10^{-3} \), and \( \epsilon\sim 10^{-8} \) is a -small regularization constant to prevent divergences. Multiplication -and division by vectors is understood as an element-wise operation. It -is clear from this formula that the learning rate is reduced in -directions where the norm of the gradient is consistently large. This -greatly speeds up the convergence by allowing us to use a larger -learning rate for flat directions. -

    @@ -311,7 +328,7 @@ learning rate for flat directions.

  • 42
  • 43
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs034.html b/doc/pub/week37/html/._week37-bs034.html index 1d4ebc309..c443a8f65 100644 --- a/doc/pub/week37/html/._week37-bs034.html +++ b/doc/pub/week37/html/._week37-bs034.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,60 +277,60 @@ MathJax.Hub.Config({

     

     

     

    -

    ADAM optimizer

    +

    Momentum parameter

    -

    A related algorithm is the ADAM optimizer. In -ADAM, we keep a running average of -both the first and second moment of the gradient and use this -information to adaptively change the learning rate for different -parameters. The method isefficient when working with large -problems involving lots data and/or parameters. It is a combination of the -gradient descent with momentum algorithm and the RMSprop algorithm -discussed above. +

    Notice that this equation is identical to previous one if we identify +the position of the particle, \( \mathbf{w} \), with the parameters +\( \boldsymbol{\theta} \). This allows us to identify the momentum +parameter and learning rate with the mass of the particle and the +viscous drag as:

    -

    In addition to keeping a running average of the first and -second moments of the gradient -(i.e. \( \mathbf{m}_t=\mathbb{E}[\mathbf{g}_t] \) and -\( \mathbf{s}_t=\mathbb{E}[\mathbf{g}^2_t] \), respectively), ADAM -performs an additional bias correction to account for the fact that we -are estimating the first two moments of the gradient using a running -average (denoted by the hats in the update rule below). The update -rule for ADAM is given by (where multiplication and division are once -again understood to be element-wise operations below) +$$ +\gamma= {m \over m +\mu \Delta t }, \qquad \eta = {(\Delta t)^2 \over m +\mu \Delta t}. +$$ + +

    Thus, as the name suggests, the momentum parameter is proportional to +the mass of the particle and effectively provides inertia. +Furthermore, in the large viscosity/small learning rate limit, our +memory time scales as \( (1-\gamma)^{-1} \approx m/(\mu \Delta t) \). +

    + +

    Why is momentum useful? SGD momentum helps the gradient descent +algorithm gain speed in directions with persistent but small gradients +even in the presence of stochasticity, while suppressing oscillations +in high-curvature directions. This becomes especially important in +situations where the landscape is shallow and flat in some directions +and narrow and steep in others. It has been argued that first-order +methods (with appropriate initial conditions) can perform comparable +to more expensive second order methods, especially in the context of +complex deep learning models. +

    + +

    These beneficial properties of momentum can sometimes become even more +pronounced by using a slight modification of the classical momentum +algorithm called Nesterov Accelerated Gradient (NAG). +

    + +

    In the NAG algorithm, rather than calculating the gradient at the +current parameters, \( \nabla_\theta E(\boldsymbol{\theta}_t) \), one +calculates the gradient at the expected value of the parameters given +our current momentum, \( \nabla_\theta E(\boldsymbol{\theta}_t +\gamma +\mathbf{v}_{t-1}) \). This yields the NAG update rule

    $$ \begin{align} -\mathbf{g}_t &= \nabla_\theta E(\boldsymbol{\theta}) -\tag{4}\\ -\mathbf{m}_t &= \beta_1 \mathbf{m}_{t-1} + (1-\beta_1) \mathbf{g}_t \nonumber \\ -\mathbf{s}_t &=\beta_2 \mathbf{s}_{t-1} +(1-\beta_2)\mathbf{g}_t^2 \nonumber \\ -\boldsymbol{\mathbf{m}}_t&={\mathbf{m}_t \over 1-\beta_1^t} \nonumber \\ -\boldsymbol{\mathbf{s}}_t &={\mathbf{s}_t \over1-\beta_2^t} \nonumber \\ -\boldsymbol{\theta}_{t+1}&=\boldsymbol{\theta}_t - \eta_t { \boldsymbol{\mathbf{m}}_t \over \sqrt{\boldsymbol{\mathbf{s}}_t} +\epsilon}, \nonumber \\ -\tag{5} +\mathbf{v}_{t}&=\gamma \mathbf{v}_{t-1}+\eta_{t}\nabla_\theta E(\boldsymbol{\theta}_t +\gamma \mathbf{v}_{t-1}) \nonumber \\ +\boldsymbol{\theta}_{t+1}&= \boldsymbol{\theta}_t -\mathbf{v}_{t}. +\tag{2} \end{align} $$ -

    where \( \beta_1 \) and \( \beta_2 \) set the memory lifetime of the first and -second moment and are typically taken to be \( 0.9 \) and \( 0.99 \) -respectively, and \( \eta \) and \( \epsilon \) are identical to RMSprop. +

    One of the major advantages of NAG is that it allows for the use of a +larger learning rate than GDM for the same choice of \( \gamma \).

    -

    Like in RMSprop, the effective step size of a parameter depends on the -magnitude of its gradient squared. To understand this better, let us -rewrite this expression in terms of the variance -\( \boldsymbol{\sigma}_t^2 = \boldsymbol{\mathbf{s}}_t - -(\boldsymbol{\mathbf{m}}_t)^2 \). Consider a single parameter \( \theta_t \). The -update rule for this parameter is given by -

    - -$$ -\Delta \theta_{t+1}= -\eta_t { \boldsymbol{m}_t \over \sqrt{\sigma_t^2 + m_t^2 }+\epsilon}. -$$ - -

    diff --git a/doc/pub/week37/html/._week37-bs035.html b/doc/pub/week37/html/._week37-bs035.html index 8d2b305ee..d835233f4 100644 --- a/doc/pub/week37/html/._week37-bs035.html +++ b/doc/pub/week37/html/._week37-bs035.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,11 +277,30 @@ MathJax.Hub.Config({

     

     

     

    -

    Algorithms and codes for Adagrad, RMSprop and Adam

    +

    Second moment of the gradient

    -

    The algorithms we have implemented are well described in the text by Goodfellow, Bengio and Courville, chapter 8.

    +

    In stochastic gradient descent, with and without momentum, we still +have to specify a schedule for tuning the learning rates \( \eta_t \) +as a function of time. As discussed in the context of Newton's +method, this presents a number of dilemmas. The learning rate is +limited by the steepest direction which can change depending on the +current position in the landscape. To circumvent this problem, ideally +our algorithm would keep track of curvature and take large steps in +shallow, flat directions and small steps in steep, narrow directions. +Second-order methods accomplish this by calculating or approximating +the Hessian and normalizing the learning rate by the +curvature. However, this is very computationally expensive for +extremely large models. Ideally, we would like to be able to +adaptively change the step size to match the landscape without paying +the steep computational price of calculating or approximating +Hessians. +

    -

    The codes which implement these algorithms are discussed below here.

    +

    During the last decade a number of methods have been introduced that accomplish +this by tracking not only the gradient, but also the second moment of +the gradient. These methods include AdaGrad, AdaDelta, Root Mean Squared Propagation (RMS-Prop), and +ADAM. +

    @@ -289,7 +327,7 @@ MathJax.Hub.Config({

  • 44
  • 45
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs036.html b/doc/pub/week37/html/._week37-bs036.html index e3d652f14..8f8250e24 100644 --- a/doc/pub/week37/html/._week37-bs036.html +++ b/doc/pub/week37/html/._week37-bs036.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,14 +277,34 @@ MathJax.Hub.Config({

     

     

     

    -

    Practical tips

    +

    RMS prop

    + +

    In RMS prop, in addition to keeping a running average of the first +moment of the gradient, we also keep track of the second moment +denoted by \( \mathbf{s}_t=\mathbb{E}[\mathbf{g}_t^2] \). The update rule +for RMS prop is given by +

    + +$$ +\begin{align} +\mathbf{g}_t &= \nabla_\theta E(\boldsymbol{\theta}) +\tag{3}\\ +\mathbf{s}_t &=\beta \mathbf{s}_{t-1} +(1-\beta)\mathbf{g}_t^2 \nonumber \\ +\boldsymbol{\theta}_{t+1}&=&\boldsymbol{\theta}_t - \eta_t { \mathbf{g}_t \over \sqrt{\mathbf{s}_t +\epsilon}}, \nonumber +\end{align} +$$ + +

    where \( \beta \) controls the averaging time of the second moment and is +typically taken to be about \( \beta=0.9 \), \( \eta_t \) is a learning rate +typically chosen to be \( 10^{-3} \), and \( \epsilon\sim 10^{-8} \) is a +small regularization constant to prevent divergences. Multiplication +and division by vectors is understood as an element-wise operation. It +is clear from this formula that the learning rate is reduced in +directions where the norm of the gradient is consistently large. This +greatly speeds up the convergence by allowing us to use a larger +learning rate for flat directions. +

    -

    diff --git a/doc/pub/week37/html/._week37-bs037.html b/doc/pub/week37/html/._week37-bs037.html index 32d254b75..95a6cb8b2 100644 --- a/doc/pub/week37/html/._week37-bs037.html +++ b/doc/pub/week37/html/._week37-bs037.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,82 +277,58 @@ MathJax.Hub.Config({

     

     

     

    -

    Sneaking in automatic differentiation using Autograd

    +

    ADAM optimizer

    -

    We anticipate our discussions to come in connection with neural networks and automatic differentiation -by showing how we can use autograd for the cases above. Later we will replace autograd with JAX. +

    A related algorithm is the ADAM optimizer. In +ADAM, we keep a running average of +both the first and second moment of the gradient and use this +information to adaptively change the learning rate for different +parameters. The method isefficient when working with large +problems involving lots data and/or parameters. It is a combination of the +gradient descent with momentum algorithm and the RMSprop algorithm +discussed above.

    +

    In addition to keeping a running average of the first and +second moments of the gradient +(i.e. \( \mathbf{m}_t=\mathbb{E}[\mathbf{g}_t] \) and +\( \mathbf{s}_t=\mathbb{E}[\mathbf{g}^2_t] \), respectively), ADAM +performs an additional bias correction to account for the fact that we +are estimating the first two moments of the gradient using a running +average (denoted by the hats in the update rule below). The update +rule for ADAM is given by (where multiplication and division are once +again understood to be element-wise operations below) +

    - -
    -
    -
    -
    -
    -
    # Using Autograd to calculate gradients for OLS
    -from random import random, seed
    -import numpy as np
    -import autograd.numpy as np
    -import matplotlib.pyplot as plt
    -from autograd import grad
    +$$
    +\begin{align}
    +\mathbf{g}_t &= \nabla_\theta E(\boldsymbol{\theta}) 
    +\tag{4}\\
    +\mathbf{m}_t &= \beta_1 \mathbf{m}_{t-1} + (1-\beta_1) \mathbf{g}_t \nonumber \\
    +\mathbf{s}_t &=\beta_2 \mathbf{s}_{t-1} +(1-\beta_2)\mathbf{g}_t^2 \nonumber \\
    +\boldsymbol{\mathbf{m}}_t&={\mathbf{m}_t \over 1-\beta_1^t} \nonumber \\
    +\boldsymbol{\mathbf{s}}_t &={\mathbf{s}_t \over1-\beta_2^t} \nonumber \\
    +\boldsymbol{\theta}_{t+1}&=\boldsymbol{\theta}_t - \eta_t { \boldsymbol{\mathbf{m}}_t \over \sqrt{\boldsymbol{\mathbf{s}}_t} +\epsilon}, \nonumber \\
    +\tag{5}
    +\end{align}
    +$$
     
    -def CostOLS(beta):
    -    return (1.0/n)*np.sum((y-X @ beta)**2)
    +

    where \( \beta_1 \) and \( \beta_2 \) set the memory lifetime of the first and +second moment and are typically taken to be \( 0.9 \) and \( 0.99 \) +respectively, and \( \eta \) and \( \epsilon \) are identical to RMSprop. +

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

    Like in RMSprop, the effective step size of a parameter depends on the +magnitude of its gradient squared. To understand this better, let us +rewrite this expression in terms of the variance +\( \boldsymbol{\sigma}_t^2 = \boldsymbol{\mathbf{s}}_t - +(\boldsymbol{\mathbf{m}}_t)^2 \). Consider a single parameter \( \theta_t \). The +update rule for this parameter is given by +

    -X = np.c_[np.ones((n,1)), x] -XT_X = X.T @ X -theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y) -print("Own inversion") -print(theta_linreg) -# Hessian matrix -H = (2.0/n)* XT_X -EigValues, EigVectors = np.linalg.eig(H) -print(f"Eigenvalues of Hessian Matrix:{EigValues}") - -theta = np.random.randn(2,1) -eta = 1.0/np.max(EigValues) -Niterations = 1000 -# define the gradient -training_gradient = grad(CostOLS) - -for iter in range(Niterations): - gradients = training_gradient(theta) - theta -= eta*gradients -print("theta from own gd") -print(theta) - -xnew = np.array([[0],[2]]) -Xnew = np.c_[np.ones((2,1)), xnew] -ypredict = Xnew.dot(theta) -ypredict2 = Xnew.dot(theta_linreg) - -plt.plot(xnew, ypredict, "r-") -plt.plot(xnew, ypredict2, "b-") -plt.plot(x, y ,'ro') -plt.axis([0,2.0,0, 15.0]) -plt.xlabel(r'$x$') -plt.ylabel(r'$y$') -plt.title(r'Random numbers ') -plt.show() -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +$$ +\Delta \theta_{t+1}= -\eta_t { \boldsymbol{m}_t \over \sqrt{\sigma_t^2 + m_t^2 }+\epsilon}. +$$

    @@ -359,6 +354,9 @@ plt.show()

  • 44
  • 45
  • 46
  • +
  • 47
  • +
  • ...
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs038.html b/doc/pub/week37/html/._week37-bs038.html index 0d2d20f03..706f006ab 100644 --- a/doc/pub/week37/html/._week37-bs038.html +++ b/doc/pub/week37/html/._week37-bs038.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,82 +277,32 @@ MathJax.Hub.Config({

     

     

     

    -

    Same code but now with momentum gradient descent

    +

    Algorithms and codes for Adagrad, RMSprop and Adam

    - -
    -
    -
    -
    -
    -
    # Using Autograd to calculate gradients for OLS
    -from random import random, seed
    -import numpy as np
    -import autograd.numpy as np
    -import matplotlib.pyplot as plt
    -from autograd import grad
    +

    The algorithms we have implemented are well described in the text by Goodfellow, Bengio and Courville, chapter 8.

    -def CostOLS(beta): - return (1.0/n)*np.sum((y-X @ beta)**2) +

    The codes which implement these algorithms are discussed after our presentation of automatic differentiation.

    +

    AdaGrad algorithm, taken from Goodfellow et al

    -n = 100 -x = 2*np.random.rand(n,1) -y = 4+3*x#+np.random.randn(n,1) +

    +
    +

    +
    +

    +

    RMSProp algorithm, taken from Goodfellow et al

    -X = np.c_[np.ones((n,1)), x] -XT_X = X.T @ X -theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y) -print("Own inversion") -print(theta_linreg) -# Hessian matrix -H = (2.0/n)* XT_X -EigValues, EigVectors = np.linalg.eig(H) -print(f"Eigenvalues of Hessian Matrix:{EigValues}") - -theta = np.random.randn(2,1) -eta = 1.0/np.max(EigValues) -Niterations = 30 - -# define the gradient -training_gradient = grad(CostOLS) - -for iter in range(Niterations): - gradients = training_gradient(theta) - theta -= eta*gradients - print(iter,gradients[0],gradients[1]) -print("theta from own gd") -print(theta) - -# Now improve with momentum gradient descent -change = 0.0 -delta_momentum = 0.3 -for iter in range(Niterations): - # calculate gradient - gradients = training_gradient(theta) - # calculate update - new_change = eta*gradients+delta_momentum*change - # take a step - theta -= new_change - # save the change - change = new_change - print(iter,gradients[0],gradients[1]) -print("theta from own gd wth momentum") -print(theta) -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    +
    +

    +
    +

    +

    ADAM algorithm, taken from Goodfellow et al

    +

    +
    +

    +
    +

    @@ -357,6 +326,8 @@ delta_momentum = 44

  • 45
  • 46
  • +
  • 47
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs039.html b/doc/pub/week37/html/._week37-bs039.html index 7aadc4545..dcc694333 100644 --- a/doc/pub/week37/html/._week37-bs039.html +++ b/doc/pub/week37/html/._week37-bs039.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,69 +277,14 @@ MathJax.Hub.Config({

     

     

     

    -

    But none of these can compete with Newton's method

    - - - -
    -
    -
    -
    -
    -
    # Using Newton's method
    -from random import random, seed
    -import numpy as np
    -import autograd.numpy as np
    -import matplotlib.pyplot as plt
    -from autograd import grad
    -
    -def CostOLS(beta):
    -    return (1.0/n)*np.sum((y-X @ beta)**2)
    -
    -n = 100
    -x = 2*np.random.rand(n,1)
    -y = 4+3*x+np.random.randn(n,1)
    -
    -X = np.c_[np.ones((n,1)), x]
    -XT_X = X.T @ X
    -beta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
    -print("Own inversion")
    -print(beta_linreg)
    -# Hessian matrix
    -H = (2.0/n)* XT_X
    -# Note that here the Hessian does not depend on the parameters beta
    -invH = np.linalg.pinv(H)
    -EigValues, EigVectors = np.linalg.eig(H)
    -print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    -
    -beta = np.random.randn(2,1)
    -Niterations = 5
    -
    -# define the gradient
    -training_gradient = grad(CostOLS)
    -
    -for iter in range(Niterations):
    -    gradients = training_gradient(beta)
    -    beta -= invH @ gradients
    -    print(iter,gradients[0],gradients[1])
    -print("beta from own Newton code")
    -print(beta)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - +

    Practical tips

    +

    diff --git a/doc/pub/week37/html/._week37-bs040.html b/doc/pub/week37/html/._week37-bs040.html index e6c23f356..4d8cb7c5d 100644 --- a/doc/pub/week37/html/._week37-bs040.html +++ b/doc/pub/week37/html/._week37-bs040.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,8 +277,12 @@ MathJax.Hub.Config({

     

     

     

    -

    Including Stochastic Gradient Descent with Autograd

    -

    In this code we include the stochastic gradient descent approach discussed above. Note here that we specify which argument we are taking the derivative with respect to when using autograd.

    +

    Sneaking in auotmatic differentiation using Autograd

    + +

    We conclude the part on optmization by showing how we can make codes +for linear regression and logistic regression using autograd. The +first example shows results with ordinary leats squares. +

    @@ -268,17 +291,15 @@ MathJax.Hub.Config({
    -
    # Using Autograd to calculate gradients using SGD
    -# OLS example
    +  
    # Using Autograd to calculate gradients for OLS
     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)
    +def CostOLS(beta):
    +    return (1.0/n)*np.sum((y-X @ beta)**2)
     
     n = 100
     x = 2*np.random.rand(n,1)
    @@ -297,12 +318,11 @@ EigValues, EigVectors = np= np.random.randn(2,1)
     eta = 1.0/np.max(EigValues)
     Niterations = 1000
    -
    -# Note that we request the derivative wrt third argument (theta, 2 here)
    -training_gradient = grad(CostOLS,2)
    +# define the gradient
    +training_gradient = grad(CostOLS)
     
     for iter in range(Niterations):
    -    gradients = (1.0/n)*training_gradient(y, X, theta)
    +    gradients = training_gradient(theta)
         theta -= eta*gradients
     print("theta from own gd")
     print(theta)
    @@ -320,27 +340,6 @@ plt.xlabel(r
     plt.ylabel(r'$y$')
     plt.title(r'Random numbers ')
     plt.show()
    -
    -n_epochs = 50
    -M = 5   #size of each minibatch
    -m = int(n/M) #number of minibatches
    -t0, t1 = 5, 50
    -def learning_schedule(t):
    -    return t0/(t+t1)
    -
    -theta = np.random.randn(2,1)
    -
    -for epoch in range(n_epochs):
    -# Can you figure out a better way of setting up the contributions to each batch?
    -    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)
    -        eta = learning_schedule(epoch*m+i)
    -        theta = theta - eta*gradients
    -print("theta from own sdg")
    -print(theta)
     
    @@ -377,6 +376,8 @@ theta = np.44
  • 45
  • 46
  • +
  • 47
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs041.html b/doc/pub/week37/html/._week37-bs041.html index ee18c3199..ca7cb828b 100644 --- a/doc/pub/week37/html/._week37-bs041.html +++ b/doc/pub/week37/html/._week37-bs041.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -266,21 +285,19 @@ MathJax.Hub.Config({
    -
    # Using Autograd to calculate gradients using SGD
    -# OLS example
    +  
    # Using Autograd to calculate gradients for OLS
     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)
    +def CostOLS(beta):
    +    return (1.0/n)*np.sum((y-X @ beta)**2)
     
     n = 100
     x = 2*np.random.rand(n,1)
    -y = 4+3*x+np.random.randn(n,1)
    +y = 4+3*x#+np.random.randn(n,1)
     
     X = np.c_[np.ones((n,1)), x]
     XT_X = X.T @ X
    @@ -294,44 +311,32 @@ EigValues, EigVectors = np= np.random.randn(2,1)
     eta = 1.0/np.max(EigValues)
    -Niterations = 100
    +Niterations = 30
     
    -# Note that we request the derivative wrt third argument (theta, 2 here)
    -training_gradient = grad(CostOLS,2)
    +# define the gradient
    +training_gradient = grad(CostOLS)
     
     for iter in range(Niterations):
    -    gradients = (1.0/n)*training_gradient(y, X, theta)
    +    gradients = training_gradient(theta)
         theta -= eta*gradients
    +    print(iter,gradients[0],gradients[1])
     print("theta from own gd")
     print(theta)
     
    -
    -n_epochs = 50
    -M = 5   #size of each minibatch
    -m = int(n/M) #number of minibatches
    -t0, t1 = 5, 50
    -def learning_schedule(t):
    -    return t0/(t+t1)
    -
    -theta = np.random.randn(2,1)
    -
    +# Now improve with momentum gradient descent
     change = 0.0
     delta_momentum = 0.3
    -
    -for epoch in range(n_epochs):
    -    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)
    -        eta = learning_schedule(epoch*m+i)
    -        # calculate update
    -        new_change = eta*gradients+delta_momentum*change
    -        # take a step
    -        theta -= new_change
    -        # save the change
    -        change = new_change
    -print("theta from own sdg with momentum")
    +for iter in range(Niterations):
    +    # calculate gradient
    +    gradients = training_gradient(theta)
    +    # calculate update
    +    new_change = eta*gradients+delta_momentum*change
    +    # take a step
    +    theta -= new_change
    +    # save the change
    +    change = new_change
    +    print(iter,gradients[0],gradients[1])
    +print("theta from own gd wth momentum")
     print(theta)
     
    @@ -368,6 +373,8 @@ delta_momentum = 44
  • 45
  • 46
  • +
  • 47
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs042.html b/doc/pub/week37/html/._week37-bs042.html index ee24d5f87..d0a1066f6 100644 --- a/doc/pub/week37/html/._week37-bs042.html +++ b/doc/pub/week37/html/._week37-bs042.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,7 +277,9 @@ MathJax.Hub.Config({

     

     

     

    -

    Similar (second order function now) problem but now with AdaGrad

    +

    Including Stochastic Gradient Descent with Autograd

    +

    In this code we include the stochastic gradient descent approach discussed above. Note here that we specify which argument we are taking the derivative with respect to when using autograd.

    +
    @@ -266,7 +287,7 @@ MathJax.Hub.Config({
    -
    # Using Autograd to calculate gradients using AdaGrad and Stochastic Gradient descent
    +  
    # Using Autograd to calculate gradients using SGD
     # OLS example
     from random import random, seed
     import numpy as np
    @@ -278,41 +299,66 @@ MathJax.Hub.Config({
     def CostOLS(y,X,theta):
         return np.sum((y-X @ theta)**2)
     
    -n = 1000
    -x = np.random.rand(n,1)
    -y = 2.0+3*x +4*x*x
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
     
    -X = np.c_[np.ones((n,1)), x, x*x]
    +X = np.c_[np.ones((n,1)), x]
     XT_X = X.T @ X
     theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
     print("Own inversion")
     print(theta_linreg)
    +# Hessian matrix
    +H = (2.0/n)* XT_X
    +EigValues, EigVectors = np.linalg.eig(H)
    +print(f"Eigenvalues of Hessian Matrix:{EigValues}")
     
    +theta = np.random.randn(2,1)
    +eta = 1.0/np.max(EigValues)
    +Niterations = 1000
     
     # Note that we request the derivative wrt third argument (theta, 2 here)
     training_gradient = grad(CostOLS,2)
    -# Define parameters for Stochastic Gradient Descent
    +
    +for iter in range(Niterations):
    +    gradients = (1.0/n)*training_gradient(y, X, theta)
    +    theta -= eta*gradients
    +print("theta from own gd")
    +print(theta)
    +
    +xnew = np.array([[0],[2]])
    +Xnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = Xnew.dot(theta)
    +ypredict2 = Xnew.dot(theta_linreg)
    +
    +plt.plot(xnew, ypredict, "r-")
    +plt.plot(xnew, ypredict2, "b-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Random numbers ')
    +plt.show()
    +
     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)
    +t0, t1 = 5, 50
    +def learning_schedule(t):
    +    return t0/(t+t1)
    +
    +theta = np.random.randn(2,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 = 0.0
    +# Can you figure out a better way of setting up the contributions to each batch?
         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
    -        update = gradients*eta/(delta+np.sqrt(Giter))
    -        theta -= update
    -print("theta from own AdaGrad")
    +        eta = learning_schedule(epoch*m+i)
    +        theta = theta - eta*gradients
    +print("theta from own sdg")
     print(theta)
     
    @@ -329,7 +375,6 @@ delta = 1e-8
    -

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

    @@ -349,6 +394,8 @@ delta = 1e-844

  • 45
  • 46
  • +
  • 47
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs043.html b/doc/pub/week37/html/._week37-bs043.html index 95d62990c..ffedd3995 100644 --- a/doc/pub/week37/html/._week37-bs043.html +++ b/doc/pub/week37/html/._week37-bs043.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,7 +277,7 @@ MathJax.Hub.Config({

     

     

     

    -

    RMSprop for adaptive learning rate with Stochastic Gradient Descent

    +

    Same code but now with momentum gradient descent

    @@ -266,7 +285,7 @@ MathJax.Hub.Config({
    -
    # Using Autograd to calculate gradients using RMSprop  and Stochastic Gradient descent
    +  
    # Using Autograd to calculate gradients using SGD
     # OLS example
     from random import random, seed
     import numpy as np
    @@ -278,47 +297,60 @@ MathJax.Hub.Config({
     def CostOLS(y,X,theta):
         return np.sum((y-X @ theta)**2)
     
    -n = 1000
    -x = np.random.rand(n,1)
    -y = 2.0+3*x +4*x*x# +np.random.randn(n,1)
    +n = 100
    +x = 2*np.random.rand(n,1)
    +y = 4+3*x+np.random.randn(n,1)
     
    -X = np.c_[np.ones((n,1)), x, x*x]
    +X = np.c_[np.ones((n,1)), x]
     XT_X = X.T @ X
     theta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
     print("Own inversion")
     print(theta_linreg)
    +# Hessian matrix
    +H = (2.0/n)* XT_X
    +EigValues, EigVectors = np.linalg.eig(H)
    +print(f"Eigenvalues of Hessian Matrix:{EigValues}")
     
    +theta = np.random.randn(2,1)
    +eta = 1.0/np.max(EigValues)
    +Niterations = 100
     
     # Note that we request the derivative wrt third argument (theta, 2 here)
     training_gradient = grad(CostOLS,2)
    -# Define parameters for Stochastic Gradient Descent
    +
    +for iter in range(Niterations):
    +    gradients = (1.0/n)*training_gradient(y, X, theta)
    +    theta -= eta*gradients
    +print("theta from own gd")
    +print(theta)
    +
    +
     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)
    +t0, t1 = 5, 50
    +def learning_schedule(t):
    +    return t0/(t+t1)
    +
    +theta = np.random.randn(2,1)
    +
    +change = 0.0
    +delta_momentum = 0.3
     
    -# 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 = 0.0
         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)
    -	# Accumulated gradient
    -	# Scaling with rho the new and the previous results
    -        Giter = (rho*Giter+(1-rho)*gradients*gradients)
    -	# Taking the diagonal only and inverting
    -        update = gradients*eta/(delta+np.sqrt(Giter))
    -	# Hadamard product
    -        theta -= update
    -print("theta from own RMSprop")
    +        eta = learning_schedule(epoch*m+i)
    +        # calculate update
    +        new_change = eta*gradients+delta_momentum*change
    +        # take a step
    +        theta -= new_change
    +        # save the change
    +        change = new_change
    +print("theta from own sdg with momentum")
     print(theta)
     
    @@ -353,6 +385,8 @@ delta = 1e-844
  • 45
  • 46
  • +
  • 47
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs044.html b/doc/pub/week37/html/._week37-bs044.html index 8bebe3729..7324f3be7 100644 --- a/doc/pub/week37/html/._week37-bs044.html +++ b/doc/pub/week37/html/._week37-bs044.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,8 +277,7 @@ MathJax.Hub.Config({

     

     

     

    -

    And finally ADAM

    - +

    Similar (second order function now) problem but now with AdaGrad

    @@ -267,7 +285,7 @@ MathJax.Hub.Config({
    -
    # Using Autograd to calculate gradients using RMSprop  and Stochastic Gradient descent
    +  
    # Using Autograd to calculate gradients using AdaGrad and Stochastic Gradient descent
     # OLS example
     from random import random, seed
     import numpy as np
    @@ -281,7 +299,7 @@ MathJax.Hub.Config({
     
     n = 1000
     x = np.random.rand(n,1)
    -y = 2.0+3*x +4*x*x# +np.random.randn(n,1)
    +y = 2.0+3*x +4*x*x
     
     X = np.c_[np.ones((n,1)), x, x*x]
     XT_X = X.T @ X
    @@ -301,30 +319,19 @@ theta = np.# Value for learning rate
     eta = 0.01
    -# Value for parameters beta1 and beta2, see https://arxiv.org/abs/1412.6980
    -beta1 = 0.9
    -beta2 = 0.999
     # Including AdaGrad parameter to avoid possible division by zero
    -delta  = 1e-7
    -iter = 0
    +delta  = 1e-8
     for epoch in range(n_epochs):
    -    first_moment = 0.0
    -    second_moment = 0.0
    -    iter += 1
    +    Giter = 0.0
         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)
    -        # Computing moments first
    -        first_moment = beta1*first_moment + (1-beta1)*gradients
    -        second_moment = beta2*second_moment+(1-beta2)*gradients*gradients
    -        first_term = first_moment/(1.0-beta1**iter)
    -        second_term = second_moment/(1.0-beta2**iter)
    -	# Scaling with rho the new and the previous results
    -        update = eta*first_term/(np.sqrt(second_term)+delta)
    +        Giter += gradients*gradients
    +        update = gradients*eta/(delta+np.sqrt(Giter))
             theta -= update
    -print("theta from own ADAM")
    +print("theta from own AdaGrad")
     print(theta)
     
    @@ -341,6 +348,7 @@ delta = 1e-7
    +

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

    @@ -358,6 +366,8 @@ delta = 1e-744

  • 45
  • 46
  • +
  • 47
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs045.html b/doc/pub/week37/html/._week37-bs045.html index 74fba6165..addba1319 100644 --- a/doc/pub/week37/html/._week37-bs045.html +++ b/doc/pub/week37/html/._week37-bs045.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -258,22 +277,84 @@ MathJax.Hub.Config({

     

     

     

    -

    Material for the lab sessions

    +

    RMSprop for adaptive learning rate with Stochastic Gradient Descent

    -
    -
    - -
      -
    1. Exercise set for week 37
    2. -
    3. Work on project 1 -
    4. -
        -
      • For more discussions of Ridge regression and calculation of averages, Wessel van Wieringen's article is highly recommended.
      • -
      -
    + +
    +
    +
    +
    +
    +
    # 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 = 1000
    +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 = 0.0
    +    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)
    +	# Accumulated gradient
    +	# Scaling with rho the new and the previous results
    +        Giter = (rho*Giter+(1-rho)*gradients*gradients)
    +	# Taking the diagonal only and inverting
    +        update = gradients*eta/(delta+np.sqrt(Giter))
    +	# Hadamard product
    +        theta -= update
    +print("theta from own RMSprop")
    +print(theta)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    - + +

      @@ -289,6 +370,9 @@ MathJax.Hub.Config({
    • 44
    • 45
    • 46
    • +
    • 47
    • +
    • 48
    • +
    • »
    diff --git a/doc/pub/week37/html/._week37-bs046.html b/doc/pub/week37/html/._week37-bs046.html index 9da2c6905..669e81735 100644 --- a/doc/pub/week37/html/._week37-bs046.html +++ b/doc/pub/week37/html/._week37-bs046.html @@ -40,159 +40,148 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'plans-for-week-37-lecture-monday'), - ('Plans for week 37, lab sessions', + ('Readings and Videos:', 2, None, 'readings-and-videos'), + ('Material for lecture Monday September 8', 2, None, - 'plans-for-week-37-lab-sessions'), - ('Material for lecture Monday September 9', + 'material-for-lecture-monday-september-8'), + ('Gradient descent and revisiting Ordinary Least Squares from ' + 'last week', 2, None, - 'material-for-lecture-monday-september-9'), - ('Deriving OLS from a probability distribution', + 'gradient-descent-and-revisiting-ordinary-least-squares-from-last-week'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', 2, None, - 'deriving-ols-from-a-probability-distribution'), - ('Independent and Identically Distrubuted (iid)', + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('Gradient descent and Ridge', 2, None, - 'independent-and-identically-distrubuted-iid'), - ('Maximum Likelihood Estimation (MLE)', + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', 2, None, - 'maximum-likelihood-estimation-mle'), - ('A new Cost Function', 2, None, 'a-new-cost-function'), - ("More basic Statistics and Bayes' theorem", + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', 2, None, - 'more-basic-statistics-and-bayes-theorem'), - ('Marginal Probability', 2, None, 'marginal-probability'), - ('Conditional Probability', 2, None, 'conditional-probability'), - ("Bayes' Theorem", 2, None, 'bayes-theorem'), - ("Interpretations of Bayes' Theorem", + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', 2, None, - 'interpretations-of-bayes-theorem'), - ("Example of Usage of Bayes' theorem", + 'using-gradient-descent-methods-limitations'), + ('Improving gradient descent with momentum', 2, None, - 'example-of-usage-of-bayes-theorem'), - ('Doing it correctly', 2, None, 'doing-it-correctly'), - ("Bayes' Theorem and Ridge and Lasso Regression", + 'improving-gradient-descent-with-momentum'), + ('Same code but now with momentum gradient descent', 2, None, - 'bayes-theorem-and-ridge-and-lasso-regression'), - ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), - ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Why resampling methods', 2, None, 'why-resampling-methods'), - ('Resampling methods', 2, None, 'resampling-methods'), - ('Resampling approaches can be computationally expensive', + 'same-code-but-now-with-momentum-gradient-descent'), + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'resampling-approaches-can-be-computationally-expensive'), - ('Why resampling methods ?', 2, None, 'why-resampling-methods'), - ('Statistical analysis', 2, None, 'statistical-analysis'), - ('Resampling methods', 2, None, 'resampling-methods'), - ('Resampling methods: Bootstrap', + 'overview-video-on-stochastic-gradient-descent-sgd'), + ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), + ('Stochastic Gradient Descent (SGD)', 2, None, - 'resampling-methods-bootstrap'), - ('The Central Limit Theorem', + 'stochastic-gradient-descent-sgd'), + ('Stochastic Gradient Descent', 2, None, - 'the-central-limit-theorem'), - ('Finding the Limit', 2, None, 'finding-the-limit'), - ('Rewriting the $\\delta$-function', + 'stochastic-gradient-descent'), + ('Computation of gradients', 2, None, 'computation-of-gradients'), + ('SGD example', 2, None, 'sgd-example'), + ('The gradient step', 2, None, 'the-gradient-step'), + ('Simple example code', 2, None, 'simple-example-code'), + ('When do we stop?', 2, None, 'when-do-we-stop'), + ('Slightly different approach', 2, None, - 'rewriting-the-delta-function'), - ('Identifying Terms', 2, None, 'identifying-terms'), - ('Wrapping it up', 2, None, 'wrapping-it-up'), - ('Confidence Intervals', 2, None, 'confidence-intervals'), - ('Standard Approach based on the Normal Distribution', + 'slightly-different-approach'), + ('Time decay rate', 2, None, 'time-decay-rate'), + ('Code with a Number of Minibatches which varies', 2, None, - 'standard-approach-based-on-the-normal-distribution'), - ('Resampling methods: Bootstrap background', + 'code-with-a-number-of-minibatches-which-varies'), + ('Replace or not', 2, None, 'replace-or-not'), + ('Momentum based GD', 2, None, 'momentum-based-gd'), + ('More on momentum based approaches', 2, None, - 'resampling-methods-bootstrap-background'), - ('Resampling methods: More Bootstrap background', + 'more-on-momentum-based-approaches'), + ('Momentum parameter', 2, None, 'momentum-parameter'), + ('Second moment of the gradient', 2, None, - 'resampling-methods-more-bootstrap-background'), - ('Resampling methods: Bootstrap approach', + 'second-moment-of-the-gradient'), + ('RMS prop', 2, None, 'rms-prop'), + ('"ADAM optimizer":"https://arxiv.org/abs/1412.6980"', 2, None, - 'resampling-methods-bootstrap-approach'), - ('Resampling methods: Bootstrap steps', + 'adam-optimizer-https-arxiv-org-abs-1412-6980'), + ('Algorithms and codes for Adagrad, RMSprop and Adam', 2, None, - 'resampling-methods-bootstrap-steps'), - ('Code example for the Bootstrap method', + 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'code-example-for-the-bootstrap-method'), - ('Plotting the Histogram', 2, None, 'plotting-the-histogram'), - ('The bias-variance tradeoff', + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'the-bias-variance-tradeoff'), - ('A way to Read the Bias-Variance Tradeoff', + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'a-way-to-read-the-bias-variance-tradeoff'), - ('Example code for Bias-Variance tradeoff', + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', 2, None, - 'example-code-for-bias-variance-tradeoff'), - ('Understanding what happens', + 'sneaking-in-auotmatic-differentiation-using-autograd'), + ('Same code but now with momentum gradient descent', 2, None, - 'understanding-what-happens'), - ('Summing up', 2, None, 'summing-up'), - ("Another Example from Scikit-Learn's Repository", + 'same-code-but-now-with-momentum-gradient-descent'), + ('Including Stochastic Gradient Descent with Autograd', 2, None, - 'another-example-from-scikit-learn-s-repository'), - ('Various steps in cross-validation', + 'including-stochastic-gradient-descent-with-autograd'), + ('Same code but now with momentum gradient descent', 2, None, - 'various-steps-in-cross-validation'), - ('Cross-validation in brief', + 'same-code-but-now-with-momentum-gradient-descent'), + ('Similar (second order function now) problem but now with ' + 'AdaGrad', 2, None, - 'cross-validation-in-brief'), - ('Code Example for Cross-validation and $k$-fold ' - 'Cross-validation', + 'similar-second-order-function-now-problem-but-now-with-adagrad'), + ('RMSprop for adaptive learning rate with Stochastic Gradient ' + 'Descent', 2, None, - 'code-example-for-cross-validation-and-k-fold-cross-validation'), - ('More examples on bootstrap and cross-validation and errors', + 'rmsprop-for-adaptive-learning-rate-with-stochastic-gradient-descent'), + ('And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"', 2, None, - 'more-examples-on-bootstrap-and-cross-validation-and-errors'), - ('The same example but now with cross-validation', - 2, - None, - 'the-same-example-but-now-with-cross-validation'), + 'and-finally-adam-https-arxiv-org-pdf-1412-6980-pdf'), ('Material for the lab sessions', 2, None, - 'material-for-the-lab-sessions'), - ('Linking the regression analysis with a statistical ' - 'interpretation', - 2, - None, - 'linking-the-regression-analysis-with-a-statistical-interpretation'), - ('Assumptions made', 2, None, 'assumptions-made'), - ('Expectation value and variance', - 2, - None, - 'expectation-value-and-variance'), - ('Expectation value and variance for $\\boldsymbol{\\beta}$', - 2, - None, - 'expectation-value-and-variance-for-boldsymbol-beta')]} + 'material-for-the-lab-sessions')]} end of tocinfo --> @@ -228,58 +217,55 @@ MathJax.Hub.Config({ Contents @@ -291,9 +277,8 @@ MathJax.Hub.Config({

     

     

     

    -

    Code Example for Cross-validation and \( k \)-fold Cross-validation

    +

    And finally ADAM

    -

    The code here uses Ridge regression with cross-validation (CV) resampling and \( k \)-fold CV in order to fit a specific polynomial.

    @@ -301,95 +286,65 @@ MathJax.Hub.Config({
    -
    import numpy as np
    +  
    # 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 sklearn.model_selection import KFold
    -from sklearn.linear_model import Ridge
    -from sklearn.model_selection import cross_val_score
    -from sklearn.preprocessing import PolynomialFeatures
    +from autograd import grad
     
    -# A seed just to ensure that the random numbers are the same for every run.
    -# Useful for eventual debugging.
    -np.random.seed(3155)
    +# Note change from previous example
    +def CostOLS(y,X,theta):
    +    return np.sum((y-X @ theta)**2)
     
    -# Generate the data.
    -nsamples = 100
    -x = np.random.randn(nsamples)
    -y = 3*x**2 + np.random.randn(nsamples)
    +n = 1000
    +x = np.random.rand(n,1)
    +y = 2.0+3*x +4*x*x# +np.random.randn(n,1)
     
    -## Cross-validation on Ridge regression using KFold only
    -
    -# Decide degree on polynomial to fit
    -poly = PolynomialFeatures(degree = 6)
    -
    -# Decide which values of lambda to use
    -nlambdas = 500
    -lambdas = np.logspace(-3, 5, nlambdas)
    -
    -# Initialize a KFold instance
    -k = 5
    -kfold = KFold(n_splits = k)
    -
    -# Perform the cross-validation to estimate MSE
    -scores_KFold = np.zeros((nlambdas, k))
    -
    -i = 0
    -for lmb in lambdas:
    -    ridge = Ridge(alpha = lmb)
    -    j = 0
    -    for train_inds, test_inds in kfold.split(x):
    -        xtrain = x[train_inds]
    -        ytrain = y[train_inds]
    -
    -        xtest = x[test_inds]
    -        ytest = y[test_inds]
    -
    -        Xtrain = poly.fit_transform(xtrain[:, np.newaxis])
    -        ridge.fit(Xtrain, ytrain[:, np.newaxis])
    -
    -        Xtest = poly.fit_transform(xtest[:, np.newaxis])
    -        ypred = ridge.predict(Xtest)
    -
    -        scores_KFold[i,j] = np.sum((ypred - ytest[:, np.newaxis])**2)/np.size(ypred)
    -
    -        j += 1
    -    i += 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)
     
     
    -estimated_mse_KFold = np.mean(scores_KFold, axis = 1)
    +# 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)
     
    -## Cross-validation using cross_val_score from sklearn along with KFold
    -
    -# kfold is an instance initialized above as:
    -# kfold = KFold(n_splits = k)
    -
    -estimated_mse_sklearn = np.zeros(nlambdas)
    -i = 0
    -for lmb in lambdas:
    -    ridge = Ridge(alpha = lmb)
    -
    -    X = poly.fit_transform(x[:, np.newaxis])
    -    estimated_mse_folds = cross_val_score(ridge, X, y[:, np.newaxis], scoring='neg_mean_squared_error', cv=kfold)
    -
    -    # cross_val_score return an array containing the estimated negative mse for every fold.
    -    # we have to the the mean of every array in order to get an estimate of the mse of the model
    -    estimated_mse_sklearn[i] = np.mean(-estimated_mse_folds)
    -
    -    i += 1
    -
    -## Plot and compare the slightly different ways to perform cross-validation
    -
    -plt.figure()
    -
    -plt.plot(np.log10(lambdas), estimated_mse_sklearn, label = 'cross_val_score')
    -plt.plot(np.log10(lambdas), estimated_mse_KFold, 'r--', label = 'KFold')
    -
    -plt.xlabel('log10(lambda)')
    -plt.ylabel('mse')
    -
    -plt.legend()
    -
    -plt.show()
    +# Value for learning rate
    +eta = 0.01
    +# Value for parameters beta1 and beta2, see https://arxiv.org/abs/1412.6980
    +beta1 = 0.9
    +beta2 = 0.999
    +# Including AdaGrad parameter to avoid possible division by zero
    +delta  = 1e-7
    +iter = 0
    +for epoch in range(n_epochs):
    +    first_moment = 0.0
    +    second_moment = 0.0
    +    iter += 1
    +    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)
    +        # Computing moments first
    +        first_moment = beta1*first_moment + (1-beta1)*gradients
    +        second_moment = beta2*second_moment+(1-beta2)*gradients*gradients
    +        first_term = first_moment/(1.0-beta1**iter)
    +        second_term = second_moment/(1.0-beta2**iter)
    +	# Scaling with rho the new and the previous results
    +        update = eta*first_term/(np.sqrt(second_term)+delta)
    +        theta -= update
    +print("theta from own ADAM")
    +print(theta)
     
    @@ -422,12 +377,6 @@ plt.show()
  • 46
  • 47
  • 48
  • -
  • 49
  • -
  • 50
  • -
  • 51
  • -
  • 52
  • -
  • 53
  • -
  • 54
  • »
  • diff --git a/doc/pub/week37/html/._week37-bs047.html b/doc/pub/week37/html/._week37-bs047.html index a80e1fa8d..e2634b78a 100644 --- a/doc/pub/week37/html/._week37-bs047.html +++ b/doc/pub/week37/html/._week37-bs047.html @@ -40,159 +40,148 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'plans-for-week-37-lecture-monday'), - ('Plans for week 37, lab sessions', + ('Readings and Videos:', 2, None, 'readings-and-videos'), + ('Material for lecture Monday September 8', 2, None, - 'plans-for-week-37-lab-sessions'), - ('Material for lecture Monday September 9', + 'material-for-lecture-monday-september-8'), + ('Gradient descent and revisiting Ordinary Least Squares from ' + 'last week', 2, None, - 'material-for-lecture-monday-september-9'), - ('Deriving OLS from a probability distribution', + 'gradient-descent-and-revisiting-ordinary-least-squares-from-last-week'), + ('Gradient descent example', 2, None, 'gradient-descent-example'), + ('The derivative of the cost/loss function', 2, None, - 'deriving-ols-from-a-probability-distribution'), - ('Independent and Identically Distrubuted (iid)', + 'the-derivative-of-the-cost-loss-function'), + ('The Hessian matrix', 2, None, 'the-hessian-matrix'), + ('Simple program', 2, None, 'simple-program'), + ('Gradient Descent Example', 2, None, 'gradient-descent-example'), + ('Gradient descent and Ridge', 2, None, - 'independent-and-identically-distrubuted-iid'), - ('Maximum Likelihood Estimation (MLE)', + 'gradient-descent-and-ridge'), + ('The Hessian matrix for Ridge Regression', 2, None, - 'maximum-likelihood-estimation-mle'), - ('A new Cost Function', 2, None, 'a-new-cost-function'), - ("More basic Statistics and Bayes' theorem", + 'the-hessian-matrix-for-ridge-regression'), + ('Program example for gradient descent with Ridge Regression', 2, None, - 'more-basic-statistics-and-bayes-theorem'), - ('Marginal Probability', 2, None, 'marginal-probability'), - ('Conditional Probability', 2, None, 'conditional-probability'), - ("Bayes' Theorem", 2, None, 'bayes-theorem'), - ("Interpretations of Bayes' Theorem", + 'program-example-for-gradient-descent-with-ridge-regression'), + ('Using gradient descent methods, limitations', 2, None, - 'interpretations-of-bayes-theorem'), - ("Example of Usage of Bayes' theorem", + 'using-gradient-descent-methods-limitations'), + ('Improving gradient descent with momentum', 2, None, - 'example-of-usage-of-bayes-theorem'), - ('Doing it correctly', 2, None, 'doing-it-correctly'), - ("Bayes' Theorem and Ridge and Lasso Regression", + 'improving-gradient-descent-with-momentum'), + ('Same code but now with momentum gradient descent', 2, None, - 'bayes-theorem-and-ridge-and-lasso-regression'), - ('Ridge and Bayes', 2, None, 'ridge-and-bayes'), - ('Lasso and Bayes', 2, None, 'lasso-and-bayes'), - ('Why resampling methods', 2, None, 'why-resampling-methods'), - ('Resampling methods', 2, None, 'resampling-methods'), - ('Resampling approaches can be computationally expensive', + 'same-code-but-now-with-momentum-gradient-descent'), + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'resampling-approaches-can-be-computationally-expensive'), - ('Why resampling methods ?', 2, None, 'why-resampling-methods'), - ('Statistical analysis', 2, None, 'statistical-analysis'), - ('Resampling methods', 2, None, 'resampling-methods'), - ('Resampling methods: Bootstrap', + 'overview-video-on-stochastic-gradient-descent-sgd'), + ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), + ('Stochastic Gradient Descent (SGD)', 2, None, - 'resampling-methods-bootstrap'), - ('The Central Limit Theorem', + 'stochastic-gradient-descent-sgd'), + ('Stochastic Gradient Descent', 2, None, - 'the-central-limit-theorem'), - ('Finding the Limit', 2, None, 'finding-the-limit'), - ('Rewriting the $\\delta$-function', + 'stochastic-gradient-descent'), + ('Computation of gradients', 2, None, 'computation-of-gradients'), + ('SGD example', 2, None, 'sgd-example'), + ('The gradient step', 2, None, 'the-gradient-step'), + ('Simple example code', 2, None, 'simple-example-code'), + ('When do we stop?', 2, None, 'when-do-we-stop'), + ('Slightly different approach', 2, None, - 'rewriting-the-delta-function'), - ('Identifying Terms', 2, None, 'identifying-terms'), - ('Wrapping it up', 2, None, 'wrapping-it-up'), - ('Confidence Intervals', 2, None, 'confidence-intervals'), - ('Standard Approach based on the Normal Distribution', + 'slightly-different-approach'), + ('Time decay rate', 2, None, 'time-decay-rate'), + ('Code with a Number of Minibatches which varies', 2, None, - 'standard-approach-based-on-the-normal-distribution'), - ('Resampling methods: Bootstrap background', + 'code-with-a-number-of-minibatches-which-varies'), + ('Replace or not', 2, None, 'replace-or-not'), + ('Momentum based GD', 2, None, 'momentum-based-gd'), + ('More on momentum based approaches', 2, None, - 'resampling-methods-bootstrap-background'), - ('Resampling methods: More Bootstrap background', + 'more-on-momentum-based-approaches'), + ('Momentum parameter', 2, None, 'momentum-parameter'), + ('Second moment of the gradient', 2, None, - 'resampling-methods-more-bootstrap-background'), - ('Resampling methods: Bootstrap approach', + 'second-moment-of-the-gradient'), + ('RMS prop', 2, None, 'rms-prop'), + ('"ADAM optimizer":"https://arxiv.org/abs/1412.6980"', 2, None, - 'resampling-methods-bootstrap-approach'), - ('Resampling methods: Bootstrap steps', + 'adam-optimizer-https-arxiv-org-abs-1412-6980'), + ('Algorithms and codes for Adagrad, RMSprop and Adam', 2, None, - 'resampling-methods-bootstrap-steps'), - ('Code example for the Bootstrap method', + 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'code-example-for-the-bootstrap-method'), - ('Plotting the Histogram', 2, None, 'plotting-the-histogram'), - ('The bias-variance tradeoff', + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'the-bias-variance-tradeoff'), - ('A way to Read the Bias-Variance Tradeoff', + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'a-way-to-read-the-bias-variance-tradeoff'), - ('Example code for Bias-Variance tradeoff', + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', 2, None, - 'example-code-for-bias-variance-tradeoff'), - ('Understanding what happens', + 'sneaking-in-auotmatic-differentiation-using-autograd'), + ('Same code but now with momentum gradient descent', 2, None, - 'understanding-what-happens'), - ('Summing up', 2, None, 'summing-up'), - ("Another Example from Scikit-Learn's Repository", + 'same-code-but-now-with-momentum-gradient-descent'), + ('Including Stochastic Gradient Descent with Autograd', 2, None, - 'another-example-from-scikit-learn-s-repository'), - ('Various steps in cross-validation', + 'including-stochastic-gradient-descent-with-autograd'), + ('Same code but now with momentum gradient descent', 2, None, - 'various-steps-in-cross-validation'), - ('Cross-validation in brief', + 'same-code-but-now-with-momentum-gradient-descent'), + ('Similar (second order function now) problem but now with ' + 'AdaGrad', 2, None, - 'cross-validation-in-brief'), - ('Code Example for Cross-validation and $k$-fold ' - 'Cross-validation', + 'similar-second-order-function-now-problem-but-now-with-adagrad'), + ('RMSprop for adaptive learning rate with Stochastic Gradient ' + 'Descent', 2, None, - 'code-example-for-cross-validation-and-k-fold-cross-validation'), - ('More examples on bootstrap and cross-validation and errors', + 'rmsprop-for-adaptive-learning-rate-with-stochastic-gradient-descent'), + ('And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"', 2, None, - 'more-examples-on-bootstrap-and-cross-validation-and-errors'), - ('The same example but now with cross-validation', - 2, - None, - 'the-same-example-but-now-with-cross-validation'), + 'and-finally-adam-https-arxiv-org-pdf-1412-6980-pdf'), ('Material for the lab sessions', 2, None, - 'material-for-the-lab-sessions'), - ('Linking the regression analysis with a statistical ' - 'interpretation', - 2, - None, - 'linking-the-regression-analysis-with-a-statistical-interpretation'), - ('Assumptions made', 2, None, 'assumptions-made'), - ('Expectation value and variance', - 2, - None, - 'expectation-value-and-variance'), - ('Expectation value and variance for $\\boldsymbol{\\beta}$', - 2, - None, - 'expectation-value-and-variance-for-boldsymbol-beta')]} + 'material-for-the-lab-sessions')]} end of tocinfo --> @@ -228,58 +217,55 @@ MathJax.Hub.Config({ Contents @@ -291,109 +277,22 @@ MathJax.Hub.Config({

     

     

     

    -

    More examples on bootstrap and cross-validation and errors

    +

    Material for the lab sessions

    - - -
    -
    -
    -
    -
    -
    # Common imports
    -import os
    -import numpy as np
    -import pandas as pd
    -import matplotlib.pyplot as plt
    -from sklearn.linear_model import LinearRegression, Ridge, Lasso
    -from sklearn.model_selection import train_test_split
    -from sklearn.utils import resample
    -from sklearn.metrics import mean_squared_error
    -# Where to save the figures and data files
    -PROJECT_ROOT_DIR = "Results"
    -FIGURE_ID = "Results/FigureFiles"
    -DATA_ID = "DataFiles/"
    -
    -if not os.path.exists(PROJECT_ROOT_DIR):
    -    os.mkdir(PROJECT_ROOT_DIR)
    -
    -if not os.path.exists(FIGURE_ID):
    -    os.makedirs(FIGURE_ID)
    -
    -if not os.path.exists(DATA_ID):
    -    os.makedirs(DATA_ID)
    -
    -def image_path(fig_id):
    -    return os.path.join(FIGURE_ID, fig_id)
    -
    -def data_path(dat_id):
    -    return os.path.join(DATA_ID, dat_id)
    -
    -def save_fig(fig_id):
    -    plt.savefig(image_path(fig_id) + ".png", format='png')
    -
    -infile = open(data_path("EoS.csv"),'r')
    -
    -# Read the EoS data as  csv file and organize the data into two arrays with density and energies
    -EoS = pd.read_csv(infile, names=('Density', 'Energy'))
    -EoS['Energy'] = pd.to_numeric(EoS['Energy'], errors='coerce')
    -EoS = EoS.dropna()
    -Energies = EoS['Energy']
    -Density = EoS['Density']
    -#  The design matrix now as function of various polytrops
    -
    -Maxpolydegree = 30
    -X = np.zeros((len(Density),Maxpolydegree))
    -X[:,0] = 1.0
    -testerror = np.zeros(Maxpolydegree)
    -trainingerror = np.zeros(Maxpolydegree)
    -polynomial = np.zeros(Maxpolydegree)
    -
    -trials = 100
    -for polydegree in range(1, Maxpolydegree):
    -    polynomial[polydegree] = polydegree
    -    for degree in range(polydegree):
    -        X[:,degree] = Density**(degree/3.0)
    -
    -# loop over trials in order to estimate the expectation value of the MSE
    -    testerror[polydegree] = 0.0
    -    trainingerror[polydegree] = 0.0
    -    for samples in range(trials):
    -        x_train, x_test, y_train, y_test = train_test_split(X, Energies, test_size=0.2)
    -        model = LinearRegression(fit_intercept=False).fit(x_train, y_train)
    -        ypred = model.predict(x_train)
    -        ytilde = model.predict(x_test)
    -        testerror[polydegree] += mean_squared_error(y_test, ytilde)
    -        trainingerror[polydegree] += mean_squared_error(y_train, ypred) 
    -
    -    testerror[polydegree] /= trials
    -    trainingerror[polydegree] /= trials
    -    print("Degree of polynomial: %3d"% polynomial[polydegree])
    -    print("Mean squared error on training data: %.8f" % trainingerror[polydegree])
    -    print("Mean squared error on test data: %.8f" % testerror[polydegree])
    -
    -plt.plot(polynomial, np.log10(trainingerror), label='Training Error')
    -plt.plot(polynomial, np.log10(testerror), label='Test Error')
    -plt.xlabel('Polynomial degree')
    -plt.ylabel('log10[MSE]')
    -plt.legend()
    -plt.show()
    -
    +
    +
    + +
      +
    1. Exercise set for week 37
    2. +
    3. Work on project 1 +
    4. +
        +
      • For more discussions of Ridge regression and calculation of averages, Wessel van Wieringen's article is highly recommended.
      • +
      +
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Note that we kept the intercept column in the fitting here. This means that we need to set the intercept in the call to the Scikit-Learn function as False. Alternatively, we could have set up the design matrix \( X \) without the first column of ones.

    +

    @@ -410,13 +309,6 @@ plt.show()

  • 46
  • 47
  • 48
  • -
  • 49
  • -
  • 50
  • -
  • 51
  • -
  • 52
  • -
  • 53
  • -
  • 54
  • -
  • »
  • diff --git a/doc/pub/week37/html/week37-bs.html b/doc/pub/week37/html/week37-bs.html index 541ecc814..cfe72140a 100644 --- a/doc/pub/week37/html/week37-bs.html +++ b/doc/pub/week37/html/week37-bs.html @@ -82,11 +82,14 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -129,19 +132,30 @@ doconce format html week37.do.txt --html_style=bootstrap --pygments_html_style=d 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -216,37 +230,42 @@ MathJax.Hub.Config({
  • Program example for gradient descent with Ridge Regression
  • Using gradient descent methods, limitations
  • Improving gradient descent with momentum
  • -
  • Same code but now with momentum gradient descent
  • -
  • Overview video on Stochastic Gradient Descent
  • +
  • Same code but now with momentum gradient descent
  • +
  • Overview video on Stochastic Gradient Descent (SGD)
  • Batches and mini-batches
  • -
  • Stochastic Gradient Descent (SGD)
  • -
  • Stochastic Gradient Descent
  • -
  • Computation of gradients
  • -
  • SGD example
  • -
  • The gradient step
  • -
  • Simple example code
  • -
  • When do we stop?
  • -
  • Slightly different approach
  • -
  • Time decay rate
  • -
  • Code with a Number of Minibatches which varies
  • -
  • Replace or not
  • -
  • Momentum based GD
  • -
  • More on momentum based approaches
  • -
  • Momentum parameter
  • -
  • Second moment of the gradient
  • -
  • RMS prop
  • -
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • -
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • -
  • Practical tips
  • -
  • Sneaking in automatic differentiation using Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • But none of these can compete with Newton's method
  • -
  • Including Stochastic Gradient Descent with Autograd
  • -
  • Same code but now with momentum gradient descent
  • -
  • Similar (second order function now) problem but now with AdaGrad
  • -
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • -
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • -
  • Material for the lab sessions
  • +
  • Pros and cons
  • +
  • Convergence rates
  • +
  • Accuracy
  • +
  • Stochastic Gradient Descent (SGD)
  • +
  • Stochastic Gradient Descent
  • +
  • Computation of gradients
  • +
  • SGD example
  • +
  • The gradient step
  • +
  • Simple example code
  • +
  • When do we stop?
  • +
  • Slightly different approach
  • +
  • Time decay rate
  • +
  • Code with a Number of Minibatches which varies
  • +
  • Replace or not
  • +
  • Momentum based GD
  • +
  • More on momentum based approaches
  • +
  • Momentum parameter
  • +
  • Second moment of the gradient
  • +
  • RMS prop
  • +
  • "ADAM optimizer":"https://arxiv.org/abs/1412.6980"
  • +
  • Algorithms and codes for Adagrad, RMSprop and Adam
  • +
  • AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html"
  • +
  • Practical tips
  • +
  • Sneaking in auotmatic differentiation using Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Including Stochastic Gradient Descent with Autograd
  • +
  • Same code but now with momentum gradient descent
  • +
  • Similar (second order function now) problem but now with AdaGrad
  • +
  • RMSprop for adaptive learning rate with Stochastic Gradient Descent
  • +
  • And finally "ADAM":"https://arxiv.org/pdf/1412.6980.pdf"
  • +
  • Material for the lab sessions
  • @@ -300,7 +319,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 46
  • +
  • 48
  • »
  • diff --git a/doc/pub/week37/html/week37-reveal.html b/doc/pub/week37/html/week37-reveal.html index c8984a7e6..f33912778 100644 --- a/doc/pub/week37/html/week37-reveal.html +++ b/doc/pub/week37/html/week37-reveal.html @@ -217,7 +217,7 @@ MathJax.Hub.Config({

      -

    1. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at https://www.deeplearningbook.org/contents/numerical.html and chapter 8.3-8.5 at URL::https://www.deeplearningbook.org/contents/optimization.html"
    2. +

    3. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at https://www.deeplearningbook.org/contents/numerical.html and chapter 8.3-8.5 at https://www.deeplearningbook.org/contents/optimization.html
    4. Rashcka et al, pages 37-44 and pages 278-283 with focus on linear regression.
    5. Video on gradient descent at https://www.youtube.com/watch?v=sDv4f4s2SB8
    6. Video on Stochastic gradient descent at https://www.youtube.com/watch?v=vMh0zPT0tLI
    7. @@ -743,9 +743,16 @@ pyplot.show()
      -

      Overview video on Stochastic Gradient Descent

      +

      Overview video on Stochastic Gradient Descent (SGD)

      What is Stochastic Gradient Descent +

      There are several reasons for using stochastic gradient descent. Some of these are:

      + +
        +

      1. Efficiency: Updates weights more frequently using a single or a small batch of samples, which speeds up convergence.
      2. +

      3. Hopefully avoid Local Minima
      4. +

      5. Memory Usage: Requires less memory compared to computing gradients for the entire dataset.
      6. +
      @@ -764,6 +771,50 @@ perform a parameter update.

      +
      +

      Pros and cons

      + +
        +

      1. Speed: SGD is faster than gradient descent because it uses only one training example per iteration, whereas gradient descent requires the entire dataset. This speed advantage becomes more significant as the size of the dataset increases.
      2. +

      3. Convergence: Gradient descent has a more predictable convergence behaviour because it uses the average gradient of the entire dataset. In contrast, SGD’s convergence behaviour can be more erratic due to its random sampling of individual training examples.
      4. +

      5. Memory: Gradient descent requires more memory than SGD because it must store the entire dataset for each iteration. SGD only needs to store the current training example, making it more memory-efficient.
      6. +
      +
      + +
      +

      Convergence rates

      + +
        +

      1. Stochastic Gradient Descent has a faster convergence rate due to the use of single training examples in each iteration.
      2. +

      3. Gradient Descent as a slower convergence rate, as it uses the entire dataset for each iteration.
      4. +
      +
      + +
      +

      Accuracy

      + +

      In general, stochastic Gradient Descent is Less accurate than gradient +descent, as it calculates the gradient on single examples, which may +not accurately represent the overall dataset. Gradient Descent is +more accurate because it uses the average gradient calculated over the +entire dataset. +

      + +

      There are other disadvantages to using SGD. The main drawback is that +its convergence behaviour can be more erratic due to the random +sampling of individual training examples. This can lead to less +accurate results, as the algorithm may not converge to the true +minimum of the cost function. Additionally, the learning rate, which +determines the step size of each update to the model’s parameters, +must be carefully chosen to ensure convergence. +

      + +

      It is however the method of choice in deep learning algorithms where +SGD is often used in combination with other optimization techniques, +such as momentum or adaptive learning rates +

      +
      +

      Stochastic Gradient Descent (SGD)

      @@ -1249,7 +1300,9 @@ $$ $$

       
      -

      One of the major advantages of NAG is that it allows for the use of a larger learning rate than GDM for the same choice of \( \gamma \).

      +

      One of the major advantages of NAG is that it allows for the use of a +larger learning rate than GDM for the same choice of \( \gamma \). +

      @@ -1272,7 +1325,7 @@ the steep computational price of calculating or approximating Hessians.

      -

      Recently, a number of methods have been introduced that accomplish +

      During the last decade a number of methods have been introduced that accomplish this by tracking not only the gradient, but also the second moment of the gradient. These methods include AdaGrad, AdaDelta, Root Mean Squared Propagation (RMS-Prop), and ADAM. @@ -1375,7 +1428,28 @@ $$

      The algorithms we have implemented are well described in the text by Goodfellow, Bengio and Courville, chapter 8.

      -

      The codes which implement these algorithms are discussed below here.

      +

      The codes which implement these algorithms are discussed after our presentation of automatic differentiation.

      +

      AdaGrad algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +

      +

      RMSProp algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +

      +

      ADAM algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +

      @@ -1390,10 +1464,11 @@ $$
      -

      Sneaking in automatic differentiation using Autograd

      +

      Sneaking in auotmatic differentiation using Autograd

      -

      We anticipate our discussions to come in connection with neural networks and automatic differentiation -by showing how we can use autograd for the cases above. Later we will replace autograd with JAX. +

      We conclude the part on optmization by showing how we can make codes +for linear regression and logistic regression using autograd. The +first example shows results with ordinary leats squares.

      @@ -1546,70 +1621,6 @@ delta_momentum = 0.3
    -
    -

    But none of these can compete with Newton's method

    - - - -
    -
    -
    -
    -
    -
    # Using Newton's method
    -from random import random, seed
    -import numpy as np
    -import autograd.numpy as np
    -import matplotlib.pyplot as plt
    -from autograd import grad
    -
    -def CostOLS(beta):
    -    return (1.0/n)*np.sum((y-X @ beta)**2)
    -
    -n = 100
    -x = 2*np.random.rand(n,1)
    -y = 4+3*x+np.random.randn(n,1)
    -
    -X = np.c_[np.ones((n,1)), x]
    -XT_X = X.T @ X
    -beta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
    -print("Own inversion")
    -print(beta_linreg)
    -# Hessian matrix
    -H = (2.0/n)* XT_X
    -# Note that here the Hessian does not depend on the parameters beta
    -invH = np.linalg.pinv(H)
    -EigValues, EigVectors = np.linalg.eig(H)
    -print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    -
    -beta = np.random.randn(2,1)
    -Niterations = 5
    -
    -# define the gradient
    -training_gradient = grad(CostOLS)
    -
    -for iter in range(Niterations):
    -    gradients = training_gradient(beta)
    -    beta -= invH @ gradients
    -    print(iter,gradients[0],gradients[1])
    -print("beta from own Newton code")
    -print(beta)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -

    Including Stochastic Gradient Descent with Autograd

    In this code we include the stochastic gradient descent approach discussed above. Note here that we specify which argument we are taking the derivative with respect to when using autograd.

    diff --git a/doc/pub/week37/html/week37-solarized.html b/doc/pub/week37/html/week37-solarized.html index f1b99880d..db444578b 100644 --- a/doc/pub/week37/html/week37-solarized.html +++ b/doc/pub/week37/html/week37-solarized.html @@ -109,11 +109,14 @@ div.toc p,a { 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -156,19 +159,30 @@ div.toc p,a { 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -258,7 +272,7 @@ MathJax.Hub.Config({

      -
    1. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at https://www.deeplearningbook.org/contents/numerical.html and chapter 8.3-8.5 at URL::https://www.deeplearningbook.org/contents/optimization.html"
    2. +
    3. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at https://www.deeplearningbook.org/contents/numerical.html and chapter 8.3-8.5 at https://www.deeplearningbook.org/contents/optimization.html
    4. Rashcka et al, pages 37-44 and pages 278-283 with focus on linear regression.
    5. Video on gradient descent at https://www.youtube.com/watch?v=sDv4f4s2SB8
    6. Video on Stochastic gradient descent at https://www.youtube.com/watch?v=vMh0zPT0tLI
    7. @@ -753,10 +767,16 @@ pyplot.show()









      -

      Overview video on Stochastic Gradient Descent

      +

      Overview video on Stochastic Gradient Descent (SGD)

      What is Stochastic Gradient Descent +

      There are several reasons for using stochastic gradient descent. Some of these are:

      +
        +
      1. Efficiency: Updates weights more frequently using a single or a small batch of samples, which speeds up convergence.
      2. +
      3. Hopefully avoid Local Minima
      4. +
      5. Memory Usage: Requires less memory compared to computing gradients for the entire dataset.
      6. +










      Batches and mini-batches

      @@ -772,6 +792,45 @@ an entire training set of several millions. This batch is then used to perform a parameter update.

      +









      +

      Pros and cons

      + +
        +
      1. Speed: SGD is faster than gradient descent because it uses only one training example per iteration, whereas gradient descent requires the entire dataset. This speed advantage becomes more significant as the size of the dataset increases.
      2. +
      3. Convergence: Gradient descent has a more predictable convergence behaviour because it uses the average gradient of the entire dataset. In contrast, SGD’s convergence behaviour can be more erratic due to its random sampling of individual training examples.
      4. +
      5. Memory: Gradient descent requires more memory than SGD because it must store the entire dataset for each iteration. SGD only needs to store the current training example, making it more memory-efficient.
      6. +
      +









      +

      Convergence rates

      + +
        +
      1. Stochastic Gradient Descent has a faster convergence rate due to the use of single training examples in each iteration.
      2. +
      3. Gradient Descent as a slower convergence rate, as it uses the entire dataset for each iteration.
      4. +
      +









      +

      Accuracy

      + +

      In general, stochastic Gradient Descent is Less accurate than gradient +descent, as it calculates the gradient on single examples, which may +not accurately represent the overall dataset. Gradient Descent is +more accurate because it uses the average gradient calculated over the +entire dataset. +

      + +

      There are other disadvantages to using SGD. The main drawback is that +its convergence behaviour can be more erratic due to the random +sampling of individual training examples. This can lead to less +accurate results, as the algorithm may not converge to the true +minimum of the cost function. Additionally, the learning rate, which +determines the step size of each update to the model’s parameters, +must be carefully chosen to ensure convergence. +

      + +

      It is however the method of choice in deep learning algorithms where +SGD is often used in combination with other optimization techniques, +such as momentum or adaptive learning rates +

      +









      Stochastic Gradient Descent (SGD)

      @@ -1225,7 +1284,9 @@ $$ \end{align} $$ -

      One of the major advantages of NAG is that it allows for the use of a larger learning rate than GDM for the same choice of \( \gamma \).

      +

      One of the major advantages of NAG is that it allows for the use of a +larger learning rate than GDM for the same choice of \( \gamma \). +











      Second moment of the gradient

      @@ -1247,7 +1308,7 @@ the steep computational price of calculating or approximating Hessians.

      -

      Recently, a number of methods have been introduced that accomplish +

      During the last decade a number of methods have been introduced that accomplish this by tracking not only the gradient, but also the second moment of the gradient. These methods include AdaGrad, AdaDelta, Root Mean Squared Propagation (RMS-Prop), and ADAM. @@ -1342,7 +1403,28 @@ $$

      The algorithms we have implemented are well described in the text by Goodfellow, Bengio and Courville, chapter 8.

      -

      The codes which implement these algorithms are discussed below here.

      +

      The codes which implement these algorithms are discussed after our presentation of automatic differentiation.

      +

      AdaGrad algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +

      +

      RMSProp algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +

      +

      ADAM algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +











      Practical tips

      @@ -1354,10 +1436,11 @@ $$
    8. Adaptive optimization methods don't always have good generalization. Recent studies have shown that adaptive methods such as ADAM, RMSPorp, and AdaGrad tend to have poor generalization compared to SGD or SGD with momentum, particularly in the high-dimensional limit (i.e. the number of parameters exceeds the number of data points). Although it is not clear at this stage why these methods perform so well in training deep neural networks, simpler procedures like properly-tuned SGD may work as well or better in these applications.










    9. -

      Sneaking in automatic differentiation using Autograd

      +

      Sneaking in auotmatic differentiation using Autograd

      -

      We anticipate our discussions to come in connection with neural networks and automatic differentiation -by showing how we can use autograd for the cases above. Later we will replace autograd with JAX. +

      We conclude the part on optmization by showing how we can make codes +for linear regression and logistic regression using autograd. The +first example shows results with ordinary leats squares.

      @@ -1510,70 +1593,6 @@ delta_momentum = 0.3
    -









    -

    But none of these can compete with Newton's method

    - - - -
    -
    -
    -
    -
    -
    # Using Newton's method
    -from random import random, seed
    -import numpy as np
    -import autograd.numpy as np
    -import matplotlib.pyplot as plt
    -from autograd import grad
    -
    -def CostOLS(beta):
    -    return (1.0/n)*np.sum((y-X @ beta)**2)
    -
    -n = 100
    -x = 2*np.random.rand(n,1)
    -y = 4+3*x+np.random.randn(n,1)
    -
    -X = np.c_[np.ones((n,1)), x]
    -XT_X = X.T @ X
    -beta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
    -print("Own inversion")
    -print(beta_linreg)
    -# Hessian matrix
    -H = (2.0/n)* XT_X
    -# Note that here the Hessian does not depend on the parameters beta
    -invH = np.linalg.pinv(H)
    -EigValues, EigVectors = np.linalg.eig(H)
    -print(f"Eigenvalues of Hessian Matrix:{EigValues}")
    -
    -beta = np.random.randn(2,1)
    -Niterations = 5
    -
    -# define the gradient
    -training_gradient = grad(CostOLS)
    -
    -for iter in range(Niterations):
    -    gradients = training_gradient(beta)
    -    beta -= invH @ gradients
    -    print(iter,gradients[0],gradients[1])
    -print("beta from own Newton code")
    -print(beta)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -









    Including Stochastic Gradient Descent with Autograd

    In this code we include the stochastic gradient descent approach discussed above. Note here that we specify which argument we are taking the derivative with respect to when using autograd.

    @@ -2020,6 +2039,7 @@ delta = 1e-7
    +
    © 1999-2025, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license diff --git a/doc/pub/week37/html/week37.html b/doc/pub/week37/html/week37.html index 3187de778..73e5119f6 100644 --- a/doc/pub/week37/html/week37.html +++ b/doc/pub/week37/html/week37.html @@ -186,11 +186,14 @@ div.toc p,a { 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ('Overview video on Stochastic Gradient Descent', + ('Overview video on Stochastic Gradient Descent (SGD)', 2, None, - 'overview-video-on-stochastic-gradient-descent'), + 'overview-video-on-stochastic-gradient-descent-sgd'), ('Batches and mini-batches', 2, None, 'batches-and-mini-batches'), + ('Pros and cons', 2, None, 'pros-and-cons'), + ('Convergence rates', 2, None, 'convergence-rates'), + ('Accuracy', 2, None, 'accuracy'), ('Stochastic Gradient Descent (SGD)', 2, None, @@ -233,19 +236,30 @@ div.toc p,a { 2, None, 'algorithms-and-codes-for-adagrad-rmsprop-and-adam'), - ('Practical tips', 2, None, 'practical-tips'), - ('Sneaking in automatic differentiation using Autograd', + ('AdaGrad algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', 2, None, - 'sneaking-in-automatic-differentiation-using-autograd'), + 'adagrad-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('RMSProp algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'rmsprop-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('ADAM algorithm, taken from "Goodfellow et ' + 'al":"https://www.deeplearningbook.org/contents/optimization.html"', + 2, + None, + 'adam-algorithm-taken-from-goodfellow-et-al-https-www-deeplearningbook-org-contents-optimization-html'), + ('Practical tips', 2, None, 'practical-tips'), + ('Sneaking in auotmatic differentiation using Autograd', + 2, + None, + 'sneaking-in-auotmatic-differentiation-using-autograd'), ('Same code but now with momentum gradient descent', 2, None, 'same-code-but-now-with-momentum-gradient-descent'), - ("But none of these can compete with Newton's method", - 2, - None, - 'but-none-of-these-can-compete-with-newton-s-method'), ('Including Stochastic Gradient Descent with Autograd', 2, None, @@ -335,7 +349,7 @@ MathJax.Hub.Config({

      -
    1. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at https://www.deeplearningbook.org/contents/numerical.html and chapter 8.3-8.5 at URL::https://www.deeplearningbook.org/contents/optimization.html"
    2. +
    3. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at https://www.deeplearningbook.org/contents/numerical.html and chapter 8.3-8.5 at https://www.deeplearningbook.org/contents/optimization.html
    4. Rashcka et al, pages 37-44 and pages 278-283 with focus on linear regression.
    5. Video on gradient descent at https://www.youtube.com/watch?v=sDv4f4s2SB8
    6. Video on Stochastic gradient descent at https://www.youtube.com/watch?v=vMh0zPT0tLI
    7. @@ -830,10 +844,16 @@ pyplot.show()









      -

      Overview video on Stochastic Gradient Descent

      +

      Overview video on Stochastic Gradient Descent (SGD)

      What is Stochastic Gradient Descent +

      There are several reasons for using stochastic gradient descent. Some of these are:

      +
        +
      1. Efficiency: Updates weights more frequently using a single or a small batch of samples, which speeds up convergence.
      2. +
      3. Hopefully avoid Local Minima
      4. +
      5. Memory Usage: Requires less memory compared to computing gradients for the entire dataset.
      6. +










      Batches and mini-batches

      @@ -849,6 +869,45 @@ an entire training set of several millions. This batch is then used to perform a parameter update.

      +









      +

      Pros and cons

      + +
        +
      1. Speed: SGD is faster than gradient descent because it uses only one training example per iteration, whereas gradient descent requires the entire dataset. This speed advantage becomes more significant as the size of the dataset increases.
      2. +
      3. Convergence: Gradient descent has a more predictable convergence behaviour because it uses the average gradient of the entire dataset. In contrast, SGD’s convergence behaviour can be more erratic due to its random sampling of individual training examples.
      4. +
      5. Memory: Gradient descent requires more memory than SGD because it must store the entire dataset for each iteration. SGD only needs to store the current training example, making it more memory-efficient.
      6. +
      +









      +

      Convergence rates

      + +
        +
      1. Stochastic Gradient Descent has a faster convergence rate due to the use of single training examples in each iteration.
      2. +
      3. Gradient Descent as a slower convergence rate, as it uses the entire dataset for each iteration.
      4. +
      +









      +

      Accuracy

      + +

      In general, stochastic Gradient Descent is Less accurate than gradient +descent, as it calculates the gradient on single examples, which may +not accurately represent the overall dataset. Gradient Descent is +more accurate because it uses the average gradient calculated over the +entire dataset. +

      + +

      There are other disadvantages to using SGD. The main drawback is that +its convergence behaviour can be more erratic due to the random +sampling of individual training examples. This can lead to less +accurate results, as the algorithm may not converge to the true +minimum of the cost function. Additionally, the learning rate, which +determines the step size of each update to the model’s parameters, +must be carefully chosen to ensure convergence. +

      + +

      It is however the method of choice in deep learning algorithms where +SGD is often used in combination with other optimization techniques, +such as momentum or adaptive learning rates +

      +









      Stochastic Gradient Descent (SGD)

      @@ -1302,7 +1361,9 @@ $$ \end{align} $$ -

      One of the major advantages of NAG is that it allows for the use of a larger learning rate than GDM for the same choice of \( \gamma \).

      +

      One of the major advantages of NAG is that it allows for the use of a +larger learning rate than GDM for the same choice of \( \gamma \). +











      Second moment of the gradient

      @@ -1324,7 +1385,7 @@ the steep computational price of calculating or approximating Hessians.

      -

      Recently, a number of methods have been introduced that accomplish +

      During the last decade a number of methods have been introduced that accomplish this by tracking not only the gradient, but also the second moment of the gradient. These methods include AdaGrad, AdaDelta, Root Mean Squared Propagation (RMS-Prop), and ADAM. @@ -1419,7 +1480,28 @@ $$

      The algorithms we have implemented are well described in the text by Goodfellow, Bengio and Courville, chapter 8.

      -

      The codes which implement these algorithms are discussed below here.

      +

      The codes which implement these algorithms are discussed after our presentation of automatic differentiation.

      +

      AdaGrad algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +

      +

      RMSProp algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +

      +

      ADAM algorithm, taken from Goodfellow et al

      + +

      +
      +

      +
      +











      Practical tips

      @@ -1431,10 +1513,11 @@ $$
    8. Adaptive optimization methods don't always have good generalization. Recent studies have shown that adaptive methods such as ADAM, RMSPorp, and AdaGrad tend to have poor generalization compared to SGD or SGD with momentum, particularly in the high-dimensional limit (i.e. the number of parameters exceeds the number of data points). Although it is not clear at this stage why these methods perform so well in training deep neural networks, simpler procedures like properly-tuned SGD may work as well or better in these applications.










    9. -

      Sneaking in automatic differentiation using Autograd

      +

      Sneaking in auotmatic differentiation using Autograd

      -

      We anticipate our discussions to come in connection with neural networks and automatic differentiation -by showing how we can use autograd for the cases above. Later we will replace autograd with JAX. +

      We conclude the part on optmization by showing how we can make codes +for linear regression and logistic regression using autograd. The +first example shows results with ordinary leats squares.

      @@ -1587,70 +1670,6 @@ delta_momentum = But none of these can compete with Newton's method - - - -
      -
      -
      -
      -
      -
      # Using Newton's method
      -from random import random, seed
      -import numpy as np
      -import autograd.numpy as np
      -import matplotlib.pyplot as plt
      -from autograd import grad
      -
      -def CostOLS(beta):
      -    return (1.0/n)*np.sum((y-X @ beta)**2)
      -
      -n = 100
      -x = 2*np.random.rand(n,1)
      -y = 4+3*x+np.random.randn(n,1)
      -
      -X = np.c_[np.ones((n,1)), x]
      -XT_X = X.T @ X
      -beta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)
      -print("Own inversion")
      -print(beta_linreg)
      -# Hessian matrix
      -H = (2.0/n)* XT_X
      -# Note that here the Hessian does not depend on the parameters beta
      -invH = np.linalg.pinv(H)
      -EigValues, EigVectors = np.linalg.eig(H)
      -print(f"Eigenvalues of Hessian Matrix:{EigValues}")
      -
      -beta = np.random.randn(2,1)
      -Niterations = 5
      -
      -# define the gradient
      -training_gradient = grad(CostOLS)
      -
      -for iter in range(Niterations):
      -    gradients = training_gradient(beta)
      -    beta -= invH @ gradients
      -    print(iter,gradients[0],gradients[1])
      -print("beta from own Newton code")
      -print(beta)
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      -
      - -









      Including Stochastic Gradient Descent with Autograd

      In this code we include the stochastic gradient descent approach discussed above. Note here that we specify which argument we are taking the derivative with respect to when using autograd.

      @@ -2097,6 +2116,7 @@ delta = 1e-7
    +
    © 1999-2025, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license diff --git a/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz b/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz index 3a4cefdc6..9dcd12eef 100644 Binary files a/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz and b/doc/pub/week37/ipynb/ipynb-week37-src.tar.gz differ diff --git a/doc/pub/week37/ipynb/week37.ipynb b/doc/pub/week37/ipynb/week37.ipynb index c40ec2419..386e755d2 100644 --- a/doc/pub/week37/ipynb/week37.ipynb +++ b/doc/pub/week37/ipynb/week37.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "ebae0536", + "id": "26195c6c", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "c87edf63", + "id": "2f3d0562", "metadata": { "editable": true }, @@ -29,7 +29,7 @@ }, { "cell_type": "markdown", - "id": "9b6436c9", + "id": "3a04c093", "metadata": { "editable": true }, @@ -52,13 +52,13 @@ }, { "cell_type": "markdown", - "id": "01055296", + "id": "71cbeb43", "metadata": { "editable": true }, "source": [ "## Readings and Videos:\n", - "1. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at and chapter 8.3-8.5 at URL::https://www.deeplearningbook.org/contents/optimization.html\"\n", + "1. Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at and chapter 8.3-8.5 at \n", "\n", "2. Rashcka et al, pages 37-44 and pages 278-283 with focus on linear regression.\n", "\n", @@ -69,7 +69,7 @@ }, { "cell_type": "markdown", - "id": "5b4c3f44", + "id": "eaa820fc", "metadata": { "editable": true }, @@ -79,7 +79,7 @@ }, { "cell_type": "markdown", - "id": "23544472", + "id": "ff06566a", "metadata": { "editable": true }, @@ -103,7 +103,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "d74adaf2", + "id": "059f5649", "metadata": { "collapsed": false, "editable": true @@ -116,7 +116,7 @@ }, { "cell_type": "markdown", - "id": "fa36c64d", + "id": "3cdf34a5", "metadata": { "editable": true }, @@ -127,7 +127,7 @@ }, { "cell_type": "markdown", - "id": "571c791d", + "id": "d66f2b53", "metadata": { "editable": true }, @@ -139,7 +139,7 @@ }, { "cell_type": "markdown", - "id": "12d3e9eb", + "id": "e0c22d3d", "metadata": { "editable": true }, @@ -149,7 +149,7 @@ }, { "cell_type": "markdown", - "id": "17610490", + "id": "8cb6c439", "metadata": { "editable": true }, @@ -161,7 +161,7 @@ }, { "cell_type": "markdown", - "id": "47fefa69", + "id": "45ba3ffb", "metadata": { "editable": true }, @@ -175,7 +175,7 @@ }, { "cell_type": "markdown", - "id": "52eb2d30", + "id": "9a8ffab0", "metadata": { "editable": true }, @@ -191,7 +191,7 @@ }, { "cell_type": "markdown", - "id": "7d89f32b", + "id": "9bb32152", "metadata": { "editable": true }, @@ -201,7 +201,7 @@ }, { "cell_type": "markdown", - "id": "5b0fb490", + "id": "7d386532", "metadata": { "editable": true }, @@ -213,7 +213,7 @@ }, { "cell_type": "markdown", - "id": "891f388a", + "id": "3eaf521e", "metadata": { "editable": true }, @@ -223,7 +223,7 @@ }, { "cell_type": "markdown", - "id": "d05ffb4b", + "id": "8e6191e9", "metadata": { "editable": true }, @@ -235,7 +235,7 @@ }, { "cell_type": "markdown", - "id": "f59689ea", + "id": "ac7e5a33", "metadata": { "editable": true }, @@ -249,7 +249,7 @@ }, { "cell_type": "markdown", - "id": "9a119fe4", + "id": "f5d64e82", "metadata": { "editable": true }, @@ -259,7 +259,7 @@ }, { "cell_type": "markdown", - "id": "ef5c109f", + "id": "65cef2b1", "metadata": { "editable": true }, @@ -270,7 +270,7 @@ }, { "cell_type": "markdown", - "id": "5412ed07", + "id": "dd1c97dd", "metadata": { "editable": true }, @@ -285,7 +285,7 @@ }, { "cell_type": "markdown", - "id": "33c5d9c9", + "id": "4771d71e", "metadata": { "editable": true }, @@ -295,7 +295,7 @@ }, { "cell_type": "markdown", - "id": "a8cf7d20", + "id": "8140a000", "metadata": { "editable": true }, @@ -307,7 +307,7 @@ }, { "cell_type": "markdown", - "id": "40f0daf3", + "id": "16bbcf2f", "metadata": { "editable": true }, @@ -319,7 +319,7 @@ }, { "cell_type": "markdown", - "id": "b09c9d54", + "id": "f2b8a434", "metadata": { "editable": true }, @@ -334,7 +334,7 @@ }, { "cell_type": "markdown", - "id": "081f1192", + "id": "4515d126", "metadata": { "editable": true }, @@ -347,7 +347,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "5842a0a2", + "id": "0fbb2309", "metadata": { "collapsed": false, "editable": true @@ -406,7 +406,7 @@ }, { "cell_type": "markdown", - "id": "923874ba", + "id": "9e083c31", "metadata": { "editable": true }, @@ -418,7 +418,7 @@ }, { "cell_type": "markdown", - "id": "442c5abb", + "id": "10a41983", "metadata": { "editable": true }, @@ -430,7 +430,7 @@ }, { "cell_type": "markdown", - "id": "743e05ca", + "id": "9e612405", "metadata": { "editable": true }, @@ -440,7 +440,7 @@ }, { "cell_type": "markdown", - "id": "27dfced9", + "id": "618d8dd0", "metadata": { "editable": true }, @@ -454,7 +454,7 @@ }, { "cell_type": "markdown", - "id": "3ff66697", + "id": "d0c88404", "metadata": { "editable": true }, @@ -464,7 +464,7 @@ }, { "cell_type": "markdown", - "id": "f63f80f9", + "id": "96f35638", "metadata": { "editable": true }, @@ -476,7 +476,7 @@ }, { "cell_type": "markdown", - "id": "dc6a4fff", + "id": "99d2a6dd", "metadata": { "editable": true }, @@ -487,7 +487,7 @@ }, { "cell_type": "markdown", - "id": "56a4b43d", + "id": "7f61638e", "metadata": { "editable": true }, @@ -502,7 +502,7 @@ }, { "cell_type": "markdown", - "id": "38c6aab3", + "id": "256e6480", "metadata": { "editable": true }, @@ -516,7 +516,7 @@ }, { "cell_type": "markdown", - "id": "a4f724c3", + "id": "3b9bd1b5", "metadata": { "editable": true }, @@ -527,7 +527,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "ae5d09dc", + "id": "d99082f7", "metadata": { "collapsed": false, "editable": true @@ -588,7 +588,7 @@ }, { "cell_type": "markdown", - "id": "184d283f", + "id": "65bea527", "metadata": { "editable": true }, @@ -610,7 +610,7 @@ }, { "cell_type": "markdown", - "id": "cfb021a5", + "id": "6d7105d1", "metadata": { "editable": true }, @@ -623,7 +623,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "a89ea0e9", + "id": "6b3f6111", "metadata": { "collapsed": false, "editable": true @@ -689,7 +689,7 @@ }, { "cell_type": "markdown", - "id": "4a29024a", + "id": "085e9053", "metadata": { "editable": true }, @@ -700,7 +700,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "9212126a", + "id": "4dc281e1", "metadata": { "collapsed": false, "editable": true @@ -774,19 +774,26 @@ }, { "cell_type": "markdown", - "id": "c12221ee", + "id": "095fdc5b", "metadata": { "editable": true }, "source": [ - "## Overview video on Stochastic Gradient Descent\n", + "## Overview video on Stochastic Gradient Descent (SGD)\n", "\n", - "[What is Stochastic Gradient Descent](https://www.youtube.com/watch?v=vMh0zPT0tLI&ab_channel=StatQuestwithJoshStarmer)" + "[What is Stochastic Gradient Descent](https://www.youtube.com/watch?v=vMh0zPT0tLI&ab_channel=StatQuestwithJoshStarmer)\n", + "There are several reasons for using stochastic gradient descent. Some of these are:\n", + "\n", + "1. Efficiency: Updates weights more frequently using a single or a small batch of samples, which speeds up convergence.\n", + "\n", + "2. Hopefully avoid Local Minima\n", + "\n", + "3. Memory Usage: Requires less memory compared to computing gradients for the entire dataset." ] }, { "cell_type": "markdown", - "id": "89e21421", + "id": "c1acf305", "metadata": { "editable": true }, @@ -807,7 +814,65 @@ }, { "cell_type": "markdown", - "id": "b3d6706b", + "id": "bb9ccd97", + "metadata": { + "editable": true + }, + "source": [ + "## Pros and cons\n", + "\n", + "1. Speed: SGD is faster than gradient descent because it uses only one training example per iteration, whereas gradient descent requires the entire dataset. This speed advantage becomes more significant as the size of the dataset increases.\n", + "\n", + "2. Convergence: Gradient descent has a more predictable convergence behaviour because it uses the average gradient of the entire dataset. In contrast, SGD’s convergence behaviour can be more erratic due to its random sampling of individual training examples.\n", + "\n", + "3. Memory: Gradient descent requires more memory than SGD because it must store the entire dataset for each iteration. SGD only needs to store the current training example, making it more memory-efficient." + ] + }, + { + "cell_type": "markdown", + "id": "f5aaa59d", + "metadata": { + "editable": true + }, + "source": [ + "## Convergence rates\n", + "\n", + "1. Stochastic Gradient Descent has a faster convergence rate due to the use of single training examples in each iteration.\n", + "\n", + "2. Gradient Descent as a slower convergence rate, as it uses the entire dataset for each iteration." + ] + }, + { + "cell_type": "markdown", + "id": "b6e06eb4", + "metadata": { + "editable": true + }, + "source": [ + "## Accuracy\n", + "\n", + "In general, stochastic Gradient Descent is Less accurate than gradient\n", + "descent, as it calculates the gradient on single examples, which may\n", + "not accurately represent the overall dataset. Gradient Descent is\n", + "more accurate because it uses the average gradient calculated over the\n", + "entire dataset.\n", + "\n", + "There are other disadvantages to using SGD. The main drawback is that\n", + "its convergence behaviour can be more erratic due to the random\n", + "sampling of individual training examples. This can lead to less\n", + "accurate results, as the algorithm may not converge to the true\n", + "minimum of the cost function. Additionally, the learning rate, which\n", + "determines the step size of each update to the model’s parameters,\n", + "must be carefully chosen to ensure convergence.\n", + "\n", + "It is however the method of choice in deep learning algorithms where\n", + "SGD is often used in combination with other optimization techniques,\n", + "such as momentum or adaptive learning rates" + ] + }, + { + "cell_type": "markdown", + "id": "e6de9732", "metadata": { "editable": true }, @@ -839,7 +904,7 @@ }, { "cell_type": "markdown", - "id": "f2900e4e", + "id": "5d6f2336", "metadata": { "editable": true }, @@ -856,7 +921,7 @@ }, { "cell_type": "markdown", - "id": "b6745dec", + "id": "9c24946f", "metadata": { "editable": true }, @@ -869,7 +934,7 @@ }, { "cell_type": "markdown", - "id": "b6f524f1", + "id": "15ae46aa", "metadata": { "editable": true }, @@ -882,7 +947,7 @@ }, { "cell_type": "markdown", - "id": "db7c028a", + "id": "eba44d5b", "metadata": { "editable": true }, @@ -895,7 +960,7 @@ }, { "cell_type": "markdown", - "id": "813b7f85", + "id": "fa5a0e9f", "metadata": { "editable": true }, @@ -909,7 +974,7 @@ }, { "cell_type": "markdown", - "id": "a562fa9a", + "id": "86e67dff", "metadata": { "editable": true }, @@ -931,7 +996,7 @@ }, { "cell_type": "markdown", - "id": "75d84b18", + "id": "1ffda2a5", "metadata": { "editable": true }, @@ -946,7 +1011,7 @@ }, { "cell_type": "markdown", - "id": "0cf6f343", + "id": "dd9589cf", "metadata": { "editable": true }, @@ -958,7 +1023,7 @@ }, { "cell_type": "markdown", - "id": "44f85de2", + "id": "bccd17a0", "metadata": { "editable": true }, @@ -971,7 +1036,7 @@ }, { "cell_type": "markdown", - "id": "92851949", + "id": "fa4254bc", "metadata": { "editable": true }, @@ -985,7 +1050,7 @@ }, { "cell_type": "markdown", - "id": "21d2691e", + "id": "d6134b3d", "metadata": { "editable": true }, @@ -996,7 +1061,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "6536b711", + "id": "46bbb72f", "metadata": { "collapsed": false, "editable": true @@ -1021,7 +1086,7 @@ }, { "cell_type": "markdown", - "id": "4005ce6c", + "id": "f354fc55", "metadata": { "editable": true }, @@ -1037,7 +1102,7 @@ }, { "cell_type": "markdown", - "id": "adec9808", + "id": "3ff93d52", "metadata": { "editable": true }, @@ -1058,7 +1123,7 @@ }, { "cell_type": "markdown", - "id": "deecc226", + "id": "3010708d", "metadata": { "editable": true }, @@ -1078,7 +1143,7 @@ }, { "cell_type": "markdown", - "id": "73685769", + "id": "0052d791", "metadata": { "editable": true }, @@ -1097,7 +1162,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "6484bffa", + "id": "aaa345b9", "metadata": { "collapsed": false, "editable": true @@ -1132,7 +1197,7 @@ }, { "cell_type": "markdown", - "id": "2438f642", + "id": "851c6b4d", "metadata": { "editable": true }, @@ -1145,7 +1210,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "8d624cf1", + "id": "664d6772", "metadata": { "collapsed": false, "editable": true @@ -1222,7 +1287,7 @@ }, { "cell_type": "markdown", - "id": "6e9eb916", + "id": "6905c3ba", "metadata": { "editable": true }, @@ -1237,7 +1302,7 @@ }, { "cell_type": "markdown", - "id": "c60a0137", + "id": "6f7347c9", "metadata": { "editable": true }, @@ -1252,7 +1317,7 @@ }, { "cell_type": "markdown", - "id": "2d8174d4", + "id": "7a8fac99", "metadata": { "editable": true }, @@ -1264,7 +1329,7 @@ }, { "cell_type": "markdown", - "id": "afc41240", + "id": "61c534ef", "metadata": { "editable": true }, @@ -1282,7 +1347,7 @@ }, { "cell_type": "markdown", - "id": "e3c96a9f", + "id": "cbe325b2", "metadata": { "editable": true }, @@ -1301,7 +1366,7 @@ }, { "cell_type": "markdown", - "id": "74e0e345", + "id": "18c4f71f", "metadata": { "editable": true }, @@ -1313,7 +1378,7 @@ }, { "cell_type": "markdown", - "id": "288fcc66", + "id": "b84f0488", "metadata": { "editable": true }, @@ -1323,7 +1388,7 @@ }, { "cell_type": "markdown", - "id": "63b49aca", + "id": "c5772ef7", "metadata": { "editable": true }, @@ -1339,7 +1404,7 @@ }, { "cell_type": "markdown", - "id": "94b37496", + "id": "c86bbefb", "metadata": { "editable": true }, @@ -1351,7 +1416,7 @@ }, { "cell_type": "markdown", - "id": "3a439485", + "id": "88aea644", "metadata": { "editable": true }, @@ -1361,7 +1426,7 @@ }, { "cell_type": "markdown", - "id": "ff92e318", + "id": "8d0f09dd", "metadata": { "editable": true }, @@ -1373,7 +1438,7 @@ }, { "cell_type": "markdown", - "id": "142e0f95", + "id": "3c0f263a", "metadata": { "editable": true }, @@ -1383,7 +1448,7 @@ }, { "cell_type": "markdown", - "id": "88d4ce9a", + "id": "e022e30b", "metadata": { "editable": true }, @@ -1395,7 +1460,7 @@ }, { "cell_type": "markdown", - "id": "5c662618", + "id": "e29f7ed3", "metadata": { "editable": true }, @@ -1411,7 +1476,7 @@ }, { "cell_type": "markdown", - "id": "2c4a2172", + "id": "745ac9fb", "metadata": { "editable": true }, @@ -1423,7 +1488,7 @@ }, { "cell_type": "markdown", - "id": "630c69f8", + "id": "e7608c5b", "metadata": { "editable": true }, @@ -1456,7 +1521,7 @@ }, { "cell_type": "markdown", - "id": "7fc49052", + "id": "3af69259", "metadata": { "editable": true }, @@ -1468,7 +1533,7 @@ }, { "cell_type": "markdown", - "id": "800856ba", + "id": "fe7f114b", "metadata": { "editable": true }, @@ -1486,17 +1551,18 @@ }, { "cell_type": "markdown", - "id": "154d4907", + "id": "aac7d523", "metadata": { "editable": true }, "source": [ - "One of the major advantages of NAG is that it allows for the use of a larger learning rate than GDM for the same choice of $\\gamma$." + "One of the major advantages of NAG is that it allows for the use of a\n", + "larger learning rate than GDM for the same choice of $\\gamma$." ] }, { "cell_type": "markdown", - "id": "17557243", + "id": "0f6129f0", "metadata": { "editable": true }, @@ -1519,7 +1585,7 @@ "the steep computational price of calculating or approximating\n", "Hessians.\n", "\n", - "Recently, a number of methods have been introduced that accomplish\n", + "During the last decade a number of methods have been introduced that accomplish\n", "this by tracking not only the gradient, but also the second moment of\n", "the gradient. These methods include AdaGrad, AdaDelta, Root Mean Squared Propagation (RMS-Prop), and\n", "[ADAM](https://arxiv.org/abs/1412.6980)." @@ -1527,7 +1593,7 @@ }, { "cell_type": "markdown", - "id": "f3d09840", + "id": "4ee6d23c", "metadata": { "editable": true }, @@ -1542,7 +1608,7 @@ }, { "cell_type": "markdown", - "id": "175455a1", + "id": "410f1144", "metadata": { "editable": true }, @@ -1560,7 +1626,7 @@ }, { "cell_type": "markdown", - "id": "cf1e9538", + "id": "b3336df7", "metadata": { "editable": true }, @@ -1572,7 +1638,7 @@ }, { "cell_type": "markdown", - "id": "da9b6589", + "id": "a50a2257", "metadata": { "editable": true }, @@ -1584,7 +1650,7 @@ }, { "cell_type": "markdown", - "id": "cbc7a25f", + "id": "1fb1ab6a", "metadata": { "editable": true }, @@ -1602,7 +1668,7 @@ }, { "cell_type": "markdown", - "id": "e8064f4a", + "id": "9e04c2f8", "metadata": { "editable": true }, @@ -1631,7 +1697,7 @@ }, { "cell_type": "markdown", - "id": "12912817", + "id": "9450e0f8", "metadata": { "editable": true }, @@ -1649,7 +1715,7 @@ }, { "cell_type": "markdown", - "id": "7864ca89", + "id": "0ec4afd8", "metadata": { "editable": true }, @@ -1661,7 +1727,7 @@ }, { "cell_type": "markdown", - "id": "02a5d4ef", + "id": "7d09f8b8", "metadata": { "editable": true }, @@ -1673,7 +1739,7 @@ }, { "cell_type": "markdown", - "id": "327a1f34", + "id": "219826a3", "metadata": { "editable": true }, @@ -1685,7 +1751,7 @@ }, { "cell_type": "markdown", - "id": "c5ac526b", + "id": "d3f0e5c5", "metadata": { "editable": true }, @@ -1697,7 +1763,7 @@ }, { "cell_type": "markdown", - "id": "e6a33564", + "id": "46fcf54e", "metadata": { "editable": true }, @@ -1709,7 +1775,7 @@ }, { "cell_type": "markdown", - "id": "4ffe0088", + "id": "9f3f1e9c", "metadata": { "editable": true }, @@ -1726,7 +1792,7 @@ }, { "cell_type": "markdown", - "id": "34eb03fb", + "id": "e4d859d2", "metadata": { "editable": true }, @@ -1745,7 +1811,7 @@ }, { "cell_type": "markdown", - "id": "18f62c05", + "id": "d9fb412a", "metadata": { "editable": true }, @@ -1757,7 +1823,7 @@ }, { "cell_type": "markdown", - "id": "5539d5a5", + "id": "a4ed4fe4", "metadata": { "editable": true }, @@ -1766,12 +1832,60 @@ "\n", "The algorithms we have implemented are well described in the text by [Goodfellow, Bengio and Courville, chapter 8](https://www.deeplearningbook.org/contents/optimization.html).\n", "\n", - "The codes which implement these algorithms are discussed below here." + "The codes which implement these algorithms are discussed after our presentation of automatic differentiation." ] }, { "cell_type": "markdown", - "id": "ae04cfe0", + "id": "c8b687aa", + "metadata": { + "editable": true + }, + "source": [ + "## AdaGrad algorithm, taken from [Goodfellow et al](https://www.deeplearningbook.org/contents/optimization.html)\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "d42508aa", + "metadata": { + "editable": true + }, + "source": [ + "## RMSProp algorithm, taken from [Goodfellow et al](https://www.deeplearningbook.org/contents/optimization.html)\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "54d1c89f", + "metadata": { + "editable": true + }, + "source": [ + "## ADAM algorithm, taken from [Goodfellow et al](https://www.deeplearningbook.org/contents/optimization.html)\n", + "\n", + "\n", + "\n", + "\n", + "

    Figure 1:

    \n", + "" + ] + }, + { + "cell_type": "markdown", + "id": "90c96a47", "metadata": { "editable": true }, @@ -1789,21 +1903,22 @@ }, { "cell_type": "markdown", - "id": "3ffaaf9a", + "id": "79eb9b5f", "metadata": { "editable": true }, "source": [ - "## Sneaking in automatic differentiation using Autograd\n", + "## Sneaking in auotmatic differentiation using Autograd\n", "\n", - "We anticipate our discussions to come in connection with neural networks and automatic differentiation\n", - "by showing how we can use **autograd** for the cases above. Later we will replace **autograd** with **JAX**." + "We conclude the part on optmization by showing how we can make codes\n", + "for linear regression and logistic regression using **autograd**. The\n", + "first example shows results with ordinary leats squares." ] }, { "cell_type": "code", "execution_count": 9, - "id": "51503c7d", + "id": "8749e605", "metadata": { "collapsed": false, "editable": true @@ -1863,7 +1978,7 @@ }, { "cell_type": "markdown", - "id": "67d85da7", + "id": "4f7cb53b", "metadata": { "editable": true }, @@ -1874,7 +1989,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "586da287", + "id": "2ca61a91", "metadata": { "collapsed": false, "editable": true @@ -1938,67 +2053,7 @@ }, { "cell_type": "markdown", - "id": "b0d53639", - "metadata": { - "editable": true - }, - "source": [ - "## But none of these can compete with Newton's method" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "81089279", - "metadata": { - "collapsed": false, - "editable": true - }, - "outputs": [], - "source": [ - "# Using Newton's method\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", - "def CostOLS(beta):\n", - " return (1.0/n)*np.sum((y-X @ beta)**2)\n", - "\n", - "n = 100\n", - "x = 2*np.random.rand(n,1)\n", - "y = 4+3*x+np.random.randn(n,1)\n", - "\n", - "X = np.c_[np.ones((n,1)), x]\n", - "XT_X = X.T @ X\n", - "beta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y)\n", - "print(\"Own inversion\")\n", - "print(beta_linreg)\n", - "# Hessian matrix\n", - "H = (2.0/n)* XT_X\n", - "# Note that here the Hessian does not depend on the parameters beta\n", - "invH = np.linalg.pinv(H)\n", - "EigValues, EigVectors = np.linalg.eig(H)\n", - "print(f\"Eigenvalues of Hessian Matrix:{EigValues}\")\n", - "\n", - "beta = np.random.randn(2,1)\n", - "Niterations = 5\n", - "\n", - "# define the gradient\n", - "training_gradient = grad(CostOLS)\n", - "\n", - "for iter in range(Niterations):\n", - " gradients = training_gradient(beta)\n", - " beta -= invH @ gradients\n", - " print(iter,gradients[0],gradients[1])\n", - "print(\"beta from own Newton code\")\n", - "print(beta)" - ] - }, - { - "cell_type": "markdown", - "id": "e302b6c8", + "id": "5ab2acb5", "metadata": { "editable": true }, @@ -2009,8 +2064,8 @@ }, { "cell_type": "code", - "execution_count": 12, - "id": "88efb71c", + "execution_count": 11, + "id": "47c2c7fd", "metadata": { "collapsed": false, "editable": true @@ -2094,7 +2149,7 @@ }, { "cell_type": "markdown", - "id": "a3e14887", + "id": "fd8262d3", "metadata": { "editable": true }, @@ -2104,8 +2159,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "id": "607e3bc9", + "execution_count": 12, + "id": "38b4d9b4", "metadata": { "collapsed": false, "editable": true @@ -2183,7 +2238,7 @@ }, { "cell_type": "markdown", - "id": "d96e1c2c", + "id": "5aa8d23f", "metadata": { "editable": true }, @@ -2193,8 +2248,8 @@ }, { "cell_type": "code", - "execution_count": 14, - "id": "6cbe854b", + "execution_count": 13, + "id": "ad237e29", "metadata": { "collapsed": false, "editable": true @@ -2253,7 +2308,7 @@ }, { "cell_type": "markdown", - "id": "0ed15b7b", + "id": "d7b69389", "metadata": { "editable": true }, @@ -2263,7 +2318,7 @@ }, { "cell_type": "markdown", - "id": "d97ab879", + "id": "b3d0a76d", "metadata": { "editable": true }, @@ -2273,8 +2328,8 @@ }, { "cell_type": "code", - "execution_count": 15, - "id": "c58a19a2", + "execution_count": 14, + "id": "62e76ebb", "metadata": { "collapsed": false, "editable": true @@ -2339,7 +2394,7 @@ }, { "cell_type": "markdown", - "id": "d7106089", + "id": "296f1151", "metadata": { "editable": true }, @@ -2349,8 +2404,8 @@ }, { "cell_type": "code", - "execution_count": 16, - "id": "d3b9cdb9", + "execution_count": 15, + "id": "004c5081", "metadata": { "collapsed": false, "editable": true @@ -2420,7 +2475,7 @@ }, { "cell_type": "markdown", - "id": "e6a7abff", + "id": "d51c3400", "metadata": { "editable": true }, diff --git a/doc/src/week37/week37.do.txt b/doc/src/week37/week37.do.txt index fc160fb0e..20b5caa14 100644 --- a/doc/src/week37/week37.do.txt +++ b/doc/src/week37/week37.do.txt @@ -21,7 +21,7 @@ o More advanced updates of the learning rate: ADAgrad, RMSprop and ADAM !split ===== Readings and Videos: ===== !bblock -o Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at URL:"https://www.deeplearningbook.org/contents/numerical.html" and chapter 8.3-8.5 at URL::https://www.deeplearningbook.org/contents/optimization.html" +o Recommended: Goodfellow et al, Deep Learning, introduction to gradient descent, see sections 4.3-4.5 at URL:"https://www.deeplearningbook.org/contents/numerical.html" and chapter 8.3-8.5 at URL:"https://www.deeplearningbook.org/contents/optimization.html" o Rashcka et al, pages 37-44 and pages 278-283 with focus on linear regression. o Video on gradient descent at URL:"https://www.youtube.com/watch?v=sDv4f4s2SB8" o Video on Stochastic gradient descent at URL:"https://www.youtube.com/watch?v=vMh0zPT0tLI" @@ -452,13 +452,15 @@ pyplot.plot(solutions, scores, '.-', color='red') pyplot.show() !ec - - !split -===== Overview video on Stochastic Gradient Descent ===== +===== Overview video on Stochastic Gradient Descent (SGD) ===== "What is Stochastic Gradient Descent":"https://www.youtube.com/watch?v=vMh0zPT0tLI&ab_channel=StatQuestwithJoshStarmer" +There are several reasons for using stochastic gradient descent. Some of these are: +o Efficiency: Updates weights more frequently using a single or a small batch of samples, which speeds up convergence. +o Hopefully avoid Local Minima +o Memory Usage: Requires less memory compared to computing gradients for the entire dataset. !split ===== Batches and mini-batches ===== @@ -474,6 +476,44 @@ gradient over batches of the training data. For example, a typical batch could c an entire training set of several millions. This batch is then used to perform a parameter update. + +!split +===== Pros and cons ===== + + +o Speed: SGD is faster than gradient descent because it uses only one training example per iteration, whereas gradient descent requires the entire dataset. This speed advantage becomes more significant as the size of the dataset increases. +o Convergence: Gradient descent has a more predictable convergence behaviour because it uses the average gradient of the entire dataset. In contrast, SGD’s convergence behaviour can be more erratic due to its random sampling of individual training examples. +o Memory: Gradient descent requires more memory than SGD because it must store the entire dataset for each iteration. SGD only needs to store the current training example, making it more memory-efficient. + + +!split +===== Convergence rates ===== + +o Stochastic Gradient Descent has a faster convergence rate due to the use of single training examples in each iteration. +o Gradient Descent as a slower convergence rate, as it uses the entire dataset for each iteration. + +!split +===== Accuracy ===== + +In general, stochastic Gradient Descent is Less accurate than gradient +descent, as it calculates the gradient on single examples, which may +not accurately represent the overall dataset. Gradient Descent is +more accurate because it uses the average gradient calculated over the +entire dataset. + + +There are other disadvantages to using SGD. The main drawback is that +its convergence behaviour can be more erratic due to the random +sampling of individual training examples. This can lead to less +accurate results, as the algorithm may not converge to the true +minimum of the cost function. Additionally, the learning rate, which +determines the step size of each update to the model’s parameters, +must be carefully chosen to ensure convergence. + +It is however the method of choice in deep learning algorithms where +SGD is often used in combination with other optimization techniques, +such as momentum or adaptive learning rates + !split ===== Stochastic Gradient Descent (SGD) ===== @@ -670,10 +710,6 @@ print("gamma_j after %d epochs: %g" % (n_epochs,gamma_j)) !ec - - - - !split ===== Code with a Number of Minibatches which varies ===== @@ -870,8 +906,8 @@ our current momentum, $\nabla_\theta E(\boldsymbol{\theta}_t +\gamma \end{align} !et -One of the major advantages of NAG is that it allows for the use of a larger learning rate than GDM for the same choice of $\gamma$. - +One of the major advantages of NAG is that it allows for the use of a +larger learning rate than GDM for the same choice of $\gamma$. !split ===== Second moment of the gradient ===== @@ -893,7 +929,7 @@ adaptively change the step size to match the landscape without paying the steep computational price of calculating or approximating Hessians. -Recently, a number of methods have been introduced that accomplish +During the last decade a number of methods have been introduced that accomplish this by tracking not only the gradient, but also the second moment of the gradient. These methods include AdaGrad, AdaDelta, Root Mean Squared Propagation (RMS-Prop), and "ADAM":"https://arxiv.org/abs/1412.6980". @@ -980,7 +1016,26 @@ update rule for this parameter is given by The algorithms we have implemented are well described in the text by "Goodfellow, Bengio and Courville, chapter 8":"https://www.deeplearningbook.org/contents/optimization.html". -The codes which implement these algorithms are discussed below here. +The codes which implement these algorithms are discussed after our presentation of automatic differentiation. + + +===== AdaGrad algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html" ===== + +FIGURE: [figures/adagrad.png, width=600 frac=0.8] + + +===== RMSProp algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html" ===== + +FIGURE: [figures/rmsprop.png, width=600 frac=0.8] + + + +===== ADAM algorithm, taken from "Goodfellow et al":"https://www.deeplearningbook.org/contents/optimization.html" ===== + +FIGURE: [figures/adam.png, width=600 frac=0.8] + + + !split @@ -995,15 +1050,12 @@ The codes which implement these algorithms are discussed below here. * _Adaptive optimization methods don't always have good generalization._ Recent studies have shown that adaptive methods such as ADAM, RMSPorp, and AdaGrad tend to have poor generalization compared to SGD or SGD with momentum, particularly in the high-dimensional limit (i.e. the number of parameters exceeds the number of data points). Although it is not clear at this stage why these methods perform so well in training deep neural networks, simpler procedures like properly-tuned SGD may work as well or better in these applications. - - - !split -===== Sneaking in automatic differentiation using Autograd ===== - -We anticipate our discussions to come in connection with neural networks and automatic differentiation -by showing how we can use _autograd_ for the cases above. Later we will replace _autograd_ with _JAX_. +===== Sneaking in auotmatic differentiation using Autograd ===== +We conclude the part on optmization by showing how we can make codes +for linear regression and logistic regression using _autograd_. The +first example shows results with ordinary leats squares. !bc pycod # Using Autograd to calculate gradients for OLS @@ -1118,51 +1170,6 @@ print(theta) !ec -!split -===== But none of these can compete with Newton's method ===== - -!bc pycod -# Using Newton's method -from random import random, seed -import numpy as np -import autograd.numpy as np -import matplotlib.pyplot as plt -from autograd import grad - -def CostOLS(beta): - return (1.0/n)*np.sum((y-X @ beta)**2) - -n = 100 -x = 2*np.random.rand(n,1) -y = 4+3*x+np.random.randn(n,1) - -X = np.c_[np.ones((n,1)), x] -XT_X = X.T @ X -beta_linreg = np.linalg.pinv(XT_X) @ (X.T @ y) -print("Own inversion") -print(beta_linreg) -# Hessian matrix -H = (2.0/n)* XT_X -# Note that here the Hessian does not depend on the parameters beta -invH = np.linalg.pinv(H) -EigValues, EigVectors = np.linalg.eig(H) -print(f"Eigenvalues of Hessian Matrix:{EigValues}") - -beta = np.random.randn(2,1) -Niterations = 5 - -# define the gradient -training_gradient = grad(CostOLS) - -for iter in range(Niterations): - gradients = training_gradient(beta) - beta -= invH @ gradients - print(iter,gradients[0],gradients[1]) -print("beta from own Newton code") -print(beta) -!ec - - !split ===== Including Stochastic Gradient Descent with Autograd ===== In this code we include the stochastic gradient descent approach discussed above. Note here that we specify which argument we are taking the derivative with respect to when using _autograd_. @@ -1512,3 +1519,11 @@ o Work on project 1 # * "Video of exercise sessions week 37":"https://youtu.be/bK4AEcTu-oM" * For more discussions of Ridge regression and calculation of averages, "Wessel van Wieringen's":"https://arxiv.org/abs/1509.09169" article is highly recommended. !eblock + + + + + + + +