-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate_communities.py
executable file
·62 lines (45 loc) · 2.22 KB
/
evaluate_communities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import pandas as pd
import operator
import statistics as stats
import os
import pickle
import argparse
def generate_plot_data(data_directory):
from networkit import scd
import execute_algorithms
base_paths = execute_algorithms.get_base_paths(data_directory)
algNames = list(map(operator.itemgetter(0), execute_algorithms.get_algorithms()))
data = {}
for base_path in base_paths:
name = os.path.basename(base_path)
G, C, seeds = execute_algorithms.get_graph_cover_seeds(base_path)
for alg in algNames:
com = execute_algorithms.get_result(base_path, alg)
for s_name, ignoreSeed in [('seed', False), ('noseed', True)]:
evaluation = scd.SCDGroundTruthComparison(G, C, com, ignoreSeed).run()
for s, f1 in evaluation.getIndividualF1().items():
data[(name, s, alg, 'F1-Score - {}'.format(s_name))] = f1
for s, ja in evaluation.getIndividualJaccard().items():
data[(name, s, alg, 'Jaccard - {}'.format(s_name))] = ja
for s, pr in evaluation.getIndividualPrecision().items():
data[(name, s, alg, 'Precision - {}'.format(s_name))] = pr
for s, rec in evaluation.getIndividualRecall().items():
data[(name, s, alg, 'Recall - {}'.format(s_name))] = rec
t = execute_algorithms.get_time(base_path, alg)
for s, c in com.items():
data[(name, s, alg, 'Conductance')] = scd.SetConductance(G, c).run().getConductance()
data[(name, s, alg, 'Size')] = len(c)
# FIXME time for each seed
data[(name, s, alg, 'Time')] = t / len(com)
with open(data_directory + '/plot_data.pickle', 'wb') as fout:
pickle.dump(data, fout)
return data
def read_plot_data(data_directory):
with open(data_directory + '/plot_data.pickle', 'rb') as fin:
return pickle.load(fin)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Evaluate the found communities')
parser.add_argument('base_directory', help='The input directory')
args = parser.parse_args()
generate_plot_data(args.base_directory)