Beispiel #1
0
 def __init__(
     self,
     return_sequences: bool = False,
     bidirectional: Optional[Union[bool, hyperparameters.Boolean]] = None,
     num_layers: Optional[Union[int, hyperparameters.Choice]] = None,
     layer_type: Optional[Union[str, hyperparameters.Choice]] = None,
     **kwargs,
 ):
     super().__init__(**kwargs)
     self.return_sequences = return_sequences
     self.bidirectional = utils.get_hyperparameter(
         bidirectional,
         hyperparameters.Boolean("bidirectional", default=True),
         bool,
     )
     self.num_layers = utils.get_hyperparameter(
         num_layers,
         hyperparameters.Choice("num_layers", [1, 2, 3], default=2),
         int,
     )
     self.layer_type = utils.get_hyperparameter(
         layer_type,
         hyperparameters.Choice("layer_type", ["gru", "lstm"],
                                default="lstm"),
         str,
     )
Beispiel #2
0
def test_Boolean():
    # Test default default
    boolean = hp_module.Boolean('bool')
    assert boolean.default is False
    # Test default setting
    boolean = hp_module.Boolean('bool', default=True)
    assert boolean.default is True
    # Wrong default type
    with pytest.raises(ValueError, match='must be a Python boolean'):
        hp_module.Boolean('bool', default=None)
    # Test serialization
    boolean = hp_module.Boolean('bool', default=True)
    boolean = hp_module.Boolean.from_config(boolean.get_config())
    assert boolean.default is True
    assert boolean.name == 'bool'

    # Test random_sample
    assert boolean.random_sample() in {True, False}
    assert boolean.random_sample(123) == boolean.random_sample(123)