Exemple #1
0
def test__update_hyperrectangles(make_random_dataset):
    """Testing if the updating of the hyperrectangles works as expected.
    As above, the core functionality is tested in for the function with the logic.
    Here, we're more interested in seeing how it works with the class object
    """
    X, _ = make_random_dataset  # pylint:disable=invalid-name
    palinstance = PALBase(X, ["model"], 4, beta_scale=1)

    palinstance._means = np.array([[0, 0, 1, 0], [0, 0, 0, 1]])
    palinstance.std = np.array([[0, 0, 0, 0], [1, 0, 0, 0]])
    with pytest.raises(TypeError):
        # Beta is not defined
        palinstance._update_hyperrectangles()

    palinstance._update_beta()
    palinstance._update_hyperrectangles()

    assert palinstance.rectangle_lows is not None
    assert palinstance.rectangle_ups is not None

    assert palinstance.rectangle_lows[0][0] == 0
    assert palinstance.rectangle_ups[0][0] == 0
    assert palinstance.rectangle_lows[0][2] == 1
    assert palinstance.rectangle_ups[0][2] == 1

    assert palinstance.rectangle_lows[1][0] < -1
    assert palinstance.rectangle_ups[1][0] > 1

    assert len(palinstance.hyperrectangle_sizes) == len(palinstance._means)
Exemple #2
0
def test_beta_update(make_random_dataset):
    """testing that the beta update works"""
    X, _ = make_random_dataset  # pylint:disable=invalid-name
    palinstance = PALBase(X, ["model"], 3)

    assert palinstance.beta is None

    palinstance._update_beta()
    assert palinstance.beta is not None

    assert palinstance.beta == 1 / 9 * 2 * np.log(
        3 * 100 * np.square(np.pi) * np.square(2) / (6 * 0.05))