Skip to content

Commit

Permalink
Support arrays in Gibbs
Browse files Browse the repository at this point in the history
  • Loading branch information
xukai92 committed Mar 9, 2017
1 parent 1f5b78c commit b5dd73e
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/samplers/support/gibbs_helper.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
function update(varInfo, samples, space)
for var in keys(varInfo)
if var.sym in space
dist = varInfo.dists[var]
s = samples[var.sym]
v = link(dist, s)
val = vectorize(dist, v)
varInfo.values[var] = val
vars = collect(keys(varInfo))
syms = keys(samples.value)
for sym in syms
if sym in space
if isa(samples.value[sym], Real)
var = filter(v -> v.uid == Symbol("$sym"), vars)[1]
dist = varInfo.dists[var]
s = samples.value[sym]
v = link(dist, s)
val = vectorize(dist, v)
varInfo.values[var] = val
else isa(samples.value[sym], Array)
s = samples.value[sym]
for i = 1:length(s)
var = filter(v -> v.uid == Symbol("$sym[$i]"), vars)[1]
dist = varInfo.dists[var]
v = link(dist, s[i])
val = vectorize(dist, v)
varInfo.values[var] = val
end
end
end
end
varInfo
Expand All @@ -18,7 +32,14 @@ function varInfo2samples(varInfo)
val = varInfo[var]
val = reconstruct(dist, val)
val = invlink(dist, val)
samples[var.sym] = val
if ~(var.sym in keys(samples))
samples[var.sym] = val
else
if length(samples[var.sym]) == 1
samples[var.sym] = [samples[var.sym]]
end
push!(samples[var.sym], val)
end
end
samples
end

0 comments on commit b5dd73e

Please sign in to comment.