我定义了以下函数:def GMM(s1, s2, s3, s4, s5, a):
"""The GMM objective function.
Arguments
---------
si: float
standard deviations of preference distribution
a: float
marginal utility of residutal income
Paramters
---------
Px: array (1,ns)
projector onto nonprice characteristic space
xk, z: arrays (J, 5) and (J, 12)
nonprice char. and instruments
invW: array (12, 12)
GMM weight matrix
Returns
-------
float."""
delta = invert(s1, s2, s3, s4, s5, a, delta0) # Invert market shares to get mean utility
bmean = np.dot(Px, delta) # Project delta onto charancteristic space
xihat = delta - np.dot(xk, bmean) # Compute implied unobservable prod. quality
temp1 = np.dot(xihat.T, z)
if np.any(np.isnan(delta)) == True:
value = 1e+10
else:
value = np.dot(np.dot(temp1, invW), temp1.T)
return np.sqrt(value)
我的问题与函数内部绑定的变量delta有关。在函数之外,我将设置delta0的初始值。现在,最终我将最小化这个函数。我希望每次函数GMM求值时,delta将使用上一个求值中的delta0作为新的delta0。我试图将delta0定义为全局变量,但它似乎不起作用。。。可能这是我的错误。不过,我在这里读到过,一般来说,这是一种不好的方法。有什么建议吗?