Пример #1
0
def test_disc_entropy_constant_vals_2d():
    """If each column in x (matrix), then H(x) = 0"""
    same_val_arr_zero = np.zeros((50, 1))
    same_val_arr_ones = np.ones((50, 1))
    same_multi_val_arr = np.concatenate((same_val_arr_ones, same_val_arr_zero),
                                        axis=1)
    H_hat = _estimate_disc_entropy(same_multi_val_arr)
    assert 0 == H_hat
Пример #2
0
def test_cont_disc_entropy_differs_cont():
    """Expect cont, disc columns to have different entropy"""
    cont = asarray2d(np.arange(50)) + 0.5
    epsilon = _compute_epsilon(cont)

    H_cont = _estimate_cont_entropy(cont, epsilon)
    H_disc = _estimate_disc_entropy(cont)

    assert H_cont != H_disc
Пример #3
0
def test_disc_entropy_two_values():
    """Entropy of fair coin ~= log(2)"""
    same_val_arr_zero = np.zeros((50, 1))
    same_val_arr_ones = np.ones((50, 1))
    diff_val_arr = np.concatenate((same_val_arr_ones, same_val_arr_zero),
                                  axis=0)

    expected_h = np.log(2)
    H_hat = _estimate_disc_entropy(diff_val_arr)
    assert round(abs(expected_h - H_hat), 7) == 0
Пример #4
0
    def test_disc_entropy_two_values(self):
        """Entropy of fair coin ~= log(2)"""
        same_val_arr_zero = np.zeros((50, 1))
        same_val_arr_ones = np.ones((50, 1))
        diff_val_arr = np.concatenate((same_val_arr_ones, same_val_arr_zero),
                                      axis=0)

        expected_h = np.log(2)
        H_hat = _estimate_disc_entropy(diff_val_arr)
        self.assertAlmostEqual(expected_h, H_hat)
Пример #5
0
def test_cont_disc_entropy_differs_disc(get_disc_columns):
    """Expect cont, disc columns to have different entropy"""
    disc = asarray2d(np.arange(50))

    # we run into trouble here because as disc as *actually* discrete,
    # epsilon would not be calculated (it is set to some dummy value of
    # -inf). instead, we patch get_disc_columns and "force" epsilon to be
    # calculated
    epsilon = _compute_epsilon(disc)
    H_cont = _estimate_cont_entropy(disc, epsilon)

    H_disc = _estimate_disc_entropy(disc)

    assert H_cont != H_disc
Пример #6
0
def test_disc_entropy_constant_vals_1d():
    """If x (column vector) is constant, then H(x) = 0"""
    same_val_arr_ones = np.ones((50, 1))
    H_hat = _estimate_disc_entropy(same_val_arr_ones)
    assert 0 == H_hat