This commit is contained in:
Morten Hjorth-Jensen
2024-09-22 21:21:59 +02:00
parent 0a6ba7c08d
commit 80f0f2ffab
102 changed files with 18315 additions and 2027 deletions
+79 -69
View File
@@ -298,6 +298,16 @@ const thebe_selector_output = ".output, .cell_output"
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
@@ -711,10 +721,10 @@ covariance matrix through the <strong>np.linalg.eig()</strong> function.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.14934258650797513
4.548263635652985
[[ 1.0875061 3.3260513 ]
[ 3.3260513 11.10994958]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.13035147135400782
4.25879315330607
[[0.86867512 2.59009792]
[2.59009792 8.82533209]]
</pre></div>
</div>
</div>
@@ -754,10 +764,10 @@ a more brute force way. Here we scale the mean values for each column of the des
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.09291556244521161
2.096511363983559
[[1. 0.7198234]
[0.7198234 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.08690184845323
1.521422502348998
[[1. 0.69768266]
[0.69768266 1. ]]
</pre></div>
</div>
</div>
@@ -786,30 +796,30 @@ this matrix we easily see that it is a positive definite matrix.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[ 0.20480187 0.26586817]
[ 0.72601722 1.13675593]
[ 0.02649469 -0.9834505 ]
[ 0.97548406 1.6266783 ]
[-1.59078383 -4.25673276]
[-0.40596423 -0.31486917]
[-0.34654596 -1.94627617]
[-1.33062878 -3.73785069]
[ 2.22810365 9.25389111]
[-0.48697869 -1.04401421]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[ 1.14550854 1.96870431]
[ 0.79787194 3.11438414]
[-0.18497496 -1.31315504]
[-1.52706754 -4.97482498]
[-1.30190897 -3.11113486]
[-0.08421808 -1.70928399]
[ 0.11992194 -0.07776381]
[-0.90717653 -2.20404927]
[ 1.05201041 5.38762019]
[ 0.89003324 2.9195033 ]]
0 1
0 0.204802 0.265868
1 0.726017 1.136756
2 0.026495 -0.983450
3 0.975484 1.626678
4 -1.590784 -4.256733
5 -0.405964 -0.314869
6 -0.346546 -1.946276
7 -1.330629 -3.737851
8 2.228104 9.253891
9 -0.486979 -1.044014
0 1.145509 1.968704
1 0.797872 3.114384
2 -0.184975 -1.313155
3 -1.527068 -4.974825
4 -1.301909 -3.111135
5 -0.084218 -1.709284
6 0.119922 -0.077764
7 -0.907177 -2.204049
8 1.052010 5.387620
9 0.890033 2.919503
0 1
0 1.000000 0.950423
1 0.950423 1.000000
0 1.000000 0.937057
1 0.937057 1.000000
</pre></div>
</div>
</div>
@@ -866,37 +876,37 @@ this matrix we easily see that it is a positive definite matrix.</p>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0 1 2 3 4 5 6 7 \
0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.0 0.072147 0.072728 0.071758 0.072209 0.072843 0.064428 0.064668
2 0.0 0.072728 0.075385 0.069979 0.071530 0.073408 0.061386 0.062260
3 0.0 0.071758 0.069979 0.076968 0.076244 0.075522 0.072286 0.071935
4 0.0 0.072209 0.071530 0.076244 0.076161 0.076150 0.070898 0.070950
5 0.0 0.072843 0.073408 0.075522 0.076150 0.076934 0.069399 0.069885
6 0.0 0.064428 0.061386 0.072286 0.070898 0.069399 0.069873 0.069179
7 0.0 0.064668 0.062260 0.071935 0.070950 0.069885 0.069179 0.068758
8 0.0 0.065062 0.063354 0.071655 0.071103 0.070514 0.068494 0.068360
9 0.0 0.065616 0.064690 0.071433 0.071356 0.071291 0.067793 0.067967
10 0.0 0.057287 0.053787 0.066153 0.064505 0.062691 0.065212 0.064382
11 0.0 0.057387 0.054286 0.065949 0.064573 0.063048 0.064834 0.064202
12 0.0 0.057607 0.054932 0.065830 0.064739 0.063518 0.064507 0.064077
13 0.0 0.057951 0.055737 0.065788 0.065001 0.064107 0.064218 0.064000
14 0.0 0.058422 0.056717 0.065818 0.065358 0.064820 0.063954 0.063959
1 0.0 0.080345 0.078573 0.079174 0.077839 0.076679 0.070275 0.069320
2 0.0 0.078573 0.078146 0.079202 0.078688 0.078268 0.071580 0.071186
3 0.0 0.079174 0.079202 0.083342 0.083016 0.082784 0.076947 0.076648
4 0.0 0.077839 0.078688 0.083016 0.083260 0.083547 0.077485 0.077601
5 0.0 0.076679 0.078268 0.082784 0.083547 0.084312 0.078044 0.078541
6 0.0 0.070275 0.071580 0.076947 0.077485 0.078044 0.072947 0.073258
7 0.0 0.069320 0.071186 0.076648 0.077601 0.078541 0.073258 0.073882
8 0.0 0.068539 0.070918 0.076479 0.077813 0.079107 0.073647 0.074561
9 0.0 0.067922 0.070772 0.076434 0.078123 0.079747 0.074115 0.075302
10 0.0 0.061319 0.063395 0.068977 0.070098 0.071191 0.066686 0.067431
11 0.0 0.060726 0.063206 0.068843 0.070274 0.071656 0.066988 0.067974
12 0.0 0.060275 0.063130 0.068827 0.070547 0.072200 0.067374 0.068587
13 0.0 0.059956 0.063161 0.068924 0.070916 0.072824 0.067843 0.069270
14 0.0 0.059761 0.063294 0.069129 0.071379 0.073528 0.068394 0.070024
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.065062 0.065616 0.057287 0.057387 0.057607 0.057951 0.058422
2 0.063354 0.064690 0.053787 0.054286 0.054932 0.055737 0.056717
3 0.071655 0.071433 0.066153 0.065949 0.065830 0.065788 0.065818
4 0.071103 0.071356 0.064505 0.064573 0.064739 0.065001 0.065358
5 0.070514 0.071291 0.062691 0.063048 0.063518 0.064107 0.064820
6 0.068494 0.067793 0.065212 0.064834 0.064507 0.064218 0.063954
7 0.068360 0.067967 0.064382 0.064202 0.064077 0.064000 0.063959
8 0.068268 0.068206 0.063526 0.063549 0.063637 0.063781 0.063977
9 0.068206 0.068504 0.062616 0.062853 0.063163 0.063545 0.063995
10 0.063526 0.062616 0.061724 0.061284 0.060870 0.060471 0.060071
11 0.063549 0.062853 0.061284 0.060994 0.060734 0.060490 0.060251
12 0.063637 0.063163 0.060870 0.060734 0.060629 0.060547 0.060475
13 0.063781 0.063545 0.060471 0.060490 0.060547 0.060631 0.060735
14 0.063977 0.063995 0.060071 0.060251 0.060475 0.060735 0.061025
1 0.068539 0.067922 0.061319 0.060726 0.060275 0.059956 0.059761
2 0.070918 0.070772 0.063395 0.063206 0.063130 0.063161 0.063294
3 0.076479 0.076434 0.068977 0.068843 0.068827 0.068924 0.069129
4 0.077813 0.078123 0.070098 0.070274 0.070547 0.070916 0.071379
5 0.079107 0.079747 0.071191 0.071656 0.072200 0.072824 0.073528
6 0.073647 0.074115 0.066686 0.066988 0.067374 0.067843 0.068394
7 0.074561 0.075302 0.067431 0.067974 0.068587 0.069270 0.070024
8 0.075513 0.076508 0.068215 0.068985 0.069811 0.070696 0.071643
9 0.076508 0.077745 0.069045 0.070027 0.071055 0.072132 0.073262
10 0.068215 0.069045 0.061898 0.062520 0.063197 0.063933 0.064728
11 0.068985 0.070027 0.062520 0.063332 0.064189 0.065096 0.066054
12 0.069811 0.071055 0.063197 0.064189 0.065217 0.066286 0.067400
13 0.070696 0.072132 0.063933 0.065096 0.066286 0.067511 0.068775
14 0.071643 0.073262 0.064728 0.066054 0.067400 0.068775 0.070183
</pre></div>
</div>
</div>
@@ -1085,10 +1095,10 @@ We can write our own code or simply use either the functionaly of <strong>numpy<
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span> 0 1
0 3.935972 1.991047
1 1.991047 2.000783
[[3.93597168 1.99104747]
[1.99104747 2.00078324]]
0 4.032196 2.034476
1 2.034476 1.997746
[[4.0321956 2.03447649]
[2.03447649 1.99774602]]
</pre></div>
</div>
</div>
@@ -1115,8 +1125,8 @@ Our own code here is not very elegant and asks for obvious improvements. It is t
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Centered covariance using own code
[[3.93597168 1.99104747]
[1.99104747 2.00078324]]
[[4.0321956 2.03447649]
[2.03447649 1.99774602]]
</pre></div>
</div>
<img alt="_images/chapter8_65_1.png" src="_images/chapter8_65_1.png" />
@@ -1176,16 +1186,16 @@ questions.</p>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvalues of Covariance matrix
5.182086698929565
0.7546682196464342
5.2895786617507
0.7403629637766833
First eigenvector
[0.84767088 0.53052247]
[0.85064942 0.52573336]
Second eigenvector
[-0.53052247 0.84767088]
[-0.52573336 0.85064942]
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvector of largest eigenvalue
[0.84767088 0.53052247]
[-0.85064942 -0.52573336]
</pre></div>
</div>
</div>