def test_graphBD(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 1, 1, 0, 1, 0, 0, 0, 1], [0, 1, 0, 0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0, 1, 1, 0], [1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 0, 0, 1, 1, 0, 1, 1, 1], [1, 0, 1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0, 1, 1, 1], [0, 1, 0, 1, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 1, 0, 1, 0], [1, 0, 1, 0, 1, 1, 0, 1, 1, 0]]) graph_bd = GraphBD(A, measure_list[GraphBD], 'zero') MeasureDegree.compute_measure(graph_bd) self.assertSequenceEqual( graph_bd.measure_dict[MeasureDegree]['degree'].tolist(), [10, 7, 8, 10, 12, 11, 9, 10, 12, 9]) self.assertSequenceEqual( graph_bd.measure_dict[MeasureDegree]['in_degree'].tolist(), [5, 5, 5, 4, 6, 7, 2, 5, 7, 3]) self.assertSequenceEqual( graph_bd.measure_dict[MeasureDegree]['out_degree'].tolist(), [5, 2, 3, 6, 6, 4, 7, 5, 5, 6]) self.assertEqual(graph_bd.measure_dict[MeasureDegree]['avg_degree'], 9.8) self.assertEqual(graph_bd.measure_dict[MeasureDegree]['avg_in_degree'], 4.9) self.assertEqual( graph_bd.measure_dict[MeasureDegree]['avg_out_degree'], 4.9)
def test_bd_2(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 1, 1, 0, 1, 0, 0, 0, 1], [0, 1, 0, 0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 1, 0, 0, 0, 1, 1, 0], [1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 0, 0, 1, 1, 0, 1, 1, 1], [1, 0, 1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 1, 1, 0, 1, 1, 1], [0, 1, 0, 1, 1, 1, 0, 1, 1, 0], [0, 1, 1, 0, 1, 1, 1, 0, 1, 0], [1, 0, 1, 0, 1, 1, 0, 1, 1, 0]]) graph = GraphBD(A, measure_list[GraphBD], 'zero') self.assertAlmostEqual(graph.get_measure(MeasureAssortativity, 'assortativity_out_in'), -0.0840, places=4) self.assertAlmostEqual(graph.get_measure(MeasureAssortativity, 'assortativity_in_out'), -0.0420, places=4) self.assertAlmostEqual(graph.get_measure(MeasureAssortativity, 'assortativity_out_out'), -0.0810, places=4) self.assertAlmostEqual(graph.get_measure(MeasureAssortativity, 'assortativity_in_in'), -0.1476, places=4)
def test_modularity_1(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 1], [1, 0, 0], [1, 0, 0]]) graph = GraphBU(A, measure_list[GraphBU], 'zero', 'max') MeasureModularity.compute_measure(graph) self.assertAlmostEqual( graph.measure_dict[MeasureModularity]['modularity'], 0, places=4)
def test_graphBD(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 0, 1, 0], [1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 0, 0]]) graph_bd = GraphBD(A, measure_list[GraphBD], 'zero') MeasureTriangles.compute_measure(graph_bd) self.assertSequenceEqual( graph_bd.measure_dict[MeasureTriangles]['triangles'].tolist(), [1, 1, 1, 0])
def test_bd(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 1], [1, 0, 0], [1, 0, 0]]) graph = GraphBD(A, measure_list[GraphBD], 'zero') betweenness = [2, 0, 0] self.assertSequenceEqual( graph.get_measure(MeasureBetweenness, 'betweenness').tolist(), betweenness)
def test_graphBU_disconnected(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 1, 0], [1, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0]]) graph = GraphBU(A, measure_list[GraphBU], 'zero', 'max') true_distance = [[0.0, 1.0, 1.0, np.inf], [1.0, 0.0, 2.0, np.inf], [1.0, 2.0, 0.0, np.inf], [np.inf, np.inf, np.inf, 0.0]] self.assertSequenceEqual(graph.D.tolist(), true_distance)
def test_graphBU(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 1, 0, 0], [1, 0, 0, 0, 0]]) graph = GraphBU(A, measure_list[GraphBU], 'zero', 'max') eccentricity = [3, 2, 2, 3, 2] self.assertSequenceEqual( graph.get_measure(MeasureEccentricity, 'eccentricity').tolist(), eccentricity)
def test_graphBU(self): measure_list = MeasureParser.list_measures() A = np.array([[1, 0, 1, 1, 1], [0, 1, 1, 0, 1], [1, 0, 1, 1, 1], [0, 0, 0, 0, 0], [0, 1, 1, 0, 1]]) graph = GraphBU(A, measure_list[GraphBU], 'zero', 'max') true_path_length = [1.25, 1.5, 1.0, 1.5, 1.25] self.assertSequenceEqual( graph.get_measure(MeasurePathLength, 'path_length').tolist(), true_path_length)
def test_wu(self): measure_list = MeasureParser.list_measures() A = np.array([[3.2, 3.14, 2.7, 0.01, 0.0], [3.2, 2.7, 3.14, 6.7, -75], [13, 0.0, 1.2, 5.7, -0.01], [5.5, 8.2, 0.3, 0.0005, -0.5], [1, 0.0, 345, 8.7, -2]]) graph = GraphWU(A, measure_list[GraphWU], 'zero', 'max') self.assertAlmostEqual( graph.get_measure(MeasureAssortativity, 'assortativity'), -0.166126077)
def test_graphBD_large(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1], [0, 0, 1, 0, 0], [1, 0, 0, 0, 0]]) graph = GraphBD(A, measure_list[GraphBU], 'zero') true_distance = [[0.0, 1.0, 2.0, 3.0, 3.0], [3.0, 0.0, 1.0, 2.0, 2.0], [2.0, 3.0, 0.0, 1.0, 1.0], [3.0, 4.0, 1.0, 0.0, 2.0], [1.0, 2.0, 3.0, 4.0, 0.0]] self.assertSequenceEqual(graph.D.tolist(), true_distance)
def test_bd(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 1, 0], [1, 0, 1, 0], [1, 1, 0, 1], [0, 0, 1, 0]]) graph = GraphBD(A, measure_list[GraphBD], 'zero') MeasureTransitivity.compute_measure(graph) self.assertAlmostEqual(graph.measure_dict[MeasureTransitivity]['transitivity'], 0.45)
def test_graphWU(self): measure_list = MeasureParser.list_measures() A = np.array([[3.2, 3.14, 2.7, 0.01, 0.0], [3.2, 2.7, 3.14, 6.7, -75], [13, 0.0, 1.2, 5.7, -0.01], [5.5, 8.2, 0.3, 0.0005, -0.5], [1, 0.0, 345, 8.7, -2]]) graph_wu = GraphWU(A, measure_list[GraphWU], 'zero', 'max') MeasureStrength.compute_measure(graph_wu) for i in range(len(A[0])): self.assertAlmostEqual(graph_wu.measure_dict[MeasureStrength]['strength'].tolist()[i], [22.7, 14.54, 366.84, 28.1, 354.7][i]) self.assertAlmostEqual(graph_wu.measure_dict[MeasureStrength]['avg_strength'], 157.376)
def test_bu(self): measure_list = MeasureParser.list_measures() A = np.array([[1, 1, 0, 1], [1, 0, 1, 1], [1, 0, 1, 1], [0, 0, 0, 0]]) graph = GraphBU(A, measure_list[GraphBU], 'zero', 'max') MeasureGlobalEfficiency.compute_measure(graph) global_efficiency = [1, 1, 1, 1] test_utility = TestUtility() test_utility.assertSequenceAlmostEqual( graph.measure_dict[MeasureGlobalEfficiency] ['global_efficiency'].tolist(), global_efficiency, 4)
def test_graphWU(self): measure_list = MeasureParser.list_measures() A = np.array([[3.2, 3.14, 2.7, 0.01, 0.0], [3.2, 2.7, 3.14, 6.7, 75], [13, 0.0, 1.2, 5.7, 0.01], [5.5, 8.2, 0.3, 0.0005, 0.5], [1, 0.0, 345, 8.7, 2]]) graph = GraphWU(A, measure_list[GraphWU], 'zero', 'max') path_length = [0.1079, 0.0612, 0.0535, 0.1341, 0.0527] self.assertSequenceAlmostEqual(graph.get_measure(MeasurePathLength, 'path_length'), path_length, places = 4)
def test_graphWU(self): measure_list = MeasureParser.list_measures() A = np.array([[3.2, 3.14, 2.7, 0.01, 0.0], [3.2, 2.7, 3.14, 6.7, 75], [13, 0.0, 1.2, 5.7, 0.01], [5.5, 8.2, 0.3, 0.0005, 0.5], [1, 0.0, 345, 8.7, 2]]) graph = GraphWU(A, measure_list[GraphWU], 'null', 'max') eccentricity = [0.1818, 0.1220, 0.1178, 0.1818, 0.1149] self.assertSequenceAlmostEqual(graph.get_measure( MeasureEccentricity, 'eccentricity'), eccentricity, places=4)
def test_graphWD(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 0, 0.1, 0.8], [0.5, 0, 0, 0.2], [0, 0.1, 0, 0.4], [0, 0, 0, 0]]) graph_wd = GraphWD(A, measure_list[GraphWD], 'zero') MeasureTriangles.compute_measure(graph_wd) for i in range(len(A[0])): self.assertAlmostEqual(graph_wd.measure_dict[MeasureTriangles] ['triangles'].tolist()[i], [0.0855, 0.0855, 0.0855, 0][i], places=4)
def test_graphWU(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 0.5, 0.1, 0.8], [0.5, 0, 0.1, 0.2], [0.1, 0.1, 0, 0.4], [0.8, 0.2, 0.4, 0]]) graph_wu = GraphWU(A, measure_list[GraphWU], 'zero', 'max') MeasureTriangles.compute_measure(graph_wu) for i in range(len(A[0])): self.assertAlmostEqual(graph_wu.measure_dict[MeasureTriangles] ['triangles'].tolist()[i], [0.9194, 0.8019, 0.6885, 0.9484][i], places=4)
def test_graphWD(self): measure_list = MeasureParser.list_measures() A = np.array([[0.0, 3.14, 2.7, 0.01, 0.0], [3.2, 0.0, 3.14, 6.7, 75], [13, 0.0, 0.0, 5.7, 0.01], [5.5, 8.2, 0.3, 0.0, 0.5], [1, 0.0, 345, 8.7, 0.0]]) graph = GraphWD(A, measure_list[GraphWD], 'abs') eccentricity = [0.4467, 0.3185, 0.3347, 0.4467, 0.3318] self.assertSequenceAlmostEqual(graph.get_measure( MeasureEccentricity, 'eccentricity'), eccentricity, places=4)
def test_graphWU(self): measure_list = MeasureParser.list_measures() A = np.array([[3.2, 3.14, 2.7, 0.01, 0.0], [3.2, 2.7, 3.14, 6.7, -75], [13, 0.0, 1.2, 5.7, -0.01], [5.5, 8.2, 0.3, 0.0005, -0.5], [1, 0.0, 345, 8.7, -2]]) graph_wu = GraphWU(A, measure_list[GraphWU], 'zero', 'max') MeasureDegree.compute_measure(graph_wu) self.assertSequenceEqual( graph_wu.measure_dict[MeasureDegree]['degree'].tolist(), [4, 3, 4, 4, 3]) self.assertEqual(graph_wu.measure_dict[MeasureDegree]['avg_degree'], 3.6)
def test_graphWD(self): measure_list = MeasureParser.list_measures() A = np.array([[0.0, 0.1, 0.5, 0.4, 0.0], [0.8, 0.0, 0.0, 0.0, 0.0], [0.5, 0.2, 0.0, 0.4, 0.0], [0.8, 0.1, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0]]) true_distance = [[0.0, 7.0, 2.0, 2.5, np.inf], [1.25, 0.0, 3.25, 3.75, np.inf], [2.0, 5.0, 0.0, 2.5, np.inf], [1.25, 8.25, 3.25, 0.0, np.inf], [np.inf, np.inf, np.inf, np.inf, 0]] graph = GraphWD(A, measure_list[GraphWD], 'zero') self.assertSequenceEqual(graph.D.tolist(), true_distance)
def test_graphWU(self): measure_list = MeasureParser.list_measures() A = np.array([[0.0, 0.1, 0.5, 0.4, 0.0], [0.1, 0.0, 0.2, 0.5, 0.0], [0.5, 0.2, 0.0, 0.4, 0.0], [0.4, 0.5, 0.4, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0]]) true_distance = [[0.0, 4.5, 2.0, 2.5, np.inf], [4.5, 0.0, 4.5, 2.0, np.inf], [2.0, 4.5, 0.0, 2.5, np.inf], [2.5, 2.0, 2.5, 0.0, np.inf], [np.inf, np.inf, np.inf, np.inf, 0]] graph = GraphWU(A, measure_list[GraphWU], 'zero', 'min') self.assertSequenceEqual(graph.D.tolist(), true_distance)
def test_wu(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 0.1, 0.2, 0.1, 0, 0, 0, 0], [0, 0, 0.5, 0, 0.1, 0, 0, 0], [0, 0, 0, 0, 0.2, 0, 0, 0], [0, 0, 0.5, 0, 0.1, 0, 0, 0], [0, 0, 0, 0, 0, 0.1, 0.5, 0], [0, 0, 0, 0, 0, 0, 0, 0.2], [0, 0, 0, 0, 0, 0, 0, 0.8], [0, 0, 0, 0, 0, 0, 0, 0]]) graph = GraphWU(A, measure_list[GraphWU], 'zero') betweenness = [0, 0, 30, 0, 24, 0, 20, 12] self.assertSequenceEqual( graph.get_measure(MeasureBetweenness, 'betweenness').tolist(), betweenness)
def test_graphBD(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [1, 0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) graph_bd = GraphBD(A, measure_list[GraphBD], 'zero') MeasureCluster.compute_measure(graph_bd) for i in range(len(A[0])): self.assertAlmostEqual( graph_bd.measure_dict[MeasureCluster]['cluster'].tolist()[i], [1.0000, 0.5000, 0.5000, 0.5000, 0, 0, 0, 0][i], places=4)
def test_graphBU(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) graph_bu = GraphBU(A, measure_list[GraphBU], 'zero', 'max') MeasureCluster.compute_measure(graph_bu) for i in range(len(A[0])): self.assertAlmostEqual( graph_bu.measure_dict[MeasureCluster]['cluster'].tolist()[i], [0.6667, 0.6667, 0.6667, 0.6667, 0.2000, 0, 0, 0][i], places=4)
def test_bu(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 0]]) graph = GraphBU(A, measure_list[GraphBU], 'zero') betweenness = [ 0.6667, 2.6667, 3.3333, 2.6667, 25.6667, 5.0000, 5.0000, 1.0000 ] self.assertSequenceAlmostEqual(graph.get_measure( MeasureBetweenness, 'betweenness'), betweenness, places=4)
def test_graphWU(self): measure_list = MeasureParser.list_measures() A = np.array([[0, 0.1, 0.2, 0.1, 0, 0, 0, 0], [0, 0, 0.5, 0, 0.1, 0, 0, 0], [0, 0, 0, 0, 0.2, 0, 0, 0], [0, 0, 0.5, 0, 0.1, 0, 0, 0], [0, 0, 0, 0, 0, 0.1, 0.5, 0], [0, 0, 0, 0, 0, 0, 0, 0.2], [0, 0, 0, 0, 0, 0, 0, 0.8], [0, 0, 0, 0, 0, 0, 0, 0]]) graph_wu = GraphWU(A, measure_list[GraphWU], 'zero', 'max') MeasureCluster.compute_measure(graph_wu) for i in range(len(A[0])): self.assertAlmostEqual( graph_wu.measure_dict[MeasureCluster]['cluster'].tolist()[i], [0.1436, 0.1436, 0.1436, 0.1436, 0.0431, 0, 0, 0][i], places=4)
def test_graphWD(self): measure_list = MeasureParser.list_measures() A = np.array([[3.2, 3.14, 2.7, 0.01, 0.0], [3.2, 2.7, 3.14, 6.7, -75], [13, 0.0, 1.2, 5.7, -0.01], [5.5, 8.2, 0.3, 0.0005, -0.5], [1, 0.0, 345, 8.7, -2]]) graph_wd = GraphWD(A, measure_list[GraphWD], 'null') MeasureStrength.compute_measure(graph_wd) for i in range(len(A[0])): self.assertAlmostEqual(graph_wd.measure_dict[MeasureStrength]['strength'].tolist()[i], [28.55, -50.62, 369.83, 34.61, 279.19][i]) self.assertAlmostEqual(graph_wd.measure_dict[MeasureStrength]['in_strength'].tolist()[i], [22.7, 11.34, 351.14, 21.11, -75.51][i]) self.assertAlmostEqual(graph_wd.measure_dict[MeasureStrength]['out_strength'].tolist()[i], [5.85, -61.96, 18.69, 13.5, 354.7][i]) self.assertAlmostEqual(graph_wd.measure_dict[MeasureStrength]['avg_strength'], 132.312) self.assertAlmostEqual(graph_wd.measure_dict[MeasureStrength]['avg_in_strength'], 66.156) self.assertAlmostEqual(graph_wd.measure_dict[MeasureStrength]['avg_out_strength'], 66.156)
def test_wu(self): measure_list = MeasureParser.list_measures() A = np.array([[0.7577, 0.7060, 0.8235, 0.4387, 0.4898], [0.7431, 0.0318, 0.6948, 0.3816, 0.4456], [0.3922, 0.2769, 0.3171, 0.7655, 0.6463], [0.6555, 0.0462, 0.9502, 0.7952, 0.7094], [0.1712, 0.0971, 0.0344, 0.1869, 0.7547]]) graph = GraphWU(A, measure_list[GraphWU], 'zero', 'max') MeasureGlobalEfficiency.compute_measure(graph) global_efficiency = [0.6780, 0.5712, 0.7787, 0.6791, 0.5728] test_utility = TestUtility() test_utility.assertSequenceAlmostEqual( graph.measure_dict[MeasureGlobalEfficiency] ['global_efficiency'].tolist(), global_efficiency, 4)
def test_graphBD(self): measure_list = MeasureParser.list_measures() A = np.array([[1, 0, 1, 1, 1], [0, 1, 1, 0, 1], [1, 0, 1, 1, 1], [0, 0, 0, 0, 0], [0, 1, 1, 0, 1]]) graph = GraphBD(A, measure_list[GraphBD], 'zero') path_length = [1.458333, 1.5833, 1.1250, np.nan, 1.2500] in_path_length = [1.6667, 1.6667, 1.0, 1.5, 1.0] out_path_length = [1.25, 1.5, 1.25, np.nan, 1.5] self.assertSequenceAlmostEqual(graph.get_measure(MeasurePathLength, 'path_length'), path_length, places = 4) self.assertSequenceAlmostEqual(graph.get_measure(MeasurePathLength, 'in_path_length'), in_path_length, places = 4) self.assertSequenceAlmostEqual(graph.get_measure(MeasurePathLength, 'out_path_length'), out_path_length, places = 4)
def test_graphWD(self): measure_list = MeasureParser.list_measures() A = np.array([[3.2, 3.14, 2.7, 0.01, 0.0], [3.2, 2.7, 3.14, 6.7, 75], [13, 0.0, 1.2, 5.7, 0.01], [5.5, 8.2, 0.3, 0.0005, 0.5], [1, 0.0, 345, 8.7, 2]]) graph = GraphWD(A, measure_list[GraphWD], 'zero') path_length = [0.2329, 0.1532, 0.1691, 0.1803, 0.1532] in_path_length = [0.1079, 0.2437, 0.1230, 0.2164, 0.1978] out_path_length = [0.3579, 0.0627, 0.2151, 0.1443, 0.1086] self.assertSequenceAlmostEqual(graph.get_measure(MeasurePathLength, 'path_length'), path_length, places = 4) self.assertSequenceAlmostEqual(graph.get_measure(MeasurePathLength, 'in_path_length'), in_path_length, places = 4) self.assertSequenceAlmostEqual(graph.get_measure(MeasurePathLength, 'out_path_length'), out_path_length, places = 4)