book update

This commit is contained in:
Morten Hjorth-Jensen
2021-04-26 09:20:25 -04:00
parent 4446c1be47
commit c82f437bcf
64 changed files with 6377 additions and 1162 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

File diff suppressed because it is too large Load Diff
+15 -4
View File
@@ -58,7 +58,7 @@
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="2. Resampling Methods" href="chapter2.html" />
<link rel="prev" title="1. Elements of Probability Theory and Statistical Data Analysis" href="statistics.html" />
<link rel="prev" title="2. Linear Algebra, Handling of Arrays and more Python Features" href="linalg.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -750,8 +760,9 @@ For an <span class="math notranslate nohighlight">\(N\times N\)</span> matrix <
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 0.82672272 0.45257846 -3.50535083 -0.60868993 -0.32256204 0.35390727
-0.8063309 -0.22751293 -0.26205577 -0.65826338]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 1.59542395e+00 -1.76635856e-01 6.09517402e-01 7.37482326e-01
1.23310910e+00 8.39779531e-04 -1.09487746e+00 8.32655571e-01
-8.22808167e-01 9.71128130e-01]
</pre></div>
</div>
</div>
@@ -2921,7 +2932,7 @@ techniques.</p>
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="statistics.html" title="previous page"><span class="section-number">1. </span>Elements of Probability Theory and Statistical Data Analysis</a>
<a class='left-prev' id="prev-link" href="linalg.html" title="previous page"><span class="section-number">2. </span>Linear Algebra, Handling of Arrays and more Python Features</a>
<a class='right-next' id="next-link" href="chapter2.html" title="next page"><span class="section-number">2. </span>Resampling Methods</a>
</div>
+35 -23
View File
@@ -57,6 +57,7 @@
<script async="async" src="_static/sphinx-thebe.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="3. Solving Differential Equations with Deep Learning" href="chapter11.html" />
<link rel="prev" title="1. Neural networks" href="chapter9.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -127,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -205,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -1860,53 +1871,53 @@ Accuracy score on test set: 0.8388888888888889
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Lambda = 1.0
Accuracy score on test set: 0.9055555555555556
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 0.1
Learning rate = 0.1
Lambda = 10.0
Accuracy score on test set: 0.8666666666666667
Learning rate = 1.0
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 1e-05
Accuracy score on test set: 0.09166666666666666
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Learning rate = 1.0
Lambda = 0.0001
Accuracy score on test set: 0.11944444444444445
Learning rate = 1.0
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 0.001
Accuracy score on test set: 0.1361111111111111
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Learning rate = 1.0
Lambda = 0.01
Accuracy score on test set: 0.1527777777777778
Learning rate = 1.0
Lambda = 0.1
Accuracy score on test set: 0.16666666666666666
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 1.0
Accuracy score on test set: 0.1111111111111111
Lambda = 0.1
Accuracy score on test set: 0.16666666666666666
Learning rate = 1.0
Lambda = 1.0
Accuracy score on test set: 0.1111111111111111
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 1.0
Lambda = 10.0
Accuracy score on test set: 0.05
Learning rate = 10.0
Lambda = 1e-05
Accuracy score on test set: 0.08888888888888889
Learning rate = 10.0
Lambda = 0.0001
Accuracy score on test set: 0.08611111111111111
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Learning rate = 10.0
Lambda = 0.0001
Accuracy score on test set: 0.08611111111111111
Learning rate = 10.0
Lambda = 0.001
Accuracy score on test set: 0.08888888888888889
@@ -2624,6 +2635,7 @@ features).</p>
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="chapter9.html" title="previous page"><span class="section-number">1. </span>Neural networks</a>
<a class='right-next' id="next-link" href="chapter11.html" title="next page"><span class="section-number">3. </span>Solving Differential Equations with Deep Learning</a>
</div>
File diff suppressed because it is too large Load Diff
+14 -4
View File
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -582,10 +592,10 @@ number <span class="math notranslate nohighlight">\(i\)</span> is left out. Usin
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Runtime: 0.142715 sec
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Runtime: 0.139172 sec
Jackknife Statistics :
original bias std. error
100.386 100.376 0.148723
100.048 100.038 0.150004
</pre></div>
</div>
</div>
@@ -713,10 +723,10 @@ theorem.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Runtime: 1.73555 sec
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Runtime: 1.73359 sec
Bootstrap Statistics :
original bias std. error
99.9151 14.9927 99.9159 0.15258
99.9929 15.0315 99.994 0.150978
</pre></div>
</div>
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
+68 -58
View File
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -876,10 +886,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.05952725829739267
4.386262724250306
[[ 1.1558068 3.35522344]
[ 3.35522344 10.90654923]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.062127739929490035
4.226441441217558
[[0.95977893 2.78652875]
[2.78652875 9.09409124]]
</pre></div>
</div>
</div>
@@ -916,10 +926,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.09168618934140788
1.945123703671126
[[1. 0.72291211]
[0.72291211 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.09053391104887817
1.9755272664385481
[[1. 0.64723729]
[0.64723729 1. ]]
</pre></div>
</div>
</div>
@@ -948,30 +958,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.2701033 0.76102689]
[ 0.51167594 2.72484235]
[ 0.32455001 -1.43364263]
[-0.53774919 -1.34290169]
[-0.05260429 -0.42595379]
[ 0.07893835 0.61280302]
[-1.6055745 -4.25652444]
[ 0.85403864 3.64196375]
[ 0.57068381 2.34793363]
[-0.41406207 -2.62954709]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[ 0.52374318 0.7528421 ]
[-1.07892554 -3.5697027 ]
[ 0.65536057 2.84854 ]
[-0.9936011 -1.75368597]
[-0.22233456 -1.63866932]
[ 1.10799046 4.51410028]
[ 1.30401938 5.04686521]
[ 0.70055962 1.28566384]
[-1.69423925 -6.23684061]
[-0.30257276 -1.24911284]]
0 1
0 0.270103 0.761027
1 0.511676 2.724842
2 0.324550 -1.433643
3 -0.537749 -1.342902
4 -0.052604 -0.425954
5 0.078938 0.612803
6 -1.605575 -4.256524
7 0.854039 3.641964
8 0.570684 2.347934
9 -0.414062 -2.629547
0 0.523743 0.752842
1 -1.078926 -3.569703
2 0.655361 2.848540
3 -0.993601 -1.753686
4 -0.222335 -1.638669
5 1.107990 4.514100
6 1.304019 5.046865
7 0.700560 1.285664
8 -1.694239 -6.236841
9 -0.302573 -1.249113
0 1
0 1.000000 0.894794
1 0.894794 1.000000
0 1.000000 0.967871
1 0.967871 1.000000
</pre></div>
</div>
</div>
@@ -1028,37 +1038,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.090640 0.079152 0.086791 0.086033 0.083807 0.076613 0.076853
2 0.0 0.079152 0.070665 0.073700 0.073719 0.072669 0.064120 0.064658
3 0.0 0.086791 0.073700 0.089130 0.086860 0.082986 0.082366 0.081697
4 0.0 0.086033 0.073719 0.086860 0.085104 0.081822 0.079399 0.079040
5 0.0 0.083807 0.072669 0.082986 0.081822 0.079272 0.074974 0.074942
6 0.0 0.076613 0.064120 0.082366 0.079399 0.074974 0.078615 0.077369
7 0.0 0.076853 0.064658 0.081697 0.079040 0.074942 0.077369 0.076344
8 0.0 0.076988 0.065180 0.080804 0.078501 0.074783 0.075867 0.075083
9 0.0 0.076812 0.065537 0.079464 0.077568 0.074305 0.073910 0.073388
10 0.0 0.067721 0.056185 0.075172 0.071927 0.067396 0.073456 0.071888
11 0.0 0.067838 0.056481 0.074711 0.071675 0.067356 0.072592 0.071185
12 0.0 0.068022 0.056864 0.074259 0.071451 0.067365 0.071702 0.070467
13 0.0 0.068244 0.057318 0.073774 0.071219 0.067394 0.070744 0.069695
14 0.0 0.068449 0.057811 0.073183 0.070913 0.067391 0.069650 0.068802
1 0.0 0.076075 0.081429 0.075275 0.076780 0.077999 0.067453 0.067971
2 0.0 0.081429 0.088214 0.081300 0.083371 0.085063 0.072811 0.073594
3 0.0 0.075275 0.081300 0.080335 0.082127 0.083567 0.075400 0.075990
4 0.0 0.076780 0.083371 0.082127 0.084184 0.085857 0.076996 0.077729
5 0.0 0.077999 0.085063 0.083567 0.085857 0.087738 0.078264 0.079128
6 0.0 0.067453 0.072811 0.075400 0.076996 0.078264 0.072961 0.073444
7 0.0 0.067971 0.073594 0.075990 0.077729 0.079128 0.073444 0.074016
8 0.0 0.068431 0.074291 0.076495 0.078367 0.079889 0.073843 0.074498
9 0.0 0.068860 0.074936 0.076947 0.078943 0.080582 0.074186 0.074922
10 0.0 0.059693 0.064192 0.068842 0.070144 0.071159 0.068084 0.068427
11 0.0 0.059875 0.064519 0.069009 0.070400 0.071499 0.068172 0.068575
12 0.0 0.060056 0.064837 0.069164 0.070641 0.071822 0.068246 0.068709
13 0.0 0.060243 0.065156 0.069319 0.070878 0.072139 0.068315 0.068837
14 0.0 0.060442 0.065483 0.069478 0.071119 0.072459 0.068387 0.068966
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.076988 0.076812 0.067721 0.067838 0.068022 0.068244 0.068449
2 0.065180 0.065537 0.056185 0.056481 0.056864 0.057318 0.057811
3 0.080804 0.079464 0.075172 0.074711 0.074259 0.073774 0.073183
4 0.078501 0.077568 0.071927 0.071675 0.071451 0.071219 0.070913
5 0.074783 0.074305 0.067396 0.067356 0.067365 0.067394 0.067391
6 0.075867 0.073910 0.073456 0.072592 0.071702 0.070744 0.069650
7 0.075083 0.073388 0.071888 0.071185 0.070467 0.069695 0.068802
8 0.074088 0.072685 0.070067 0.069534 0.069000 0.068429 0.067755
9 0.072685 0.071614 0.067818 0.067465 0.067127 0.066772 0.066339
10 0.070067 0.067818 0.069854 0.068745 0.067594 0.066361 0.064984
11 0.069534 0.067465 0.068745 0.067758 0.066737 0.065641 0.064409
12 0.069000 0.067127 0.067594 0.066737 0.065852 0.064903 0.063827
13 0.068429 0.066772 0.066361 0.065641 0.064903 0.064110 0.063205
14 0.067755 0.066339 0.064984 0.064409 0.063827 0.063205 0.062484
1 0.068431 0.068860 0.059693 0.059875 0.060056 0.060243 0.060442
2 0.074291 0.074936 0.064192 0.064519 0.064837 0.065156 0.065483
3 0.076495 0.076947 0.068842 0.069009 0.069164 0.069319 0.069478
4 0.078367 0.078943 0.070144 0.070400 0.070641 0.070878 0.071119
5 0.079889 0.080582 0.071159 0.071499 0.071822 0.072139 0.072459
6 0.073843 0.074186 0.068084 0.068172 0.068246 0.068315 0.068387
7 0.074498 0.074922 0.068427 0.068575 0.068709 0.068837 0.068966
8 0.075062 0.075564 0.068693 0.068901 0.069093 0.069278 0.069465
9 0.075564 0.076143 0.068909 0.069174 0.069423 0.069665 0.069908
10 0.068693 0.068909 0.064578 0.064582 0.064574 0.064559 0.064545
11 0.068901 0.069174 0.064582 0.064632 0.064668 0.064698 0.064728
12 0.069093 0.069423 0.064574 0.064668 0.064748 0.064822 0.064896
13 0.069278 0.069665 0.064559 0.064698 0.064822 0.064940 0.065058
14 0.069465 0.069908 0.064545 0.064728 0.064896 0.065058 0.065220
</pre></div>
</div>
</div>
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
+13 -3
View File
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -536,9 +546,9 @@ predicting the target features of query instances is as follows:</p>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>2nd degree coefficients:
zero power: -0.9578173338515308
first power: -0.06900718352507469
second power: 0.0001745458342080017
zero power: 1.3961181500194275
first power: -0.0007183308296987448
second power: 0.0002882855342275337
</pre></div>
</div>
<img alt="_images/chapter6_1_1.png" src="_images/chapter6_1_1.png" />
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
+80 -70
View File
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -516,10 +526,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.013770665200945059
4.0696182771562865
[[ 1.28864075 3.9567042 ]
[ 3.9567042 12.91108638]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.2310524795427768
3.1831903689627863
[[0.86117632 2.59603122]
[2.59603122 9.06044826]]
</pre></div>
</div>
</div>
@@ -559,10 +569,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.09677449095137611
2.1297860009663863
[[1. 0.72674076]
[0.72674076 1. ]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.08745913868064381
2.1128123336365077
[[1. 0.6798478]
[0.6798478 1. ]]
</pre></div>
</div>
</div>
@@ -591,30 +601,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>[[ 1.10924603 3.83689962]
[-1.78744085 -5.79440072]
[-0.99810985 -3.0835973 ]
[ 0.02436339 -0.99150612]
[ 1.282947 4.23630419]
[-0.47573169 -0.92807223]
[-0.45955372 -1.52210478]
[-0.27330595 0.26924602]
[ 0.32511025 0.73840521]
[ 1.2524754 3.23882611]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[ 1.21030078 4.50152769]
[ 0.85231126 2.49259646]
[-0.27754082 -0.99161035]
[-0.05499028 -0.95681341]
[ 0.65405197 0.57844946]
[ 0.12802926 0.88441436]
[ 0.43424077 1.60051748]
[-1.57205214 -3.89834457]
[-0.77949144 -1.89899948]
[-0.59485937 -2.31173763]]
0 1
0 1.109246 3.836900
1 -1.787441 -5.794401
2 -0.998110 -3.083597
3 0.024363 -0.991506
4 1.282947 4.236304
5 -0.475732 -0.928072
6 -0.459554 -1.522105
7 -0.273306 0.269246
8 0.325110 0.738405
9 1.252475 3.238826
0 1
0 1.00000 0.98078
1 0.98078 1.00000
0 1.210301 4.501528
1 0.852311 2.492596
2 -0.277541 -0.991610
3 -0.054990 -0.956813
4 0.654052 0.578449
5 0.128029 0.884414
6 0.434241 1.600517
7 -1.572052 -3.898345
8 -0.779491 -1.898999
9 -0.594859 -2.311738
0 1
0 1.000000 0.957565
1 0.957565 1.000000
</pre></div>
</div>
</div>
@@ -671,37 +681,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.088871 0.091057 0.086480 0.086882 0.087207 0.076599 0.076736
2 0.0 0.091057 0.094219 0.089279 0.090116 0.090850 0.079397 0.079778
3 0.0 0.086480 0.089279 0.089816 0.090608 0.091280 0.082607 0.083021
4 0.0 0.086882 0.090116 0.090608 0.091649 0.092562 0.083598 0.084176
5 0.0 0.087207 0.090850 0.091280 0.092562 0.093708 0.084468 0.085206
6 0.0 0.076599 0.079397 0.082607 0.083598 0.084468 0.077844 0.078449
7 0.0 0.076736 0.079778 0.083021 0.084176 0.085206 0.078449 0.079175
8 0.0 0.076896 0.080176 0.083441 0.084757 0.085945 0.079053 0.079897
9 0.0 0.077088 0.080599 0.083875 0.085351 0.086696 0.079662 0.080623
10 0.0 0.066962 0.069634 0.074011 0.075111 0.076098 0.070962 0.071693
11 0.0 0.067119 0.069952 0.074388 0.075607 0.076712 0.071496 0.072320
12 0.0 0.067315 0.070309 0.074797 0.076135 0.077358 0.072056 0.072972
13 0.0 0.067553 0.070705 0.075243 0.076699 0.078039 0.072646 0.073655
14 0.0 0.067832 0.071144 0.075726 0.077300 0.078758 0.073267 0.074370
1 0.0 0.091583 0.077830 0.092209 0.086333 0.080182 0.084446 0.080360
2 0.0 0.077830 0.067325 0.077735 0.073465 0.068967 0.071391 0.068389
3 0.0 0.092209 0.077735 0.099350 0.092714 0.085784 0.094735 0.090145
4 0.0 0.086333 0.073465 0.092714 0.086992 0.080974 0.088533 0.084586
5 0.0 0.080182 0.068967 0.085784 0.080974 0.075877 0.082067 0.078752
6 0.0 0.084446 0.071391 0.094735 0.088533 0.082067 0.092739 0.088427
7 0.0 0.080360 0.068389 0.090145 0.084586 0.078752 0.088427 0.084585
8 0.0 0.076446 0.065511 0.085713 0.080765 0.075532 0.084250 0.080847
9 0.0 0.072627 0.062704 0.081361 0.076998 0.072349 0.080136 0.077151
10 0.0 0.076483 0.065094 0.088105 0.082612 0.076881 0.087850 0.084014
11 0.0 0.073208 0.062649 0.084453 0.079459 0.074213 0.084413 0.080946
12 0.0 0.070145 0.060358 0.081016 0.076483 0.071690 0.081166 0.078040
13 0.0 0.067263 0.058198 0.077760 0.073657 0.069286 0.078077 0.075268
14 0.0 0.064527 0.056149 0.074647 0.070949 0.066978 0.075114 0.072600
8 9 10 11 12 13 14
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
1 0.076896 0.077088 0.066962 0.067119 0.067315 0.067553 0.067832
2 0.080176 0.080599 0.069634 0.069952 0.070309 0.070705 0.071144
3 0.083441 0.083875 0.074011 0.074388 0.074797 0.075243 0.075726
4 0.084757 0.085351 0.075111 0.075607 0.076135 0.076699 0.077300
5 0.085945 0.086696 0.076098 0.076712 0.077358 0.078039 0.078758
6 0.079053 0.079662 0.070962 0.071496 0.072056 0.072646 0.073267
7 0.079897 0.080623 0.071693 0.072320 0.072972 0.073655 0.074370
8 0.080736 0.081579 0.072417 0.073137 0.073882 0.074657 0.075466
9 0.081579 0.082540 0.073144 0.073955 0.074793 0.075662 0.076565
10 0.072417 0.073144 0.065549 0.066186 0.066845 0.067528 0.068238
11 0.073137 0.073955 0.066186 0.066898 0.067632 0.068392 0.069179
12 0.073882 0.074793 0.066845 0.067632 0.068443 0.069279 0.070144
13 0.074657 0.075662 0.067528 0.068392 0.069279 0.070193 0.071137
14 0.075466 0.076565 0.068238 0.069179 0.070144 0.071137 0.072162
1 0.076446 0.072627 0.076483 0.073208 0.070145 0.067263 0.064527
2 0.065511 0.062704 0.065094 0.062649 0.060358 0.058198 0.056149
3 0.085713 0.081361 0.088105 0.084453 0.081016 0.077760 0.074647
4 0.080765 0.076998 0.082612 0.079459 0.076483 0.073657 0.070949
5 0.075532 0.072349 0.076881 0.074213 0.071690 0.069286 0.066978
6 0.084250 0.080136 0.087850 0.084413 0.081166 0.078077 0.075114
7 0.080847 0.077151 0.084014 0.080946 0.078040 0.075268 0.072600
8 0.077525 0.074225 0.080285 0.077563 0.074977 0.072501 0.070112
9 0.074225 0.071304 0.076603 0.074208 0.071924 0.069731 0.067608
10 0.080285 0.076603 0.084360 0.081287 0.078374 0.075595 0.072921
11 0.077563 0.074208 0.081287 0.078509 0.075868 0.073341 0.070901
12 0.074977 0.071924 0.078374 0.075868 0.073479 0.071184 0.068960
13 0.072501 0.069731 0.075595 0.073341 0.071184 0.069105 0.067084
14 0.070112 0.067608 0.072921 0.070901 0.068960 0.067084 0.065252
</pre></div>
</div>
</div>
@@ -890,10 +900,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.947193 2.023730
1 2.023730 2.048423
[[3.94719285 2.02373037]
[2.02373037 2.04842273]]
0 3.923640 1.961854
1 1.961854 1.947452
[[3.92363958 1.96185372]
[1.96185372 1.94745179]]
</pre></div>
</div>
</div>
@@ -920,8 +930,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.94719285 2.02373037]
[2.02373037 2.04842273]]
[[3.92363958 1.96185372]
[1.96185372 1.94745179]]
</pre></div>
</div>
<img alt="_images/chapter8_65_1.png" src="_images/chapter8_65_1.png" />
@@ -981,16 +991,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.233163823635816
0.7624517604393659
5.132179379442221
0.7389119925478163
First eigenvector
[0.84401218 0.536324 ]
[0.85141702 0.52448933]
Second eigenvector
[-0.536324 0.84401218]
[-0.52448933 0.85141702]
</pre></div>
</div>
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Eigenvector of largest eigenvalue
[-0.84401218 -0.536324 ]
[0.85141702 0.52448933]
</pre></div>
</div>
</div>
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
+10
View File
@@ -126,6 +126,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -204,6 +209,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -126,6 +126,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -204,6 +209,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
+10
View File
@@ -127,6 +127,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -205,6 +210,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
+31 -17
View File
@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Linear Algebra, Handling of Arrays and more Python Features &#8212; Applied Data Analysis and Machine Learning</title>
<title>2. Linear Algebra, Handling of Arrays and more Python Features &#8212; Applied Data Analysis and Machine Learning</title>
<link rel="stylesheet" href="_static/css/index.f658d18f9b420779cfdf24aa0a7e2d77.css">
@@ -57,6 +57,8 @@
<script async="async" src="_static/sphinx-thebe.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="1. Linear Regression, basic Elements" href="chapter1.html" />
<link rel="prev" title="1. Elements of Probability Theory and Statistical Data Analysis" href="statistics.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -120,12 +122,17 @@
Review of Statistics with Resampling Techniques and Linear Algebra
</span>
</p>
<ul class="nav sidenav_l1">
<ul class="current nav sidenav_l1">
<li class="toctree-l1">
<a class="reference internal" href="statistics.html">
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -204,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -277,32 +289,32 @@
<ul class="nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#introduction">
Introduction
2.1. Introduction
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#important-matrix-and-vector-handling-packages">
Important Matrix and vector handling packages
2.2. Important Matrix and vector handling packages
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#basic-matrix-features">
Basic Matrix Features
2.3. Basic Matrix Features
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#numpy-and-arrays">
Numpy and arrays
2.4. Numpy and arrays
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#gaussian-elimination">
Gaussian Elimination
2.5. Gaussian Elimination
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#lu-decomposition-the-inverse-of-a-matrix">
LU Decomposition, the inverse of a matrix
2.5.1. LU Decomposition, the inverse of a matrix
</a>
</li>
</ul>
@@ -320,9 +332,9 @@
<div>
<div class="section" id="linear-algebra-handling-of-arrays-and-more-python-features">
<h1>Linear Algebra, Handling of Arrays and more Python Features<a class="headerlink" href="#linear-algebra-handling-of-arrays-and-more-python-features" title="Permalink to this headline"></a></h1>
<h1><span class="section-number">2. </span>Linear Algebra, Handling of Arrays and more Python Features<a class="headerlink" href="#linear-algebra-handling-of-arrays-and-more-python-features" title="Permalink to this headline"></a></h1>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">2.1. </span>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
<p>The aim of this set of lectures is to review some central linear algebra algorithms that we will need in our
data analysis part and in the construction of Machine Learning algorithms (ML).
This will allow us to introduce some central programming features of high-level languages like Python and
@@ -335,7 +347,7 @@ Rust, C++, Fortran etc. In order to avoid confusion however, in these lectures w
attention to Python, C++ and Fortran.</p>
</div>
<div class="section" id="important-matrix-and-vector-handling-packages">
<h2>Important Matrix and vector handling packages<a class="headerlink" href="#important-matrix-and-vector-handling-packages" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">2.2. </span>Important Matrix and vector handling packages<a class="headerlink" href="#important-matrix-and-vector-handling-packages" title="Permalink to this headline"></a></h2>
<p>There are several central software packages for linear algebra and eigenvalue problems. Several of the more
popular ones have been wrapped into ofter software packages like those from the widely used text <strong>Numerical Recipes</strong>. The original source codes in many of the available packages are often taken from the widely used
software package LAPACK, which follows two other popular packages
@@ -363,7 +375,7 @@ as well. Before we proceed we believe it may be convenient to repeat some bas
matrices and vectors.</p>
</div>
<div class="section" id="basic-matrix-features">
<h2>Basic Matrix Features<a class="headerlink" href="#basic-matrix-features" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">2.3. </span>Basic Matrix Features<a class="headerlink" href="#basic-matrix-features" title="Permalink to this headline"></a></h2>
<p>Matrix properties reminder</p>
<div class="math notranslate nohighlight">
\[\begin{split}
@@ -420,7 +432,7 @@ matrices and vectors.</p>
</ul>
</div>
<div class="section" id="numpy-and-arrays">
<h2>Numpy and arrays<a class="headerlink" href="#numpy-and-arrays" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">2.4. </span>Numpy and arrays<a class="headerlink" href="#numpy-and-arrays" title="Permalink to this headline"></a></h2>
<p><a class="reference external" href="http://www.numpy.org/">Numpy</a> provides an easy way to handle arrays in Python. The standard way to import this library is as</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
@@ -432,8 +444,8 @@ matrices and vectors.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[-0.23170141 0.15928244 -1.066565 0.31568163 0.12797488 -0.23528928
0.27537361 -0.76476686 -0.51566228 0.13825481]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[ 0.44960994 -0.31524949 -0.60668732 -1.03920139 -0.23088568 -0.05148059
-1.4727093 0.29019465 0.82846181 -0.09720925]
</pre></div>
</div>
</div>
@@ -683,7 +695,7 @@ covariance matrix through the <strong>np.linalg.eig()</strong> function.</p>
</div>
</div>
<div class="section" id="gaussian-elimination">
<h2>Gaussian Elimination<a class="headerlink" href="#gaussian-elimination" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">2.5. </span>Gaussian Elimination<a class="headerlink" href="#gaussian-elimination" title="Permalink to this headline"></a></h2>
<p>We start with the linear set of equations</p>
<div class="math notranslate nohighlight">
\[
@@ -1037,7 +1049,7 @@ needed to solve the set of <span class="math notranslate nohighlight">\(n\)</spa
<li><p>Thereafter you call the function <code class="docutils literal notranslate"><span class="pre">lubksb(double</span> <span class="pre">a,</span> <span class="pre">int</span> <span class="pre">n,</span> <span class="pre">int</span> <span class="pre">indx,</span> <span class="pre">double</span> <span class="pre">w)</span></code> which uses the LU decomposed matrix <span class="math notranslate nohighlight">\(\bf A\)</span> and the vector <span class="math notranslate nohighlight">\(\bf w\)</span> and returns <span class="math notranslate nohighlight">\(\bf x\)</span> in the same place as <span class="math notranslate nohighlight">\(\bf w\)</span>. Upon exit the original content in <span class="math notranslate nohighlight">\(\bf w\)</span> is destroyed. If you wish to keep this information, you should make a backup of it in your calling function.</p></li>
</ul>
<div class="section" id="lu-decomposition-the-inverse-of-a-matrix">
<h3>LU Decomposition, the inverse of a matrix<a class="headerlink" href="#lu-decomposition-the-inverse-of-a-matrix" title="Permalink to this headline"></a></h3>
<h3><span class="section-number">2.5.1. </span>LU Decomposition, the inverse of a matrix<a class="headerlink" href="#lu-decomposition-the-inverse-of-a-matrix" title="Permalink to this headline"></a></h3>
<p>If the inverse exists then</p>
<div class="math notranslate nohighlight">
\[
@@ -1119,6 +1131,8 @@ can be written as a vector with unknown entries</p>
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="statistics.html" title="previous page"><span class="section-number">1. </span>Elements of Probability Theory and Statistical Data Analysis</a>
<a class='right-next' id="next-link" href="chapter1.html" title="next page"><span class="section-number">1. </span>Linear Regression, basic Elements</a>
</div>
Binary file not shown.
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
+10
View File
@@ -131,6 +131,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -209,6 +214,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
File diff suppressed because one or more lines are too long
+43 -33
View File
@@ -57,7 +57,7 @@
<script async="async" src="_static/sphinx-thebe.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="1. Linear Regression, basic Elements" href="chapter1.html" />
<link rel="next" title="2. Linear Algebra, Handling of Arrays and more Python Features" href="linalg.html" />
<link rel="prev" title="Textbooks" href="textbooks.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -1200,27 +1210,27 @@ uncorrelated.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.6316131519476521
[[ 1.58583117 3.99570082 2.24918666 2.33134902 3.73092594 4.00094337
2.29968639 0.76636138 2.96927041 3.12145392]
[ 3.99570082 10.06767012 5.66710831 5.87412671 9.40053655 10.08087938
5.79434872 1.93094377 7.48144978 7.86489523]
[ 2.24918666 5.66710831 3.19002472 3.30655573 5.29157771 5.67454382
3.26164856 1.08693147 4.21132056 4.42716265]
[ 2.33134902 5.87412671 3.30655573 3.42734359 5.48487805 5.88183385
3.38079597 1.12663687 4.36515931 4.58888607]
[ 3.73092594 9.40053655 5.29157771 5.48487805 8.77761055 9.4128705
5.41038654 1.8029899 6.98569195 7.34372841]
[ 4.00094337 10.08087938 5.67454382 5.88183385 9.4128705 10.09410597
5.80195118 1.93347726 7.4912658 7.87521435]
[ 2.29968639 5.79434872 3.26164856 3.38079597 5.41038654 5.80195118
3.33488053 1.11133574 4.30587499 4.52656325]
[ 0.76636138 1.93094377 1.08693147 1.12663687 1.8029899 1.93347726
1.11133574 0.37034823 1.43491579 1.50845929]
[ 2.96927041 7.48144978 4.21132056 4.36515931 6.98569195 7.4912658
4.30587499 1.43491579 5.55958728 5.84453185]
[ 3.12145392 7.86489523 4.42716265 4.58888607 7.34372841 7.87521435
4.52656325 1.50845929 5.84453185 6.14408063]]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>4.752993882123058
[[ 4.70339379 7.80064137 18.20965525 1.99515112 14.01360746 10.49675434
5.81431951 6.88529462 8.48275939 8.04252289]
[ 7.80064137 12.93746782 30.20095624 3.30898476 23.24175499 17.40900715
9.64312649 11.41935301 14.06876966 13.33863154]
[18.20965525 30.20095624 70.50048516 7.72442532 54.25507027 40.63922482
22.51071426 26.65710056 32.84184377 31.13742451]
[ 1.99515112 3.30898476 7.72442532 0.84633101 5.9444873 4.45265953
2.46639907 2.92070022 3.59833509 3.41158944]
[14.01360746 23.24175499 54.25507027 5.9444873 41.75308359 31.27473511
17.32357417 20.51450938 25.27410326 23.96243304]
[10.49675434 17.40900715 40.63922482 4.45265953 31.27473511 23.42603161
12.97605223 15.36619075 18.93131756 17.94882393]
[ 5.81431951 9.64312649 22.51071426 2.46639907 17.32357417 12.97605223
7.18764212 8.51157793 10.48635849 9.94213961]
[ 6.88529462 11.41935301 26.65710056 2.92070022 20.51450938 15.36619075
8.51157793 10.07937759 12.41790507 11.77344318]
[ 8.48275939 14.06876966 32.84184377 3.59833509 25.27410326 18.93131756
10.48635849 12.41790507 15.29899688 14.50501268]
[ 8.04252289 13.33863154 31.13742451 3.41158944 23.96243304 17.94882393
9.94213961 11.77344318 14.50501268 13.75223451]]
</pre></div>
</div>
</div>
@@ -1528,15 +1538,15 @@ more practically oriented methods like the blocking technique.</p>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.061385629710443756
3.886244383872239
-0.4373494288983646
0.929966635783332 9.541535199360583 9.55018532654326
2.804295941652906 2.3112435515086704 6.263998234191122
[[0.92996664 2.80429594 2.31124355]
[2.80429594 9.5415352 6.26399823]
[2.31124355 6.26399823 9.55018533]]
[16.6429986 0.06118675 3.31750181]
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>-0.027477551848353866
3.7802249527556957
-0.4029931539585397
0.8404538734963756 8.457307018163291 11.102672153764402
2.530192962097468 2.272095736442208 6.697993128260892
[[ 0.84045387 2.53019296 2.27209574]
[ 2.53019296 8.45730702 6.69799313]
[ 2.27209574 6.69799313 11.10267215]]
[17.29496013 0.06631095 3.03916197]
</pre></div>
</div>
</div>
@@ -1943,7 +1953,7 @@ assumption for approximating <span class="math notranslate nohighlight">\(\sigma
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.05495434737667005 0.9160106163023461
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>0.07147629989718486 0.9457130616859395
</pre></div>
</div>
<img alt="_images/statistics_184_1.png" src="_images/statistics_184_1.png" />
@@ -2378,7 +2388,7 @@ the true <span class="math notranslate nohighlight">\(\angle\theta\rangle\)</spa
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="textbooks.html" title="previous page">Textbooks</a>
<a class='right-next' id="next-link" href="chapter1.html" title="next page"><span class="section-number">1. </span>Linear Regression, basic Elements</a>
<a class='right-next' id="next-link" href="linalg.html" title="next page"><span class="section-number">2. </span>Linear Algebra, Handling of Arrays and more Python Features</a>
</div>
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -128,6 +128,11 @@
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p class="caption collapsible-parent">
<span class="caption-text">
@@ -206,6 +211,11 @@
2. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
3. Solving Differential Equations with Deep Learning
</a>
</li>
</ul>
</nav> <!-- To handle the deprecated key -->
@@ -441,8 +441,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[ 1.3280646 -0.56501263 0.21077998 -0.55360402 0.06730225 1.01324127\n",
" -0.21780848 -0.34317041 0.45298301 0.08215028]\n"
"[ 1.59542395e+00 -1.76635856e-01 6.09517402e-01 7.37482326e-01\n",
" 1.23310910e+00 8.39779531e-04 -1.09487746e+00 8.32655571e-01\n",
" -8.22808167e-01 9.71128130e-01]\n"
]
}
],
@@ -2322,62 +2322,52 @@
"Learning rate = 0.1\n",
"Lambda = 1.0\n",
"Accuracy score on test set: 0.9055555555555556\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Learning rate = 0.1\n",
"Lambda = 10.0\n",
"Accuracy score on test set: 0.8666666666666667\n",
"\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Learning rate = 1.0\n",
"Lambda = 1e-05\n",
"Accuracy score on test set: 0.09166666666666666\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Learning rate = 1.0\n",
"Lambda = 0.0001\n",
"Accuracy score on test set: 0.11944444444444445\n",
"\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Learning rate = 1.0\n",
"Lambda = 0.001\n",
"Accuracy score on test set: 0.1361111111111111\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Learning rate = 1.0\n",
"Lambda = 0.01\n",
"Accuracy score on test set: 0.1527777777777778\n",
"\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Learning rate = 1.0\n",
"Lambda = 0.1\n",
"Accuracy score on test set: 0.16666666666666666\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Learning rate = 1.0\n",
"Lambda = 1.0\n",
"Accuracy score on test set: 0.1111111111111111\n",
"\n",
"Learning rate = 1.0\n",
"Lambda = 10.0\n",
"Accuracy score on test set: 0.05\n",
"\n"
]
},
@@ -2385,6 +2375,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Learning rate = 1.0\n",
"Lambda = 10.0\n",
"Accuracy score on test set: 0.05\n",
"\n",
"Learning rate = 10.0\n",
"Lambda = 1e-05\n",
"Accuracy score on test set: 0.08888888888888889\n",
@@ -2392,10 +2386,6 @@
"Learning rate = 10.0\n",
"Lambda = 0.0001\n",
"Accuracy score on test set: 0.08611111111111111\n",
"\n",
"Learning rate = 10.0\n",
"Lambda = 0.001\n",
"Accuracy score on test set: 0.08888888888888889\n",
"\n"
]
},
@@ -2403,6 +2393,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Learning rate = 10.0\n",
"Lambda = 0.001\n",
"Accuracy score on test set: 0.08888888888888889\n",
"\n",
"Learning rate = 10.0\n",
"Lambda = 0.01\n",
"Accuracy score on test set: 0.08888888888888889\n",
File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

