What is the exact format I need to use to define a two parameter function to optimize. For instance:
def func(var_1, var_2):
return var_1**2 + var_2**2
domain = [{'name': 'var_1', 'type': 'continuous', 'domain': (-1, 1)},
{'name': 'var_2', 'type': 'continuous', 'domain': (-1, 1)}]
BO = GPyOpt.methods.BayesianOptimization(f=func, domain = domain)
returns the error:
func() missing 1 required positional argument: 'var_2'
Thanks.
Hi, the objective function should take as input and output numpy arrays. That's why you are getting the error (you have the two variables as separated arguments).
Javier
I'll close this one but please re-open if it is not clear.
Thanks for your answer. I am still unable to get this right:
def func(x):
return np.array([x[0]**2+x[1]**2])
domain = [{'name': 'var_1', 'type': 'continuous', 'domain': (-1, 1)},
{'name': 'var_2', 'type': 'continuous', 'domain': (-1, 1)}]
BO = GPyOpt.methods.BayesianOptimization(f=func, domain = domain)
returns the error:
IndexError: index 1 is out of bounds for axis 0 with size 1
Hi, the problem is in the input and output of the objective function. They need to be 2d numpy arrays (as it is used in GPy).
Hope this helps!
Javier
Hi, this was not very intuitive for me. I suggest to make it easier in future versions, e.g. the function accepts n inputs, and not a 2d numpy arrays with all the inputs.
Most helpful comment
Hi, this was not very intuitive for me. I suggest to make it easier in future versions, e.g. the function accepts n inputs, and not a 2d numpy arrays with all the inputs.