matchzoo.engine.hyper_spaces
¶
Hyper parameter search spaces wrapping hyperopt.
Module Contents¶
Classes¶
Hyperopt proxy class. |
|
|
|
|
|
|
Functions¶
|
|
|
Take a sample in the hyper space. |
-
class
matchzoo.engine.hyper_spaces.
HyperoptProxy
(hyperopt_func: typing.Callable[…, hyperopt.pyll.Apply], **kwargs)¶ Bases:
object
Hyperopt proxy class.
See hyperopt’s documentation for more details: https://github.com/hyperopt/hyperopt/wiki/FMin
Reason of these wrappers:
A hyper space in hyperopt requires a label to instantiate. This label is used later as a reference to original hyper space that is sampled. In matchzoo, hyper spaces are used in
matchzoo.engine.Param
. Only if a hyper space’s label matches its parentmatchzoo.engine.Param
’s name, matchzoo can correctly back-refrenced the parameter got sampled. This can be done by asking the user always use the same name for a parameter and its hyper space, but typos can occur. As a result, these wrappers are created to hide hyper spaces’ label, and always correctly bind them with its parameter’s name.- Examples::
>>> import matchzoo as mz >>> from hyperopt.pyll.stochastic import sample
- Basic Usage:
>>> model = mz.models.DenseBaseline() >>> sample(model.params.hyper_space) {'mlp_num_layers': 1.0, 'mlp_num_units': 274.0}
- Arithmetic Operations:
>>> new_space = 2 ** mz.hyper_spaces.quniform(2, 6) >>> model.params.get('mlp_num_layers').hyper_space = new_space >>> sample(model.params.hyper_space) {'mlp_num_layers': 8.0, 'mlp_num_units': 292.0}
-
convert
(self, name: str) → hyperopt.pyll.Apply¶ Attach name as hyperopt.hp’s label.
- Parameters
name –
- Returns
a hyperopt ready search space
-
__add__
(self, other)¶ __add__.
-
__radd__
(self, other)¶ __radd__.
-
__sub__
(self, other)¶ __sub__.
-
__rsub__
(self, other)¶ __rsub__.
-
__mul__
(self, other)¶ __mul__.
-
__rmul__
(self, other)¶ __rmul__.
-
__truediv__
(self, other)¶ __truediv__.
-
__rtruediv__
(self, other)¶ __rtruediv__.
-
__floordiv__
(self, other)¶ __floordiv__.
-
__rfloordiv__
(self, other)¶ __rfloordiv__.
-
__pow__
(self, other)¶ __pow__.
-
__rpow__
(self, other)¶ __rpow__.
-
__neg__
(self)¶ __neg__.
-
matchzoo.engine.hyper_spaces.
_wrap_as_composite_func
(self, other, func)¶
-
class
matchzoo.engine.hyper_spaces.
choice
(options: list)¶ Bases:
matchzoo.engine.hyper_spaces.HyperoptProxy
hyperopt.hp.choice()
proxy.-
__str__
(self)¶ - Returns
str representation of the hyper space.
-
-
class
matchzoo.engine.hyper_spaces.
quniform
(low: numbers.Number, high: numbers.Number, q: numbers.Number = 1)¶ Bases:
matchzoo.engine.hyper_spaces.HyperoptProxy
hyperopt.hp.quniform()
proxy.-
__str__
(self)¶ - Returns
str representation of the hyper space.
-
-
class
matchzoo.engine.hyper_spaces.
uniform
(low: numbers.Number, high: numbers.Number)¶ Bases:
matchzoo.engine.hyper_spaces.HyperoptProxy
hyperopt.hp.uniform()
proxy.-
__str__
(self)¶ - Returns
str representation of the hyper space.
-
-
matchzoo.engine.hyper_spaces.
sample
(space)¶ Take a sample in the hyper space.
This method is stateless, so the distribution of the samples is different from that of tune call. This function just gives a general idea of what a sample from the space looks like.
Example
>>> import matchzoo as mz >>> space = mz.models.DenseBaseline.get_default_params().hyper_space >>> mz.hyper_spaces.sample(space) {'mlp_num_fan_out': ...}