Hi.
I’m trying to create a model in which the shape of a distribution relies on the posteriori of a discrete random variable. I have done this before in a statistics class using the law of iterated expectation, but I’m wondering if this is going to work in PyMC.
Here is a somewhat simplified example of what I’m trying to achieve:
obs1 = 3
obs2 = 10
with pm.Model() as mod:
K = pm.Geometric("K", 1/10) # Variable specifing the length of M
like = pm.Binomial("like", p=0.5, n=K, observed=obs1)
M = pm.Normal("M", mu=0, sigma=1, size=(K,))
N = pm.Normal("N", mu=at.sum(M), sigma=1, observed=obs2)
idata = pm.sample()
But this yields a Value Error:
ValueError: Bad shape in start point:
Expected shape (8,) for var 'M', got: (10,)
I have the impression that PyMC initializes K to the expected value from the Geometric distribution, then sets this as the length of M. Then, when the sampling starts this yields the given error.
I am wondering if this is possible, and if not, if anyone can think of a workaround.
Any help is appreciated!