pythonscikit-learnscikit-optimize

How to define the search space for a simple equation optimization


I'm trying to learn skopt, but I'm struggling to get even a simple multivariate minimization to run.

import skopt

def black_box_function(some_x, some_y):
    return -some_x + 2 - (some_y - 1) ** 2 + 1

BOUNDS = [(0, 100.0), (0, 100.0)]

result = skopt.dummy_minimize(func=black_box_function, dimensions=BOUNDS)

When I run this, it seems to figure out that I want the search space for some_x to lie between 0 and 100, but it returns this error:

TypeError: black_box_function() missing 1 required positional argument: 'some_y'.

How can I define the search space for both some_x and some_y?


Solution

  • Quoting the documentation

    Function to minimize. Should take a single list of parameters and return the objective value.

    So black_box_function should not have two parameters some_x, some_y, but a single parameter some_xy, that is a list of those two

    def black_box_function(some_xy):
        some_x, some_y = some_xy
        return -some_x + 2 - (some_y - 1) ** 2 + 1