-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCM20230517_ISLR2_2.1.4_Neural_Network_Models
2245 lines (1895 loc) · 84 KB
/
PCM20230517_ISLR2_2.1.4_Neural_Network_Models
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
### A Pluto.jl notebook ###
# v0.19.26
using Markdown
using InteractiveUtils
# ╔═╡ 0de0b5c9-ec94-4d19-936d-b2cbb5f3b3b8
using CSV, DataFrames, Statistics, GLM, Plots
# ╔═╡ 2174f7b1-3da2-44bb-b6c0-c7aa26760111
using Flux
# ╔═╡ 64c23eb4-4664-4573-ae57-c2815f01148f
using Flux: train!
# ╔═╡ f80ea5a0-f57d-11ed-2f72-530e4436b981
md"
==================================================================================
#### ISLR2\_2.1.4\_Neural Network Models
##### file: PCM20230517\_ISLR2\_2.1.4\_Neural\_Network\_Models
##### code: (1.9.0/0.19.25) by PCM *** 2023/05/29 ***
==================================================================================
"
# ╔═╡ e3eaba32-50a8-4cb9-877b-1bbfa3b3e8e1
md"
---
##### 1. [Fitting a straight line](http://fluxml.ai/Flux.jl/stable/models/overview/)
"
# ╔═╡ 8237996f-fde7-40b9-a285-cc614f98dc1a
let
# =============================================================================
regressionModel(x) = 4x + 2
estimatedModel(x, w, b) = w .* x .+ b
# =============================================================================
# construct training and test data for predictor x
x_train, x_test = hcat(0:5...), hcat(6:10...)
# construct training and test data for criterium y
y_train, y_test = regressionModel.(x_train), regressionModel.(x_test)
#----------------------------------------------------------------------
# beware ! in 'train!' 'data' is expected
# in 'loss' 'x_train, y_train' is expected
data = [(x_train, y_train)]
# =============================================================================
# construct neural net with 1 input, 0 latent, and 1 output node
neuralRegressionModel = Dense(1 => 1)
#------------------------------------------------------------------------------
# definition of mean square error loss function
loss(model, x, y) = mean(abs2.(model(x) .- y))
epsilon = 10f-6
#------------------------------------------------------------------------------
# initial loss and loss after one training epoch
lossHistory = Array{Float32}(undef, 0) # new array
weight0, bias0 = neuralRegressionModel.weight, neuralRegressionModel.bias
push!(lossHistory, loss(neuralRegressionModel, x_train, y_train))
lossOld = last(lossHistory)
optStrategy = Descent()
train!(loss, neuralRegressionModel, data, optStrategy)
push!(lossHistory, loss(neuralRegressionModel, x_train, y_train))
lossNew = last(lossHistory)
#------------------------------------------------------------------------------
nOfEpochs = 0
while abs(lossOld - lossNew) > epsilon
nOfEpochs += 1
lossOld = last(lossHistory)
train!(loss, neuralRegressionModel, data, optStrategy)
lossNew = loss(neuralRegressionModel, x_train, y_train)
push!(lossHistory, lossNew)
end # while
weight, bias = neuralRegressionModel.weight, neuralRegressionModel.bias
#------------------------------------------------------------------------------
plot(title="Data and Regression Model E(Y|X=x) = 4x + 2")
plot!(x_train, y_train, seriestype=:scatter, color=:cornflowerblue, legend=:none, xlabel="X", ylabel="Y")
yHat = estimatedModel(0:0.1:5, weight, bias)
plot!(0:0.1:5, yHat, seriestype=:line, linecolor=:red)
lossNewRounded = round(lossNew, digits=4)
annotate!(4.5, 5, "mse=$lossNewRounded")
# (epochs=nOfEpochs, lossHistory=lossHistory, weight=weight, bias=bias)
# =============================================================================
end # let
# ╔═╡ 2ccc41a0-45d0-4de5-ae71-6ad572a2525b
md"
---
##### 2. Fitting a Linear Univariate Regression
(inspired by the corresponding [Flux-tutorial](http://fluxml.ai/Flux.jl/stable/tutorials/linear_regression/)) but with some modifications :)
"
# ╔═╡ f6b48792-9c03-42e8-9327-44b616198bd3
md"
---
###### 2.1 Generating Function, Randomization of $Y$, and Classical OLS-Regression
$f(x) = 3x + 2$
$\;$
$E(Y|x) = \beta_0 + \beta_1x$
$\;$
$Y = \beta_0 + \beta_1 x + E$
$\;$
$\hat{\beta} = (X'X)^{-1}X'ys$
$\;$
where $E$ = error variable with constant variance $\sigma_{Y|x}.$
"
# ╔═╡ d8b92235-7c8a-4efd-8151-a258cf64cfef
let # in contrast to tutorial slightly modified code
# ================================================================================
# definition of generating function
f(x) = 3.0 .* x .+ 2.0
nObs = 61 # number of observations
#---------------------------------------------------------------------------------
# generation of predictor data
x = [z for z in -3.0:0.1:3.0]
y = f(x)
ys = y .* rand(nObs) # the ys are randomized
rxy = round(cor(x, ys), digits=3)
#---------------------------------------------------------------------------------
# estimation of classical linear univariate regression model in pure Julia
X = hcat(ones(nObs, 1), x) # predictor matrix X
b = (X'X)^-1*(X'ys)
yHat = X*b
ryHaty = round(cor(yHat, ys), digits=3) # correlation(yhat, y)
bHat = round(b[2], digits=2)
cHat = round(b[1], digits=2)
#---------------------------------------------------------------------------------
# definition of mean square error loss function
mse = round(mean(abs2.(yHat .- y)), digits=3)
# ================================================================================
plot(title = "Generating Function, Data, and Class. OLS-Regression", xlims=(-3.5, 3.5), ylims=(-9, 13))
#--------------------------------------------------------------------------------
# plot of generating function
plot!(x, y, linestyle = :dash, lw = 2, label = "f(x) = 3.0 .* x .+ 2.0 (Generating Function)", xlabel = "x", ylabel= "y")
#--------------------------------------------------------------------------------
# plot of data
plot!(x, ys, seriestype = :scatter, label = " (x, y) = Data", xlabel = "x", ylabel= "y")
#---------------------------------------------------------------------------------
# plot of classical linear univariate regression line
plot!(x, yHat, seriestype=:line, linewidth=2, label ="E(Y|x) = $bHat .* x .+ $cHat (Classical OLS)")
#---------------------------------------------------------------------------------
annotate!(2.3, -5, "r(X, Y) = $rxy", 10)
annotate!(2.07, -6.2, "r(E(Y|x), Y) = $ryHaty", 10)
annotate!(2.4, -7.5, "mse = $mse", 10)
# ================================================================================
end # let
# ╔═╡ d83382df-7e37-430c-b2b6-cc8a25257a3c
md"
---
###### 2.2 As 2.1 plus GLM-OLS-Regression
$f(x) = 3x + 2$
$\;$
$E(Y|x) = \beta_0 + \beta_1x$
$\;$
$Y = \beta_0 + \beta_1 x + E$
$\;$
$\hat{\beta} = (X'X)^{-1}X'ys$
$\;$
where $E$ = error variable with constant variance $\sigma_{Y|x}.$
"
# ╔═╡ 1b05d618-e9b5-4027-a99e-04cf7f1f32f6
let # in contrast to tutorial slightly modified code
# ================================================================================
# definition of generating function
f(x) = 3.0 .* x .+ 2.0
nObs = 61 # number of observations
#---------------------------------------------------------------------------------
# generation of predictor data
x = [z for z in -3.0:0.1:3.0]
y = f(x)
ys = y .* rand(nObs) # the ys are randomized
rxy = round(cor(x, ys), digits=3)
#---------------------------------------------------------------------------------
# estimation of classical linear univariate regression model in pure Julia
X = hcat(ones(nObs, 1), x) # predictor matrix X
b = (X'X)^-1*(X'ys)
yHat = X*b
bHat = round(b[2], digits=2)
cHat = round(b[1], digits=2)
# ================================================================================
# construction of dataframe for use in GLM's lm
dataFr = DataFrame(X=x, Ys=ys)
#---------------------------------------------------------------------------------
# classical OLS-regression with GLM
univRegOLS = lm(@formula(Ys ~ 1 + X), dataFr) # regression object
yHatLm = predict(univRegOLS) # predictions of y
ryHaty = round(cor(yHatLm, ys), digits=3) # correlation(yhat, y)
cHatLm, bHatLm, = # estimated parameters
round(coef(univRegOLS)[1], digits=2), round(coef(univRegOLS)[2], digits=2)
#---------------------------------------------------------------------------------
# definition of mean square error loss function
mse = round(mean(abs2.(yHat .- y)), digits=3)
# ================================================================================
plot(title = "As 2.1 plus GLM-Regression", xlims=(-3.5, 3.5), ylims=(-9, 13))
#--------------------------------------------------------------------------------
# plot of generating function
plot!(x, y, linestyle = :dash, lw = 2, label = "f(x) = 3.0 .* x .+ 2.0 (Generating Function)", xlabel = "x", ylabel= "y")
#--------------------------------------------------------------------------------
# plot of data
plot!(x, ys, seriestype = :scatter, label = " (x, y) = Data", xlabel = "x", ylabel= "y")
#---------------------------------------------------------------------------------
# plot of classical linear univariate regression line
plot!(x, yHat, seriestype=:line, linewidth=2, label ="E(Y|x) = $bHat .* x .+ $cHat (Classical OLS)")
#--------------------------------------------------------------------------------
# plot of GLM-regression line
plot!(x, yHatLm, seriestype=:line, linestyle = :dash, linewidth=2, label ="E(Y|x) = $bHat .* x .+ $cHat (GLM-Regression)")
#---------------------------------------------------------------------------------
annotate!(2.3, -5, "r(X, Y) = $rxy", 10)
annotate!(2.07, -6.2, "r(E(Y|x), Y) = $ryHaty", 10)
annotate!(2.35, -7.4, "mse = $mse", 10)
# ===========3====================================================================
end # let
# ╔═╡ 244c6a02-0150-4669-b319-bf2dd12c23df
md"
---
###### 2.3 As 2.2 plus Gradient-Descent OLS-Regression
$f(x) = 3x + 2$
$\;$
$E(Y|x) = \beta_0 + \beta_1x$
$\;$
$Y = \beta_0 + \beta_1 x + E$
$\;$
where $E$ = error variable with constant variance $\sigma_{Y|x}.$
"
# ╔═╡ 56f5a82c-770e-404e-bfdd-d36d8ec70b34
let # in contrast to tutorial slightly modified code
# ================================================================================
# definition of generating function
f(x) = 3.0 .* x .+ 2.0
nObs = 61 # number of observations
#---------------------------------------------------------------------------------
# generation of predictor data
x = [z for z in -3.0:0.1:3.0]
y = f(x)
ys = y .* rand(nObs) # the ys are randomized
rxy = round(cor(x, ys), digits=3)
#---------------------------------------------------------------------------------
# estimation of classical linear univariate regression model in pure Julia
X = hcat(ones(nObs, 1), x) # predictor matrix X
b = (X'X)^-1*(X'ys)
yHat = X*b
bHat = round(b[2], digits=2)
cHat = round(b[1], digits=2)
# ================================================================================
# construction of dataframe for use in GLM's lm
dataFr = DataFrame(X=x, Ys=ys)
#---------------------------------------------------------------------------------
# classical OLS-regression with GLM
univRegOLS = lm(@formula(Ys ~ 1 + X), dataFr) # regression object
yHat = predict(univRegOLS) # predictions of y
cHat, bHat = # estimated parameters
round(coef(univRegOLS)[1], digits=2), round(coef(univRegOLS)[2], digits=2)
# ================================================================================
# definition of regression model for estimation of parameters by gradient descent
regressionModel(W, b, x) = @. W*x + b # makes predictions yHat
lossHistory = Array{Float64}(undef, 0) # new array for documenting loss
#---------------------------------------------------------------------------------
# definition of mean square error loss function
mseLoss(model, W, b, x, y) = mean(abs2.(model(W, b, x) .- y))
#---------------------------------------------------------------------------------
# initialization and first trial
W = rand(Float64, 1, 1) # initial regression coefficient w0 in Float64
W0 = W
b = [0.0e0] # initial bias b0 in Float64
b0 = b
regressionModel(W, b, x) |> size == (61, 1) # ==> true --> :)
regressionModel(W, b, x)[1], y[1] # first trial, ok ?
push!(lossHistory, mseLoss(regressionModel, W, b, x, ys)) # first MSE
lossOld = last(lossHistory) # first MSE
#---------------------------------------------------------------------------------
# Train classical regression model
# define gradient(mseLoss, regressionModel, W, b, x, y)
_, dLdW, dLdb, _, _ = gradient(mseLoss, regressionModel, W, b, x, ys)
#--------------------------------------------------------------------------------
# initial parameter update
W = W .- 0.1 .* dLdW
b = b .- 0.1 .* dLdb
push!(lossHistory, mseLoss(regressionModel, W, b, x, ys)) # 2nd MSE
lossOld = last(lossHistory) # 2nd MSE
#--------------------------------------------------------------------------------
# definition of one step training
function trainRegressionModel()
_, dLdW, dLdb, _, _ = gradient(mseLoss, regressionModel, W, b, x, ys)
@. W = W - 0.1 * dLdW
@. b = b - 0.1 * dLdb
end # function trainRegressionModel
#--------------------------------------------------------------------------------
# one step training
trainRegressionModel()
lossNew = mseLoss(regressionModel, W, b, x, ys)
W, b, lossOld, lossNew
#--------------------------------------------------------------------------------
nOfEpochs = 0
epsilon = 1.0E-7
# while !(lossOld ≈ lossNew)
while abs((lossOld - lossNew) > epsilon)
nOfEpochs += 1
lossOld = last(lossHistory)
trainRegressionModel()
lossNew = mseLoss(regressionModel, W, b, x, ys)
push!(lossHistory, lossNew)
end # while
yHatGrD = regressionModel(W, b, x)
ryHaty = round(cor(yHatGrD, ys)[1,1], digits=3) # correlation(yhat, y)
mse = round(lossNew, digits=3)
slope, constant = round(W[1,1], digits=2), round(b[1], digits=2)
nOfEpochs, W0, b0, W, b, mse
# ================================================================================
plot(title = "As 2.2 plus Gradient-Descent OLS-Regression", xlims=(-3.5, 3.5), ylims=(-9, 13))
#--------------------------------------------------------------------------------
# plot of generating function
plot!(x, y, linestyle = :dash, linewidth = 2, label = "f(x) = 3 .* x .+ 2 (Generating Function)", xlabel = "x", ylabel= "y")
#--------------------------------------------------------------------------------
# plot of data
plot!(x, ys, seriestype = :scatter, label = " (x, y) = Data", xlabel = "x", ylabel= "y")
#---------------------------------------------------------------------------------
# plot of classical linear univariate regression line
plot!(x, yHat, seriestype=:line, linewidth=2, label ="E(Y|x) = $bHat .* x .+ $cHat (Classical OLS)")
#--------------------------------------------------------------------------------
# plot of GLM-regression line
plot!(x, yHat, seriestype=:line, linestyle=:dash, linewidth = 2, label ="E(Y|x) = $bHat .* x .+ $cHat (GLM-Regression)")
#--------------------------------------------------------------------------------
# plot of gradient-descent OLS-regression line
plot!(x, regressionModel(W, b, x), seriestype=:line, linestyle=:dash, linewidth = 2,label ="E(Y|x) = $slope .* x .+ $constant (Gradient Descent)")
#---------------------------------------------------------------------------------
annotate!(2.3, -5, "r(X, Y) = $rxy", 10)
annotate!(2.07, -6.2, "r(E(Y|x), Y) = $ryHaty", 10)
annotate!(2.4, -7.4, "mse = $mse", 10)
# ================================================================================
end # let
# ╔═╡ defa354b-394f-4c90-8077-f05a631b29f8
md"
---
###### 2.4 As 2.3 plus Flux-Neural-Net OLS-Regression
$f(x) = E(Y|x) = \beta_0 + \beta_1x$
$\;$
$Y = \beta_0 + \beta_1 x + E$
$\;$
where $E$ = error variable with constant variance $\sigma_{Y|x}.$
"
# ╔═╡ 15ce3433-4f38-43a9-877c-9d2e57407732
let # in contrast to tutorial slightly modified code
# ================================================================================
# definition of generating function
f(x) = 3.0 .* x .+ 2.0
nObs = 61 # number of observations
#---------------------------------------------------------------------------------
# generation of predictor data
x = [z for z in -3.0:0.1:3.0]
y = f(x)
ys = y .* rand(nObs) # the ys are randomized
rxy = round(cor(x, ys), digits=3)
#---------------------------------------------------------------------------------
# estimation of classical linear univariate regression model in pure Julia
X = hcat(ones(nObs, 1), x) # predictor matrix X
b = (X'X)^-1*(X'ys)
yHat = X*b
bHat = round(b[2], digits=2)
cHat = round(b[1], digits=2)
# ================================================================================
# construction of dataframe for use in GLM's lm
dataFr = DataFrame(X=x, Ys=ys)
#---------------------------------------------------------------------------------
# classical OLS-regression with GLM
univRegOLS = lm(@formula(Ys ~ 1 + X), dataFr) # regression object
yHat = predict(univRegOLS) # predictions of y
cHat, bHat = # estimated parameters
round(coef(univRegOLS)[1], digits=2), round(coef(univRegOLS)[2], digits=2)
# ================================================================================
# construction of dataframe for use in GLM's lm
dataFr = DataFrame(X=x, Ys=ys)
#---------------------------------------------------------------------------------
# classical OLS-regression with GLM
univRegOLS = lm(@formula(Ys ~ 1 + X), dataFr) # regression object
yHat = predict(univRegOLS) # predictions of y
ryHaty = round(cor(yHat, ys), digits=4) # correlation(yhat, y)
cHat, bHat = # estimated parameters
round(coef(univRegOLS)[1], digits=2), round(coef(univRegOLS)[2], digits=2)
# ================================================================================
# definition of regression model for estimation of parameters by gradient descent
regressionModel(W, b, x) = @. W*x + b # makes predictions yHat
lossHistory = Array{Float64}(undef, 0) # new array for documenting loss
#---------------------------------------------------------------------------------
# definition of mean square error loss function
mseLoss(model, W, b, x, y) = mean(abs2.(model(W, b, x) .- y))
#---------------------------------------------------------------------------------
# initialization and first trial
W = rand(Float64, 1, 1) # initial regression coefficient w0 in Float64
W0 = W
b = [0.0e0] # initial bias b0 in Float64
b0 = b
regressionModel(W, b, x) |> size == (61, 1) # ==> true --> :)
regressionModel(W, b, x)[1], y[1] # first trial, ok ?
push!(lossHistory, mseLoss(regressionModel, W, b, x, ys)) # first MSE
lossOld = last(lossHistory) # first MSE
#---------------------------------------------------------------------------------
# Train classical regression model
# define gradient(mseLoss, regressionModel, W, b, x, y)
_, dLdW, dLdb, _, _ = gradient(mseLoss, regressionModel, W, b, x, ys)
#--------------------------------------------------------------------------------
# initial parameter update
W = W .- 0.1 .* dLdW
b = b .- 0.1 .* dLdb
push!(lossHistory, mseLoss(regressionModel, W, b, x, ys)) # 2nd MSE
lossOld = last(lossHistory) # 2nd MSE
#--------------------------------------------------------------------------------
# definition of one step training
function trainRegressionModel()
_, dLdW, dLdb, _, _ = gradient(mseLoss, regressionModel, W, b, x, ys)
@. W = W - 0.1 * dLdW
@. b = b - 0.1 * dLdb
end # function trainRegressionModel
#--------------------------------------------------------------------------------
# one step training the OLS-regression model
trainRegressionModel()
lossOld = last(lossHistory) # 2nd MSE
lossNew = mseLoss(regressionModel, W, b, x, ys) # 3rd MSE
W, b, lossOld, lossNew
#--------------------------------------------------------------------------------
# n-step training process
nOfEpochs = 0
epsilon = 1.0E-7
# while !(lossOld ≈ lossNew)
while abs((lossOld - lossNew) > epsilon)
nOfEpochs += 1
lossOld = last(lossHistory)
trainRegressionModel()
lossNew = mseLoss(regressionModel, W, b, x, ys)
push!(lossHistory, lossNew)
end # while
mse = round(lossNew, digits=3)
slope, constant = round(W[1,1], digits=2), round(b[1], digits=2)
nOfEpochs, W0, b0, W, b, mse
# ================================================================================
# definition of FLUX 1-0-1 neural net regression model
fluxRegressionModel = Dense(1 => 1)
#------------------------------------------------------------------------
# definition of mean square error loss function
fluxMseLoss(fluxRegressionModel, x, y) = Flux.mse(fluxRegressionModel(x), y)
fluxLossHistory = Array{Float32}(undef, 0) # new array for documenting loss
#---------------------------------------------------------------------------------
# initial guesses and first trial
x32 = convert(Vector{Float32}, x)
ys32 = convert(Vector{Float32}, ys)
#--------------------------------------------------------------------------------
# initial guesses, first trial, initial loss
weight, bias = fluxRegressionModel.weight, fluxRegressionModel.bias
# test, whether correct size of input
fluxRegressionModel(x32') |> size == (1, 61) # ==> true --> :)
# first trial
fluxRegressionModel(x32'), ys32
# initial loss
fluxLossOld = fluxMseLoss(fluxRegressionModel, x32', ys32') # 1st MSE
push!(fluxLossHistory, fluxLossOld) # 1st MSE
#--------------------------------------------------------------------------------
# comparison: is final OLS-regression loss approx eq to initial Flux-loss ?
mseLoss(regressionModel, W, b, x, ys) ≈ # '≈' = is approximately equal ?
fluxMseLoss(fluxRegressionModel, x32', ys32') ? ":)" : ":("
#--------------------------------------------------------------------------------
# definition of one step Flux-training
function trainFluxRegressionModel()
dLdm, _, _ = gradient(fluxMseLoss, fluxRegressionModel, x32', ys32')
@. fluxRegressionModel.weight =
fluxRegressionModel.weight - 0.001 * dLdm.weight
@. fluxRegressionModel.bias =
fluxRegressionModel.bias - 0.001 * dLdm.bias
end # function trainFluxRegressionModel
#--------------------------------------------------------------------------------
# one step training the Flux-OLS-regression model
trainFluxRegressionModel()
fluxLossNew = fluxMseLoss(fluxRegressionModel, x32', ys32') # 2nd MSE
push!(fluxLossHistory, fluxLossNew) # 2nd MSE
fluxWeight0 = fluxRegressionModel.weight
fluxBias0 = fluxRegressionModel.bias
fluxWeight0, fluxBias0, fluxLossHistory
#--------------------------------------------------------------------------------
# n-step training process
nOfFluxEpochs = 0
fluxEpsilon = 1.0E-8
while abs(fluxLossOld - fluxLossNew) > fluxEpsilon
nOfFluxEpochs += 1
fluxLossOld = last(fluxLossHistory)
trainFluxRegressionModel()
fluxLossNew = fluxMseLoss(fluxRegressionModel, x32', ys32')
push!(fluxLossHistory, fluxLossNew)
end # while
yHatFNN = fluxRegressionModel(x32')
ryHaty = round(cor(yHatFNN', ys)[1,1], digits=3) # correlation(yhat, y)
fluxMse = round(fluxLossNew, digits=3)
fluxWeight, fluxBias =
round(fluxRegressionModel.weight[1,1], digits=convert(Int32, 2)),
round(fluxRegressionModel.bias[1], digits=convert(Int32, 2))
nOfFluxEpochs, fluxWeight0, fluxBias0, fluxWeight, fluxBias, fluxLossHistory, mseLoss(regressionModel, W, b, x, ys)
#--------------------------------------------------------------------------------
# comparison: is final OLS-regression loss approx eq to initial Flux-loss ?
mseLoss(regressionModel, W, b, x, ys) ≈ # '≈' = is approximately equal ?
fluxMseLoss(fluxRegressionModel, x32', ys32') ? ":)" : ":("
# ================================================================================
plot(title = "As 2.3 plus Flux-Neural-Net OLS-Regression", xlims=(-4, 4), ylims=(-9, 14))
#--------------------------------------------------------------------------------
# plot of generating function
plot!(x, y, linestyle = :dash, linewidth = 2, label = "f(x) = 3.0 .* x .+ 2.0 (Generating Function)", xlabel = "x", ylabel= "y")
#--------------------------------------------------------------------------------
# plot of data
plot!(x, ys, seriestype = :scatter, label = " (x, y) = Data", xlabel = "x", ylabel= "y")
#---------------------------------------------------------------------------------
# plot of classical linear univariate regression line
plot!(x, yHat, seriestype=:line, linewidth=2, label ="E(Y|x) = $bHat .* x .+ $cHat (Classical OLS)")
#--------------------------------------------------------------------------------
# plot of GLM-regression line
plot!(x, yHat, seriestype=:line, linestyle=:dash, linewidth = 2, label ="E(Y|x) = $bHat .* x .+ $cHat (GLM-Regression)")
#--------------------------------------------------------------------------------
# plot of gradient-descent OLS-regression line
plot!(x, regressionModel(W, b, x), seriestype=:line, linestyle=:dash, linewidth = 2,label ="E(Y|x) = $slope .* x .+ $constant (Gradient Descent)")
#---------------------------------------------------------------------------------
# plot of neural-net OLS-regression line
plot!(x, fluxRegressionModel(x32')', linewidth = 2, linestyle=:dash, label ="E(Y|x) = $fluxWeight .* x .+ $fluxBias (FluxNeuralNet)")
#---------------------------------------------------------------------------------
annotate!(2.3, -5.8, "r(X, Y) = $rxy", 10)
annotate!(2.07, -7, "r(E(Y|x), Y) = $ryHaty", 10)
annotate!(2.4, -8.2, "mse = $mse", 10)
# ================================================================================
end # let
# ╔═╡ 0d3b93ca-e5cd-44db-a537-d027336fae3f
md"
---
##### References
- **Flux Overview: Fitting A Straight Line**; [http://fluxml.ai/Flux.jl/stable/models/overview/](http://fluxml.ai/Flux.jl/stable/models/overview/); last visit 2023/0529
- **Flux Tutorial: Linear Regression**; [http://fluxml.ai/Flux.jl/stable/tutorials/linear_regression/](http://fluxml.ai/Flux.jl/stable/tutorials/linear_regression/); last visit 2023/05/29
"
# ╔═╡ ab48cb8c-da35-4de3-8d2b-c977d6b7e773
md"
---
##### end of ch. 2.1.4
"
# ╔═╡ a1274c46-2010-498a-bd8b-ddc2b3cab34f
md"
====================================================================================
This is a **draft** under the Attribution-NonCommercial-ShareAlike 4.0 International **(CC BY-NC-SA 4.0)** license. Comments, suggestions for improvement and bug reports are welcome: **claus.moebus(@)uol.de**
====================================================================================
"
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
CSV = "~0.10.10"
DataFrames = "~1.5.0"
Flux = "~0.13.16"
GLM = "~1.8.3"
Plots = "~1.38.12"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.9.0"
manifest_format = "2.0"
project_hash = "e5d321c7ed1ce094af1741950b376bfcba7e7b65"
[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "16b6dbc4cf7caee4e1e75c49485ec67b667098a0"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.3.1"
weakdeps = ["ChainRulesCore"]
[deps.AbstractFFTs.extensions]
AbstractFFTsChainRulesCoreExt = "ChainRulesCore"
[[deps.Accessors]]
deps = ["Compat", "CompositionsBase", "ConstructionBase", "Dates", "InverseFunctions", "LinearAlgebra", "MacroTools", "Requires", "Test"]
git-tree-sha1 = "2b301c2388067d655fe5e4ca6d4aa53b61f895b4"
uuid = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
version = "0.1.31"
[deps.Accessors.extensions]
AccessorsAxisKeysExt = "AxisKeys"
AccessorsIntervalSetsExt = "IntervalSets"
AccessorsStaticArraysExt = "StaticArrays"
AccessorsStructArraysExt = "StructArrays"
[deps.Accessors.weakdeps]
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
git-tree-sha1 = "76289dc51920fdc6e0013c872ba9551d54961c24"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.6.2"
weakdeps = ["StaticArrays"]
[deps.Adapt.extensions]
AdaptStaticArraysExt = "StaticArrays"
[[deps.ArgCheck]]
git-tree-sha1 = "a3a402a35a2f7e0b87828ccabbd5ebfbebe356b4"
uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197"
version = "2.3.0"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[deps.Atomix]]
deps = ["UnsafeAtomics"]
git-tree-sha1 = "c06a868224ecba914baa6942988e2f2aade419be"
uuid = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
version = "0.1.0"
[[deps.BFloat16s]]
deps = ["LinearAlgebra", "Printf", "Random", "Test"]
git-tree-sha1 = "dbf84058d0a8cbbadee18d25cf606934b22d7c66"
uuid = "ab4f0b2a-ad5b-11e8-123f-65d77653426b"
version = "0.4.2"
[[deps.BangBang]]
deps = ["Compat", "ConstructionBase", "InitialValues", "LinearAlgebra", "Requires", "Setfield", "Tables"]
git-tree-sha1 = "54b00d1b93791f8e19e31584bd30f2cb6004614b"
uuid = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
version = "0.3.38"
[deps.BangBang.extensions]
BangBangChainRulesCoreExt = "ChainRulesCore"
BangBangDataFramesExt = "DataFrames"
BangBangStaticArraysExt = "StaticArrays"
BangBangStructArraysExt = "StructArrays"
BangBangTypedTablesExt = "TypedTables"
[deps.BangBang.weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[deps.Baselet]]
git-tree-sha1 = "aebf55e6d7795e02ca500a689d326ac979aaf89e"
uuid = "9718e550-a3fa-408a-8086-8db961cd8217"
version = "0.1.1"
[[deps.BitFlags]]
git-tree-sha1 = "43b1a4a8f797c1cddadf60499a8a077d4af2cd2d"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.7"
[[deps.Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "19a35467a82e236ff51bc17a3a44b69ef35185a2"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+0"
[[deps.CEnum]]
git-tree-sha1 = "eb4cb44a499229b3b8426dcfb5dd85333951ff90"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.4.2"
[[deps.CSV]]
deps = ["CodecZlib", "Dates", "FilePathsBase", "InlineStrings", "Mmap", "Parsers", "PooledArrays", "PrecompileTools", "SentinelArrays", "Tables", "Unicode", "WeakRefStrings", "WorkerUtilities"]
git-tree-sha1 = "ed28c86cbde3dc3f53cf76643c2e9bc11d56acc7"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
version = "0.10.10"
[[deps.CUDA]]
deps = ["AbstractFFTs", "Adapt", "BFloat16s", "CEnum", "CUDA_Driver_jll", "CUDA_Runtime_Discovery", "CUDA_Runtime_jll", "CompilerSupportLibraries_jll", "ExprTools", "GPUArrays", "GPUCompiler", "KernelAbstractions", "LLVM", "LazyArtifacts", "Libdl", "LinearAlgebra", "Logging", "Preferences", "Printf", "Random", "Random123", "RandomNumbers", "Reexport", "Requires", "SparseArrays", "SpecialFunctions", "UnsafeAtomicsLLVM"]
git-tree-sha1 = "280893f920654ebfaaaa1999fbd975689051f890"
uuid = "052768ef-5323-5732-b1bb-66c8b64840ba"
version = "4.2.0"
[[deps.CUDA_Driver_jll]]
deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"]
git-tree-sha1 = "498f45593f6ddc0adff64a9310bb6710e851781b"
uuid = "4ee394cb-3365-5eb0-8335-949819d2adfc"
version = "0.5.0+1"
[[deps.CUDA_Runtime_Discovery]]
deps = ["Libdl"]
git-tree-sha1 = "bcc4a23cbbd99c8535a5318455dcf0f2546ec536"
uuid = "1af6417a-86b4-443c-805f-a4643ffb695f"
version = "0.2.2"
[[deps.CUDA_Runtime_jll]]
deps = ["Artifacts", "CUDA_Driver_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"]
git-tree-sha1 = "5248d9c45712e51e27ba9b30eebec65658c6ce29"
uuid = "76a88914-d11a-5bdc-97e0-2f5a05c973a2"
version = "0.6.0+0"
[[deps.CUDNN_jll]]
deps = ["Artifacts", "CUDA_Runtime_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"]
git-tree-sha1 = "2918fbffb50e3b7a0b9127617587afa76d4276e8"
uuid = "62b44479-cb7b-5706-934f-f13b2eb2e645"
version = "8.8.1+0"
[[deps.Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "CompilerSupportLibraries_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Pkg", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "4b859a208b2397a7a623a03449e4636bdb17bcf2"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.16.1+1"
[[deps.Calculus]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "f641eb0a4f00c343bbc32346e1217b86f3ce9dad"
uuid = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
version = "0.5.1"
[[deps.ChainRules]]
deps = ["Adapt", "ChainRulesCore", "Compat", "Distributed", "GPUArraysCore", "IrrationalConstants", "LinearAlgebra", "Random", "RealDot", "SparseArrays", "Statistics", "StructArrays"]
git-tree-sha1 = "8bae903893aeeb429cf732cf1888490b93ecf265"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "1.49.0"
[[deps.ChainRulesCore]]
deps = ["Compat", "LinearAlgebra", "SparseArrays"]
git-tree-sha1 = "e30f2f4e20f7f186dc36529910beaedc60cfa644"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.16.0"
[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "9c209fb7536406834aa938fb149964b985de6c83"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.1"
[[deps.ColorSchemes]]
deps = ["ColorTypes", "ColorVectorSpace", "Colors", "FixedPointNumbers", "PrecompileTools", "Random"]
git-tree-sha1 = "be6ab11021cd29f0344d5c4357b163af05a48cba"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.21.0"
[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "eb7f0f8307f71fac7c606984ea5fb2817275d6e4"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.4"
[[deps.ColorVectorSpace]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "SpecialFunctions", "Statistics", "TensorCore"]
git-tree-sha1 = "600cc5508d66b78aae350f7accdb58763ac18589"
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
version = "0.9.10"
[[deps.Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "fc08e5930ee9a4e03f84bfb5211cb54e7769758a"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.10"
[[deps.CommonSubexpressions]]
deps = ["MacroTools", "Test"]
git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7"
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
version = "0.3.0"
[[deps.Compat]]
deps = ["UUIDs"]
git-tree-sha1 = "7a60c856b9fa189eb34f5f8a6f6b5529b7942957"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "4.6.1"
weakdeps = ["Dates", "LinearAlgebra"]
[deps.Compat.extensions]
CompatLinearAlgebraExt = "LinearAlgebra"
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.0.2+0"
[[deps.CompositionsBase]]
git-tree-sha1 = "802bb88cd69dfd1509f6670416bd4434015693ad"
uuid = "a33af91c-f02d-484b-be07-31d278c5ca2b"
version = "0.1.2"
weakdeps = ["InverseFunctions"]
[deps.CompositionsBase.extensions]
CompositionsBaseInverseFunctionsExt = "InverseFunctions"
[[deps.ConcurrentUtilities]]
deps = ["Serialization", "Sockets"]
git-tree-sha1 = "96d823b94ba8d187a6d8f0826e731195a74b90e9"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.2.0"
[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "738fec4d684a9a6ee9598a8bfee305b26831f28c"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.5.2"
[deps.ConstructionBase.extensions]
ConstructionBaseIntervalSetsExt = "IntervalSets"
ConstructionBaseStaticArraysExt = "StaticArrays"
[deps.ConstructionBase.weakdeps]
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
[[deps.ContextVariablesX]]
deps = ["Compat", "Logging", "UUIDs"]
git-tree-sha1 = "25cc3803f1030ab855e383129dcd3dc294e322cc"
uuid = "6add18c4-b38d-439d-96f6-d6bc489c04c5"
version = "0.1.3"
[[deps.Contour]]
git-tree-sha1 = "d05d9e7b7aedff4e5b51a029dced05cfb6125781"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.6.2"
[[deps.Crayons]]
git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
version = "4.1.1"
[[deps.DataAPI]]
git-tree-sha1 = "8da84edb865b0b5b0100c0666a9bc9a0b71c553c"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.15.0"
[[deps.DataFrames]]
deps = ["Compat", "DataAPI", "Future", "InlineStrings", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrettyTables", "Printf", "REPL", "Random", "Reexport", "SentinelArrays", "SnoopPrecompile", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"]
git-tree-sha1 = "aa51303df86f8626a962fccb878430cdb0a97eee"
uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
version = "1.5.0"
[[deps.DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "d1fff3a548102f48987a52a2e0d114fa97d730f0"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.13"
[[deps.DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"
[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
[[deps.DefineSingletons]]
git-tree-sha1 = "0fba8b706d0178b4dc7fd44a96a92382c9065c2c"
uuid = "244e2a9f-e319-4986-a169-4d1fe445cd52"
version = "0.1.2"
[[deps.DelimitedFiles]]
deps = ["Mmap"]
git-tree-sha1 = "9e2f36d3c96a820c678f2f1f1782582fcf685bae"
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
version = "1.9.1"
[[deps.DiffResults]]
deps = ["StaticArraysCore"]
git-tree-sha1 = "782dd5f4561f5d267313f23853baaaa4c52ea621"
uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
version = "1.1.0"
[[deps.DiffRules]]
deps = ["IrrationalConstants", "LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"]
git-tree-sha1 = "a4ad7ef19d2cdc2eff57abbbe68032b1cd0bd8f8"
uuid = "b552c78f-8df3-52c6-915a-8e097449b14b"
version = "1.13.0"
[[deps.Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
[[deps.Distributions]]
deps = ["FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsAPI", "StatsBase", "StatsFuns", "Test"]
git-tree-sha1 = "5eeb2bd01e5065090ad591a205d8cad432ae6cb6"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
version = "0.25.93"
[deps.Distributions.extensions]
DistributionsChainRulesCoreExt = "ChainRulesCore"
DistributionsDensityInterfaceExt = "DensityInterface"
[deps.Distributions.weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
[[deps.DocStringExtensions]]
deps = ["LibGit2"]
git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.9.3"
[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
version = "1.6.0"
[[deps.DualNumbers]]
deps = ["Calculus", "NaNMath", "SpecialFunctions"]
git-tree-sha1 = "5837a837389fccf076445fce071c8ddaea35a566"
uuid = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
version = "0.6.8"
[[deps.Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "bad72f730e9e91c08d9427d5e8db95478a3c323d"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.4.8+0"
[[deps.ExprTools]]
git-tree-sha1 = "c1d06d129da9f55715c6c212866f5b1bddc5fa00"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
version = "0.1.9"
[[deps.FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "b57e3acbe22f8484b4b5ff66a7499717fe1a9cc8"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.4.1"
[[deps.FFMPEG_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "PCRE2_jll", "Pkg", "Zlib_jll", "libaom_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "74faea50c1d007c85837327f6775bea60b5492dd"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.4.2+2"
[[deps.FLoops]]
deps = ["BangBang", "Compat", "FLoopsBase", "InitialValues", "JuliaVariables", "MLStyle", "Serialization", "Setfield", "Transducers"]
git-tree-sha1 = "ffb97765602e3cbe59a0589d237bf07f245a8576"
uuid = "cc61a311-1640-44b5-9fba-1b764f453329"
version = "0.2.1"
[[deps.FLoopsBase]]
deps = ["ContextVariablesX"]
git-tree-sha1 = "656f7a6859be8673bf1f35da5670246b923964f7"
uuid = "b9860ae5-e623-471e-878b-f6a53c775ea6"
version = "0.1.1"
[[deps.FilePathsBase]]
deps = ["Compat", "Dates", "Mmap", "Printf", "Test", "UUIDs"]
git-tree-sha1 = "e27c4ebe80e8699540f2d6c805cc12203b614f12"
uuid = "48062228-2e41-5def-b9a4-89aafe57970f"
version = "0.9.20"
[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
[[deps.FillArrays]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"]
git-tree-sha1 = "3cce72ec679a5e8e6a84ff09dd03b721de420cfe"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"