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
julia> using DynamicPPL | |
julia> @model function demo1(x) | |
x ~ Normal() | |
end | |
demo1 (generic function with 1 method) | |
julia> @model function demo2(x) | |
x ~ Normal() | |
end |
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
julia> using DynamicPPL, Distributions, Bijectors | |
julia> using Symbolics | |
julia> using Symbolics: SymbolicUtils | |
julia> import StatsFuns | |
julia> # Make stuff from Distributions.jl primitives so that we don't recurse into them. | |
@register Normal() |
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
julia> using Distributions, ForwardDiff | |
julia> import Distributions: StatsFuns # StatsFuns.jl is used within Distributions.jl, so we just grab from there | |
julia> ForwardDiff.derivative(λ -> StatsFuns.poiscdf(λ, 1), 1.0) | |
ERROR: MethodError: no method matching poiscdf(::ForwardDiff.Dual{ForwardDiff.Tag{var"#1#2", Float64}, Float64, 1}, ::Int64) | |
Closest candidates are: | |
poiscdf(::Union{Float64, Int64}, ::Union{Float64, Int64}) at /home/tor/.julia/packages/StatsFuns/zJ1EI/src/rmath.jl:77 | |
Stacktrace: | |
[1] (::var"#1#2")(λ::ForwardDiff.Dual{ForwardDiff.Tag{var"#1#2", Float64}, Float64, 1}) |
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
julia> using Turing, Random | |
julia> @model function gdemo(xs) | |
# Assumptions | |
σ² ~ InverseGamma(2, 3) | |
μ ~ Normal(0, √σ²) | |
# Observations | |
for i = 1:length(xs) | |
xs[i] ~ Normal(μ, √σ²) | |
end |
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
julia> using Turing | |
julia> include("utils.jl") | |
julia> @model function demo(xs) | |
s ~ InverseGamma(2, 3) | |
m ~ Normal(0, √s) | |
for i in eachindex(xs) | |
xs[i] ~ Normal(m, √s) | |
end |
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
julia> using Bijectors | |
julia> using ForwardDiff | |
julia> using ComponentArrays, UnPack | |
julia> using Bijectors: LeakyReLU, Shift, Scale | |
julia> # Affine transformation is simply a `Scale` composed with `Shift` | |
using Bijectors: Shift, Scale |
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
julia> using ArviZ, Turing | |
julia> J = 8; | |
julia> y = [28.0, 8.0, -3.0, 7.0, -1.0, 1.0, 18.0, 12.0]; | |
julia> σ = [15.0, 10.0, 16.0, 11.0, 9.0, 11.0, 10.0, 18.0]; | |
julia> schools = [ | |
"Choate", |
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
using Turing | |
using TensorBoardLogger, Logging | |
using OnlineStats # used to compute different statistics on-the-fly | |
using StatsBase # Provides us with the `Histogram` which is supported by `TensorBoardLogger.jl` | |
using LinearAlgebra | |
using DataStructures # will use a `CircularBuffer` to only keep track of some `n` last samples | |
struct TBCallback | |
logger::TBLogger | |
end |
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
julia> using Random | |
julia> using Turing | |
julia> rng = MersenneTwister(42); | |
julia> @model function demo(x) | |
s ~ InverseGamma(2, 3) | |
m ~ Normal(0, √s) | |
for i in eachindex(x) |