我正在尝试调用scipy.optimize.minimize
以最小化函数poissonNegLogLikelihood
,该函数定义如下:
def poissonNegLogLikelihood(lam, y):
Computes the negative log-likelihood for a Poisson random variable.
Inputs:
lam - float or array. Parameter for the poisson distribution.
y - float or array. Observed data.
Outputs:
log_lik - float. The negative log-likelihood for the data (y) with parameter (lam).
Y = np.atleast_1d(y)
LAM = np.atleast_1d(lam)
log_lik = -np.sum(np.multiply(Y,np.log(LAM)) - gammaln(Y+1) - LAM)
return log_lik
这个函数工作正常,但是当我尝试将它用作它的输入时,scipy.optimize.minimize
它返回 [inf]。这就是我传递它的方式:
data = np.array([1.0])
betas = np.array([0])
minimize(poissonNegLogLikelihood,betas,args=(data),jac=False)
我是否使用了scipy.optimize.minimize
错误的功能?