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_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_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_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_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_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_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, 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_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_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)
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_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)