diff --git a/doc/pub/Regression/html/._Regression-bs000.html b/doc/pub/Regression/html/._Regression-bs000.html index cc3f0021f..4a67b29fe 100644 --- a/doc/pub/Regression/html/._Regression-bs000.html +++ b/doc/pub/Regression/html/._Regression-bs000.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -169,7 +191,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Nov 26, 2017

    +

    May 14, 2018


    @@ -193,7 +215,7 @@ MathJax.Hub.Config({

  • 9
  • 10
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • @@ -211,7 +233,7 @@ MathJax.Hub.Config({
    - © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    diff --git a/doc/pub/Regression/html/._Regression-bs001.html b/doc/pub/Regression/html/._Regression-bs001.html index 777c2c361..f43eec86c 100644 --- a/doc/pub/Regression/html/._Regression-bs001.html +++ b/doc/pub/Regression/html/._Regression-bs001.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -190,7 +212,7 @@ A regression model aims at finding a likelihood function \( p(y\vert \hat{x}) \)
  • 10
  • 11
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs002.html b/doc/pub/Regression/html/._Regression-bs002.html index 288bdafdf..cc5368d14 100644 --- a/doc/pub/Regression/html/._Regression-bs002.html +++ b/doc/pub/Regression/html/._Regression-bs002.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -187,7 +209,7 @@ where \( \epsilon_i \) is the error in our approximation.
  • 11
  • 12
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs003.html b/doc/pub/Regression/html/._Regression-bs003.html index ca1627dd7..74eebe1e7 100644 --- a/doc/pub/Regression/html/._Regression-bs003.html +++ b/doc/pub/Regression/html/._Regression-bs003.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -187,7 +209,7 @@ $$
  • 12
  • 13
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs004.html b/doc/pub/Regression/html/._Regression-bs004.html index a126953f7..723f92182 100644 --- a/doc/pub/Regression/html/._Regression-bs004.html +++ b/doc/pub/Regression/html/._Regression-bs004.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -207,7 +229,7 @@ $$
  • 13
  • 14
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs005.html b/doc/pub/Regression/html/._Regression-bs005.html index 0367be6e7..59697268f 100644 --- a/doc/pub/Regression/html/._Regression-bs005.html +++ b/doc/pub/Regression/html/._Regression-bs005.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -192,7 +214,7 @@ $$
  • 14
  • 15
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs006.html b/doc/pub/Regression/html/._Regression-bs006.html index d90e92da0..d1c1f99de 100644 --- a/doc/pub/Regression/html/._Regression-bs006.html +++ b/doc/pub/Regression/html/._Regression-bs006.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -198,7 +220,7 @@ The left-hand side of this equation forms know. Our error vector \( \hat{\epsilo
  • 15
  • 16
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs007.html b/doc/pub/Regression/html/._Regression-bs007.html index 709ab27c2..a96947c77 100644 --- a/doc/pub/Regression/html/._Regression-bs007.html +++ b/doc/pub/Regression/html/._Regression-bs007.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -193,7 +215,7 @@ $$
  • 16
  • 17
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs008.html b/doc/pub/Regression/html/._Regression-bs008.html index 16c7281c3..69833f422 100644 --- a/doc/pub/Regression/html/._Regression-bs008.html +++ b/doc/pub/Regression/html/._Regression-bs008.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -196,7 +218,7 @@ $$
  • 17
  • 18
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs009.html b/doc/pub/Regression/html/._Regression-bs009.html index 264847ecc..1910d9c8c 100644 --- a/doc/pub/Regression/html/._Regression-bs009.html +++ b/doc/pub/Regression/html/._Regression-bs009.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -211,6 +233,8 @@ $$
  • 17
  • 18
  • 19
  • +
  • ...
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs010.html b/doc/pub/Regression/html/._Regression-bs010.html index 88c1bc3a8..dfe70b9a7 100644 --- a/doc/pub/Regression/html/._Regression-bs010.html +++ b/doc/pub/Regression/html/._Regression-bs010.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -198,6 +220,9 @@ $$
  • 17
  • 18
  • 19
  • +
  • 20
  • +
  • ...
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs011.html b/doc/pub/Regression/html/._Regression-bs011.html index 91828da6d..e6e9f71e6 100644 --- a/doc/pub/Regression/html/._Regression-bs011.html +++ b/doc/pub/Regression/html/._Regression-bs011.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -199,6 +221,10 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r
  • 17
  • 18
  • 19
  • +
  • 20
  • +
  • 21
  • +
  • ...
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs012.html b/doc/pub/Regression/html/._Regression-bs012.html index 95f7bf81f..06627f8f1 100644 --- a/doc/pub/Regression/html/._Regression-bs012.html +++ b/doc/pub/Regression/html/._Regression-bs012.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -150,27 +172,34 @@ MathJax.Hub.Config({ -

    The \( \chi^2 \) function

    -
    -
    -

    +

    Simple regression model

    +We are now ready to write our first program which aims at solving the above linear regression equations. We start with data we have produced ourselves, in this case normally distributed random numbers along the \( x \)-axis. These numbers define then the value of a function \( y(x)=4+3x+N(0,1) \). Thereafter we order the \( x \) values and employ our linear regression algorithm to set up the best fit.

    -Normally, the response (dependent or outcome) variable \( y_i \) the outcome of a numerical experiment or another type of experiment and is thus only an approximation to the true value. It is then always accompanied by an error estimate, often limited to a statistical error estimate given by the standard deviation discussed earlier. In the discussion here we will treat \( y_i \) as our exact value for the response variable. -

    -Introducing the standard deviation \( \sigma_i \) for each measurement \( y_i \), we define now the \( \chi^2 \) function as -$$ -\chi^2(\hat{\beta})=\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\left(\hat{y}-\hat{\tilde{y}}\right)^T\frac{1}{\hat{\Sigma^2}}\left(\hat{y}-\hat{\tilde{y}}\right), -$$ + +

    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
     
    -where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements.
    -
    -

    -

    -
    +x = 2*np.random.rand(100,1) +y = 4+3*x+np.random.randn(100,1) +xb = np.c_[np.ones((100,1)), x] +theta = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y) +xnew = np.array([[0],[2]]) +xbnew = np.c_[np.ones((2,1)), xnew] +ypredict = xbnew.dot(theta) +plt.plot(xnew, ypredict, "r-") +plt.plot(x, y ,'ro') +plt.axis([0,2.0,0, 15.0]) +plt.xlabel(r'$x$') +plt.ylabel(r'$y$') +plt.title(r'Linear Regression') +plt.show() +

    @@ -193,6 +222,11 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as

  • 17
  • 18
  • 19
  • +
  • 20
  • +
  • 21
  • +
  • 22
  • +
  • ...
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs013.html b/doc/pub/Regression/html/._Regression-bs013.html index a1e2c54ae..8098226bc 100644 --- a/doc/pub/Regression/html/._Regression-bs013.html +++ b/doc/pub/Regression/html/._Regression-bs013.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -150,32 +172,32 @@ MathJax.Hub.Config({ -

    The \( \chi^2 \) function

    -
    -
    -

    - +

    Simple regression model, now using scikit-learn

    +We can repeat the above algorithm using scikit-learn as follows.

    -In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\hat{\beta}) \) by requiring -$$ -\frac{\partial \chi^2(\hat{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0, -$$ -which results in -$$ -\frac{\partial \chi^2(\hat{\beta})}{\partial \beta_j} = -2\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0, -$$ - -or in a matrix-vector form as -$$ -\frac{\partial \chi^2(\hat{\beta})}{\partial \hat{\beta}} = 0 = \hat{A}^T\left( \hat{b}-\hat{A}\hat{\beta}\right). -$$ - -where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \hat{b} \) with elements \( b_i = y_i/\sigma_i \). -

    -
    + +
    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import LinearRegression
     
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +linreg = LinearRegression()
    +linreg.fit(x,y)
    +xnew = np.array([[0],[2]])
    +ypredict = linreg.predict(xnew)
     
    +plt.plot(xnew, ypredict, "r-")
    +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()
    +

    @@ -197,6 +219,12 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix

  • 17
  • 18
  • 19
  • +
  • 20
  • +
  • 21
  • +
  • 22
  • +
  • 23
  • +
  • ...
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs014.html b/doc/pub/Regression/html/._Regression-bs014.html index b5be5a813..b749eb4b2 100644 --- a/doc/pub/Regression/html/._Regression-bs014.html +++ b/doc/pub/Regression/html/._Regression-bs014.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -150,29 +172,15 @@ MathJax.Hub.Config({ -

    The \( \chi^2 \) function

    -
    -
    -

    +

    Correlations and the quality of our results

    +In order to test the quality of our fit, there are several measures which can be implemented. One is the so-called +correlation function defined as +$$ +\mathrm{Corr}(X,Y) = \frac{\sum_{i=1}^n(x_i-\overline{x})(y_i-\overline{y})}{\sqrt{\sum_{i=1}^n(x_i-\overline{x})^2}\sqrt{\sum_{i=1}^n(y_i-\overline{y})^2} } +$$

    -We can rewrite -$$ -\frac{\partial \chi^2(\hat{\beta})}{\partial \hat{\beta}} = 0 = \hat{A}^T\left( \hat{b}-\hat{A}\hat{\beta}\right), -$$ - -as -$$ -\hat{A}^T\hat{b} = \hat{A}^T\hat{A}\hat{\beta}, -$$ - -and if the matrix \( \hat{A}^T\hat{A} \) is invertible we have the solution -$$ -\hat{\beta} =\left(\hat{A}^T\hat{A}\right)^{-1}\hat{A}^T\hat{b}. -$$ -

    -
    - +Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis.

    @@ -194,6 +202,11 @@ $$

  • 17
  • 18
  • 19
  • +
  • 20
  • +
  • 21
  • +
  • 22
  • +
  • 23
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs015.html b/doc/pub/Regression/html/._Regression-bs015.html index a4a3ed276..950cb8fee 100644 --- a/doc/pub/Regression/html/._Regression-bs015.html +++ b/doc/pub/Regression/html/._Regression-bs015.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -156,25 +178,17 @@ MathJax.Hub.Config({

    -If we then introduce the matrix +Normally, the response (dependent or outcome) variable \( y_i \) the outcome of a numerical experiment or another type of experiment and is thus only an approximation to the true value. It is then always accompanied by an error estimate, often limited to a statistical error estimate given by the standard deviation discussed earlier. In the discussion here we will treat \( y_i \) as our exact value for the response variable. + +

    +Introducing the standard deviation \( \sigma_i \) for each measurement \( y_i \), we define now the \( \chi^2 \) function as $$ -\hat{H} = \hat{A}^T\hat{A}, +\chi^2(\hat{\beta})=\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\left(\hat{y}-\hat{\tilde{y}}\right)^T\frac{1}{\hat{\Sigma^2}}\left(\hat{y}-\hat{\tilde{y}}\right), $$ -we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \hat{H} \) are \( h_{ij} \)) -$$ -\beta_j = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}\frac{y_i}{\sigma_i}\frac{x_{ik}}{\sigma_i} = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}b_ia_{ik} -$$ +where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements. -We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as -$$ -\sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2, -$$ - -resulting in -$$ -\sigma^2(\beta_j) = \left(\sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}a_{ik}\right)\left(\sum_{l=0}^{p-1}h_{jl}\sum_{m=0}^{n-1}a_{ml}\right) = h_{jj}! -$$ +

    @@ -198,6 +212,11 @@ $$

  • 17
  • 18
  • 19
  • +
  • 20
  • +
  • 21
  • +
  • 22
  • +
  • 23
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs016.html b/doc/pub/Regression/html/._Regression-bs016.html index 48f91c954..8ae7cc076 100644 --- a/doc/pub/Regression/html/._Regression-bs016.html +++ b/doc/pub/Regression/html/._Regression-bs016.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -154,20 +176,24 @@ MathJax.Hub.Config({

    -The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write + +

    +In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\hat{\beta}) \) by requiring $$ -y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i. +\frac{\partial \chi^2(\hat{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0, $$ -By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by +which results in $$ -\frac{\partial \chi^2(\hat{\beta})}{\partial \beta_0} = -2\left[ \sum_{i=0}^{1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0, +\frac{\partial \chi^2(\hat{\beta})}{\partial \beta_j} = -2\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0, $$ -and +or in a matrix-vector form as $$ -\frac{\partial \chi^2(\hat{\beta})}{\partial \beta_0} = -2\left[ \sum_{i=0}^{1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0. +\frac{\partial \chi^2(\hat{\beta})}{\partial \hat{\beta}} = 0 = \hat{A}^T\left( \hat{b}-\hat{A}\hat{\beta}\right). $$ + +where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \hat{b} \) with elements \( b_i = y_i/\sigma_i \).

    @@ -190,6 +216,11 @@ $$
  • 17
  • 18
  • 19
  • +
  • 20
  • +
  • 21
  • +
  • 22
  • +
  • 23
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs017.html b/doc/pub/Regression/html/._Regression-bs017.html index 41242ec07..2ab31e2a9 100644 --- a/doc/pub/Regression/html/._Regression-bs017.html +++ b/doc/pub/Regression/html/._Regression-bs017.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -156,39 +178,20 @@ MathJax.Hub.Config({

    -We define then +We can rewrite $$ -\gamma = \sum_{i=0}^{1}\frac{1}{\sigma_i^2}, +\frac{\partial \chi^2(\hat{\beta})}{\partial \hat{\beta}} = 0 = \hat{A}^T\left( \hat{b}-\hat{A}\hat{\beta}\right), $$ - +as $$ -\gamma_x = \sum_{i=0}^{1}\frac{x_{i}}{\sigma_i^2}, +\hat{A}^T\hat{b} = \hat{A}^T\hat{A}\hat{\beta}, $$ +and if the matrix \( \hat{A}^T\hat{A} \) is invertible we have the solution $$ -\gamma_y = \sum_{i=0}^{1}\left(\frac{y_i}{\sigma_i^2}\right), +\hat{\beta} =\left(\hat{A}^T\hat{A}\right)^{-1}\hat{A}^T\hat{b}. $$ - -$$ -\gamma_{xx} = \sum_{i=0}^{1}\frac{x_ix_{i}}{\sigma_i^2}, -$$ - -$$ -\gamma_{xy} = \sum_{i=0}^{1}\frac{y_ix_{i}}{\sigma_i^2}, -$$ - -and show that -$$ -\beta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}, -$$ - -$$ -\beta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}. -$$ - -

    -The LSM suffers often from both being underdetermined and overdetermined in the unknown coefficients \( \beta_i \). A better approach is to use the Singular Value Decomposition (SVD) method discussed below. @@ -210,6 +213,11 @@ The LSM suffers often from both being underdetermined and overdetermined in the

  • 17
  • 18
  • 19
  • +
  • 20
  • +
  • 21
  • +
  • 22
  • +
  • 23
  • +
  • 24
  • »
  • diff --git a/doc/pub/Regression/html/._Regression-bs018.html b/doc/pub/Regression/html/._Regression-bs018.html index 35d75e287..6b3d60888 100644 --- a/doc/pub/Regression/html/._Regression-bs018.html +++ b/doc/pub/Regression/html/._Regression-bs018.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -150,20 +172,36 @@ MathJax.Hub.Config({ -

    The singular value decompostion

    +

    The \( \chi^2 \) function

    -How can we use the singular value decomposition to find the parameters \( \beta_j \)? More details will come. We first note that a general \( m\times n \) matrix \( \hat{A} \) can be written in terms of a diagonal matrix \( \hat{\Sigma} \) of dimensionality \( n\times n \) and two orthognal matrices \( \hat{U} \) and \( \hat{V} \), where the first has dimensionality \( m \times n \) and the last dimensionality \( n\times n \). We have then + +

    +If we then introduce the matrix $$ -\hat{A} = \hat{U}\hat{\Sigma}\hat{V} +\hat{H} = \hat{A}^T\hat{A}, +$$ + +we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \hat{H} \) are \( h_{ij} \)) +$$ +\beta_j = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}\frac{y_i}{\sigma_i}\frac{x_{ik}}{\sigma_i} = \sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}b_ia_{ik} +$$ + +We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as +$$ +\sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2, +$$ + +resulting in +$$ +\sigma^2(\beta_j) = \left(\sum_{k=0}^{p-1}h_{jk}\sum_{i=0}^{n-1}a_{ik}\right)\left(\sum_{l=0}^{p-1}h_{jl}\sum_{m=0}^{n-1}a_{ml}\right) = h_{jj}! $$

    -

    diff --git a/doc/pub/Regression/html/Regression-bs.html b/doc/pub/Regression/html/Regression-bs.html index cc3f0021f..4a67b29fe 100644 --- a/doc/pub/Regression/html/Regression-bs.html +++ b/doc/pub/Regression/html/Regression-bs.html @@ -73,13 +73,30 @@ Automatically generated HTML file from DocOnce source 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -128,13 +145,18 @@ MathJax.Hub.Config({
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • Interpretations and optimizing our parameters
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • -
  • The \( \chi^2 \) function
  • +
  • Simple regression model
  • +
  • Simple regression model, now using scikit-learn
  • +
  • Correlations and the quality of our results
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • The \( \chi^2 \) function
  • -
  • The singular value decompostion
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • The \( \chi^2 \) function
  • +
  • Simple regression model with gradient descent
  • +
  • Simple regression model with stochastic gradient descent
  • +
  • The singular value decompostion
  • @@ -169,7 +191,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Nov 26, 2017

    +

    May 14, 2018


    @@ -193,7 +215,7 @@ MathJax.Hub.Config({

  • 9
  • 10
  • ...
  • -
  • 19
  • +
  • 24
  • »
  • @@ -211,7 +233,7 @@ MathJax.Hub.Config({
    - © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    diff --git a/doc/pub/Regression/html/Regression-reveal.html b/doc/pub/Regression/html/Regression-reveal.html index 316de914a..0f1ad5c48 100644 --- a/doc/pub/Regression/html/Regression-reveal.html +++ b/doc/pub/Regression/html/Regression-reveal.html @@ -148,12 +148,12 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

     
    -

    Nov 26, 2017

    +

    May 14, 2018


    - © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    @@ -492,7 +492,84 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r
    -

    The \( \chi^2 \) function

    +

    Simple regression model

    +We are now ready to write our first program which aims at solving the above linear regression equations. We start with data we have produced ourselves, in this case normally distributed random numbers along the \( x \)-axis. These numbers define then the value of a function \( y(x)=4+3x+N(0,1) \). Thereafter we order the \( x \) values and employ our linear regression algorithm to set up the best fit. + +

    + + +

    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(theta)
    +
    +plt.plot(xnew, ypredict, "r-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Linear Regression')
    +plt.show()
    +
    +
    + + +
    +

    Simple regression model, now using scikit-learn

    +We can repeat the above algorithm using scikit-learn as follows. +

    + + +

    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import LinearRegression
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +linreg = LinearRegression()
    +linreg.fit(x,y)
    +xnew = np.array([[0],[2]])
    +ypredict = linreg.predict(xnew)
    +
    +plt.plot(xnew, ypredict, "r-")
    +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()
    +
    +
    + + +
    +

    Correlations and the quality of our results

    +In order to test the quality of our fit, there are several measures which can be implemented. One is the so-called +correlation function defined as +

     
    +$$ +\mathrm{Corr}(X,Y) = \frac{\sum_{i=1}^n(x_i-\overline{x})(y_i-\overline{y})}{\sqrt{\sum_{i=1}^n(x_i-\overline{x})^2}\sqrt{\sum_{i=1}^n(y_i-\overline{y})^2} } +$$ +

     
    + +

    +Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis. +

    + + +
    +

    The \( \chi^2 \) function

    @@ -515,7 +592,7 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as

    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -546,7 +623,7 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix

    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -575,7 +652,7 @@ $$

    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -611,7 +688,7 @@ $$

    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -640,7 +717,7 @@ $$

    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -695,7 +772,78 @@ The LSM suffers often from both being underdetermined and overdetermined in the

    -

    The singular value decompostion

    +

    Simple regression model with gradient descent

    +Add info about the equations, play around with different learning rates +

    + + +

    # Importing various packages
    +from math import exp, sqrt
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +print(theta_linreg)
    +theta = np.random.randn(2,1)
    +
    +eta = 0.1
    +Niterations = 1000
    +m = 100
    +
    +for iter in range(Niterations):
    +    gradients = 2.0/m*xb.T.dot(xb.dot(theta)-y)
    +    theta -= eta*gradients
    +
    +print(theta)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(theta)
    +ypredict2 = xbnew.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()
    +
    +
    + + +
    +

    Simple regression model with stochastic gradient descent

    +Add info about the equations, play around with different learning rates +

    + + +

    # Importing various packages
    +from math import exp, sqrt
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import SGDRegressor
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +print(theta_linreg)
    +sgdreg = SGDRegressor(n_iter = 50, penalty=None, eta0=0.1)
    +sgdreg.fit(x,y.ravel())
    +print(sgdreg.intercept_, sgdreg.coef_)
    +
    +
    + + +
    +

    The singular value decompostion

    diff --git a/doc/pub/Regression/html/Regression-solarized.html b/doc/pub/Regression/html/Regression-solarized.html index a0ba5efaa..154f6eca6 100644 --- a/doc/pub/Regression/html/Regression-solarized.html +++ b/doc/pub/Regression/html/Regression-solarized.html @@ -93,13 +93,30 @@ div { text-align: justify; text-justify: inter-word; } 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -141,7 +158,7 @@ MathJax.Hub.Config({

    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Nov 26, 2017

    +

    May 14, 2018












    @@ -441,7 +458,80 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r











    -

    The \( \chi^2 \) function

    +

    Simple regression model

    +We are now ready to write our first program which aims at solving the above linear regression equations. We start with data we have produced ourselves, in this case normally distributed random numbers along the \( x \)-axis. These numbers define then the value of a function \( y(x)=4+3x+N(0,1) \). Thereafter we order the \( x \) values and employ our linear regression algorithm to set up the best fit. + +

    + + +

    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(theta)
    +
    +plt.plot(xnew, ypredict, "r-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Linear Regression')
    +plt.show()
    +
    +

    +









    + +

    Simple regression model, now using scikit-learn

    +We can repeat the above algorithm using scikit-learn as follows. +

    + + +

    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import LinearRegression
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +linreg = LinearRegression()
    +linreg.fit(x,y)
    +xnew = np.array([[0],[2]])
    +ypredict = linreg.predict(xnew)
    +
    +plt.plot(xnew, ypredict, "r-")
    +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()
    +
    +

    +









    + +

    Correlations and the quality of our results

    +In order to test the quality of our fit, there are several measures which can be implemented. One is the so-called +correlation function defined as +$$ +\mathrm{Corr}(X,Y) = \frac{\sum_{i=1}^n(x_i-\overline{x})(y_i-\overline{y})}{\sqrt{\sum_{i=1}^n(x_i-\overline{x})^2}\sqrt{\sum_{i=1}^n(y_i-\overline{y})^2} } +$$ + +

    +Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis. + +

    +









    + +

    The \( \chi^2 \) function

    @@ -464,7 +554,7 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -492,7 +582,7 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -518,7 +608,7 @@ $$











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -549,7 +639,7 @@ $$











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -573,7 +663,7 @@ $$











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -618,7 +708,76 @@ The LSM suffers often from both being underdetermined and overdetermined in the











    -

    The singular value decompostion

    +

    Simple regression model with gradient descent

    +Add info about the equations, play around with different learning rates +

    + + +

    # Importing various packages
    +from math import exp, sqrt
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +print(theta_linreg)
    +theta = np.random.randn(2,1)
    +
    +eta = 0.1
    +Niterations = 1000
    +m = 100
    +
    +for iter in range(Niterations):
    +    gradients = 2.0/m*xb.T.dot(xb.dot(theta)-y)
    +    theta -= eta*gradients
    +
    +print(theta)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(theta)
    +ypredict2 = xbnew.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()
    +
    +

    +









    + +

    Simple regression model with stochastic gradient descent

    +Add info about the equations, play around with different learning rates +

    + + +

    # Importing various packages
    +from math import exp, sqrt
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import SGDRegressor
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +print(theta_linreg)
    +sgdreg = SGDRegressor(n_iter = 50, penalty=None, eta0=0.1)
    +sgdreg.fit(x,y.ravel())
    +print(sgdreg.intercept_, sgdreg.coef_)
    +
    +

    +









    + +

    The singular value decompostion

    @@ -635,7 +794,7 @@ $$

    - © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    diff --git a/doc/pub/Regression/html/Regression.html b/doc/pub/Regression/html/Regression.html index 1c1b11675..e42300f00 100644 --- a/doc/pub/Regression/html/Regression.html +++ b/doc/pub/Regression/html/Regression.html @@ -98,13 +98,30 @@ div { text-align: justify; text-justify: inter-word; } 2, None, '___sec10'), - ('The $\\chi^2$ function', 2, None, '___sec11'), - ('The $\\chi^2$ function', 2, None, '___sec12'), - ('The $\\chi^2$ function', 2, None, '___sec13'), + ('Simple regression model', 2, None, '___sec11'), + ('Simple regression model, now using _scikit-learn_', + 2, + None, + '___sec12'), + ('Correlations and the quality of our results', + 2, + None, + '___sec13'), ('The $\\chi^2$ function', 2, None, '___sec14'), ('The $\\chi^2$ function', 2, None, '___sec15'), ('The $\\chi^2$ function', 2, None, '___sec16'), - ('The singular value decompostion', 2, None, '___sec17')]} + ('The $\\chi^2$ function', 2, None, '___sec17'), + ('The $\\chi^2$ function', 2, None, '___sec18'), + ('The $\\chi^2$ function', 2, None, '___sec19'), + ('Simple regression model with gradient descent', + 2, + None, + '___sec20'), + ('Simple regression model with stochastic gradient descent', + 2, + None, + '___sec21'), + ('The singular value decompostion', 2, None, '___sec22')]} end of tocinfo --> @@ -146,7 +163,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Nov 26, 2017

    +

    May 14, 2018












    @@ -446,7 +463,80 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r











    -

    The \( \chi^2 \) function

    +

    Simple regression model

    +We are now ready to write our first program which aims at solving the above linear regression equations. We start with data we have produced ourselves, in this case normally distributed random numbers along the \( x \)-axis. These numbers define then the value of a function \( y(x)=4+3x+N(0,1) \). Thereafter we order the \( x \) values and employ our linear regression algorithm to set up the best fit. + +

    + + +

    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(theta)
    +
    +plt.plot(xnew, ypredict, "r-")
    +plt.plot(x, y ,'ro')
    +plt.axis([0,2.0,0, 15.0])
    +plt.xlabel(r'$x$')
    +plt.ylabel(r'$y$')
    +plt.title(r'Linear Regression')
    +plt.show()
    +
    +

    +









    + +

    Simple regression model, now using scikit-learn

    +We can repeat the above algorithm using scikit-learn as follows. +

    + + +

    # Importing various packages
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import LinearRegression
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +linreg = LinearRegression()
    +linreg.fit(x,y)
    +xnew = np.array([[0],[2]])
    +ypredict = linreg.predict(xnew)
    +
    +plt.plot(xnew, ypredict, "r-")
    +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()
    +
    +

    +









    + +

    Correlations and the quality of our results

    +In order to test the quality of our fit, there are several measures which can be implemented. One is the so-called +correlation function defined as +$$ +\mathrm{Corr}(X,Y) = \frac{\sum_{i=1}^n(x_i-\overline{x})(y_i-\overline{y})}{\sqrt{\sum_{i=1}^n(x_i-\overline{x})^2}\sqrt{\sum_{i=1}^n(y_i-\overline{y})^2} } +$$ + +

    +Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis. + +

    +









    + +

    The \( \chi^2 \) function

    @@ -469,7 +559,7 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -497,7 +587,7 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -523,7 +613,7 @@ $$











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -554,7 +644,7 @@ $$











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -578,7 +668,7 @@ $$











    -

    The \( \chi^2 \) function

    +

    The \( \chi^2 \) function

    @@ -623,7 +713,76 @@ The LSM suffers often from both being underdetermined and overdetermined in the











    -

    The singular value decompostion

    +

    Simple regression model with gradient descent

    +Add info about the equations, play around with different learning rates +

    + + +

    # Importing various packages
    +from math import exp, sqrt
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +print(theta_linreg)
    +theta = np.random.randn(2,1)
    +
    +eta = 0.1
    +Niterations = 1000
    +m = 100
    +
    +for iter in range(Niterations):
    +    gradients = 2.0/m*xb.T.dot(xb.dot(theta)-y)
    +    theta -= eta*gradients
    +
    +print(theta)
    +xnew = np.array([[0],[2]])
    +xbnew = np.c_[np.ones((2,1)), xnew]
    +ypredict = xbnew.dot(theta)
    +ypredict2 = xbnew.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()
    +
    +

    +









    + +

    Simple regression model with stochastic gradient descent

    +Add info about the equations, play around with different learning rates +

    + + +

    # Importing various packages
    +from math import exp, sqrt
    +from random import random, seed
    +import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.linear_model import SGDRegressor
    +
    +x = 2*np.random.rand(100,1)
    +y = 4+3*x+np.random.randn(100,1)
    +
    +xb = np.c_[np.ones((100,1)), x]
    +theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
    +print(theta_linreg)
    +sgdreg = SGDRegressor(n_iter = 50, penalty=None, eta0=0.1)
    +sgdreg.fit(x,y.ravel())
    +print(sgdreg.intercept_, sgdreg.coef_)
    +
    +

    +









    + +

    The singular value decompostion

    @@ -640,7 +799,7 @@ $$

    - © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license + © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
    diff --git a/doc/pub/Regression/ipynb/ipynb-Regression-src.tar.gz b/doc/pub/Regression/ipynb/ipynb-Regression-src.tar.gz index 2c3527626..c25938b62 100644 Binary files a/doc/pub/Regression/ipynb/ipynb-Regression-src.tar.gz and b/doc/pub/Regression/ipynb/ipynb-Regression-src.tar.gz differ diff --git a/doc/pub/Regression/pdf/Regression-beamer-handouts2x3.pdf b/doc/pub/Regression/pdf/Regression-beamer-handouts2x3.pdf index f2c78c9c6..58944e8b9 100644 Binary files a/doc/pub/Regression/pdf/Regression-beamer-handouts2x3.pdf and b/doc/pub/Regression/pdf/Regression-beamer-handouts2x3.pdf differ diff --git a/doc/pub/Regression/pdf/Regression-beamer.pdf b/doc/pub/Regression/pdf/Regression-beamer.pdf index dfc547a0a..89c3b892d 100644 Binary files a/doc/pub/Regression/pdf/Regression-beamer.pdf and b/doc/pub/Regression/pdf/Regression-beamer.pdf differ diff --git a/doc/pub/Regression/pdf/Regression-minted.pdf b/doc/pub/Regression/pdf/Regression-minted.pdf index 5171de9dc..547b76b4c 100644 Binary files a/doc/pub/Regression/pdf/Regression-minted.pdf and b/doc/pub/Regression/pdf/Regression-minted.pdf differ