I have a function which takes a list of variables as an argument and I would like to minimize this function using scipy.optimize.minimize.
The problem is that it is decided on runtime for which variable in the argument list the minimization should be done. All other variables will get a fixed value.
Let's make an example to clarify:
a = 1
c = 1.1
d = -1.2
def func( b ):
return function_to_minimize( array=[a,b,c,d] )
sol = scipy.optimize.minimize( func, [b0], args=(a,c,d) )
This works, however, it could be that b, c and d are known and I want to optimize a to find the minimum solution.
To make it even more complicated, the length of the list is not known either. That means there could be a variabel e, f, g, ... and so on.
The actual notation is as follows. The element which is None is the one which should be optimized for.
array = [1, 1.1, None, -0.5, 4]
def func(arr):
return function_to_minimize(arr)
startvalue = 1.0
sol = scipy.optimize.minimize( func, [startvalue], args='Array without None' )
Is there a way to tell scipy.optimize.minimize for which element to optimize for? Is there perhaps a smart lambda trick which I could do?
I would really appreciate your help!