Beispiel #1
0
def test_bildegree():
    deg = Network.SmallDirectedTestNetwork().bildegree()
    deg_ref = np.array([0, 0, 0, 0, 0, 0], dtype=np.int16)
    assert (deg == deg_ref).all()

    net = Network.SmallTestNetwork()
    assert (net.bildegree() == net.degree()).all()
Beispiel #2
0
def test_nsi_outdegree():
    net = Network.SmallDirectedTestNetwork()

    deg_ref = np.array([5.3, 5.9, 1.9, 3.8, 5.7, 4.])
    assert np.allclose(net.nsi_outdegree(), deg_ref)

    deg_ref = np.array([5.3, 5.9, 1.9, 3.8, 5.7, 4., 4.])
    assert np.allclose(net.splitted_copy().nsi_outdegree(), deg_ref)
Beispiel #3
0
def test_nsi_indegree():
    net = Network.SmallDirectedTestNetwork()

    deg_ref = np.array([6.3, 5.3, 5.9, 3.6, 4., 2.5])
    assert np.allclose(net.nsi_indegree(), deg_ref)

    deg_ref = np.array([6.3, 5.3, 5.9, 3.6, 4., 2.5, 2.5])
    assert np.allclose(net.splitted_copy().nsi_indegree(), deg_ref)
Beispiel #4
0
def test_nsi_local_midmotif_clustering():
    net = Network.SmallDirectedTestNetwork()

    res = net.nsi_local_midmotif_clustering()
    exp = np.array([0.45372866, 0.51646946, 1., 1., 0.88815789, 1.])
    assert np.allclose(res, exp)

    res = net.splitted_copy(node=4).local_midmotif_clustering()
    exp = np.array([0., 0., 0., 1., 0.8, 0., 0.8])
    assert np.allclose(res, exp)
Beispiel #5
0
def test_nsi_local_outmotif_clustering():
    net = Network.SmallDirectedTestNetwork()

    res = net.nsi_local_outmotif_clustering()
    exp = np.array(
        [0.66998932, 0.66934789, 1., 0.75277008, 0.58387196, 0.765625])
    assert np.allclose(res, exp)

    res = net.splitted_copy(node=1).nsi_local_outmotif_clustering()
    exp = np.array([
        0.66998932, 0.66934789, 1., 0.75277008, 0.58387196, 0.765625,
        0.66934789
    ])
    assert np.allclose(res, exp)
Beispiel #6
0
def test_nsi_local_inmotif_clustering():
    net = Network.SmallDirectedTestNetwork()

    res = net.nsi_local_inmotif_clustering()
    exp = np.array(
        [0.52884858, 0.66998932, 0.66934789, 0.75694444, 0.755625, 1.])
    assert np.allclose(res, exp)

    res = net.splitted_copy(node=1).nsi_local_inmotif_clustering()
    exp = np.array([
        0.52884858, 0.66998932, 0.66934789, 0.75694444, 0.755625, 1.,
        0.66998932
    ])
    assert np.allclose(res, exp)
Beispiel #7
0
def test_nsi_local_cyclemotif_clustering():
    net = Network.SmallDirectedTestNetwork()

    res = net.nsi_local_cyclemotif_clustering()
    exp = np.array(
        [0.18448637, 0.20275024, 0.3220339, 0.32236842, 0.34385965, 0.625])
    assert np.allclose(res, exp)

    res = net.splitted_copy(node=1).nsi_local_cyclemotif_clustering()
    exp = np.array([
        0.18448637, 0.20275024, 0.3220339, 0.32236842, 0.34385965, 0.625,
        0.20275024
    ])
    assert np.allclose(res, exp)
Beispiel #8
0
def test_nsi_twinness():
    net = Network.SmallDirectedTestNetwork()

    res = net.nsi_twinness()
    exp = np.array([[0.12931034, 0.45689655, 0., 0.31034483, 0., 0.],
                    [0., 0.15178571, 0.52678571, 0., 0.35714286, 0.],
                    [0., 0., 0.24358974, 0., 0., 0.],
                    [0., 0.33928571, 0., 0.28378378, 0., 0.],
                    [0.32758621, 0., 0.43298969, 0., 0.2371134, 0.],
                    [0.34482759, 0., 0., 0., 0., 0.38461538]])
    assert np.allclose(res, exp)

    res = net.splitted_copy().nsi_twinness()
    exp = np.array([[0.12931034, 0.45689655, 0., 0.31034483, 0., 0., 0.],
                    [0., 0.15178571, 0.52678571, 0., 0.35714286, 0., 0.],
                    [0., 0., 0.24358974, 0., 0., 0., 0.],
                    [0., 0.33928571, 0., 0.28378378, 0., 0., 0.],
                    [0.32758621, 0., 0.43298969, 0., 0.2371134, 0., 0.],
                    [0.34482759, 0., 0., 0., 0., 0.38461538, 0.38461538],
                    [0.34482759, 0., 0., 0., 0., 0.38461538, 0.38461538]])
    assert np.allclose(res, exp)
Beispiel #9
0
def testNSI():
    """
    Consistency of nsi measures with splitted network copies
    """
    dnw = Network.SmallDirectedTestNetwork()
    nw = Network.SmallTestNetwork()

    nsi_measures = [
        "nsi_degree", "nsi_indegree", "nsi_outdegree", "nsi_closeness",
        "nsi_harmonic_closeness", "nsi_exponential_closeness",
        "nsi_arenas_betweenness", "nsi_spreading",
        "nsi_local_cyclemotif_clustering", "nsi_local_midmotif_clustering",
        "nsi_local_inmotif_clustering", "nsi_local_outmotif_clustering",
        ("nsi_degree", {
            "key": "link_weights"
        }), ("nsi_indegree", {
            "key": "link_weights"
        }), ("nsi_outdegree", {
            "key": "link_weights"
        }), ("nsi_local_cyclemotif_clustering", {
            "key": "link_weights"
        }), ("nsi_local_midmotif_clustering", {
            "key": "link_weights"
        }), ("nsi_local_inmotif_clustering", {
            "key": "link_weights"
        }), ("nsi_local_outmotif_clustering", {
            "key": "link_weights"
        })
    ]

    nsi_undirected_measures = [
        "nsi_local_clustering", "nsi_average_neighbors_degree",
        "nsi_max_neighbors_degree", "nsi_eigenvector_centrality",
        "nsi_local_clustering", "nsi_local_soffer_clustering",
        "nsi_newman_betweenness"
    ]

    compareNSI(dnw, nsi_measures)
    compareNSI(nw, nsi_measures + nsi_undirected_measures)
Beispiel #10
0
def test_local_outmotif_clustering():
    res = Network.SmallDirectedTestNetwork().local_outmotif_clustering()
    exp = np.array([0.5, 0.5, 0., 0., 0., 0.])
    assert np.allclose(res, exp)
Beispiel #11
0
def test_outdegree():
    deg = Network.SmallDirectedTestNetwork().outdegree()
    deg_ref = np.array([2, 2, 0, 1, 2, 1])
    assert (deg == deg_ref).all()
Beispiel #12
0
def test_indegree():
    deg = Network.SmallDirectedTestNetwork().indegree()
    deg_ref = np.array([2, 2, 2, 1, 1, 0])
    assert (deg == deg_ref).all()