【发布时间】:2021-04-16 01:57:47
【问题描述】:
下面的代码使用与scipy.integrate.dblquad 的双重积分来计算copula 密度函数c 的微分熵c*np.log(c),该函数有一个依赖参数theta,通常为正。公式可以找到here。
import numpy as np
from scipy import integrate
def copula_entropy(theta):
c = lambda v, u: ((1+theta)*(u*v)**(-1-theta)) * (u**(-theta)
+ v**(-theta) -1)**(-1/theta-2)
return -integrate.dblquad(c*np.log(c), 0, 1, lambda u: 0, lambda u: 1)[0]
调用函数
copula_entropy(1)
返回错误
TypeError: loop of ufunc does not support argument 0 of type function which has no callable log method
如何使该功能起作用?
【问题讨论】:
-
不知道是否重要,但
((1+theta)*(u*v)**(-1-theta)) * (u*(-theta) + v*(-theta) -1)**(-1/theta)似乎与 c(u, v) 的公式不匹配。 -
哦,最后缺少
-2,谢谢 -
嗯,它还有
u*(-theta)和v*(-theta)而不是u**(-theta)和v**(-theta)。
标签: python scipy statistics integral entropy