I have a objective function, say obj(x, arg_1, arg_2)
within f()
, I have variable_3 = f(x, arg_1, arg_2)
obj()
will return abs(x-variable_3)
I need to minimize the returned value of obj()
using scipy.optimize.minimize
I guess I need to do it like this:
def obj(x, arg_1, arg_2)
v_3 = f(x, arg_1, arg_2)
return abs(x-v_3)
x0 = 1
result = minimize(obj, x0, args = (arg_1, arg_2))
Is this correct? Why I alwasy get errors?
Alternatively, actually I can do it in this way:
def obj(x, v_3)
return abs(x-v_3)
def myfun(arg_1, arg_2)
x0 = 1
v_3 = f(x0, arg_1, arg_2)
result = minimize(obj, x0, args = v_3)
return result
But obviously, this is what I want. So could somebody tell me how to do this minimization? Thanks