PYMC MAP适合的问题

时间:2015-04-14 18:29:15

标签: python pymc

我使用PyMC来实现多项式 - dirichlet对。我想为我们拥有的所有实例映射模型。 我面临的问题是,一旦MAP.fit()改变了先前的分布。因此,对于每个新实例,我需要有一个新的先前分布,这应该没问题。但是,我一直看到这个错误:

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.

以下是代码:

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

我认为这是pymc包的错误。有没有办法在不改变先前分布的情况下进行MAP?

由于

以下链接中的答案解决了我的问题:

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

1 个答案:

答案 0 :(得分:0)

基本上,dirichlet分布产生的概率接近于0.

以下链接解决了我的问题: https://groups.google.com/forum/#!topic/pymc/uYQSGW4acf8