-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathislr_ch10.html
executable file
·1058 lines (745 loc) · 55.2 KB
/
islr_ch10.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<!-- Document Settings -->
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!-- On Post front-matter YAML, set "use_math: true" to use LaTex -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
equationNumbers: {
autoNumber: "AMS"
}
},
tex2jax: {
inlineMath: [ ['$', '$'], ["\\(","\\)"] ],
displayMath: [ ['$$', '$$'], ["\\[","\\]"] ],
processEscapes: true,
}
});
MathJax.Hub.Register.MessageHook("Math Processing Error",function (message) {
alert("Math Processing Error: "+message[1]);
});
MathJax.Hub.Register.MessageHook("TeX Jax - parse error",function (message) {
alert("Math Processing Error: "+message[1]);
});
</script>
<script type="text/javascript" async
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<!-- Base Meta -->
<!-- dynamically fixing the title for tag/author pages -->
<title>ISLR - Chapter 10. Deep Learning</title>
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Styles'n'Scripts -->
<link rel="stylesheet" type="text/css" href="/assets/built/screen.css" />
<link rel="stylesheet" type="text/css" href="/assets/built/screen.edited.css" />
<link rel="stylesheet" type="text/css" href="/assets/built/syntax.css" />
<!-- syntax.css -->
<link rel="stylesheet" type="text/css" href="/assets/built/syntax.css" />
<!-- highlight.js -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">
<style>.hljs { background: none; }</style>
<!--[if IE]>
<style>
p, ol, ul{
width: 100%;
}
blockquote{
width: 100%;
}
</style>
<![endif]-->
<!-- This tag outputs SEO meta+structured data and other important settings -->
<meta name="description" content="" />
<link rel="shortcut icon" href="http://0.0.0.0:4000/assets/built/images/favicon.jpg" type="image/png" />
<link rel="canonical" href="http://0.0.0.0:4000/islr_ch10" />
<meta name="referrer" content="no-referrer-when-downgrade" />
<!--title below is coming from _includes/dynamic_title-->
<meta property="og:site_name" content="Darron's Devlog" />
<meta property="og:type" content="website" />
<meta property="og:title" content="ISLR - Chapter 10. Deep Learning" />
<meta property="og:description" content="Chapter 10. Deep Learning 10.1. Single Layer Neural Networks 10.2. Multilayer Neural Networks 10.3. Convolutional Neural Networks 10.3.1. Convolution Layers 10.3.2. Pooling Layers 10.3.3. Architecture of a Convolutional Neural Network 10.3.4. Data Augmentation 10.4. Document Classification 10.5. Recurrent Neural Networks 10.5.1. Sequential Models for Document Classification 10.5.2. Time Series Forecasting" />
<meta property="og:url" content="http://0.0.0.0:4000/islr_ch10" />
<meta property="og:image" content="http://0.0.0.0:4000/assets/built/images/blog-cover1.png" />
<meta property="article:publisher" content="https://www.facebook.com/" />
<meta property="article:author" content="https://www.facebook.com/" />
<meta property="article:published_time" content="2020-05-27T15:00:00+00:00" />
<meta property="article:modified_time" content="2020-05-27T15:00:00+00:00" />
<meta property="article:tag" content="ISLR" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="ISLR - Chapter 10. Deep Learning" />
<meta name="twitter:description" content="Chapter 10. Deep Learning 10.1. Single Layer Neural Networks 10.2. Multilayer Neural Networks 10.3. Convolutional Neural Networks 10.3.1. Convolution Layers 10.3.2. Pooling Layers 10.3.3. Architecture of a Convolutional Neural Network 10.3.4. Data Augmentation 10.4. Document Classification 10.5. Recurrent Neural Networks 10.5.1. Sequential Models for Document Classification 10.5.2. Time Series Forecasting" />
<meta name="twitter:url" content="http://0.0.0.0:4000/" />
<meta name="twitter:image" content="http://0.0.0.0:4000/assets/built/images/blog-cover1.png" />
<meta name="twitter:label1" content="Written by" />
<meta name="twitter:data1" content="Darron's Devlog" />
<meta name="twitter:label2" content="Filed under" />
<meta name="twitter:data2" content="ISLR" />
<meta name="twitter:site" content="@" />
<meta name="twitter:creator" content="@" />
<meta property="og:image:width" content="1400" />
<meta property="og:image:height" content="933" />
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Website",
"publisher": {
"@type": "Organization",
"name": "Darron's Devlog",
"logo": "http://0.0.0.0:4000/"
},
"url": "http://0.0.0.0:4000/islr_ch10",
"image": {
"@type": "ImageObject",
"url": "http://0.0.0.0:4000/assets/built/images/blog-cover1.png",
"width": 2000,
"height": 666
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "http://0.0.0.0:4000/islr_ch10"
},
"description": "Chapter 10. Deep Learning 10.1. Single Layer Neural Networks 10.2. Multilayer Neural Networks 10.3. Convolutional Neural Networks 10.3.1. Convolution Layers 10.3.2. Pooling Layers 10.3.3. Architecture of a Convolutional Neural Network 10.3.4. Data Augmentation 10.4. Document Classification 10.5. Recurrent Neural Networks 10.5.1. Sequential Models for Document Classification 10.5.2. Time Series Forecasting"
}
</script>
<!-- <script type="text/javascript" src="https://demo.ghost.io/public/ghost-sdk.min.js?v=724281a32e"></script>
<script type="text/javascript">
ghost.init({
clientId: "ghost-frontend",
clientSecret: "f84a07a72b17"
});
</script> -->
<meta name="generator" content="Jekyll 3.6.2" />
<link rel="alternate" type="application/rss+xml" title="ISLR - Chapter 10. Deep Learning" href="/feed.xml" />
</head>
<body class="post-template">
<div class="site-wrapper">
<!-- All the main content gets inserted here, index.hbs, post.hbs, etc -->
<!-- default -->
<!-- The tag above means: insert everything in this file
into the {body} of the default.hbs template -->
<header class="site-header outer">
<div class="inner">
<nav class="site-nav">
<div class="site-nav-left">
<a class="site-nav-logo" href="/">Darron's Devlog</a>
<ul class="nav" role="menu">
<li class="nav-home" role="menuitem"><a href="/">Home</a></li>
<li class="nav-about" role="menuitem"><a href="/about/">About</a></li>
<li class="nav-projects" role="menuitem"><a href="/tag/projects/">Projects</a></li>
<li class="nav-studies" role="menuitem"><a href="/tag/studies/">Studies</a></li>
<li class="nav-blog" role="menuitem"><a href="/tag/blog/">Blog</a></li>
<li class="nav-archive" role="menuitem">
<a href="/archive.html">All Posts</a>
</li>
</ul>
</div>
<div class="site-nav-right">
<div class="social-links">
</div>
<a class="subscribe-button" href="#subscribe">Search</a>
</div>
</nav>
</div>
</header>
<!-- Everything inside the #post tags pulls data from the post -->
<!-- #post -->
<main id="site-main" class="site-main outer" role="main">
<div class="inner">
<article class="post-full tag-islr no-image">
<header class="post-full-header">
<section class="post-full-meta">
<time class="post-full-meta-date" datetime="27 May 2020">27 May 2020</time>
<span class="date-divider">/</span>
<a href='/tag/islr/'>ISLR</a>
</section>
<h1 class="post-full-title">ISLR - Chapter 10. Deep Learning</h1>
</header>
<!--
-->
<section class="post-full-content">
<div class="kg-card-markdown">
<ul id="markdown-toc">
<li><a href="#chapter-10-deep-learning" id="markdown-toc-chapter-10-deep-learning">Chapter 10. Deep Learning</a></li>
<li><a href="#101-single-layer-neural-networks" id="markdown-toc-101-single-layer-neural-networks">10.1. Single Layer Neural Networks</a></li>
<li><a href="#102-multilayer-neural-networks" id="markdown-toc-102-multilayer-neural-networks">10.2. Multilayer Neural Networks</a></li>
<li><a href="#103-convolutional-neural-networks" id="markdown-toc-103-convolutional-neural-networks">10.3. Convolutional Neural Networks</a> <ul>
<li><a href="#1031-convolution-layers" id="markdown-toc-1031-convolution-layers">10.3.1. Convolution Layers</a></li>
<li><a href="#1032-pooling-layers" id="markdown-toc-1032-pooling-layers">10.3.2. Pooling Layers</a></li>
<li><a href="#1033-architecture-of-a-convolutional-neural-network" id="markdown-toc-1033-architecture-of-a-convolutional-neural-network">10.3.3. Architecture of a Convolutional Neural Network</a></li>
<li><a href="#1034-data-augmentation" id="markdown-toc-1034-data-augmentation">10.3.4. Data Augmentation</a></li>
</ul>
</li>
<li><a href="#104-document-classification" id="markdown-toc-104-document-classification">10.4. Document Classification</a></li>
<li><a href="#105-recurrent-neural-networks" id="markdown-toc-105-recurrent-neural-networks">10.5. Recurrent Neural Networks</a> <ul>
<li><a href="#1051-sequential-models-for-document-classification" id="markdown-toc-1051-sequential-models-for-document-classification">10.5.1. Sequential Models for Document Classification</a></li>
<li><a href="#1052-time-series-forecasting" id="markdown-toc-1052-time-series-forecasting">10.5.2. Time Series Forecasting</a> <ul>
<li><a href="#rnn-forecaster" id="markdown-toc-rnn-forecaster">RNN forecaster</a></li>
<li><a href="#autoregression" id="markdown-toc-autoregression">Autoregression</a></li>
</ul>
</li>
<li><a href="#1053-summary-of-rnns" id="markdown-toc-1053-summary-of-rnns">10.5.3. Summary of RNNs</a></li>
</ul>
</li>
<li><a href="#106-when-to-use-deep-learning" id="markdown-toc-106-when-to-use-deep-learning">10.6. When to Use Deep Learning</a></li>
<li><a href="#107-fitting-a-neural-network" id="markdown-toc-107-fitting-a-neural-network">10.7. Fitting a Neural Network</a> <ul>
<li><a href="#1071-backpropagation" id="markdown-toc-1071-backpropagation">10.7.1. Backpropagation</a></li>
<li><a href="#1072-regularization-and-stochastic-gradient-descent" id="markdown-toc-1072-regularization-and-stochastic-gradient-descent">10.7.2. Regularization and Stochastic Gradient Descent</a></li>
<li><a href="#1073-dropout-learning" id="markdown-toc-1073-dropout-learning">10.7.3. Dropout Learning</a></li>
<li><a href="#1074-network-tuning" id="markdown-toc-1074-network-tuning">10.7.4. Network Tuning</a></li>
</ul>
</li>
<li><a href="#108-interpolation-and-double-descent" id="markdown-toc-108-interpolation-and-double-descent">10.8. Interpolation and Double Descent</a></li>
</ul>
<h2 id="chapter-10-deep-learning">Chapter 10. Deep Learning</h2>
<h2 id="101-single-layer-neural-networks">10.1. Single Layer Neural Networks</h2>
<ul>
<li>
<p>A neural network takes input vector of <em>p</em> variables \(X=(X_1,X_2,\ldots,X_p)\) and builds a nonlinear function $f(X)$ to predict the response <em>Y</em>. What distinguishes neural networks from these methods is the particular <em>structure</em> of the model.</p>
</li>
<li>
<p>E.g. a simple <em>feed-forward neural network</em>:<br />
\(\begin{align*}
f(X)&= \beta_0 + \sum_{k=1}^K\beta_k h_k(X) \\
&= \beta_0 + \sum_{k=1}^K\beta_k g(w_{k0}+\sum_{j=1}^p w_{kj}X_j).
\end{align*}\)<br />
In the terminology, the features \(X_1,\ldots,X_4\) make up the units in the <em>input layer</em>. Each of the inputs from the input lyaer feed into each of the <em>K hidden units</em>. In two steps; First the <em>K activations</em> $A_k$ in the hidden layer are computed as functions of the input features $X_1,\ldots,X_p$,<br />
\(A_k = h_k(X) = g(w_{k0}+\sum_{j=1}^p w_{kj}X_j)\),<br />
where \(g(z)\) is a nonlinear <em>activation function</em> that is specified in advance. We can think of each \(A_k\) as a different transformation \(h_k(X)\) of the original features, like basis functions of Chapter 7. These <em>K</em> activations then feed into the output layer, resulting in<br />
\(f(X) = \beta_0 + \sum_{k=1}^K \beta_k A_k\),<br />
a linear regression model. All the parameters $\beta_0,\ldots,\beta_K$ and $w_{10},\ldots,w_{Kp}$ need to be estimated from data.</p>
</li>
<li>
<p>With deriving <em>K</em> new features by computing <em>K</em> different linear combinations of <em>X</em>, the model squashes each through an activation function $g(\cdot)$ to transform it. The final model is linear in these derived variables.</p>
</li>
<li>Activation functions
<ul>
<li><em>sigmoid</em> activation function:<br />
\(g(z)=\frac{e^z}{1+e^z}=\frac{1}{1+e^{-z}}\)<br />
which is the same function used in logistic regression to convert a linear function into probabilities between zero and one.</li>
<li><strong><em>ReLU</em></strong>(<em>rectified linear unit</em>) activation function:<br />
\(g(z) = (z)_{+} = \begin{cases}0, & \mbox{if }z<0 \\
z, & \mbox{othersize}.\end{cases}\)<br />
can be computed and stored more efficiently than a sigmoid function. Although it thresholds at zero, because we apply it to a linear function the constant term \(w_{k0}\) will shift this inflection point.</li>
</ul>
</li>
<li>
<p>The nonlinearity in the activation function \(g(\cdot)\) is essential, since without it the model would collapse into a simple linear model. Moreoever, having a nonlinear activation function allows the model to capture complex nonlinearities and interaction effects.</p>
</li>
<li>Fitting a neural network requires estimating the unknown parameters. For a quantitative response, typically squared-error loss is used, so that the parameters are chosen to minimize \(\sum_{i=1}^n(y_i-f(x_i))^2\).</li>
</ul>
<h2 id="102-multilayer-neural-networks">10.2. Multilayer Neural Networks</h2>
<ul>
<li>
<p>With <em>H</em> multiple hidden layers,<br />
the first hidden layer is<br />
\(\begin{align*}
A_k^{(1)} &= h_k^{(1)}(X) \\
&= g(w_{k0}^{(1)}+\sum_{j=1}^p w_{kj}^{(1)}X_j)
\end{align*}\)<br />
for \(k=1,\ldots,K_1\).<br />
The <em>h</em>th hidden layer treats the activations \(A_k^{(h-1)}\) as inputs and computes new activations<br />
\(\begin{align*}
A_{k'}^{(h)} &= h_{k'}^{(h)}(X) \\
&= g(w_{k'0}^{(h)}+\sum_{k'=1}^{K_1} w_{hk'}^{(h)}A_k^{(h-1)})
\end{align*}\)<br />
for \(k'=1,\ldots,K_h\). Each \(A_{k'}^{(h)} = h_{k'}^{(h)}(X)\) is a function of input vector <em>X</em>. Thus, through a chain of transformations, the network is able to build up fairly complex transformations of <em>X</em> that ultimately feed into the output layer as features.</p>
</li>
<li>
<p>The notation \(\mathbf{W}_h\) represents the entire matrix of weights that feed from the hidden layer $L_{h-1}$ to $L_h$. Each element $A_k^{(h-1)}$ feeds to the hidden layer $L_h$ via the matrix of weights \(\mathbf{W}_h\).</p>
</li>
<li>
<p>On the output layer in the classification case, compute <em>M</em> different linear models similar to our single model to get separate quantitative responses for each classes. To represent class probabilities \(f_m(X)=Pr(Y=m|X)\), we use the <em>softmax</em> activation function<br />
\(f_m(X)=Pr(Y=m|X)=\frac{e^{Z_m}}{\sum_{l=0}^{M-1} e^{Z_l}}\).<br />
The classifier assigns the image to the class with the highest probability.</p>
</li>
<li>
<p>To train this network, since the response is qualitative, we look for coefficient estimates that minimize the negative multinomial log-likelihood<br />
\(-\sum_{i=1}^n\sum_{m=0}^{M-1}y_{im}\log(f_m(x_i))\),<br />
known as the <em>cross-entropy</em>, a generalization of the criterion for two-class logistic regression. If the response were quantitative, we would instead minimize squared-error loss as before.</p>
</li>
</ul>
<h2 id="103-convolutional-neural-networks">10.3. Convolutional Neural Networks</h2>
<h3 id="1031-convolution-layers">10.3.1. Convolution Layers</h3>
<ul>
<li>
<p>A <em>convolution layer</em> is made up of a large number of <em>convolution filters</em>, each of which is a template that determines whether a particular local feature is present in an image. A very simple operation, called a <em>convolution</em> amounts to repeatedly multiplying matrix elements and then adding the results. Resulting <em>convolved image highlights regions of the original image that resemble the convolution filter</em>.</p>
</li>
<li>
<p>In a convolution layer, we use a whole bank of filters to pick out a variety of differently-oriented edges and shapes in the image. Using predefined filters in this way is standard practice in image processing. By contrast, we can think of the filter weights as the parameters going from an input layer to a hidden layer. Thus, with CNNs the filters are learned for the specific classification task.</p>
</li>
</ul>
<h3 id="1032-pooling-layers">10.3.2. Pooling Layers</h3>
<ul>
<li>A <em>pooling</em> layer provides a way to condense a large image into a smaller summary image. The <em>max pooling</em> operation summarizes each non-overlapping block of pixels in an image using the maximum value in the block. This reduces the size of the image and also provides some <em>location invariance</em>.</li>
</ul>
<h3 id="1033-architecture-of-a-convolutional-neural-network">10.3.3. Architecture of a Convolutional Neural Network</h3>
<ul>
<li>Convolve-then-pool sequence:<br />
Start with the three-dimensional feature map of a color image, consist of three $n\times n$ two-dimensional feature map of pixels.<br />
Each convolve layer takes as input the three-dimensional feature map from the previous layer and treats it like a single multi-channel image. Each convolution filter learned has as many channels as this feature map.<br />
Since the channel feature maps are reduced in size after each pool layer, we usually increase the number of filters in the next convolve layer to compensate.<br />
Sometimes we repeat several convolve layers before a pool layer. This effectively increases the dimension of the filter.<br />
These operations are repeated until the pooling has reduced each channel feature map down to just a few pixels in each dimension.<br />
Then the three-dimensional feature maps are flattened; the pixels are treated as separate units, and fed into one or more fully-connected layers before reaching the output layer, which is a <em>softmax activation</em> for the classification.</li>
</ul>
<h3 id="1034-data-augmentation">10.3.4. Data Augmentation</h3>
<ul>
<li>
<p>Each training image is replicated many times, with each replicate randomly distorted in a natural way such that human recognition is unaffected. Typical distortions are zoom, horizontal and vertical shift, shear, small rotations, and horizontal flips. This is a way of increasing the training set considerably with somewhat different examples, and thus protects against overfitting.</p>
</li>
<li>
<p>We can see this as a form of regularization: we build a cloud of images around each original image, all with the same label. This kind of fattening of the data is similar in spirit to ridge regularization.</p>
</li>
</ul>
<h2 id="104-document-classification">10.4. Document Classification</h2>
<ul>
<li>
<p>For the two-class response of the sentiment of the text data, which will be positive or negative. Each document can be a different length, include slang or non-words, have spelling errors, etc. We need to find a way to featurize such a document.</p>
</li>
<li>
<p>The simplest featurization is BOW, <em>bog-of-words</em> model. With dictionary containing <em>M</em> words, we create a binary feature vector of length <em>M</em> for each document, scoring 1 for presence, and 0 otherwise. The resulting training feature matrix <strong>X</strong> is a <em>sparse matrix</em>, most of the values are the same(to zero); it can be stored efficiently in <em>sparse matrix format</em>. Then we can build a neural network model with the feature matrix as input layers.</p>
</li>
<li>
<p>The bag-of-words model summarizes a document by the words present, and ignores their context. There are at least two popular ways to take the context into account:</p>
<ul>
<li>The <em>bag-of-n-grams</em> model recording the consecutive co-occurrence of every distinct set of words.</li>
<li>Treat the document as a sequence, taking account of all the words in the context of those that preceded and those that follow.</li>
</ul>
</li>
</ul>
<h2 id="105-recurrent-neural-networks">10.5. Recurrent Neural Networks</h2>
<ul>
<li>
<p>In a <em>recurrent neural network</em> (RNN), the input object <em>X</em> is a <em>sequence</em>. Considering a corpus of documents, each document can be represented as a sequence of <em>L</em> words, so \(X=\left\{ X_1,X_2,\ldots,X_L\right\}\). RNNs are designed to capture the sequential nature of such(text) input objects like CNNs for the spatial structure of image inputs. The output <em>Y</em> can also be a sequence (such as in language translation), but often is a scalar, like the binary sentiment label of a movie review document.</p>
</li>
<li>
<p>The structure of a very basic RNN; with a sequence \(X=\left\{ X_1,X_2,\ldots,X_L\right\}\), a simple output <em>Y</em>, and a hidden-layer sequence \(\left\{ A_l \right\}_1^L =\left\{ A_1,A_2,\ldots,A_L\right\}\). Each \(X_l\) is a vector representation for the $l$th word.<br />
Suppose it has <em>p</em> components \(X_l^T = (X_{l1},X_{l2},\ldots,X_{lp})\), and hidden layer consists of <em>K</em> units \(A_l^T = (A_{l1},\ldots,A_{lK})\). We represent the collection of \(K \times (p+1)\) shared weights $w_{kj}$ for the input layer by a matrix <strong>W</strong>, and similarly <strong>U</strong> is a \(K \times K\) matrix of the weights $u_{ks}$ for the hidden-to hideen layers, and <strong>B</strong> is a <em>K+1</em> vector of weights $\beta_k$ for the output layer.<br />
Then \(A_{lk}=g(w_{k0}+\sum_{j=1}^p w_{kj}X_{lj} + \sum_{s=1}^K u_{ks} A_{l-1,s})\), and the output \(O_l = \beta_0 + \sum_{k=1}^K\beta_k A_{lk}\) for a quantitative response, for example. Here $g(\cdot)$ is an activation function such as ReLU. Note that the same weights <strong>W</strong>, <strong>U</strong>, and <strong>B</strong> are not functions of $l$. This is a form of <em>weights sharing</em> used by RNNs, similar to the use of filters in CNNs.<br />
Proceeded from beginning to end, the activations $A_l$ accumulate a history of what has been seen before, so that the learned context can be used for prediction.<br />
<img src="/assets/images/ch10_simpleRNN.png" alt="png" width="70%" height="70%" /></p>
</li>
<li>
<p>For regression problems the loss function is $(Y-O_L)^2$, which only references the final output \(O_L = \beta_0 + \sum_{k=1}^K\beta_k A_{Lk}\) and others before are not used. With <em>n</em> input sequence/response pairs, the parameters are found by minimizing the sum of squares \(\sum_{i=1}^n(y_i-o_{iL})^2\).</p>
</li>
</ul>
<h3 id="1051-sequential-models-for-document-classification">10.5.1. Sequential Models for Document Classification</h3>
<ul>
<li>
<p>Beacuse of the dimensionality problem of bag-of-words model(one-hot-encoded vector), we use lower-dimensional <em>embedding</em> space instead. Rather than representing each word by a binary vector with zeros and a single one in some position, we will represent it by a set of <em>m</em> real numbers, none of which are typically zero.</p>
</li>
<li>
<p>The <em>embedding layer</em> <strong>E</strong> comes from the optimization part of a neural network, or we can use a <em>weight freezing</em>, inserting a precomputed matrix <strong>E</strong> in the embedding layer. The idea is that the positions of words in the embedding space preserve semantic meaning: synonyms should appear near each other.</p>
</li>
<li>
<p>The next step is to limit each document to the last <em>L</em> words. Documents that are shorter get padded with zeros upfront. So now each document is represented by a series consisting of <em>L</em> vectors, and each $X_l$ in the sequence has <em>m</em> components.</p>
</li>
<li>
<p>Then we run the process of simple RNN as presented before, with <strong>B</strong> has <em>2(K+1)</em> for two-class logistic regression. If the embedding layer <strong>E</strong> is learned, that adds an additional $m \times D$ parameters, and is by far the biggest cost.</p>
</li>
<li>
<p>More elaborate versions use long term and short term memory (LSTM). However, LSTM models take a long time to train, which makes exploring many architectures and parameter optimization tedious.</p>
</li>
</ul>
<h3 id="1052-time-series-forecasting">10.5.2. Time Series Forecasting</h3>
<ul>
<li>
<p>In an example of Stock price predition, one feature of stock market data is that the day-to-day observations are not independent of each other. The series exhibit <em>auto-correlation</em>; values nearby in time tend to be similar to each other.</p>
</li>
<li>
<p>Consider pairs of observations $(v_t,v_{t-l})$, a <em>lag</em> of $l$ days apart. If we take all such pairs in the $v_t$ series and compute their correlation coefficient, this gives the autocorrelation at lag $l$.</p>
</li>
<li>
<p>Another interesting characteristic of this forecasting problem is that the response variable $v_t$; <code class="language-plaintext highlighter-rouge">log_volume</code> is also a predictor. We will use the past values of <code class="language-plaintext highlighter-rouge">log_volume</code> to predict values in the future.</p>
</li>
</ul>
<h4 id="rnn-forecaster">RNN forecaster</h4>
<ul>
<li>
<p>We wish to predict a value $v_t$ from past values $v_{t-1},v_{t-2},\ldots$ and also to make use of past values of the other series $r_{t-1},r_{t-2},\ldots$ and $z_{t-1},z_{t-2},\ldots$.</p>
</li>
<li>
<p>Idea: to extract many short mini-series of input sequences with a predefined length <em>L</em>(lag), and a corresponding target <em>Y</em>.<br />
\(X_1= \begin{pmatrix} v_{t-L}\\ r_{t-L}\\ z_{t-L} \end{pmatrix}, X_2= \begin{pmatrix} v_{t-L+1}\\ r_{t-L+1}\\ z_{t-L+1} \end{pmatrix}, \cdots, X_L= \begin{pmatrix} v_{t-1}\\ r_{t-1}\\ z_{t-1} \end{pmatrix}\), and \(Y=v_t\).<br />
Here the target <em>Y</em> is the value of response at a single timepoint <em>t</em>, and the input sequence <em>X</em> is the series of 3-vectors \(\left\{X_l\right\}_1^L\) consisting of measurements from day <em>t-L, t-L+1,</em> up to <em>t-1</em>. Each value of <em>t</em> makes a separate pair (<em>X,Y</em>). Then we run RNN model for prediction.</p>
</li>
</ul>
<h4 id="autoregression">Autoregression</h4>
<ul>
<li>
<p>The RNN we just fit has much in common with a traditional <em>autoregression</em>(AR) linear model. Constructed a response vector <strong>y</strong> and a matrix <strong>M</strong> of predictors for least squares regression:<br />
\(\mathbf{y}=\begin{bmatrix} v_{L+1}\\ v_{L+2}\\ \vdots\\ v_T \end{bmatrix}\),
\(\mathbf{M}=\begin{bmatrix} 1 & v_L & v_{L-1} & \cdots & v_1 \\
1 & v_{L+1} & v_{L} & \cdots & v_2 \\
\vdots & \vdots & \ddots & \vdots \\
1 & v_{T-1} & v_{T-2} & \cdots & v_{T-L}
\end{bmatrix}\)<br />
each have <em>T-L</em> rows, one per observation. The predictors for any given reponse $v_t$ on day <em>t</em> are the previous <em>L</em> values of the same series. Fitting a regression of <strong>y</strong> on <strong>M</strong> amounts to fitting the model<br />
\(\hat{y}_t = \hat\beta_0 + \hat\beta_1 v_{t-1} + \hat\beta_2 v_{t-2} + \cdots +
\hat\beta_L v_{t-L}\),<br />
and is called an order-<em>L</em> autoregressive model, or simplay AR(<em>L</em>).</p>
</li>
<li>The RNN processes data sequence from left to right with the same weights <strong>W</strong>, while the AR model simply treats all <em>L</em> elements of the sequence equally as a vector of $L \times p$ predictors; a process called <em>flattening</em> in the neural network. Of course the RNN also includes the hidden layer activations which transfer information along the sequence, and introduces additional nonlinearity with much more parameters.
<h3 id="1053-summary-of-rnns">10.5.3. Summary of RNNs</h3>
</li>
<li>There are many variations and enhancements of the simple RNN for sequence modeling. One approach uses a onedimensional convolutional neural network, treating the sequence of vectors as an image. One can also have additional hidden layers; multi-layer RNN. Alternative <em>bidirectional</em> RNNs scan the sequences in both directions. In language translation the target is also a sequence of words, in a language different from that of the input sequence. Both the input sequence and the target sequence share the hidden units, so-called <em>Seq2Seq</em> learning.</li>
</ul>
<h2 id="106-when-to-use-deep-learning">10.6. When to Use Deep Learning</h2>
<ul>
<li>
<p>Should we discard all our older tools, and use deep learning on every problem with data? We follow Occam’s razor principle: when faced with several methods that give roughly equivalent performance, pick the simplest.</p>
</li>
<li>
<p>Typically we expect deep learning to be an attractive choice when the sample size of the training set is extremely large, and when interpretability of the model is not a high priority.</p>
</li>
</ul>
<h2 id="107-fitting-a-neural-network">10.7. Fitting a Neural Network</h2>
<ul>
<li>
<p>In simple network, the parameters are \(\beta = (\beta_0,\beta_1,\ldots,\beta_K)\), each of the \(w_k=(w_{k0},w_{k1},\ldots,w_{kp})\) for <em>k</em> in <em>K</em>. Given observations ($x_i,y_i$) for <em>i</em> in <em>n</em>, we fit the model by solving a nonlinear least squares problem<br />
\(\begin{align*}\text{min}_{\left\{ w_k \right\}_1^K, \beta }\frac{1}{2}\sum_{i=1}^n(y_i-f(x_i))^2,\end{align*}\)<br />
where \(f(x_i)=\beta_0+\sum_{k=1}^K\beta_k g(w_{k0}+\sum_{j=1}^p w_{kj}x_{ij})\).</p>
</li>
<li>
<p>The minimization objective is quite simple, but because of the nested arrangement of the parameters and the symmetry of the hidden units, it is not straightforward to minimize. The problem is nonconvex in the parameters, and hence there are multiple solutions. To overcome some of these issues and to protect from overfitting, two general strategies are employed when fitting neural networks: <em>Slow learning</em> and <em>Regularization</em>.</p>
</li>
<li>
<p>Suppose we represent all the parameters in one long vecter \(\theta\). Then we can rewrite the objective as<br />
\(R(\theta)=\frac{1}{2}\sum_{i=1}^n(y_i-f_{\theta}(x_i))^2\), where we make explicit the dependence of <em>f</em> on the parameters. The idea of gradient descent is</p>
<ol>
<li>Start with a guess \(\theta^0\) for all the parameters in \(\theta\), and set \(t=0\).</li>
<li>Iterate until the objective fails to decrease:<br />
(a) Find a vector \(\delta\) reflects a small change in \(\theta\), such that \(\theta^{t+1} = \theta^t + \delta\) reduces the objective; i.e. such that \(R(\theta^{t+1})<R(\theta^t)\).<br />
(b) Set \(t \leftarrow t+1\).</li>
</ol>
</li>
</ul>
<h3 id="1071-backpropagation">10.7.1. Backpropagation</h3>
<ul>
<li>
<p>How do we find the directions to move \(\theta\) so as to decrease the objective? The <em>gradient</em> of $R(\theta)$, evaluated at some current value \(\theta=\theta^m\), is the vector of partial derivatives at that point:<br />
\(\begin{align*}\triangledown R(\theta^m) = \frac{\partial R(\theta)}{\partial\theta}|_{\theta=\theta^m}\end{align*}\).<br />
The subscript \(\theta=\theta^m\) means that after computing the vector of derivatives, we evaluate it at the current guess, \(\theta^m\). This gives the direction in $\theta$-space in which $R(\theta)$ <em>increases</em> most rapidly. The idea of gradient descent is to move $\theta$ a little in the <em>opposite</em> direction(since we wish to go downhill):<br />
\(\theta^{m+1}\leftarrow\theta^m - \rho\triangledown R(\theta^m)\).<br />
For a small enough value of the <em>learning rate</em> $\rho$, this step will decrease the objective $R(\theta)$; i.e. $R(\theta^{m+1})\le R(\theta^m)$. If the gradient vector is zero, then we may have arrived at a minimum of the objective.</p>
</li>
<li>
<p>Calculation: the <em>chain rule</em> of differentiation</p>
</li>
</ul>
<h3 id="1072-regularization-and-stochastic-gradient-descent">10.7.2. Regularization and Stochastic Gradient Descent</h3>
<ul>
<li>
<p><em>stochastic gradient descent</em>(SGD):<br />
When n is large, instead of calculating over all <em>n</em> observations, we can sample a small fraction or <em>minibatch</em> of them each time we compute a gradient step.</p>
</li>
<li>
<p>Regularization:<br />
E.g. Ridge regularization on the weights, augmenting the objective function with a penalty term on classification problem:<br />
\(R(\theta;\lambda)=-\sum_{i=1}^n\sum_{m=0}^{M-1}y_{im}\log(f_m(x_i))
+\lambda\sum_j\theta_j^2\).<br />
With $\lambda$ as preset at a small value or found using the validation-set approach. We can also use different values of $\lambda$ for the groups of weights from different layers. Lasso is also a popular alternative.</p>
</li>
</ul>
<h3 id="1073-dropout-learning">10.7.3. Dropout Learning</h3>
<ul>
<li>Efficient form of regularization, similar in some respects to ridge regularization. The idea is to randomly remove a fraction of the units in a layer when fitting the model, separately each time a training observation is processed. This prevents nodes from becoming over-specialized, and can be seen as a form of regularization.</li>
</ul>
<h3 id="1074-network-tuning">10.7.4. Network Tuning</h3>
<ul>
<li>Choices that all have an effect on the performance:<br />
The number of hidden layers, and the number of units per layer.<br />
Regularization tuning parameters.<br />
Details of stochastic gradient descent.</li>
</ul>
<h2 id="108-interpolation-and-double-descent">10.8. Interpolation and Double Descent</h2>
<ul>
<li>
<p>In certain specific settings it can be possible for a statistical learning method that interpolates the training data to perform well; or at least, better than a slightly less complex model that does not quite interpolate the data. The phenomenon is known as <em>double descent</em>, where the test error has a U-shape before the interpolation threshold is reached, and then it descends again (for a while, at least) as an increasingly flexible model is fit. The double-descent phenomenon does not contradict the bias-variance trade-off.</p>
</li>
<li>
<p>It has been used by the machine learning community to explain the successful practice of using an overparametrized neural network (many layers, and many hidden units), and then fitting all the way to zero training error. However, zero error fit is not always optimal, we typically do not want to rely on this behavior.</p>
</li>
</ul>
</div>
</section>
<!-- Email subscribe form at the bottom of the page -->
<!--
<section class="subscribe-form">
<h3 class="subscribe-form-title">Subscribe to Darron's Devlog</h3>
<p>Get the latest posts delivered right to your inbox</p>
<span id="searchform" method="post" action="/subscribe/" class="">
<input class="confirm" type="hidden" name="confirm" />
<input class="location" type="hidden" name="location" />
<input class="referrer" type="hidden" name="referrer" />
<div class="form-group">
<input class="subscribe-email" onkeyup="myFunc()"
id="searchtext" type="text" name="searchtext"
placeholder="Search..." />
</div>
<script type="text/javascript">
function myFunc() {
if(event.keyCode == 13) {
var url = encodeURIComponent($("#searchtext").val());
location.href = "/search.html?query=" + url;
}
}
</script>
</span>
</section>
-->
<footer class="post-full-footer">
<!-- Everything inside the #author tags pulls data from the author -->
<!-- #author-->
<!-- /author -->
</footer>
<!-- If you use Disqus comments, just uncomment this block.
The only thing you need to change is "test-apkdzgmqhj" - which
should be replaced with your own Disqus site-id. -->
<section class="post-full-comments">
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
var this_page_url = 'http://0.0.0.0:4000/islr_ch10';
var this_page_identifier = '/islr_ch10';
var this_page_title = 'ISLR - Chapter 10. Deep Learning';
};
(function() {
var d = document, s = d.createElement('script');
s.src = 'https://.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
</section>
</article>
</div>
</main>
<!-- Links to Previous/Next posts -->
<aside class="read-next outer">
<div class="inner">
<div class="read-next-feed">
<article class="read-next-card"
style="background-image: url(/assets/built/images/blog-cover1.png)"
>
<header class="read-next-card-header">
<small class="read-next-card-header-sitetitle">— Darron's Devlog —</small>
<h3 class="read-next-card-header-title"><a href="/tag/islr/">Islr</a></h3>
</header>
<div class="read-next-divider"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 14.5s2 3 5 3 5.5-2.463 5.5-5.5S21 6.5 18 6.5c-5 0-7 11-12 11C2.962 17.5.5 15.037.5 12S3 6.5 6 6.5s4.5 3.5 4.5 3.5"/></svg>
</div>
<div class="read-next-card-content">
<ul>
<li><a href="/islr_ch9">ISLR - Chapter 9. Support Vector Machines</a></li>
<li><a href="/islr_ch8">ISLR - Chapter 8. Tree-Based Methods</a></li>
<li><a href="/islr_ch7">ISLR - Chapter 7. Moving Beyond Linearity</a></li>
</ul>
</div>
<footer class="read-next-card-footer">
<a href="/tag/islr/">
See all 8 posts →
</a>
</footer>
</article>
<!-- If there's a next post, display it using the same markup included from - partials/post-card.hbs -->
<article class="post-card post-template no-image">
<div class="post-card-content">
<a class="post-card-content-link" href="/NLP_korean_RNN">
<header class="post-card-header">
<span class="post-card-tags">Projects</span>
<h2 class="post-card-title">NLP - Korean Language Text Analysis with RNN</h2>
</header>
<section class="post-card-excerpt">
<p>
</p>
</section>
</a>
<footer class="post-card-meta">
</footer>
</div>
</article>
<!-- If there's a previous post, display it using the same markup included from - partials/post-card.hbs -->
<article class="post-card post-template no-image">
<div class="post-card-content">
<a class="post-card-content-link" href="/islr_ch9">
<header class="post-card-header">
<span class="post-card-tags">Islr</span>
<h2 class="post-card-title">ISLR - Chapter 9. Support Vector Machines</h2>
</header>
<section class="post-card-excerpt">
<p>Chapter 9. Support Vector Machines 9.1. Maximal Margin Classifier 9.1.1. What Is a Hyperplane? 9.1.2. Classification Using a Separating Hyperplane 9.1.3. The Maximal Margin Classifier 9.1.4. Construction of the Maximal Margin Classifier 9.1.5.</p>
</section>
</a>
<footer class="post-card-meta">
</footer>
</div>
</article>
</div>
</div>
</aside>
<!-- Floating header which appears on-scroll, included from includes/floating-header.hbs -->
<div class="floating-header">
<div class="floating-header-logo">
<a href="/">
<span>Darron's Devlog</span>
</a>
</div>
<span class="floating-header-divider">—</span>
<div class="floating-header-title">ISLR - Chapter 10. Deep Learning</div>
<div class="floating-header-share">
<div class="floating-header-share-label">Share this <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M7.5 15.5V4a1.5 1.5 0 1 1 3 0v4.5h2a1 1 0 0 1 1 1h2a1 1 0 0 1 1 1H18a1.5 1.5 0 0 1 1.5 1.5v3.099c0 .929-.13 1.854-.385 2.748L17.5 23.5h-9c-1.5-2-5.417-8.673-5.417-8.673a1.2 1.2 0 0 1 1.76-1.605L7.5 15.5zm6-6v2m-3-3.5v3.5m6-1v2"/>
</svg>
</div>
<a class="floating-header-share-tw" href="https://twitter.com/share?text=ISLR+-+Chapter+10.+Deep+Learning&url=https://12kdh43.github.io/islr_ch10"
onclick="window.open(this.href, 'share-twitter', 'width=550,height=235');return false;">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M30.063 7.313c-.813 1.125-1.75 2.125-2.875 2.938v.75c0 1.563-.188 3.125-.688 4.625a15.088 15.088 0 0 1-2.063 4.438c-.875 1.438-2 2.688-3.25 3.813a15.015 15.015 0 0 1-4.625 2.563c-1.813.688-3.75 1-5.75 1-3.25 0-6.188-.875-8.875-2.625.438.063.875.125 1.375.125 2.688 0 5.063-.875 7.188-2.5-1.25 0-2.375-.375-3.375-1.125s-1.688-1.688-2.063-2.875c.438.063.813.125 1.125.125.5 0 1-.063 1.5-.25-1.313-.25-2.438-.938-3.313-1.938a5.673 5.673 0 0 1-1.313-3.688v-.063c.813.438 1.688.688 2.625.688a5.228 5.228 0 0 1-1.875-2c-.5-.875-.688-1.813-.688-2.75 0-1.063.25-2.063.75-2.938 1.438 1.75 3.188 3.188 5.25 4.25s4.313 1.688 6.688 1.813a5.579 5.579 0 0 1 1.5-5.438c1.125-1.125 2.5-1.688 4.125-1.688s3.063.625 4.188 1.813a11.48 11.48 0 0 0 3.688-1.375c-.438 1.375-1.313 2.438-2.563 3.188 1.125-.125 2.188-.438 3.313-.875z"/></svg>
</a>
<a class="floating-header-share-fb" href="https://www.facebook.com/sharer/sharer.php?u=https://12kdh43.github.io/islr_ch10"
onclick="window.open(this.href, 'share-facebook','width=580,height=296');return false;">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><path d="M19 6h5V0h-5c-3.86 0-7 3.14-7 7v3H8v6h4v16h6V16h5l1-6h-6V7c0-.542.458-1 1-1z"/></svg>
</a>
</div>
<progress class="progress" value="0">
<div class="progress-container">
<span class="progress-bar"></span>
</div>
</progress>
</div>
<!-- /post -->
<!-- The #contentFor helper here will send everything inside it up to the matching #block helper found in default.hbs -->
<!-- Previous/next page links - displayed on every page -->
<!-- The footer at the very bottom of the screen -->
<footer class="site-footer outer">
<div class="site-footer-content inner">
<section class="copyright"><a href="/">Darron's Devlog</a> © 2022</section>
<!--
<section class="poweredby">Proudly published with <a href="https://jekyllrb.com/">Jekyll</a> &
<a href="https://pages.github.com/" target="_blank" rel="noopener">GitHub Pages</a> using
<a href="https://github.com/jekyllt/jasper2" target="_blank" rel="noopener">Jasper2</a></section>
-->
<nav class="site-footer-nav">
<a href="/">Latest Posts</a>
</nav>
</div>
</footer>
</div>
<!-- The big email subscribe modal content -->
<div id="subscribe" class="subscribe-overlay">
<a class="subscribe-overlay-close" href="#"></a>
<div class="subscribe-overlay-content">
<h1 class="subscribe-overlay-title">Search Darron's Devlog</h1>
<p class="subscribe-overlay-description">
</p>
<span id="searchform" method="post" action="/subscribe/" class="">
<input class="confirm" type="hidden" name="confirm" />
<input class="location" type="hidden" name="location" />
<input class="referrer" type="hidden" name="referrer" />
<div class="form-group">
<input class="subscribe-email" onkeyup="myFunc()"
id="searchtext" type="text" name="searchtext"
placeholder="Search..." />
</div>
<script type="text/javascript">
function myFunc() {
if(event.keyCode == 13) {
var url = encodeURIComponent($("#searchtext").val());
location.href = "/search.html?query=" + url;
}
}
</script>
</span>
</div>
</div>
<!-- highlight.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.10.0/components/prism-abap.min.js"></script>
<script>$(document).ready(function() {
$('pre code').each(function(i, block) {
hljs.highlightBlock(block);
});
});</script>
<!-- jQuery + Fitvids, which makes all video embeds responsive -->
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<script type="text/javascript" src="/assets/js/jquery.fitvids.js"></script>
<script type="text/javascript" src="https://demo.ghost.io/assets/js/jquery.fitvids.js?v=724281a32e"></script>
<!-- Paginator increased to "infinit" in _config.yml -->
<!-- if paginator.posts -->
<!-- <script>
var maxPages = parseInt('');
</script>
<script src="/assets/js/infinitescroll.js"></script> -->
<!-- /endif -->
<!-- Add Google Analytics -->
<!-- Google Analytics Tracking code -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '', 'auto');
ga('send', 'pageview');
</script>
<!-- The #block helper will pull in data from the #contentFor other template files. In this case, there's some JavaScript which we only want to use in post.hbs, but it needs to be included down here, after jQuery has already loaded. -->
<script>
// NOTE: Scroll performance is poor in Safari
// - this appears to be due to the events firing much more slowly in Safari.
// Dropping the scroll event and using only a raf loop results in smoother
// scrolling but continuous processing even when not scrolling
$(document).ready(function () {
// Start fitVids
var $postContent = $(".post-full-content");
$postContent.fitVids();
// End fitVids
var progressBar = document.querySelector('progress');