Open finf281 opened 4 years ago
This is unfortuanitely not easy to fix at the moment. (I think.)
Here is a slightly hacky solution to the problem:
@model function hmm(yobs, obsidx, K, N, ::Type{Ty} = Float64) where {Ty}
ymis = Vector{Ty}(undef, N-length(obsidx))
# State sequence.
s = tzeros(Int, N)
# Emission matrix.
m ~ arraydist([Normal(i, 0.5) for i in 1:K])
# Transition matrix.
T ~ filldist(Dirichlet(K, 1/K), K)
jo, jm = 1, 1
# Observe each point of the input.
s[1] ~ Categorical(K)
dist = Normal(m[s[1]], 0.1)
if 1 ∈ obsidx
yobs[jo] ~ dist
jo += 1
else
ymis[jm] ~ dist
jm += 1
end
for i = 2:N
s[i] ~ Categorical(T[:,s[i-1]])
dist = Normal(m[s[i]], 0.1)
if i ∈ obsidx
yobs[jo] ~ dist
jo += 1
else
ymis[jm] ~ dist
jm += 1
end
end
end
y = [ 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, missing, 3.0, 3.0, 2.0, 2.0, 2.0, 1.0, 1.0 ];
N, K = length(y), 3;
obsidx = findall(!ismissing, y)
yobs = y[obsidx]
m = hmm(yobs, obsidx, K, N)
g = Gibbs(HMC(0.01, 5, :m, :T, :ymis), PG(10, :s))
c = sample(m, g, 100);
If we take the HMM Example from the tutorials section of this project's documentation, everything works as expected. However, if we set one of the values in the generated y data vector to missing, we get a Malformed dims error on the creation of a TArray.