EmuKit / emukit

A Python-based toolbox of various methods in decision making, uncertainty quantification and statistical emulation: multi-fidelity, experimental design, Bayesian optimisation, Bayesian quadrature, etc.
https://emukit.github.io/emukit/
Apache License 2.0
591 stars 128 forks source link

Parameter Space Constraint #401

Open Rblack999 opened 2 years ago

Rblack999 commented 2 years ago

In exploring this library, I am trying to define a very particular parameter space for an optimization problem and am wondering if/how it can be implemented? I'm trying to do BO Experimental Design, and have defined my parameter space as the following:

parameter_space = ParameterSpace([DiscreteParameter('x1',np.linspace(0,1,11)), DiscreteParameter('x2',np.linspace(0,1,11)), DiscreteParameter('x3',np.linspace(0,1,11)), DiscreteParameter('x4',np.linspace(0,1,11)), DiscreteParameter('x5',np.linspace(0,1,11)), DiscreteParameter('x6',np.linspace(0,1,11))])

Essentially, a 6 column matrix with each [[0,0.1,0.2...1]] in spacing of 0.1.

However, I would like to constrain this to have summation of x1 to x6 == 1. That is, only select x_new values to output a single vector but with the columns (x1 to x6) adding up to 1, rejecting any vector that does not meet this criteria.

Is this possible to implement? I have looked into the constraint libraries but have come up short. If not using constraints, is their a way to explicitly define that space (it will be a shape(2121,6) matrix in the end). My understanding is that a matrix cannot be used, but only a 1d or 2d (n,1) array can be used.

Thanks!

apaleyes commented 2 years ago

Sounds like you just need to define a linear constraint. We support those, here is the doc link. Note that when your lower and upper bounds are the same, this turns into equality constraint, which is what you are after.

Also, here is an example of how to do constraints in Emukit. It talks about non-linear ones, but the idea is the same, you just use a different, simpler, class. https://nbviewer.org/github/emukit/emukit/blob/main/notebooks/Emukit-tutorial-constrained-optimization.ipynb

apaleyes commented 2 years ago

Oh, by the way, while using constraints please be aware of an annoying bug #291 which might impact your code