@@ -236,10 +236,28 @@ def probe(self, params: ParamsType, lazy: bool = True) -> None:
236
236
self ._space .keys , self ._space .res ()[- 1 ], self ._space .params_config , self .max
237
237
)
238
238
239
+ def random_sample (self , n : int = 1 ) -> dict [str , float | NDArray [Float ]]:
240
+ """Generate a random sample of parameters from the target space.
241
+
242
+ Parameters
243
+ ----------
244
+ n: int, optional(default=1)
245
+ Number of random samples to generate.
246
+
247
+ Returns
248
+ -------
249
+ list of dict
250
+ List of randomly sampled parameters.
251
+ """
252
+ return [
253
+ self ._space .array_to_params (self ._space .random_sample (random_state = self ._random_state ))
254
+ for _ in range (n )
255
+ ]
256
+
239
257
def suggest (self ) -> dict [str , float | NDArray [Float ]]:
240
258
"""Suggest a promising point to probe next."""
241
259
if len (self ._space ) == 0 :
242
- return self ._space . array_to_params ( self . _space . random_sample (random_state = self . _random_state ))
260
+ return self .random_sample (1 )[ 0 ]
243
261
244
262
# Finding argmax of the acquisition function.
245
263
suggestion = self ._acquisition_function .suggest (
@@ -259,9 +277,7 @@ def _prime_queue(self, init_points: int) -> None:
259
277
if not self ._queue and self ._space .empty :
260
278
init_points = max (init_points , 1 )
261
279
262
- for _ in range (init_points ):
263
- sample = self ._space .random_sample (random_state = self ._random_state )
264
- self ._queue .append (self ._space .array_to_params (sample ))
280
+ self ._queue .extend (self .random_sample (init_points ))
265
281
266
282
def maximize (self , init_points : int = 5 , n_iter : int = 25 ) -> None :
267
283
r"""
0 commit comments