update notebook
This commit is contained in:
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -169,7 +191,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Nov 26, 2017</h4></center> <!-- date -->
|
||||
<center><h4>May 14, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -193,7 +215,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._Regression-bs008.html">9</a></li>
|
||||
<li><a href="._Regression-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
@@ -211,7 +233,7 @@ MathJax.Hub.Config({
|
||||
|
||||
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
<!-- copyright --> © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
</center>
|
||||
|
||||
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -190,7 +212,7 @@ A regression model aims at finding a likelihood function \( p(y\vert \hat{x}) \)
|
||||
<li><a href="._Regression-bs009.html">10</a></li>
|
||||
<li><a href="._Regression-bs010.html">11</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs002.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -187,7 +209,7 @@ where \( \epsilon_i \) is the error in our approximation.
|
||||
<li><a href="._Regression-bs010.html">11</a></li>
|
||||
<li><a href="._Regression-bs011.html">12</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs003.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -187,7 +209,7 @@ $$
|
||||
<li><a href="._Regression-bs011.html">12</a></li>
|
||||
<li><a href="._Regression-bs012.html">13</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs004.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -207,7 +229,7 @@ $$
|
||||
<li><a href="._Regression-bs012.html">13</a></li>
|
||||
<li><a href="._Regression-bs013.html">14</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs005.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -192,7 +214,7 @@ $$
|
||||
<li><a href="._Regression-bs013.html">14</a></li>
|
||||
<li><a href="._Regression-bs014.html">15</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs006.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -198,7 +220,7 @@ The left-hand side of this equation forms know. Our error vector \( \hat{\epsilo
|
||||
<li><a href="._Regression-bs014.html">15</a></li>
|
||||
<li><a href="._Regression-bs015.html">16</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs007.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -193,7 +215,7 @@ $$
|
||||
<li><a href="._Regression-bs015.html">16</a></li>
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs008.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -196,7 +218,7 @@ $$
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs009.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -211,6 +233,8 @@ $$
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs010.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -198,6 +220,9 @@ $$
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs011.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -199,6 +221,10 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs012.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -150,27 +172,34 @@ MathJax.Hub.Config({
|
||||
<a name="part0012"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec11" class="anchor">The \( \chi^2 \) function </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<h2 id="___sec11" class="anchor">Simple regression model </h2>
|
||||
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.
|
||||
|
||||
<p>
|
||||
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.
|
||||
|
||||
<p>
|
||||
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),
|
||||
$$
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Importing various packages</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">random</span> <span style="color: #008000; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
|
||||
where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements.
|
||||
|
||||
<p>
|
||||
</div>
|
||||
</div>
|
||||
x <span style="color: #666666">=</span> <span style="color: #666666">2*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
|
||||
xb <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)), x]
|
||||
theta <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv(xb<span style="color: #666666">.</span>T<span style="color: #666666">.</span>dot(xb))<span style="color: #666666">.</span>dot(xb<span style="color: #666666">.</span>T)<span style="color: #666666">.</span>dot(y)
|
||||
xnew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([[<span style="color: #666666">0</span>],[<span style="color: #666666">2</span>]])
|
||||
xbnew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((<span style="color: #666666">2</span>,<span style="color: #666666">1</span>)), xnew]
|
||||
ypredict <span style="color: #666666">=</span> xbnew<span style="color: #666666">.</span>dot(theta)
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(xnew, ypredict, <span style="color: #BA2121">"r-"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x, y ,<span style="color: #BA2121">'ro'</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>,<span style="color: #666666">2.0</span>,<span style="color: #666666">0</span>, <span style="color: #666666">15.0</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Linear Regression'</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -193,6 +222,11 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs013.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -150,32 +172,32 @@ MathJax.Hub.Config({
|
||||
<a name="part0013"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec12" class="anchor">The \( \chi^2 \) function </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
|
||||
<h2 id="___sec12" class="anchor">Simple regression model, now using <b>scikit-learn</b> </h2>
|
||||
We can repeat the above algorithm using <b>scikit-learn</b> as follows.
|
||||
<p>
|
||||
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 \).
|
||||
</div>
|
||||
</div>
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Importing various packages</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">random</span> <span style="color: #008000; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
|
||||
|
||||
x <span style="color: #666666">=</span> <span style="color: #666666">2*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
linreg <span style="color: #666666">=</span> LinearRegression()
|
||||
linreg<span style="color: #666666">.</span>fit(x,y)
|
||||
xnew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([[<span style="color: #666666">0</span>],[<span style="color: #666666">2</span>]])
|
||||
ypredict <span style="color: #666666">=</span> linreg<span style="color: #666666">.</span>predict(xnew)
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(xnew, ypredict, <span style="color: #BA2121">"r-"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x, y ,<span style="color: #BA2121">'ro'</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>,<span style="color: #666666">2.0</span>,<span style="color: #666666">0</span>, <span style="color: #666666">15.0</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Random numbers '</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
@@ -197,6 +219,12 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="._Regression-bs022.html">23</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs014.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -150,29 +172,15 @@ MathJax.Hub.Config({
|
||||
<a name="part0014"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec13" class="anchor">The \( \chi^2 \) function </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<h2 id="___sec13" class="anchor">Correlations and the quality of our results </h2>
|
||||
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} }
|
||||
$$
|
||||
|
||||
<p>
|
||||
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}.
|
||||
$$
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis.
|
||||
|
||||
<p>
|
||||
<p>
|
||||
@@ -194,6 +202,11 @@ $$
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="._Regression-bs022.html">23</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs015.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -156,25 +178,17 @@ MathJax.Hub.Config({
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
|
||||
<p>
|
||||
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.
|
||||
|
||||
<p>
|
||||
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}!
|
||||
$$
|
||||
<p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -198,6 +212,11 @@ $$
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="._Regression-bs022.html">23</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs016.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -154,20 +176,24 @@ MathJax.Hub.Config({
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write
|
||||
|
||||
<p>
|
||||
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 \).
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -190,6 +216,11 @@ $$
|
||||
<li class="active"><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="._Regression-bs022.html">23</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs017.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -156,39 +178,20 @@ MathJax.Hub.Config({
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
|
||||
<p>
|
||||
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}.
|
||||
$$
|
||||
|
||||
<p>
|
||||
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.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -210,6 +213,11 @@ The LSM suffers often from both being underdetermined and overdetermined in the
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li class="active"><a href="._Regression-bs017.html">18</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="._Regression-bs022.html">23</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs018.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -150,20 +172,36 @@ MathJax.Hub.Config({
|
||||
<a name="part0018"></a>
|
||||
<!-- !split -->
|
||||
|
||||
<h2 id="___sec17" class="anchor">The singular value decompostion </h2>
|
||||
<h2 id="___sec17" class="anchor">The \( \chi^2 \) function </h2>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
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
|
||||
|
||||
<p>
|
||||
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}!
|
||||
$$
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<p>
|
||||
|
||||
<p>
|
||||
<!-- navigation buttons at the bottom of the page -->
|
||||
<ul class="pagination">
|
||||
@@ -179,6 +217,12 @@ $$
|
||||
<li><a href="._Regression-bs016.html">17</a></li>
|
||||
<li><a href="._Regression-bs017.html">18</a></li>
|
||||
<li class="active"><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs019.html">20</a></li>
|
||||
<li><a href="._Regression-bs020.html">21</a></li>
|
||||
<li><a href="._Regression-bs021.html">22</a></li>
|
||||
<li><a href="._Regression-bs022.html">23</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs019.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -128,13 +145,18 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs009.html#___sec8" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs010.html#___sec9" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs011.html#___sec10" style="font-size: 80%;">Interpretations and optimizing our parameters</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs012.html#___sec11" style="font-size: 80%;">Simple regression model</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs013.html#___sec12" style="font-size: 80%;">Simple regression model, now using <b>scikit-learn</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs014.html#___sec13" style="font-size: 80%;">Correlations and the quality of our results</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs015.html#___sec14" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs016.html#___sec15" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs017.html#___sec16" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs018.html#___sec17" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs019.html#___sec18" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs020.html#___sec19" style="font-size: 80%;">The \( \chi^2 \) function</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs021.html#___sec20" style="font-size: 80%;">Simple regression model with gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs022.html#___sec21" style="font-size: 80%;">Simple regression model with stochastic gradient descent</a></li>
|
||||
<!-- navigation toc: --> <li><a href="._Regression-bs023.html#___sec22" style="font-size: 80%;">The singular value decompostion</a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -169,7 +191,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Nov 26, 2017</h4></center> <!-- date -->
|
||||
<center><h4>May 14, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
@@ -193,7 +215,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._Regression-bs008.html">9</a></li>
|
||||
<li><a href="._Regression-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._Regression-bs018.html">19</a></li>
|
||||
<li><a href="._Regression-bs023.html">24</a></li>
|
||||
<li><a href="._Regression-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
@@ -211,7 +233,7 @@ MathJax.Hub.Config({
|
||||
|
||||
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
<!-- copyright --> © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
</center>
|
||||
|
||||
|
||||
|
||||
@@ -148,12 +148,12 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p> <br>
|
||||
<center><h4>Nov 26, 2017</h4></center> <!-- date -->
|
||||
<center><h4>May 14, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
<!-- copyright --> © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
</center>
|
||||
</section>
|
||||
|
||||
@@ -492,7 +492,84 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec11">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec11">Simple regression model </h2>
|
||||
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.
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">random</span> <span style="color: #8B008B; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
|
||||
x = <span style="color: #B452CD">2</span>*np.random.rand(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.randn(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
|
||||
xb = np.c_[np.ones((<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)), x]
|
||||
theta = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
|
||||
xnew = np.array([[<span style="color: #B452CD">0</span>],[<span style="color: #B452CD">2</span>]])
|
||||
xbnew = np.c_[np.ones((<span style="color: #B452CD">2</span>,<span style="color: #B452CD">1</span>)), xnew]
|
||||
ypredict = xbnew.dot(theta)
|
||||
|
||||
plt.plot(xnew, ypredict, <span style="color: #CD5555">"r-"</span>)
|
||||
plt.plot(x, y ,<span style="color: #CD5555">'ro'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0</span>,<span style="color: #B452CD">2.0</span>,<span style="color: #B452CD">0</span>, <span style="color: #B452CD">15.0</span>])
|
||||
plt.xlabel(<span style="color: #CD5555">r'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">r'$y$'</span>)
|
||||
plt.title(<span style="color: #CD5555">r'Linear Regression'</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec12">Simple regression model, now using <b>scikit-learn</b> </h2>
|
||||
We can repeat the above algorithm using <b>scikit-learn</b> as follows.
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">random</span> <span style="color: #8B008B; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> LinearRegression
|
||||
|
||||
x = <span style="color: #B452CD">2</span>*np.random.rand(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.randn(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
linreg = LinearRegression()
|
||||
linreg.fit(x,y)
|
||||
xnew = np.array([[<span style="color: #B452CD">0</span>],[<span style="color: #B452CD">2</span>]])
|
||||
ypredict = linreg.predict(xnew)
|
||||
|
||||
plt.plot(xnew, ypredict, <span style="color: #CD5555">"r-"</span>)
|
||||
plt.plot(x, y ,<span style="color: #CD5555">'ro'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0</span>,<span style="color: #B452CD">2.0</span>,<span style="color: #B452CD">0</span>, <span style="color: #B452CD">15.0</span>])
|
||||
plt.xlabel(<span style="color: #CD5555">r'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">r'$y$'</span>)
|
||||
plt.title(<span style="color: #CD5555">r'Random numbers '</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec13">Correlations and the quality of our results </h2>
|
||||
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
|
||||
<p> <br>
|
||||
$$
|
||||
\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} }
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>
|
||||
Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis.
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec14">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -515,7 +592,7 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec12">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec15">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -546,7 +623,7 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec13">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec16">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -575,7 +652,7 @@ $$
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec14">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec17">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -611,7 +688,7 @@ $$
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec15">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec18">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -640,7 +717,7 @@ $$
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec16">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec19">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -695,7 +772,78 @@ The LSM suffers often from both being underdetermined and overdetermined in the
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec17">The singular value decompostion </h2>
|
||||
<h2 id="___sec20">Simple regression model with gradient descent </h2>
|
||||
Add info about the equations, play around with different learning rates
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">math</span> <span style="color: #8B008B; font-weight: bold">import</span> exp, sqrt
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">random</span> <span style="color: #8B008B; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
|
||||
x = <span style="color: #B452CD">2</span>*np.random.rand(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.randn(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
|
||||
xb = np.c_[np.ones((<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)), x]
|
||||
theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(theta_linreg)
|
||||
theta = np.random.randn(<span style="color: #B452CD">2</span>,<span style="color: #B452CD">1</span>)
|
||||
|
||||
eta = <span style="color: #B452CD">0.1</span>
|
||||
Niterations = <span style="color: #B452CD">1000</span>
|
||||
m = <span style="color: #B452CD">100</span>
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> <span style="color: #658b00">iter</span> <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(Niterations):
|
||||
gradients = <span style="color: #B452CD">2.0</span>/m*xb.T.dot(xb.dot(theta)-y)
|
||||
theta -= eta*gradients
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(theta)
|
||||
xnew = np.array([[<span style="color: #B452CD">0</span>],[<span style="color: #B452CD">2</span>]])
|
||||
xbnew = np.c_[np.ones((<span style="color: #B452CD">2</span>,<span style="color: #B452CD">1</span>)), xnew]
|
||||
ypredict = xbnew.dot(theta)
|
||||
ypredict2 = xbnew.dot(theta_linreg)
|
||||
plt.plot(xnew, ypredict, <span style="color: #CD5555">"r-"</span>)
|
||||
plt.plot(xnew, ypredict2, <span style="color: #CD5555">"b-"</span>)
|
||||
plt.plot(x, y ,<span style="color: #CD5555">'ro'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0</span>,<span style="color: #B452CD">2.0</span>,<span style="color: #B452CD">0</span>, <span style="color: #B452CD">15.0</span>])
|
||||
plt.xlabel(<span style="color: #CD5555">r'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">r'$y$'</span>)
|
||||
plt.title(<span style="color: #CD5555">r'Random numbers '</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec21">Simple regression model with stochastic gradient descent </h2>
|
||||
Add info about the equations, play around with different learning rates
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">math</span> <span style="color: #8B008B; font-weight: bold">import</span> exp, sqrt
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">random</span> <span style="color: #8B008B; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> SGDRegressor
|
||||
|
||||
x = <span style="color: #B452CD">2</span>*np.random.rand(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.randn(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
|
||||
xb = np.c_[np.ones((<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)), x]
|
||||
theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(theta_linreg)
|
||||
sgdreg = SGDRegressor(n_iter = <span style="color: #B452CD">50</span>, penalty=<span style="color: #658b00">None</span>, eta0=<span style="color: #B452CD">0.1</span>)
|
||||
sgdreg.fit(x,y.ravel())
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(sgdreg.intercept_, sgdreg.coef_)
|
||||
</pre></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section>
|
||||
<h2 id="___sec22">The singular value decompostion </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -141,7 +158,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Nov 26, 2017</h4></center> <!-- date -->
|
||||
<center><h4>May 14, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -441,7 +458,80 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec11">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec11">Simple regression model </h2>
|
||||
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.
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">random</span> <span style="color: #8B008B; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
|
||||
x = <span style="color: #B452CD">2</span>*np.random.rand(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.randn(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
|
||||
xb = np.c_[np.ones((<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)), x]
|
||||
theta = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
|
||||
xnew = np.array([[<span style="color: #B452CD">0</span>],[<span style="color: #B452CD">2</span>]])
|
||||
xbnew = np.c_[np.ones((<span style="color: #B452CD">2</span>,<span style="color: #B452CD">1</span>)), xnew]
|
||||
ypredict = xbnew.dot(theta)
|
||||
|
||||
plt.plot(xnew, ypredict, <span style="color: #CD5555">"r-"</span>)
|
||||
plt.plot(x, y ,<span style="color: #CD5555">'ro'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0</span>,<span style="color: #B452CD">2.0</span>,<span style="color: #B452CD">0</span>, <span style="color: #B452CD">15.0</span>])
|
||||
plt.xlabel(<span style="color: #CD5555">r'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">r'$y$'</span>)
|
||||
plt.title(<span style="color: #CD5555">r'Linear Regression'</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec12">Simple regression model, now using <b>scikit-learn</b> </h2>
|
||||
We can repeat the above algorithm using <b>scikit-learn</b> as follows.
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">random</span> <span style="color: #8B008B; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> LinearRegression
|
||||
|
||||
x = <span style="color: #B452CD">2</span>*np.random.rand(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.randn(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
linreg = LinearRegression()
|
||||
linreg.fit(x,y)
|
||||
xnew = np.array([[<span style="color: #B452CD">0</span>],[<span style="color: #B452CD">2</span>]])
|
||||
ypredict = linreg.predict(xnew)
|
||||
|
||||
plt.plot(xnew, ypredict, <span style="color: #CD5555">"r-"</span>)
|
||||
plt.plot(x, y ,<span style="color: #CD5555">'ro'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0</span>,<span style="color: #B452CD">2.0</span>,<span style="color: #B452CD">0</span>, <span style="color: #B452CD">15.0</span>])
|
||||
plt.xlabel(<span style="color: #CD5555">r'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">r'$y$'</span>)
|
||||
plt.title(<span style="color: #CD5555">r'Random numbers '</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec13">Correlations and the quality of our results </h2>
|
||||
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} }
|
||||
$$
|
||||
|
||||
<p>
|
||||
Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec14">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -464,7 +554,7 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec12">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec15">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -492,7 +582,7 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec13">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec16">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -518,7 +608,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec14">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec17">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -549,7 +639,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec15">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec18">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -573,7 +663,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec16">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec19">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -618,7 +708,76 @@ The LSM suffers often from both being underdetermined and overdetermined in the
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec17">The singular value decompostion </h2>
|
||||
<h2 id="___sec20">Simple regression model with gradient descent </h2>
|
||||
Add info about the equations, play around with different learning rates
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">math</span> <span style="color: #8B008B; font-weight: bold">import</span> exp, sqrt
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">random</span> <span style="color: #8B008B; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
|
||||
x = <span style="color: #B452CD">2</span>*np.random.rand(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.randn(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
|
||||
xb = np.c_[np.ones((<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)), x]
|
||||
theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(theta_linreg)
|
||||
theta = np.random.randn(<span style="color: #B452CD">2</span>,<span style="color: #B452CD">1</span>)
|
||||
|
||||
eta = <span style="color: #B452CD">0.1</span>
|
||||
Niterations = <span style="color: #B452CD">1000</span>
|
||||
m = <span style="color: #B452CD">100</span>
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> <span style="color: #658b00">iter</span> <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(Niterations):
|
||||
gradients = <span style="color: #B452CD">2.0</span>/m*xb.T.dot(xb.dot(theta)-y)
|
||||
theta -= eta*gradients
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(theta)
|
||||
xnew = np.array([[<span style="color: #B452CD">0</span>],[<span style="color: #B452CD">2</span>]])
|
||||
xbnew = np.c_[np.ones((<span style="color: #B452CD">2</span>,<span style="color: #B452CD">1</span>)), xnew]
|
||||
ypredict = xbnew.dot(theta)
|
||||
ypredict2 = xbnew.dot(theta_linreg)
|
||||
plt.plot(xnew, ypredict, <span style="color: #CD5555">"r-"</span>)
|
||||
plt.plot(xnew, ypredict2, <span style="color: #CD5555">"b-"</span>)
|
||||
plt.plot(x, y ,<span style="color: #CD5555">'ro'</span>)
|
||||
plt.axis([<span style="color: #B452CD">0</span>,<span style="color: #B452CD">2.0</span>,<span style="color: #B452CD">0</span>, <span style="color: #B452CD">15.0</span>])
|
||||
plt.xlabel(<span style="color: #CD5555">r'$x$'</span>)
|
||||
plt.ylabel(<span style="color: #CD5555">r'$y$'</span>)
|
||||
plt.title(<span style="color: #CD5555">r'Random numbers '</span>)
|
||||
plt.show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec21">Simple regression model with stochastic gradient descent </h2>
|
||||
Add info about the equations, play around with different learning rates
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">math</span> <span style="color: #8B008B; font-weight: bold">import</span> exp, sqrt
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">random</span> <span style="color: #8B008B; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">import</span> SGDRegressor
|
||||
|
||||
x = <span style="color: #B452CD">2</span>*np.random.rand(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.randn(<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)
|
||||
|
||||
xb = np.c_[np.ones((<span style="color: #B452CD">100</span>,<span style="color: #B452CD">1</span>)), x]
|
||||
theta_linreg = np.linalg.inv(xb.T.dot(xb)).dot(xb.T).dot(y)
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(theta_linreg)
|
||||
sgdreg = SGDRegressor(n_iter = <span style="color: #B452CD">50</span>, penalty=<span style="color: #658b00">None</span>, eta0=<span style="color: #B452CD">0.1</span>)
|
||||
sgdreg.fit(x,y.ravel())
|
||||
<span style="color: #8B008B; font-weight: bold">print</span>(sgdreg.intercept_, sgdreg.coef_)
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec22">The singular value decompostion </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -635,7 +794,7 @@ $$
|
||||
|
||||
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
<!-- copyright --> © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
</center>
|
||||
|
||||
|
||||
|
||||
@@ -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 -->
|
||||
|
||||
<body>
|
||||
@@ -146,7 +163,7 @@ MathJax.Hub.Config({
|
||||
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
|
||||
<br>
|
||||
<p>
|
||||
<center><h4>Nov 26, 2017</h4></center> <!-- date -->
|
||||
<center><h4>May 14, 2018</h4></center> <!-- date -->
|
||||
<br>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
@@ -446,7 +463,80 @@ meaning that the solution for \( \hat{\beta} \) is the one which minimizes the r
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec11">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec11">Simple regression model </h2>
|
||||
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.
|
||||
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Importing various packages</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">random</span> <span style="color: #008000; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
|
||||
x <span style="color: #666666">=</span> <span style="color: #666666">2*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
|
||||
xb <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)), x]
|
||||
theta <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv(xb<span style="color: #666666">.</span>T<span style="color: #666666">.</span>dot(xb))<span style="color: #666666">.</span>dot(xb<span style="color: #666666">.</span>T)<span style="color: #666666">.</span>dot(y)
|
||||
xnew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([[<span style="color: #666666">0</span>],[<span style="color: #666666">2</span>]])
|
||||
xbnew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((<span style="color: #666666">2</span>,<span style="color: #666666">1</span>)), xnew]
|
||||
ypredict <span style="color: #666666">=</span> xbnew<span style="color: #666666">.</span>dot(theta)
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(xnew, ypredict, <span style="color: #BA2121">"r-"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x, y ,<span style="color: #BA2121">'ro'</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>,<span style="color: #666666">2.0</span>,<span style="color: #666666">0</span>, <span style="color: #666666">15.0</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Linear Regression'</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec12">Simple regression model, now using <b>scikit-learn</b> </h2>
|
||||
We can repeat the above algorithm using <b>scikit-learn</b> as follows.
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Importing various packages</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">random</span> <span style="color: #008000; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> LinearRegression
|
||||
|
||||
x <span style="color: #666666">=</span> <span style="color: #666666">2*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
linreg <span style="color: #666666">=</span> LinearRegression()
|
||||
linreg<span style="color: #666666">.</span>fit(x,y)
|
||||
xnew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([[<span style="color: #666666">0</span>],[<span style="color: #666666">2</span>]])
|
||||
ypredict <span style="color: #666666">=</span> linreg<span style="color: #666666">.</span>predict(xnew)
|
||||
|
||||
plt<span style="color: #666666">.</span>plot(xnew, ypredict, <span style="color: #BA2121">"r-"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x, y ,<span style="color: #BA2121">'ro'</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>,<span style="color: #666666">2.0</span>,<span style="color: #666666">0</span>, <span style="color: #666666">15.0</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Random numbers '</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec13">Correlations and the quality of our results </h2>
|
||||
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} }
|
||||
$$
|
||||
|
||||
<p>
|
||||
Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis.
|
||||
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec14">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -469,7 +559,7 @@ where the matrix \( \hat{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec12">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec15">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -497,7 +587,7 @@ where we have defined the matrix \( \hat{A} =\hat{X}/\hat{\Sigma} \) with matrix
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec13">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec16">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -523,7 +613,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec14">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec17">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -554,7 +644,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec15">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec18">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -578,7 +668,7 @@ $$
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec16">The \( \chi^2 \) function </h2>
|
||||
<h2 id="___sec19">The \( \chi^2 \) function </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -623,7 +713,76 @@ The LSM suffers often from both being underdetermined and overdetermined in the
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec17">The singular value decompostion </h2>
|
||||
<h2 id="___sec20">Simple regression model with gradient descent </h2>
|
||||
Add info about the equations, play around with different learning rates
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Importing various packages</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">math</span> <span style="color: #008000; font-weight: bold">import</span> exp, sqrt
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">random</span> <span style="color: #008000; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
|
||||
x <span style="color: #666666">=</span> <span style="color: #666666">2*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
|
||||
xb <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)), x]
|
||||
theta_linreg <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv(xb<span style="color: #666666">.</span>T<span style="color: #666666">.</span>dot(xb))<span style="color: #666666">.</span>dot(xb<span style="color: #666666">.</span>T)<span style="color: #666666">.</span>dot(y)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(theta_linreg)
|
||||
theta <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(<span style="color: #666666">2</span>,<span style="color: #666666">1</span>)
|
||||
|
||||
eta <span style="color: #666666">=</span> <span style="color: #666666">0.1</span>
|
||||
Niterations <span style="color: #666666">=</span> <span style="color: #666666">1000</span>
|
||||
m <span style="color: #666666">=</span> <span style="color: #666666">100</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">for</span> <span style="color: #008000">iter</span> <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(Niterations):
|
||||
gradients <span style="color: #666666">=</span> <span style="color: #666666">2.0/</span>m<span style="color: #666666">*</span>xb<span style="color: #666666">.</span>T<span style="color: #666666">.</span>dot(xb<span style="color: #666666">.</span>dot(theta)<span style="color: #666666">-</span>y)
|
||||
theta <span style="color: #666666">-=</span> eta<span style="color: #666666">*</span>gradients
|
||||
|
||||
<span style="color: #008000; font-weight: bold">print</span>(theta)
|
||||
xnew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([[<span style="color: #666666">0</span>],[<span style="color: #666666">2</span>]])
|
||||
xbnew <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((<span style="color: #666666">2</span>,<span style="color: #666666">1</span>)), xnew]
|
||||
ypredict <span style="color: #666666">=</span> xbnew<span style="color: #666666">.</span>dot(theta)
|
||||
ypredict2 <span style="color: #666666">=</span> xbnew<span style="color: #666666">.</span>dot(theta_linreg)
|
||||
plt<span style="color: #666666">.</span>plot(xnew, ypredict, <span style="color: #BA2121">"r-"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(xnew, ypredict2, <span style="color: #BA2121">"b-"</span>)
|
||||
plt<span style="color: #666666">.</span>plot(x, y ,<span style="color: #BA2121">'ro'</span>)
|
||||
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">0</span>,<span style="color: #666666">2.0</span>,<span style="color: #666666">0</span>, <span style="color: #666666">15.0</span>])
|
||||
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">r'$x$'</span>)
|
||||
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">r'$y$'</span>)
|
||||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r'Random numbers '</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec21">Simple regression model with stochastic gradient descent </h2>
|
||||
Add info about the equations, play around with different learning rates
|
||||
<p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Importing various packages</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">math</span> <span style="color: #008000; font-weight: bold">import</span> exp, sqrt
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">random</span> <span style="color: #008000; font-weight: bold">import</span> random, seed
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">import</span> SGDRegressor
|
||||
|
||||
x <span style="color: #666666">=</span> <span style="color: #666666">2*</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>rand(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>randn(<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)
|
||||
|
||||
xb <span style="color: #666666">=</span> np<span style="color: #666666">.</span>c_[np<span style="color: #666666">.</span>ones((<span style="color: #666666">100</span>,<span style="color: #666666">1</span>)), x]
|
||||
theta_linreg <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv(xb<span style="color: #666666">.</span>T<span style="color: #666666">.</span>dot(xb))<span style="color: #666666">.</span>dot(xb<span style="color: #666666">.</span>T)<span style="color: #666666">.</span>dot(y)
|
||||
<span style="color: #008000; font-weight: bold">print</span>(theta_linreg)
|
||||
sgdreg <span style="color: #666666">=</span> SGDRegressor(n_iter <span style="color: #666666">=</span> <span style="color: #666666">50</span>, penalty<span style="color: #666666">=</span><span style="color: #008000">None</span>, eta0<span style="color: #666666">=0.1</span>)
|
||||
sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.</span>ravel())
|
||||
<span style="color: #008000; font-weight: bold">print</span>(sgdreg<span style="color: #666666">.</span>intercept_, sgdreg<span style="color: #666666">.</span>coef_)
|
||||
</pre></div>
|
||||
<p>
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
|
||||
<h2 id="___sec22">The singular value decompostion </h2>
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
@@ -640,7 +799,7 @@ $$
|
||||
|
||||
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2017, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
<!-- copyright --> © 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
</center>
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user