0
votes

I use PyMC to implement a multinomial-dirichlet pair. I want to MAP the model for all the instances that we have. The issue I face is that once MAP.fit() the prior distribution is changed. Thus, for every new instance, I need to have a new prior distribution, which should be fine. However, I keep seeing this error:

Traceback (most recent call last):
  File "/Users/xingweiy/Project/StarRating/TimePlot/BayesianPrediction/DiricheletMultinomialStarRating.py", line 41, in <module>
    prediction = predict.predict(input,prior)
  File "/Users/xingweiy/Project/StarRating/TimePlot/BayesianPrediction/predict.py", line 12, in predict
    likelihood = pm.Categorical('rating',prior,value = exp_data,observed = True)
  File "/Library/Python/2.7/site-packages/pymc-2.3.4-py2.7-macosx-10.9-intel.egg/pymc/distributions.py", line 3170, in __init__
    verbose=verbose, **kwds)
  File "/Library/Python/2.7/site-packages/pymc-2.3.4-py2.7-macosx-10.9-intel.egg/pymc/PyMCObjects.py", line 772, in __init__
    if not isinstance(self.logp, float):
  File "/Library/Python/2.7/site-packages/pymc-2.3.4-py2.7-macosx-10.9-intel.egg/pymc/PyMCObjects.py", line 929, in get_logp
    raise ZeroProbability(self.errmsg)
pymc.Node.ZeroProbability: Stochastic rating's value is outside its support,
 or it forbids its parents' current values.

Here is the code:

alpha= np.array([0.1,0.1,0.1,0.1,0.1])
prior = pm.Dirichlet('prior',alpha)
exp_data = np.array(input)
likelihood = pm.Categorical('rating',prior,value = exp_data,observed = True)
MaximumPosterior = inf.inference(prior, likelihood, exp_data)

def inference(prior,likelihood,observation):
    model = Model({'likelihood':likelihood,'prior':prior})
    M = MAP(model)
    M.fit()
    result = M.prior.value
    result = np.append(result,1- np.sum(M.prior.value))
    return result

I think it is a bug of pymc package. Is there any way to do MAP without changing the prior distribution?

Thanks

The answer in the link below solved my issue:

https://groups.google.com/forum/#!topic/pymc/uYQSGW4acf8

1
Could you show your model input? - FuzzyDuck
It is just a list of integers, e.g. [1,5,1,5,3,4]. Each instance is a list of integers between 1 to 10. But the size of the list may be different. - user2547081
BTW, if I do not provide a new prior for every instance, the program could run without any problem. However, the results are wrong since the prior distribution is changed after MAP.fit() - user2547081
It will be easier for us to reproduce your error if you show the full code. - FuzzyDuck

1 Answers

0
votes

Basically, the dirichlet distribution generates probability that is close to 0.

The link below solved my issue: https://groups.google.com/forum/#!topic/pymc/uYQSGW4acf8