Skip to content

Commit

Permalink
Change LDA to new syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong Ge committed May 2, 2017
1 parent f4d69f9 commit de0bfdf
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions benchmarks/lda.model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
# }
# }

@model ldamodel(K, V, M, N, w, doc, alpha, beta) = begin
@model ldamodel(K, V, M, N, w, doc, beta, alpha) = begin
theta = Vector{Vector{Real}}(M)
for m = 1:M
theta[m] ~ Dirichlet(alpha)
end

phi = Vector{Vector{Real}}(K)
for k = 1:K
phi[k] ~ Dirichlet(β)
phi[k] ~ Dirichlet(beta)
end

# z = tzeros(Int, N)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/lda.run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include("benchmarkhelper.jl")
include("lda-stan.data.jl")
include("lda.model.jl")

bench_res = tbenchmark("HMCDA(300, 0.65, 1.5)", "ldamodel", "ldastandata[1]")
bench_res = tbenchmark("HMCDA(300, 0.65, 1.5)", "ldamodel", "data=ldastandata[1]")
bench_res[4].names = ["phi[1]", "phi[2]"]
logd = build_logd("LDA", bench_res...)

Expand Down
4 changes: 3 additions & 1 deletion src/Turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ doc"""
Debugging print function: The first argument controls the verbosity of message, e.g. larger v leads to more verbose debugging messages.
"""
dprintln(v, args...) = v < Turing.VERBOSITY ? println("\r[Turing]: ", args..., "\n $(stacktrace()[2])") : nothing
dwarn(v, args...) = v < Turing.VERBOSITY ? print_with_color(:red, "\r[Turing]: ", mapreduce(string,*,args), "\n $(stacktrace()[2])\n") : nothing
dwarn(v, args...) = v < Turing.VERBOSITY ? print_with_color(:red, "\r[Turing.WARNING]: ", mapreduce(string,*,args), "\n $(stacktrace()[2])\n") : nothing
derror(v, args...) = error("\r[Turing.ERROR]: ", mapreduce(string,*,args))


global FCOMPILER = 1

Expand Down
5 changes: 3 additions & 2 deletions src/core/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@ macro model(fexpr)
end
if _k != nothing
_k_str = string(_k)
dprintln(1, _k_str, " = ", _k)
_ = quote
if haskey(data, keytype(data)($_k_str))
if nothing != $_k
warn(" parameter "*$_k_str*" found twice, value in data dictionary will be used.")
Turing.dwarn(0, " parameter "*$_k_str*" found twice, value in data dictionary will be used.")
end
else
data[keytype(data)($_k_str)] = $_k
data[keytype(data)($_k_str)] == nothing && error(" data "*$_k_str*" is not provided.")
data[keytype(data)($_k_str)] == nothing && Turing.derror(0, "Data `"*$_k_str*"` is not provided.")
end
end
unshift!(fdefn_outer.args[2].args, _)
Expand Down

0 comments on commit de0bfdf

Please sign in to comment.