Skopt.gp_minimize: Passing args to objectiv function

741 Views Asked by At

I am trying to implement an optimisation using gp_minimize from skopt. However my objective functions needs some objects to work on, similar to this:

def objective(optimisation_parameters, trees):
    trees.manipulate(optimisation_parameters)
    trees.shake()
    return trees.count_fallen_fruits()
def optimise():
    trees = [tree.Tree() for _ in range(0,5)]
    res = gp_minimize(objectiv,space,...,args = trees)

Is there any (proper) way to do this? I have several ideas:

  1. Read and store the trees in a pickle file each optimisation
  2. Define the trees so that they are in scope for the objective function

Thanks

1

There are 1 best solutions below

0
On

Your idea 2 is the common option. It is utilized in this example.

A scratch based on your code snippets might look like this:

trees = [tree.Tree() for _ in range(0,5)]

def objective(optimisation_parameters):
    trees.manipulate(optimisation_parameters)
    trees.shake()
    return trees.count_fallen_fruits()

res = gp_minimize(objective, space, ...)