Пример #1
0
    def test_global(self):
        known_vals_unnormalized = {'a1': 1.5, 'a2': 1, 'b1': 0.5, 'b2': 0}
        known_vals_normalized = {'a1': 0.375, 'a2': 0.25, 'b1': 0.125,
                                 'b2': 0}

        gamma = global_gefura(self.G, self.groups, normalized=False)
        assert_dict_almost_equal(gamma, known_vals_unnormalized)
        assert_dict_almost_equal(global_gefura(self.G, self.groups),
                                 known_vals_normalized)
Пример #2
0
def test_singleton_groups():
    G = nx.Graph()
    G.add_edge(1, 2)
    groups = [{1}, {2}]
    expected = {1: 0., 2: 0.}

    assert_dict_almost_equal(global_gefura(G, groups, normalized=False),
                             expected)
    # Normalization should not throw ZeroDivisionError
    assert_dict_almost_equal(global_gefura(G, groups), expected)
Пример #3
0
def test_2_groups_line_graph():
    edges = [('a1', 'a2'), ('a2', 'b1'), ('b1', 'b2'), ('b2', 'b3')]
    groups = [{'a1', 'a2'}, {'b1', 'b2', 'b3'}]
    known_vals = {'a1': 0, 'a2': 1, 'b1': 1, 'b2': 0.5, 'b3': 0}
    G = nx.Graph()
    G.add_edges_from(edges)

    assert_dict_almost_equal(global_gefura(G, groups), known_vals)
    assert_dict_almost_equal(local_gefura(G, groups), known_vals)
Пример #4
0
def test_line_graph():
    edges = [('a1', 'b1'), ('b1', 'b2'), ('b2', 'c1'), ('c1', 'c2'),
             ('c2', 'b3'), ('b3', 'a2')]
    known_vals = {'a1': 0, 'a2': 0, 'b1': 4 / 12, 'b2': 6 / 12, 'b3': 4 / 12,
                  'c1': 6 / 11, 'c2': 5 / 11}
    G = nx.Graph()
    G.add_edges_from(edges)
    groups = [{'a1', 'a2'}, {'b1', 'b2', 'b3'}, {'c1', 'c2'}]

    assert_dict_almost_equal(global_gefura(G, groups), known_vals)
Пример #5
0
def test_3_groups():
    edges = [('a1', 'a2'), ('a1', 'a3'), ('a2', 'a3'), ('a3', 'b1'),
             ('a2', 'b2'), ('b1', 'b2'), ('b2', 'c1'), ('b1', 'c3'),
             ('b2', 'c2'), ('c2', 'c3')]
    known_vals = {'a1': 0, 'a2': 13 / 48, 'a3': 17 / 96, 'b1': 29 / 90,
                  'b2': 5 / 9, 'c1': 0, 'c2': 5 / 96, 'c3': 5 / 96}
    G = nx.Graph()
    G.add_edges_from(edges)
    groups = [{'a1', 'a2', 'a3'}, {'b1', 'b2'}, {'c1', 'c2', 'c3'}]

    assert_dict_almost_equal(global_gefura(G, groups), known_vals)
Пример #6
0
def test_2_groups_unnormalized():
    edges = [('b1', 'a1'), ('a1', 'a2'), ('a1', 'b2'),
             ('a2', 'a3'), ('a3', 'b2')]
    groups = [{'a1', 'a2', 'a3'}, {'b1', 'b2'}]
    known_vals = {'a1': 2.5, 'a2': 0.5, 'a3': 0.5, 'b1': 0, 'b2': 0.5}
    G = nx.Graph()
    G.add_edges_from(edges)

    assert_dict_almost_equal(global_gefura(G, groups, normalized=False),
                             known_vals)
    assert_dict_almost_equal(local_gefura(G, groups, normalized=False),
                             known_vals)
Пример #7
0
    def test_global_ignore_weights(self):
        known_vals = {'a1': 1 / 3, 'a2': 1 / 3,
                      'b1': 0.25, 'b2': 0.25, 'b3': 0}

        gamma = global_gefura(self.G, self.groups)
        assert_dict_almost_equal(gamma, known_vals)
Пример #8
0
    def test_global(self):
        known_vals = {'a1': 0.5, 'a2': 1 / 6,
                      'b1': 0.5, 'b2': 0.125, 'b3': 0.125}

        gamma = global_gefura(self.G, self.groups, weight='weight')
        assert_dict_almost_equal(gamma, known_vals)