Probabilistic Programming 0: Check installation

This notebook lets you test out your installation of Jupyter and Julia. It will also automatically download all the packages you need for the course, precompile them and check if they run correctly.

In [1]:
# Check correct Julia version (will throw error if false)
@assert VERSION == v"1.6.3"
In [2]:
# Set up workspace (downloads and installs necessary packages)
using Pkg
Pkg.activate("./workspace/")
Pkg.instantiate();
  Activating environment at `~/syndr/Wouter/Onderwijs/Vakken/tueindhoven/5SSD0 - Bayesian Machine Learning & Information Processing/2021-2022 Q2/BMLIP/lessons/notebooks/probprog/workspace/Project.toml`
   Installed x264_jll ──────────── v2021.5.5+0
   Installed libfdk_aac_jll ────── v2.0.2+0
   Installed x265_jll ──────────── v3.5.0+0
   Installed PyPlot ────────────── v2.10.0
   Installed DocStringExtensions ─ v0.8.6
   Installed Plots ─────────────── v1.23.6
   Installed Distributions ─────── v0.25.28
   Installed Bzip2_jll ─────────── v1.0.8+0
   Installed HDF5 ──────────────── v0.15.7
   Installed PlotUtils ─────────── v1.0.15
   Installed DiffRules ─────────── v1.4.0
   Installed ForwardDiff ───────── v0.10.23
   Installed MacroTools ────────── v0.5.9
   Installed StatsBase ─────────── v0.33.12
   Installed PDMats ────────────── v0.11.3
   Installed PyCall ────────────── v1.92.5
   Installed PrettyTables ──────── v1.2.3
   Installed IrrationalConstants ─ v0.1.1
   Installed DataAPI ───────────── v1.9.0
   Installed ChangesOfVariables ── v0.1.1
   Installed QuadGK ────────────── v2.4.2
   Installed Latexify ──────────── v0.15.9
   Installed StaticArrays ──────── v1.2.13
   Installed DensityInterface ──── v0.3.3
   Installed DataFrames ────────── v1.2.2
   Installed Missings ──────────── v1.0.2
   Installed RecipesBase ───────── v1.1.2
   Installed FileIO ────────────── v1.11.2
   Installed EarCut_jll ────────── v2.2.3+0
   Installed UnicodeFun ────────── v0.4.1
   Installed InvertedIndices ───── v1.1.0
   Installed Fontconfig_jll ────── v2.13.93+0
   Installed StatsFuns ─────────── v0.9.13
   Installed LogExpFunctions ───── v0.3.5
   Installed Reexport ──────────── v1.2.2
   Installed StructArrays ──────── v0.6.3
   Installed Blosc ─────────────── v0.7.1
   Installed SentinelArrays ────── v1.3.8
   Installed GR_jll ────────────── v0.62.0+0
   Installed FreeType2_jll ─────── v2.10.4+0
   Installed Tables ────────────── v1.6.0
   Installed PooledArrays ──────── v1.3.0
   Installed InverseFunctions ──── v0.1.2
   Installed LaTeXStrings ──────── v1.3.0
   Installed RecipesPipeline ───── v0.4.1
   Installed SpecialFunctions ──── v1.8.1
   Installed GeometryBasics ────── v0.4.1
   Installed ChainRulesCore ────── v1.11.1
   Installed FFMPEG_jll ────────── v4.4.0+0
   Installed FillArrays ────────── v0.12.7
   Installed HTTP ──────────────── v0.9.16
   Installed VersionParsing ────── v1.2.1
   Installed Parsers ───────────── v1.1.2
   Installed Cairo_jll ─────────── v1.16.1+0
   Installed Compat ────────────── v3.40.0
   Installed ForneyLab ─────────── v0.11.3
   Installed libass_jll ────────── v0.15.1+0
   Installed GR ────────────────── v0.62.1
   Installed ColorSchemes ──────── v3.15.0
    Building HDF5 ──→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/698c099c6613d7b7f151832868728f426abe698b/build.log`
    Building PyCall → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/4ba3651d33ef76e24fef6a598b63ffd1c5e1cd17/build.log`
    Building GR ────→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/30f2b340c2fff8410d89bfcdc9c0a6dd661ac5f7/build.log`
Precompiling project...
OpenLibm_jll
DataAPI
Reexport
LaTeXStrings
InvertedIndices
PDMats
RecipesBase
IrrationalConstants
UnicodeFun
InverseFunctions
Compat
ChangesOfVariables
FillArrays
SentinelArrays
DocStringExtensions
libfdk_aac_jll
Blosc
Graphite2_jll
Missings
x265_jll
PooledArrays
Bzip2_jll
x264_jll
EarCut_jll
Tables
MacroTools
DensityInterface
FileIO
FreeType2_jll
CommonSubexpressions
ChainRulesCore
HTTP
Latexify
Fontconfig_jll
HDF5
DataStructures
Cairo_jll
SortingAlgorithms
Documenter
Qt5Base_jll
LogExpFunctions
QuadGK
HarfBuzz_jll
JLD
Colors
libass_jll
StaticArrays
StatsBase
PyCall
FFMPEG_jll
PrettyTables
DiffResults
Contour
FFMPEG
GR_jll
StructArrays
CSV
SpecialFunctions
DiffRules
GR
PyPlot
ColorSchemes
StatsFuns
ForwardDiff
GeometryBasics
Distributions
PlotUtils
ForneyLab
RecipesPipeline
PlotThemes
DataFrames
Plots
  72 dependencies successfully precompiled in 71 seconds (89 already precompiled)
In [3]:
# Test ForneyLab (will throw errors if inference failed)
using ForneyLab

graph = FactorGraph()

@RV μ ~ GaussianMeanVariance(0.0, 1.0)
@RV x ~ GaussianMeanVariance(μ, 1.0)
placeholder(x, :x)

algorithm = messagePassingAlgorithm(μ, id=:μ)
source_code = algorithmSourceCode(algorithm)
eval(Meta.parse(source_code))

data = Dict(:x => 3.0)
marginals = Dict()
stepμ!(data, marginals)

@assert typeof(marginals) == Dict{Any,Any}
@assert marginals[:μ] == ProbabilityDistribution(Univariate,GaussianWeightedMeanPrecision, xi=3.0, w=2.0)
┌ Info: Precompiling ForneyLab [9fc3f58a-c2cc-5bff-9419-6a294fefdca9]
└ @ Base loading.jl:1342
In [4]:
# Test plotting
using Plots
pyplot()

x = range(0, stop=10, length=50)
y = x.^3

plot(x, y, label="", xlabel="x", ylabel="y")
┌ Info: Precompiling Plots [91a5bcdd-55d7-5caf-9e0b-520d859cae80]
└ @ Base loading.jl:1342
┌ Info: Precompiling PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee]
└ @ Base loading.jl:1342
Out[4]:
In [5]:
# Test Unicode characters in plots and LaTeXString
using LaTeXStrings

θ = range(0, stop=1, length=50)
 = θ.^3 .* (1 .- θ).^7

plot(θ, , xlabel="θ", ylabel="p(θ)", label=L"p(θ) = \prod_{i=1}^{N} θ^{X_i} \cdot (1-\theta)^{1 - X_i}")
Out[5]:
In [6]:
# Testing data loading and management
using CSV
using DataFrames

df = DataFrame(CSV.File("../datasets/old_faithful.csv"))
Out[6]:

271 rows × 2 columns

3.60000079.000000
Float64Float64
11.854.0
23.33374.0
32.28362.0
44.53385.0
52.88355.0
64.788.0
73.685.0
81.9551.0
94.3585.0
101.83354.0
113.91784.0
124.278.0
131.7547.0
144.783.0
152.16752.0
161.7562.0
174.884.0
181.652.0
194.2579.0
201.851.0
211.7547.0
223.4578.0
233.06769.0
244.53374.0
253.683.0
261.96755.0
274.08376.0
283.8578.0
294.43379.0
304.373.0