python - PYMC MAP Fit problems -
i use pymc implement multinomial-dirichlet pair. want map model instances have. issue face once map.fit() prior distribution changed. thus, every new instance, need have new prior distribution, should fine. however, keep seeing 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 outside support, or forbids parents' current values.
here 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 bug of pymc package. there way map without changing prior distribution?
thanks
the answer in link below solved issue:
basically, dirichlet distribution generates probability close 0.
the link below solved issue: https://groups.google.com/forum/#!topic/pymc/uyqsgw4acf8
Comments
Post a Comment