|
23 | 23 | DEFAULT_MAX_RS_DRAWS, |
24 | 24 | rejection_sample, |
25 | 25 | tunable_feature_indices, |
26 | | - validate_bounds, |
27 | 26 | ) |
28 | 27 | from ax.utils.common.docutils import copy_doc |
29 | 28 | from ax.utils.common.logger import get_logger |
@@ -85,6 +84,7 @@ def __init__( |
85 | 84 | # Used for deduplication. |
86 | 85 | self.fallback_to_sample_polytope = fallback_to_sample_polytope |
87 | 86 | self.polytope_sampler_kwargs: dict[str, Any] = polytope_sampler_kwargs or {} |
| 87 | + self._bounds: npt.NDArray = np.empty((0, 2)) |
88 | 88 | self.attempted_draws: int = 0 |
89 | 89 | if generated_points is not None: |
90 | 90 | # generated_points was deprecated in Ax 1.0.0, so it can now be reaped. |
@@ -146,15 +146,8 @@ def gen( |
146 | 146 | tf_indices = tunable_feature_indices( |
147 | 147 | bounds=search_space_digest.bounds, fixed_features=fixed_features |
148 | 148 | ) |
149 | | - if fixed_features: |
150 | | - fixed_feature_indices = np.array(list(fixed_features.keys())) |
151 | | - else: |
152 | | - fixed_feature_indices = np.array([]) |
| 149 | + self._bounds = np.array(search_space_digest.bounds) # (d, 2) |
153 | 150 |
|
154 | | - validate_bounds( |
155 | | - bounds=search_space_digest.bounds, |
156 | | - fixed_feature_indices=fixed_feature_indices, |
157 | | - ) |
158 | 151 | max_draws = DEFAULT_MAX_RS_DRAWS |
159 | 152 | discrete_indices = set(search_space_digest.discrete_choices.keys()) |
160 | 153 | continuous_indices = { |
@@ -282,22 +275,29 @@ def _gen_unconstrained( |
282 | 275 | An (n x d) array of generated points. |
283 | 276 |
|
284 | 277 | """ |
285 | | - tunable_points = self._gen_samples(n=n, tunable_d=len(tunable_feature_indices)) |
| 278 | + tunable_bounds = self._bounds[tunable_feature_indices] |
| 279 | + tunable_points = self._gen_samples( |
| 280 | + n=n, |
| 281 | + tunable_d=len(tunable_feature_indices), |
| 282 | + bounds=tunable_bounds, |
| 283 | + ) |
286 | 284 | return add_fixed_features( |
287 | 285 | tunable_points=tunable_points, |
288 | 286 | d=d, |
289 | 287 | tunable_feature_indices=tunable_feature_indices, |
290 | 288 | fixed_features=fixed_features, |
291 | 289 | ) |
292 | 290 |
|
293 | | - def _gen_samples(self, n: int, tunable_d: int) -> npt.NDArray: |
294 | | - """Generate n samples on [0, 1]^d. |
| 291 | + def _gen_samples(self, n: int, tunable_d: int, bounds: npt.NDArray) -> npt.NDArray: |
| 292 | + """Generate n samples within the given bounds. |
295 | 293 |
|
296 | 294 | Args: |
297 | 295 | n: Number of points to generate. |
| 296 | + tunable_d: Number of tunable dimensions. |
| 297 | + bounds: A (tunable_d x 2) array of (lower, upper) bounds. |
298 | 298 |
|
299 | 299 | Returns: |
300 | | - (n x d) array of generated points. |
| 300 | + (n x tunable_d) array of generated points. |
301 | 301 |
|
302 | 302 | """ |
303 | 303 | raise NotImplementedError("Base RandomGenerator can't generate samples.") |
@@ -359,7 +359,6 @@ def _convert_bounds(self, bounds: list[tuple[float, float]]) -> Tensor | None: |
359 | 359 |
|
360 | 360 | Args: |
361 | 361 | bounds: A list of (lower, upper) tuples for each column of X. |
362 | | - Defined on [0, 1]^d. |
363 | 362 |
|
364 | 363 | Returns: |
365 | 364 | Optional 2 x d tensor representing the bounds |
|
0 commit comments