Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions 05_prob_prog_intro/05_prob_prog_intro.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.12.18
# v0.12.21

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -37,6 +37,14 @@ begin
title!("Prior distribution for p")
end

# ╔═╡ 3a8615d2-8be3-11eb-3913-b97d04bb053a
md"### To do list

We are currently working on:

";


# ╔═╡ 9608da48-1acd-11eb-102a-27fbac1ec88c
md" # Probabilistic Programming"

Expand Down Expand Up @@ -152,7 +160,7 @@ We can see in the plot below, showing the posterior or updated distribution of *
# ╔═╡ 0c570210-1af6-11eb-1d5d-5f78f2a000fd
begin
p_summary = chain[:p]
plot(p_summary, seriestype = :histogram, normed=true, legend=false, size=(400, 250), color="purple", alpha=0.7)
plot(p_summary, seriestype = :histogram, normed=true, legend=false, size=(500, 250), color="purple", alpha=0.7)
title!("Posterior distribution of p after getting tails")
ylabel!("Probability")
xlabel!("p")
Expand Down Expand Up @@ -235,7 +243,18 @@ plot(plots[3], plots_[3], title = ["Posterior for Uniform prior and 4 outcomes"
md"So in this case, incorporating our beliefs in the prior distribution we saw the model reached faster the more plausible values for *p*, needing less outcomes to reach a very similar posterior distribution. When we used an uniform prior, we were conservative, meaning that we said we didn't know anything about *p* so we assign equal probability for all values. Sometimes these kind of distribution (uniform distributions), called a non-informative prior, can be maybe too conservative, being in some cases not helpful at all. They even can slow the convergence of the model to the more plausible values for our posterior, as shown."

# ╔═╡ 92a7cfaa-1a2e-11eb-06f2-f50e91cfbba0
md" ### Bayesian Bandits "
md" ### Summary

In this chapter, we gave an introduction to probabilistic programming languages and explored the classic coin flipping example in a Bayesian way.

First, we saw that in this kind of Bernoulli trial scenario, where the experiment has two possible outcomes 0 or 1, it is a good idea to set our likelihood to a binomial distribution.
We also learned what sampling is and saw why we use it to update our beliefs.
Then we used the Julia library Turing.jl to create a probabilistic model, setting our prior probability to a uniform distribution and the likelihood to a binomial one.
We sampled our model with the Markov chain Monte Carlo algorithm and saw how the posterior probability was updated every time we input a new coin flip result.

Finally, we created a new model with the prior probability set to a normal distribution centered on *p* = 0.5 which gave us more accurate results.

"

# ╔═╡ 95efe302-35a4-11eb-17ac-3f0ad66fb164
md"
Expand All @@ -244,7 +263,26 @@ md"
* [Not a monad tutorial article about Soss.jl](https://notamonadtutorial.com/soss-probabilistic-programming-with-julia-6acc5add5549)
"

# ╔═╡ a77d01ca-8b78-11eb-34dc-b18bf984bf22
md" ### Give us feedback


This book is currently in a beta version. We are looking forward to getting feedback and criticism:
* Submit a GitHub issue **[here](https://github.com/unbalancedparentheses/data_science_in_julia_for_hackers/issues)**.
* Mail us to **[email protected]**

Thank you!
"


# ╔═╡ a8fda810-8b78-11eb-21af-d18ab85709b7
md"
[Next chapter](https://datasciencejuliahackers.com/06_gravity.jl.html)
"


# ╔═╡ Cell order:
# ╟─3a8615d2-8be3-11eb-3913-b97d04bb053a
# ╟─9608da48-1acd-11eb-102a-27fbac1ec88c
# ╟─14b8e170-1ad9-11eb-2111-3784e7029ba0
# ╟─e8557342-1adc-11eb-3978-33880f4a97a2
Expand Down Expand Up @@ -278,5 +316,7 @@ md"
# ╟─e407fa56-1af7-11eb-18c2-79423a9e4135
# ╠═efa0b506-1af7-11eb-2a9a-cb08f7f2d715
# ╟─f719af54-1af7-11eb-05d3-ff9aef8fb6ed
# ╠═92a7cfaa-1a2e-11eb-06f2-f50e91cfbba0
# ╟─92a7cfaa-1a2e-11eb-06f2-f50e91cfbba0
# ╟─95efe302-35a4-11eb-17ac-3f0ad66fb164
# ╟─a77d01ca-8b78-11eb-34dc-b18bf984bf22
# ╟─a8fda810-8b78-11eb-21af-d18ab85709b7
Loading