-
Notifications
You must be signed in to change notification settings - Fork 0
/
section6_logistic_regression.jl
3548 lines (2908 loc) · 129 KB
/
section6_logistic_regression.jl
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.46
using Markdown
using InteractiveUtils
# ╔═╡ 661b028c-260c-41f8-9d8a-13cfea4c7e22
using Turing
# ╔═╡ bce03358-19c9-11ed-31d9-5b0929af50b6
begin
using PlutoUI
using StatsPlots
using Plots; default(fontfamily="Computer Modern", framestyle=:box) # LaTex-style
# using Turing
using DataFrames
using StatsFuns: logistic
using Random
using LaTeXStrings
using Logging; Logging.disable_logging(Logging.Warn);
end;
# ╔═╡ 74a2053f-ef53-41df-8afc-997c166e6f67
begin
using RDatasets
# Import the "Default" dataset.
default_df = dataset("ISLR", "Default");
# Show the first six rows of the dataset.
first(default_df, 6)
end
# ╔═╡ 920b9b1f-b56d-465c-bce2-e08530ec4bb4
using StatsBase
# ╔═╡ 0a8fff98-24fd-49d6-a6b2-061e6350350b
TableOfContents()
# ╔═╡ ccc43bd4-2149-4136-87f4-a4d251fc1f7a
md"[**↩ Home**](https://lf28.github.io/BayesianModelling/)
[**↪ Next Chapter**](./section7_glm.html)
"
# ╔═╡ 9810605e-586b-4f38-a43c-4240cb91e154
md"""
# Bayesian logistic regression
"""
# ╔═╡ e752d05f-bc3c-42a4-ac5a-0517637c59b9
md"""
## Frequentist's logistic regression
### The model
Recall linear regression's probabilistic model:
```math
p(y_n|\mathbf{x}_n, \beta_0, \boldsymbol{\beta}_1, \sigma^2) = \mathcal{N}(y_n; \mu(\mathbf{x}_n), \sigma^2),
```
where ``\mu`` is a linear function of the input ``\mathbf{x}_n``
```math
\mu(\mathbf{x}_n) = \beta_0+\mathbf{x}_n^\top \boldsymbol{\beta}_1,
```
and a Gaussian likelihood is assumed for the target ``y_n``.
For binary classifications, ``y_n`` can only take binary choices (assume ``y_n\in \{0,1\}``). To reflect the change, a Bernoulli likelihood seems more suitable. However, a direct replacement of the mean parameter such as
```math
\text{WRONG: }\;\;p(y_n|\mathbf{x}_n, \beta_0, \boldsymbol{\beta}_1) = \texttt{Bernoulli}(y_n; \mu(\mathbf{x}_n))= \begin{cases} \mu(\mathbf{x}_n) & y_n=1\\ 1-\mu(\mathbf{x}_n) & y_n=0\end{cases}
```
would not work, since a Bernoulli distribution's parameter needs to be between 0 and 1 but ``\mu(\mathbf{x})\in \mathbb{R}`` as a linear function is not constrained.
A remedy is to impose a ``\mathbb{R}\rightarrow [0,1]`` function to squeeze an unconstrained input of ``\mu`` to be between 0 and 1. And the logistic function does exactly the trick. The function is defined as
```math
\texttt{logistic}(\mu) \triangleq \sigma(\mu) = \frac{1}{1+e^{-\mu}}.
```
We use ``\sigma`` as a shorthand notation for the logistic transformation. The function is plotted below:
$(begin
plot(logistic, xlabel=L"\mu", ylabel="", label=L"\texttt{logistic}(\mu)", legend=:topleft, lw=2, size=(450,300))
end)
Note that no matter what the input is, the output is always between 0 and 1, which is exactly what we need.
"""
# ╔═╡ 793a70b2-af69-4b4c-b4c0-8eef3b4654e9
md"""
To put the above steps together, we have the frequentist's probabilistic model for logistic regression:
!!! information "Logistic regression"
```math
p(y_n|\mathbf{x}_n, \boldsymbol{\beta}) = \texttt{Bernoulli}(y_n; \sigma(\mu_n)),
```
where ``\mu_n= \beta_0 + \mathbf{x}_n^\top\boldsymbol{\beta}_1``.
"""
# ╔═╡ af482903-2975-48d7-a4fe-4cebfa337a2b
md"""
### Estimation
A logistic regression model can be fit again by maximising the likelihood function
```math
\hat{\boldsymbol{\beta}} \leftarrow \arg\max p(\mathbf{y}|\mathbf{X}, \boldsymbol{\beta}).
```
Since the optimization problem has no closed-form analytical solution, an iterative gradient-based optimisation algorithm such as gradient descent is usually used to find the MLE estimator. In Julia, logistic regressions can be fit by using `GLM.jl`.
"""
# ╔═╡ ada4ad28-358e-4144-9d5c-f3b1d27deff1
md"""
### A toy example
"""
# ╔═╡ 7a189076-f53f-48ed-ace2-ffbcc287ff6f
begin
D1 = [
7 4;
5 6;
8 6;
9.5 5;
9 7
]
D2 = [
2 3;
3 2;
3 6;
5.5 4.5;
5 3;
]
D = [D1; D2]
targets = [ones(5); zeros(5)]
AB = [1.5 8; 10 1.9]
end;
# ╔═╡ 1068259e-a7f6-4a56-b526-59e080c54d27
begin
using GLM
glm_fit = glm([ones(size(D)[1]) D], targets, Bernoulli(), LogitLink())
end
# ╔═╡ 60a5cad4-c676-4334-8cbe-47877a68943f
md"""
We have plotted the fit model below. It can be observed the fitted regression function, defined as
```math
p(y_n=1|\mathbf{x}_n, \hat\beta_0, \hat{\boldsymbol{\beta}}_1) = \hat{\sigma}(\mu_n)= \frac{1}{1+\exp(- \hat\beta_0 - \mathbf{x}_n^\top\hat{\boldsymbol{\beta}}_1)}
```
is a very sharp S-shaped surface valued between 0 and 1. Towards the top right corner of the input space, the prediction is closer to 1.0, entailing the output ``y_n`` is more likely to be positive (or class 1). And the model also implies a linear decision boundary as expected.
"""
# ╔═╡ ccda7f54-67ee-4d17-a16c-6f8597447d1e
md"""
#### Pathological frequentist's prediction
One thing worth noting is the sharpness of the prediction surface. Data points on one side of the thin decision boundary are all indistinguishably predicted with either ``p(y_n=1|\ldots)=1,`` or ``0``. Such a clean-cut prediction is counter-intuitive. It should be naturally expected that
* predictions near the boundary should be more uncertain than those further away
* predictions further away from the observed data (marked as ```A, B``` in the figure) should be more uncertain.
We will see next how Bayesian approaches the problem and provides us with an alternative prediction which is more reasonable.
"""
# ╔═╡ e2918ef9-7f86-4d3b-93cb-65b8b5f48987
md"""
## Bayesian logistic regression
The Bayesian model reuses the likelihood function for ``\mathbf{y}``, but also imposes a prior on the regression parameter ``\beta_0, \boldsymbol{\beta}_1``. The final model is very similar to the linear regression equivalent, where we assume Gaussian priors for the regression parameter ``\beta_0, \boldsymbol{\beta}_1``.
!!! infor "Bayesian logistic regression"
```math
\begin{align}
\text{Priors: }\;\;\;\;\;\;\beta_0 &\sim \mathcal{N}(m_0^{\beta_0}, v_0^{\beta_0})\\
\boldsymbol{\beta}_1 &\sim \mathcal{N}(\mathbf{m}_0^{{\beta}_1}, \mathbf{V}_0^{{\beta}_1})\\
\text{Likelihood: }\;\;\text{for } n &= 1,2,\ldots, N:\\
\mu_n &=\beta_0 + \boldsymbol{\beta}_1^\top\mathbf{x}_n \\
\sigma_n &= \texttt{logistic}(\mu_n)\\
y_n &\sim \texttt{Bernoulli}(\sigma_n).
\end{align}
```
"""
# ╔═╡ 8b73706e-fe00-4489-8095-b3ec4528c58b
md"""
### Implementation in `Julia`
Model translation is straightforward.
"""
# ╔═╡ 6d2af85d-8c9e-4da7-8a38-6c0df102f954
begin
@model function bayesian_logistic_reg(X, y; v₀=10^2, V₀ = 10^2)
# priors
β0 ~ Normal(0, sqrt(v₀))
nfeatures = size(X)[2]
β ~ MvNormal(zeros(nfeatures), sqrt(V₀))
# Likelihood
μs = β0 .+ X * β
# logistic transformations
σs = logistic.(μs)
for i in eachindex(y)
y[i] ~ Bernoulli(σs[i])
end
return (; σs)
end
end;
# ╔═╡ 8a8d8eb9-9cea-43f0-9607-9d3ca908c370
md"Next, we use `Turing` to do Bayesian logistic regression analysis on the toy data example introduced earlier."
# ╔═╡ 41a3984c-aee4-494f-8ba2-69c0274185ed
chain_logreg_sim_data = let
sample(
bayesian_logistic_reg(D, targets; v₀=5^2),
NUTS(),
MCMCThreads(),
2000,
3
)
end;
# ╔═╡ e1e43074-9e5f-4516-bf0d-0ce4209afb6c
summarystats(chain_logreg_sim_data)
# ╔═╡ 15b2d945-4e78-4c41-9712-5d623b15914e
describe(chain_logreg_sim_data)[2]
# ╔═╡ 5e5fdd62-ac1c-4ef6-a5a4-64ffe441b496
plot(chain_logreg_sim_data)
# ╔═╡ bdcc9726-d1fd-4d34-987e-925e1a96e58f
md"""
### Bayesian prediction
"""
# ╔═╡ fd9d6126-d764-40f5-9a4d-fda49a0962a9
md"""
To make a prediction at a new input location ``\mathbf{x}_\ast``, we can use the `predict()` or `generated_quantities()` method from `Turing`.
The procedure starts with initialising a `Turing` model with `missing` prediction targets ``\mathbf{y}_\ast``. Then use either `predict()` or `generated_quantities()` to find the Monte Carlo approximated prediction. Check the code below for an example.
"""
# ╔═╡ 69258680-fc21-40ca-998a-1a81279342ea
begin
# randomly generated test dataset
N_test = 5
D_test = rand(N_test, 2) * 10
pred_model = bayesian_logistic_reg(D_test, Vector{Union{Missing, Float64}}(undef, size(D_test)[1]))
y_preds = predict(pred_model, chain_logreg_sim_data)
end;
# ╔═╡ be4d04ff-9ae8-40c6-ae7b-9ec29cd23b43
mixeddensity(y_preds[:,1:1,:], size(100,100))
# ╔═╡ a84e1f2f-fdde-432f-89d3-265480ef9f53
md"""
## Prediction comparison
"""
# ╔═╡ 6aaa775e-b2c4-4943-8860-9aff2e4a725c
md"""
### Why does Bayesian predict better?
Recall to make a prediction at a new input ``\mathbf{x}_\ast``, the Bayesian approach aims at computing its posterior (predictive) distribution, which is computed via an integration (and then approximated by the Monte Carlo method):
```math
\begin{align}
p_{\text{Bayes}}(y_\ast=1 |\mathbf{x}_\ast, \mathcal{D}) &= \int p(y_\ast=1|\boldsymbol{\beta})p(\boldsymbol{\beta}|\mathcal{D}) \mathrm{d}\boldsymbol{\beta}\\
&= \int \sigma_{\mathbf{x}_\ast}(\boldsymbol{\beta}) p(\boldsymbol{\beta}|\mathcal{D}) \mathrm{d}\boldsymbol{\beta}\\
&\approx \frac{1}{R} \sum_{r=1}^R \sigma^{(r)}_{\mathbf{x}_\ast},
\end{align}
```
where, to avoid cluttered notations, we have assumed ``\boldsymbol{\beta}^\top = [\beta_0, \boldsymbol{\beta}_1]``, and
```math
\sigma^{(r)}_{\mathbf{x}_\ast} = \frac{1}{1+\exp\{\beta^{(r)}_0 +\mathbf{x}_\ast^\top \boldsymbol{\beta}_1^{(r)}\}}.
```
Compared with the frequentist's point prediction
```math
p_{\text{freq}}(y_{\ast}=1|\mathbf{x}_\ast, \hat{\boldsymbol{\beta}}) = \hat{\sigma}_{\mathbf{x}_\ast}(\hat{\boldsymbol{\beta}})= \frac{1}{1+\exp(- \hat\beta_0 - \mathbf{x}_\ast^\top\hat{\boldsymbol{\beta}}_1)},
```
the Bayesian prediction is an *ensemble* method. To be more specific, there are in total ``R`` predictions made based on the ``R`` MCMC samples ``\{\beta_0^{(r)}, \boldsymbol{\beta}_1^{(r)}\}_{r=1}^R``. And the Bayesian provides the final verdict by averaging over the ``R`` individual models.
The idea is illustrated below in a figure in which the posterior prediction mean (thick green line) is plotted with some of the ensemble models (lighter grey lines). The Bayesian approach by averaging over multiple models provides a more reasonable over-fitting proof prediction.
"""
# ╔═╡ 68b88445-fb94-4d26-a723-234b3045ca54
begin
p1_ = Plots.plot(D1[:,1], D1[:,2], xlabel=L"$x_1$", ylabel=L"$x_2$", label="class 1", seriestype=:scatter, markersize = 4, legend = :outerright, title="Binary classification", xlim=[0, 11], ylim=[0, 9.5])
Plots.plot!(p1_, D2[:,1], D2[:,2], label="class 2", seriestype=:scatter, markersize = 4)
Plots.plot!(p1_, AB[1:1, 1], AB[1:1, 2], label="", seriestype=:scatter, markersize = 3, markershape =:x, annotate = [(AB[1,1]-0.8, AB[1,2], "A"), (AB[2,1]-0.8, AB[2,2], "B")], markerstrokewidth = 3, markercolor=:red)
Plots.plot!(p1_, AB[2:2, 1], AB[2:2,2], seriestype=:scatter, label="", markersize = 3, markershape =:x, markerstrokewidth = 3, markercolor=:red)
# Plots.plot!(size=(500,500))
end;
# ╔═╡ 39c43d27-6806-4fb6-a0e8-5f41ae0ee94e
md"""
## A real-world example
In this section, we apply Bayesian logistic regression analysis to a real-world dataset. The data used here is described in the book [Introduction to Statistical Learning](https://hastie.su.domains/ISLR2/ISLRv2_website.pdf). The dataset (referred to as `Default`) is about customer default records for a credit card company.
"""
# ╔═╡ 436f0628-ee73-4045-82f3-6d785b5ba51f
md"""
#### Step 1: import the dataset
"""
# ╔═╡ e47c4ad6-17e4-4265-bee2-738b81e61696
md"""
#### Step 2: pre-process the dataset
"""
# ╔═╡ 8b56260f-2e42-4a89-a1c0-bf856b9f75d3
md"""
By checking the raw data, we find the `Default` and `Student` variables are of `string` type. We need to first transform them into binary data types.
"""
# ╔═╡ 40db5082-3558-4fd4-ab47-1127f6d67e38
begin
# transform the non-numerical features to numerical
default_df[!, :DefaultNum] = map((x) -> x.Default == "Yes" ? true : false, eachrow(default_df))
default_df[!, :StudentNum] = map((x) -> x.Student == "Yes" ? true : false, eachrow(default_df))
end;
# ╔═╡ fbcdbc4e-f55b-4bf8-a10d-42f2627dbfdb
describe(default_df)
# ╔═╡ 8c73a18f-55a1-4740-8795-5bbb6ff425de
md"The two numerical features `Balance` and `Income` are with very different mean and value ranges. It is in general a good idea to standardize them such that the transformed data are with zero mean and unit variance. By standardising the features, the prior's variances, *i.e. ``\mathbf{V}_0^{\boldsymbol{\beta}}``*, are also easier to be specified, since all the features are of the same scale.
"
# ╔═╡ 0ca3c752-627f-40ce-ac6c-d10fc90d4663
begin
XX, yy = Matrix(default_df[!, [:Balance, :Income, :StudentNum]]), default_df[!, :DefaultNum]
feature_scalar = fit(ZScoreTransform, XX[:, 1:2], dims=1)
XX[:, 1:2] .= StatsBase.transform(feature_scalar, XX[:, 1:2])
end;
# ╔═╡ a84de1b9-3c27-4b63-822f-f454b7d3098b
md"""
#### Step 4: making inference with `Turing`
"""
# ╔═╡ b25a3f92-f3ad-4c05-961d-2f69d39d98c3
md"It is, in general, a good idea to fit the data with the frequentist model first and use the estimation as a reference."
# ╔═╡ 4d9c1339-c38f-4705-9c00-2c99228da905
begin
default_df_new = DataFrame([XX yy], [:Balance, :Income, :StudentNum, :Default])
glm(@formula(Default ~ Balance +Income+StudentNum), default_df_new, Bernoulli(), LogitLink())
end
# ╔═╡ bd11a4c4-1f2b-4d3c-8e3f-8382dd9f3b3c
md"Next, we use the Bayesian logistic regression model implemented in `Turing` to do the inference."
# ╔═╡ 244ba3cf-63ba-4501-8e88-f71c95c15a7c
chain_default = let
chain = sample(
bayesian_logistic_reg(XX, yy; v₀=1, V₀ =1),
NUTS(),
MCMCThreads(),
2000,
3
)
replacenames(chain, Dict(["β[1]" => "Balance", "β[2]" => "Income", "β[3]" => "Student"]))
end;
# ╔═╡ c83f3735-6aba-4183-b010-5f21cd2ff968
describe(chain_default)[1]
# ╔═╡ 30d1520d-d301-422a-81e1-a40122d5e3fa
md"It can be observed that the Bayesian inference's posterior means are similar to the frequentist's estimation, which implies our prior choice is reasonably weak."
# ╔═╡ 53c5b238-61fd-4ef3-9194-b076b3434b16
describe(chain_default)[2]
# ╔═╡ 0c34decf-ee35-4f9d-bf83-cfff75f8ff3b
md"The Bayesian's credible interval also tells us the intercept, `Balance`, and `Student` are significant predictors (their 95% credible intervals are either strictly positive or negative). But `Income` factor's impact on predicting the log-ratio of `Default` is not statistically significant, which is in agreement with the Frequentist's analysis. The same result can also be observed from the density plots."
# ╔═╡ f092a42e-16e9-45ac-88cd-133a92402ff6
plot(chain_default)
# ╔═╡ 59245146-ef30-4df1-9ac3-776871e5d062
md"""
## Appendix
"""
# ╔═╡ ea897f9a-89ff-421c-989a-b5f395cec705
begin
prediction(ws, x1, x2) = mean(logistic.(ws * [1.0, x1, x2]))
end
# ╔═╡ 78d6fe62-432b-49f3-b38f-0f6f6f5a04ed
chain_array = let
model_ex1 = bayesian_logistic_reg(D, targets)
Random.seed!(100)
chain=sample(model_ex1, NUTS(), 1000, discard_initial=100, thinning=10)
Array(chain)
end;
# ╔═╡ 2a632fe1-698f-4265-8509-453ee7827ae6
let
p_bayes_pred = Plots.plot(D1[:, 1], D1[:,2], seriestype=:scatter, markersize = 5, markercolor=1, label="class 1", legend=:topright, xlim=[-1, 11], ylim=[-1,11])
Plots.plot!(p_bayes_pred, D2[:, 1], D2[:,2], seriestype=:scatter, markersize = 5, markercolor=2, label="class 2")
mean_pred = mean(chain_array, dims=1)[:]
b, k = -chain_array[1, 1:2] ./ chain_array[1, 3]
plot!(-2:12, (x) -> k*x+b, lw=0.1, lc=:gray, label=L"\sigma^{(r)}\sim p(\sigma|\mathcal{D})")
for i in 2:60
b, k = -chain_array[i, 1:2] ./ chain_array[i, 3]
plot!(-2:12, (x) -> k*x+b, lw=0.1, lc=:gray, label="")
end
b, k = - mean_pred[1:2] ./ mean_pred[3]
plot!(-2:12, (x) -> k*x+b, lw=3, lc=3, label=L"\texttt{mean}(\sigma^{(r)})")
p_bayes_pred
end
# ╔═╡ c92f0602-9a6c-4e2c-8a28-2a870d332fe4
begin
p1 = Plots.plot(D1[:,1], D1[:,2], xlabel=L"x_1", ylabel=L"x_2", label="class 1", seriestype=:scatter, markersize = 4, legend = :bottomright, title="Binary classification", ratio =1.0)
Plots.plot!(p1, D2[:,1], D2[:,2], label="class 2", seriestype=:scatter, markersize = 4)
# plot!((x)-> -x, lw=4, lc=:gray, label="Decision boundary", ls=:dash, legend=:outerright)
end;
# ╔═╡ f42b1665-df4b-4181-be03-71ccc3dbfae2
md"""
In a supervised learning setting, we are predicting the target ``y_n`` based on ``n``-the sample's features ``\mathbf{x}_n``.
For example, in regression analysis, the target or labels ``y_n`` are assumed to be real-valued, i.e. ``y_n\in \mathbb{R}``. For example, in the ```Advertising``` example, the target ```sales``` of a particular problem is real-valued.
The targets ``y_n``, however, can take value other than the real number. For example, a very common example is ``y_n`` can take binary choices, say ``y_n \in \{\texttt{true}, \texttt{false}\}``. Such a supervised learning task is usually referred to as *binary* **classification**. For example, given a subject's age, gender, and other measurements, how likely he/she will survive a pandemic? The outcome is binary here: either survive or not. Also, check the following plot for an example of binary classification with 2-dimensional input.
$(begin
p1
end)
A popular statistical model for binary classification is *logistic regression*, in which we aim at drawing a linear decision boundary to classify the input (as shown in the figure above). In this chapter, we are going to investigate how to do Bayesian logistic regression. We will first review the frequentist's logistic model and then extends it to a Bayesian approach. The two approaches will be compared and the benefit of the Bayesian approach should become evident when we compare their prediction on unseen input data.
"""
# ╔═╡ 82fc962c-a172-47ef-a86c-fa49bace3567
p_freq_1= let
freq_coef = coef(glm_fit)'
# prediction(ws, x1, x2) = logistic(ws * [1.0, x1, x2])
p_freq_1 = Plots.contour(2:0.1:9, 2:0.1:8, (x, y) -> prediction(freq_coef, x, y), fill=false, connectgaps=true, levels=8, line_smoothing = 0.85, legend=:left, title="Frequentist Prediction", c=:roma, ratio=1.0, xlabel=L"x_1", ylabel=L"x_2")
Plots.plot!(p_freq_1, D1[:, 1], D1[:,2], seriestype=:scatter, markersize = 3, markercolor=1, label="class 1")
Plots.plot!(p_freq_1, D2[:, 1], D2[:,2], seriestype=:scatter, markersize = 3, markercolor=2, label="class 2")
Plots.plot!(p_freq_1, AB[1:2, 1], AB[1:2, 2], label="", seriestype=:scatter, markersize = 2, markershape =:star4, annotate = [(AB[1,1], AB[1,2], text("A", :top,:red, 9)), (AB[2,1], AB[2,2], text("B", :top, :red, 9))], markerstrokewidth = 1, markercolor=:red)
markers = [2, 5, 6, 9]
for m in markers
p0 = round(prediction(freq_coef, D[m, 1], D[m, 2]), digits=2)
annotate!(D[m, 1], D[m,2], text(L"\hat{\sigma}="*"$(p0)", :bottom, 10))
end
for i in 1:2
p0 = round(prediction(freq_coef, AB[i, 1], AB[i, 2]), digits=2)
annotate!(AB[i, 1], AB[i,2], text(L"\hat{\sigma}="*"$(p0)", :bottom, :red, 10))
end
p_freq_1
end;
# ╔═╡ cd76fa94-d0d7-43bb-8221-2a4dafa8af53
p_freq_1
# ╔═╡ 3e45f16f-ea6c-4960-98b7-1e642fb919c1
p_bayes_1 = let
p_bayes_1 = Plots.contour(2:0.1:9, 2:0.1:8, (x, y) -> prediction(chain_array, x, y), fill=false, connectgaps=true, levels=8, line_smoothing = 0.85, legend=:left, title="Bayesian Prediction", c=:roma, ratio=1.0, xlabel=L"x_1", ylabel=L"x_2")
Plots.plot!(p_bayes_1, D1[:, 1], D1[:,2], seriestype=:scatter, markersize = 3, markercolor=1, label="class 1")
Plots.plot!(p_bayes_1, D2[:, 1], D2[:,2], seriestype=:scatter, markersize = 3, markercolor=2, label="class 2")
Plots.plot!(p_bayes_1, AB[1:2, 1], AB[1:2, 2], label="", seriestype=:scatter, markersize = 2, markershape =:star4, annotate = [(AB[1,1], AB[1,2], text("A", :top,:red, 9)), (AB[2,1], AB[2,2], text("B", :top, :red, 9))], markerstrokewidth = 1, markercolor=:red)
markers = [2, 5, 6, 9]
for m in markers
p0 = round(prediction(chain_array, D[m, 1], D[m, 2]), digits=2)
annotate!(D[m, 1], D[m,2], text(L"\hat{\sigma}="*"$(p0)", :bottom, 10))
end
for i in 1:2
p0 = round(prediction(chain_array, AB[i, 1], AB[i, 2]), digits=2)
annotate!(AB[i, 1], AB[i,2], text(L"\hat{\sigma}="*"$(p0)", :bottom, :red, 10))
end
p_bayes_1
end;
# ╔═╡ 44ccb675-a657-4fe8-934f-ddf29cb78f74
md"""
We have discussed the undesired properties of the Frequentist's method. The prediction lack nuance to account for the differences between the prediction locations. The prediction is very black and white: all data points are either predicted with 100% or 0% being positive.
Now we move on to check what the Bayesian prediction surface looks like. Recall that Bayesian inference always aims at computing the posterior of the quantity of interest. In this case, what we are interested in is the predictive distribution on a new input location ``\mathbf{x}_\ast``:
```math
p(y_\ast=1|\mathbf{x}_\ast, \mathcal{D}).
```
The contour plot of the Bayesian predictive distribution is listed below.
$(begin
p_bayes_1
end)
It can be observed that the Bayesian prediction is more nuanced compared with the clean-cut frequentist's prediction.
* data points closer to the decision boundary are correctly predicted with less confidence
* data points located further away from the observed input data are predicted with some reasonable level of uncertainty.
The surface plots of the two predictions are listed below for a more direct visual comparison. The Bayesian prediction is more natural and matches people's expectations.
"""
# ╔═╡ 8a21c570-9bfe-4f66-9157-1b0dc4028ef4
p_freq_surface_1 = let
freq_coef = coef(glm_fit)'
Plots.surface(0:0.1:10, 0:0.1:10, (x, y) -> prediction(freq_coef, x, y), legend=:best, title="Frequentist Prediction", c=:roma, ratio=1.0, xlabel=L"x_1", ylabel=L"x_2", zlabel=L"p(y=1|\ldots)")
end;
# ╔═╡ 0c70c6be-518b-4ba4-bd69-cc34d2217077
p_freq_surface_1
# ╔═╡ f9b3916a-d4b2-4e6b-9a7d-be077fd45ac0
p_bayes_surface_1 = let
Plots.surface(0:0.1:10, 0:0.1:10, (x, y) -> prediction(chain_array, x, y), legend=:best, title="Bayesian Prediction", c=:roma, ratio=1.0, xlabel=L"x_1", ylabel=L"x_2", zlabel=L"p(y=1|\ldots)")
end;
# ╔═╡ 922704a0-b0c9-4fe0-a0fb-3ab58a7f01d9
plot(p_freq_surface_1, p_bayes_surface_1, size=(800,400))
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
[compat]
DataFrames = "~1.3.4"
GLM = "~1.8.0"
LaTeXStrings = "~1.3.0"
Plots = "~1.40.8"
PlutoUI = "~0.7.39"
RDatasets = "~0.7.7"
StatsBase = "~0.34.3"
StatsFuns = "~1.3.0"
StatsPlots = "~0.15.1"
Turing = "~0.34.1"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.11.0"
manifest_format = "2.0"
project_hash = "1dcdbf5079b89822ff3c58129edd7898184ff907"
[[deps.ADTypes]]
git-tree-sha1 = "eea5d80188827b35333801ef97a40c2ed653b081"
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
version = "1.9.0"
[deps.ADTypes.extensions]
ADTypesChainRulesCoreExt = "ChainRulesCore"
ADTypesEnzymeCoreExt = "EnzymeCore"
[deps.ADTypes.weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
[[deps.AbstractFFTs]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "d92ad398961a3ed262d8bf04a1a2b8340f915fef"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "1.5.0"
weakdeps = ["ChainRulesCore", "Test"]
[deps.AbstractFFTs.extensions]
AbstractFFTsChainRulesCoreExt = "ChainRulesCore"
AbstractFFTsTestExt = "Test"
[[deps.AbstractMCMC]]
deps = ["BangBang", "ConsoleProgressMonitor", "Distributed", "FillArrays", "LogDensityProblems", "Logging", "LoggingExtras", "ProgressLogging", "Random", "StatsBase", "TerminalLoggers", "Transducers"]
git-tree-sha1 = "c732dd9f356d26cc48d3b484f3fd9886c0ba8ba3"
uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
version = "5.5.0"
[[deps.AbstractPPL]]
deps = ["AbstractMCMC", "Accessors", "DensityInterface", "Random"]
git-tree-sha1 = "6380a9a03a4207bac53ac310dd3a283bb4df54ef"
uuid = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
version = "0.8.4"
[[deps.AbstractPlutoDingetjes]]
deps = ["Pkg"]
git-tree-sha1 = "6e1d2a35f2f90a4bc7c2ed98079b2ba09c35b83a"
uuid = "6e696c72-6542-2067-7265-42206c756150"
version = "1.3.2"
[[deps.AbstractTrees]]
git-tree-sha1 = "2d9c9a55f9c93e8887ad391fbae72f8ef55e1177"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
version = "0.4.5"
[[deps.Accessors]]
deps = ["CompositionsBase", "ConstructionBase", "InverseFunctions", "LinearAlgebra", "MacroTools", "Markdown"]
git-tree-sha1 = "b392ede862e506d451fc1616e79aa6f4c673dab8"
uuid = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
version = "0.1.38"
[deps.Accessors.extensions]
AccessorsAxisKeysExt = "AxisKeys"
AccessorsDatesExt = "Dates"
AccessorsIntervalSetsExt = "IntervalSets"
AccessorsStaticArraysExt = "StaticArrays"
AccessorsStructArraysExt = "StructArrays"
AccessorsTestExt = "Test"
AccessorsUnitfulExt = "Unitful"
[deps.Accessors.weakdeps]
AxisKeys = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
git-tree-sha1 = "6a55b747d1812e699320963ffde36f1ebdda4099"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "4.0.4"
weakdeps = ["StaticArrays"]
[deps.Adapt.extensions]
AdaptStaticArraysExt = "StaticArrays"
[[deps.AdvancedHMC]]
deps = ["AbstractMCMC", "ArgCheck", "DocStringExtensions", "InplaceOps", "LinearAlgebra", "LogDensityProblems", "LogDensityProblemsAD", "ProgressMeter", "Random", "Requires", "Setfield", "SimpleUnPack", "Statistics", "StatsBase", "StatsFuns"]
git-tree-sha1 = "1da0961a400c28d1e5f057e922ff75ec5d6a5747"
uuid = "0bf59076-c3b1-5ca4-86bd-e02cd72cde3d"
version = "0.6.2"
[deps.AdvancedHMC.extensions]
AdvancedHMCCUDAExt = "CUDA"
AdvancedHMCMCMCChainsExt = "MCMCChains"
AdvancedHMCOrdinaryDiffEqExt = "OrdinaryDiffEq"
[deps.AdvancedHMC.weakdeps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
[[deps.AdvancedMH]]
deps = ["AbstractMCMC", "Distributions", "FillArrays", "LinearAlgebra", "LogDensityProblems", "Random", "Requires"]
git-tree-sha1 = "66ac4c7b320d2434f04d48116db02e73e6dabc8b"
uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170"
version = "0.8.3"
weakdeps = ["DiffResults", "ForwardDiff", "MCMCChains", "StructArrays"]
[deps.AdvancedMH.extensions]
AdvancedMHForwardDiffExt = ["DiffResults", "ForwardDiff"]
AdvancedMHMCMCChainsExt = "MCMCChains"
AdvancedMHStructArraysExt = "StructArrays"
[[deps.AdvancedPS]]
deps = ["AbstractMCMC", "Distributions", "Random", "Random123", "Requires", "SSMProblems", "StatsFuns"]
git-tree-sha1 = "5dcd3de7e7346f48739256e71a86d0f96690b8c8"
uuid = "576499cb-2369-40b2-a588-c64705576edc"
version = "0.6.0"
weakdeps = ["Libtask"]
[deps.AdvancedPS.extensions]
AdvancedPSLibtaskExt = "Libtask"
[[deps.AdvancedVI]]
deps = ["ADTypes", "Bijectors", "DiffResults", "Distributions", "DistributionsAD", "DocStringExtensions", "ForwardDiff", "LinearAlgebra", "ProgressMeter", "Random", "Requires", "StatsBase", "StatsFuns", "Tracker"]
git-tree-sha1 = "c217a9b531b4b752eb120a9f820527126ba68fb9"
uuid = "b5ca4192-6429-45e5-a2d9-87aec30a685c"
version = "0.2.8"
[deps.AdvancedVI.extensions]
AdvancedVIEnzymeExt = ["Enzyme"]
AdvancedVIFluxExt = ["Flux"]
AdvancedVIReverseDiffExt = ["ReverseDiff"]
AdvancedVIZygoteExt = ["Zygote"]
[deps.AdvancedVI.weakdeps]
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
[[deps.AliasTables]]
deps = ["PtrArrays", "Random"]
git-tree-sha1 = "9876e1e164b144ca45e9e3198d0b689cadfed9ff"
uuid = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"
version = "1.1.3"
[[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.2"
[[deps.ArnoldiMethod]]
deps = ["LinearAlgebra", "Random", "StaticArrays"]
git-tree-sha1 = "d57bd3762d308bded22c3b82d033bff85f6195c6"
uuid = "ec485272-7323-5ecc-a04f-4719b315124d"
version = "0.4.0"
[[deps.Arpack]]
deps = ["Arpack_jll", "Libdl", "LinearAlgebra", "Logging"]
git-tree-sha1 = "9b9b347613394885fd1c8c7729bfc60528faa436"
uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
version = "0.5.4"
[[deps.Arpack_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "OpenBLAS_jll", "Pkg"]
git-tree-sha1 = "5ba6c757e8feccf03a1554dfaf3e26b3cfc7fd5e"
uuid = "68821587-b530-5797-8361-c406ea357684"
version = "3.5.1+1"
[[deps.ArrayInterface]]
deps = ["Adapt", "LinearAlgebra"]
git-tree-sha1 = "3640d077b6dafd64ceb8fd5c1ec76f7ca53bcf76"
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
version = "7.16.0"
[deps.ArrayInterface.extensions]
ArrayInterfaceBandedMatricesExt = "BandedMatrices"
ArrayInterfaceBlockBandedMatricesExt = "BlockBandedMatrices"
ArrayInterfaceCUDAExt = "CUDA"
ArrayInterfaceCUDSSExt = "CUDSS"
ArrayInterfaceChainRulesExt = "ChainRules"
ArrayInterfaceGPUArraysCoreExt = "GPUArraysCore"
ArrayInterfaceReverseDiffExt = "ReverseDiff"
ArrayInterfaceSparseArraysExt = "SparseArrays"
ArrayInterfaceStaticArraysCoreExt = "StaticArraysCore"
ArrayInterfaceTrackerExt = "Tracker"
[deps.ArrayInterface.weakdeps]
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
BlockBandedMatrices = "ffab5731-97b5-5995-9138-79e8c1846df0"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CUDSS = "45b445bb-4962-46a0-9369-b4df9d0f772e"
ChainRules = "082447d4-558c-5d27-93f4-14fc19e9eca2"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
version = "1.11.0"
[[deps.Atomix]]
deps = ["UnsafeAtomics"]
git-tree-sha1 = "c06a868224ecba914baa6942988e2f2aade419be"
uuid = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
version = "0.1.0"
[[deps.AxisAlgorithms]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
git-tree-sha1 = "01b8ccb13d68535d73d2b0c23e39bd23155fb712"
uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950"
version = "1.1.0"
[[deps.AxisArrays]]
deps = ["Dates", "IntervalSets", "IterTools", "RangeArrays"]
git-tree-sha1 = "16351be62963a67ac4083f748fdb3cca58bfd52f"
uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
version = "0.4.7"
[[deps.BangBang]]
deps = ["Accessors", "ConstructionBase", "InitialValues", "LinearAlgebra", "Requires"]
git-tree-sha1 = "e2144b631226d9eeab2d746ca8880b7ccff504ae"
uuid = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
version = "0.4.3"
[deps.BangBang.extensions]
BangBangChainRulesCoreExt = "ChainRulesCore"
BangBangDataFramesExt = "DataFrames"
BangBangStaticArraysExt = "StaticArrays"
BangBangStructArraysExt = "StructArrays"
BangBangTablesExt = "Tables"
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"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
version = "1.11.0"
[[deps.Baselet]]
git-tree-sha1 = "aebf55e6d7795e02ca500a689d326ac979aaf89e"
uuid = "9718e550-a3fa-408a-8086-8db961cd8217"
version = "0.1.1"
[[deps.Bijections]]
git-tree-sha1 = "d8b0439d2be438a5f2cd68ec158fe08a7b2595b7"
uuid = "e2ed5e7c-b2de-5872-ae92-c73ca462fb04"
version = "0.1.9"
[[deps.Bijectors]]
deps = ["ArgCheck", "ChainRules", "ChainRulesCore", "ChangesOfVariables", "Compat", "Distributions", "DocStringExtensions", "Functors", "InverseFunctions", "IrrationalConstants", "LinearAlgebra", "LogExpFunctions", "MappedArrays", "Random", "Reexport", "Requires", "Roots", "SparseArrays", "Statistics"]
git-tree-sha1 = "92edc3544607c4fda1b30357910597e2a70dc5ea"
uuid = "76274a88-744f-5084-9051-94815aaf08c4"
version = "0.13.18"
[deps.Bijectors.extensions]
BijectorsDistributionsADExt = "DistributionsAD"
BijectorsEnzymeExt = "Enzyme"
BijectorsForwardDiffExt = "ForwardDiff"
BijectorsLazyArraysExt = "LazyArrays"
BijectorsReverseDiffExt = "ReverseDiff"
BijectorsTapirExt = "Tapir"
BijectorsTrackerExt = "Tracker"
BijectorsZygoteExt = "Zygote"
[deps.Bijectors.weakdeps]
DistributionsAD = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Tapir = "07d77754-e150-4737-8c94-cd238a1fb45b"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
[[deps.BitFlags]]
git-tree-sha1 = "0691e34b3bb8be9307330f88d1a3c3f25466c24d"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"
[[deps.Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9e2a6b69137e6969bab0152632dcb3bc108c8bdd"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+1"
[[deps.CEnum]]
git-tree-sha1 = "389ad5c84de1ae7cf0e28e381131c98ea87d54fc"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.5.0"
[[deps.CSV]]
deps = ["CodecZlib", "Dates", "FilePathsBase", "InlineStrings", "Mmap", "Parsers", "PooledArrays", "PrecompileTools", "SentinelArrays", "Tables", "Unicode", "WeakRefStrings", "WorkerUtilities"]
git-tree-sha1 = "6c834533dc1fabd820c1db03c839bf97e45a3fab"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
version = "0.10.14"
[[deps.Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "CompilerSupportLibraries_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "009060c9a6168704143100f36ab08f06c2af4642"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.18.2+1"
[[deps.CategoricalArrays]]
deps = ["DataAPI", "Future", "Missings", "Printf", "Requires", "Statistics", "Unicode"]
git-tree-sha1 = "1568b28f91293458345dabba6a5ea3f183250a61"
uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597"
version = "0.10.8"
[deps.CategoricalArrays.extensions]
CategoricalArraysJSONExt = "JSON"
CategoricalArraysRecipesBaseExt = "RecipesBase"
CategoricalArraysSentinelArraysExt = "SentinelArrays"
CategoricalArraysStructTypesExt = "StructTypes"
[deps.CategoricalArrays.weakdeps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SentinelArrays = "91c51154-3ec4-41a3-a24f-3f23e20d615c"
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
[[deps.ChainRules]]
deps = ["Adapt", "ChainRulesCore", "Compat", "Distributed", "GPUArraysCore", "IrrationalConstants", "LinearAlgebra", "Random", "RealDot", "SparseArrays", "SparseInverseSubset", "Statistics", "StructArrays", "SuiteSparse"]
git-tree-sha1 = "be227d253d132a6d57f9ccf5f67c0fb6488afd87"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "1.71.0"
[[deps.ChainRulesCore]]
deps = ["Compat", "LinearAlgebra"]
git-tree-sha1 = "3e4b134270b372f2ed4d4d0e936aabaefc1802bc"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.25.0"
weakdeps = ["SparseArrays"]
[deps.ChainRulesCore.extensions]
ChainRulesCoreSparseArraysExt = "SparseArrays"
[[deps.ChangesOfVariables]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "799b25ca3a8a24936ae7b5c52ad194685fc3e6ef"
uuid = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
version = "0.1.9"
weakdeps = ["InverseFunctions", "Test"]
[deps.ChangesOfVariables.extensions]
ChangesOfVariablesInverseFunctionsExt = "InverseFunctions"
ChangesOfVariablesTestExt = "Test"
[[deps.Clustering]]
deps = ["Distances", "LinearAlgebra", "NearestNeighbors", "Printf", "Random", "SparseArrays", "Statistics", "StatsBase"]
git-tree-sha1 = "9ebb045901e9bbf58767a9f34ff89831ed711aae"
uuid = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
version = "0.15.7"
[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "bce6804e5e6044c6daab27bb533d1295e4a2e759"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.6"
[[deps.ColorSchemes]]
deps = ["ColorTypes", "ColorVectorSpace", "Colors", "FixedPointNumbers", "PrecompileTools", "Random"]
git-tree-sha1 = "b5278586822443594ff615963b0c09755771b3e0"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.26.0"
[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "b10d0b65641d57b8b4d5e234446582de5047050d"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.5"
[[deps.ColorVectorSpace]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "Requires", "Statistics", "TensorCore"]
git-tree-sha1 = "a1f44953f2382ebb937d60dafbe2deea4bd23249"
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
version = "0.10.0"
weakdeps = ["SpecialFunctions"]
[deps.ColorVectorSpace.extensions]
SpecialFunctionsExt = "SpecialFunctions"
[[deps.Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "362a287c3aa50601b0bc359053d5c2468f0e7ce0"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.12.11"
[[deps.Combinatorics]]
git-tree-sha1 = "08c8b6831dc00bfea825826be0bc8336fc369860"
uuid = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
version = "1.0.2"
[[deps.CommonSolve]]
git-tree-sha1 = "0eee5eb66b1cf62cd6ad1b460238e60e4b09400c"
uuid = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
version = "0.2.4"
[[deps.CommonSubexpressions]]
deps = ["MacroTools"]