bayesian-optimization 2.0.1__tar.gz → 2.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bayesian-optimization
3
- Version: 2.0.1
3
+ Version: 2.0.3
4
4
  Summary: Bayesian Optimization package
5
5
  License: MIT
6
6
  Author: Fernando Nogueira
@@ -15,7 +15,8 @@ Classifier: Programming Language :: Python :: 3.13
15
15
  Requires-Dist: colorama (>=0.4.6,<0.5.0)
16
16
  Requires-Dist: numpy (>=1.25)
17
17
  Requires-Dist: scikit-learn (>=1.0.0,<2.0.0)
18
- Requires-Dist: scipy (>=1.0.0,<2.0.0)
18
+ Requires-Dist: scipy (>=1.0.0,<2.0.0) ; python_version < "3.13"
19
+ Requires-Dist: scipy (>=1.14.1,<2.0.0) ; python_version >= "3.13"
19
20
  Description-Content-Type: text/markdown
20
21
 
21
22
  <div align="center">
@@ -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._queue.append(self._space.random_sample())
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:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "bayesian-optimization"
3
- version = "2.0.1"
3
+ version = "2.0.3"
4
4
  description = "Bayesian Optimization package"
5
5
  authors = ["Fernando Nogueira"]
6
6
  license = "MIT"
@@ -11,7 +11,10 @@ packages = [{include = "bayes_opt"}]
11
11
  python = "^3.9"
12
12
  scikit-learn = "^1.0.0"
13
13
  numpy = ">=1.25"
14
- scipy = "^1.0.0"
14
+ scipy = [
15
+ {version = "^1.0.0", python = "<3.13"},
16
+ {version = "^1.14.1", python = ">=3.13"}
17
+ ]
15
18
  colorama = "^0.4.6"
16
19
 
17
20