bayesian-optimization 3.2.2__tar.gz → 3.3.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.
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/PKG-INFO +1 -1
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/bayesian_optimization.py +37 -19
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/pyproject.toml +1 -1
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/LICENSE +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/README.md +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/__init__.py +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/acquisition.py +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/constraint.py +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/domain_reduction.py +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/exception.py +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/logger.py +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/parameter.py +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/py.typed +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/target_space.py +0 -0
- {bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/util.py +0 -0
{bayesian_optimization-3.2.2 → bayesian_optimization-3.3.0}/bayes_opt/bayesian_optimization.py
RENAMED
|
@@ -26,7 +26,7 @@ from bayes_opt.target_space import TargetSpace
|
|
|
26
26
|
from bayes_opt.util import ensure_rng
|
|
27
27
|
|
|
28
28
|
if TYPE_CHECKING:
|
|
29
|
-
from collections.abc import Callable
|
|
29
|
+
from collections.abc import Callable
|
|
30
30
|
|
|
31
31
|
from numpy.random import RandomState
|
|
32
32
|
from numpy.typing import NDArray
|
|
@@ -85,7 +85,7 @@ class BayesianOptimization:
|
|
|
85
85
|
def __init__(
|
|
86
86
|
self,
|
|
87
87
|
f: Callable[..., float] | None,
|
|
88
|
-
pbounds:
|
|
88
|
+
pbounds: BoundsMapping,
|
|
89
89
|
acquisition_function: AcquisitionFunction | None = None,
|
|
90
90
|
constraint: NonlinearConstraint | None = None,
|
|
91
91
|
random_state: int | RandomState | None = None,
|
|
@@ -406,13 +406,13 @@ class BayesianOptimization:
|
|
|
406
406
|
params["kernel"] = wrap_kernel(kernel=params["kernel"], transform=self._space.kernel_transform)
|
|
407
407
|
self._gp.set_params(**params)
|
|
408
408
|
|
|
409
|
-
def
|
|
410
|
-
"""
|
|
409
|
+
def _state_to_dict(self) -> dict[str, Any]:
|
|
410
|
+
"""Convert optimizer state to a dictionary.
|
|
411
411
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
412
|
+
Returns
|
|
413
|
+
-------
|
|
414
|
+
dict
|
|
415
|
+
Dictionary containing the complete optimizer state.
|
|
416
416
|
"""
|
|
417
417
|
random_state = None
|
|
418
418
|
if self._random_state is not None:
|
|
@@ -428,7 +428,7 @@ class BayesianOptimization:
|
|
|
428
428
|
# Get constraint values if they exist
|
|
429
429
|
constraint_values = self._space._constraint_values.tolist() if self.is_constrained else None
|
|
430
430
|
acquisition_params = self._acquisition_function.get_acquisition_params()
|
|
431
|
-
|
|
431
|
+
return {
|
|
432
432
|
"pbounds": {key: self._space._bounds[i].tolist() for i, key in enumerate(self._space.keys)},
|
|
433
433
|
# Add current transformed bounds if using bounds transformer
|
|
434
434
|
"transformed_bounds": (self._space.bounds.tolist() if self._bounds_transformer else None),
|
|
@@ -448,20 +448,14 @@ class BayesianOptimization:
|
|
|
448
448
|
"acquisition_params": acquisition_params,
|
|
449
449
|
}
|
|
450
450
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
def load_state(self, path: str | PathLike[str]) -> None:
|
|
455
|
-
"""Load optimizer state from a JSON file.
|
|
451
|
+
def _load_state_dict(self, state: dict[str, Any]) -> None:
|
|
452
|
+
"""Load optimizer state from a dictionary.
|
|
456
453
|
|
|
457
454
|
Parameters
|
|
458
455
|
----------
|
|
459
|
-
|
|
460
|
-
|
|
456
|
+
state : dict
|
|
457
|
+
Dictionary containing the optimizer state.
|
|
461
458
|
"""
|
|
462
|
-
with Path(path).open("r") as file:
|
|
463
|
-
state = json.load(file)
|
|
464
|
-
|
|
465
459
|
params_array = np.asarray(state["params"], dtype=np.float64)
|
|
466
460
|
target_array = np.asarray(state["target"], dtype=np.float64)
|
|
467
461
|
constraint_array = (
|
|
@@ -504,3 +498,27 @@ class BayesianOptimization:
|
|
|
504
498
|
state["random_state"]["cached_gaussian"],
|
|
505
499
|
)
|
|
506
500
|
self._random_state.set_state(random_state_tuple)
|
|
501
|
+
|
|
502
|
+
def save_state(self, path: str | PathLike[str]) -> None:
|
|
503
|
+
"""Save complete state for reconstruction of the optimizer.
|
|
504
|
+
|
|
505
|
+
Parameters
|
|
506
|
+
----------
|
|
507
|
+
path : str or PathLike
|
|
508
|
+
Path to save the optimization state
|
|
509
|
+
"""
|
|
510
|
+
state = self._state_to_dict()
|
|
511
|
+
with Path(path).open("w") as f:
|
|
512
|
+
json.dump(state, f, indent=2)
|
|
513
|
+
|
|
514
|
+
def load_state(self, path: str | PathLike[str]) -> None:
|
|
515
|
+
"""Load optimizer state from a JSON file.
|
|
516
|
+
|
|
517
|
+
Parameters
|
|
518
|
+
----------
|
|
519
|
+
path : str or PathLike
|
|
520
|
+
Path to the JSON file containing the optimizer state.
|
|
521
|
+
"""
|
|
522
|
+
with Path(path).open("r") as file:
|
|
523
|
+
state = json.load(file)
|
|
524
|
+
self._load_state_dict(state)
|
|
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
|