I'm working with scipy.optimize
library.
In the adjoint variable method, some of the resulted values from the objective function are needed to compute the jacobian.
Is that possible to use them in the jacobian function without using global
variables?
For example,
def fun(x):
'''
something, something...
'''
# solving system equation.
u = spsolve(K,f)
return u.dot(f)
def jac(x):
'''
something, something...
'''
# computing jacobian using the adjoint method
return -(u.T@K@u).flatten()
In the jac
function, u
and K
are necessary...
How can I do this?