bayesian-optimization 1.5.0__tar.gz → 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.1
2
+ Name: bayesian-optimization
3
+ Version: 2.0.0
4
+ Summary: Bayesian Optimization package
5
+ License: MIT
6
+ Author: Fernando Nogueira
7
+ Requires-Python: >=3.9,<4.0
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: colorama (>=0.4.6,<0.5.0)
16
+ Requires-Dist: numpy (>=1.25)
17
+ Requires-Dist: scikit-learn (>=1.0.0,<2.0.0)
18
+ Requires-Dist: scipy (>=1.0.0,<2.0.0)
19
+ Description-Content-Type: text/markdown
20
+
21
+ <div align="center">
22
+ <img src="https://raw.githubusercontent.com/bayesian-optimization/BayesianOptimization/master/docsrc/static/func.png"><br><br>
23
+ </div>
24
+
25
+ # Bayesian Optimization
26
+
27
+ ![tests](https://github.com/bayesian-optimization/BayesianOptimization/actions/workflows/run_tests.yml/badge.svg)
28
+ [![docs - stable](https://img.shields.io/badge/docs-stable-blue)](https://bayesian-optimization.github.io/BayesianOptimization/index.html)
29
+ [![Codecov](https://codecov.io/github/bayesian-optimization/BayesianOptimization/badge.svg?branch=master&service=github)](https://codecov.io/github/bayesian-optimization/BayesianOptimization?branch=master)
30
+ [![Pypi](https://img.shields.io/pypi/v/bayesian-optimization.svg)](https://pypi.python.org/pypi/bayesian-optimization)
31
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/bayesian-optimization)
32
+
33
+
34
+ Pure Python implementation of bayesian global optimization with gaussian
35
+ processes.
36
+
37
+
38
+ This is a constrained global optimization package built upon bayesian inference
39
+ and gaussian processes, that attempts to find the maximum value of an unknown
40
+ function in as few iterations as possible. This technique is particularly
41
+ suited for optimization of high cost functions and situations where the balance
42
+ between exploration and exploitation is important.
43
+
44
+ ## Installation
45
+
46
+ * pip (via PyPI):
47
+
48
+ ```console
49
+ $ pip install bayesian-optimization
50
+ ```
51
+
52
+ * Conda (via conda-forge):
53
+
54
+ ```console
55
+ $ conda install -c conda-forge bayesian-optimization
56
+ ```
57
+
58
+ ## How does it work?
59
+
60
+ See the [documentation](https://bayesian-optimization.github.io/BayesianOptimization/) for how to use this package.
61
+
62
+ Bayesian optimization works by constructing a posterior distribution of functions (gaussian process) that best describes the function you want to optimize. As the number of observations grows, the posterior distribution improves, and the algorithm becomes more certain of which regions in parameter space are worth exploring and which are not, as seen in the picture below.
63
+
64
+ ![BayesianOptimization in action](docsrc/static/bo_example.png)
65
+
66
+ As you iterate over and over, the algorithm balances its needs of exploration and exploitation taking into account what it knows about the target function. At each step a Gaussian Process is fitted to the known samples (points previously explored), and the posterior distribution, combined with a exploration strategy (such as UCB (Upper Confidence Bound), or EI (Expected Improvement)), are used to determine the next point that should be explored (see the gif below).
67
+
68
+ ![BayesianOptimization in action](docsrc/static/bayesian_optimization.gif)
69
+
70
+ This process is designed to minimize the number of steps required to find a combination of parameters that are close to the optimal combination. To do so, this method uses a proxy optimization problem (finding the maximum of the acquisition function) that, albeit still a hard problem, is cheaper (in the computational sense) and common tools can be employed. Therefore Bayesian Optimization is most adequate for situations where sampling the function to be optimized is a very expensive endeavor. See the references for a proper discussion of this method.
71
+
72
+ This project is under active development. If you run into trouble, find a bug or notice
73
+ anything that needs correction, please let us know by filing an issue.
74
+
75
+
76
+ ## Basic tour of the Bayesian Optimization package
77
+
78
+ ### 1. Specifying the function to be optimized
79
+
80
+ This is a function optimization package, therefore the first and most important ingredient is, of course, the function to be optimized.
81
+
82
+ **DISCLAIMER:** We know exactly how the output of the function below depends on its parameter. Obviously this is just an example, and you shouldn't expect to know it in a real scenario. However, it should be clear that you don't need to. All you need in order to use this package (and more generally, this technique) is a function `f` that takes a known set of parameters and outputs a real number.
83
+
84
+
85
+ ```python
86
+ def black_box_function(x, y):
87
+ """Function with unknown internals we wish to maximize.
88
+
89
+ This is just serving as an example, for all intents and
90
+ purposes think of the internals of this function, i.e.: the process
91
+ which generates its output values, as unknown.
92
+ """
93
+ return -x ** 2 - (y - 1) ** 2 + 1
94
+ ```
95
+
96
+ ### 2. Getting Started
97
+
98
+ All we need to get started is to instantiate a `BayesianOptimization` object specifying a function to be optimized `f`, and its parameters with their corresponding bounds, `pbounds`. This is a constrained optimization technique, so you must specify the minimum and maximum values that can be probed for each parameter in order for it to work
99
+
100
+
101
+ ```python
102
+ from bayes_opt import BayesianOptimization
103
+
104
+ # Bounded region of parameter space
105
+ pbounds = {'x': (2, 4), 'y': (-3, 3)}
106
+
107
+ optimizer = BayesianOptimization(
108
+ f=black_box_function,
109
+ pbounds=pbounds,
110
+ random_state=1,
111
+ )
112
+ ```
113
+
114
+ The BayesianOptimization object will work out of the box without much tuning needed. The main method you should be aware of is `maximize`, which does exactly what you think it does.
115
+
116
+ There are many parameters you can pass to maximize, nonetheless, the most important ones are:
117
+ - `n_iter`: How many steps of bayesian optimization you want to perform. The more steps the more likely to find a good maximum you are.
118
+ - `init_points`: How many steps of **random** exploration you want to perform. Random exploration can help by diversifying the exploration space.
119
+
120
+
121
+ ```python
122
+ optimizer.maximize(
123
+ init_points=2,
124
+ n_iter=3,
125
+ )
126
+ ```
127
+
128
+ | iter | target | x | y |
129
+ -------------------------------------------------
130
+ | 1 | -7.135 | 2.834 | 1.322 |
131
+ | 2 | -7.78 | 2.0 | -1.186 |
132
+ | 3 | -19.0 | 4.0 | 3.0 |
133
+ | 4 | -16.3 | 2.378 | -2.413 |
134
+ | 5 | -4.441 | 2.105 | -0.005822 |
135
+ =================================================
136
+
137
+
138
+ The best combination of parameters and target value found can be accessed via the property `optimizer.max`.
139
+
140
+
141
+ ```python
142
+ print(optimizer.max)
143
+ >>> {'target': -4.441293113411222, 'params': {'y': -0.005822117636089974, 'x': 2.104665051994087}}
144
+ ```
145
+
146
+
147
+ While the list of all parameters probed and their corresponding target values is available via the property `optimizer.res`.
148
+
149
+
150
+ ```python
151
+ for i, res in enumerate(optimizer.res):
152
+ print("Iteration {}: \n\t{}".format(i, res))
153
+
154
+ >>> Iteration 0:
155
+ >>> {'target': -7.135455292718879, 'params': {'y': 1.3219469606529488, 'x': 2.8340440094051482}}
156
+ >>> Iteration 1:
157
+ >>> {'target': -7.779531005607566, 'params': {'y': -1.1860045642089614, 'x': 2.0002287496346898}}
158
+ >>> Iteration 2:
159
+ >>> {'target': -19.0, 'params': {'y': 3.0, 'x': 4.0}}
160
+ >>> Iteration 3:
161
+ >>> {'target': -16.29839645063864, 'params': {'y': -2.412527795983739, 'x': 2.3776144540856503}}
162
+ >>> Iteration 4:
163
+ >>> {'target': -4.441293113411222, 'params': {'y': -0.005822117636089974, 'x': 2.104665051994087}}
164
+ ```
165
+
166
+
167
+ ## Minutiae
168
+
169
+ ### Citation
170
+
171
+ If you used this package in your research, please cite it:
172
+
173
+ ```
174
+ @Misc{,
175
+ author = {Fernando Nogueira},
176
+ title = {{Bayesian Optimization}: Open source constrained global optimization tool for {Python}},
177
+ year = {2014--},
178
+ url = " https://github.com/bayesian-optimization/BayesianOptimization"
179
+ }
180
+ ```
181
+ If you used any of the advanced functionalities, please additionally cite the corresponding publication:
182
+
183
+ For the `SequentialDomainTransformer`:
184
+ ```
185
+ @article{
186
+ author = {Stander, Nielen and Craig, Kenneth},
187
+ year = {2002},
188
+ month = {06},
189
+ pages = {},
190
+ title = {On the robustness of a simple domain reduction scheme for simulation-based optimization},
191
+ volume = {19},
192
+ journal = {International Journal for Computer-Aided Engineering and Software (Eng. Comput.)},
193
+ doi = {10.1108/02644400210430190}
194
+ }
195
+ ```
196
+
197
+ For constrained optimization:
198
+ ```
199
+ @inproceedings{gardner2014bayesian,
200
+ title={Bayesian optimization with inequality constraints.},
201
+ author={Gardner, Jacob R and Kusner, Matt J and Xu, Zhixiang Eddie and Weinberger, Kilian Q and Cunningham, John P},
202
+ booktitle={ICML},
203
+ volume={2014},
204
+ pages={937--945},
205
+ year={2014}
206
+ }
207
+ ```
208
+
@@ -0,0 +1,187 @@
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/bayesian-optimization/BayesianOptimization/master/docsrc/static/func.png"><br><br>
3
+ </div>
4
+
5
+ # Bayesian Optimization
6
+
7
+ ![tests](https://github.com/bayesian-optimization/BayesianOptimization/actions/workflows/run_tests.yml/badge.svg)
8
+ [![docs - stable](https://img.shields.io/badge/docs-stable-blue)](https://bayesian-optimization.github.io/BayesianOptimization/index.html)
9
+ [![Codecov](https://codecov.io/github/bayesian-optimization/BayesianOptimization/badge.svg?branch=master&service=github)](https://codecov.io/github/bayesian-optimization/BayesianOptimization?branch=master)
10
+ [![Pypi](https://img.shields.io/pypi/v/bayesian-optimization.svg)](https://pypi.python.org/pypi/bayesian-optimization)
11
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/bayesian-optimization)
12
+
13
+
14
+ Pure Python implementation of bayesian global optimization with gaussian
15
+ processes.
16
+
17
+
18
+ This is a constrained global optimization package built upon bayesian inference
19
+ and gaussian processes, that attempts to find the maximum value of an unknown
20
+ function in as few iterations as possible. This technique is particularly
21
+ suited for optimization of high cost functions and situations where the balance
22
+ between exploration and exploitation is important.
23
+
24
+ ## Installation
25
+
26
+ * pip (via PyPI):
27
+
28
+ ```console
29
+ $ pip install bayesian-optimization
30
+ ```
31
+
32
+ * Conda (via conda-forge):
33
+
34
+ ```console
35
+ $ conda install -c conda-forge bayesian-optimization
36
+ ```
37
+
38
+ ## How does it work?
39
+
40
+ See the [documentation](https://bayesian-optimization.github.io/BayesianOptimization/) for how to use this package.
41
+
42
+ Bayesian optimization works by constructing a posterior distribution of functions (gaussian process) that best describes the function you want to optimize. As the number of observations grows, the posterior distribution improves, and the algorithm becomes more certain of which regions in parameter space are worth exploring and which are not, as seen in the picture below.
43
+
44
+ ![BayesianOptimization in action](docsrc/static/bo_example.png)
45
+
46
+ As you iterate over and over, the algorithm balances its needs of exploration and exploitation taking into account what it knows about the target function. At each step a Gaussian Process is fitted to the known samples (points previously explored), and the posterior distribution, combined with a exploration strategy (such as UCB (Upper Confidence Bound), or EI (Expected Improvement)), are used to determine the next point that should be explored (see the gif below).
47
+
48
+ ![BayesianOptimization in action](docsrc/static/bayesian_optimization.gif)
49
+
50
+ This process is designed to minimize the number of steps required to find a combination of parameters that are close to the optimal combination. To do so, this method uses a proxy optimization problem (finding the maximum of the acquisition function) that, albeit still a hard problem, is cheaper (in the computational sense) and common tools can be employed. Therefore Bayesian Optimization is most adequate for situations where sampling the function to be optimized is a very expensive endeavor. See the references for a proper discussion of this method.
51
+
52
+ This project is under active development. If you run into trouble, find a bug or notice
53
+ anything that needs correction, please let us know by filing an issue.
54
+
55
+
56
+ ## Basic tour of the Bayesian Optimization package
57
+
58
+ ### 1. Specifying the function to be optimized
59
+
60
+ This is a function optimization package, therefore the first and most important ingredient is, of course, the function to be optimized.
61
+
62
+ **DISCLAIMER:** We know exactly how the output of the function below depends on its parameter. Obviously this is just an example, and you shouldn't expect to know it in a real scenario. However, it should be clear that you don't need to. All you need in order to use this package (and more generally, this technique) is a function `f` that takes a known set of parameters and outputs a real number.
63
+
64
+
65
+ ```python
66
+ def black_box_function(x, y):
67
+ """Function with unknown internals we wish to maximize.
68
+
69
+ This is just serving as an example, for all intents and
70
+ purposes think of the internals of this function, i.e.: the process
71
+ which generates its output values, as unknown.
72
+ """
73
+ return -x ** 2 - (y - 1) ** 2 + 1
74
+ ```
75
+
76
+ ### 2. Getting Started
77
+
78
+ All we need to get started is to instantiate a `BayesianOptimization` object specifying a function to be optimized `f`, and its parameters with their corresponding bounds, `pbounds`. This is a constrained optimization technique, so you must specify the minimum and maximum values that can be probed for each parameter in order for it to work
79
+
80
+
81
+ ```python
82
+ from bayes_opt import BayesianOptimization
83
+
84
+ # Bounded region of parameter space
85
+ pbounds = {'x': (2, 4), 'y': (-3, 3)}
86
+
87
+ optimizer = BayesianOptimization(
88
+ f=black_box_function,
89
+ pbounds=pbounds,
90
+ random_state=1,
91
+ )
92
+ ```
93
+
94
+ The BayesianOptimization object will work out of the box without much tuning needed. The main method you should be aware of is `maximize`, which does exactly what you think it does.
95
+
96
+ There are many parameters you can pass to maximize, nonetheless, the most important ones are:
97
+ - `n_iter`: How many steps of bayesian optimization you want to perform. The more steps the more likely to find a good maximum you are.
98
+ - `init_points`: How many steps of **random** exploration you want to perform. Random exploration can help by diversifying the exploration space.
99
+
100
+
101
+ ```python
102
+ optimizer.maximize(
103
+ init_points=2,
104
+ n_iter=3,
105
+ )
106
+ ```
107
+
108
+ | iter | target | x | y |
109
+ -------------------------------------------------
110
+ | 1 | -7.135 | 2.834 | 1.322 |
111
+ | 2 | -7.78 | 2.0 | -1.186 |
112
+ | 3 | -19.0 | 4.0 | 3.0 |
113
+ | 4 | -16.3 | 2.378 | -2.413 |
114
+ | 5 | -4.441 | 2.105 | -0.005822 |
115
+ =================================================
116
+
117
+
118
+ The best combination of parameters and target value found can be accessed via the property `optimizer.max`.
119
+
120
+
121
+ ```python
122
+ print(optimizer.max)
123
+ >>> {'target': -4.441293113411222, 'params': {'y': -0.005822117636089974, 'x': 2.104665051994087}}
124
+ ```
125
+
126
+
127
+ While the list of all parameters probed and their corresponding target values is available via the property `optimizer.res`.
128
+
129
+
130
+ ```python
131
+ for i, res in enumerate(optimizer.res):
132
+ print("Iteration {}: \n\t{}".format(i, res))
133
+
134
+ >>> Iteration 0:
135
+ >>> {'target': -7.135455292718879, 'params': {'y': 1.3219469606529488, 'x': 2.8340440094051482}}
136
+ >>> Iteration 1:
137
+ >>> {'target': -7.779531005607566, 'params': {'y': -1.1860045642089614, 'x': 2.0002287496346898}}
138
+ >>> Iteration 2:
139
+ >>> {'target': -19.0, 'params': {'y': 3.0, 'x': 4.0}}
140
+ >>> Iteration 3:
141
+ >>> {'target': -16.29839645063864, 'params': {'y': -2.412527795983739, 'x': 2.3776144540856503}}
142
+ >>> Iteration 4:
143
+ >>> {'target': -4.441293113411222, 'params': {'y': -0.005822117636089974, 'x': 2.104665051994087}}
144
+ ```
145
+
146
+
147
+ ## Minutiae
148
+
149
+ ### Citation
150
+
151
+ If you used this package in your research, please cite it:
152
+
153
+ ```
154
+ @Misc{,
155
+ author = {Fernando Nogueira},
156
+ title = {{Bayesian Optimization}: Open source constrained global optimization tool for {Python}},
157
+ year = {2014--},
158
+ url = " https://github.com/bayesian-optimization/BayesianOptimization"
159
+ }
160
+ ```
161
+ If you used any of the advanced functionalities, please additionally cite the corresponding publication:
162
+
163
+ For the `SequentialDomainTransformer`:
164
+ ```
165
+ @article{
166
+ author = {Stander, Nielen and Craig, Kenneth},
167
+ year = {2002},
168
+ month = {06},
169
+ pages = {},
170
+ title = {On the robustness of a simple domain reduction scheme for simulation-based optimization},
171
+ volume = {19},
172
+ journal = {International Journal for Computer-Aided Engineering and Software (Eng. Comput.)},
173
+ doi = {10.1108/02644400210430190}
174
+ }
175
+ ```
176
+
177
+ For constrained optimization:
178
+ ```
179
+ @inproceedings{gardner2014bayesian,
180
+ title={Bayesian optimization with inequality constraints.},
181
+ author={Gardner, Jacob R and Kusner, Matt J and Xu, Zhixiang Eddie and Weinberger, Kilian Q and Cunningham, John P},
182
+ booktitle={ICML},
183
+ volume={2014},
184
+ pages={937--945},
185
+ year={2014}
186
+ }
187
+ ```
@@ -0,0 +1,26 @@
1
+ """Pure Python implementation of bayesian global optimization with gaussian processes."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import importlib.metadata
6
+
7
+ from bayes_opt import acquisition
8
+ from bayes_opt.bayesian_optimization import BayesianOptimization, Events
9
+ from bayes_opt.constraint import ConstraintModel
10
+ from bayes_opt.domain_reduction import SequentialDomainReductionTransformer
11
+ from bayes_opt.logger import JSONLogger, ScreenLogger
12
+ from bayes_opt.target_space import TargetSpace
13
+
14
+ __version__ = importlib.metadata.version("bayesian-optimization")
15
+
16
+
17
+ __all__ = [
18
+ "acquisition",
19
+ "BayesianOptimization",
20
+ "TargetSpace",
21
+ "ConstraintModel",
22
+ "Events",
23
+ "ScreenLogger",
24
+ "JSONLogger",
25
+ "SequentialDomainReductionTransformer",
26
+ ]