Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 670d2c7

Browse files
authored
Move images to Makie (#72)
* added .JuliaFormatter.toml * makie 02_bayes_stats.jl * makie 03_prob_dist * format 01_why_Julia * format everything * makie conversion * using stuff multiline * makie 04_Turing * remove plots stuff from Project.toml * animations and makie 05_MCMC * fix setrange in 12_Turing_tricks
1 parent 18fb675 commit 670d2c7

15 files changed

+686
-553
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "blue"

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
66
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
88
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
9+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
910
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1011
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
1112
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
@@ -14,15 +15,12 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1415
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1516
Franklin = "713c75ef-9fc9-4b05-94a9-213340da978e"
1617
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
17-
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
1818
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
1919
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
2020
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
2121
NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c"
22-
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
2322
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
2423
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
25-
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
2624
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
2725

2826
[compat]

_literate/01_why_Julia.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@
7676
# Here is Julia:
7777

7878
# ```julia
79-
# using Random, StatsBase, DataFrames, BenchmarkTools, Chain
79+
# using Random
80+
# using StatsBase
81+
# using DataFrames
82+
# using BenchmarkTools
83+
# using Chain
8084
# Random.seed!(123)
8185
#
8286
# n = 10_000
@@ -474,12 +478,16 @@
474478
# to define the action that one type `Pet` takes when it meets another `Pet`:
475479

476480
abstract type Pet end
477-
struct Dog <: Pet name::String end
478-
struct Cat <: Pet name::String end
481+
struct Dog <: Pet
482+
name::String
483+
end
484+
struct Cat <: Pet
485+
name::String
486+
end
479487

480488
function encounter(a::Pet, b::Pet)
481489
verb = meets(a, b)
482-
println("$(a.name) meets $(b.name) and $verb")
490+
return println("$(a.name) meets $(b.name) and $verb")
483491
end
484492

485493
meets(a::Dog, b::Dog) = "sniffs";
@@ -639,7 +647,7 @@ using BenchmarkTools
639647
# with a simple column selection. We do this by defining a new method of the `*` function (multiplier function)
640648
# of `Base` Julia. Additionally we also create a new optimized method of `inner()` for dealing with `OneHotVector`:
641649

642-
import Base:*
650+
import Base: *
643651

644652
*(A::AbstractMatrix, v::OneHotVector) = A[:, v.ind]
645653
inner(v::OneHotVector, A, w::OneHotVector) = A[v.ind, w.ind]

_literate/02_bayes_stats.jl

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -416,24 +416,23 @@
416416
# and the 75% percentile of the probability density of $\theta$. In this example, MLE leads to estimated values that are not
417417
# consistent with the actual probability density of the value of $\theta$.
418418

419-
using Plots, StatsPlots, Distributions, LaTeXStrings
419+
using CairoMakie
420+
using Distributions
420421

421422
d = LogNormal(0, 2)
422423
range_d = 0:0.001:4
423424
q25 = quantile(d, 0.25)
424425
q75 = quantile(d, 0.75)
425-
plot((range_d, pdf.(d, range_d)),
426-
leg=false,
427-
xlims=(-0.2, 4.2),
428-
lw=3,
429-
xlabel=L"\theta",
430-
ylabel="Density")
431-
scatter!((mode(d), pdf(d, mode(d))), mc=:green, ms=5)
432-
plot!(range(q25, stop=q75, length=100),
433-
x -> pdf(d, x),
434-
lc=false, fc=:blues,
435-
fill=true, fa=0.5)
436-
savefig(joinpath(@OUTPUT, "lognormal.svg")); # hide
426+
credint = range(q25; stop=q75, length=100)
427+
f, ax, l = lines(
428+
range_d,
429+
pdf.(d, range_d);
430+
linewidth=3,
431+
axis=(; limits=(-0.2, 4.2, nothing, nothing), xlabel=L"\theta", ylabel="Density"),
432+
)
433+
scatter!(ax, mode(d), pdf(d, mode(d)); color=:green, markersize=12)
434+
band!(ax, credint, 0.0, pdf.(d, credint); color=(:steelblue, 0.5))
435+
save(joinpath(@OUTPUT, "lognormal.svg"), f); # hide
437436

438437
# \fig{lognormal}
439438
# \center{_**Log-Normal**: Maximum Likelihood Estimate vs Credible Intervals_} \\
@@ -454,19 +453,22 @@ range_d = -2:0.01:14
454453
sim_d = rand(d, 10_000)
455454
q25 = quantile(sim_d, 0.25)
456455
q75 = quantile(sim_d, 0.75)
457-
plot((range_d, pdf.(d, range_d)),
458-
leg=false,
459-
xlims=(-2, 14),
460-
xticks=[0, 5, 10],
461-
lw=3,
462-
xlabel=L"\theta",
463-
ylabel="Density")
464-
scatter!((mode(d2), pdf(d, mode(d2))), mc=:green, ms=5)
465-
plot!(range(q25, stop=q75, length=100),
466-
x -> pdf(d, x),
467-
lc=false, fc=:blues,
468-
fill=true, fa=0.5)
469-
savefig(joinpath(@OUTPUT, "mixture.svg")); # hide
456+
credint = range(q25; stop=q75, length=100)
457+
458+
f, ax, l = lines(
459+
range_d,
460+
pdf.(d, range_d);
461+
linewidth=3,
462+
axis=(;
463+
limits=(-2, 14, nothing, nothing),
464+
xticks=[0, 5, 10],
465+
xlabel=L"\theta",
466+
ylabel="Density",
467+
),
468+
)
469+
scatter!(ax, mode(d2), pdf(d, mode(d2)); color=:green, markersize=12)
470+
band!(ax, credint, 0.0, pdf.(d, credint); color=(:steelblue, 0.5))
471+
save(joinpath(@OUTPUT, "mixture.svg"), f); # hide
470472

471473
# \fig{mixture}
472474
# \center{_**Mixture**: Maximum Likelihood Estimate vs Credible Intervals_} \\

0 commit comments

Comments
 (0)