I attempt the following multiple integral in the code below for a higher-than-bivariate version (n=2
) of a copula density function, c(u1,u2)
. In other words, n>2
dimensions.
import numpy as np
from scipy import integrate
def H(theta):
c = lambda *us: ((1+theta)*np.prod(*us)**(-1-theta)) * (np.sum(*us **(-theta))-1)**(-1/theta-2)
return -integrate.nquad(
func = lambda *us : c(*us)*np.log(c(*us)),
ranges = (0,1)**n,
args = (theta,)
)[0]
theta, n = 1, 3
print(H(theta))
where *us
represents the arbitrary number of u
's I can pass in. The second input argument to integrate.nquad
, which is ranges=(0,1)**n
, is the [0,1] support of the integral due to n
dimensions of u
's, which I try to explain in the derivation above. However, this part of the code gives the following error.
TypeError: unsupported operand type(s) for ** or pow(): 'tuple' and 'int'
If I change this input to ranges=(0,1)
by removing the exponent n
as suggested by the error, then I get a different error:
How am I really supposed to declare the [(0,1)**n]
support for a multiple integral in integrate.nquad
? The documentation does not give a matching example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…