Skip to content

Commit f960362

Browse files
committed
fixes
1 parent 544016d commit f960362

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

models/dppl_hmm_semisup.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ end
5353
end
5454
gamma .= temp_gamma
5555
end
56-
DynamicPPL.@addlogprob! logsumexp(gamma)
56+
@addlogprob! logsumexp(gamma)
5757
end
5858

5959
model = dppl_hmm_semisup(K, T, T_unsup, w, z, u, alpha, beta)

models/dppl_lda.jl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@ theta = rand(Dirichlet(alpha), m)
99
doc_lengths = rand(Poisson(1_000), m)
1010
n = sum(doc_lengths)
1111

12-
w_lda = Vector{Int}(undef, n)
13-
doc_lda = Vector{Int}(undef, n)
12+
w = Vector{Int}(undef, n)
13+
doc = Vector{Int}(undef, n)
1414
for i in 1:m
15-
# Because all the models exist in the same scope, we need
16-
# to add some variable suffixes to avoid local/global
17-
# scope warnings. This is quite ugly and should be solved
18-
# properly, using e.g. modules or functions.
19-
local idx_lda = sum(doc_lengths[1:i-1]) # starting index for inner loop
15+
local idx = sum(doc_lengths[1:i-1]) # starting index for inner loop
2016
for j in 1:doc_lengths[i]
21-
z_lda = rand(Categorical(theta[:, i]))
22-
w_lda[idx_lda + j] = rand(Categorical(phi[:, z_lda]))
23-
doc_lda[idx_lda + j] = i
17+
z = rand(Categorical(theta[:, i]))
18+
w[idx + j] = rand(Categorical(phi[:, z]))
19+
doc[idx + j] = i
2420
end
2521
end
2622

2723
@model function dppl_lda(k, m, w, doc, alpha, beta)
2824
theta ~ filldist(Dirichlet(alpha), m)
2925
phi ~ filldist(Dirichlet(beta), k)
3026
log_phi_dot_theta = log.(phi * theta)
31-
DynamicPPL.@addlogprob! sum(log_phi_dot_theta[CartesianIndex.(w, doc)])
27+
@addlogprob! sum(log_phi_dot_theta[CartesianIndex.(w, doc)])
3228
end
3329

34-
model = dppl_lda(k, m, w_lda, doc_lda, alpha, beta)
30+
model = dppl_lda(k, m, w, doc, alpha, beta)

0 commit comments

Comments
 (0)