@@ -1146,10 +1146,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.05952725829739267\n",
"4.386262724250306\n",
"[[ 1.1558068 3.35522344]\n",
" [ 3.35522344 10.90654923]]\n"
"0.062127739929490035\n",
"4.226441441217558\n",
"[[0.95977893 2.78652875]\n",
" [2.78652875 9.09409124]]\n"
]
}
],
@@ -1189,10 +1189,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"0.09168618934140788\n",
"1.945123703671126\n",
"[[1. 0.72291211]\n",
" [0.72291211 1. ]]\n"
"0.09053391104887817\n",
"1.9755272664385481\n",
"[[1. 0.64723729]\n",
" [0.64723729 1. ]]\n"
]
}
],
@@ -1246,30 +1246,30 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0.2701033 0.76102689]\n",
" [ 0.51167594 2.72484235]\n",
" [ 0.32455001 -1.43364263]\n",
" [-0.53774919 -1.34290169]\n",
" [-0.05260429 -0.42595379]\n",
" [ 0.07893835 0.61280302]\n",
" [-1.6055745 -4.25652444]\n",
" [ 0.85403864 3.64196375]\n",
" [ 0.57068381 2.34793363]\n",
" [-0.41406207 -2.62954709]]\n",
"[[ 0.52374318 0.7528421 ]\n",
" [-1.07892554 -3.5697027 ]\n",
" [ 0.65536057 2.84854 ]\n",
" [-0.9936011 -1.75368597]\n",
" [-0.22233456 -1.63866932]\n",
" [ 1.10799046 4.51410028]\n",
" [ 1.30401938 5.04686521]\n",
" [ 0.70055962 1.28566384]\n",
" [-1.69423925 -6.23684061]\n",
" [-0.30257276 -1.24911284]]\n",
" 0 1\n",
"0 0.270103 0.761027\n",
"1 0.511676 2.724842\n",
"2 0.324550 -1.433643\n",
"3 -0.537749 -1.342902\n",
"4 -0.052604 -0.425954\n",
"5 0.078938 0.612803\n",
"6 -1.605575 -4.256524\n",
"7 0.854039 3.641964\n",
"8 0.570684 2.347934\n",
"9 -0.414062 -2.629547\n",
"0 0.523743 0.752842\n",
"1 -1.078926 -3.569703\n",
"2 0.655361 2.848540\n",
"3 -0.993601 -1.753686\n",
"4 -0.222335 -1.638669\n",
"5 1.107990 4.514100\n",
"6 1.304019 5.046865\n",
"7 0.700560 1.285664\n",
"8 -1.694239 -6.236841\n",
"9 -0.302573 -1.249113\n",
" 0 1\n",
"0 1.000000 0.894794\n",
"1 0.894794 1.000000\n"
"0 1.000000 0.967871\n",
"1 0.967871 1.000000\n"
]
}
],
@@ -1310,37 +1310,37 @@
"text": [
" 0 1 2 3 4 5 6 7 \\\n",
"0 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"1 0.0 0.090640 0.079152 0.086791 0.086033 0.083807 0.076613 0.076853 \n",
"2 0.0 0.079152 0.070665 0.073700 0.073719 0.072669 0.064120 0.064658 \n",
"3 0.0 0.086791 0.073700 0.089130 0.086860 0.082986 0.082366 0.081697 \n",
"4 0.0 0.086033 0.073719 0.086860 0.085104 0.081822 0.079399 0.079040 \n",
"5 0.0 0.083807 0.072669 0.082986 0.081822 0.079272 0.074974 0.074942 \n",
"6 0.0 0.076613 0.064120 0.082366 0.079399 0.074974 0.078615 0.077369 \n",
"7 0.0 0.076853 0.064658 0.081697 0.079040 0.074942 0.077369 0.076344 \n",
"8 0.0 0.076988 0.065180 0.080804 0.078501 0.074783 0.075867 0.075083 \n",
"9 0.0 0.076812 0.065537 0.079464 0.077568 0.074305 0.073910 0.073388 \n",
"10 0.0 0.067721 0.056185 0.075172 0.071927 0.067396 0.073456 0.071888 \n",
"11 0.0 0.067838 0.056481 0.074711 0.071675 0.067356 0.072592 0.071185 \n",
"12 0.0 0.068022 0.056864 0.074259 0.071451 0.067365 0.071702 0.070467 \n",
"13 0.0 0.068244 0.057318 0.073774 0.071219 0.067394 0.070744 0.069695 \n",
"14 0.0 0.068449 0.057811 0.073183 0.070913 0.067391 0.069650 0.068802 \n",
"1 0.0 0.076075 0.081429 0.075275 0.076780 0.077999 0.067453 0.067971 \n",
"2 0.0 0.081429 0.088214 0.081300 0.083371 0.085063 0.072811 0.073594 \n",
"3 0.0 0.075275 0.081300 0.080335 0.082127 0.083567 0.075400 0.075990 \n",
"4 0.0 0.076780 0.083371 0.082127 0.084184 0.085857 0.076996 0.077729 \n",
"5 0.0 0.077999 0.085063 0.083567 0.085857 0.087738 0.078264 0.079128 \n",
"6 0.0 0.067453 0.072811 0.075400 0.076996 0.078264 0.072961 0.073444 \n",
"7 0.0 0.067971 0.073594 0.075990 0.077729 0.079128 0.073444 0.074016 \n",
"8 0.0 0.068431 0.074291 0.076495 0.078367 0.079889 0.073843 0.074498 \n",
"9 0.0 0.068860 0.074936 0.076947 0.078943 0.080582 0.074186 0.074922 \n",
"10 0.0 0.059693 0.064192 0.068842 0.070144 0.071159 0.068084 0.068427 \n",
"11 0.0 0.059875 0.064519 0.069009 0.070400 0.071499 0.068172 0.068575 \n",
"12 0.0 0.060056 0.064837 0.069164 0.070641 0.071822 0.068246 0.068709 \n",
"13 0.0 0.060243 0.065156 0.069319 0.070878 0.072139 0.068315 0.068837 \n",
"14 0.0 0.060442 0.065483 0.069478 0.071119 0.072459 0.068387 0.068966 \n",
"\n",
" 8 9 10 11 12 13 14 \n",
"0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 \n",
"1 0.076988 0.076812 0.067721 0.067838 0.068022 0.068244 0.068449 \n",
"2 0.065180 0.065537 0.056185 0.056481 0.056864 0.057318 0.057811 \n",
"3 0.080804 0.079464 0.075172 0.074711 0.074259 0.073774 0.073183 \n",
"4 0.078501 0.077568 0.071927 0.071675 0.071451 0.071219 0.070913 \n",
"5 0.074783 0.074305 0.067396 0.067356 0.067365 0.067394 0.067391 \n",
"6 0.075867 0.073910 0.073456 0.072592 0.071702 0.070744 0.069650 \n",
"7 0.075083 0.073388 0.071888 0.071185 0.070467 0.069695 0.068802 \n",
"8 0.074088 0.072685 0.070067 0.069534 0.069000 0.068429 0.067755 \n",
"9 0.072685 0.071614 0.067818 0.067465 0.067127 0.066772 0.066339 \n",
"10 0.070067 0.067818 0.069854 0.068745 0.067594 0.066361 0.064984 \n",
"11 0.069534 0.067465 0.068745 0.067758 0.066737 0.065641 0.064409 \n",
"12 0.069000 0.067127 0.067594 0.066737 0.065852 0.064903 0.063827 \n",
"13 0.068429 0.066772 0.066361 0.065641 0.064903 0.064110 0.063205 \n",
"14 0.067755 0.066339 0.064984 0.064409 0.063827 0.063205 0.062484 \n"
"1 0.068431 0.068860 0.059693 0.059875 0.060056 0.060243 0.060442 \n",
"2 0.074291 0.074936 0.064192 0.064519 0.064837 0.065156 0.065483 \n",
"3 0.076495 0.076947 0.068842 0.069009 0.069164 0.069319 0.069478 \n",
"4 0.078367 0.078943 0.070144 0.070400 0.070641 0.070878 0.071119 \n",
"5 0.079889 0.080582 0.071159 0.071499 0.071822 0.072139 0.072459 \n",
"6 0.073843 0.074186 0.068084 0.068172 0.068246 0.068315 0.068387 \n",
"7 0.074498 0.074922 0.068427 0.068575 0.068709 0.068837 0.068966 \n",
"8 0.075062 0.075564 0.068693 0.068901 0.069093 0.069278 0.069465 \n",
"9 0.075564 0.076143 0.068909 0.069174 0.069423 0.069665 0.069908 \n",
"10 0.068693 0.068909 0.064578 0.064582 0.064574 0.064559 0.064545 \n",
"11 0.068901 0.069174 0.064582 0.064632 0.064668 0.064698 0.064728 \n",
"12 0.069093 0.069423 0.064574 0.064668 0.064748 0.064822 0.064896 \n",
"13 0.069278 0.069665 0.064559 0.064698 0.064822 0.064940 0.065058 \n",
"14 0.069465 0.069908 0.064545 0.064728 0.064896 0.065058 0.065220 \n"
]
}
],
File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 31 KiB

