MCPcopy Create free account
hub / github.com/bayesian-optimization/BayesianOptimization / TargetSpace

Class TargetSpace

bayes_opt/target_space.py:35–714  ·  view source on GitHub ↗

Holds the param-space coordinates (X) and target values (Y). Allows for constant-time appends. Parameters ---------- target_func : function or None. Function to be maximized. pbounds : dict Dictionary with parameters names as keys and a tuple with minimum

Source from the content-addressed store, hash-verified

33
34
35class TargetSpace:
36 """Holds the param-space coordinates (X) and target values (Y).
37
38 Allows for constant-time appends.
39
40 Parameters
41 ----------
42 target_func : function or None.
43 Function to be maximized.
44
45 pbounds : dict
46 Dictionary with parameters names as keys and a tuple with minimum
47 and maximum values.
48
49 random_state : int, RandomState, or None
50 optionally specify a seed for a random number generator
51
52 allow_duplicate_points: bool, optional (default=False)
53 If True, the optimizer will allow duplicate points to be registered.
54 This behavior may be desired in high noise situations where repeatedly probing
55 the same point will give different answers. In other situations, the acquisition
56 may occasionally generate a duplicate point.
57
58 Examples
59 --------
60 >>> def target_func(p1, p2):
61 >>> return p1 + p2
62 >>> pbounds = {"p1": (0, 1), "p2": (1, 100)}
63 >>> space = TargetSpace(target_func, pbounds, random_state=0)
64 >>> x = np.array([4, 5])
65 >>> y = target_func(x)
66 >>> space.register(x, y)
67 >>> assert self.max()["target"] == 9
68 >>> assert self.max()["params"] == {"p1": 1.0, "p2": 2.0}
69 """
70
71 def __init__(
72 self,
73 target_func: Callable[..., float] | None,
74 pbounds: BoundsMapping,
75 constraint: NonlinearConstraint | None = None,
76 random_state: int | RandomState | None = None,
77 allow_duplicate_points: bool | None = False,
78 ) -> None:
79 self._allow_duplicate_points = allow_duplicate_points or False
80 self.n_duplicate_points = 0
81
82 # The function to be optimized
83 self.target_func = target_func
84
85 # Get the name of the parameters
86 self._keys: list[str] = list(pbounds.keys())
87
88 self._params_config = self.make_params(pbounds)
89 self._dim = sum([self._params_config[key].dim for key in self._keys])
90
91 self._masks = self.make_masks()
92 self._bounds = self.calculate_bounds()

Callers 15

target_spaceFunction · 0.90
constrained_target_spaceFunction · 0.90
test_float_parametersFunction · 0.90
test_int_parametersFunction · 0.90
test_cat_parametersFunction · 0.90
test_to_stringFunction · 0.90
test_wrapped_kernel_fitFunction · 0.90
test_params_to_arrayFunction · 0.90
test_array_to_paramsFunction · 0.90

Calls

no outgoing calls

Tested by 15

target_spaceFunction · 0.72
constrained_target_spaceFunction · 0.72
test_float_parametersFunction · 0.72
test_int_parametersFunction · 0.72
test_cat_parametersFunction · 0.72
test_to_stringFunction · 0.72
test_wrapped_kernel_fitFunction · 0.72
test_params_to_arrayFunction · 0.72
test_array_to_paramsFunction · 0.72