Gpyopt: Format of multivariate objective functions

Created on 28 Feb 2017  路  5Comments  路  Source: SheffieldML/GPyOpt

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.

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.

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lewisscola picture lewisscola  路  11Comments

AliBaheri picture AliBaheri  路  3Comments

cbelth picture cbelth  路  6Comments

YoshikawaMasashi picture YoshikawaMasashi  路  7Comments

1Reinier picture 1Reinier  路  4Comments