bayesian-optimization 2.0.1__tar.gz → 2.0.2__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-2.0.1 → bayesian_optimization-2.0.2}/PKG-INFO +1 -1
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/bayesian_optimization.py +28 -2
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/target_space.py +0 -13
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/pyproject.toml +1 -1
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/LICENSE +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/README.md +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/__init__.py +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/acquisition.py +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/constraint.py +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/domain_reduction.py +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/event.py +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/exception.py +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/logger.py +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/observer.py +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/py.typed +0 -0
- {bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/util.py +0 -0
{bayesian_optimization-2.0.1 → bayesian_optimization-2.0.2}/bayes_opt/bayesian_optimization.py
RENAMED
|
@@ -8,7 +8,9 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
from collections import deque
|
|
10
10
|
from typing import TYPE_CHECKING, Any
|
|
11
|
+
from warnings import warn
|
|
11
12
|
|
|
13
|
+
import numpy as np
|
|
12
14
|
from sklearn.gaussian_process import GaussianProcessRegressor
|
|
13
15
|
from sklearn.gaussian_process.kernels import Matern
|
|
14
16
|
|
|
@@ -22,7 +24,6 @@ from bayes_opt.util import ensure_rng
|
|
|
22
24
|
if TYPE_CHECKING:
|
|
23
25
|
from collections.abc import Callable, Iterable, Mapping, Sequence
|
|
24
26
|
|
|
25
|
-
import numpy as np
|
|
26
27
|
from numpy.random import RandomState
|
|
27
28
|
from numpy.typing import NDArray
|
|
28
29
|
from scipy.optimize import NonlinearConstraint
|
|
@@ -166,6 +167,7 @@ class BayesianOptimization(Observable):
|
|
|
166
167
|
error_msg = "The transformer must be an instance of DomainTransformer"
|
|
167
168
|
raise TypeError(error_msg) from exc
|
|
168
169
|
|
|
170
|
+
self._sorting_warning_already_shown = False # TODO: remove in future version
|
|
169
171
|
super().__init__(events=DEFAULT_EVENTS)
|
|
170
172
|
|
|
171
173
|
@property
|
|
@@ -220,6 +222,17 @@ class BayesianOptimization(Observable):
|
|
|
220
222
|
constraint_value: float or None
|
|
221
223
|
Value of the constraint function at the observation, if any.
|
|
222
224
|
"""
|
|
225
|
+
# TODO: remove in future version
|
|
226
|
+
if isinstance(params, np.ndarray) and not self._sorting_warning_already_shown:
|
|
227
|
+
msg = (
|
|
228
|
+
"You're attempting to register an np.ndarray. Currently, the optimizer internally sorts"
|
|
229
|
+
" parameters by key and expects any registered array to respect this order. In future"
|
|
230
|
+
" versions this behaviour will change and the order as given by the pbounds dictionary"
|
|
231
|
+
" will be used. If you wish to retain sorted parameters, please manually sort your pbounds"
|
|
232
|
+
" dictionary before constructing the optimizer."
|
|
233
|
+
)
|
|
234
|
+
warn(msg, stacklevel=1)
|
|
235
|
+
self._sorting_warning_already_shown = True
|
|
223
236
|
self._space.register(params, target, constraint_value)
|
|
224
237
|
self.dispatch(Events.OPTIMIZATION_STEP)
|
|
225
238
|
|
|
@@ -239,6 +252,18 @@ class BayesianOptimization(Observable):
|
|
|
239
252
|
If True, the optimizer will evaluate the points when calling
|
|
240
253
|
maximize(). Otherwise it will evaluate it at the moment.
|
|
241
254
|
"""
|
|
255
|
+
# TODO: remove in future version
|
|
256
|
+
if isinstance(params, np.ndarray) and not self._sorting_warning_already_shown:
|
|
257
|
+
msg = (
|
|
258
|
+
"You're attempting to register an np.ndarray. Currently, the optimizer internally sorts"
|
|
259
|
+
" parameters by key and expects any registered array to respect this order. In future"
|
|
260
|
+
" versions this behaviour will change and the order as given by the pbounds dictionary"
|
|
261
|
+
" will be used. If you wish to retain sorted parameters, please manually sort your pbounds"
|
|
262
|
+
" dictionary before constructing the optimizer."
|
|
263
|
+
)
|
|
264
|
+
warn(msg, stacklevel=1)
|
|
265
|
+
self._sorting_warning_already_shown = True
|
|
266
|
+
params = self._space.array_to_params(params)
|
|
242
267
|
if lazy:
|
|
243
268
|
self._queue.append(params)
|
|
244
269
|
else:
|
|
@@ -267,7 +292,8 @@ class BayesianOptimization(Observable):
|
|
|
267
292
|
init_points = max(init_points, 1)
|
|
268
293
|
|
|
269
294
|
for _ in range(init_points):
|
|
270
|
-
self.
|
|
295
|
+
sample = self._space.random_sample()
|
|
296
|
+
self._queue.append(self._space.array_to_params(sample))
|
|
271
297
|
|
|
272
298
|
def _prime_subscriptions(self) -> None:
|
|
273
299
|
if not any([len(subs) for subs in self._events.values()]):
|
|
@@ -102,8 +102,6 @@ class TargetSpace:
|
|
|
102
102
|
else:
|
|
103
103
|
self._constraint_values = np.empty(shape=(0, constraint.lb.size), dtype=float)
|
|
104
104
|
|
|
105
|
-
self._sorting_warning_already_shown = False # TODO: remove in future version
|
|
106
|
-
|
|
107
105
|
def __contains__(self, x: NDArray[Float]) -> bool:
|
|
108
106
|
"""Check if this parameter has already been registered.
|
|
109
107
|
|
|
@@ -332,17 +330,6 @@ class TargetSpace:
|
|
|
332
330
|
>>> len(space)
|
|
333
331
|
1
|
|
334
332
|
"""
|
|
335
|
-
# TODO: remove in future version
|
|
336
|
-
if isinstance(params, np.ndarray) and not self._sorting_warning_already_shown:
|
|
337
|
-
msg = (
|
|
338
|
-
"You're attempting to register an np.ndarray. Currently, the optimizer internally sorts"
|
|
339
|
-
" parameters by key and expects any registered array to respect this order. In future"
|
|
340
|
-
" versions this behaviour will change and the order as given by the pbounds dictionary"
|
|
341
|
-
" will be used. If you wish to retain sorted parameters, please manually sort your pbounds"
|
|
342
|
-
" dictionary before constructing the optimizer."
|
|
343
|
-
)
|
|
344
|
-
warn(msg, stacklevel=1)
|
|
345
|
-
self._sorting_warning_already_shown = True
|
|
346
333
|
x = self._as_array(params)
|
|
347
334
|
if x in self:
|
|
348
335
|
if self._allow_duplicate_points:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|