def log_likelihood(self,x,r=None,p=None):
r = r if r is not None else self.r
p = p if p is not None else self.p
x = np.array(x,ndmin=1)
if self.p > 0:
xnn = x[x >= 0]
raw = np.empty(x.shape)
raw[x>=0] = special.gammaln(r + xnn) - special.gammaln(r) \
- special.gammaln(xnn+1) + r*np.log(1-p) + xnn*np.log(p)
raw[x<0] = -np.inf
return raw if isinstance(x,np.ndarray) else raw[0]
else:
raw = np.log(np.zeros(x.shape))
raw[x == 0] = 0.
return raw if isinstance(x,np.ndarray) else raw[0]
评论列表
文章目录