Created
July 12, 2021 19:14
-
-
Save gongcastro/77299de891a525e5e4967d2b67dc3f43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# animate the Beta distribution | |
# parameter vectors | |
x = collect(0.01:0.01:0.99); # sampling space | |
α = collect(0.1:0.1:10); | |
β = collect(0.1:0.1:10); | |
# only β=5 is used, but I don't want to mess up the code | |
# extract probability densities for all combinations of parameters | |
y = zeros(length(x), length(α), length(β)); # pre-alocate | |
for i = 1:length(α), j = 1:length(β) | |
y[:, i, j] .= pdf.(Beta(α[i], β[j]), x); | |
end | |
# plot | |
indices = vcat(1:length(β), reverse(1:length(β))); | |
anim = @animate for i = indices | |
scatter( | |
x, y[:, :, i], | |
colorbar=true, fill_z=length(α), | |
lw=3, ylims=(0, 6), palette=:RdYlBu_10, | |
legend=false, | |
xlabel="Sampling space", ylabel="", | |
title="Beta(α, β) probability density" | |
) | |
plot!([0.925, 1],[5.5, 5.5],arrow=true,color=:black,linewidth=2,label="") | |
annotate!(0.85, 5, text(string.("β = ", β[i]), :black, :left, 12)) | |
annotate!(0.85, 5.5, text("α = ", :black, :left, 12)) | |
end | |
gif(anim, "beta.gif", fps = 30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment