In the paper, they discuss a Gibbs sampler implementation but I would like to specify this in a Julia PPL. Hereās how far I got in Turing (probably very non-optimized):
@model function MRREM(X, y)
N, A, K = size(X)
Ī² ~ filldist(Normal(0, 1), K)
Ļc ~ Exponential()
Īø = [@views X[i,:,:] * Ī² for i in 1:N]
z ~ arraydist([MvNormal(t, I) for t in Īø])
zmax = maximum(z, dims=1) |> vec
c ~ arraydist([Truncated(Normal(0, Ļc), -Inf, zm) for zm in zmax])
# y ~ ???
end
let
N, A, k = 100, 20, 3
X = rand(N, A, k)
MRREM(X, missing) |> rand
end
But I donāt really know how to specify the ifelse for the y_{ir} in a PPL or how to transform this into something that you can sample from / evaluate the logdensity of. Does someone know what to do here?
Itās pretty typical for PPLs to have difficulty āobservingā deterministic functions of a distribution. I think the standard way to do this would be to integrate out c, so each y[i] follows a Bernoulli distribution as a function of Ļc and zmax[i].
You could write this in the model itself, or (in Soss or Tilde) build a new measure to express this, then use that measure in the model. The advantage of this is that you can test the measure independently and do any performance doing in isolation.
Thanks, @cscherrer. That sounded like more math than Iām comfortable with but luckily I found that further down in the paper they give a specification of the probability of the y_{ir}'s as:
Btw., I remember seeing something about truncated measures in MeasureTheory but couldnāt find it anymore. Is there something I overlooked or is there anything planned?