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)
def test_local_line_graph(): edges = [('a3', 'a2'), ('a2', 'c1'), ('c1', 'b1'), ('b1', 'a1'), ('a1', 'b2'), ('b2', 'b3')] groups = [{'a1', 'a2', 'a3'}, {'b1', 'b2', 'b3'}, {'c1'}] known_vals = {'a1': 4, 'a2': 4, 'a3': 0, 'b1': 6, 'b2': 4, 'b3': 0, 'c1': 0} G = nx.Graph() G.add_edges_from(edges) assert_dict_almost_equal(local_gefura(G, groups, normalized=False), known_vals)
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)
def test_local_directed(): edges = [('a1', 'a2'), ('a1', 'b1'), ('a2', 'a1'), ('a2', 'a3'), ('b1', 'b2'), ('b1', 'c1'), ('c1', 'a1'), ('c2', 'c1')] groups = [{'a1', 'a2', 'a3'}, {'b1', 'b2'}, {'c1', 'c2'}] known_out = {'a1': 0.375, 'a2': 0, 'a3': 0, 'b1': 0, 'b2': 0, 'c1': 1, 'c2': 0} known_in = {'a1': 0.75, 'a2': 0.375, 'a3': 0, 'b1': 0.8, 'b2': 0, 'c1': 0, 'c2': 0} known_all = {'a1': 9 / 16, 'a2': 3 / 16, 'a3': 0, 'b1': 0.4, 'b2': 0, 'c1': 0.5, 'c2': 0} G = nx.DiGraph() G.add_edges_from(edges) for d, vals in (('out', known_out), ('in', known_in), ('all', known_all)): assert_dict_almost_equal(local_gefura(G, groups, direction=d), vals)
def test_local(self): known_vals_unnormalized_out = {'a1': 0.5, 'a2': 1, 'b1': 0, 'b2': 0} known_vals_unnormalized_in = {'a1': 1, 'a2': 0, 'b1': 0.5, 'b2': 0} known_vals_unnormalized_all = {'a1': 1.5, 'a2': 1, 'b1': 0.5, 'b2': 0} known_vals_normalized_out = {'a1': 0.25, 'a2': 0.5, 'b1': 0, 'b2': 0} known_vals_normalized_in = {'a1': 0.5, 'a2': 0, 'b1': 0.25, 'b2': 0} known_vals_normalized_all = {'a1': 0.375, 'a2': 0.25, 'b1': 0.125, 'b2': 0} gamma_out = local_gefura(self.G, self.groups, normalized=False) assert_dict_almost_equal(gamma_out, known_vals_unnormalized_out) gamma_in = local_gefura(self.G, self.groups, normalized=False, direction='in') assert_dict_almost_equal(gamma_in, known_vals_unnormalized_in) gamma_all = local_gefura(self.G, self.groups, normalized=False, direction='all') assert_dict_almost_equal(gamma_all, known_vals_unnormalized_all) gamma_out = local_gefura(self.G, self.groups) assert_dict_almost_equal(gamma_out, known_vals_normalized_out) gamma_in = local_gefura(self.G, self.groups, direction='in') assert_dict_almost_equal(gamma_in, known_vals_normalized_in) gamma_all = local_gefura(self.G, self.groups, direction='all') assert_dict_almost_equal(gamma_all, known_vals_normalized_all)
def test_local_directed_wrong_direction_value(): local_gefura(nx.DiGraph(), [], direction="foobar")
def test_unnormalized(self): known_gamma = {'a1': 0.5, 'a2': 0, 'b1': 1.5, 'b2': 1.5, 'c1': 0.5, 'c2': 0} gamma = local_gefura(self.G, self.groups, normalized=False) assert_dict_almost_equal(gamma, known_gamma)
def test_normalized(self): known_gamma = {'a1': 0.125, 'a2': 0, 'b1': 0.375, 'b2': 0.375, 'c1': 0.125, 'c2': 0} gamma = local_gefura(self.G, self.groups) assert_dict_almost_equal(gamma, known_gamma)
def test_local(self): known_vals = dict(a1=1.5, a2=0.5, b1=2, b2=0.5, b3=0.5) gamma = local_gefura(self.G, self.groups, weight='weight', normalized=False) assert_dict_almost_equal(gamma, known_vals)