def evalCommunityDetection(algo, G): """ Evaluate a community detection algorithm """ t = stopwatch.Timer() algo.run() zeta = algo.getPartition() t.stop() results = [["time [s]", t.elapsed], ["# communities", zeta.numberOfSubsets()], ["modularity", Modularity().getQuality(zeta, G)]] print(tabulate.tabulate(results))
def inspectPartitions(partition, graph): if not have_tabulate: raise MissingDependencyError("tabulate") partitionSizes = partition.subsetSizes() mod = Modularity().getQuality(partition, graph) props = [ ["# partitions", partition.numberOfSubsets()], ["min partition size", min(partitionSizes)], ["max partition size", max(partitionSizes)], ["avg. partition size", sum(partitionSizes) / len(partitionSizes)], ["imbalance", computeImbalance(partition, graph)], ["edge cut", computeEdgeCut(partition, graph)], ["edge cut (portion)", computeEdgeCut(partition, graph) / graph.numberOfEdges() ], ["modularity", mod], ] print(tabulate.tabulate(props))
def inspectCommunities(zeta, G): """ Display information about communities :param zeta communities :param G graph """ communitySizes = zeta.subsetSizes() mod = Modularity().getQuality(zeta, G) commProps = [ ["# communities", zeta.numberOfSubsets()], ["min community size", min(communitySizes)], ["max community size", max(communitySizes)], ["avg. community size", sum(communitySizes) / len(communitySizes)], #["imbalance", zeta.getImbalance()], ["modularity", mod], ] print(tabulate.tabulate(commProps))