bayesian-optimization 1.5.0__tar.gz → 1.5.1__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.
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/PKG-INFO +7 -7
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/README.md +5 -5
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/logger.py +12 -5
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/target_space.py +16 -7
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/pyproject.toml +6 -2
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/LICENSE +0 -0
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/__init__.py +0 -0
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/bayesian_optimization.py +0 -0
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/constraint.py +0 -0
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/domain_reduction.py +0 -0
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/event.py +0 -0
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/observer.py +0 -0
- {bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: bayesian-optimization
|
|
3
|
-
Version: 1.5.
|
|
3
|
+
Version: 1.5.1
|
|
4
4
|
Summary: Bayesian Optimization package
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Fernando Nogueira
|
|
@@ -12,20 +12,20 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
14
|
Requires-Dist: colorama (>=0.4.6,<0.5.0)
|
|
15
|
-
Requires-Dist: numpy (>=1.
|
|
15
|
+
Requires-Dist: numpy (>=1.25)
|
|
16
16
|
Requires-Dist: scikit-learn (>=1.0.0,<2.0.0)
|
|
17
17
|
Requires-Dist: scipy (>=1.0.0,<2.0.0)
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
|
|
20
20
|
<div align="center">
|
|
21
|
-
<img src="https://raw.githubusercontent.com/bayesian-optimization/BayesianOptimization/master/static/func.png"><br><br>
|
|
21
|
+
<img src="https://raw.githubusercontent.com/bayesian-optimization/BayesianOptimization/master/docsrc/static/func.png"><br><br>
|
|
22
22
|
</div>
|
|
23
23
|
|
|
24
24
|
# Bayesian Optimization
|
|
25
25
|
|
|
26
26
|

|
|
27
27
|
[](https://codecov.io/github/bayesian-optimization/BayesianOptimization?branch=master)
|
|
28
|
-
[](https://pypi.python.org/pypi/bayesian-optimization)
|
|
28
|
+
[](https://pypi.python.org/pypi/bayesian-optimization)
|
|
29
29
|
|
|
30
30
|
Pure Python implementation of bayesian global optimization with gaussian
|
|
31
31
|
processes.
|
|
@@ -70,11 +70,11 @@ for ideas on how to implement bayesian optimization in a distributed fashion usi
|
|
|
70
70
|
|
|
71
71
|
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.
|
|
72
72
|
|
|
73
|
-

|
|
74
74
|
|
|
75
75
|
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).
|
|
76
76
|
|
|
77
|
-

|
|
78
78
|
|
|
79
79
|
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.
|
|
80
80
|
|
|
@@ -202,7 +202,7 @@ Sometimes the initial boundaries specified for a problem are too wide, and addin
|
|
|
202
202
|
|
|
203
203
|
When it's worthwhile to converge on an optimal point quickly rather than try to find the optimal point, contracting the domain around the current optimal value as the search progresses can speed up the search progress considerably. Using the `SequentialDomainReductionTransformer` the bounds of the problem can be panned and zoomed dynamically in an attempt to improve convergence.
|
|
204
204
|
|
|
205
|
-

|
|
206
206
|
|
|
207
207
|
An example of using the `SequentialDomainReductionTransformer` is shown in the [domain reduction notebook](http://bayesian-optimization.github.io/BayesianOptimization/domain_reduction.html). More information about this method can be found in the paper ["On the robustness of a simple domain reduction scheme for simulation‐based optimization"](http://www.truegrid.com/srsm_revised.pdf).
|
|
208
208
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/bayesian-optimization/BayesianOptimization/master/static/func.png"><br><br>
|
|
2
|
+
<img src="https://raw.githubusercontent.com/bayesian-optimization/BayesianOptimization/master/docsrc/static/func.png"><br><br>
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
# Bayesian Optimization
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
[](https://codecov.io/github/bayesian-optimization/BayesianOptimization?branch=master)
|
|
9
|
-
[](https://pypi.python.org/pypi/bayesian-optimization)
|
|
9
|
+
[](https://pypi.python.org/pypi/bayesian-optimization)
|
|
10
10
|
|
|
11
11
|
Pure Python implementation of bayesian global optimization with gaussian
|
|
12
12
|
processes.
|
|
@@ -51,11 +51,11 @@ for ideas on how to implement bayesian optimization in a distributed fashion usi
|
|
|
51
51
|
|
|
52
52
|
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.
|
|
53
53
|
|
|
54
|
-

|
|
55
55
|
|
|
56
56
|
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).
|
|
57
57
|
|
|
58
|
-

|
|
59
59
|
|
|
60
60
|
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.
|
|
61
61
|
|
|
@@ -183,7 +183,7 @@ Sometimes the initial boundaries specified for a problem are too wide, and addin
|
|
|
183
183
|
|
|
184
184
|
When it's worthwhile to converge on an optimal point quickly rather than try to find the optimal point, contracting the domain around the current optimal value as the search progresses can speed up the search progress considerably. Using the `SequentialDomainReductionTransformer` the bounds of the problem can be panned and zoomed dynamically in an attempt to improve convergence.
|
|
185
185
|
|
|
186
|
-

|
|
187
187
|
|
|
188
188
|
An example of using the `SequentialDomainReductionTransformer` is shown in the [domain reduction notebook](http://bayesian-optimization.github.io/BayesianOptimization/domain_reduction.html). More information about this method can be found in the paper ["On the robustness of a simple domain reduction scheme for simulation‐based optimization"](http://www.truegrid.com/srsm_revised.pdf).
|
|
189
189
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
from __future__ import print_function
|
|
3
3
|
import os
|
|
4
4
|
import json
|
|
5
|
+
import numpy as np
|
|
5
6
|
from .observer import _Tracker
|
|
6
7
|
from .event import Events
|
|
7
8
|
from colorama import Fore, just_fix_windows_console
|
|
@@ -45,7 +46,10 @@ class ScreenLogger(_Tracker):
|
|
|
45
46
|
|
|
46
47
|
_default_cell_size = 9
|
|
47
48
|
_default_precision = 4
|
|
48
|
-
|
|
49
|
+
_colour_new_max = Fore.MAGENTA
|
|
50
|
+
_colour_regular_message = Fore.RESET
|
|
51
|
+
_colour_reset = Fore.RESET
|
|
52
|
+
|
|
49
53
|
def __init__(self, verbose=2, is_constrained=False):
|
|
50
54
|
self._verbose = verbose
|
|
51
55
|
self._is_constrained = is_constrained
|
|
@@ -135,7 +139,7 @@ class ScreenLogger(_Tracker):
|
|
|
135
139
|
return s[:self._default_cell_size - 3] + "..."
|
|
136
140
|
return s
|
|
137
141
|
|
|
138
|
-
def _step(self, instance, colour=
|
|
142
|
+
def _step(self, instance, colour=_colour_regular_message):
|
|
139
143
|
"""Log a step.
|
|
140
144
|
|
|
141
145
|
Parameters
|
|
@@ -144,7 +148,7 @@ class ScreenLogger(_Tracker):
|
|
|
144
148
|
The instance associated with the event.
|
|
145
149
|
|
|
146
150
|
colour :
|
|
147
|
-
(Default value = Fore.
|
|
151
|
+
(Default value = _colour_regular_message, equivalent to Fore.RESET)
|
|
148
152
|
|
|
149
153
|
Returns
|
|
150
154
|
-------
|
|
@@ -162,7 +166,7 @@ class ScreenLogger(_Tracker):
|
|
|
162
166
|
for key in instance.space.keys:
|
|
163
167
|
cells.append(self._format_number(res["params"][key]))
|
|
164
168
|
|
|
165
|
-
return "| " + " | ".join([colour + cells[i] for i in range(len(cells))]) + " |"
|
|
169
|
+
return "| " + " | ".join([colour + cells[i] + self._colour_reset for i in range(len(cells))]) + " |"
|
|
166
170
|
|
|
167
171
|
def _header(self, instance):
|
|
168
172
|
"""Print the header of the log.
|
|
@@ -230,7 +234,7 @@ class ScreenLogger(_Tracker):
|
|
|
230
234
|
if self._verbose == 1 and not is_new_max:
|
|
231
235
|
line = ""
|
|
232
236
|
else:
|
|
233
|
-
colour =
|
|
237
|
+
colour = self._colour_new_max if is_new_max else self._colour_regular_message
|
|
234
238
|
line = self._step(instance, colour=colour) + "\n"
|
|
235
239
|
elif event == Events.OPTIMIZATION_END:
|
|
236
240
|
line = "=" * self._header_length + "\n"
|
|
@@ -291,6 +295,9 @@ class JSONLogger(_Tracker):
|
|
|
291
295
|
|
|
292
296
|
if "allowed" in data: # fix: github.com/fmfn/BayesianOptimization/issues/361
|
|
293
297
|
data["allowed"] = bool(data["allowed"])
|
|
298
|
+
|
|
299
|
+
if "constraint" in data and isinstance(data["constraint"], np.ndarray):
|
|
300
|
+
data["constraint"] = data["constraint"].tolist()
|
|
294
301
|
|
|
295
302
|
with open(self._path, "a") as f:
|
|
296
303
|
f.write(json.dumps(data) + "\n")
|
|
@@ -302,7 +302,7 @@ class TargetSpace():
|
|
|
302
302
|
self.n_duplicate_points = self.n_duplicate_points + 1
|
|
303
303
|
|
|
304
304
|
print(Fore.RED + f'Data point {x} is not unique. {self.n_duplicate_points}'
|
|
305
|
-
' duplicates registered. Continuing ...')
|
|
305
|
+
' duplicates registered. Continuing ...' + Fore.RESET)
|
|
306
306
|
else:
|
|
307
307
|
raise NotUniqueError(f'Data point {x} is not unique. You can set'
|
|
308
308
|
' "allow_duplicate_points=True" to avoid this error')
|
|
@@ -312,21 +312,30 @@ class TargetSpace():
|
|
|
312
312
|
if not np.all((self._bounds[:, 0] <= x) & (x <= self._bounds[:, 1])):
|
|
313
313
|
warn(f'\nData point {x} is outside the bounds of the parameter space. ', stacklevel=2)
|
|
314
314
|
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
# Make copies of the data, so as not to modify the originals incase something fails
|
|
316
|
+
# during the registration process. This prevents out-of-sync data.
|
|
317
|
+
params_copy = np.concatenate([self._params, x.reshape(1, -1)])
|
|
318
|
+
target_copy = np.concatenate([self._target, [target]])
|
|
319
|
+
cache_copy = self._cache.copy() # shallow copy suffices
|
|
317
320
|
|
|
318
321
|
if self._constraint is None:
|
|
319
322
|
# Insert data into unique dictionary
|
|
320
|
-
|
|
323
|
+
cache_copy[_hashable(x.ravel())] = target
|
|
321
324
|
else:
|
|
322
325
|
if constraint_value is None:
|
|
323
326
|
msg = ("When registering a point to a constrained TargetSpace" +
|
|
324
327
|
" a constraint value needs to be present.")
|
|
325
328
|
raise ValueError(msg)
|
|
326
329
|
# Insert data into unique dictionary
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
+
cache_copy[_hashable(x.ravel())] = (target, constraint_value)
|
|
331
|
+
constraint_values_copy = np.concatenate([self._constraint_values,
|
|
332
|
+
[constraint_value]])
|
|
333
|
+
self._constraint_values = constraint_values_copy
|
|
334
|
+
|
|
335
|
+
# Operations passed, update the variables
|
|
336
|
+
self._params = params_copy
|
|
337
|
+
self._target = target_copy
|
|
338
|
+
self._cache = cache_copy
|
|
330
339
|
|
|
331
340
|
def probe(self, params):
|
|
332
341
|
"""Evaluate the target function on a point and register the result.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "bayesian-optimization"
|
|
3
|
-
version = "1.5.
|
|
3
|
+
version = "1.5.1"
|
|
4
4
|
description = "Bayesian Optimization package"
|
|
5
5
|
authors = ["Fernando Nogueira"]
|
|
6
6
|
license = "MIT"
|
|
@@ -10,7 +10,7 @@ packages = [{include = "bayes_opt"}]
|
|
|
10
10
|
[tool.poetry.dependencies]
|
|
11
11
|
python = "^3.9"
|
|
12
12
|
scikit-learn = "^1.0.0"
|
|
13
|
-
numpy = "
|
|
13
|
+
numpy = ">=1.25"
|
|
14
14
|
scipy = "^1.0.0"
|
|
15
15
|
colorama = "^0.4.6"
|
|
16
16
|
|
|
@@ -31,6 +31,10 @@ nbformat = "^5.9.2"
|
|
|
31
31
|
nbconvert = "^7.14.2"
|
|
32
32
|
jupyter = "^1.0.0"
|
|
33
33
|
matplotlib = "^3.0"
|
|
34
|
+
sphinx = "^7.3.7"
|
|
35
|
+
nbsphinx = "^0.9.4"
|
|
36
|
+
sphinx-rtd-theme = "^2.0.0"
|
|
37
|
+
myst-parser = "^3.0.1"
|
|
34
38
|
|
|
35
39
|
|
|
36
40
|
[build-system]
|
|
File without changes
|
|
File without changes
|
{bayesian_optimization-1.5.0 → bayesian_optimization-1.5.1}/bayes_opt/bayesian_optimization.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|