bayesian-optimization / BayesianOptimization

A Python implementation of global optimization with gaussian processes.
https://bayesian-optimization.github.io/BayesianOptimization/index.html
MIT License
7.81k stars 1.53k forks source link

Constrained optimization but constraint function is unknown #473

Closed jacktang closed 5 months ago

jacktang commented 5 months ago

Hello,

I am running 11 dim constrained optimization problem, the bound is clear, and constraint function is unknown. I noticed that BayesianOptimization supports constraint function approximation. But I am not clear how to define black_box_function_with_constraints. Take below code as example (from https://bayesian-optimization.github.io/BayesianOptimization/constraints.html)

def black_box_function_with_constraints(x, y):
    if y <= x:
        return -10
    else:
        return -x ** 2 - (y - 1) ** 2 + 1

why -10 is constraint values? Thanks!

till-m commented 5 months ago

Hello @jacktang,

let me rewrite the specific example from above using pseudocode:


def black_box_function_with_constraints(**kwargs):
    if not constraint_fulfilled(**kwargs):
        return BAD_VALUE
    else:
        return target_function(**kwargs)

I would encourage you to read the constraints documentation again. Other than that, If you can be more specific with your problem, I might be able to help better.

jacktang commented 5 months ago

Hello @till-m , thanks for your reply! In my case, the black box function is evaluated by some CFD simulation software, and the constraint function is unknown, I will check the output of simulation, if the result is not completed, i suppose the constraint violented. Can the BAD_VALUE be - np.inf?

till-m commented 5 months ago

Hey @jacktang,

the idea behind this approach is to discourage the optimizer from re-visiting a region that most likeli does not fulfill the constraints by registering a "bad value". Choosing -np.inf will break the GP fitting, it would be better to choose a bad, but potentially realistic value -- i.e. something slightly worse than what you've previously observed during optimization.

jacktang commented 5 months ago

Thanks for the explanation!