Skip to content

Commit

Permalink
Deploying to gh-pages from @ 1593f86 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
lf28 committed Dec 3, 2023
1 parent 111e312 commit 23d49b9
Show file tree
Hide file tree
Showing 25 changed files with 3,064 additions and 285 deletions.
11 changes: 6 additions & 5 deletions index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ md"""
* [Lecture 3. Bayesian inference 2](./lectures/lecture_bayes2.html)
* [Lecture 4. MCMC 1](./lectures/lecture_mcmc1.html)
* [Lecture 5. MCMC 2](./lectures/lecture_mcmc2.html)
* [Lecture 6. Turing](./lectures/lecture_turing.html)
* [Lecture 7. Bayesian linear regression](./lectures/lecture_linerreg.html)
* [Lecture 8. Bayesian logistic regression](./lectures/lecture_logreg1.html)
* [Lecture 9. Bayesian logistic regression with Turing](./lectures/lecture_logreg2.html)
* [Lecture 10. Non linear models](./lectures/lecture_nonlin.html)
* [Lecture 6. Bayesian inference 3](./lectures/lecture_bayes3.html)
* [Lecture 7. Turing](./lectures/lecture_turing.html)
* [Lecture 8. Bayesian linear regression](./lectures/lecture_linerreg.html)
* [Lecture 9. Bayesian logistic regression](./lectures/lecture_logreg1.html)
* [Lecture 10. Bayesian logistic regression with Turing](./lectures/lecture_logreg2.html)
* [Lecture 11*. Non linear models](./lectures/lecture_nonlin.html)
"""

# ╔═╡ 0edb7166-5be6-49e7-8ccb-9e36bd1e3c0a
Expand Down
Binary file modified index.plutostate
Binary file not shown.
106 changes: 76 additions & 30 deletions lectures/lecture_bayes1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ md"""
## In this lecture
* More Bayesian inference
* more examples of the workflow
* the workflow: modelling + computation
* Estimate the bias of a coin (Bernoulli likelihood)
Expand Down Expand Up @@ -104,23 +104,25 @@ md"""
## Forward modelling
The random variables are
#### The *random variables* are
**The positive rate**: ``\theta \in [0,1]``:
* ##### *The positive rate*: ``\theta \in [0,1]``
* the unknown positive rate of the seller; also known as the bias for Bernoulli r.v.
* the bias for Bernoulli r.v.
**The observed tosses**: ``\mathcal{D} =\{Y_1, \ldots, Y_n\}``
* ##### *The observed tosses*: ``\mathcal{D} =\{Y_1, \ldots, Y_n\}``
How the random variables shall be linked?
* need to think generatively
* the following seems right
\
\
##### How the random variables shall be linked?
```math
\theta \Rightarrow \mathcal{D}
\Large \theta \Rightarrow \mathcal{D}
```
* common cause pattern
* the tossing results depend on $\theta$
"""

# ╔═╡ 66926dbf-964d-4048-b8ad-459f36236c14
Expand All @@ -129,12 +131,10 @@ md"""
## The graphical model
Equivalently, we can represent it as a graphical model
In other words, the joint distribution is factored as (conditional independence assumption)
```math
\large
P(\theta, Y_1, Y_2, \ldots, Y_{10}) = \underbrace{P(\theta)}_{\text{prior}} \underbrace{P(Y_1, Y_2, \ldots, Y_{10}|\theta)}_{\text{likelihood}} = P(\theta)\prod_i P(Y_i|\theta)
```
Expand Down Expand Up @@ -209,9 +209,8 @@ P(\mathcal{D}|\theta) = \theta^{N^+}(1-\theta)^{N-N^+}
# ╔═╡ 1bc6b970-f1fa-48c9-b17e-cef4d01aa47a
md"""
## MLE
## Maximum likelihood estimation
The likelihood ``P(\mathcal{D}|\theta)`` is plotted
"""

