update
This commit is contained in:
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -401,7 +389,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs008.html">9</a></li>
|
||||
<li><a href="._week34-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -392,7 +380,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs009.html">10</a></li>
|
||||
<li><a href="._week34-bs010.html">11</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs002.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -392,7 +380,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs010.html">11</a></li>
|
||||
<li><a href="._week34-bs011.html">12</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs003.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -397,7 +385,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs011.html">12</a></li>
|
||||
<li><a href="._week34-bs012.html">13</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs004.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -386,7 +374,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs012.html">13</a></li>
|
||||
<li><a href="._week34-bs013.html">14</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs005.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -393,7 +381,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs013.html">14</a></li>
|
||||
<li><a href="._week34-bs014.html">15</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs006.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -398,7 +386,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs014.html">15</a></li>
|
||||
<li><a href="._week34-bs015.html">16</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs007.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -398,7 +386,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs015.html">16</a></li>
|
||||
<li><a href="._week34-bs016.html">17</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs008.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -400,7 +388,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs016.html">17</a></li>
|
||||
<li><a href="._week34-bs017.html">18</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs009.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -401,7 +389,7 @@ al is also widely used in the Machine Learning community. See next slide for lin
|
||||
<li><a href="._week34-bs017.html">18</a></li>
|
||||
<li><a href="._week34-bs018.html">19</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs010.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -403,7 +391,7 @@ Each chapter of RLM gives access to the pertinent notebooks. These notebooks are
|
||||
<li><a href="._week34-bs018.html">19</a></li>
|
||||
<li><a href="._week34-bs019.html">20</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs011.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -403,7 +391,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs019.html">20</a></li>
|
||||
<li><a href="._week34-bs020.html">21</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs012.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -396,7 +384,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs020.html">21</a></li>
|
||||
<li><a href="._week34-bs021.html">22</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs013.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -399,7 +387,7 @@ Python is the recurring programming language.
|
||||
<li><a href="._week34-bs021.html">22</a></li>
|
||||
<li><a href="._week34-bs022.html">23</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs014.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -396,7 +384,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs022.html">23</a></li>
|
||||
<li><a href="._week34-bs023.html">24</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs015.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -398,7 +386,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs023.html">24</a></li>
|
||||
<li><a href="._week34-bs024.html">25</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs016.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -398,7 +386,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs024.html">25</a></li>
|
||||
<li><a href="._week34-bs025.html">26</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs017.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -400,7 +388,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs025.html">26</a></li>
|
||||
<li><a href="._week34-bs026.html">27</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs018.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -399,7 +387,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs026.html">27</a></li>
|
||||
<li><a href="._week34-bs027.html">28</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs019.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -396,7 +384,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs027.html">28</a></li>
|
||||
<li><a href="._week34-bs028.html">29</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs020.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -401,7 +389,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs028.html">29</a></li>
|
||||
<li><a href="._week34-bs029.html">30</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs021.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -407,7 +395,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs029.html">30</a></li>
|
||||
<li><a href="._week34-bs030.html">31</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs022.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -408,7 +396,7 @@ desired output of a system. Some of the most common tasks are:
|
||||
<li><a href="._week34-bs030.html">31</a></li>
|
||||
<li><a href="._week34-bs031.html">32</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs023.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -399,7 +387,7 @@ whether we deal with supervised or unsupervised learning.
|
||||
<li><a href="._week34-bs031.html">32</a></li>
|
||||
<li><a href="._week34-bs032.html">33</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs024.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -390,7 +378,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs032.html">33</a></li>
|
||||
<li><a href="._week34-bs033.html">34</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs025.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -396,7 +384,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs033.html">34</a></li>
|
||||
<li><a href="._week34-bs034.html">35</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs026.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -403,7 +391,7 @@ dataset.
|
||||
<li><a href="._week34-bs034.html">35</a></li>
|
||||
<li><a href="._week34-bs035.html">36</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs027.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -394,7 +382,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs035.html">36</a></li>
|
||||
<li><a href="._week34-bs036.html">37</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs028.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -395,7 +383,7 @@ discriminative in nature.
|
||||
<li><a href="._week34-bs036.html">37</a></li>
|
||||
<li><a href="._week34-bs037.html">38</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs029.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -394,7 +382,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs037.html">38</a></li>
|
||||
<li><a href="._week34-bs038.html">39</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs030.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -400,7 +388,7 @@ data (for example an image), rather than trying to predict a label for say a gi
|
||||
<li><a href="._week34-bs038.html">39</a></li>
|
||||
<li><a href="._week34-bs039.html">40</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs031.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -416,7 +404,7 @@ what is the likelihood of finding \( B \).
|
||||
<li><a href="._week34-bs039.html">40</a></li>
|
||||
<li><a href="._week34-bs040.html">41</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs032.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -413,7 +401,7 @@ could easily be many different models that fit the given data set <em>equally we
|
||||
<li><a href="._week34-bs040.html">41</a></li>
|
||||
<li><a href="._week34-bs041.html">42</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs033.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -411,7 +399,7 @@ may first try the simplest class of models, namely linear models, followed obvio
|
||||
<li><a href="._week34-bs041.html">42</a></li>
|
||||
<li><a href="._week34-bs042.html">43</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs034.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -424,7 +412,7 @@ you can use <b>pip</b> as well and simply install Python as
|
||||
<li><a href="._week34-bs042.html">43</a></li>
|
||||
<li><a href="._week34-bs043.html">44</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs035.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -417,7 +405,7 @@ no setup and runs entirely in the cloud. Try it out!
|
||||
<li><a href="._week34-bs043.html">44</a></li>
|
||||
<li><a href="._week34-bs044.html">45</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs036.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -404,7 +392,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs044.html">45</a></li>
|
||||
<li><a href="._week34-bs045.html">46</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs037.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -404,7 +392,7 @@ lectures.
|
||||
<li><a href="._week34-bs045.html">46</a></li>
|
||||
<li><a href="._week34-bs046.html">47</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs038.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -434,7 +422,7 @@ further processing. For example, convert to latex as
|
||||
<li><a href="._week34-bs046.html">47</a></li>
|
||||
<li><a href="._week34-bs047.html">48</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs039.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -399,7 +387,7 @@ developed in the 1970s, namely EISPACK and LINPACK. We describe them shortly he
|
||||
<li><a href="._week34-bs047.html">48</a></li>
|
||||
<li><a href="._week34-bs048.html">49</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs040.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -612,7 +600,7 @@ x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>l
|
||||
<li><a href="._week34-bs048.html">49</a></li>
|
||||
<li><a href="._week34-bs049.html">50</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs041.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -657,7 +645,7 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week34-bs049.html">50</a></li>
|
||||
<li><a href="._week34-bs050.html">51</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs042.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -634,7 +622,7 @@ For multidimensional arrays, we recommend strongly <a href="http://xarray.pydata
|
||||
<li><a href="._week34-bs050.html">51</a></li>
|
||||
<li><a href="._week34-bs051.html">52</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs043.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -390,7 +378,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs051.html">52</a></li>
|
||||
<li><a href="._week34-bs052.html">53</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs044.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -833,40 +821,6 @@ infile <span style="color: #666666">=</span> <span style="color: #008000">open</
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various <b>matplotlib</b> commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function. </p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #f8f8f8">
|
||||
<pre style="line-height: 125%;"><span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pylab</span> <span style="color: #008000; font-weight: bold">import</span> plt, mpl
|
||||
plt<span style="color: #666666">.</span>style<span style="color: #666666">.</span>use(<span style="color: #BA2121">'seaborn'</span>)
|
||||
mpl<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'font.family'</span>] <span style="color: #666666">=</span> <span style="color: #BA2121">'serif'</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">MakePlot</span>(x,y, styles, labels, axlabels):
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">10</span>,<span style="color: #666666">6</span>))
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(x)):
|
||||
plt<span style="color: #666666">.</span>plot(x[i], y[i], styles[i], label <span style="color: #666666">=</span> labels[i])
|
||||
plt<span style="color: #666666">.</span>xlabel(axlabels[<span style="color: #666666">0</span>])
|
||||
plt<span style="color: #666666">.</span>ylabel(axlabels[<span style="color: #666666">1</span>])
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=0</span>)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Our next step is to read the data on experimental binding energies and
|
||||
reorganize them as functions of the mass number \( A \), the number of
|
||||
protons \( Z \) and neutrons \( N \) using <b>pandas</b>. Before we do this it is
|
||||
@@ -1192,7 +1146,7 @@ Now it is time to dive more into the details of various methods. We will start w
|
||||
<li><a href="._week34-bs052.html">53</a></li>
|
||||
<li><a href="._week34-bs053.html">54</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs045.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -363,11 +351,11 @@ MathJax.Hub.Config({
|
||||
<!-- !split -->
|
||||
<h2 id="why-linear-regression-aka-ordinary-least-squares-and-family" class="anchor">Why Linear Regression (aka Ordinary Least Squares and family) </h2>
|
||||
|
||||
<p>Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \).</p>
|
||||
<p>Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\theta} \).</p>
|
||||
<ul>
|
||||
<li> Method of choice for fitting a continuous function!</li>
|
||||
<li> Gives an excellent introduction to central Machine Learning features with <b>understandable pedagogical</b> links to other methods like <b>Neural Networks</b>, <b>Support Vector Machines</b> etc</li>
|
||||
<li> Analytical expression for the fitting parameters \( \boldsymbol{\beta} \)</li>
|
||||
<li> Analytical expression for the fitting parameters \( \boldsymbol{\theta} \)</li>
|
||||
<li> Analytical expressions for statistical propertiers like mean values, variances, confidence intervals and more</li>
|
||||
<li> Analytical relation with probabilistic interpretations</li>
|
||||
<li> Easy to introduce basic concepts like bias-variance tradeoff, cross-validation, resampling and regularization techniques and many other ML topics</li>
|
||||
@@ -404,7 +392,7 @@ Similarly, <a href="https://arxiv.org/abs/1803.08823" target="_self">Mehta et al
|
||||
<li><a href="._week34-bs053.html">54</a></li>
|
||||
<li><a href="._week34-bs054.html">55</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs046.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -367,14 +355,16 @@ MathJax.Hub.Config({
|
||||
<!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
|
||||
<p>Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \).
|
||||
The first variable is called the <b>dependent</b>, the <b>outcome</b> or the <b>response</b> variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable, or simply just the <b>inputs</b>.
|
||||
The first variable \( y \) is called the the <b>outcome</b> or the <b>response</b> variable, or simply just the <b>outputs</b>.
|
||||
</p>
|
||||
|
||||
<p>The set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable, or simply just the <b>inputs</b>. <b>We will throughout the course just use inputs and outputs as names</b>.</p>
|
||||
|
||||
<p>A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) or in the more traditional sense a function \( \boldsymbol{y}(\boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with </p>
|
||||
<ul>
|
||||
<li> \( n \) cases \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> Response (target, dependent or outcome) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> \( p \) so-called explanatory (independent or predictor or feature) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). See below for more explicit examples.</li>
|
||||
<li> Response (our output) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> \( p \) so-called explanatory (independent or predictor or feature) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). These are the inputs. See below for more explicit examples.</li>
|
||||
</ul>
|
||||
<p> The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in order to infer specific dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.</p>
|
||||
</div>
|
||||
@@ -406,7 +396,7 @@ The first variable is called the <b>dependent</b>, the <b>outcome</b> or the <b>
|
||||
<li><a href="._week34-bs054.html">55</a></li>
|
||||
<li><a href="._week34-bs055.html">56</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs047.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -380,11 +368,11 @@ regression analysis is to explain \( \boldsymbol{y} \) in terms of
|
||||
f(\mathbf{X}_{i,\ast}) \). When no prior knowledge on the form of
|
||||
\( f(\cdot) \) is available, it is common to assume a linear relationship
|
||||
between \( \boldsymbol{X} \) and \( \boldsymbol{y} \). This assumption gives rise to
|
||||
the <em>linear regression model</em> where \( \boldsymbol{\beta} = [\beta_0, \ldots,
|
||||
\beta_{p-1}]^{T} \) are the <em>regression parameters</em>.
|
||||
the <em>linear regression model</em> where \( \boldsymbol{\theta} = [\theta_0, \ldots,
|
||||
\theta_{p-1}]^{T} \) are the <em>regression parameters</em>.
|
||||
</p>
|
||||
|
||||
<p>Linear regression gives us a set of analytical equations for the parameters \( \beta_j \).</p>
|
||||
<p>Linear regression gives us a set of analytical equations for the parameters \( \theta_j \).</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -414,7 +402,7 @@ the <em>linear regression model</em> where \( \boldsymbol{\beta} = [\beta_0, \ld
|
||||
<li><a href="._week34-bs055.html">56</a></li>
|
||||
<li><a href="._week34-bs056.html">57</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs048.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -413,7 +401,7 @@ so-called <a href="https://www.sciencedirect.com/science/article/pii/S0957417407
|
||||
<li><a href="._week34-bs056.html">57</a></li>
|
||||
<li><a href="._week34-bs057.html">58</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs049.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -369,7 +357,7 @@ MathJax.Hub.Config({
|
||||
|
||||
<p>Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is</p>
|
||||
$$
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \beta_j x_i^j+\epsilon_i,
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \theta_j x_i^j+\epsilon_i,
|
||||
$$
|
||||
|
||||
<p>where \( \epsilon_i \) is the error in our approximation. </p>
|
||||
@@ -402,7 +390,7 @@ $$
|
||||
<li><a href="._week34-bs057.html">58</a></li>
|
||||
<li><a href="._week34-bs058.html">59</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs050.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -368,11 +356,11 @@ MathJax.Hub.Config({
|
||||
<p>For every set of values \( y_i,x_i \) we have thus the corresponding set of equations</p>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0+\beta_1x_0^1+\beta_2x_0^2+\dots+\beta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0+\beta_1x_1^1+\beta_2x_1^2+\dots+\beta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0+\beta_1x_2^1+\beta_2x_2^2+\dots+\beta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0+\theta_1x_0^1+\theta_2x_0^2+\dots+\theta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0+\theta_1x_1^1+\theta_2x_1^2+\dots+\theta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0+\theta_1x_2^1+\theta_2x_2^2+\dots+\theta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0+\beta_1x_{n-1}^1+\beta_2x_{n-1}^2+\dots+\beta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0+\theta_1x_{n-1}^1+\theta_2x_{n-1}^2+\dots+\theta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
</div>
|
||||
@@ -404,7 +392,7 @@ $$
|
||||
<li><a href="._week34-bs058.html">59</a></li>
|
||||
<li><a href="._week34-bs059.html">60</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs051.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -372,7 +360,7 @@ $$
|
||||
|
||||
<p>and</p>
|
||||
$$
|
||||
\boldsymbol{\beta} = [\beta_0,\beta_1, \beta_2,\dots, \beta_{n-1}]^T,
|
||||
\boldsymbol{\theta} = [\theta_0,\theta_1, \theta_2,\dots, \theta_{n-1}]^T,
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
@@ -394,7 +382,7 @@ $$
|
||||
|
||||
<p>we can rewrite our equations as</p>
|
||||
$$
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}.
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\theta}+\boldsymbol{\epsilon}.
|
||||
$$
|
||||
|
||||
<p>The above design matrix is called a <a href="https://en.wikipedia.org/wiki/Vandermonde_matrix" target="_self">Vandermonde matrix</a>.</p>
|
||||
@@ -427,7 +415,7 @@ $$
|
||||
<li><a href="._week34-bs059.html">60</a></li>
|
||||
<li><a href="._week34-bs060.html">61</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs052.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -375,13 +363,13 @@ of values \( y_i,x_i \) we can then generalize the equations to
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -416,7 +404,7 @@ $$
|
||||
<li><a href="._week34-bs060.html">61</a></li>
|
||||
<li><a href="._week34-bs061.html">62</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs053.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -379,10 +367,10 @@ $$
|
||||
|
||||
<p>and without loss of generality we rewrite again our equations as</p>
|
||||
$$
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}.
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\theta}+\boldsymbol{\epsilon}.
|
||||
$$
|
||||
|
||||
<p>The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values? </p>
|
||||
<p>The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\theta} \) are our unknow quantities. How can we obtain the optimal set of \( \theta_i \) values? </p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -412,7 +400,7 @@ $$
|
||||
<li><a href="._week34-bs061.html">62</a></li>
|
||||
<li><a href="._week34-bs062.html">63</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs054.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -368,13 +356,13 @@ MathJax.Hub.Config({
|
||||
<p>We have defined the matrix \( \boldsymbol{X} \) via the equations</p>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -411,7 +399,7 @@ our matrix as \( \boldsymbol{X}\in {\mathbb{R}}^{n\times p} \), with the predict
|
||||
<li><a href="._week34-bs062.html">63</a></li>
|
||||
<li><a href="._week34-bs063.html">64</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs055.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -457,9 +445,9 @@ display(DesignMatrix)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as</p>
|
||||
<p>With \( \boldsymbol{\theta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as</p>
|
||||
$$
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>throughout these lectures. </p>
|
||||
@@ -489,7 +477,7 @@ $$
|
||||
<li><a href="._week34-bs063.html">64</a></li>
|
||||
<li><a href="._week34-bs064.html">65</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs056.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -365,19 +353,19 @@ MathJax.Hub.Config({
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<p>With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as</p>
|
||||
<p>With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\theta} \) as</p>
|
||||
$$
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely</p>
|
||||
<p>and in order to find the optimal parameters \( \theta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely</p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as</p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}.
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}.
|
||||
$$
|
||||
|
||||
<p>This function is one possible way to define the so-called cost function.</p>
|
||||
@@ -387,10 +375,10 @@ the function \( C \) as
|
||||
</p>
|
||||
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
C(\boldsymbol{\theta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
$$
|
||||
|
||||
<p>since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out. </p>
|
||||
<p>since when taking the first derivative with respect to the unknown parameters \( \theta \), the factor of \( 2 \) cancels out. </p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -420,7 +408,7 @@ $$
|
||||
<li><a href="._week34-bs064.html">65</a></li>
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs057.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -368,14 +356,14 @@ MathJax.Hub.Config({
|
||||
|
||||
<p>The function </p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\},
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value.
|
||||
When linking (see the discussion below) with the maximum likelihood approach below, we will indeed interpret \( y_i \) as a mean value
|
||||
</p>
|
||||
$$
|
||||
y_{i}=\langle y_i \rangle = \beta_0x_{i,0}+\beta_1x_{i,1}+\beta_2x_{i,2}+\dots+\beta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
y_{i}=\langle y_i \rangle = \theta_0x_{i,0}+\theta_1x_{i,1}+\theta_2x_{i,2}+\dots+\theta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
$$
|
||||
|
||||
<p>where \( \langle y_i \rangle \) is the mean value. Keep in mind also that
|
||||
@@ -388,25 +376,25 @@ the standard deviation discussed earlier. In the discussion here we
|
||||
will treat \( y_i \) as our exact value for the response variable.
|
||||
</p>
|
||||
|
||||
<p>In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem</p>
|
||||
<p>In order to find the parameters \( \theta_i \) we will then minimize the spread of \( C(\boldsymbol{\theta}) \), that is we are going to solve the problem</p>
|
||||
$$
|
||||
{\displaystyle \min_{\boldsymbol{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}.
|
||||
{\displaystyle \min_{\boldsymbol{\theta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}.
|
||||
$$
|
||||
|
||||
<p>In practical terms it means we will require</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
$$
|
||||
|
||||
<p>which results in</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>or in a matrix-vector form as</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right).
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right).
|
||||
$$
|
||||
</div>
|
||||
</div>
|
||||
@@ -437,7 +425,7 @@ $$
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs058.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -367,17 +355,17 @@ MathJax.Hub.Config({
|
||||
<!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<p>We can rewrite</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right),
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right),
|
||||
$$
|
||||
|
||||
<p>as</p>
|
||||
$$
|
||||
\boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution</p>
|
||||
$$
|
||||
\boldsymbol{\beta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
\boldsymbol{\theta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
$$
|
||||
|
||||
<p>We note also that since our design matrix is defined as \( \boldsymbol{X}\in
|
||||
@@ -427,8 +415,6 @@ allow for the usage of direct linear algebra methods such as <b>LU</b> decomposi
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs059.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -367,20 +355,20 @@ MathJax.Hub.Config({
|
||||
<!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<p>The residuals \( \boldsymbol{\epsilon} \) are in turn given by</p>
|
||||
$$
|
||||
\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and with </p>
|
||||
$$
|
||||
\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0,
|
||||
\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0,
|
||||
$$
|
||||
|
||||
<p>we have</p>
|
||||
$$
|
||||
\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0,
|
||||
\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0,
|
||||
$$
|
||||
|
||||
<p>meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.</p>
|
||||
<p>meaning that the solution for \( \boldsymbol{\theta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -410,9 +398,6 @@ $$
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs068.html">69</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs060.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -363,7 +351,7 @@ MathJax.Hub.Config({
|
||||
<!-- !split -->
|
||||
<h2 id="own-code-for-ordinary-least-squares" class="anchor">Own code for Ordinary Least Squares </h2>
|
||||
|
||||
<p>It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to
|
||||
<p>It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\theta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to
|
||||
write
|
||||
</p>
|
||||
|
||||
@@ -475,10 +463,6 @@ plt<span style="color: #666666">.</span>show()
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs068.html">69</a></li>
|
||||
<li><a href="._week34-bs069.html">70</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs061.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -490,9 +478,6 @@ Since we are not using <b>Scikit-Learn</b> here we can define our own \( R2 \) f
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs068.html">69</a></li>
|
||||
<li><a href="._week34-bs069.html">70</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs062.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -381,7 +369,7 @@ as
|
||||
</p>
|
||||
|
||||
$$
|
||||
\chi^2(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
\chi^2(\boldsymbol{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements. </p>
|
||||
@@ -409,9 +397,6 @@ $$
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs068.html">69</a></li>
|
||||
<li><a href="._week34-bs069.html">70</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs063.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -366,19 +354,19 @@ MathJax.Hub.Config({
|
||||
<div class="panel-body">
|
||||
<!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
|
||||
<p>In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring</p>
|
||||
<p>In order to find the parameters \( \theta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\theta}) \) by requiring</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\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,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0,
|
||||
$$
|
||||
|
||||
<p>which results in</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\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,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>or in a matrix-vector form as</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right).
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\theta}\right).
|
||||
$$
|
||||
|
||||
<p>where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \). </p>
|
||||
@@ -405,9 +393,6 @@ $$
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs068.html">69</a></li>
|
||||
<li><a href="._week34-bs069.html">70</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs064.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -368,17 +356,17 @@ MathJax.Hub.Config({
|
||||
|
||||
<p>We can rewrite</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right),
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\theta}\right),
|
||||
$$
|
||||
|
||||
<p>as</p>
|
||||
$$
|
||||
\boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\beta},
|
||||
\boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution</p>
|
||||
$$
|
||||
\boldsymbol{\beta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}.
|
||||
\boldsymbol{\theta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}.
|
||||
$$
|
||||
</div>
|
||||
</div>
|
||||
@@ -402,9 +390,6 @@ $$
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs068.html">69</a></li>
|
||||
<li><a href="._week34-bs069.html">70</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs065.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -371,19 +359,19 @@ $$
|
||||
\boldsymbol{H} = \left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1},
|
||||
$$
|
||||
|
||||
<p>we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))</p>
|
||||
<p>we have then the following expression for the parameters \( \theta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))</p>
|
||||
$$
|
||||
\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}
|
||||
\theta_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}
|
||||
$$
|
||||
|
||||
<p>We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise)</p>
|
||||
<p>We state without proof the expression for the uncertainty in the parameters \( \theta_j \) as (we leave this as an exercise)</p>
|
||||
$$
|
||||
\sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2,
|
||||
\sigma^2(\theta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \theta_j}{\partial y_i}\right)^2,
|
||||
$$
|
||||
|
||||
<p>resulting in </p>
|
||||
$$
|
||||
\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}!
|
||||
\sigma^2(\theta_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>
|
||||
@@ -406,9 +394,6 @@ $$
|
||||
<li class="active"><a href="._week34-bs065.html">66</a></li>
|
||||
<li><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs068.html">69</a></li>
|
||||
<li><a href="._week34-bs069.html">70</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs066.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -367,17 +355,17 @@ MathJax.Hub.Config({
|
||||
<!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
|
||||
<p>The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write</p>
|
||||
$$
|
||||
y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i.
|
||||
y=y(x) \rightarrow y(x_i) \approx \theta_0+\theta_1 x_i.
|
||||
$$
|
||||
|
||||
<p>By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by</p>
|
||||
<p>By computing the derivatives of \( \chi^2 \) with respect to \( \theta_0 \) and \( \theta_1 \) show that these are given by</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
$$
|
||||
</div>
|
||||
</div>
|
||||
@@ -399,9 +387,6 @@ $$
|
||||
<li><a href="._week34-bs065.html">66</a></li>
|
||||
<li class="active"><a href="._week34-bs066.html">67</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs068.html">69</a></li>
|
||||
<li><a href="._week34-bs069.html">70</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -232,16 +232,7 @@ doconce format html week34.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -347,9 +338,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs067.html#the-chi-2-function" style="font-size: 80%;"><b>The \( \chi^2 \) function</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs068.html#fitting-an-equation-of-state-for-dense-nuclear-matter" style="font-size: 80%;"><b>Fitting an Equation of State for Dense Nuclear Matter</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs069.html#the-code" style="font-size: 80%;"><b>The code</b></a></li>
|
||||
<!-- navigation toc: --> <li><a href="._week34-bs070.html#splitting-our-data-in-training-and-test-data" style="font-size: 80%;"><b>Splitting our Data in Training and Test data</b></a></li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
@@ -401,7 +389,7 @@ MathJax.Hub.Config({
|
||||
<li><a href="._week34-bs008.html">9</a></li>
|
||||
<li><a href="._week34-bs009.html">10</a></li>
|
||||
<li><a href="">...</a></li>
|
||||
<li><a href="._week34-bs070.html">71</a></li>
|
||||
<li><a href="._week34-bs067.html">68</a></li>
|
||||
<li><a href="._week34-bs001.html">»</a></li>
|
||||
</ul>
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
|
||||
@@ -2226,40 +2226,6 @@ infile = <span style="color: #658b00">open</span>(data_path(<span style="color:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various <b>matplotlib</b> commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function. </p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="font-size: 80%; line-height: 125%;"><span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">pylab</span> <span style="color: #8B008B; font-weight: bold">import</span> plt, mpl
|
||||
plt.style.use(<span style="color: #CD5555">'seaborn'</span>)
|
||||
mpl.rcParams[<span style="color: #CD5555">'font.family'</span>] = <span style="color: #CD5555">'serif'</span>
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">MakePlot</span>(x,y, styles, labels, axlabels):
|
||||
plt.figure(figsize=(<span style="color: #B452CD">10</span>,<span style="color: #B452CD">6</span>))
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #658b00">len</span>(x)):
|
||||
plt.plot(x[i], y[i], styles[i], label = labels[i])
|
||||
plt.xlabel(axlabels[<span style="color: #B452CD">0</span>])
|
||||
plt.ylabel(axlabels[<span style="color: #B452CD">1</span>])
|
||||
plt.legend(loc=<span style="color: #B452CD">0</span>)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Our next step is to read the data on experimental binding energies and
|
||||
reorganize them as functions of the mass number \( A \), the number of
|
||||
protons \( Z \) and neutrons \( N \) using <b>pandas</b>. Before we do this it is
|
||||
@@ -2564,11 +2530,11 @@ Now it is time to dive more into the details of various methods. We will start w
|
||||
<section>
|
||||
<h2 id="why-linear-regression-aka-ordinary-least-squares-and-family">Why Linear Regression (aka Ordinary Least Squares and family) </h2>
|
||||
|
||||
<p>Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \).</p>
|
||||
<p>Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\theta} \).</p>
|
||||
<ul>
|
||||
<p><li> Method of choice for fitting a continuous function!</li>
|
||||
<p><li> Gives an excellent introduction to central Machine Learning features with <b>understandable pedagogical</b> links to other methods like <b>Neural Networks</b>, <b>Support Vector Machines</b> etc</li>
|
||||
<p><li> Analytical expression for the fitting parameters \( \boldsymbol{\beta} \)</li>
|
||||
<p><li> Analytical expression for the fitting parameters \( \boldsymbol{\theta} \)</li>
|
||||
<p><li> Analytical expressions for statistical propertiers like mean values, variances, confidence intervals and more</li>
|
||||
<p><li> Analytical relation with probabilistic interpretations</li>
|
||||
<p><li> Easy to introduce basic concepts like bias-variance tradeoff, cross-validation, resampling and regularization techniques and many other ML topics</li>
|
||||
@@ -2589,14 +2555,16 @@ Similarly, <a href="https://arxiv.org/abs/1803.08823" target="_blank">Mehta et a
|
||||
<p>
|
||||
|
||||
<p>Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \).
|
||||
The first variable is called the <b>dependent</b>, the <b>outcome</b> or the <b>response</b> variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable, or simply just the <b>inputs</b>.
|
||||
The first variable \( y \) is called the the <b>outcome</b> or the <b>response</b> variable, or simply just the <b>outputs</b>.
|
||||
</p>
|
||||
|
||||
<p>The set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable, or simply just the <b>inputs</b>. <b>We will throughout the course just use inputs and outputs as names</b>.</p>
|
||||
|
||||
<p>A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) or in the more traditional sense a function \( \boldsymbol{y}(\boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with </p>
|
||||
<ul>
|
||||
<p><li> \( n \) cases \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<p><li> Response (target, dependent or outcome) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<p><li> \( p \) so-called explanatory (independent or predictor or feature) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). See below for more explicit examples.</li>
|
||||
<p><li> Response (our output) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<p><li> \( p \) so-called explanatory (independent or predictor or feature) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). These are the inputs. See below for more explicit examples.</li>
|
||||
</ul>
|
||||
<p>
|
||||
<p> The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in order to infer specific dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.</p>
|
||||
@@ -2623,11 +2591,11 @@ regression analysis is to explain \( \boldsymbol{y} \) in terms of
|
||||
f(\mathbf{X}_{i,\ast}) \). When no prior knowledge on the form of
|
||||
\( f(\cdot) \) is available, it is common to assume a linear relationship
|
||||
between \( \boldsymbol{X} \) and \( \boldsymbol{y} \). This assumption gives rise to
|
||||
the <em>linear regression model</em> where \( \boldsymbol{\beta} = [\beta_0, \ldots,
|
||||
\beta_{p-1}]^{T} \) are the <em>regression parameters</em>.
|
||||
the <em>linear regression model</em> where \( \boldsymbol{\theta} = [\theta_0, \ldots,
|
||||
\theta_{p-1}]^{T} \) are the <em>regression parameters</em>.
|
||||
</p>
|
||||
|
||||
<p>Linear regression gives us a set of analytical equations for the parameters \( \beta_j \).</p>
|
||||
<p>Linear regression gives us a set of analytical equations for the parameters \( \theta_j \).</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -2670,7 +2638,7 @@ so-called <a href="https://www.sciencedirect.com/science/article/pii/S0957417407
|
||||
<p>Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is</p>
|
||||
<p> <br>
|
||||
$$
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \beta_j x_i^j+\epsilon_i,
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \theta_j x_i^j+\epsilon_i,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -2687,11 +2655,11 @@ $$
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0+\beta_1x_0^1+\beta_2x_0^2+\dots+\beta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0+\beta_1x_1^1+\beta_2x_1^2+\dots+\beta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0+\beta_1x_2^1+\beta_2x_2^2+\dots+\beta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0+\theta_1x_0^1+\theta_2x_0^2+\dots+\theta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0+\theta_1x_1^1+\theta_2x_1^2+\dots+\theta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0+\theta_1x_2^1+\theta_2x_2^2+\dots+\theta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0+\beta_1x_{n-1}^1+\beta_2x_{n-1}^2+\dots+\beta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0+\theta_1x_{n-1}^1+\theta_2x_{n-1}^2+\dots+\theta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2713,7 +2681,7 @@ $$
|
||||
<p>and</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{\beta} = [\beta_0,\beta_1, \beta_2,\dots, \beta_{n-1}]^T,
|
||||
\boldsymbol{\theta} = [\theta_0,\theta_1, \theta_2,\dots, \theta_{n-1}]^T,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -2741,7 +2709,7 @@ $$
|
||||
<p>we can rewrite our equations as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}.
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\theta}+\boldsymbol{\epsilon}.
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -2765,13 +2733,13 @@ of values \( y_i,x_i \) we can then generalize the equations to
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2803,11 +2771,11 @@ $$
|
||||
<p>and without loss of generality we rewrite again our equations as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}.
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\theta}+\boldsymbol{\epsilon}.
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values? </p>
|
||||
<p>The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\theta} \) are our unknow quantities. How can we obtain the optimal set of \( \theta_i \) values? </p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -2820,13 +2788,13 @@ $$
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2935,10 +2903,10 @@ display(DesignMatrix)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as</p>
|
||||
<p>With \( \boldsymbol{\theta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -2950,24 +2918,24 @@ $$
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
<p>With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as</p>
|
||||
<p>With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\theta} \) as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely</p>
|
||||
<p>and in order to find the optimal parameters \( \theta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely</p>
|
||||
<p> <br>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}.
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}.
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -2979,11 +2947,11 @@ the function \( C \) as
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
C(\boldsymbol{\theta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out. </p>
|
||||
<p>since when taking the first derivative with respect to the unknown parameters \( \theta \), the factor of \( 2 \) cancels out. </p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -2996,7 +2964,7 @@ $$
|
||||
<p>The function </p>
|
||||
<p> <br>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\},
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -3005,7 +2973,7 @@ When linking (see the discussion below) with the maximum likelihood approach bel
|
||||
</p>
|
||||
<p> <br>
|
||||
$$
|
||||
y_{i}=\langle y_i \rangle = \beta_0x_{i,0}+\beta_1x_{i,1}+\beta_2x_{i,2}+\dots+\beta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
y_{i}=\langle y_i \rangle = \theta_0x_{i,0}+\theta_1x_{i,1}+\theta_2x_{i,2}+\dots+\theta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -3019,32 +2987,32 @@ the standard deviation discussed earlier. In the discussion here we
|
||||
will treat \( y_i \) as our exact value for the response variable.
|
||||
</p>
|
||||
|
||||
<p>In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem</p>
|
||||
<p>In order to find the parameters \( \theta_i \) we will then minimize the spread of \( C(\boldsymbol{\theta}) \), that is we are going to solve the problem</p>
|
||||
<p> <br>
|
||||
$$
|
||||
{\displaystyle \min_{\boldsymbol{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}.
|
||||
{\displaystyle \min_{\boldsymbol{\theta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}.
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>In practical terms it means we will require</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>which results in</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>or in a matrix-vector form as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right).
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right).
|
||||
$$
|
||||
<p> <br>
|
||||
</div>
|
||||
@@ -3058,21 +3026,21 @@ $$
|
||||
<p>We can rewrite</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right),
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right),
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{\beta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
\boldsymbol{\theta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -3105,25 +3073,25 @@ allow for the usage of direct linear algebra methods such as <b>LU</b> decomposi
|
||||
<p>The residuals \( \boldsymbol{\epsilon} \) are in turn given by</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>and with </p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0,
|
||||
\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>we have</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0,
|
||||
\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.</p>
|
||||
<p>meaning that the solution for \( \boldsymbol{\theta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.</p>
|
||||
</div>
|
||||
|
||||
<p>Let us now return to our nuclear binding energies and simply code the above equations. </p>
|
||||
@@ -3132,7 +3100,7 @@ $$
|
||||
<section>
|
||||
<h2 id="own-code-for-ordinary-least-squares">Own code for Ordinary Least Squares </h2>
|
||||
|
||||
<p>It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to
|
||||
<p>It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\theta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to
|
||||
write
|
||||
</p>
|
||||
|
||||
@@ -3353,7 +3321,7 @@ as
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\chi^2(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
\chi^2(\boldsymbol{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -3367,24 +3335,24 @@ $$
|
||||
<b></b>
|
||||
<p>
|
||||
|
||||
<p>In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring</p>
|
||||
<p>In order to find the parameters \( \theta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\theta}) \) by requiring</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\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,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>which results in</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\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,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>or in a matrix-vector form as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right).
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\theta}\right).
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -3401,21 +3369,21 @@ $$
|
||||
<p>We can rewrite</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right),
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\theta}\right),
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>as</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\beta},
|
||||
\boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\theta},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\boldsymbol{\beta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}.
|
||||
\boldsymbol{\theta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}.
|
||||
$$
|
||||
<p> <br>
|
||||
</div>
|
||||
@@ -3434,24 +3402,24 @@ $$
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))</p>
|
||||
<p>we have then the following expression for the parameters \( \theta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\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}
|
||||
\theta_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}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise)</p>
|
||||
<p>We state without proof the expression for the uncertainty in the parameters \( \theta_j \) as (we leave this as an exercise)</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2,
|
||||
\sigma^2(\theta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \theta_j}{\partial y_i}\right)^2,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>resulting in </p>
|
||||
<p> <br>
|
||||
$$
|
||||
\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}!
|
||||
\sigma^2(\theta_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> <br>
|
||||
</div>
|
||||
@@ -3465,21 +3433,21 @@ $$
|
||||
<p>The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write</p>
|
||||
<p> <br>
|
||||
$$
|
||||
y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i.
|
||||
y=y(x) \rightarrow y(x_i) \approx \theta_0+\theta_1 x_i.
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by</p>
|
||||
<p>By computing the derivatives of \( \chi^2 \) with respect to \( \theta_0 \) and \( \theta_1 \) show that these are given by</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>and</p>
|
||||
<p> <br>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
$$
|
||||
<p> <br>
|
||||
</div>
|
||||
@@ -3528,270 +3496,24 @@ $$
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\beta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2},
|
||||
\theta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2},
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\beta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}.
|
||||
\theta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}.
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>This approach (different linear and non-linear regression) suffers
|
||||
often from both being underdetermined and overdetermined in the
|
||||
unknown coefficients \( \beta_i \). A better approach is to use the
|
||||
unknown coefficients \( \theta_i \). A better approach is to use the
|
||||
Singular Value Decomposition (SVD) method discussed next week.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="fitting-an-equation-of-state-for-dense-nuclear-matter">Fitting an Equation of State for Dense Nuclear Matter </h2>
|
||||
|
||||
<p>Before we continue, let us introduce yet another example. We are going to fit the
|
||||
nuclear equation of state using results from many-body calculations.
|
||||
The equation of state we have made available here, as function of
|
||||
density, has been derived using modern nucleon-nucleon potentials with
|
||||
<a href="https://www.sciencedirect.com/science/article/pii/S0370157399001106" target="_blank">the addition of three-body
|
||||
forces</a>. This
|
||||
time the file is presented as a standard <b>csv</b> file.
|
||||
</p>
|
||||
|
||||
<p>The beginning of the Python code here is similar to what you have seen
|
||||
before, with the same initializations and declarations. We use also
|
||||
<b>pandas</b> again, rather extensively in order to organize our data.
|
||||
</p>
|
||||
|
||||
<p>The difference now is that we use <b>Scikit-Learn's</b> regression tools
|
||||
instead of our own matrix inversion implementation. Furthermore, we
|
||||
sneak in <b>Ridge</b> regression (to be discussed below) which includes a
|
||||
hyperparameter \( \lambda \), also to be explained below.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="the-code">The code </h2>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="font-size: 80%; line-height: 125%;"><span style="color: #228B22"># Common imports</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">os</span>
|
||||
<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">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</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">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">import</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">skl</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.metrics</span> <span style="color: #8B008B; font-weight: bold">import</span> mean_squared_error, r2_score, mean_absolute_error
|
||||
|
||||
<span style="color: #228B22"># Where to save the figures and data files</span>
|
||||
PROJECT_ROOT_DIR = <span style="color: #CD5555">"Results"</span>
|
||||
FIGURE_ID = <span style="color: #CD5555">"Results/FigureFiles"</span>
|
||||
DATA_ID = <span style="color: #CD5555">"DataFiles/"</span>
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(PROJECT_ROOT_DIR):
|
||||
os.mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(FIGURE_ID):
|
||||
os.makedirs(FIGURE_ID)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(DATA_ID):
|
||||
os.makedirs(DATA_ID)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">image_path</span>(fig_id):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(FIGURE_ID, fig_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">data_path</span>(dat_id):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">save_fig</span>(fig_id):
|
||||
plt.savefig(image_path(fig_id) + <span style="color: #CD5555">".png"</span>, <span style="color: #658b00">format</span>=<span style="color: #CD5555">'png'</span>)
|
||||
|
||||
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">"EoS.csv"</span>),<span style="color: #CD5555">'r'</span>)
|
||||
|
||||
<span style="color: #228B22"># Read the EoS data as csv file and organize the data into two arrays with density and energies</span>
|
||||
EoS = pd.read_csv(infile, names=(<span style="color: #CD5555">'Density'</span>, <span style="color: #CD5555">'Energy'</span>))
|
||||
EoS[<span style="color: #CD5555">'Energy'</span>] = pd.to_numeric(EoS[<span style="color: #CD5555">'Energy'</span>], errors=<span style="color: #CD5555">'coerce'</span>)
|
||||
EoS = EoS.dropna()
|
||||
Energies = EoS[<span style="color: #CD5555">'Energy'</span>]
|
||||
Density = EoS[<span style="color: #CD5555">'Density'</span>]
|
||||
<span style="color: #228B22"># The design matrix now as function of various polytrops</span>
|
||||
X = np.zeros((<span style="color: #658b00">len</span>(Density),<span style="color: #B452CD">4</span>))
|
||||
X[:,<span style="color: #B452CD">3</span>] = Density**(<span style="color: #B452CD">4.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
X[:,<span style="color: #B452CD">2</span>] = Density
|
||||
X[:,<span style="color: #B452CD">1</span>] = Density**(<span style="color: #B452CD">2.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
X[:,<span style="color: #B452CD">0</span>] = <span style="color: #B452CD">1</span>
|
||||
|
||||
<span style="color: #228B22"># We use now Scikit-Learn's linear regressor and ridge regressor</span>
|
||||
<span style="color: #228B22"># OLS part</span>
|
||||
clf = skl.LinearRegression().fit(X, Energies)
|
||||
ytilde = clf.predict(X)
|
||||
EoS[<span style="color: #CD5555">'Eols'</span>] = ytilde
|
||||
<span style="color: #228B22"># The mean squared error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Mean squared error: %.2f"</span> % mean_squared_error(Energies, ytilde))
|
||||
<span style="color: #228B22"># Explained variance score: 1 is perfect prediction </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Variance score: %.2f'</span> % r2_score(Energies, ytilde))
|
||||
<span style="color: #228B22"># Mean absolute error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Mean absolute error: %.2f'</span> % mean_absolute_error(Energies, ytilde))
|
||||
<span style="color: #658b00">print</span>(clf.coef_, clf.intercept_)
|
||||
|
||||
<span style="color: #228B22"># The Ridge regression with a hyperparameter lambda = 0.1</span>
|
||||
_lambda = <span style="color: #B452CD">0.1</span>
|
||||
clf_ridge = skl.Ridge(alpha=_lambda).fit(X, Energies)
|
||||
yridge = clf_ridge.predict(X)
|
||||
EoS[<span style="color: #CD5555">'Eridge'</span>] = yridge
|
||||
<span style="color: #228B22"># The mean squared error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Mean squared error: %.2f"</span> % mean_squared_error(Energies, yridge))
|
||||
<span style="color: #228B22"># Explained variance score: 1 is perfect prediction </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Variance score: %.2f'</span> % r2_score(Energies, yridge))
|
||||
<span style="color: #228B22"># Mean absolute error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Mean absolute error: %.2f'</span> % mean_absolute_error(Energies, yridge))
|
||||
<span style="color: #658b00">print</span>(clf_ridge.coef_, clf_ridge.intercept_)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_xlabel(<span style="color: #CD5555">r'$\rho[\mathrm{fm}^{-3}]$'</span>)
|
||||
ax.set_ylabel(<span style="color: #CD5555">r'Energy per particle'</span>)
|
||||
ax.plot(EoS[<span style="color: #CD5555">'Density'</span>], EoS[<span style="color: #CD5555">'Energy'</span>], alpha=<span style="color: #B452CD">0.7</span>, lw=<span style="color: #B452CD">2</span>,
|
||||
label=<span style="color: #CD5555">'Theoretical data'</span>)
|
||||
ax.plot(EoS[<span style="color: #CD5555">'Density'</span>], EoS[<span style="color: #CD5555">'Eols'</span>], alpha=<span style="color: #B452CD">0.7</span>, lw=<span style="color: #B452CD">2</span>, c=<span style="color: #CD5555">'m'</span>,
|
||||
label=<span style="color: #CD5555">'OLS'</span>)
|
||||
ax.plot(EoS[<span style="color: #CD5555">'Density'</span>], EoS[<span style="color: #CD5555">'Eridge'</span>], alpha=<span style="color: #B452CD">0.7</span>, lw=<span style="color: #B452CD">2</span>, c=<span style="color: #CD5555">'g'</span>,
|
||||
label=<span style="color: #CD5555">'Ridge $\lambda = 0.1$'</span>)
|
||||
ax.legend()
|
||||
save_fig(<span style="color: #CD5555">"EoSfitting"</span>)
|
||||
plt.show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>The above simple polynomial in density \( \rho \) gives an excellent fit
|
||||
to the data.
|
||||
</p>
|
||||
|
||||
<p>We note also that there is a small deviation between the
|
||||
standard OLS and the Ridge regression at higher densities. We discuss this in more detail
|
||||
below.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="splitting-our-data-in-training-and-test-data">Splitting our Data in Training and Test data </h2>
|
||||
|
||||
<p>It is normal in essentially all Machine Learning studies to split the
|
||||
data in a training set and a test set (sometimes also an additional
|
||||
validation set). <b>Scikit-Learn</b> has an own function for this. There
|
||||
is no explicit recipe for how much data should be included as training
|
||||
data and say test data. An accepted rule of thumb is to use
|
||||
approximately \( 2/3 \) to \( 4/5 \) of the data as training data. We will
|
||||
postpone a discussion of this splitting to the end of these notes and
|
||||
our discussion of the so-called <b>bias-variance</b> tradeoff. Here we
|
||||
limit ourselves to repeat the above equation of state fitting example
|
||||
but now splitting the data into a training set and a test set.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="font-size: 80%; line-height: 125%;"><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">os</span>
|
||||
<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">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</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.model_selection</span> <span style="color: #8B008B; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #228B22"># Where to save the figures and data files</span>
|
||||
PROJECT_ROOT_DIR = <span style="color: #CD5555">"Results"</span>
|
||||
FIGURE_ID = <span style="color: #CD5555">"Results/FigureFiles"</span>
|
||||
DATA_ID = <span style="color: #CD5555">"DataFiles/"</span>
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(PROJECT_ROOT_DIR):
|
||||
os.mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(FIGURE_ID):
|
||||
os.makedirs(FIGURE_ID)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(DATA_ID):
|
||||
os.makedirs(DATA_ID)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">image_path</span>(fig_id):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(FIGURE_ID, fig_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">data_path</span>(dat_id):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">save_fig</span>(fig_id):
|
||||
plt.savefig(image_path(fig_id) + <span style="color: #CD5555">".png"</span>, <span style="color: #658b00">format</span>=<span style="color: #CD5555">'png'</span>)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">R2</span>(y_data, y_model):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> <span style="color: #B452CD">1</span> - np.sum((y_data - y_model) ** <span style="color: #B452CD">2</span>) / np.sum((y_data - np.mean(y_data)) ** <span style="color: #B452CD">2</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">MSE</span>(y_data,y_model):
|
||||
n = np.size(y_model)
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> np.sum((y_data-y_model)**<span style="color: #B452CD">2</span>)/n
|
||||
|
||||
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">"EoS.csv"</span>),<span style="color: #CD5555">'r'</span>)
|
||||
|
||||
<span style="color: #228B22"># Read the EoS data as csv file and organized into two arrays with density and energies</span>
|
||||
EoS = pd.read_csv(infile, names=(<span style="color: #CD5555">'Density'</span>, <span style="color: #CD5555">'Energy'</span>))
|
||||
EoS[<span style="color: #CD5555">'Energy'</span>] = pd.to_numeric(EoS[<span style="color: #CD5555">'Energy'</span>], errors=<span style="color: #CD5555">'coerce'</span>)
|
||||
EoS = EoS.dropna()
|
||||
Energies = EoS[<span style="color: #CD5555">'Energy'</span>]
|
||||
Density = EoS[<span style="color: #CD5555">'Density'</span>]
|
||||
<span style="color: #228B22"># The design matrix now as function of various polytrops</span>
|
||||
X = np.zeros((<span style="color: #658b00">len</span>(Density),<span style="color: #B452CD">5</span>))
|
||||
X[:,<span style="color: #B452CD">0</span>] = <span style="color: #B452CD">1</span>
|
||||
X[:,<span style="color: #B452CD">1</span>] = Density**(<span style="color: #B452CD">2.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
X[:,<span style="color: #B452CD">2</span>] = Density
|
||||
X[:,<span style="color: #B452CD">3</span>] = Density**(<span style="color: #B452CD">4.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
X[:,<span style="color: #B452CD">4</span>] = Density**(<span style="color: #B452CD">5.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
<span style="color: #228B22"># We split the data in test and training data</span>
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, Energies, test_size=<span style="color: #B452CD">0.2</span>)
|
||||
<span style="color: #228B22"># matrix inversion to find beta</span>
|
||||
beta = np.linalg.inv(X_train.T.dot(X_train)).dot(X_train.T).dot(y_train)
|
||||
<span style="color: #228B22"># and then make the prediction</span>
|
||||
ytilde = X_train @ beta
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Training R2"</span>)
|
||||
<span style="color: #658b00">print</span>(R2(y_train,ytilde))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Training MSE"</span>)
|
||||
<span style="color: #658b00">print</span>(MSE(y_train,ytilde))
|
||||
ypredict = X_test @ beta
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test R2"</span>)
|
||||
<span style="color: #658b00">print</span>(R2(y_test,ypredict))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test MSE"</span>)
|
||||
<span style="color: #658b00">print</span>(MSE(y_test,ypredict))
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
</div> <!-- class="slides" -->
|
||||
|
||||
@@ -259,16 +259,7 @@ div.toc p,a {
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -2207,40 +2198,6 @@ infile = <span style="color: #658b00">open</span>(data_path(<span style="color:
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various <b>matplotlib</b> commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function. </p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="line-height: 125%;"><span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">pylab</span> <span style="color: #8B008B; font-weight: bold">import</span> plt, mpl
|
||||
plt.style.use(<span style="color: #CD5555">'seaborn'</span>)
|
||||
mpl.rcParams[<span style="color: #CD5555">'font.family'</span>] = <span style="color: #CD5555">'serif'</span>
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">MakePlot</span>(x,y, styles, labels, axlabels):
|
||||
plt.figure(figsize=(<span style="color: #B452CD">10</span>,<span style="color: #B452CD">6</span>))
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #658b00">len</span>(x)):
|
||||
plt.plot(x[i], y[i], styles[i], label = labels[i])
|
||||
plt.xlabel(axlabels[<span style="color: #B452CD">0</span>])
|
||||
plt.ylabel(axlabels[<span style="color: #B452CD">1</span>])
|
||||
plt.legend(loc=<span style="color: #B452CD">0</span>)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Our next step is to read the data on experimental binding energies and
|
||||
reorganize them as functions of the mass number \( A \), the number of
|
||||
protons \( Z \) and neutrons \( N \) using <b>pandas</b>. Before we do this it is
|
||||
@@ -2544,11 +2501,11 @@ Now it is time to dive more into the details of various methods. We will start w
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="why-linear-regression-aka-ordinary-least-squares-and-family">Why Linear Regression (aka Ordinary Least Squares and family) </h2>
|
||||
|
||||
<p>Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \).</p>
|
||||
<p>Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\theta} \).</p>
|
||||
<ul>
|
||||
<li> Method of choice for fitting a continuous function!</li>
|
||||
<li> Gives an excellent introduction to central Machine Learning features with <b>understandable pedagogical</b> links to other methods like <b>Neural Networks</b>, <b>Support Vector Machines</b> etc</li>
|
||||
<li> Analytical expression for the fitting parameters \( \boldsymbol{\beta} \)</li>
|
||||
<li> Analytical expression for the fitting parameters \( \boldsymbol{\theta} \)</li>
|
||||
<li> Analytical expressions for statistical propertiers like mean values, variances, confidence intervals and more</li>
|
||||
<li> Analytical relation with probabilistic interpretations</li>
|
||||
<li> Easy to introduce basic concepts like bias-variance tradeoff, cross-validation, resampling and regularization techniques and many other ML topics</li>
|
||||
@@ -2567,14 +2524,16 @@ Similarly, <a href="https://arxiv.org/abs/1803.08823" target="_blank">Mehta et a
|
||||
<p>
|
||||
|
||||
<p>Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \).
|
||||
The first variable is called the <b>dependent</b>, the <b>outcome</b> or the <b>response</b> variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable, or simply just the <b>inputs</b>.
|
||||
The first variable \( y \) is called the the <b>outcome</b> or the <b>response</b> variable, or simply just the <b>outputs</b>.
|
||||
</p>
|
||||
|
||||
<p>The set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable, or simply just the <b>inputs</b>. <b>We will throughout the course just use inputs and outputs as names</b>.</p>
|
||||
|
||||
<p>A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) or in the more traditional sense a function \( \boldsymbol{y}(\boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with </p>
|
||||
<ul>
|
||||
<li> \( n \) cases \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> Response (target, dependent or outcome) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> \( p \) so-called explanatory (independent or predictor or feature) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). See below for more explicit examples.</li>
|
||||
<li> Response (our output) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> \( p \) so-called explanatory (independent or predictor or feature) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). These are the inputs. See below for more explicit examples.</li>
|
||||
</ul>
|
||||
<p> The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in order to infer specific dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.</p>
|
||||
</div>
|
||||
@@ -2600,11 +2559,11 @@ regression analysis is to explain \( \boldsymbol{y} \) in terms of
|
||||
f(\mathbf{X}_{i,\ast}) \). When no prior knowledge on the form of
|
||||
\( f(\cdot) \) is available, it is common to assume a linear relationship
|
||||
between \( \boldsymbol{X} \) and \( \boldsymbol{y} \). This assumption gives rise to
|
||||
the <em>linear regression model</em> where \( \boldsymbol{\beta} = [\beta_0, \ldots,
|
||||
\beta_{p-1}]^{T} \) are the <em>regression parameters</em>.
|
||||
the <em>linear regression model</em> where \( \boldsymbol{\theta} = [\theta_0, \ldots,
|
||||
\theta_{p-1}]^{T} \) are the <em>regression parameters</em>.
|
||||
</p>
|
||||
|
||||
<p>Linear regression gives us a set of analytical equations for the parameters \( \beta_j \).</p>
|
||||
<p>Linear regression gives us a set of analytical equations for the parameters \( \theta_j \).</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2644,7 +2603,7 @@ so-called <a href="https://www.sciencedirect.com/science/article/pii/S0957417407
|
||||
|
||||
<p>Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is</p>
|
||||
$$
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \beta_j x_i^j+\epsilon_i,
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \theta_j x_i^j+\epsilon_i,
|
||||
$$
|
||||
|
||||
<p>where \( \epsilon_i \) is the error in our approximation. </p>
|
||||
@@ -2659,11 +2618,11 @@ $$
|
||||
<p>For every set of values \( y_i,x_i \) we have thus the corresponding set of equations</p>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0+\beta_1x_0^1+\beta_2x_0^2+\dots+\beta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0+\beta_1x_1^1+\beta_2x_1^2+\dots+\beta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0+\beta_1x_2^1+\beta_2x_2^2+\dots+\beta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0+\theta_1x_0^1+\theta_2x_0^2+\dots+\theta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0+\theta_1x_1^1+\theta_2x_1^2+\dots+\theta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0+\theta_1x_2^1+\theta_2x_2^2+\dots+\theta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0+\beta_1x_{n-1}^1+\beta_2x_{n-1}^2+\dots+\beta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0+\theta_1x_{n-1}^1+\theta_2x_{n-1}^2+\dots+\theta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
</div>
|
||||
@@ -2681,7 +2640,7 @@ $$
|
||||
|
||||
<p>and</p>
|
||||
$$
|
||||
\boldsymbol{\beta} = [\beta_0,\beta_1, \beta_2,\dots, \beta_{n-1}]^T,
|
||||
\boldsymbol{\theta} = [\theta_0,\theta_1, \theta_2,\dots, \theta_{n-1}]^T,
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
@@ -2703,7 +2662,7 @@ $$
|
||||
|
||||
<p>we can rewrite our equations as</p>
|
||||
$$
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}.
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\theta}+\boldsymbol{\epsilon}.
|
||||
$$
|
||||
|
||||
<p>The above design matrix is called a <a href="https://en.wikipedia.org/wiki/Vandermonde_matrix" target="_blank">Vandermonde matrix</a>.</p>
|
||||
@@ -2725,13 +2684,13 @@ of values \( y_i,x_i \) we can then generalize the equations to
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -2759,10 +2718,10 @@ $$
|
||||
|
||||
<p>and without loss of generality we rewrite again our equations as</p>
|
||||
$$
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}.
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\theta}+\boldsymbol{\epsilon}.
|
||||
$$
|
||||
|
||||
<p>The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values? </p>
|
||||
<p>The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\theta} \) are our unknow quantities. How can we obtain the optimal set of \( \theta_i \) values? </p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2774,13 +2733,13 @@ $$
|
||||
<p>We have defined the matrix \( \boldsymbol{X} \) via the equations</p>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -2888,9 +2847,9 @@ display(DesignMatrix)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as</p>
|
||||
<p>With \( \boldsymbol{\theta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as</p>
|
||||
$$
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>throughout these lectures. </p>
|
||||
@@ -2900,19 +2859,19 @@ $$
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
<p>With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as</p>
|
||||
<p>With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\theta} \) as</p>
|
||||
$$
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely</p>
|
||||
<p>and in order to find the optimal parameters \( \theta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely</p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as</p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}.
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}.
|
||||
$$
|
||||
|
||||
<p>This function is one possible way to define the so-called cost function.</p>
|
||||
@@ -2922,10 +2881,10 @@ the function \( C \) as
|
||||
</p>
|
||||
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
C(\boldsymbol{\theta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
$$
|
||||
|
||||
<p>since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out. </p>
|
||||
<p>since when taking the first derivative with respect to the unknown parameters \( \theta \), the factor of \( 2 \) cancels out. </p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2937,14 +2896,14 @@ $$
|
||||
|
||||
<p>The function </p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\},
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value.
|
||||
When linking (see the discussion below) with the maximum likelihood approach below, we will indeed interpret \( y_i \) as a mean value
|
||||
</p>
|
||||
$$
|
||||
y_{i}=\langle y_i \rangle = \beta_0x_{i,0}+\beta_1x_{i,1}+\beta_2x_{i,2}+\dots+\beta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
y_{i}=\langle y_i \rangle = \theta_0x_{i,0}+\theta_1x_{i,1}+\theta_2x_{i,2}+\dots+\theta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
$$
|
||||
|
||||
<p>where \( \langle y_i \rangle \) is the mean value. Keep in mind also that
|
||||
@@ -2957,25 +2916,25 @@ the standard deviation discussed earlier. In the discussion here we
|
||||
will treat \( y_i \) as our exact value for the response variable.
|
||||
</p>
|
||||
|
||||
<p>In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem</p>
|
||||
<p>In order to find the parameters \( \theta_i \) we will then minimize the spread of \( C(\boldsymbol{\theta}) \), that is we are going to solve the problem</p>
|
||||
$$
|
||||
{\displaystyle \min_{\boldsymbol{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}.
|
||||
{\displaystyle \min_{\boldsymbol{\theta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}.
|
||||
$$
|
||||
|
||||
<p>In practical terms it means we will require</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
$$
|
||||
|
||||
<p>which results in</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>or in a matrix-vector form as</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right).
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right).
|
||||
$$
|
||||
</div>
|
||||
|
||||
@@ -2987,17 +2946,17 @@ $$
|
||||
<p>
|
||||
<p>We can rewrite</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right),
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right),
|
||||
$$
|
||||
|
||||
<p>as</p>
|
||||
$$
|
||||
\boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution</p>
|
||||
$$
|
||||
\boldsymbol{\beta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
\boldsymbol{\theta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
$$
|
||||
|
||||
<p>We note also that since our design matrix is defined as \( \boldsymbol{X}\in
|
||||
@@ -3028,20 +2987,20 @@ allow for the usage of direct linear algebra methods such as <b>LU</b> decomposi
|
||||
<p>
|
||||
<p>The residuals \( \boldsymbol{\epsilon} \) are in turn given by</p>
|
||||
$$
|
||||
\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and with </p>
|
||||
$$
|
||||
\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0,
|
||||
\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0,
|
||||
$$
|
||||
|
||||
<p>we have</p>
|
||||
$$
|
||||
\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0,
|
||||
\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0,
|
||||
$$
|
||||
|
||||
<p>meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.</p>
|
||||
<p>meaning that the solution for \( \boldsymbol{\theta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3050,7 +3009,7 @@ $$
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="own-code-for-ordinary-least-squares">Own code for Ordinary Least Squares </h2>
|
||||
|
||||
<p>It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to
|
||||
<p>It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\theta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to
|
||||
write
|
||||
</p>
|
||||
|
||||
@@ -3270,7 +3229,7 @@ as
|
||||
</p>
|
||||
|
||||
$$
|
||||
\chi^2(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
\chi^2(\boldsymbol{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements. </p>
|
||||
@@ -3283,19 +3242,19 @@ $$
|
||||
<b></b>
|
||||
<p>
|
||||
|
||||
<p>In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring</p>
|
||||
<p>In order to find the parameters \( \theta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\theta}) \) by requiring</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\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,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0,
|
||||
$$
|
||||
|
||||
<p>which results in</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\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,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>or in a matrix-vector form as</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right).
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\theta}\right).
|
||||
$$
|
||||
|
||||
<p>where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \). </p>
|
||||
@@ -3310,17 +3269,17 @@ $$
|
||||
|
||||
<p>We can rewrite</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right),
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\theta}\right),
|
||||
$$
|
||||
|
||||
<p>as</p>
|
||||
$$
|
||||
\boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\beta},
|
||||
\boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution</p>
|
||||
$$
|
||||
\boldsymbol{\beta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}.
|
||||
\boldsymbol{\theta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}.
|
||||
$$
|
||||
</div>
|
||||
|
||||
@@ -3336,19 +3295,19 @@ $$
|
||||
\boldsymbol{H} = \left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1},
|
||||
$$
|
||||
|
||||
<p>we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))</p>
|
||||
<p>we have then the following expression for the parameters \( \theta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))</p>
|
||||
$$
|
||||
\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}
|
||||
\theta_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}
|
||||
$$
|
||||
|
||||
<p>We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise)</p>
|
||||
<p>We state without proof the expression for the uncertainty in the parameters \( \theta_j \) as (we leave this as an exercise)</p>
|
||||
$$
|
||||
\sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2,
|
||||
\sigma^2(\theta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \theta_j}{\partial y_i}\right)^2,
|
||||
$$
|
||||
|
||||
<p>resulting in </p>
|
||||
$$
|
||||
\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}!
|
||||
\sigma^2(\theta_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>
|
||||
|
||||
@@ -3360,17 +3319,17 @@ $$
|
||||
<p>
|
||||
<p>The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write</p>
|
||||
$$
|
||||
y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i.
|
||||
y=y(x) \rightarrow y(x_i) \approx \theta_0+\theta_1 x_i.
|
||||
$$
|
||||
|
||||
<p>By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by</p>
|
||||
<p>By computing the derivatives of \( \chi^2 \) with respect to \( \theta_0 \) and \( \theta_1 \) show that these are given by</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
$$
|
||||
</div>
|
||||
|
||||
@@ -3411,266 +3370,22 @@ $$
|
||||
<p>we obtain</p>
|
||||
|
||||
$$
|
||||
\beta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2},
|
||||
\theta_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}.
|
||||
\theta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}.
|
||||
$$
|
||||
|
||||
<p>This approach (different linear and non-linear regression) suffers
|
||||
often from both being underdetermined and overdetermined in the
|
||||
unknown coefficients \( \beta_i \). A better approach is to use the
|
||||
unknown coefficients \( \theta_i \). A better approach is to use the
|
||||
Singular Value Decomposition (SVD) method discussed next week.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="fitting-an-equation-of-state-for-dense-nuclear-matter">Fitting an Equation of State for Dense Nuclear Matter </h2>
|
||||
|
||||
<p>Before we continue, let us introduce yet another example. We are going to fit the
|
||||
nuclear equation of state using results from many-body calculations.
|
||||
The equation of state we have made available here, as function of
|
||||
density, has been derived using modern nucleon-nucleon potentials with
|
||||
<a href="https://www.sciencedirect.com/science/article/pii/S0370157399001106" target="_blank">the addition of three-body
|
||||
forces</a>. This
|
||||
time the file is presented as a standard <b>csv</b> file.
|
||||
</p>
|
||||
|
||||
<p>The beginning of the Python code here is similar to what you have seen
|
||||
before, with the same initializations and declarations. We use also
|
||||
<b>pandas</b> again, rather extensively in order to organize our data.
|
||||
</p>
|
||||
|
||||
<p>The difference now is that we use <b>Scikit-Learn's</b> regression tools
|
||||
instead of our own matrix inversion implementation. Furthermore, we
|
||||
sneak in <b>Ridge</b> regression (to be discussed below) which includes a
|
||||
hyperparameter \( \lambda \), also to be explained below.
|
||||
</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="the-code">The code </h2>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="line-height: 125%;"><span style="color: #228B22"># Common imports</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">os</span>
|
||||
<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">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</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">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">import</span> <span style="color: #008b45; text-decoration: underline">sklearn.linear_model</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">skl</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.metrics</span> <span style="color: #8B008B; font-weight: bold">import</span> mean_squared_error, r2_score, mean_absolute_error
|
||||
|
||||
<span style="color: #228B22"># Where to save the figures and data files</span>
|
||||
PROJECT_ROOT_DIR = <span style="color: #CD5555">"Results"</span>
|
||||
FIGURE_ID = <span style="color: #CD5555">"Results/FigureFiles"</span>
|
||||
DATA_ID = <span style="color: #CD5555">"DataFiles/"</span>
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(PROJECT_ROOT_DIR):
|
||||
os.mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(FIGURE_ID):
|
||||
os.makedirs(FIGURE_ID)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(DATA_ID):
|
||||
os.makedirs(DATA_ID)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">image_path</span>(fig_id):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(FIGURE_ID, fig_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">data_path</span>(dat_id):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">save_fig</span>(fig_id):
|
||||
plt.savefig(image_path(fig_id) + <span style="color: #CD5555">".png"</span>, <span style="color: #658b00">format</span>=<span style="color: #CD5555">'png'</span>)
|
||||
|
||||
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">"EoS.csv"</span>),<span style="color: #CD5555">'r'</span>)
|
||||
|
||||
<span style="color: #228B22"># Read the EoS data as csv file and organize the data into two arrays with density and energies</span>
|
||||
EoS = pd.read_csv(infile, names=(<span style="color: #CD5555">'Density'</span>, <span style="color: #CD5555">'Energy'</span>))
|
||||
EoS[<span style="color: #CD5555">'Energy'</span>] = pd.to_numeric(EoS[<span style="color: #CD5555">'Energy'</span>], errors=<span style="color: #CD5555">'coerce'</span>)
|
||||
EoS = EoS.dropna()
|
||||
Energies = EoS[<span style="color: #CD5555">'Energy'</span>]
|
||||
Density = EoS[<span style="color: #CD5555">'Density'</span>]
|
||||
<span style="color: #228B22"># The design matrix now as function of various polytrops</span>
|
||||
X = np.zeros((<span style="color: #658b00">len</span>(Density),<span style="color: #B452CD">4</span>))
|
||||
X[:,<span style="color: #B452CD">3</span>] = Density**(<span style="color: #B452CD">4.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
X[:,<span style="color: #B452CD">2</span>] = Density
|
||||
X[:,<span style="color: #B452CD">1</span>] = Density**(<span style="color: #B452CD">2.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
X[:,<span style="color: #B452CD">0</span>] = <span style="color: #B452CD">1</span>
|
||||
|
||||
<span style="color: #228B22"># We use now Scikit-Learn's linear regressor and ridge regressor</span>
|
||||
<span style="color: #228B22"># OLS part</span>
|
||||
clf = skl.LinearRegression().fit(X, Energies)
|
||||
ytilde = clf.predict(X)
|
||||
EoS[<span style="color: #CD5555">'Eols'</span>] = ytilde
|
||||
<span style="color: #228B22"># The mean squared error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Mean squared error: %.2f"</span> % mean_squared_error(Energies, ytilde))
|
||||
<span style="color: #228B22"># Explained variance score: 1 is perfect prediction </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Variance score: %.2f'</span> % r2_score(Energies, ytilde))
|
||||
<span style="color: #228B22"># Mean absolute error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Mean absolute error: %.2f'</span> % mean_absolute_error(Energies, ytilde))
|
||||
<span style="color: #658b00">print</span>(clf.coef_, clf.intercept_)
|
||||
|
||||
<span style="color: #228B22"># The Ridge regression with a hyperparameter lambda = 0.1</span>
|
||||
_lambda = <span style="color: #B452CD">0.1</span>
|
||||
clf_ridge = skl.Ridge(alpha=_lambda).fit(X, Energies)
|
||||
yridge = clf_ridge.predict(X)
|
||||
EoS[<span style="color: #CD5555">'Eridge'</span>] = yridge
|
||||
<span style="color: #228B22"># The mean squared error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Mean squared error: %.2f"</span> % mean_squared_error(Energies, yridge))
|
||||
<span style="color: #228B22"># Explained variance score: 1 is perfect prediction </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Variance score: %.2f'</span> % r2_score(Energies, yridge))
|
||||
<span style="color: #228B22"># Mean absolute error </span>
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">'Mean absolute error: %.2f'</span> % mean_absolute_error(Energies, yridge))
|
||||
<span style="color: #658b00">print</span>(clf_ridge.coef_, clf_ridge.intercept_)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_xlabel(<span style="color: #CD5555">r'$\rho[\mathrm{fm}^{-3}]$'</span>)
|
||||
ax.set_ylabel(<span style="color: #CD5555">r'Energy per particle'</span>)
|
||||
ax.plot(EoS[<span style="color: #CD5555">'Density'</span>], EoS[<span style="color: #CD5555">'Energy'</span>], alpha=<span style="color: #B452CD">0.7</span>, lw=<span style="color: #B452CD">2</span>,
|
||||
label=<span style="color: #CD5555">'Theoretical data'</span>)
|
||||
ax.plot(EoS[<span style="color: #CD5555">'Density'</span>], EoS[<span style="color: #CD5555">'Eols'</span>], alpha=<span style="color: #B452CD">0.7</span>, lw=<span style="color: #B452CD">2</span>, c=<span style="color: #CD5555">'m'</span>,
|
||||
label=<span style="color: #CD5555">'OLS'</span>)
|
||||
ax.plot(EoS[<span style="color: #CD5555">'Density'</span>], EoS[<span style="color: #CD5555">'Eridge'</span>], alpha=<span style="color: #B452CD">0.7</span>, lw=<span style="color: #B452CD">2</span>, c=<span style="color: #CD5555">'g'</span>,
|
||||
label=<span style="color: #CD5555">'Ridge $\lambda = 0.1$'</span>)
|
||||
ax.legend()
|
||||
save_fig(<span style="color: #CD5555">"EoSfitting"</span>)
|
||||
plt.show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>The above simple polynomial in density \( \rho \) gives an excellent fit
|
||||
to the data.
|
||||
</p>
|
||||
|
||||
<p>We note also that there is a small deviation between the
|
||||
standard OLS and the Ridge regression at higher densities. We discuss this in more detail
|
||||
below.
|
||||
</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="splitting-our-data-in-training-and-test-data">Splitting our Data in Training and Test data </h2>
|
||||
|
||||
<p>It is normal in essentially all Machine Learning studies to split the
|
||||
data in a training set and a test set (sometimes also an additional
|
||||
validation set). <b>Scikit-Learn</b> has an own function for this. There
|
||||
is no explicit recipe for how much data should be included as training
|
||||
data and say test data. An accepted rule of thumb is to use
|
||||
approximately \( 2/3 \) to \( 4/5 \) of the data as training data. We will
|
||||
postpone a discussion of this splitting to the end of these notes and
|
||||
our discussion of the so-called <b>bias-variance</b> tradeoff. Here we
|
||||
limit ourselves to repeat the above equation of state fitting example
|
||||
but now splitting the data into a training set and a test set.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="line-height: 125%;"><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">os</span>
|
||||
<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">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</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.model_selection</span> <span style="color: #8B008B; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #228B22"># Where to save the figures and data files</span>
|
||||
PROJECT_ROOT_DIR = <span style="color: #CD5555">"Results"</span>
|
||||
FIGURE_ID = <span style="color: #CD5555">"Results/FigureFiles"</span>
|
||||
DATA_ID = <span style="color: #CD5555">"DataFiles/"</span>
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(PROJECT_ROOT_DIR):
|
||||
os.mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(FIGURE_ID):
|
||||
os.makedirs(FIGURE_ID)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #8B008B">not</span> os.path.exists(DATA_ID):
|
||||
os.makedirs(DATA_ID)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">image_path</span>(fig_id):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(FIGURE_ID, fig_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">data_path</span>(dat_id):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> os.path.join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">save_fig</span>(fig_id):
|
||||
plt.savefig(image_path(fig_id) + <span style="color: #CD5555">".png"</span>, <span style="color: #658b00">format</span>=<span style="color: #CD5555">'png'</span>)
|
||||
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">R2</span>(y_data, y_model):
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> <span style="color: #B452CD">1</span> - np.sum((y_data - y_model) ** <span style="color: #B452CD">2</span>) / np.sum((y_data - np.mean(y_data)) ** <span style="color: #B452CD">2</span>)
|
||||
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">MSE</span>(y_data,y_model):
|
||||
n = np.size(y_model)
|
||||
<span style="color: #8B008B; font-weight: bold">return</span> np.sum((y_data-y_model)**<span style="color: #B452CD">2</span>)/n
|
||||
|
||||
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">"EoS.csv"</span>),<span style="color: #CD5555">'r'</span>)
|
||||
|
||||
<span style="color: #228B22"># Read the EoS data as csv file and organized into two arrays with density and energies</span>
|
||||
EoS = pd.read_csv(infile, names=(<span style="color: #CD5555">'Density'</span>, <span style="color: #CD5555">'Energy'</span>))
|
||||
EoS[<span style="color: #CD5555">'Energy'</span>] = pd.to_numeric(EoS[<span style="color: #CD5555">'Energy'</span>], errors=<span style="color: #CD5555">'coerce'</span>)
|
||||
EoS = EoS.dropna()
|
||||
Energies = EoS[<span style="color: #CD5555">'Energy'</span>]
|
||||
Density = EoS[<span style="color: #CD5555">'Density'</span>]
|
||||
<span style="color: #228B22"># The design matrix now as function of various polytrops</span>
|
||||
X = np.zeros((<span style="color: #658b00">len</span>(Density),<span style="color: #B452CD">5</span>))
|
||||
X[:,<span style="color: #B452CD">0</span>] = <span style="color: #B452CD">1</span>
|
||||
X[:,<span style="color: #B452CD">1</span>] = Density**(<span style="color: #B452CD">2.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
X[:,<span style="color: #B452CD">2</span>] = Density
|
||||
X[:,<span style="color: #B452CD">3</span>] = Density**(<span style="color: #B452CD">4.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
X[:,<span style="color: #B452CD">4</span>] = Density**(<span style="color: #B452CD">5.0</span>/<span style="color: #B452CD">3.0</span>)
|
||||
<span style="color: #228B22"># We split the data in test and training data</span>
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, Energies, test_size=<span style="color: #B452CD">0.2</span>)
|
||||
<span style="color: #228B22"># matrix inversion to find beta</span>
|
||||
beta = np.linalg.inv(X_train.T.dot(X_train)).dot(X_train.T).dot(y_train)
|
||||
<span style="color: #228B22"># and then make the prediction</span>
|
||||
ytilde = X_train @ beta
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Training R2"</span>)
|
||||
<span style="color: #658b00">print</span>(R2(y_train,ytilde))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Training MSE"</span>)
|
||||
<span style="color: #658b00">print</span>(MSE(y_train,ytilde))
|
||||
ypredict = X_test @ beta
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test R2"</span>)
|
||||
<span style="color: #658b00">print</span>(R2(y_test,ypredict))
|
||||
<span style="color: #658b00">print</span>(<span style="color: #CD5555">"Test MSE"</span>)
|
||||
<span style="color: #658b00">print</span>(MSE(y_test,ypredict))
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2025, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
|
||||
+75
-360
@@ -336,16 +336,7 @@ div.toc p,a {
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function'),
|
||||
('Fitting an Equation of State for Dense Nuclear Matter',
|
||||
2,
|
||||
None,
|
||||
'fitting-an-equation-of-state-for-dense-nuclear-matter'),
|
||||
('The code', 2, None, 'the-code'),
|
||||
('Splitting our Data in Training and Test data',
|
||||
2,
|
||||
None,
|
||||
'splitting-our-data-in-training-and-test-data')]}
|
||||
('The $\\chi^2$ function', 2, None, 'the-chi-2-function')]}
|
||||
end of tocinfo -->
|
||||
|
||||
<body>
|
||||
@@ -2284,40 +2275,6 @@ infile <span style="color: #666666">=</span> <span style="color: #008000">open</
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various <b>matplotlib</b> commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function. </p>
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #f8f8f8">
|
||||
<pre style="line-height: 125%;"><span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">pylab</span> <span style="color: #008000; font-weight: bold">import</span> plt, mpl
|
||||
plt<span style="color: #666666">.</span>style<span style="color: #666666">.</span>use(<span style="color: #BA2121">'seaborn'</span>)
|
||||
mpl<span style="color: #666666">.</span>rcParams[<span style="color: #BA2121">'font.family'</span>] <span style="color: #666666">=</span> <span style="color: #BA2121">'serif'</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">MakePlot</span>(x,y, styles, labels, axlabels):
|
||||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">10</span>,<span style="color: #666666">6</span>))
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #008000">len</span>(x)):
|
||||
plt<span style="color: #666666">.</span>plot(x[i], y[i], styles[i], label <span style="color: #666666">=</span> labels[i])
|
||||
plt<span style="color: #666666">.</span>xlabel(axlabels[<span style="color: #666666">0</span>])
|
||||
plt<span style="color: #666666">.</span>ylabel(axlabels[<span style="color: #666666">1</span>])
|
||||
plt<span style="color: #666666">.</span>legend(loc<span style="color: #666666">=0</span>)
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Our next step is to read the data on experimental binding energies and
|
||||
reorganize them as functions of the mass number \( A \), the number of
|
||||
protons \( Z \) and neutrons \( N \) using <b>pandas</b>. Before we do this it is
|
||||
@@ -2621,11 +2578,11 @@ Now it is time to dive more into the details of various methods. We will start w
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="why-linear-regression-aka-ordinary-least-squares-and-family">Why Linear Regression (aka Ordinary Least Squares and family) </h2>
|
||||
|
||||
<p>Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\beta} \).</p>
|
||||
<p>Fitting a continuous function with linear parameterization in terms of the parameters \( \boldsymbol{\theta} \).</p>
|
||||
<ul>
|
||||
<li> Method of choice for fitting a continuous function!</li>
|
||||
<li> Gives an excellent introduction to central Machine Learning features with <b>understandable pedagogical</b> links to other methods like <b>Neural Networks</b>, <b>Support Vector Machines</b> etc</li>
|
||||
<li> Analytical expression for the fitting parameters \( \boldsymbol{\beta} \)</li>
|
||||
<li> Analytical expression for the fitting parameters \( \boldsymbol{\theta} \)</li>
|
||||
<li> Analytical expressions for statistical propertiers like mean values, variances, confidence intervals and more</li>
|
||||
<li> Analytical relation with probabilistic interpretations</li>
|
||||
<li> Easy to introduce basic concepts like bias-variance tradeoff, cross-validation, resampling and regularization techniques and many other ML topics</li>
|
||||
@@ -2644,14 +2601,16 @@ Similarly, <a href="https://arxiv.org/abs/1803.08823" target="_blank">Mehta et a
|
||||
<p>
|
||||
|
||||
<p>Regression modeling deals with the description of the sampling distribution of a given random variable \( y \) and how it varies as function of another variable or a set of such variables \( \boldsymbol{x} =[x_0, x_1,\dots, x_{n-1}]^T \).
|
||||
The first variable is called the <b>dependent</b>, the <b>outcome</b> or the <b>response</b> variable while the set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable, or simply just the <b>inputs</b>.
|
||||
The first variable \( y \) is called the the <b>outcome</b> or the <b>response</b> variable, or simply just the <b>outputs</b>.
|
||||
</p>
|
||||
|
||||
<p>The set of variables \( \boldsymbol{x} \) is called the independent variable, or the predictor variable or the explanatory variable, or simply just the <b>inputs</b>. <b>We will throughout the course just use inputs and outputs as names</b>.</p>
|
||||
|
||||
<p>A regression model aims at finding a likelihood function \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) or in the more traditional sense a function \( \boldsymbol{y}(\boldsymbol{x}) \), that is the conditional distribution for \( \boldsymbol{y} \) with a given \( \boldsymbol{x} \). The estimation of \( p(\boldsymbol{y}\vert \boldsymbol{x}) \) is made using a data set with </p>
|
||||
<ul>
|
||||
<li> \( n \) cases \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> Response (target, dependent or outcome) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> \( p \) so-called explanatory (independent or predictor or feature) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). See below for more explicit examples.</li>
|
||||
<li> Response (our output) variable \( y_i \) with \( i = 0, 1, 2, \dots, n-1 \)</li>
|
||||
<li> \( p \) so-called explanatory (independent or predictor or feature) variables \( \boldsymbol{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}] \) with \( i = 0, 1, 2, \dots, n-1 \) and explanatory variables running from \( 0 \) to \( p-1 \). These are the inputs. See below for more explicit examples.</li>
|
||||
</ul>
|
||||
<p> The goal of the regression analysis is to extract/exploit relationship between \( \boldsymbol{y} \) and \( \boldsymbol{x} \) in order to infer specific dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.</p>
|
||||
</div>
|
||||
@@ -2677,11 +2636,11 @@ regression analysis is to explain \( \boldsymbol{y} \) in terms of
|
||||
f(\mathbf{X}_{i,\ast}) \). When no prior knowledge on the form of
|
||||
\( f(\cdot) \) is available, it is common to assume a linear relationship
|
||||
between \( \boldsymbol{X} \) and \( \boldsymbol{y} \). This assumption gives rise to
|
||||
the <em>linear regression model</em> where \( \boldsymbol{\beta} = [\beta_0, \ldots,
|
||||
\beta_{p-1}]^{T} \) are the <em>regression parameters</em>.
|
||||
the <em>linear regression model</em> where \( \boldsymbol{\theta} = [\theta_0, \ldots,
|
||||
\theta_{p-1}]^{T} \) are the <em>regression parameters</em>.
|
||||
</p>
|
||||
|
||||
<p>Linear regression gives us a set of analytical equations for the parameters \( \beta_j \).</p>
|
||||
<p>Linear regression gives us a set of analytical equations for the parameters \( \theta_j \).</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2721,7 +2680,7 @@ so-called <a href="https://www.sciencedirect.com/science/article/pii/S0957417407
|
||||
|
||||
<p>Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of \( y \) which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree \( n-1 \) with \( n \) points, that is</p>
|
||||
$$
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \beta_j x_i^j+\epsilon_i,
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \theta_j x_i^j+\epsilon_i,
|
||||
$$
|
||||
|
||||
<p>where \( \epsilon_i \) is the error in our approximation. </p>
|
||||
@@ -2736,11 +2695,11 @@ $$
|
||||
<p>For every set of values \( y_i,x_i \) we have thus the corresponding set of equations</p>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0+\beta_1x_0^1+\beta_2x_0^2+\dots+\beta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0+\beta_1x_1^1+\beta_2x_1^2+\dots+\beta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0+\beta_1x_2^1+\beta_2x_2^2+\dots+\beta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0+\theta_1x_0^1+\theta_2x_0^2+\dots+\theta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0+\theta_1x_1^1+\theta_2x_1^2+\dots+\theta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0+\theta_1x_2^1+\theta_2x_2^2+\dots+\theta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0+\beta_1x_{n-1}^1+\beta_2x_{n-1}^2+\dots+\beta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0+\theta_1x_{n-1}^1+\theta_2x_{n-1}^2+\dots+\theta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
</div>
|
||||
@@ -2758,7 +2717,7 @@ $$
|
||||
|
||||
<p>and</p>
|
||||
$$
|
||||
\boldsymbol{\beta} = [\beta_0,\beta_1, \beta_2,\dots, \beta_{n-1}]^T,
|
||||
\boldsymbol{\theta} = [\theta_0,\theta_1, \theta_2,\dots, \theta_{n-1}]^T,
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
@@ -2780,7 +2739,7 @@ $$
|
||||
|
||||
<p>we can rewrite our equations as</p>
|
||||
$$
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}.
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\theta}+\boldsymbol{\epsilon}.
|
||||
$$
|
||||
|
||||
<p>The above design matrix is called a <a href="https://en.wikipedia.org/wiki/Vandermonde_matrix" target="_blank">Vandermonde matrix</a>.</p>
|
||||
@@ -2802,13 +2761,13 @@ of values \( y_i,x_i \) we can then generalize the equations to
|
||||
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -2836,10 +2795,10 @@ $$
|
||||
|
||||
<p>and without loss of generality we rewrite again our equations as</p>
|
||||
$$
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon}.
|
||||
\boldsymbol{y} = \boldsymbol{X}\boldsymbol{\theta}+\boldsymbol{\epsilon}.
|
||||
$$
|
||||
|
||||
<p>The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\beta} \) are our unknow quantities. How can we obtain the optimal set of \( \beta_i \) values? </p>
|
||||
<p>The left-hand side of this equation is kwown. Our error vector \( \boldsymbol{\epsilon} \) and the parameter vector \( \boldsymbol{\theta} \) are our unknow quantities. How can we obtain the optimal set of \( \theta_i \) values? </p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2851,13 +2810,13 @@ $$
|
||||
<p>We have defined the matrix \( \boldsymbol{X} \) via the equations</p>
|
||||
$$
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
$$
|
||||
|
||||
@@ -2965,9 +2924,9 @@ display(DesignMatrix)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>With \( \boldsymbol{\beta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as</p>
|
||||
<p>With \( \boldsymbol{\theta}\in {\mathbb{R}}^{p\times 1} \), it means that we will hereafter write our equations for the approximation as</p>
|
||||
$$
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>throughout these lectures. </p>
|
||||
@@ -2977,19 +2936,19 @@ $$
|
||||
<div class="alert alert-block alert-block alert-text-normal">
|
||||
<b></b>
|
||||
<p>
|
||||
<p>With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\beta} \) as</p>
|
||||
<p>With the above we use the design matrix to define the approximation \( \boldsymbol{\tilde{y}} \) via the unknown quantity \( \boldsymbol{\theta} \) as</p>
|
||||
$$
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\tilde{y}}= \boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and in order to find the optimal parameters \( \beta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely</p>
|
||||
<p>and in order to find the optimal parameters \( \theta_i \) instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values \( y_i \) (which represent hopefully the exact values) and the parameterized values \( \tilde{y}_i \), namely</p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>or using the matrix \( \boldsymbol{X} \) and in a more compact matrix-vector notation as</p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}.
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}.
|
||||
$$
|
||||
|
||||
<p>This function is one possible way to define the so-called cost function.</p>
|
||||
@@ -2999,10 +2958,10 @@ the function \( C \) as
|
||||
</p>
|
||||
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
C(\boldsymbol{\theta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
$$
|
||||
|
||||
<p>since when taking the first derivative with respect to the unknown parameters \( \beta \), the factor of \( 2 \) cancels out. </p>
|
||||
<p>since when taking the first derivative with respect to the unknown parameters \( \theta \), the factor of \( 2 \) cancels out. </p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3014,14 +2973,14 @@ $$
|
||||
|
||||
<p>The function </p>
|
||||
$$
|
||||
C(\boldsymbol{\beta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\},
|
||||
C(\boldsymbol{\theta})=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>can be linked to the variance of the quantity \( y_i \) if we interpret the latter as the mean value.
|
||||
When linking (see the discussion below) with the maximum likelihood approach below, we will indeed interpret \( y_i \) as a mean value
|
||||
</p>
|
||||
$$
|
||||
y_{i}=\langle y_i \rangle = \beta_0x_{i,0}+\beta_1x_{i,1}+\beta_2x_{i,2}+\dots+\beta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
y_{i}=\langle y_i \rangle = \theta_0x_{i,0}+\theta_1x_{i,1}+\theta_2x_{i,2}+\dots+\theta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
$$
|
||||
|
||||
<p>where \( \langle y_i \rangle \) is the mean value. Keep in mind also that
|
||||
@@ -3034,25 +2993,25 @@ the standard deviation discussed earlier. In the discussion here we
|
||||
will treat \( y_i \) as our exact value for the response variable.
|
||||
</p>
|
||||
|
||||
<p>In order to find the parameters \( \beta_i \) we will then minimize the spread of \( C(\boldsymbol{\beta}) \), that is we are going to solve the problem</p>
|
||||
<p>In order to find the parameters \( \theta_i \) we will then minimize the spread of \( C(\boldsymbol{\theta}) \), that is we are going to solve the problem</p>
|
||||
$$
|
||||
{\displaystyle \min_{\boldsymbol{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)\right\}.
|
||||
{\displaystyle \min_{\boldsymbol{\theta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)^T\left(\boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)\right\}.
|
||||
$$
|
||||
|
||||
<p>In practical terms it means we will require</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
$$
|
||||
|
||||
<p>which results in</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>or in a matrix-vector form as</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right).
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right).
|
||||
$$
|
||||
</div>
|
||||
|
||||
@@ -3064,17 +3023,17 @@ $$
|
||||
<p>
|
||||
<p>We can rewrite</p>
|
||||
$$
|
||||
\frac{\partial C(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right),
|
||||
\frac{\partial C(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right),
|
||||
$$
|
||||
|
||||
<p>as</p>
|
||||
$$
|
||||
\boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{X}^T\boldsymbol{y} = \boldsymbol{X}^T\boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and if the matrix \( \boldsymbol{X}^T\boldsymbol{X} \) is invertible we have the solution</p>
|
||||
$$
|
||||
\boldsymbol{\beta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
\boldsymbol{\theta} =\left(\boldsymbol{X}^T\boldsymbol{X}\right)^{-1}\boldsymbol{X}^T\boldsymbol{y}.
|
||||
$$
|
||||
|
||||
<p>We note also that since our design matrix is defined as \( \boldsymbol{X}\in
|
||||
@@ -3105,20 +3064,20 @@ allow for the usage of direct linear algebra methods such as <b>LU</b> decomposi
|
||||
<p>
|
||||
<p>The residuals \( \boldsymbol{\epsilon} \) are in turn given by</p>
|
||||
$$
|
||||
\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta},
|
||||
\boldsymbol{\epsilon} = \boldsymbol{y}-\boldsymbol{\tilde{y}} = \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and with </p>
|
||||
$$
|
||||
\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0,
|
||||
\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0,
|
||||
$$
|
||||
|
||||
<p>we have</p>
|
||||
$$
|
||||
\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\beta}\right)= 0,
|
||||
\boldsymbol{X}^T\boldsymbol{\epsilon}=\boldsymbol{X}^T\left( \boldsymbol{y}-\boldsymbol{X}\boldsymbol{\theta}\right)= 0,
|
||||
$$
|
||||
|
||||
<p>meaning that the solution for \( \boldsymbol{\beta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.</p>
|
||||
<p>meaning that the solution for \( \boldsymbol{\theta} \) is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.</p>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3127,7 +3086,7 @@ $$
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="own-code-for-ordinary-least-squares">Own code for Ordinary Least Squares </h2>
|
||||
|
||||
<p>It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\beta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to
|
||||
<p>It is rather straightforward to implement the matrix inversion and obtain the parameters \( \boldsymbol{\theta} \). After having defined the matrix \( \boldsymbol{X} \) we simply need to
|
||||
write
|
||||
</p>
|
||||
|
||||
@@ -3347,7 +3306,7 @@ as
|
||||
</p>
|
||||
|
||||
$$
|
||||
\chi^2(\boldsymbol{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
\chi^2(\boldsymbol{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)^T\frac{1}{\boldsymbol{\Sigma^2}}\left(\boldsymbol{y}-\boldsymbol{\tilde{y}}\right)\right\},
|
||||
$$
|
||||
|
||||
<p>where the matrix \( \boldsymbol{\Sigma} \) is a diagonal matrix with \( \sigma_i \) as matrix elements. </p>
|
||||
@@ -3360,19 +3319,19 @@ $$
|
||||
<b></b>
|
||||
<p>
|
||||
|
||||
<p>In order to find the parameters \( \beta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\beta}) \) by requiring</p>
|
||||
<p>In order to find the parameters \( \theta_i \) we will then minimize the spread of \( \chi^2(\boldsymbol{\theta}) \) by requiring</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\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,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0,
|
||||
$$
|
||||
|
||||
<p>which results in</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_j} = -\frac{2}{n}\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,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>or in a matrix-vector form as</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right).
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\theta}\right).
|
||||
$$
|
||||
|
||||
<p>where we have defined the matrix \( \boldsymbol{A} =\boldsymbol{X}/\boldsymbol{\Sigma} \) with matrix elements \( a_{ij} = x_{ij}/\sigma_i \) and the vector \( \boldsymbol{b} \) with elements \( b_i = y_i/\sigma_i \). </p>
|
||||
@@ -3387,17 +3346,17 @@ $$
|
||||
|
||||
<p>We can rewrite</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \boldsymbol{\beta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\beta}\right),
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \boldsymbol{\theta}} = 0 = \boldsymbol{A}^T\left( \boldsymbol{b}-\boldsymbol{A}\boldsymbol{\theta}\right),
|
||||
$$
|
||||
|
||||
<p>as</p>
|
||||
$$
|
||||
\boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\beta},
|
||||
\boldsymbol{A}^T\boldsymbol{b} = \boldsymbol{A}^T\boldsymbol{A}\boldsymbol{\theta},
|
||||
$$
|
||||
|
||||
<p>and if the matrix \( \boldsymbol{A}^T\boldsymbol{A} \) is invertible we have the solution</p>
|
||||
$$
|
||||
\boldsymbol{\beta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}.
|
||||
\boldsymbol{\theta} =\left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1}\boldsymbol{A}^T\boldsymbol{b}.
|
||||
$$
|
||||
</div>
|
||||
|
||||
@@ -3413,19 +3372,19 @@ $$
|
||||
\boldsymbol{H} = \left(\boldsymbol{A}^T\boldsymbol{A}\right)^{-1},
|
||||
$$
|
||||
|
||||
<p>we have then the following expression for the parameters \( \beta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))</p>
|
||||
<p>we have then the following expression for the parameters \( \theta_j \) (the matrix elements of \( \boldsymbol{H} \) are \( h_{ij} \))</p>
|
||||
$$
|
||||
\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}
|
||||
\theta_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}
|
||||
$$
|
||||
|
||||
<p>We state without proof the expression for the uncertainty in the parameters \( \beta_j \) as (we leave this as an exercise)</p>
|
||||
<p>We state without proof the expression for the uncertainty in the parameters \( \theta_j \) as (we leave this as an exercise)</p>
|
||||
$$
|
||||
\sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2,
|
||||
\sigma^2(\theta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \theta_j}{\partial y_i}\right)^2,
|
||||
$$
|
||||
|
||||
<p>resulting in </p>
|
||||
$$
|
||||
\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}!
|
||||
\sigma^2(\theta_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>
|
||||
|
||||
@@ -3437,17 +3396,17 @@ $$
|
||||
<p>
|
||||
<p>The first step here is to approximate the function \( y \) with a first-order polynomial, that is we write</p>
|
||||
$$
|
||||
y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i.
|
||||
y=y(x) \rightarrow y(x_i) \approx \theta_0+\theta_1 x_i.
|
||||
$$
|
||||
|
||||
<p>By computing the derivatives of \( \chi^2 \) with respect to \( \beta_0 \) and \( \beta_1 \) show that these are given by</p>
|
||||
<p>By computing the derivatives of \( \chi^2 \) with respect to \( \theta_0 \) and \( \theta_1 \) show that these are given by</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
$$
|
||||
\frac{\partial \chi^2(\boldsymbol{\beta})}{\partial \beta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
\frac{\partial \chi^2(\boldsymbol{\theta})}{\partial \theta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
$$
|
||||
</div>
|
||||
|
||||
@@ -3488,266 +3447,22 @@ $$
|
||||
<p>we obtain</p>
|
||||
|
||||
$$
|
||||
\beta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2},
|
||||
\theta_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}.
|
||||
\theta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}.
|
||||
$$
|
||||
|
||||
<p>This approach (different linear and non-linear regression) suffers
|
||||
often from both being underdetermined and overdetermined in the
|
||||
unknown coefficients \( \beta_i \). A better approach is to use the
|
||||
unknown coefficients \( \theta_i \). A better approach is to use the
|
||||
Singular Value Decomposition (SVD) method discussed next week.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="fitting-an-equation-of-state-for-dense-nuclear-matter">Fitting an Equation of State for Dense Nuclear Matter </h2>
|
||||
|
||||
<p>Before we continue, let us introduce yet another example. We are going to fit the
|
||||
nuclear equation of state using results from many-body calculations.
|
||||
The equation of state we have made available here, as function of
|
||||
density, has been derived using modern nucleon-nucleon potentials with
|
||||
<a href="https://www.sciencedirect.com/science/article/pii/S0370157399001106" target="_blank">the addition of three-body
|
||||
forces</a>. This
|
||||
time the file is presented as a standard <b>csv</b> file.
|
||||
</p>
|
||||
|
||||
<p>The beginning of the Python code here is similar to what you have seen
|
||||
before, with the same initializations and declarations. We use also
|
||||
<b>pandas</b> again, rather extensively in order to organize our data.
|
||||
</p>
|
||||
|
||||
<p>The difference now is that we use <b>Scikit-Learn's</b> regression tools
|
||||
instead of our own matrix inversion implementation. Furthermore, we
|
||||
sneak in <b>Ridge</b> regression (to be discussed below) which includes a
|
||||
hyperparameter \( \lambda \), also to be explained below.
|
||||
</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="the-code">The code </h2>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #f8f8f8">
|
||||
<pre style="line-height: 125%;"><span style="color: #408080; font-style: italic"># Common imports</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">os</span>
|
||||
<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">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</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">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">import</span> <span style="color: #0000FF; font-weight: bold">sklearn.linear_model</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">skl</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.metrics</span> <span style="color: #008000; font-weight: bold">import</span> mean_squared_error, r2_score, mean_absolute_error
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Where to save the figures and data files</span>
|
||||
PROJECT_ROOT_DIR <span style="color: #666666">=</span> <span style="color: #BA2121">"Results"</span>
|
||||
FIGURE_ID <span style="color: #666666">=</span> <span style="color: #BA2121">"Results/FigureFiles"</span>
|
||||
DATA_ID <span style="color: #666666">=</span> <span style="color: #BA2121">"DataFiles/"</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(PROJECT_ROOT_DIR):
|
||||
os<span style="color: #666666">.</span>mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(FIGURE_ID):
|
||||
os<span style="color: #666666">.</span>makedirs(FIGURE_ID)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(DATA_ID):
|
||||
os<span style="color: #666666">.</span>makedirs(DATA_ID)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">image_path</span>(fig_id):
|
||||
<span style="color: #008000; font-weight: bold">return</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>join(FIGURE_ID, fig_id)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">data_path</span>(dat_id):
|
||||
<span style="color: #008000; font-weight: bold">return</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">save_fig</span>(fig_id):
|
||||
plt<span style="color: #666666">.</span>savefig(image_path(fig_id) <span style="color: #666666">+</span> <span style="color: #BA2121">".png"</span>, <span style="color: #008000">format</span><span style="color: #666666">=</span><span style="color: #BA2121">'png'</span>)
|
||||
|
||||
infile <span style="color: #666666">=</span> <span style="color: #008000">open</span>(data_path(<span style="color: #BA2121">"EoS.csv"</span>),<span style="color: #BA2121">'r'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Read the EoS data as csv file and organize the data into two arrays with density and energies</span>
|
||||
EoS <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>read_csv(infile, names<span style="color: #666666">=</span>(<span style="color: #BA2121">'Density'</span>, <span style="color: #BA2121">'Energy'</span>))
|
||||
EoS[<span style="color: #BA2121">'Energy'</span>] <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>to_numeric(EoS[<span style="color: #BA2121">'Energy'</span>], errors<span style="color: #666666">=</span><span style="color: #BA2121">'coerce'</span>)
|
||||
EoS <span style="color: #666666">=</span> EoS<span style="color: #666666">.</span>dropna()
|
||||
Energies <span style="color: #666666">=</span> EoS[<span style="color: #BA2121">'Energy'</span>]
|
||||
Density <span style="color: #666666">=</span> EoS[<span style="color: #BA2121">'Density'</span>]
|
||||
<span style="color: #408080; font-style: italic"># The design matrix now as function of various polytrops</span>
|
||||
X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((<span style="color: #008000">len</span>(Density),<span style="color: #666666">4</span>))
|
||||
X[:,<span style="color: #666666">3</span>] <span style="color: #666666">=</span> Density<span style="color: #666666">**</span>(<span style="color: #666666">4.0/3.0</span>)
|
||||
X[:,<span style="color: #666666">2</span>] <span style="color: #666666">=</span> Density
|
||||
X[:,<span style="color: #666666">1</span>] <span style="color: #666666">=</span> Density<span style="color: #666666">**</span>(<span style="color: #666666">2.0/3.0</span>)
|
||||
X[:,<span style="color: #666666">0</span>] <span style="color: #666666">=</span> <span style="color: #666666">1</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># We use now Scikit-Learn's linear regressor and ridge regressor</span>
|
||||
<span style="color: #408080; font-style: italic"># OLS part</span>
|
||||
clf <span style="color: #666666">=</span> skl<span style="color: #666666">.</span>LinearRegression()<span style="color: #666666">.</span>fit(X, Energies)
|
||||
ytilde <span style="color: #666666">=</span> clf<span style="color: #666666">.</span>predict(X)
|
||||
EoS[<span style="color: #BA2121">'Eols'</span>] <span style="color: #666666">=</span> ytilde
|
||||
<span style="color: #408080; font-style: italic"># The mean squared error </span>
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Mean squared error: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">"</span> <span style="color: #666666">%</span> mean_squared_error(Energies, ytilde))
|
||||
<span style="color: #408080; font-style: italic"># Explained variance score: 1 is perfect prediction </span>
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Variance score: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">'</span> <span style="color: #666666">%</span> r2_score(Energies, ytilde))
|
||||
<span style="color: #408080; font-style: italic"># Mean absolute error </span>
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Mean absolute error: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">'</span> <span style="color: #666666">%</span> mean_absolute_error(Energies, ytilde))
|
||||
<span style="color: #008000">print</span>(clf<span style="color: #666666">.</span>coef_, clf<span style="color: #666666">.</span>intercept_)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># The Ridge regression with a hyperparameter lambda = 0.1</span>
|
||||
_lambda <span style="color: #666666">=</span> <span style="color: #666666">0.1</span>
|
||||
clf_ridge <span style="color: #666666">=</span> skl<span style="color: #666666">.</span>Ridge(alpha<span style="color: #666666">=</span>_lambda)<span style="color: #666666">.</span>fit(X, Energies)
|
||||
yridge <span style="color: #666666">=</span> clf_ridge<span style="color: #666666">.</span>predict(X)
|
||||
EoS[<span style="color: #BA2121">'Eridge'</span>] <span style="color: #666666">=</span> yridge
|
||||
<span style="color: #408080; font-style: italic"># The mean squared error </span>
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Mean squared error: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">"</span> <span style="color: #666666">%</span> mean_squared_error(Energies, yridge))
|
||||
<span style="color: #408080; font-style: italic"># Explained variance score: 1 is perfect prediction </span>
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Variance score: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">'</span> <span style="color: #666666">%</span> r2_score(Energies, yridge))
|
||||
<span style="color: #408080; font-style: italic"># Mean absolute error </span>
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Mean absolute error: </span><span style="color: #BB6688; font-weight: bold">%.2f</span><span style="color: #BA2121">'</span> <span style="color: #666666">%</span> mean_absolute_error(Energies, yridge))
|
||||
<span style="color: #008000">print</span>(clf_ridge<span style="color: #666666">.</span>coef_, clf_ridge<span style="color: #666666">.</span>intercept_)
|
||||
|
||||
fig, ax <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>subplots()
|
||||
ax<span style="color: #666666">.</span>set_xlabel(<span style="color: #BA2121">r'$\rho[\mathrm</span><span style="color: #BB6688; font-weight: bold">{fm}</span><span style="color: #BA2121">^{-3}]$'</span>)
|
||||
ax<span style="color: #666666">.</span>set_ylabel(<span style="color: #BA2121">r'Energy per particle'</span>)
|
||||
ax<span style="color: #666666">.</span>plot(EoS[<span style="color: #BA2121">'Density'</span>], EoS[<span style="color: #BA2121">'Energy'</span>], alpha<span style="color: #666666">=0.7</span>, lw<span style="color: #666666">=2</span>,
|
||||
label<span style="color: #666666">=</span><span style="color: #BA2121">'Theoretical data'</span>)
|
||||
ax<span style="color: #666666">.</span>plot(EoS[<span style="color: #BA2121">'Density'</span>], EoS[<span style="color: #BA2121">'Eols'</span>], alpha<span style="color: #666666">=0.7</span>, lw<span style="color: #666666">=2</span>, c<span style="color: #666666">=</span><span style="color: #BA2121">'m'</span>,
|
||||
label<span style="color: #666666">=</span><span style="color: #BA2121">'OLS'</span>)
|
||||
ax<span style="color: #666666">.</span>plot(EoS[<span style="color: #BA2121">'Density'</span>], EoS[<span style="color: #BA2121">'Eridge'</span>], alpha<span style="color: #666666">=0.7</span>, lw<span style="color: #666666">=2</span>, c<span style="color: #666666">=</span><span style="color: #BA2121">'g'</span>,
|
||||
label<span style="color: #666666">=</span><span style="color: #BA2121">'Ridge $\lambda = 0.1$'</span>)
|
||||
ax<span style="color: #666666">.</span>legend()
|
||||
save_fig(<span style="color: #BA2121">"EoSfitting"</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>The above simple polynomial in density \( \rho \) gives an excellent fit
|
||||
to the data.
|
||||
</p>
|
||||
|
||||
<p>We note also that there is a small deviation between the
|
||||
standard OLS and the Ridge regression at higher densities. We discuss this in more detail
|
||||
below.
|
||||
</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="splitting-our-data-in-training-and-test-data">Splitting our Data in Training and Test data </h2>
|
||||
|
||||
<p>It is normal in essentially all Machine Learning studies to split the
|
||||
data in a training set and a test set (sometimes also an additional
|
||||
validation set). <b>Scikit-Learn</b> has an own function for this. There
|
||||
is no explicit recipe for how much data should be included as training
|
||||
data and say test data. An accepted rule of thumb is to use
|
||||
approximately \( 2/3 \) to \( 4/5 \) of the data as training data. We will
|
||||
postpone a discussion of this splitting to the end of these notes and
|
||||
our discussion of the so-called <b>bias-variance</b> tradeoff. Here we
|
||||
limit ourselves to repeat the above equation of state fitting example
|
||||
but now splitting the data into a training set and a test set.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #f8f8f8">
|
||||
<pre style="line-height: 125%;"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">os</span>
|
||||
<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">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</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.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
|
||||
<span style="color: #408080; font-style: italic"># Where to save the figures and data files</span>
|
||||
PROJECT_ROOT_DIR <span style="color: #666666">=</span> <span style="color: #BA2121">"Results"</span>
|
||||
FIGURE_ID <span style="color: #666666">=</span> <span style="color: #BA2121">"Results/FigureFiles"</span>
|
||||
DATA_ID <span style="color: #666666">=</span> <span style="color: #BA2121">"DataFiles/"</span>
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(PROJECT_ROOT_DIR):
|
||||
os<span style="color: #666666">.</span>mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(FIGURE_ID):
|
||||
os<span style="color: #666666">.</span>makedirs(FIGURE_ID)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #AA22FF; font-weight: bold">not</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>exists(DATA_ID):
|
||||
os<span style="color: #666666">.</span>makedirs(DATA_ID)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">image_path</span>(fig_id):
|
||||
<span style="color: #008000; font-weight: bold">return</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>join(FIGURE_ID, fig_id)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">data_path</span>(dat_id):
|
||||
<span style="color: #008000; font-weight: bold">return</span> os<span style="color: #666666">.</span>path<span style="color: #666666">.</span>join(DATA_ID, dat_id)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">save_fig</span>(fig_id):
|
||||
plt<span style="color: #666666">.</span>savefig(image_path(fig_id) <span style="color: #666666">+</span> <span style="color: #BA2121">".png"</span>, <span style="color: #008000">format</span><span style="color: #666666">=</span><span style="color: #BA2121">'png'</span>)
|
||||
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">R2</span>(y_data, y_model):
|
||||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">1</span> <span style="color: #666666">-</span> np<span style="color: #666666">.</span>sum((y_data <span style="color: #666666">-</span> y_model) <span style="color: #666666">**</span> <span style="color: #666666">2</span>) <span style="color: #666666">/</span> np<span style="color: #666666">.</span>sum((y_data <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y_data)) <span style="color: #666666">**</span> <span style="color: #666666">2</span>)
|
||||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">MSE</span>(y_data,y_model):
|
||||
n <span style="color: #666666">=</span> np<span style="color: #666666">.</span>size(y_model)
|
||||
<span style="color: #008000; font-weight: bold">return</span> np<span style="color: #666666">.</span>sum((y_data<span style="color: #666666">-</span>y_model)<span style="color: #666666">**2</span>)<span style="color: #666666">/</span>n
|
||||
|
||||
infile <span style="color: #666666">=</span> <span style="color: #008000">open</span>(data_path(<span style="color: #BA2121">"EoS.csv"</span>),<span style="color: #BA2121">'r'</span>)
|
||||
|
||||
<span style="color: #408080; font-style: italic"># Read the EoS data as csv file and organized into two arrays with density and energies</span>
|
||||
EoS <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>read_csv(infile, names<span style="color: #666666">=</span>(<span style="color: #BA2121">'Density'</span>, <span style="color: #BA2121">'Energy'</span>))
|
||||
EoS[<span style="color: #BA2121">'Energy'</span>] <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>to_numeric(EoS[<span style="color: #BA2121">'Energy'</span>], errors<span style="color: #666666">=</span><span style="color: #BA2121">'coerce'</span>)
|
||||
EoS <span style="color: #666666">=</span> EoS<span style="color: #666666">.</span>dropna()
|
||||
Energies <span style="color: #666666">=</span> EoS[<span style="color: #BA2121">'Energy'</span>]
|
||||
Density <span style="color: #666666">=</span> EoS[<span style="color: #BA2121">'Density'</span>]
|
||||
<span style="color: #408080; font-style: italic"># The design matrix now as function of various polytrops</span>
|
||||
X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((<span style="color: #008000">len</span>(Density),<span style="color: #666666">5</span>))
|
||||
X[:,<span style="color: #666666">0</span>] <span style="color: #666666">=</span> <span style="color: #666666">1</span>
|
||||
X[:,<span style="color: #666666">1</span>] <span style="color: #666666">=</span> Density<span style="color: #666666">**</span>(<span style="color: #666666">2.0/3.0</span>)
|
||||
X[:,<span style="color: #666666">2</span>] <span style="color: #666666">=</span> Density
|
||||
X[:,<span style="color: #666666">3</span>] <span style="color: #666666">=</span> Density<span style="color: #666666">**</span>(<span style="color: #666666">4.0/3.0</span>)
|
||||
X[:,<span style="color: #666666">4</span>] <span style="color: #666666">=</span> Density<span style="color: #666666">**</span>(<span style="color: #666666">5.0/3.0</span>)
|
||||
<span style="color: #408080; font-style: italic"># We split the data in test and training data</span>
|
||||
X_train, X_test, y_train, y_test <span style="color: #666666">=</span> train_test_split(X, Energies, test_size<span style="color: #666666">=0.2</span>)
|
||||
<span style="color: #408080; font-style: italic"># matrix inversion to find beta</span>
|
||||
beta <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>inv(X_train<span style="color: #666666">.</span>T<span style="color: #666666">.</span>dot(X_train))<span style="color: #666666">.</span>dot(X_train<span style="color: #666666">.</span>T)<span style="color: #666666">.</span>dot(y_train)
|
||||
<span style="color: #408080; font-style: italic"># and then make the prediction</span>
|
||||
ytilde <span style="color: #666666">=</span> X_train <span style="color: #666666">@</span> beta
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Training R2"</span>)
|
||||
<span style="color: #008000">print</span>(R2(y_train,ytilde))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Training MSE"</span>)
|
||||
<span style="color: #008000">print</span>(MSE(y_train,ytilde))
|
||||
ypredict <span style="color: #666666">=</span> X_test <span style="color: #666666">@</span> beta
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test R2"</span>)
|
||||
<span style="color: #008000">print</span>(R2(y_test,ypredict))
|
||||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Test MSE"</span>)
|
||||
<span style="color: #008000">print</span>(MSE(y_test,ypredict))
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- ------------------- end of main content --------------- -->
|
||||
<center style="font-size:80%">
|
||||
<!-- copyright --> © 1999-2025, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 23 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 24 KiB |
Binary file not shown.
+371
-648
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+74
-289
@@ -1331,22 +1331,6 @@ def save_fig(fig_id):
|
||||
infile = open(data_path("MassEval2016.dat"),'r')
|
||||
!ec
|
||||
|
||||
|
||||
Before we proceed, we define also a function for making our plots. You can obviously avoid this and simply set up various _matplotlib_ commands every time you need them. You may however find it convenient to collect all such commands in one function and simply call this function.
|
||||
!bc pycod
|
||||
from pylab import plt, mpl
|
||||
plt.style.use('seaborn')
|
||||
mpl.rcParams['font.family'] = 'serif'
|
||||
|
||||
def MakePlot(x,y, styles, labels, axlabels):
|
||||
plt.figure(figsize=(10,6))
|
||||
for i in range(len(x)):
|
||||
plt.plot(x[i], y[i], styles[i], label = labels[i])
|
||||
plt.xlabel(axlabels[0])
|
||||
plt.ylabel(axlabels[1])
|
||||
plt.legend(loc=0)
|
||||
!ec
|
||||
|
||||
Our next step is to read the data on experimental binding energies and
|
||||
reorganize them as functions of the mass number $A$, the number of
|
||||
protons $Z$ and neutrons $N$ using _pandas_. Before we do this it is
|
||||
@@ -1518,10 +1502,10 @@ Now it is time to dive more into the details of various methods. We will start w
|
||||
!split
|
||||
===== Why Linear Regression (aka Ordinary Least Squares and family) =====
|
||||
|
||||
Fitting a continuous function with linear parameterization in terms of the parameters $\bm{\beta}$.
|
||||
Fitting a continuous function with linear parameterization in terms of the parameters $\bm{\theta}$.
|
||||
* Method of choice for fitting a continuous function!
|
||||
* Gives an excellent introduction to central Machine Learning features with _understandable pedagogical_ links to other methods like _Neural Networks_, _Support Vector Machines_ etc
|
||||
* Analytical expression for the fitting parameters $\bm{\beta}$
|
||||
* Analytical expression for the fitting parameters $\bm{\theta}$
|
||||
* Analytical expressions for statistical propertiers like mean values, variances, confidence intervals and more
|
||||
* Analytical relation with probabilistic interpretations
|
||||
* Easy to introduce basic concepts like bias-variance tradeoff, cross-validation, resampling and regularization techniques and many other ML topics
|
||||
@@ -1538,12 +1522,14 @@ Similarly, "Mehta et al's article":"https://arxiv.org/abs/1803.08823" is also re
|
||||
!bblock
|
||||
|
||||
Regression modeling deals with the description of the sampling distribution of a given random variable $y$ and how it varies as function of another variable or a set of such variables $\bm{x} =[x_0, x_1,\dots, x_{n-1}]^T$.
|
||||
The first variable is called the _dependent_, the _outcome_ or the _response_ variable while the set of variables $\bm{x}$ is called the independent variable, or the predictor variable or the explanatory variable, or simply just the _inputs_.
|
||||
The first variable $y$ is called the the _outcome_ or the _response_ variable, or simply just the _outputs_.
|
||||
|
||||
The set of variables $\bm{x}$ is called the independent variable, or the predictor variable or the explanatory variable, or simply just the _inputs_. _We will throughout the course just use inputs and outputs as names_.
|
||||
|
||||
A regression model aims at finding a likelihood function $p(\bm{y}\vert \bm{x})$ or in the more traditional sense a function $\bm{y}(\bm{x})$, that is the conditional distribution for $\bm{y}$ with a given $\bm{x}$. The estimation of $p(\bm{y}\vert \bm{x})$ is made using a data set with
|
||||
* $n$ cases $i = 0, 1, 2, \dots, n-1$
|
||||
* Response (target, dependent or outcome) variable $y_i$ with $i = 0, 1, 2, \dots, n-1$
|
||||
* $p$ so-called explanatory (independent or predictor or feature) variables $\bm{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}]$ with $i = 0, 1, 2, \dots, n-1$ and explanatory variables running from $0$ to $p-1$. See below for more explicit examples.
|
||||
* Response (our output) variable $y_i$ with $i = 0, 1, 2, \dots, n-1$
|
||||
* $p$ so-called explanatory (independent or predictor or feature) variables $\bm{x}_i=[x_{i0}, x_{i1}, \dots, x_{ip-1}]$ with $i = 0, 1, 2, \dots, n-1$ and explanatory variables running from $0$ to $p-1$. These are the inputs. See below for more explicit examples.
|
||||
The goal of the regression analysis is to extract/exploit relationship between $\bm{y}$ and $\bm{x}$ in order to infer specific dependencies, approximations to the likelihood functions, functional relationships and to make predictions, making fits and many other things.
|
||||
!eblock
|
||||
|
||||
@@ -1565,10 +1551,10 @@ $\bm{X}$ through a functional relationship like $y_i =
|
||||
f(\mathbf{X}_{i,\ast})$. When no prior knowledge on the form of
|
||||
$f(\cdot)$ is available, it is common to assume a linear relationship
|
||||
between $\bm{X}$ and $\bm{y}$. This assumption gives rise to
|
||||
the *linear regression model* where $\bm{\beta} = [\beta_0, \ldots,
|
||||
\beta_{p-1}]^{T}$ are the *regression parameters*.
|
||||
the *linear regression model* where $\bm{\theta} = [\theta_0, \ldots,
|
||||
\theta_{p-1}]^{T}$ are the *regression parameters*.
|
||||
|
||||
Linear regression gives us a set of analytical equations for the parameters $\beta_j$.
|
||||
Linear regression gives us a set of analytical equations for the parameters $\theta_j$.
|
||||
|
||||
!eblock
|
||||
|
||||
@@ -1608,7 +1594,7 @@ Before we proceed let us study a case where we aim at fitting a set of data $\bm
|
||||
Since obtaining these data points may not be trivial, we want to use these data to fit a function which can allow us to make predictions for values of $y$ which are not in the present set. The perhaps simplest approach is to assume we can parametrize our function in terms of a polynomial of degree $n-1$ with $n$ points, that is
|
||||
!bt
|
||||
\[
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \beta_j x_i^j+\epsilon_i,
|
||||
y=y(x) \rightarrow y(x_i)=\tilde{y}_i+\epsilon_i=\sum_{j=0}^{n-1} \theta_j x_i^j+\epsilon_i,
|
||||
\]
|
||||
!et
|
||||
where $\epsilon_i$ is the error in our approximation.
|
||||
@@ -1622,11 +1608,11 @@ where $\epsilon_i$ is the error in our approximation.
|
||||
For every set of values $y_i,x_i$ we have thus the corresponding set of equations
|
||||
!bt
|
||||
\begin{align*}
|
||||
y_0&=\beta_0+\beta_1x_0^1+\beta_2x_0^2+\dots+\beta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0+\beta_1x_1^1+\beta_2x_1^2+\dots+\beta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0+\beta_1x_2^1+\beta_2x_2^2+\dots+\beta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0+\theta_1x_0^1+\theta_2x_0^2+\dots+\theta_{n-1}x_0^{n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0+\theta_1x_1^1+\theta_2x_1^2+\dots+\theta_{n-1}x_1^{n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0+\theta_1x_2^1+\theta_2x_2^2+\dots+\theta_{n-1}x_2^{n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0+\beta_1x_{n-1}^1+\beta_2x_{n-1}^2+\dots+\beta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0+\theta_1x_{n-1}^1+\theta_2x_{n-1}^2+\dots+\theta_{n-1}x_{n-1}^{n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
!et
|
||||
!eblock
|
||||
@@ -1644,7 +1630,7 @@ Defining the vectors
|
||||
and
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta} = [\beta_0,\beta_1, \beta_2,\dots, \beta_{n-1}]^T,
|
||||
\bm{\theta} = [\theta_0,\theta_1, \theta_2,\dots, \theta_{n-1}]^T,
|
||||
\]
|
||||
!et
|
||||
and
|
||||
@@ -1669,7 +1655,7 @@ and the design matrix
|
||||
we can rewrite our equations as
|
||||
!bt
|
||||
\[
|
||||
\bm{y} = \bm{X}\bm{\beta}+\bm{\epsilon}.
|
||||
\bm{y} = \bm{X}\bm{\theta}+\bm{\epsilon}.
|
||||
\]
|
||||
!et
|
||||
The above design matrix is called a "Vandermonde matrix":"https://en.wikipedia.org/wiki/Vandermonde_matrix".
|
||||
@@ -1688,13 +1674,13 @@ of values $y_i,x_i$ we can then generalize the equations to
|
||||
|
||||
!bt
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_2\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_i\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
!et
|
||||
|
||||
@@ -1721,10 +1707,10 @@ x_{n-1,0}& x_{n-1,1} &x_{n-1,2}& \dots & \dots &x_{n-1,n-1}\\
|
||||
and without loss of generality we rewrite again our equations as
|
||||
!bt
|
||||
\[
|
||||
\bm{y} = \bm{X}\bm{\beta}+\bm{\epsilon}.
|
||||
\bm{y} = \bm{X}\bm{\theta}+\bm{\epsilon}.
|
||||
\]
|
||||
!et
|
||||
The left-hand side of this equation is kwown. Our error vector $\bm{\epsilon}$ and the parameter vector $\bm{\beta}$ are our unknow quantities. How can we obtain the optimal set of $\beta_i$ values?
|
||||
The left-hand side of this equation is kwown. Our error vector $\bm{\epsilon}$ and the parameter vector $\bm{\theta}$ are our unknow quantities. How can we obtain the optimal set of $\theta_i$ values?
|
||||
!eblock
|
||||
|
||||
|
||||
@@ -1734,13 +1720,13 @@ The left-hand side of this equation is kwown. Our error vector $\bm{\epsilon}$ a
|
||||
We have defined the matrix $\bm{X}$ via the equations
|
||||
!bt
|
||||
\begin{align*}
|
||||
y_0&=\beta_0x_{00}+\beta_1x_{01}+\beta_2x_{02}+\dots+\beta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\beta_0x_{10}+\beta_1x_{11}+\beta_2x_{12}+\dots+\beta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\beta_0x_{20}+\beta_1x_{21}+\beta_2x_{22}+\dots+\beta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
y_0&=\theta_0x_{00}+\theta_1x_{01}+\theta_2x_{02}+\dots+\theta_{n-1}x_{0n-1}+\epsilon_0\\
|
||||
y_1&=\theta_0x_{10}+\theta_1x_{11}+\theta_2x_{12}+\dots+\theta_{n-1}x_{1n-1}+\epsilon_1\\
|
||||
y_2&=\theta_0x_{20}+\theta_1x_{21}+\theta_2x_{22}+\dots+\theta_{n-1}x_{2n-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{i}&=\beta_0x_{i0}+\beta_1x_{i1}+\beta_2x_{i2}+\dots+\beta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
y_{i}&=\theta_0x_{i0}+\theta_1x_{i1}+\theta_2x_{i2}+\dots+\theta_{n-1}x_{in-1}+\epsilon_1\\
|
||||
\dots & \dots \\
|
||||
y_{n-1}&=\beta_0x_{n-1,0}+\beta_1x_{n-1,2}+\beta_2x_{n-1,2}+\dots+\beta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
y_{n-1}&=\theta_0x_{n-1,0}+\theta_1x_{n-1,2}+\theta_2x_{n-1,2}+\dots+\theta_{n-1}x_{n-1,n-1}+\epsilon_{n-1}.\\
|
||||
\end{align*}
|
||||
!et
|
||||
|
||||
@@ -1829,10 +1815,10 @@ DesignMatrix.columns = ['1', 'A', 'A^(2/3)', 'A^(-1/3)', '1/A']
|
||||
display(DesignMatrix)
|
||||
!ec
|
||||
|
||||
With $\bm{\beta}\in {\mathbb{R}}^{p\times 1}$, it means that we will hereafter write our equations for the approximation as
|
||||
With $\bm{\theta}\in {\mathbb{R}}^{p\times 1}$, it means that we will hereafter write our equations for the approximation as
|
||||
!bt
|
||||
\[
|
||||
\bm{\tilde{y}}= \bm{X}\bm{\beta},
|
||||
\bm{\tilde{y}}= \bm{X}\bm{\theta},
|
||||
\]
|
||||
!et
|
||||
throughout these lectures.
|
||||
@@ -1841,22 +1827,22 @@ throughout these lectures.
|
||||
!split
|
||||
===== Optimizing our parameters, more details =====
|
||||
!bblock
|
||||
With the above we use the design matrix to define the approximation $\bm{\tilde{y}}$ via the unknown quantity $\bm{\beta}$ as
|
||||
With the above we use the design matrix to define the approximation $\bm{\tilde{y}}$ via the unknown quantity $\bm{\theta}$ as
|
||||
!bt
|
||||
\[
|
||||
\bm{\tilde{y}}= \bm{X}\bm{\beta},
|
||||
\bm{\tilde{y}}= \bm{X}\bm{\theta},
|
||||
\]
|
||||
!et
|
||||
and in order to find the optimal parameters $\beta_i$ instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values $y_i$ (which represent hopefully the exact values) and the parameterized values $\tilde{y}_i$, namely
|
||||
and in order to find the optimal parameters $\theta_i$ instead of solving the above linear algebra problem, we define a function which gives a measure of the spread between the values $y_i$ (which represent hopefully the exact values) and the parameterized values $\tilde{y}_i$, namely
|
||||
!bt
|
||||
\[
|
||||
C(\bm{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\bm{y}-\bm{\tilde{y}}\right)^T\left(\bm{y}-\bm{\tilde{y}}\right)\right\},
|
||||
C(\bm{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\left\{\left(\bm{y}-\bm{\tilde{y}}\right)^T\left(\bm{y}-\bm{\tilde{y}}\right)\right\},
|
||||
\]
|
||||
!et
|
||||
or using the matrix $\bm{X}$ and in a more compact matrix-vector notation as
|
||||
!bt
|
||||
\[
|
||||
C(\bm{\beta})=\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\beta}\right)^T\left(\bm{y}-\bm{X}\bm{\beta}\right)\right\}.
|
||||
C(\bm{\theta})=\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\theta}\right)^T\left(\bm{y}-\bm{X}\bm{\theta}\right)\right\}.
|
||||
\]
|
||||
!et
|
||||
This function is one possible way to define the so-called cost function.
|
||||
@@ -1868,10 +1854,10 @@ the function $C$ as
|
||||
|
||||
!bt
|
||||
\[
|
||||
C(\bm{\beta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
C(\bm{\theta})=\frac{1}{2n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2,
|
||||
\]
|
||||
!et
|
||||
since when taking the first derivative with respect to the unknown parameters $\beta$, the factor of $2$ cancels out.
|
||||
since when taking the first derivative with respect to the unknown parameters $\theta$, the factor of $2$ cancels out.
|
||||
!eblock
|
||||
|
||||
|
||||
@@ -1882,14 +1868,14 @@ since when taking the first derivative with respect to the unknown parameters $\
|
||||
The function
|
||||
!bt
|
||||
\[
|
||||
C(\bm{\beta})=\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\beta}\right)^T\left(\bm{y}-\bm{X}\bm{\beta}\right)\right\},
|
||||
C(\bm{\theta})=\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\theta}\right)^T\left(\bm{y}-\bm{X}\bm{\theta}\right)\right\},
|
||||
\]
|
||||
!et
|
||||
can be linked to the variance of the quantity $y_i$ if we interpret the latter as the mean value.
|
||||
When linking (see the discussion below) with the maximum likelihood approach below, we will indeed interpret $y_i$ as a mean value
|
||||
!bt
|
||||
\[
|
||||
y_{i}=\langle y_i \rangle = \beta_0x_{i,0}+\beta_1x_{i,1}+\beta_2x_{i,2}+\dots+\beta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
y_{i}=\langle y_i \rangle = \theta_0x_{i,0}+\theta_1x_{i,1}+\theta_2x_{i,2}+\dots+\theta_{n-1}x_{i,n-1}+\epsilon_i,
|
||||
\]
|
||||
!et
|
||||
|
||||
@@ -1902,29 +1888,29 @@ 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.
|
||||
|
||||
In order to find the parameters $\beta_i$ we will then minimize the spread of $C(\bm{\beta})$, that is we are going to solve the problem
|
||||
In order to find the parameters $\theta_i$ we will then minimize the spread of $C(\bm{\theta})$, that is we are going to solve the problem
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\beta}\right)^T\left(\bm{y}-\bm{X}\bm{\beta}\right)\right\}.
|
||||
{\displaystyle \min_{\bm{\theta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\theta}\right)^T\left(\bm{y}-\bm{X}\bm{\theta}\right)\right\}.
|
||||
\]
|
||||
!et
|
||||
In practical terms it means we will require
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial C(\bm{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
\frac{\partial C(\bm{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)^2\right]=0,
|
||||
\]
|
||||
!et
|
||||
which results in
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial C(\bm{\beta})}{\partial \beta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\beta_0x_{i,0}-\beta_1x_{i,1}-\beta_2x_{i,2}-\dots-\beta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
\frac{\partial C(\bm{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_{ij}\left(y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}\right)\right]=0,
|
||||
\]
|
||||
!et
|
||||
or in a matrix-vector form as
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial C(\bm{\beta})}{\partial \bm{\beta}} = 0 = \bm{X}^T\left( \bm{y}-\bm{X}\bm{\beta}\right).
|
||||
\frac{\partial C(\bm{\theta})}{\partial \bm{\theta}} = 0 = \bm{X}^T\left( \bm{y}-\bm{X}\bm{\theta}\right).
|
||||
\]
|
||||
!et
|
||||
|
||||
@@ -1938,19 +1924,19 @@ or in a matrix-vector form as
|
||||
We can rewrite
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial C(\bm{\beta})}{\partial \bm{\beta}} = 0 = \bm{X}^T\left( \bm{y}-\bm{X}\bm{\beta}\right),
|
||||
\frac{\partial C(\bm{\theta})}{\partial \bm{\theta}} = 0 = \bm{X}^T\left( \bm{y}-\bm{X}\bm{\theta}\right),
|
||||
\]
|
||||
!et
|
||||
as
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\bm{y} = \bm{X}^T\bm{X}\bm{\beta},
|
||||
\bm{X}^T\bm{y} = \bm{X}^T\bm{X}\bm{\theta},
|
||||
\]
|
||||
!et
|
||||
and if the matrix $\bm{X}^T\bm{X}$ is invertible we have the solution
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta} =\left(\bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}.
|
||||
\bm{\theta} =\left(\bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}.
|
||||
\]
|
||||
!et
|
||||
|
||||
@@ -1976,22 +1962,22 @@ _Small question_: Do you think the example we have at hand here (the nuclear bin
|
||||
The residuals $\bm{\epsilon}$ are in turn given by
|
||||
!bt
|
||||
\[
|
||||
\bm{\epsilon} = \bm{y}-\bm{\tilde{y}} = \bm{y}-\bm{X}\bm{\beta},
|
||||
\bm{\epsilon} = \bm{y}-\bm{\tilde{y}} = \bm{y}-\bm{X}\bm{\theta},
|
||||
\]
|
||||
!et
|
||||
and with
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\left( \bm{y}-\bm{X}\bm{\beta}\right)= 0,
|
||||
\bm{X}^T\left( \bm{y}-\bm{X}\bm{\theta}\right)= 0,
|
||||
\]
|
||||
!et
|
||||
we have
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\bm{\epsilon}=\bm{X}^T\left( \bm{y}-\bm{X}\bm{\beta}\right)= 0,
|
||||
\bm{X}^T\bm{\epsilon}=\bm{X}^T\left( \bm{y}-\bm{X}\bm{\theta}\right)= 0,
|
||||
\]
|
||||
!et
|
||||
meaning that the solution for $\bm{\beta}$ is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.
|
||||
meaning that the solution for $\bm{\theta}$ is the one which minimizes the residuals. Later we will link this with the maximum likelihood approach.
|
||||
|
||||
!eblock
|
||||
|
||||
@@ -2001,7 +1987,7 @@ Let us now return to our nuclear binding energies and simply code the above equa
|
||||
!split
|
||||
===== Own code for Ordinary Least Squares =====
|
||||
|
||||
It is rather straightforward to implement the matrix inversion and obtain the parameters $\bm{\beta}$. After having defined the matrix $\bm{X}$ we simply need to
|
||||
It is rather straightforward to implement the matrix inversion and obtain the parameters $\bm{\theta}$. After having defined the matrix $\bm{X}$ we simply need to
|
||||
write
|
||||
!bc pycod
|
||||
# matrix inversion to find beta
|
||||
@@ -2080,7 +2066,7 @@ as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\chi^2(\bm{\beta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\bm{y}-\bm{\tilde{y}}\right)^T\frac{1}{\bm{\Sigma^2}}\left(\bm{y}-\bm{\tilde{y}}\right)\right\},
|
||||
\chi^2(\bm{\theta})=\frac{1}{n}\sum_{i=0}^{n-1}\frac{\left(y_i-\tilde{y}_i\right)^2}{\sigma_i^2}=\frac{1}{n}\left\{\left(\bm{y}-\bm{\tilde{y}}\right)^T\frac{1}{\bm{\Sigma^2}}\left(\bm{y}-\bm{\tilde{y}}\right)\right\},
|
||||
\]
|
||||
!et
|
||||
where the matrix $\bm{\Sigma}$ is a diagonal matrix with $\sigma_i$ as matrix elements.
|
||||
@@ -2091,22 +2077,22 @@ where the matrix $\bm{\Sigma}$ is a diagonal matrix with $\sigma_i$ as matrix el
|
||||
===== The $\chi^2$ function =====
|
||||
!bblock
|
||||
|
||||
In order to find the parameters $\beta_i$ we will then minimize the spread of $\chi^2(\bm{\beta})$ by requiring
|
||||
In order to find the parameters $\theta_i$ we will then minimize the spread of $\chi^2(\bm{\theta})$ by requiring
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial \chi^2(\bm{\beta})}{\partial \beta_j} = \frac{\partial }{\partial \beta_j}\left[ \frac{1}{n}\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,
|
||||
\frac{\partial \chi^2(\bm{\theta})}{\partial \theta_j} = \frac{\partial }{\partial \theta_j}\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)^2\right]=0,
|
||||
\]
|
||||
!et
|
||||
which results in
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial \chi^2(\bm{\beta})}{\partial \beta_j} = -\frac{2}{n}\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,
|
||||
\frac{\partial \chi^2(\bm{\theta})}{\partial \theta_j} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}\frac{x_{ij}}{\sigma_i}\left(\frac{y_i-\theta_0x_{i,0}-\theta_1x_{i,1}-\theta_2x_{i,2}-\dots-\theta_{n-1}x_{i,n-1}}{\sigma_i}\right)\right]=0,
|
||||
\]
|
||||
!et
|
||||
or in a matrix-vector form as
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial \chi^2(\bm{\beta})}{\partial \bm{\beta}} = 0 = \bm{A}^T\left( \bm{b}-\bm{A}\bm{\beta}\right).
|
||||
\frac{\partial \chi^2(\bm{\theta})}{\partial \bm{\theta}} = 0 = \bm{A}^T\left( \bm{b}-\bm{A}\bm{\theta}\right).
|
||||
\]
|
||||
!et
|
||||
where we have defined the matrix $\bm{A} =\bm{X}/\bm{\Sigma}$ with matrix elements $a_{ij} = x_{ij}/\sigma_i$ and the vector $\bm{b}$ with elements $b_i = y_i/\sigma_i$.
|
||||
@@ -2119,19 +2105,19 @@ where we have defined the matrix $\bm{A} =\bm{X}/\bm{\Sigma}$ with matrix elemen
|
||||
We can rewrite
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial \chi^2(\bm{\beta})}{\partial \bm{\beta}} = 0 = \bm{A}^T\left( \bm{b}-\bm{A}\bm{\beta}\right),
|
||||
\frac{\partial \chi^2(\bm{\theta})}{\partial \bm{\theta}} = 0 = \bm{A}^T\left( \bm{b}-\bm{A}\bm{\theta}\right),
|
||||
\]
|
||||
!et
|
||||
as
|
||||
!bt
|
||||
\[
|
||||
\bm{A}^T\bm{b} = \bm{A}^T\bm{A}\bm{\beta},
|
||||
\bm{A}^T\bm{b} = \bm{A}^T\bm{A}\bm{\theta},
|
||||
\]
|
||||
!et
|
||||
and if the matrix $\bm{A}^T\bm{A}$ is invertible we have the solution
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta} =\left(\bm{A}^T\bm{A}\right)^{-1}\bm{A}^T\bm{b}.
|
||||
\bm{\theta} =\left(\bm{A}^T\bm{A}\right)^{-1}\bm{A}^T\bm{b}.
|
||||
\]
|
||||
!et
|
||||
!eblock
|
||||
@@ -2146,22 +2132,22 @@ If we then introduce the matrix
|
||||
\bm{H} = \left(\bm{A}^T\bm{A}\right)^{-1},
|
||||
\]
|
||||
!et
|
||||
we have then the following expression for the parameters $\beta_j$ (the matrix elements of $\bm{H}$ are $h_{ij}$)
|
||||
we have then the following expression for the parameters $\theta_j$ (the matrix elements of $\bm{H}$ are $h_{ij}$)
|
||||
!bt
|
||||
\[
|
||||
\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}
|
||||
\theta_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}
|
||||
\]
|
||||
!et
|
||||
We state without proof the expression for the uncertainty in the parameters $\beta_j$ as (we leave this as an exercise)
|
||||
We state without proof the expression for the uncertainty in the parameters $\theta_j$ as (we leave this as an exercise)
|
||||
!bt
|
||||
\[
|
||||
\sigma^2(\beta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \beta_j}{\partial y_i}\right)^2,
|
||||
\sigma^2(\theta_j) = \sum_{i=0}^{n-1}\sigma_i^2\left( \frac{\partial \theta_j}{\partial y_i}\right)^2,
|
||||
\]
|
||||
!et
|
||||
resulting in
|
||||
!bt
|
||||
\[
|
||||
\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}!
|
||||
\sigma^2(\theta_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}!
|
||||
\]
|
||||
!et
|
||||
!eblock
|
||||
@@ -2172,19 +2158,19 @@ resulting in
|
||||
The first step here is to approximate the function $y$ with a first-order polynomial, that is we write
|
||||
!bt
|
||||
\[
|
||||
y=y(x) \rightarrow y(x_i) \approx \beta_0+\beta_1 x_i.
|
||||
y=y(x) \rightarrow y(x_i) \approx \theta_0+\theta_1 x_i.
|
||||
\]
|
||||
!et
|
||||
By computing the derivatives of $\chi^2$ with respect to $\beta_0$ and $\beta_1$ show that these are given by
|
||||
By computing the derivatives of $\chi^2$ with respect to $\theta_0$ and $\theta_1$ show that these are given by
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial \chi^2(\bm{\beta})}{\partial \beta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
\frac{\partial \chi^2(\bm{\theta})}{\partial \theta_0} = -2\left[ \frac{1}{n}\sum_{i=0}^{n-1}\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0,
|
||||
\]
|
||||
!et
|
||||
and
|
||||
!bt
|
||||
\[
|
||||
\frac{\partial \chi^2(\bm{\beta})}{\partial \beta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\beta_0-\beta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
\frac{\partial \chi^2(\bm{\theta})}{\partial \theta_1} = -\frac{2}{n}\left[ \sum_{i=0}^{n-1}x_i\left(\frac{y_i-\theta_0-\theta_1x_{i}}{\sigma_i^2}\right)\right]=0.
|
||||
\]
|
||||
!et
|
||||
!eblock
|
||||
@@ -2229,225 +2215,24 @@ we obtain
|
||||
|
||||
!bt
|
||||
\[
|
||||
\beta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2},
|
||||
\theta_0 = \frac{\gamma_{xx}\gamma_y-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2},
|
||||
\]
|
||||
!et
|
||||
|
||||
!bt
|
||||
\[
|
||||
\beta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}.
|
||||
\theta_1 = \frac{\gamma_{xy}\gamma-\gamma_x\gamma_y}{\gamma\gamma_{xx}-\gamma_x^2}.
|
||||
\]
|
||||
!et
|
||||
|
||||
This approach (different linear and non-linear regression) suffers
|
||||
often from both being underdetermined and overdetermined in the
|
||||
unknown coefficients $\beta_i$. A better approach is to use the
|
||||
unknown coefficients $\theta_i$. A better approach is to use the
|
||||
Singular Value Decomposition (SVD) method discussed next week.
|
||||
|
||||
!eblock
|
||||
|
||||
|
||||
!split
|
||||
===== Fitting an Equation of State for Dense Nuclear Matter =====
|
||||
|
||||
Before we continue, let us introduce yet another example. We are going to fit the
|
||||
nuclear equation of state using results from many-body calculations.
|
||||
The equation of state we have made available here, as function of
|
||||
density, has been derived using modern nucleon-nucleon potentials with
|
||||
"the addition of three-body
|
||||
forces":"https://www.sciencedirect.com/science/article/pii/S0370157399001106". This
|
||||
time the file is presented as a standard _csv_ file.
|
||||
|
||||
The beginning of the Python code here is similar to what you have seen
|
||||
before, with the same initializations and declarations. We use also
|
||||
_pandas_ again, rather extensively in order to organize our data.
|
||||
|
||||
The difference now is that we use _Scikit-Learn's_ regression tools
|
||||
instead of our own matrix inversion implementation. Furthermore, we
|
||||
sneak in _Ridge_ regression (to be discussed below) which includes a
|
||||
hyperparameter $\lambda$, also to be explained below.
|
||||
|
||||
!split
|
||||
===== The code =====
|
||||
|
||||
!bc pycod
|
||||
# Common imports
|
||||
import os
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.pyplot as plt
|
||||
import sklearn.linear_model as skl
|
||||
from sklearn.metrics import mean_squared_error, r2_score, mean_absolute_error
|
||||
|
||||
# Where to save the figures and data files
|
||||
PROJECT_ROOT_DIR = "Results"
|
||||
FIGURE_ID = "Results/FigureFiles"
|
||||
DATA_ID = "DataFiles/"
|
||||
|
||||
if not os.path.exists(PROJECT_ROOT_DIR):
|
||||
os.mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
if not os.path.exists(FIGURE_ID):
|
||||
os.makedirs(FIGURE_ID)
|
||||
|
||||
if not os.path.exists(DATA_ID):
|
||||
os.makedirs(DATA_ID)
|
||||
|
||||
def image_path(fig_id):
|
||||
return os.path.join(FIGURE_ID, fig_id)
|
||||
|
||||
def data_path(dat_id):
|
||||
return os.path.join(DATA_ID, dat_id)
|
||||
|
||||
def save_fig(fig_id):
|
||||
plt.savefig(image_path(fig_id) + ".png", format='png')
|
||||
|
||||
infile = open(data_path("EoS.csv"),'r')
|
||||
|
||||
# Read the EoS data as csv file and organize the data into two arrays with density and energies
|
||||
EoS = pd.read_csv(infile, names=('Density', 'Energy'))
|
||||
EoS['Energy'] = pd.to_numeric(EoS['Energy'], errors='coerce')
|
||||
EoS = EoS.dropna()
|
||||
Energies = EoS['Energy']
|
||||
Density = EoS['Density']
|
||||
# The design matrix now as function of various polytrops
|
||||
X = np.zeros((len(Density),4))
|
||||
X[:,3] = Density**(4.0/3.0)
|
||||
X[:,2] = Density
|
||||
X[:,1] = Density**(2.0/3.0)
|
||||
X[:,0] = 1
|
||||
|
||||
# We use now Scikit-Learn's linear regressor and ridge regressor
|
||||
# OLS part
|
||||
clf = skl.LinearRegression().fit(X, Energies)
|
||||
ytilde = clf.predict(X)
|
||||
EoS['Eols'] = ytilde
|
||||
# The mean squared error
|
||||
print("Mean squared error: %.2f" % mean_squared_error(Energies, ytilde))
|
||||
# Explained variance score: 1 is perfect prediction
|
||||
print('Variance score: %.2f' % r2_score(Energies, ytilde))
|
||||
# Mean absolute error
|
||||
print('Mean absolute error: %.2f' % mean_absolute_error(Energies, ytilde))
|
||||
print(clf.coef_, clf.intercept_)
|
||||
|
||||
# The Ridge regression with a hyperparameter lambda = 0.1
|
||||
_lambda = 0.1
|
||||
clf_ridge = skl.Ridge(alpha=_lambda).fit(X, Energies)
|
||||
yridge = clf_ridge.predict(X)
|
||||
EoS['Eridge'] = yridge
|
||||
# The mean squared error
|
||||
print("Mean squared error: %.2f" % mean_squared_error(Energies, yridge))
|
||||
# Explained variance score: 1 is perfect prediction
|
||||
print('Variance score: %.2f' % r2_score(Energies, yridge))
|
||||
# Mean absolute error
|
||||
print('Mean absolute error: %.2f' % mean_absolute_error(Energies, yridge))
|
||||
print(clf_ridge.coef_, clf_ridge.intercept_)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_xlabel(r'$\rho[\mathrm{fm}^{-3}]$')
|
||||
ax.set_ylabel(r'Energy per particle')
|
||||
ax.plot(EoS['Density'], EoS['Energy'], alpha=0.7, lw=2,
|
||||
label='Theoretical data')
|
||||
ax.plot(EoS['Density'], EoS['Eols'], alpha=0.7, lw=2, c='m',
|
||||
label='OLS')
|
||||
ax.plot(EoS['Density'], EoS['Eridge'], alpha=0.7, lw=2, c='g',
|
||||
label='Ridge $\lambda = 0.1$')
|
||||
ax.legend()
|
||||
save_fig("EoSfitting")
|
||||
plt.show()
|
||||
!ec
|
||||
|
||||
The above simple polynomial in density $\rho$ gives an excellent fit
|
||||
to the data.
|
||||
|
||||
We note also that there is a small deviation between the
|
||||
standard OLS and the Ridge regression at higher densities. We discuss this in more detail
|
||||
below.
|
||||
|
||||
|
||||
!split
|
||||
===== Splitting our Data in Training and Test data =====
|
||||
|
||||
It is normal in essentially all Machine Learning studies to split the
|
||||
data in a training set and a test set (sometimes also an additional
|
||||
validation set). _Scikit-Learn_ has an own function for this. There
|
||||
is no explicit recipe for how much data should be included as training
|
||||
data and say test data. An accepted rule of thumb is to use
|
||||
approximately $2/3$ to $4/5$ of the data as training data. We will
|
||||
postpone a discussion of this splitting to the end of these notes and
|
||||
our discussion of the so-called _bias-variance_ tradeoff. Here we
|
||||
limit ourselves to repeat the above equation of state fitting example
|
||||
but now splitting the data into a training set and a test set.
|
||||
|
||||
!bc pycod
|
||||
import os
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
from sklearn.model_selection import train_test_split
|
||||
# Where to save the figures and data files
|
||||
PROJECT_ROOT_DIR = "Results"
|
||||
FIGURE_ID = "Results/FigureFiles"
|
||||
DATA_ID = "DataFiles/"
|
||||
|
||||
if not os.path.exists(PROJECT_ROOT_DIR):
|
||||
os.mkdir(PROJECT_ROOT_DIR)
|
||||
|
||||
if not os.path.exists(FIGURE_ID):
|
||||
os.makedirs(FIGURE_ID)
|
||||
|
||||
if not os.path.exists(DATA_ID):
|
||||
os.makedirs(DATA_ID)
|
||||
|
||||
def image_path(fig_id):
|
||||
return os.path.join(FIGURE_ID, fig_id)
|
||||
|
||||
def data_path(dat_id):
|
||||
return os.path.join(DATA_ID, dat_id)
|
||||
|
||||
def save_fig(fig_id):
|
||||
plt.savefig(image_path(fig_id) + ".png", format='png')
|
||||
|
||||
def R2(y_data, y_model):
|
||||
return 1 - np.sum((y_data - y_model) ** 2) / np.sum((y_data - np.mean(y_data)) ** 2)
|
||||
def MSE(y_data,y_model):
|
||||
n = np.size(y_model)
|
||||
return np.sum((y_data-y_model)**2)/n
|
||||
|
||||
infile = open(data_path("EoS.csv"),'r')
|
||||
|
||||
# Read the EoS data as csv file and organized into two arrays with density and energies
|
||||
EoS = pd.read_csv(infile, names=('Density', 'Energy'))
|
||||
EoS['Energy'] = pd.to_numeric(EoS['Energy'], errors='coerce')
|
||||
EoS = EoS.dropna()
|
||||
Energies = EoS['Energy']
|
||||
Density = EoS['Density']
|
||||
# The design matrix now as function of various polytrops
|
||||
X = np.zeros((len(Density),5))
|
||||
X[:,0] = 1
|
||||
X[:,1] = Density**(2.0/3.0)
|
||||
X[:,2] = Density
|
||||
X[:,3] = Density**(4.0/3.0)
|
||||
X[:,4] = Density**(5.0/3.0)
|
||||
# We split the data in test and training data
|
||||
X_train, X_test, y_train, y_test = train_test_split(X, Energies, test_size=0.2)
|
||||
# matrix inversion to find beta
|
||||
beta = np.linalg.inv(X_train.T.dot(X_train)).dot(X_train.T).dot(y_train)
|
||||
# and then make the prediction
|
||||
ytilde = X_train @ beta
|
||||
print("Training R2")
|
||||
print(R2(y_train,ytilde))
|
||||
print("Training MSE")
|
||||
print(MSE(y_train,ytilde))
|
||||
ypredict = X_test @ beta
|
||||
print("Test R2")
|
||||
print(R2(y_test,ypredict))
|
||||
print("Test MSE")
|
||||
print(MSE(y_test,ypredict))
|
||||
!ec
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user