def test_top10_central_closeness(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     cc = measures.top10_central_closeness
     assert len(cc) == 10
     for item in cc:
         assert isinstance(item, tuple)
         assert len(item) == 2
         assert isinstance(item[1], float)
 def test_largest_component_measures(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isinstance(measures.largest_component_measures.node_count, int)
     assert isinstance(measures.largest_component_measures.edge_count, int)
     if measures.largest_component_measures.directed:
         assert measures.largest_component_measures.strongly_connected
     else:
         assert measures.largest_component_measures.connected
 def test_top10_central_degree(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     dc = measures.top10_central_degree
     assert len(dc) == 10
     for item in dc:
         assert isinstance(item, tuple)
         assert len(item) == 2
         assert isinstance(item[1], float)
 def test_avg_strength(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     if measures.weighted:
         if measures.directed:
             avg_strength_in, avg_strength_out = measures.avg_strength
             assert isinstance(avg_strength_in, float)
             assert isinstance(avg_strength_out, float)
         else:
             assert isinstance(measures.avg_strength, float)
     else:
         with pytest.raises(MeasureError):
             measures.avg_strength
 def test_basic_measures(self, graph_path: Path, expected: Any):
     measure = GraphMeasures(load_graphml(graph_path))
     if measure.directed:
         measure.strongly_connected
         measure.weakly_connected
         with pytest.raises(MeasureError):
             measure.connected
     else:
         measure.connected
         with pytest.raises(MeasureError):
             measure.weakly_connected
         with pytest.raises(MeasureError):
             measure.strongly_connected
 def test_degree_distribution(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     if measures.directed:
         assert isinstance(measures.degree_distribution, tuple)
         assert len(measures.degree_distribution) == 2
         assert isinstance(measures.degree_distribution[1], dict)
         for distribution in measures.degree_distribution:
             assert isinstance(distribution, dict)
             for degree, count in distribution.items():
                 assert isinstance(degree, int)
                 assert isinstance(count, int)
             assert issorted(list(distribution.keys()))
     else:
         assert isinstance(measures.degree_distribution, dict)
         for degree, count in measures.degree_distribution.items():
             assert isinstance(degree, int)
             assert isinstance(count, int)
         assert issorted(measures.degree_distribution.keys())
 def test_edge_count(self, graph_path: Path, expected: int):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isclose(measures.edge_count, expected, rel_tol=0.1)
 def test_avg_betweenness_centrality(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isinstance(measures.avg_betweenness_centrality, float)
 def test_component_count(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isinstance(measures.component_count, int)
 def test_avg_clustering_coefficient(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isclose(measures.avg_clustering_coefficient,
                    expected,
                    rel_tol=0.12)
 def test_global_efficiency(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isinstance(measures.global_efficiency, float)
 def test_eccentricity(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isinstance(measures.eccentricity, (int, float))
 def test_diameter(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isinstance(measures.diameter, int)
 def test_shortest_path_length(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isinstance(measures.shortest_path_length, (int, float))
 def test_avg_edge_count(self, graph_path: Path, expected: Any):
     measures = GraphMeasures(load_graphml(graph_path))
     if measures.directed:
         assert trunc(sum(measures.avg_edge_count)) == expected
     else:
         assert trunc(measures.avg_edge_count) == expected
Example #16
0
            plt.savefig(results_hist_weight_out.as_posix())
            plt.close()
        else:
            results_hist_weight: Path = results / f"{name}_hist_weight.png"
            plt.xlabel('Snaga')
            plt.xlabel('Frekvencija')
            weights = tuple(edge[2]['weight']
                            for edge in measures.graph.edges().data())
            plt.hist(weights, bins=HISTOGRAM_BINS)
            plt.savefig(results_hist_weight.as_posix())
            plt.close()
    print(f"{datetime.now()} - Graph {name}: FINISHED - histograms")


stat_functions = (write_basic, write_histograms, write_centrality,
                  write_modularity)

if __name__ == '__main__':
    '''
    path = graph_paths[4]
    p = Process(target=write_modularity, args=(GraphMeasures(load_graphml(path)), path.stem))
    p.start()
    '''

    for graph_id in (0, 1, 2, 3, 4):
        path = graph_paths[graph_id]
        graph_measures = GraphMeasures(load_graphml(path))
        for func in stat_functions:
            process = Process(target=func, args=(graph_measures, path.stem))
            process.start()
 def test_degree_assortativity(self, graph_path: Path, expected):
     measures = GraphMeasures(load_graphml(graph_path))
     assert isinstance(measures.degree_assortativity, float)