Setting bounds on each dimension of x for a function f(x1,x2) in skopt

350 Views Asked by At

I have a function f(x1,x2) and would like to set the bounds for a gp_minimization for the two dimensions of x using skopt.

With one variable (x1) it works great:

def func(x1):
    return x1[0]

bounds = [(1.0, 10.0)]

gp_res = gp_minimize(func, dimensions=bounds, acq_func="EI", n_calls=100, random_state=0)

But using a function with multiple variables like f(x1,x2) I need to add the bounds of the second variable. I tried it this way:

def func(x1, x2):
    return x1[0][0]*x2[0][1]

bounds = [[(1.0, 10.0),(10.1, 9.9)]]
bounds[0][0] #(1.0,10.0) To set the bounds for x1
bounds[0][1] #(10.1,9.9) To set the bounds for x2

gp_res = gp_minimize(func=func, dimensions=bounds, acq_func="EI", n_calls=100, random_state=0)

I get the error message: ValueError: Invalid dimension [(1.0, 4.0), (1.1, 3.9)]. Read the documentation for supported types.

By changing the bounds to this:

def func(x1, x2):
    return x1[0][0]*x2[0][1]

bounds = [(1.0, 10.0),(10.1, 9.9)]

gp_res = gp_minimize(func=func, dimensions=bounds, acq_func="EI", n_calls=100, random_state=0)

I receive the following error message: TypeError: func() missing 1 required positional argument: 'x2'

Can you help me with this issue? How can I set the bounds for two variables?

Refering to this example (Tim Head, July 2016. Reformatted by Holger Nahrstaedt 2020): https://scikit-optimize.github.io/stable/auto_examples/strategy-comparison.html#sphx-glr-download-auto-examples-strategy-comparison-py

1

There are 1 best solutions below

1
On

Solved it.

Solution:

dim1 = Real(name='x1', low=1.0, high=100.0)
dim2 = Real(name='x2', low=1.0, high=100.0)
bounds = [dim1, dim2]

@use_named_args(dimensions=bounds)
def func(x1, x2):
 return x1*x2