pg.random_sample¶
Accessible via pg.random_sample
, pg.hyper.random_sample
.
- random_sample(value, num_examples=None, where=None, seed=None)[source]¶
Returns an iterator of random sampled examples.
Example:
hyper_dict = pg.Dict(x=pg.oneof(range(3)), y=pg.floatv(0.0, 1.0)) # Generate one random example from the hyper_dict. d = next(pg.random_sample(hyper_dict)) # Generate 5 random examples with random seed. ds = list(pg.random_sample(hyper_dict, 5, seed=1)) # Generate 3 random examples of `x` with `y` intact. ds = list(pg.random_sample(hyper_dict, 3, where=lambda x: isinstance(x, pg.hyper.OneOf)))
- Parameters:
value – A (maybe) hyper value.
num_examples – An optional integer as number of examples to propose. If None, propose will return an iterator that iterates forever.
where – Function to filter hyper primitives. If None, all hyper primitives in value will be included in the encoding/decoding process. Otherwise only the hyper primitives on which ‘where’ returns True will be included. where can be useful to partition a search space into separate optimization processes. Please see ‘Template’ docstr for details.
seed – An optional integer as random seed.
- Returns:
Iterator of random examples.