Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DistributionsAD = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
Expand Down
3 changes: 2 additions & 1 deletion models/demo_assume_matrix_observe_matrix_index.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FillArrays
using LinearAlgebra: Diagonal

@model function demo_assume_matrix_observe_matrix_index(
Expand All @@ -6,7 +7,7 @@ using LinearAlgebra: Diagonal
) where {TV}
n = length(x)
d = n ÷ 2
s ~ reshape(product_distribution(fill(InverseGamma(2, 3), n)), d, 2)
s ~ reshape(product_distribution(Fill(InverseGamma(2, 3), n)), d, 2)
s_vec = vec(s)
m ~ MvNormal(zeros(n), Diagonal(s_vec))
x[:, 1] ~ MvNormal(m, Diagonal(s_vec))
Expand Down
4 changes: 3 additions & 1 deletion models/dppl_gauss_unknown.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using FillArrays

n = 10_000
s = abs(rand()) + 0.5
y = randn() .+ s * randn(n)
Expand All @@ -6,7 +8,7 @@ y = randn() .+ s * randn(n)
N = length(y)
m ~ Normal(0, 1)
s ~ truncated(Cauchy(0, 5); lower = 0)
y ~ product_distribution(fill(Normal(m, s), N))
y ~ product_distribution(Fill(Normal(m, s), N))
end

model = dppl_gauss_unknown(y)
3 changes: 2 additions & 1 deletion models/dppl_hier_poisson.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FillArrays
using Turing: LogPoisson

nd, ns = 5, 10
Expand All @@ -16,7 +17,7 @@ idx = repeat(collect(1:ns), inner = nd)
a0 ~ Normal(0, 10)
a1 ~ Normal(0, 1)
a0_sig ~ truncated(Cauchy(0, 1); lower = 0)
a0s ~ product_distribution(fill(Normal(0, a0_sig), ns))
a0s ~ product_distribution(Fill(Normal(0, a0_sig), ns))
alpha = a0 .+ a0s[idx] .+ a1 * x
y ~ product_distribution(LogPoisson.(alpha))
end
Expand Down
4 changes: 3 additions & 1 deletion models/dppl_high_dim_gauss.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using FillArrays

@model function dppl_high_dim_gauss(D)
m ~ product_distribution(fill(Normal(0, 1), D))
m ~ product_distribution(Fill(Normal(0, 1), D))
end

model = dppl_high_dim_gauss(10_000)
5 changes: 3 additions & 2 deletions models/dppl_hmm_semisup.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FillArrays
using StatsFuns: logsumexp

# Set up hyperparameters
Expand Down Expand Up @@ -28,8 +29,8 @@ for t = 2:T_unsup
end

@model function dppl_hmm_semisup(K, T, T_unsup, w, z, u, alpha, beta)
theta ~ product_distribution(fill(Dirichlet(alpha), K))
phi ~ product_distribution(fill(Dirichlet(beta), K))
theta ~ product_distribution(Fill(Dirichlet(alpha), K))
phi ~ product_distribution(Fill(Dirichlet(beta), K))
for t = 1:T
w[t] ~ Categorical(phi[:, z[t]])
end
Expand Down
6 changes: 4 additions & 2 deletions models/dppl_lda.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using FillArrays

v = 100 # words
k = 5 # topics
m = 10 # number of docs
Expand All @@ -21,8 +23,8 @@ for i = 1:m
end

@model function dppl_lda(k, m, w, doc, alpha, beta)
theta ~ product_distribution(fill(Dirichlet(alpha), m))
phi ~ product_distribution(fill(Dirichlet(beta), k))
theta ~ product_distribution(Fill(Dirichlet(alpha), m))
phi ~ product_distribution(Fill(Dirichlet(beta), k))
log_phi_dot_theta = log.(phi * theta)
@addlogprob! sum(log_phi_dot_theta[CartesianIndex.(w, doc)])
end
Expand Down
3 changes: 2 additions & 1 deletion models/dppl_naive_bayes.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FillArrays
using MLDatasets: MNIST
using MultivariateStats: fit, PCA, transform

Expand All @@ -20,7 +21,7 @@ image_vec = image_subset[:, :]
labels = labels[1:N]

@model function dppl_naive_bayes(image_vec, labels, C, D)
m ~ product_distribution(fill(Normal(0, 10), C, D))
m ~ product_distribution(Fill(Normal(0, 10), C, D))
image_vec ~ product_distribution(Normal.(m[labels, :]))
end

Expand Down
Loading