pg.dna_spec¶
Accessible via pg.dna_spec
, pg.search_space
, pg.hyper.dna_spec
, pg.hyper.search_space
.
- dna_spec(value, where=None)[source]¶
Returns the DNASpec from a (maybe) hyper value.
Example:
hyper = pg.Dict(x=pg.oneof([1, 2, 3]), y=pg.oneof(['a', 'b'])) spec = pg.dna_spec(hyper) assert spec.space_size == 6 assert len(spec.decision_points) == 2 print(spec.decision_points) # Select a partial space with `where` argument. spec = pg.dna_spec(hyper, where=lambda x: len(x.candidates) == 2) assert spec.space_size == 2 assert len(spec.decision_points) == 1
See also: :rtype:
pg.DNASpec
- Parameters:
value – A (maybe) hyper value.
where – Function to filter hyper primitives. If None, all hyper primitives from 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 very useful to partition a search space into separate optimization processes. Please see ‘Template’ docstr for details.
- Returns:
A DNASpec object, which represents the search space from algorithm’s view.