PyMC: Getting zero or close-to-zero Categorical likelihood

萝らか妹 提交于 2019-12-05 17:47:22
Delphine

I figured out the problem was the difference between Categorical distribution and Multinomial distribution. I had struggled on finding the actual difference between the two and finally found it here:

The categorical distribution is equivalent to a multinomial distribution with the number of trials equal to one.

Therefore, the Categorical likelihood has only probabilities of the different outcomes as a parameter, and takes frequencies as observed data.

On the other hand, the Multinomial distribution takes the probabilities of the different outcomes AND the number of trials as parameters, and takes number of observations per outcome as data.

The following code works as I expected:

data=np.array([33,66,1])
rates=pymc.Uniform('rates',0,100,size=4,value=[0.01,2,10,1])

@pymc.deterministic
def prob(rates=rates):
    return np.array([0.33,0.66,0.01])

likelihood=pymc.Multinomial('likelihood',n=sum(data),p=prob,value=data,observed=True)

And the two following probabilities are very similar:

pymc.categorical_like(data/data.sum(),prob.value)
pymc.multinomial_like(data,sum(data),prob.value)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!