Ejemplo n.º 1
0
 def test_reverse(self):
     """Check if it reverses `transform` properly, if possible."""
     t = Reverse(Quantize())
     assert t.reverse(8.6) == 8
     assert t.reverse(5.3) == 5
     assert numpy.all(
         t.reverse([8.6, 5.3]) == numpy.array([8, 5], dtype=int))
Ejemplo n.º 2
0
 def test_transform(self):
     """Check if it transforms properly."""
     t = Reverse(Quantize())
     assert t.transform(9) == 9.0
     assert t.transform(5) == 5.0
     assert numpy.all(
         t.transform([9, 5]) == numpy.array([9.0, 5.0], dtype=float))
Ejemplo n.º 3
0
 def test_domain_and_target_type(self):
     """Check if attribute-like `domain_type` and `target_type` do
     what's expected.
     """
     t = Reverse(Quantize())
     assert t.domain_type == 'integer'
     assert t.target_type == 'real'
Ejemplo n.º 4
0
def test_quantization_does_not_violate_bounds():
    """Regress on bug that converts valid float in tdim to non valid excl. upper bound."""
    dim = Integer("yo", "uniform", 3, 7)
    transformers = [Reverse(Quantize())]
    tdim = TransformedDimension(Compose(transformers, dim.type), dim)
    assert 11 not in dim
    assert 10 in dim
    # but be careful, because upper bound is inclusive
    assert 11.5 not in tdim
    assert 10.6 in tdim
    assert tdim.reverse(9.6) in dim
    # solution is to quantize with 'floor' instead of 'round'
    assert tdim.reverse(9.6) == 9
Ejemplo n.º 5
0
 def test_repr_format(self):
     """Check representation of a transformed dimension."""
     t = Reverse(Quantize())
     assert t.repr_format('asfa') == 'ReverseQuantize(asfa)'
Ejemplo n.º 6
0
 def test_no_reverse_one_hot_encode(self):
     """Do NOT support real to categorical."""
     with pytest.raises(AssertionError):
         Reverse(OneHotEncode([1, 2, 3]))
Ejemplo n.º 7
0
 def test_infer_target_shape(self):
     """Check if it infers the shape of a transformed `Dimension`."""
     t = Reverse(Quantize())
     assert t.infer_target_shape((5,)) == (5,)
Ejemplo n.º 8
0
 def test_deepcopy(self):
     """Verify that the transformation object can be copied"""
     t = Reverse(Quantize())
     t.transform([2])
     copy.deepcopy(t)