我想最大化theta参数的似然函数。似然函数定义为:
from scipy.optimize import minimize
def prloglik(theta,n,r):
N=theta;k=len(n)
ar1=np.sum(np.log(np.array(range(N))+1))
ar2=np.sum(n)*np.log(np.sum(n)/(k*N))
ar3=(k*N-np.sum(n))*np.log(1-(np.sum(n))/(k*N))
par=np.sum(np.log(np.array(range(N-r))+1))
return(-(ar1+ar2+ar3-par))
我用:
res=minimize(prloglik,1000,method='BFGS',args=(nn,962))
nn
是一个numpy数组。我收到了这个错误:
TypeError: only integer arrays with one element can be converted to an index
任何人都可以帮助我吗?
答案 0 :(得分:0)
好的,我找到了解决方案而不是:
select Team_id, sum(Game_count) as 'Game_count'
from (
select Team_1 as 'Team_id', count(*) as 'Game_count'
from games
group by Team_1
union all
select Team_2, count(*)
from games
group by Team_2
) as q
我把
np.sum(np.log(np.array(range(N))+1))
而不是
math.lgamma(N+1)
我把
np.sum(np.log(np.array(range(N-r))+1))
但它同样的事情,分别是因子N和N-r的对数,我不明白为什么它不接受我以前的方式。