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

Commit

Permalink
fix truncated using lower keyword argument
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Jul 14, 2022
1 parent 5684e8d commit 287bacc
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions turing/11-hierarchical_varying_intercept-cheese.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ idx = cheese[:, :background_int]

# prior for variance of random intercepts
# usually requires thoughtful specification
τ ~ truncated(Cauchy(0, 2), 0, Inf) # group-level SDs intercepts
αⱼ ~ filldist(Normal(0, τ), n_gr) # group-level intercepts
τ ~ truncated(Cauchy(0, 2); lower=0) # group-level SDs intercepts
αⱼ ~ filldist(Normal(0, τ), n_gr) # group-level intercepts

# likelihood
y ~ MvNormal.+ αⱼ[idx] .+ X * β, σ^2 * I)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ idx = cheese[:, :background_int]

# prior for variance of random intercepts
# usually requires thoughtful specification
τ ~ truncated(Cauchy(0, 2), 0, Inf) # group-level SDs intercepts
zⱼ ~ filldist(Normal(0, 1), n_gr) # group-level non-centered intercepts
αⱼ = zⱼ .* τ # group-level intercepts
τ ~ truncated(Cauchy(0, 2); lower=0) # group-level SDs intercepts
zⱼ ~ filldist(Normal(0, 1), n_gr) # group-level non-centered intercepts
αⱼ = zⱼ .* τ # group-level intercepts

# likelihood
y ~ MvNormal.+ αⱼ[idx] .+ X * β, σ^2 * I)
Expand Down
4 changes: 2 additions & 2 deletions turing/12-hierarchical_varying_slope-cheese.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ idx = cheese[:, :background_int]

# prior for variance of random slopes
# usually requires thoughtful specification
τ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), n_gr) # group-level SDs slopes
βⱼ ~ arraydist([MvNormal(Diagonal(fill(τ[j], predictors).^2)) for j in 1:n_gr]) # group-level slopes
τ ~ filldist(truncated(Cauchy(0, 2); lower=0), n_gr) # group-level SDs slopes
βⱼ ~ arraydist([MvNormal(Diagonal(fill(τ[j], predictors).^2)) for j in 1:n_gr]) # group-level slopes

# likelihood
for i in 1:N
Expand Down
6 changes: 3 additions & 3 deletions turing/12-hierarchical_varying_slope-non_centered-cheese.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ idx = cheese[:, :background_int]

# prior for variance of random slopes
# usually requires thoughtful specification
τ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), n_gr) # group-level SDs slopes
Zⱼ ~ filldist(Normal(0, 1), predictors, n_gr) # group-level non-centered slopes
βⱼ = Zⱼ * τ # group-level slopes
τ ~ filldist(truncated(Cauchy(0, 2); lower=0), n_gr) # group-level SDs slopes
Zⱼ ~ filldist(Normal(0, 1), predictors, n_gr) # group-level non-centered slopes
βⱼ = Zⱼ * τ # group-level slopes

# likelihood
y ~ MvNormal.+ X * β .+ X * βⱼ, σ^2 * I)
Expand Down
4 changes: 2 additions & 2 deletions turing/13-hierarchical_varying_intercept_slope-cheese.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ idx = cheese[:, :background_int]

# prior for variance of random intercepts and slopes
# usually requires thoughtful specification
τₐ ~ truncated(Cauchy(0, 2), 0, Inf) # group-level SDs intercepts
τᵦ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), n_gr) # group-level SDs slopes
τₐ ~ truncated(Cauchy(0, 2); lower=0) # group-level SDs intercepts
τᵦ ~ filldist(truncated(Cauchy(0, 2); lower=0), n_gr) # group-level SDs slopes
αⱼ ~ filldist(Normal(0, τₐ), n_gr) # group-level intercepts
βⱼ ~ arraydist([MvNormal(Diagonal(fill(τᵦ[j], predictors).^2)) for j in 1:n_gr]) # group-level slopes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ idx = cheese[:, :background_int]

# prior for variance of random intercepts and slopes
# usually requires thoughtful specification
τₐ ~ truncated(Cauchy(0, 2), 0, Inf) # group-level SDs intercepts
τᵦ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), n_gr) # group-level SDs slopes
zⱼ ~ filldist(Normal(0, 1), n_gr) # group-level non-centered intercepts
Zⱼ ~ filldist(Normal(0, 1), predictors, n_gr) # group-level non-centered slopes
αⱼ = zⱼ .* τₐ # group-level intercepts
βⱼ = Zⱼ * τᵦ # group-level slopes
τₐ ~ truncated(Cauchy(0, 2); lower=0) # group-level SDs intercepts
τᵦ ~ filldist(truncated(Cauchy(0, 2); lower=0), n_gr) # group-level SDs slopes
zⱼ ~ filldist(Normal(0, 1), n_gr) # group-level non-centered intercepts
Zⱼ ~ filldist(Normal(0, 1), predictors, n_gr) # group-level non-centered slopes
αⱼ = zⱼ .* τₐ # group-level intercepts
βⱼ = Zⱼ * τᵦ # group-level slopes

# likelihood
y ~ MvNormal.+ αⱼ[idx] .+ X * β .+ X * βⱼ, σ^2 * I)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ idx = cheese[:, :background_int]

# # prior for variance of random intercepts and slopes
# # usually requires thoughtful specification
# τ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), predictors) # group-level SDs
# γ ~ filldist(Normal(0, 5), predictors, n_gr) # matrix of group coefficients
# Z ~ filldist(Normal(0, 1), predictors, n_gr) # matrix of non-centered group coefficients
# τ ~ filldist(truncated(Cauchy(0, 2); lower=0), predictors) # group-level SDs
# γ ~ filldist(Normal(0, 5), predictors, n_gr) # matrix of group coefficients
# Z ~ filldist(Normal(0, 1), predictors, n_gr) # matrix of non-centered group coefficients

# # reconstruct β from Ω and τ
# β = γ + τ .* Ω.L * Z
Expand Down Expand Up @@ -85,12 +85,12 @@ using PDMats

# prior for variance of random intercepts and slopes
# usually requires thoughtful specification
τ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), predictors) # group-level SDs
γ ~ filldist(Normal(0, 5), predictors, n_gr) # matrix of group coefficients
Z ~ filldist(Normal(0, 1), predictors, n_gr) # matrix of non-centered group coefficients
τ ~ filldist(truncated(Cauchy(0, 2); lower=0), predictors) # group-level SDs
γ ~ filldist(Normal(0, 5), predictors, n_gr) # matrix of group coefficients
Z ~ filldist(Normal(0, 1), predictors, n_gr) # matrix of non-centered group coefficients

# reconstruct β from Ω and τ
Ω_L = LowerTriangular(collect.* L_U')) # collect is necessary for ReverseDiff for some reason
Ω_L = LowerTriangular(collect.* L_U')) # collect is necessary for ReverseDiff for some reason
Ω = PDMat(Cholesky(Ω_L))
β = γ + Ω * Z

Expand Down

0 comments on commit 287bacc

Please sign in to comment.