Esempio n. 1
0
def test_mi(data_with_redundancy):  # pylint: disable=redefined-outer-name
    random.seed(SEED)
    from ndd.nsb import mutual_information
    h1 = ndd.from_data(data_with_redundancy[1])
    h2 = ndd.from_data(data_with_redundancy[2])
    h12 = ndd.from_data(data_with_redundancy[[1, 2]])
    mi = h1 + h2 - h12
    assert numpy.isclose(mutual_information(data_with_redundancy[[1, 2]]), mi)
Esempio n. 2
0
def test_mi(data_with_redundancy):
    random.seed(SEED)
    from ndd.nsb import mutual_information
    h1 = ndd.from_data(data_with_redundancy[1])
    h2 = ndd.from_data(data_with_redundancy[2])
    h12 = ndd.from_data(data_with_redundancy[[1, 2]])
    mi = h1 + h2 - h12
    estimate = mutual_information(data_with_redundancy[[1, 2]])
    assert numpy.isclose(estimate, mi)
Esempio n. 3
0
def test_conditional_entropy(data_with_redundancy):
    random.seed(SEED)
    from ndd.nsb import mutual_information
    data = data_with_redundancy[[1, 2]]
    estimate = (ndd.from_data(data) - ndd.conditional_entropy(data, c=0) -
                ndd.conditional_entropy(data, c=1))
    assert numpy.isclose(estimate, mutual_information(data), atol=0.01)
Esempio n. 4
0
def test_conditional_entropy(data_with_redundancy):  # pylint: disable=redefined-outer-name
    random.seed(SEED)
    from ndd.nsb import mutual_information
    data = data_with_redundancy[[1, 2]]
    assert numpy.isclose(mutual_information(data),
                         ndd.from_data(data) -
                         ndd.conditional_entropy(data, c=0) -
                         ndd.conditional_entropy(data, c=1),
                         atol=0.01)
Esempio n. 5
0
def test_mmi(data_with_redundancy):  # pylint: disable=redefined-outer-name
    random.seed(SEED)
    from ndd.nsb import interaction_information
    h0 = ndd.from_data(data_with_redundancy[0])
    h1 = ndd.from_data(data_with_redundancy[1])
    h2 = ndd.from_data(data_with_redundancy[2])
    h01 = ndd.from_data(data_with_redundancy[[0, 1]])
    h02 = ndd.from_data(data_with_redundancy[[0, 2]])
    h12 = ndd.from_data(data_with_redundancy[[1, 2]])
    h012 = ndd.from_data(data_with_redundancy)
    mmi = -(h0 + h1 + h2 - h01 - h02 - h12 + h012)
    assert numpy.isclose(interaction_information(data_with_redundancy), mmi)
Esempio n. 6
0
def test_mmi(data_with_redundancy):
    random.seed(SEED)
    from ndd.nsb import interaction_information
    h0 = ndd.from_data(data_with_redundancy[0], ks=[3])
    h1 = ndd.from_data(data_with_redundancy[1], ks=[3])
    h2 = ndd.from_data(data_with_redundancy[2], ks=[3])
    h01 = ndd.from_data(data_with_redundancy[[0, 1]], ks=[3] * 2)
    h02 = ndd.from_data(data_with_redundancy[[0, 2]], ks=[3] * 2)
    h12 = ndd.from_data(data_with_redundancy[[1, 2]], ks=[3] * 2)
    h012 = ndd.from_data(data_with_redundancy, ks=[3] * 3)
    mmi = -(h0 + h1 + h2 - h01 - h02 - h12 + h012)
    estimate = interaction_information(data_with_redundancy, ks=[3] * 3)
    assert numpy.isclose(estimate, mmi, atol=0.01)