PyMC:获得零或接近零的分类可能性 [英] PyMC: Getting zero or close-to-zero Categorical likelihood

查看:126
本文介绍了PyMC:获得零或接近零的分类可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据随机Petri网模型估算费率。我不明白为什么,但是即使在给定我为速率定义的初始值的情况下,将数据数据精确地与预期的观察次数相对应的情况下,也会出现ZeroProbability错误。

I am trying to estimate rates from a stochastic Petri Net model. I don't understand why, but I get a ZeroProbability Error, even when making up data data to correspond exactly to the expected number of observations given the initial values I define for the rates.

例如,以下比率[0.01,2,10,1]对应于3种不同结果[0.33,0.66,0.01]的概率。如果我观察到100个结果,我希望观察到[33、66、1]属于每个结果。

For example, the following rates [0.01, 2, 10, 1] correpond to a probability of 3 different outcomes of [0.33, 0.66, 0.01]. If I observed, 100 outcomes, I would expect to observe that [33, 66, 1] fall within each of the outcomes.

但是,如果我运行以下模型,我收到了ZeroProbability错误(我正在简化prob函数,该函数连接到更大的代码):

Yet if I run the following model, I get a ZeroProbability Error (I'm simplifying the prob function, which connects to a much larger piece of code):

data=[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.Categorical('likelihood',p=prob,value=data,observed=True)

调用pymc。 categorical_like(data,prob.value)返回-1.8 e308 ...

Calling pymc.categorical_like(data,prob.value) returns -1.8 e308...

我缺少什么?

推荐答案

我发现问题出在分类分布和多项式分布之间。我一直在努力寻找两者之间的实际差异,最后在此处找到了

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:


分类分布等于试验次数等于1的多项式分布。

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)

这篇关于PyMC:获得零或接近零的分类可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