@@ -159,8 +159,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[-0.23170141 0.15928244 -1.066565 0.31568163 0.12797488 -0.23528928\n",
" 0.27537361 -0.76476686 -0.51566228 0.13825481]\n"
"[ 0.44960994 -0.31524949 -0.60668732 -1.03920139 -0.23088568 -0.05148059\n",
" -1.4727093 0.29019465 0.82846181 -0.09720925]\n"
]
}
],
File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

+1 -2
View File
@@ -8,7 +8,7 @@
numbered: true
chapters:
- file: statistics.ipynb
- file: linearalgebra.ipynb
- file: linalg.ipynb
- part: From Regression to Support Vector Machines
numbered: true
chapters:
@@ -32,4 +32,3 @@
- file: chapter9.ipynb
- file: chapter10.ipynb
- file: chapter11.ipynb
- file: chapter12.ipynb
-732
View File
@@ -1,732 +0,0 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Convolutional Neural Networks (recognizing images)\n",
"\n",
"\n",
"Convolutional neural networks (CNNs) were developed during the last\n",
"decade of the previous century, with a focus on character recognition\n",
"tasks. Nowadays, CNNs are a central element in the spectacular success\n",
"of deep learning methods. The success in for example image\n",
"classifications have made them a central tool for most machine\n",
"learning practitioners.\n",
"\n",
"CNNs are very similar to ordinary Neural Networks.\n",
"They are made up of neurons that have learnable weights and\n",
"biases. Each neuron receives some inputs, performs a dot product and\n",
"optionally follows it with a non-linearity. The whole network still\n",
"expresses a single differentiable score function: from the raw image\n",
"pixels on one end to class scores at the other. And they still have a\n",
"loss function (for example Softmax) on the last (fully-connected) layer\n",
"and all the tips/tricks we developed for learning regular Neural\n",
"Networks still apply (back propagation, gradient descent etc etc).\n",
"\n",
"What is the difference? **CNN architectures make the explicit assumption that\n",
"the inputs are images, which allows us to encode certain properties\n",
"into the architecture. These then make the forward function more\n",
"efficient to implement and vastly reduce the amount of parameters in\n",
"the network.**\n",
"\n",
"Here we provide only a superficial overview, for the more interested, we recommend highly the course\n",
"[IN5400 Machine Learning for Image Analysis](https://www.uio.no/studier/emner/matnat/ifi/IN5400/index-eng.html)\n",
"and the slides of [CS231](http://cs231n.github.io/convolutional-networks/).\n",
"\n",
"Another good read is the article here <https://arxiv.org/pdf/1603.07285.pdf>. \n",
"\n",
"\n",
"As an example, consider\n",
"an image of size $32\\times 32\\times 3$ (32 wide, 32 high, 3 color channels), so a\n",
"single fully-connected neuron in a first hidden layer of a regular\n",
"Neural Network would have $32\\times 32\\times 3 = 3072$ weights. This amount still\n",
"seems manageable, but clearly this fully-connected structure does not\n",
"scale to larger images. For example, an image of more respectable\n",
"size, say $200\\times 200\\times 3$, would lead to neurons that have \n",
"$200\\times 200\\times 3 = 120,000$ weights. \n",
"\n",
"We could have\n",
"several such neurons, and the parameters would add up quickly! Clearly,\n",
"this full connectivity is wasteful and the huge number of parameters\n",
"would quickly lead to possible overfitting.\n",
"\n",
"<!-- FIGURE: [figslides/nn.jpeg, width=500 frac=0.6] A regular 3-layer Neural Network. -->\n",
"\n",
"\n",
"\n",
"Convolutional Neural Networks take advantage of the fact that the\n",
"input consists of images and they constrain the architecture in a more\n",
"sensible way. \n",
"\n",
"In particular, unlike a regular Neural Network, the\n",
"layers of a CNN have neurons arranged in 3 dimensions: width,\n",
"height, depth. (Note that the word depth here refers to the third\n",
"dimension of an activation volume, not to the depth of a full Neural\n",
"Network, which can refer to the total number of layers in a network.)\n",
"\n",
"To understand it better, the above example of an image \n",
"with an input volume of\n",
"activations has dimensions $32\\times 32\\times 3$ (width, height,\n",
"depth respectively). \n",
"\n",
"The neurons in a layer will\n",
"only be connected to a small region of the layer before it, instead of\n",
"all of the neurons in a fully-connected manner. Moreover, the final\n",
"output layer could for this specific image have dimensions $1\\times 1 \\times 10$, \n",
"because by the\n",
"end of the CNN architecture we will reduce the full image into a\n",
"single vector of class scores, arranged along the depth\n",
"dimension. \n",
"\n",
"<!-- FIGURE: [figslides/cnn.jpeg, width=500 frac=0.6] A CNN arranges its neurons in three dimensions (width, heigh#t, depth), as visualized in one of the layers. Every layer of a CNN transforms the 3D input volume to a 3D out#put volume of neuron activations. In this example, the red input layer holds the image, so its width and heigh#t would be the dimensions of the image, and the depth would be 3 (Red, Green, Blue channels). -->\n",
"\n",
"\n",
"\n",
"\n",
"A simple CNN is a sequence of layers, and every layer of a CNN\n",
"transforms one volume of activations to another through a\n",
"differentiable function. We use three main types of layers to build\n",
"CNN architectures: Convolutional Layer, Pooling Layer, and\n",
"Fully-Connected Layer (exactly as seen in regular Neural Networks). We\n",
"will stack these layers to form a full CNN architecture.\n",
"\n",
"A simple CNN for image classification could have the architecture:\n",
"\n",
"* **INPUT** ($32\\times 32 \\times 3$) will hold the raw pixel values of the image, in this case an image of width 32, height 32, and with three color channels R,G,B.\n",
"\n",
"* **CONV** (convolutional )layer will compute the output of neurons that are connected to local regions in the input, each computing a dot product between their weights and a small region they are connected to in the input volume. This may result in volume such as $[32\\times 32\\times 12]$ if we decided to use 12 filters.\n",
"\n",
"* **RELU** layer will apply an elementwise activation function, such as the $max(0,x)$ thresholding at zero. This leaves the size of the volume unchanged ($[32\\times 32\\times 12]$).\n",
"\n",
"* **POOL** (pooling) layer will perform a downsampling operation along the spatial dimensions (width, height), resulting in volume such as $[16\\times 16\\times 12]$.\n",
"\n",
"* **FC** (i.e. fully-connected) layer will compute the class scores, resulting in volume of size $[1\\times 1\\times 10]$, where each of the 10 numbers correspond to a class score, such as among the 10 categories of the MNIST images we considered above . As with ordinary Neural Networks and as the name implies, each neuron in this layer will be connected to all the numbers in the previous volume.\n",
"\n",
"CNNs transform the original image layer by layer from the original\n",
"pixel values to the final class scores. \n",
"\n",
"Observe that some layers contain\n",
"parameters and other dont. In particular, the CNN layers perform\n",
"transformations that are a function of not only the activations in the\n",
"input volume, but also of the parameters (the weights and biases of\n",
"the neurons). On the other hand, the RELU/POOL layers will implement a\n",
"fixed function. The parameters in the CONV/FC layers will be trained\n",
"with gradient descent so that the class scores that the CNN computes\n",
"are consistent with the labels in the training set for each image.\n",
"\n",
"\n",
"\n",
"### CNNs in brief\n",
"\n",
"In summary:\n",
"\n",
"* A CNN architecture is in the simplest case a list of Layers that transform the image volume into an output volume (e.g. holding the class scores)\n",
"\n",
"* There are a few distinct types of Layers (e.g. CONV/FC/RELU/POOL are by far the most popular)\n",
"\n",
"* Each Layer accepts an input 3D volume and transforms it to an output 3D volume through a differentiable function\n",
"\n",
"* Each Layer may or may not have parameters (e.g. CONV/FC do, RELU/POOL dont)\n",
"\n",
"* Each Layer may or may not have additional hyperparameters (e.g. CONV/FC/POOL do, RELU doesnt)\n",
"\n",
"For more material on convolutional networks, we strongly recommend\n",
"the course\n",
"[IN5400 Machine Learning for Image Analysis](https://www.uio.no/studier/emner/matnat/ifi/IN5400/index-eng.html)\n",
"and the slides of [CS231](http://cs231n.github.io/convolutional-networks/) which is taught at Stanford University (consistently ranked as one of the top computer science programs in the world). [Michael Nielsen's book is a must read, in particular chapter 6 which deals with CNNs](http://neuralnetworksanddeeplearning.com/chap6.html).\n",
"\n",
"\n",
"\n",
"\n",
"## CNNs in more detail, building convolutional neural networks in Tensorflow and Keras\n",
"\n",
"\n",
"As discussed above, CNNs are neural networks built from the assumption that the inputs\n",
"to the network are 2D images. This is important because the number of features or pixels in images\n",
"grows very fast with the image size, and an enormous number of weights and biases are needed in order to build an accurate network. \n",
"\n",
"As before, we still have our input, a hidden layer and an output. What's novel about convolutional networks\n",
"are the **convolutional** and **pooling** layers stacked in pairs between the input and the hidden layer.\n",
"In addition, the data is no longer represented as a 2D feature matrix, instead each input is a number of 2D\n",
"matrices, typically 1 for each color dimension (Red, Green, Blue). \n",
"\n",
"\n",
"\n",
"It means that to represent the entire\n",
"dataset of images, we require a 4D matrix or **tensor**. This tensor has the dimensions:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"(n_{inputs},\\, n_{pixels, width},\\, n_{pixels, height},\\, depth) .\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The MNIST dataset consists of grayscale images with a pixel size of\n",
"$28\\times 28$, meaning we require $28 \\times 28 = 724$ weights to each\n",
"neuron in the first hidden layer.\n",
"\n",
"If we were to analyze images of size $128\\times 128$ we would require\n",
"$128 \\times 128 = 16384$ weights to each neuron. Even worse if we were\n",
"dealing with color images, as most images are, we have an image matrix\n",
"of size $128\\times 128$ for each color dimension (Red, Green, Blue),\n",
"meaning 3 times the number of weights $= 49152$ are required for every\n",
"single neuron in the first hidden layer.\n",
"\n",
"\n",
"\n",
"Images typically have strong local correlations, meaning that a small\n",
"part of the image varies little from its neighboring regions. If for\n",
"example we have an image of a blue car, we can roughly assume that a\n",
"small blue part of the image is surrounded by other blue regions.\n",
"\n",
"Therefore, instead of connecting every single pixel to a neuron in the\n",
"first hidden layer, as we have previously done with deep neural\n",
"networks, we can instead connect each neuron to a small part of the\n",
"image (in all 3 RGB depth dimensions). The size of each small area is\n",
"fixed, and known as a [receptive](https://en.wikipedia.org/wiki/Receptive_field).\n",
"\n",
"\n",
"\n",
"The layers of a convolutional neural network arrange neurons in 3D: width, height and depth. \n",
"The input image is typically a square matrix of depth 3. \n",
"\n",
"A **convolution** is performed on the image which outputs\n",
"a 3D volume of neurons. The weights to the input are arranged in a number of 2D matrices, known as **filters**.\n",
"\n",
"\n",
"Each filter slides along the input image, taking the dot product\n",
"between each small part of the image and the filter, in all depth\n",
"dimensions. This is then passed through a non-linear function,\n",
"typically the **Rectified Linear (ReLu)** function, which serves as the\n",
"activation of the neurons in the first convolutional layer. This is\n",
"further passed through a **pooling layer**, which reduces the size of the\n",
"convolutional layer, e.g. by taking the maximum or average across some\n",
"small regions, and this serves as input to the next convolutional\n",
"layer.\n",
"\n",
"\n",
"\n",
"By systematically reducing the size of the input volume, through\n",
"convolution and pooling, the network should create representations of\n",
"small parts of the input, and then from them assemble representations\n",
"of larger areas. The final pooling layer is flattened to serve as\n",
"input to a hidden layer, such that each neuron in the final pooling\n",
"layer is connected to every single neuron in the hidden layer. This\n",
"then serves as input to the output layer, e.g. a softmax output for\n",
"classification.\n",
"\n",
"\n",
"\n",
"### Prerequisites: Collect and pre-process data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"# import necessary packages\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from sklearn import datasets\n",
"\n",
"\n",
"# ensure the same random numbers appear every time\n",
"np.random.seed(0)\n",
"\n",
"# display images in notebook\n",
"%matplotlib inline\n",
"plt.rcParams['figure.figsize'] = (12,12)\n",
"\n",
"\n",
"# download MNIST dataset\n",
"digits = datasets.load_digits()\n",
"\n",
"# define inputs and labels\n",
"inputs = digits.images\n",
"labels = digits.target\n",
"\n",
"# RGB images have a depth of 3\n",
"# our images are grayscale so they should have a depth of 1\n",
"inputs = inputs[:,:,:,np.newaxis]\n",
"\n",
"print(\"inputs = (n_inputs, pixel_width, pixel_height, depth) = \" + str(inputs.shape))\n",
"print(\"labels = (n_inputs) = \" + str(labels.shape))\n",
"\n",
"\n",
"# choose some random images to display\n",
"n_inputs = len(inputs)\n",
"indices = np.arange(n_inputs)\n",
"random_indices = np.random.choice(indices, size=5)\n",
"\n",
"for i, image in enumerate(digits.images[random_indices]):\n",
" plt.subplot(1, 5, i+1)\n",
" plt.axis('off')\n",
" plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')\n",
" plt.title(\"Label: %d\" % digits.target[random_indices[i]])\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Importing Keras and Tensorflow"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"from tensorflow.keras import datasets, layers, models\n",
"from tensorflow.keras.layers import Input\n",
"from tensorflow.keras.models import Sequential #This allows appending layers to existing models\n",
"from tensorflow.keras.layers import Dense #This allows defining the characteristics of a particular layer\n",
"from tensorflow.keras import optimizers #This allows using whichever optimiser we want (sgd,adam,RMSprop)\n",
"from tensorflow.keras import regularizers #This allows using whichever regularizer we want (l1,l2,l1_l2)\n",
"from tensorflow.keras.utils import to_categorical #This allows using categorical cross entropy as the cost function\n",
"#from tensorflow.keras import Conv2D\n",
"#from tensorflow.keras import MaxPooling2D\n",
"#from tensorflow.keras import Flatten\n",
"\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"# representation of labels\n",
"labels = to_categorical(labels)\n",
"\n",
"# split into train and test data\n",
"# one-liner from scikit-learn library\n",
"train_size = 0.8\n",
"test_size = 1 - train_size\n",
"X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,\n",
" test_size=test_size)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"def create_convolutional_neural_network_keras(input_shape, receptive_field,\n",
" n_filters, n_neurons_connected, n_categories,\n",
" eta, lmbd):\n",
" model = Sequential()\n",
" model.add(layers.Conv2D(n_filters, (receptive_field, receptive_field), input_shape=input_shape, padding='same',\n",
" activation='relu', kernel_regularizer=regularizers.l2(lmbd)))\n",
" model.add(layers.MaxPooling2D(pool_size=(2, 2)))\n",
" model.add(layers.Flatten())\n",
" model.add(layers.Dense(n_neurons_connected, activation='relu', kernel_regularizer=regularizers.l2(lmbd)))\n",
" model.add(layers.Dense(n_categories, activation='softmax', kernel_regularizer=regularizers.l2(lmbd)))\n",
" \n",
" sgd = optimizers.SGD(lr=eta)\n",
" model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])\n",
" \n",
" return model\n",
"\n",
"epochs = 100\n",
"batch_size = 100\n",
"input_shape = X_train.shape[1:4]\n",
"receptive_field = 3\n",
"n_filters = 10\n",
"n_neurons_connected = 50\n",
"n_categories = 10\n",
"\n",
"eta_vals = np.logspace(-5, 1, 7)\n",
"lmbd_vals = np.logspace(-5, 1, 7)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"CNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)\n",
" \n",
"for i, eta in enumerate(eta_vals):\n",
" for j, lmbd in enumerate(lmbd_vals):\n",
" CNN = create_convolutional_neural_network_keras(input_shape, receptive_field,\n",
" n_filters, n_neurons_connected, n_categories,\n",
" eta, lmbd)\n",
" CNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)\n",
" scores = CNN.evaluate(X_test, Y_test)\n",
" \n",
" CNN_keras[i][j] = CNN\n",
" \n",
" print(\"Learning rate = \", eta)\n",
" print(\"Lambda = \", lmbd)\n",
" print(\"Test accuracy: %.3f\" % scores[1])\n",
" print()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Final visualization"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# visual representation of grid search\n",
"# uses seaborn heatmap, could probably do this in matplotlib\n",
"import seaborn as sns\n",
"\n",
"sns.set()\n",
"\n",
"train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n",
"test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))\n",
"\n",
"for i in range(len(eta_vals)):\n",
" for j in range(len(lmbd_vals)):\n",
" CNN = CNN_keras[i][j]\n",
"\n",
" train_accuracy[i][j] = CNN.evaluate(X_train, Y_train)[1]\n",
" test_accuracy[i][j] = CNN.evaluate(X_test, Y_test)[1]\n",
"\n",
" \n",
"fig, ax = plt.subplots(figsize = (10, 10))\n",
"sns.heatmap(train_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n",
"ax.set_title(\"Training Accuracy\")\n",
"ax.set_ylabel(\"$\\eta$\")\n",
"ax.set_xlabel(\"$\\lambda$\")\n",
"plt.show()\n",
"\n",
"fig, ax = plt.subplots(figsize = (10, 10))\n",
"sns.heatmap(test_accuracy, annot=True, ax=ax, cmap=\"viridis\")\n",
"ax.set_title(\"Test Accuracy\")\n",
"ax.set_ylabel(\"$\\eta$\")\n",
"ax.set_xlabel(\"$\\lambda$\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The CIFAR01 data set\n",
"\n",
"The CIFAR10 dataset contains 60,000 color images in 10 classes, with\n",
"6,000 images in each class. The dataset is divided into 50,000\n",
"training images and 10,000 testing images. The classes are mutually\n",
"exclusive and there is no overlap between them."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"\n",
"from tensorflow.keras import datasets, layers, models\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# We import the data set\n",
"(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()\n",
"\n",
"# Normalize pixel values to be between 0 and 1 by dividing by 255. \n",
"train_images, test_images = train_images / 255.0, test_images / 255.0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To verify that the dataset looks correct, let's plot the first 25 images from the training set and display the class name below each image."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',\n",
" 'dog', 'frog', 'horse', 'ship', 'truck']\n",
"\n",
"plt.figure(figsize=(10,10))\n",
"for i in range(25):\n",
" plt.subplot(5,5,i+1)\n",
" plt.xticks([])\n",
" plt.yticks([])\n",
" plt.grid(False)\n",
" plt.imshow(train_images[i], cmap=plt.cm.binary)\n",
" # The CIFAR labels happen to be arrays, \n",
" # which is why you need the extra index\n",
" plt.xlabel(class_names[train_labels[i][0]])\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The 6 lines of code below define the convolutional base using a common pattern: a stack of Conv2D and MaxPooling2D layers.\n",
"\n",
"As input, a CNN takes tensors of shape (image_height, image_width, color_channels), ignoring the batch size. If you are new to these dimensions, color_channels refers to (R,G,B). In this example, you will configure our CNN to process inputs of shape (32, 32, 3), which is the format of CIFAR images. You can do this by passing the argument input_shape to our first layer."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"model = models.Sequential()\n",
"model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))\n",
"model.add(layers.MaxPooling2D((2, 2)))\n",
"model.add(layers.Conv2D(64, (3, 3), activation='relu'))\n",
"model.add(layers.MaxPooling2D((2, 2)))\n",
"model.add(layers.Conv2D(64, (3, 3), activation='relu'))\n",
"\n",
"# Let's display the architecture of our model so far.\n",
"\n",
"model.summary()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can see that the output of every Conv2D and MaxPooling2D layer is a 3D tensor of shape (height, width, channels). The width and height dimensions tend to shrink as you go deeper in the network. The number of output channels for each Conv2D layer is controlled by the first argument (e.g., 32 or 64). Typically, as the width and height shrink, you can afford (computationally) to add more output channels in each Conv2D layer.\n",
"\n",
"\n",
"\n",
"To complete our model, you will feed the last output tensor from the\n",
"convolutional base (of shape (4, 4, 64)) into one or more Dense layers\n",
"to perform classification. Dense layers take vectors as input (which\n",
"are 1D), while the current output is a 3D tensor. First, you will\n",
"flatten (or unroll) the 3D output to 1D, then add one or more Dense\n",
"layers on top. CIFAR has 10 output classes, so you use a final Dense\n",
"layer with 10 outputs and a softmax activation."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"model.add(layers.Flatten())\n",
"model.add(layers.Dense(64, activation='relu'))\n",
"model.add(layers.Dense(10))\n",
"Here's the complete architecture of our model.\n",
"\n",
"model.summary()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, our (4, 4, 64) outputs were flattened into vectors of shape (1024) before going through two Dense layers.\n",
"\n",
"Compile and train the model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"model.compile(optimizer='adam',\n",
" loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n",
" metrics=['accuracy'])\n",
"\n",
"history = model.fit(train_images, train_labels, epochs=10, \n",
" validation_data=(test_images, test_labels))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, we evaluate the model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"plt.plot(history.history['accuracy'], label='accuracy')\n",
"plt.plot(history.history['val_accuracy'], label = 'val_accuracy')\n",
"plt.xlabel('Epoch')\n",
"plt.ylabel('Accuracy')\n",
"plt.ylim([0.5, 1])\n",
"plt.legend(loc='lower right')\n",
"\n",
"test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)\n",
"\n",
"print(test_acc)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Recurrent neural networks: Overarching view\n",
"\n",
"Till now our focus has been, including convolutional neural networks\n",
"as well, on feedforward neural networks. The output or the activations\n",
"flow only in one direction, from the input layer to the output layer.\n",
"\n",
"A recurrent neural network (RNN) looks very much like a feedforward\n",
"neural network, except that it also has connections pointing\n",
"backward. \n",
"\n",
"RNNs are used to analyze time series data such as stock prices, and\n",
"tell you when to buy or sell. In autonomous driving systems, they can\n",
"anticipate car trajectories and help avoid accidents. More generally,\n",
"they can work on sequences of arbitrary lengths, rather than on\n",
"fixed-sized inputs like all the nets we have discussed so far. For\n",
"example, they can take sentences, documents, or audio samples as\n",
"input, making them extremely useful for natural language processing\n",
"systems such as automatic translation and speech-to-text.\n",
"\n",
"\n",
"\n",
"\n",
"### A simple example"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"editable": true
},
"outputs": [],
"source": [
"# Start importing packages\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import tensorflow as tf\n",
"from tensorflow.keras import datasets, layers, models\n",
"from tensorflow.keras.layers import Input\n",
"from tensorflow.keras.models import Model, Sequential \n",
"from tensorflow.keras.layers import Dense, SimpleRNN, LSTM, GRU\n",
"from tensorflow.keras import optimizers \n",
"from tensorflow.keras import regularizers \n",
"from tensorflow.keras.utils import to_categorical \n",
"\n",
"\n",
"\n",
"# convert into dataset matrix\n",
"def convertToMatrix(data, step):\n",
" X, Y =[], []\n",
" for i in range(len(data)-step):\n",
" d=i+step \n",
" X.append(data[i:d,])\n",
" Y.append(data[d,])\n",
" return np.array(X), np.array(Y)\n",
"\n",
"step = 4\n",
"N = 1000 \n",
"Tp = 800 \n",
"\n",
"t=np.arange(0,N)\n",
"x=np.sin(0.02*t)+2*np.random.rand(N)\n",
"df = pd.DataFrame(x)\n",
"df.head()\n",
"\n",
"plt.plot(df)\n",
"plt.show()\n",
"\n",
"values=df.values\n",
"train,test = values[0:Tp,:], values[Tp:N,:]\n",
"\n",
"# add step elements into train and test\n",
"test = np.append(test,np.repeat(test[-1,],step))\n",
"train = np.append(train,np.repeat(train[-1,],step))\n",
" \n",
"trainX,trainY =convertToMatrix(train,step)\n",
"testX,testY =convertToMatrix(test,step)\n",
"trainX = np.reshape(trainX, (trainX.shape[0], 1, trainX.shape[1]))\n",
"testX = np.reshape(testX, (testX.shape[0], 1, testX.shape[1]))\n",
"\n",
"model = Sequential()\n",
"model.add(SimpleRNN(units=32, input_shape=(1,step), activation=\"relu\"))\n",
"model.add(Dense(8, activation=\"relu\")) \n",
"model.add(Dense(1))\n",
"model.compile(loss='mean_squared_error', optimizer='rmsprop')\n",
"model.summary()\n",
"\n",
"model.fit(trainX,trainY, epochs=100, batch_size=16, verbose=2)\n",
"trainPredict = model.predict(trainX)\n",
"testPredict= model.predict(testX)\n",
"predicted=np.concatenate((trainPredict,testPredict),axis=0)\n",
"\n",
"trainScore = model.evaluate(trainX, trainY, verbose=0)\n",
"print(trainScore)\n",
"\n",
"index = df.index.values\n",
"plt.plot(index,df)\n",
"plt.plot(index,predicted)\n",
"plt.axvline(df.index[Tp], c=\"r\")\n",
"plt.show()"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}
Binary file not shown.