How do I add limiting conditions when using GpyOpt?

假装没事ソ 提交于 2019-12-04 16:50:36

GPyOpt only supports constrains in a form of c(x0, x1, ..., xn) <= 0, so the best you can do is to pick a small enough value and "sandwich" the constrain expression that you have with it. Let's say 0.1 is sufficiently small, then you could do this:

(x0 + x1 + x2 + x3 + x4 + x5) - 100000000 <= 0.1
(x0 + x1 + x2 + x3 + x4 + x5) - 100000000 >= -0.1

and then

(x0 + x1 + x2 + x3 + x4 + x5) - 100000000 - 0.1 <= 0
100000000 - (x0 + x1 + x2 + x3 + x4 + x5) - 0.1 <= 0

The API would look like that:

constraints = [
    {
        'name': 'constr_1',
        'constraint': '(x[:,0] + x[:,1] + x[:,2] + x[:,3] + x[:,4] + x[:,5]) - 100000000 - 0.1'
    },
    {
        'name': 'constr_2',
        'constraint': '100000000 - (x[:,0] + x[:,1] + x[:,2] + x[:,3] + x[:,4] + x[:,5]) - 0.1'
    }
]

myBopt = GPyOpt.methods.BayesianOptimization(f=f, domain=bounds, constraints = constraints)

I found a faster way.

If you need X0+X1.....Xn ==100000000 , you only give X0+X1....Xn-1 to GpyOpt.

After GpyOpt give you (X0+X1.....Xn-1), you can get Xn = 100000000 - sum(X0+X1.....Xn-1)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!