Esempio n. 1
0
def test_discretize_nd_box():
    cont = Box(np.array([0.0, 1.0]), np.array([1.0, 2.0]))
    trafo = discretize(cont, 10)

    assert trafo.target == MultiDiscrete([(0, 9), (0, 9)])
    check_convert(trafo, (0, 0), [0.0, 1.0])
    check_convert(trafo, (9, 9), [1.0, 2.0])

    trafo = discretize(cont, (5, 10))

    assert trafo.target == MultiDiscrete([(0, 4), (0, 9)])
    check_convert(trafo, (0, 0), [0.0, 1.0])
    check_convert(trafo, (4, 9), [1.0, 2.0])
Esempio n. 2
0
def test_discretize_errors():
    cont = Box(np.array([0.0, 1.0]), np.array([1.0, 2.0]))
    with pytest.raises(TypeError):
        trafo = discretize(5, 5)

    with pytest.raises(ValueError):
        trafo = discretize(cont, 1)

    with pytest.raises(NotImplementedError):
        trafo = discretize(Tuple(spaces=[cont]), 10)

    with pytest.raises(ValueError):
        trafo = discretize(cont, [1, 1])

    with pytest.raises(ValueError):
        trafo = discretize(cont, [5, 5, 5])
Esempio n. 3
0
def test_discretize_1d_box():
    cont = Box(np.array([0.0]), np.array([1.0]))
    trafo = discretize(cont, 10)

    assert trafo.target == Discrete(10)
    assert trafo.convert_from(0) == 0.0
    assert trafo.convert_from(9) == 1.0
    assert trafo.convert_to(0.0) == 0
    assert trafo.convert_to(1.0) == 9
def test_discretize_nd_box():
    from space_wrappers.tests.space_equal import expects

    cont = Box(np.array([0.0, 1.0]), np.array([1.0, 2.0]), dtype=np.float32)
    trafo = discretize(cont, 10)

    assert trafo.target == expects(MultiDiscrete([10, 10]))
    check_convert(trafo, (0, 0), [0.0, 1.0])
    check_convert(trafo, (9, 9), [1.0, 2.0])

    trafo = discretize(cont, (5, 10))

    assert trafo.target == expects(MultiDiscrete([5, 10]))
    check_convert(trafo, (0, 0), [0.0, 1.0])
    check_convert(trafo, (4, 9), [1.0, 2.0])

    # check that it also works with np.ndarray data
    check_convert(trafo, np.array([0, 0]), [0.0, 1.0])
Esempio n. 5
0
def test_discretize_discrete():
    start = Discrete(5)
    trafo = discretize(start, 10)
    assert trafo.target == start
    check_convert(trafo, 3, 3)