迭代贝叶斯优化包中的整数 Python
Iterate over integers in Bayesian Optimization package Python
我使用贝叶斯优化包 (https://github.com/fmfn/BayesianOptimization) 进行参数优化。默认情况下,此库迭代浮点数,但我不需要迭代整数,我该如何执行?
def black_box_function(x, y):
return -x ** 2 - (y - 1) ** 2 + 1
from bayes_opt import BayesianOptimization
pbounds = {'x': (2, 4), 'y': (-3, 3)}
optimizer = BayesianOptimization(
f=black_box_function,
pbounds=pbounds,
verbose=2,
random_state=1,
)
optimizer.maximize(
init_points=2,
n_iter=3,
)
# and as you can see it is iterated not over integers.
| iter | target | x | y |
-------------------------------------------------
| 1 | -7.135 | 2.834 | 1.322 |
| 2 | -7.78 | 2.0 | -1.186 |
| 3 | -19.0 | 4.0 | 3.0 |
| 4 | -16.3 | 2.378 | -2.413 |
| 5 | -4.441 | 2.105 | -0.005822 |
=================================================
为此,您可以阅读 advanced tour 的第 2 部分。
我使用贝叶斯优化包 (https://github.com/fmfn/BayesianOptimization) 进行参数优化。默认情况下,此库迭代浮点数,但我不需要迭代整数,我该如何执行?
def black_box_function(x, y):
return -x ** 2 - (y - 1) ** 2 + 1
from bayes_opt import BayesianOptimization
pbounds = {'x': (2, 4), 'y': (-3, 3)}
optimizer = BayesianOptimization(
f=black_box_function,
pbounds=pbounds,
verbose=2,
random_state=1,
)
optimizer.maximize(
init_points=2,
n_iter=3,
)
# and as you can see it is iterated not over integers.
| iter | target | x | y |
-------------------------------------------------
| 1 | -7.135 | 2.834 | 1.322 |
| 2 | -7.78 | 2.0 | -1.186 |
| 3 | -19.0 | 4.0 | 3.0 |
| 4 | -16.3 | 2.378 | -2.413 |
| 5 | -4.441 | 2.105 | -0.005822 |
=================================================
为此,您可以阅读 advanced tour 的第 2 部分。