0
我使用PyMC來實現多項 - 迪裏克萊對。我想爲所有的實例映射模型。 我面臨的問題是,一旦MAP.fit()先前的分佈發生了變化。因此,對於每一個新實例,我都需要有一個新的事先分配,這應該沒問題。但是,我總是看到這樣的錯誤:PYMC MAP適合問題
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
您能否顯示您的模型輸入? – FuzzyDuck
它只是一個整數列表,例如[1,5,1,5,3,4]。每個實例都是1到10之間的整數列表。但列表的大小可能不同。 – user2547081
順便說一句,如果我沒有提供每個實例的新的優先事項,該程序可以毫無問題地運行。但是,結果是錯誤的,因爲先前的分佈在MAP.fit() – user2547081