Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _multicomplex2(f, fx, x, h, *args, **kwds):
z = bicomplex(x + 1j * h, h)
return f(z, *args, **kwds).imag12
def _multicomplex2(f, fx, x, h, *args, **kwargs):
'''Calculate Hessian with bicomplex-step derivative approximation
'''
n = len(x)
ee = np.diag(h)
hess = np.outer(h, h)
for i in range(n):
for j in range(i, n):
zph = bicomplex(x + 1j * ee[i, :], ee[j, :])
hess[i, j] = (f(zph, *args, **kwargs)).imag12 / hess[j, i]
hess[j, i] = hess[i, j]
return hess
def _multicomplex2(f, fx, x, h, *args, **kwds):
n = len(x)
increments = np.identity(n) * h
partials = [f(bicomplex(x + 1j * hi, hi), *args, **kwds).imag12
for hi in increments]
return np.array(partials)
def _multicomplex(f, fx, x, h, *args, **kwds):
n = len(x)
increments = np.identity(n) * 1j * h
partials = [f(bicomplex(x + hi, 0), *args, **kwds).imag
for hi in increments]
return np.array(partials).T
def _multicomplex(f, fx, x, h, *args, **kwds):
z = bicomplex(x + 1j * h, 0)
return f(z, *args, **kwds).imag