Dear all,
I want to sample_prior_predictive from pm.Categorical with p as a vector, but it gives me only one sample rathar than an array of samples.
For example, the code:
P = [[.5,.5,0],[0,.01,.99]]
with pm.Model() as model:
output = pm.Categorical('output',p=P,shape=(2,))
sampling = pm.sample_prior_predictive(5)
sampling['output']
gives only:
array([1, 2])
However, the use of only one P gives an expected result:
P = [.5,.5,0]
with pm.Model() as model:
output = pm.Categorical('output',p=P)
sampling = pm.sample_prior_predictive(5)
sampling['output']
the output:
array([0, 1, 1, 1, 1])
As a workaround, I can of course try to implement a for-loop in my pm.Model and loop over all Ps, but it would not look very nice. Alternativale, pm.Multinomial provides the desired result:
P = [[.5,.5,0],[0,.01,.99]]
with pm.Model() as model:
output = pm.Multinomial('output',n=1,p=P,shape=(2,3))
sampling = pm.sample_prior_predictive(5)
[(np.flatnonzero(x)%3).tolist() for x in sampling['output']]
with output:
[[1, 2], [1, 2], [0, 2], [1, 2], [1, 2]]
but again it looks less nicer as it would be with one-line Categorical.
Could you please point out on my mistake in the first code-snippet? Thanks in advance.