I am currently using scipy optimize.minimize to get the minimal value of a function with 5 parameters. I would like for four of the inputs to be put in as fixed parameters of the function and I would like the optimize.minimize to give me the value of the fifth input in order to get the lowest possible output from the function.
Here is the code I have currently:
from numpy import array
import scipy.optimize as optimize
from scipy.optimize import minimize
def objective(speed, params):
a,b,c,d=params
return abs(rg.predict([[speed,params]]))
p0=np.array([[98.3,46.9,119.9,59.1]])
x0=np.array([[4]])
result = optimize.minimize(objective, x0, args=(p0,),method='nelder-mead')
print(result.x)
I am looking for a way to be able to pass a list or array of the fixed parameters inside of the optimize.minimize function. However the above code gives me this error:
ValueError: not enough values to unpack (expected 4, got 1)
The only way I can seem to make it work is to hard code in the inputs like this:
def objective(params):
a=100
b=20
c=119.9
d=params
e=59.1
return abs(rg.predict([[a,b,c,d,e]]))
x0=np.array([[4.5]])
result = optimize.minimize(objective, x0, method='nelder-mead')
print(result.x)
Am I approaching this in the correct way? How can I pass in a list or array as fixed inputs?