I'm observing discrete histories counts: f in N^b. They are generated by a latent, hidden multinomial process with more categories than observable histories. We considered x in N^a (a > b) the counts from the latent process as parameters to fit.
f is a deterministic function of x that I know. I also know the expression of each cell probability for x: pi in [0,1]^a. So it seems natural to me to write:
x ~ dmulti(pi,a)
But x is not totally free in N^a since it must respect a certain number of constraint to keep consistent with the data f.
We worked out a certain number of degrees of freedom for x: d in N^c (a > c), that can be freely drawn from a certain distribution D without conflicting with f. x can then be deterministically rebuilt from any d. So it also seems natural to me to write:
d ~ D()
x <- rebuildX(d)
But of course, I'm getting an overlap error:
Node X[] overlaps previously defined nodes.
I think that I can't define a single node with 2 different properties in JAGS, which makes sense.
Is there any idiom I should use in this case?
Last edit: Iago-lito 2015-03-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What you need here is an observable function. There are two existing observable functions provided by JAGS. One is dinterval for censored data and the other is dsum for when you observe the sum of two or more latent random variables.
An observable function behave like a function (in that the left hand side of a relation is a deterministic function of the parameters on the right hand side) but also like a distribution (they generate a likelihood). It may need a special sampler to jointly update the latent variables while preserving the constraints imposed by the observable function. This is true for dsum which has two special samplers: one for discrete and one for continuous data.
So it's complicated. If your rebuildX function says that x[i] is a sum of elements of d then you might be able to use dsum. Otherwise this seems a little bit beyond the capabilities of JAGS.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I wrote a small module to implement in JAGS the custom discrete distribution I need: sampling from a convex, multivariate polytope. JAGS's extensibility philosophy helped a lot, and the paper from Wabersich et al. as well. Thank you first for all the features JAGS provides.
There is not yet any way to do this sampling directly, but I managed to approximate it by running a small Gibbs chain each time the randomSample function is called, storing the intermediate results somewhere else in memory in order to respect its const signature.
I can then write in JAGS:
d ~ dLRBPolytope(L.f, R.f, gibbsSteps, warmupSteps)
.. and JAGS will generate uniform samples from the polytope (this amazes me and it's really fast!).
But when I try to write my full model..
(d is the information needed to build my latent variable X, supposed to come from a multinomial process)
(since the observable function I would need doesn't exist yet (too specific I think), I use the Poisson trick)
d ~ dLRBPolytope(L.f, R.f, gibbsSteps, warmupSteps)
X <- rebuiltX(d)
Ln.Likelihood <- MultinomialLikelihood(X)
lambda <- HighConstant - Ln.Likelihood
PoissonTrick ~ dpois(lambda)# given as data as zero
I get the following error:
Unable to find appropriate sampler
Does this really mean I need to write a custom SamplerFactory as well? If yes, where can I find any documentation about this?
Thank you again for your kind answers so far :)
Last edit: Iago-lito 2015-04-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm observing discrete histories counts: f in N^b. They are generated by a latent, hidden multinomial process with more categories than observable histories. We considered x in N^a (a > b) the counts from the latent process as parameters to fit.
f is a deterministic function of x that I know. I also know the expression of each cell probability for x: pi in [0,1]^a. So it seems natural to me to write:
But x is not totally free in N^a since it must respect a certain number of constraint to keep consistent with the data f.
We worked out a certain number of degrees of freedom for x: d in N^c (a > c), that can be freely drawn from a certain distribution D without conflicting with f. x can then be deterministically rebuilt from any d. So it also seems natural to me to write:
But of course, I'm getting an overlap error:
I think that I can't define a single node with 2 different properties in JAGS, which makes sense.
Is there any idiom I should use in this case?
Last edit: Iago-lito 2015-03-24
What you need here is an observable function. There are two existing observable functions provided by JAGS. One is
dinterval
for censored data and the other isdsum
for when you observe the sum of two or more latent random variables.An observable function behave like a function (in that the left hand side of a relation is a deterministic function of the parameters on the right hand side) but also like a distribution (they generate a likelihood). It may need a special sampler to jointly update the latent variables while preserving the constraints imposed by the observable function. This is true for
dsum
which has two special samplers: one for discrete and one for continuous data.So it's complicated. If your
rebuildX
function says thatx[i]
is a sum of elements ofd
then you might be able to usedsum
. Otherwise this seems a little bit beyond the capabilities of JAGS.I wrote a small module to implement in JAGS the custom discrete distribution I need: sampling from a convex, multivariate polytope. JAGS's extensibility philosophy helped a lot, and the paper from Wabersich et al. as well. Thank you first for all the features JAGS provides.
There is not yet any way to do this sampling directly, but I managed to approximate it by running a small Gibbs chain each time the
randomSample
function is called, storing the intermediate results somewhere else in memory in order to respect itsconst
signature.I can then write in JAGS:
.. and JAGS will generate uniform samples from the polytope (this amazes me and it's really fast!).
But when I try to write my full model..
(d is the information needed to build my latent variable X, supposed to come from a multinomial process)
(since the observable function I would need doesn't exist yet (too specific I think), I use the Poisson trick)
I get the following error:
Does this really mean I need to write a custom SamplerFactory as well? If yes, where can I find any documentation about this?
Thank you again for your kind answers so far :)
Last edit: Iago-lito 2015-04-07