# ╔═╡ 15571edc-32d7-4ac5-9c53-d49f595f84b1
Expand Down Expand Up @@ -295,7 +294,7 @@ $(let
end)
The MLE is
$$\hat{\theta}_{\text{ML}} = \frac{0}{2} =0$$
$$\large \hat{\theta}_{\text{ML}} = \frac{0}{2} =0$$
"""

Expand Down Expand Up @@ -342,14 +341,17 @@ The only random variables are the data ``\mathcal{D}``
* frequentists only need the likelihood ``P(\mathcal{D}|\theta)``
* MLEs are usually random variables (therefore, with sampling distribution)
## Frequentist approach
A **confidence interval** can be calculated as
$$(\hat{\theta} - z_{\alpha/2} \hat{\texttt{se}}, \hat{\theta} + z_{\alpha/2} \hat{\texttt{se}}), \text{where}$$
$$\hat{\texttt{se}}= \sqrt{\frac{\hat{\theta}(1-\hat{\theta})}{N}}.$$
* ``\hat{\theta}`` is the MLE, which is a random variable
* the interval is formed based on the converging property of the MLE
* ##### ``\hat{\theta}, \hat{\texttt{se}}`` are random variables
* ##### the intervals themselves are random but $\theta$ is fixed
"""

# ╔═╡ b3bcf03b-f4f8-4ddb-ab59-fa5f780ed563
Expand All @@ -358,17 +360,19 @@ md"""
## Confidence interval
For our problem, a 90% frequentist confidence interval is
For our problem, a 90% frequentist **confidence interval** is
$$(0.46, 0.94)$$
$$\large (0.46, 0.94)$$
> But how shall we interpret this interval?
> #### But how shall we interpret this interval?
* ``\theta`` is not a random variable, it is clearly not an uncertainty statement about ``\theta``
* but the interval itself is random
* ``\theta`` is not a random variable
* ##### not an uncertainty statement about ``\theta`` in the Bayesian sense
* ##### but the intervals are random
## Confidence interval
!!! danger ""
Expand All @@ -385,6 +389,7 @@ $$(0.46, 0.94)$$

# ╔═╡ ff01e390-a72d-41b0-9a7c-1d63060491f9
md"""
##
The animation illustrates the idea
* conditional on the hypothesis that the coin is fair, *i.e.* ``\theta =0.5`` (it works for any ``\theta\in [0,1]``)
Expand Down Expand Up @@ -416,6 +421,46 @@ And Bayesian inference is procedurally simple and uniform
* frequentist methods need different tests for different purposes
"""

# ╔═╡ 84f66218-1309-4cfd-8250-11bd75f78eb4
md"""
## Bayesian vs Frequentist
"""

# ╔═╡ 98e84190-393a-4eb9-8f1c-fa90bf8973d2
TwoColumn(md"""
### Bayesian
##### ``\theta`` is random
* many ``\theta`` flausible
##### ``\mathcal{D}`` random but observed (fixed)
* only one ``\mathcal{D}`` assumed
##### One algorithm rules all
* *i.e.* Bayes' rule
""", md"""
### Frequentist
##### ``\theta`` is not random (fixed)
* only one ``\theta`` (although unknown)
##### ``\mathcal{D}`` random and repeated (varies)
* many possible ``\mathcal{D}`` assumed
##### One algorithm per problem
* recall those `tests` you have been taught
""")

# ╔═╡ 6131ad55-eee7-44ec-b965-ce17ef3f8f84
begin
cint_normal(n, k; θ=k/n, z=1.96) = max(k/n - z * sqrt*(1-θ)/n),0), min(k/n + z * sqrt*(1-θ)/n),1.0)
Expand Down Expand Up @@ -485,8 +530,6 @@ md"""
# ╔═╡ 89f0aa81-1da3-41a0-8d72-72637d8052aa
md"""
It is the same to estimating a coin's bias actually
> Seller *A* is "tossed" 10 times.
> * 8 out of the 10 experiments are positive.
> * what is the unknown positive rating ?
Expand Down Expand Up @@ -536,7 +579,8 @@ let
plot!(post_plt, θs, posterior_dis, color=2, label ="Posterior", fill=true, alpha=0.5)
plot!(post_plt, θs, 1/length(θs) * ones(length(θs)), seriestype=:sticks, markershape=:circle, color =1, alpha=0.2, label="")
plot!(post_plt, θs, 1/length(θs) * ones(length(θs)), color=1, label ="Prior", fill=true, alpha=0.2)
plot(prior_plt_seller, like_plt_seller, post_plt, layout=l)
like_plt = plot(θs, θ -> (θ, 𝒟), seriestype=:sticks, color=1, markershape=:circle, xlabel=L"θ", ylabel=L"P(\{0,0\}|θ)", label="", title="Likelihood: "*L"P(\{0,0\}|\theta)")
plot(prior_plt_seller, like_plt, post_plt, layout=l)
end

# ╔═╡ fde1b917-9d81-4a29-b553-caad3c736682
Expand Down Expand Up @@ -679,7 +723,7 @@ md"""
The heatmap of the posterior density is also plotted for reference.
$(begin
gr()
Plots.plot(θ₁s, θ₂s, ps', st=:heatmap, xlabel=L"\theta_A", ylabel=L"\theta_B", ratio=1, xlim=[0,1], ylim=[0,1], zlim =[-0.003, maximum(ps)], colorbar=false, c=:plasma, zlabel="density", alpha=0.7, title="Posterior's density heapmap")
end)
Expand Down Expand Up @@ -831,11 +875,11 @@ md"""
The posterior distribution ``P(\theta|\mathcal{D})`` provides what we need to know
* the mode of the posterior is around 0.7
* the **mode** of the posterior is around 0.7
To summarise the uncertainty, we can report **highest probability density interval (HPDI)**
To **summarise the uncertainty**, we often report **highest probability density interval (HPDI)**
* Bayesian **credible interval** (c.f. confidence interval)
Expand All @@ -844,7 +888,7 @@ To summarise the uncertainty, we can report **highest probability density interv
$$p(l \leq \theta \leq u|\mathcal D) = 90 \%.$$
* however, the wide tail suggests it is not very certain; we only have observed 10 tosses after all
* the 90% region for ``\theta`` is ($(θs_refined[l2]), $(θs_refined[u2]))
* ##### the 90% region for ``\theta`` is ($(θs_refined[l2]), $(θs_refined[u2]))
"""

# ╔═╡ f7456b7a-3d05-468a-a7ee-50a83affba72
Expand Down Expand Up @@ -2407,6 +2451,8 @@ version = "1.4.1+1"
# ╟─ff01e390-a72d-41b0-9a7c-1d63060491f9
# ╟─6d136ab7-c7ea-43a7-a16d-0af53b123b59
# ╟─c1edf5ff-f25f-4a71-95fb-53515aae9d97
# ╟─84f66218-1309-4cfd-8250-11bd75f78eb4
# ╟─98e84190-393a-4eb9-8f1c-fa90bf8973d2
# ╟─a152a7bd-062d-4fd9-be38-c217fdaca20f
# ╟─6131ad55-eee7-44ec-b965-ce17ef3f8f84
# ╟─a2642e09-3202-4c73-914a-bdd6c0b374c2
Expand Down
Binary file modified lectures/lecture_bayes1.plutostate
Binary file not shown.
18 changes: 13 additions & 5 deletions lectures/lecture_bayes2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,14 @@ md"""
## In this lecture
* Prior distribution choices
* conjugate priors
* some common distributions for priors
* Predictive distributions and their checks
* prior predictive check
* posterior predictive check
* Conjugate inference
Expand Down Expand Up @@ -719,6 +717,16 @@ end
md"""
# Bayesian predictive checks
## This time
* Predictive distributions and their checks
* prior predictive check
* posterior predictive check
"""

# ╔═╡ 6b460036-890d-4364-aac2-2c61dc44ed75
Expand Down
Binary file modified lectures/lecture_bayes2.plutostate
Binary file not shown.
16 changes: 16 additions & 0 deletions lectures/lecture_bayes3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=device-width"><meta charset="utf-8"><meta property='og:type' content='article'>

<meta name="pluto-insertion-spot-meta">
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white"><meta name="theme-color" media="(prefers-color-scheme: dark)" content="#2a2928"><meta name="color-scheme" content="light dark"><link rel="icon" type="image/png" sizes="16x16" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/favicon-16x16.347d2855.png" integrity="sha384-3qsGeVLdddzV9oIkj3PhXXQX2CZCjOD/CiyrPQOX6InOWw3HAHClrsQhPfX9uRAj" crossorigin="anonymous"><link rel="icon" type="image/png" sizes="32x32" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/favicon-32x32.8789add4.png" integrity="sha384-cOe5vSoBIgKNgkUL27p9RpsGVY0uBg9PejLccDy+fR8ZD1Iv5dF1MGHjIZAIZwm6" crossorigin="anonymous"><link rel="icon" type="image/png" sizes="96x96" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/favicon-96x96.48689391.png" integrity="sha384-TN49cYb8GyNmrZT14bsYXXo4l1x1NJeJ/EHuVAauAKsNPopPHLojijs9jFT4Vs8c" crossorigin="anonymous"><link rel="pluto-logo-big" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/logo.004c1d7c.svg" integrity="sha384-GkQkODcGxsrSRJCkeakBXihum0GUM44cwBgKyutDimectXCbCgj6Vu3jlrueqEcN" crossorigin="anonymous"><link rel="pluto-logo-small" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/favicon_unsaturated.d1387b25.svg" integrity="sha384-omwjH+Qy3hpAVf5FYd/pkaDBuVAfsEDRN7eBxEA8Ek00OAWP+aiV+GpEYk3I7lyo" crossorigin="anonymous"><script type="module" src="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.26f5d75a.js" integrity="sha384-j0xlZKz53TCdRRMsnQ1QpafDB+zRgGHrDmTRQWKYXNvJMxhIVDznB5f9TfC43k1B" crossorigin="anonymous"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/juliamono.c6034ab4.css" integrity="sha384-n0za6lUXlyf4XC+nGkZWj3TLDnRbNpAcoi4PZGSlQMPoyqGa9kGY+ZXkUgZGIhQt" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.13f61af1.css" integrity="sha384-ilRJ5tzXTTNidx95nKQMvAklaLGfhTUWUhF4fr8jy75PnMkhkjhrbHNF7zxkxu5X" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/vollkorn.089565a8.css" integrity="sha384-jnV/84VtSgBLF70H+s2rxJcOUZIMDR+X/ElFZA83i9ZtZSWiIMFAgPyrWkOJV08q" crossorigin="anonymous"><script defer="">console.log("Pluto.jl, by Fons van der Plas (https://github.com/fonsp), Mikołaj Bochenski (https://github.com/malyvsen), Michiel Dral (https://github.com/dralletje) and friends 🌈");</script><script src="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.b8733d72.js" defer="" integrity="sha384-84yPd6AGZ/1IUiaBlssipmMKMFz9WGFQ+u8vYZ9cWicH6bZm7ZOej+kLDXnIIAQJ" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.9f9dc874.js" defer="" integrity="sha384-tkFo1EK72I9JvoTmHFa199dfRzW8mkXPUkHb/N7UhYI+bxKzX3Kh8LNCZz1ltsFF" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.90ede145.js" defer="" integrity="sha384-CuNU9gQg6fa/yynNqNWjHWzPm4nj+d7O6+HXsNGSqClhs/bYQIbBC3Lw/kh8Ukui" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.dbeed08a.js" defer="" integrity="sha384-1BEdQwXfZi4ZpsNV8w1X8pQcVK1/DS/+/M8OTo3gol7mdEspSN7nT6llX57NQCSt" crossorigin="anonymous"></script><script id="iframe-resizer-content-window-script" src="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.6386bd9d.js" crossorigin="anonymous" defer="" integrity="sha384-tgN2a0VDi/lCYwZuDqT7L+A/Y/9kpxf3HV7zv2BJ5Fu7zW0EClq0nM4crfK3TRPs"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.e9534656.css" type="text/css" integrity="sha384-0tNzQOZ9M1+ZH4z9q47LEBLOf8vb1jOFVN+e7Q3JESoJ0CQWsaHn4u07nry5SPz4" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.14f23ca4.css" type="text/css" media="all" data-pluto-file="hide-ui" integrity="sha384-++EDAMZbJynENol9onosKuuWP4ex4rhT9Rl/oELs6oVltwZdU9DC0W1nYT4Ttb9V" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.105bd258.css" type="text/css" integrity="sha384-2oz3nAiRIiIcTjp1HFGTtsqQ636JlyvepEXpHhF4JDxPAhDiD0vRdTJ7TOfvD165" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.1f4cf2ca.css" type="text/css" integrity="sha384-lBSBsn8FT1UzGOsNVudfV8RSHQEuNWqrCb6xQnF10uvF9AiCzYsCRXvKlhtQvV3c" crossorigin="anonymous"><link rel="preload" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/juliamono.c6034ab4.css" as="style" integrity="sha384-n0za6lUXlyf4XC+nGkZWj3TLDnRbNpAcoi4PZGSlQMPoyqGa9kGY+ZXkUgZGIhQt" crossorigin="anonymous"><link rel="preload" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/vollkorn.089565a8.css" as="style" integrity="sha384-jnV/84VtSgBLF70H+s2rxJcOUZIMDR+X/ElFZA83i9ZtZSWiIMFAgPyrWkOJV08q" crossorigin="anonymous"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.e82e08bd.css" type="text/css" integrity="sha384-7YN+h8b6N4N65qk8TG/J2KPF95D8z3sGNd06rokz4CX9oWu0KnRAF5cVWu3BkkaN" crossorigin="anonymous"><script data-pluto-file="launch-parameters">
window.pluto_notebook_id = undefined;
window.pluto_isolated_cell_ids = undefined;
window.pluto_notebookfile = "lecture_bayes3.jl";
window.pluto_disable_ui = true;
window.pluto_slider_server_url = undefined;
window.pluto_binder_url = "https://mybinder.org/v2/gh/fonsp/pluto-on-binder/v0.19.32";
window.pluto_statefile = "lecture_bayes3.plutostate";
window.pluto_preamble_html = undefined;
</script>

<meta name="pluto-insertion-spot-parameters">
<script src="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.c36f728c.js" type="module" defer="" integrity="sha384-cYatbAoH849b+gfjarJ3/mtvWjsp24oV0kGmpn3/E9BHuo2cIoYjldpPOCCdT9mb" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/gh/fonsp/[email protected]/frontend-dist/editor.8a3292da.js" integrity="sha384-itp4oE2PRbSrrTHVpWh8sqAuVUsz7ja6L2Dgp/JRfMCD2AwVdTk56K96POF3oLmu" crossorigin="anonymous"></script><script type="text/javascript" id="MathJax-script" integrity="sha384-4kE/rQ11E8xT9QgrCBTyvenkuPfQo8rXYQvJZuMgxyPOoUfpatjQPlgdv6V5yhUK" crossorigin="" not-the-src-yet="https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg-full.js" async=""></script></head><body class="loading no-MαθJax"> <div style="display:flex;min-height:100vh;"> <pluto-editor class="fullscreen"></pluto-editor> </div> </body></html>
Loading

0 comments on commit 23d49b9

Please sign in to comment.