-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathreport_kahip_cut.py
45 lines (40 loc) · 1.26 KB
/
report_kahip_cut.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
import os, sys, json
import numpy as np
from collections import defaultdict
dataset = sys.argv[1]
### Paths
# Location of raw dataset (HDF5 format)
dataset_folder = "./datasets"
# Output folder
output_folder = "workflow_output"
dataset_output_folder = os.path.join(output_folder, dataset)
# Param file
param_file = os.path.join(output_folder, dataset, dataset + '.params.txt')
### Parameters
with open(param_file) as input:
params = json.load(input)
###
print params.keys()
print params["falconn_knn_graph_trunc_py"]
n = params["num_points"]
partition = []
with open(params["kahip_output"], "r") as input:
for line in input:
partition.append(line.strip())
if len(partition) != n:
raise Exception("wrong length")
counter = defaultdict(int)
for x in partition:
counter[x] += 1
print counter
knn_graph = np.load(params["falconn_knn_graph_trunc_py"])
print knn_graph.shape
cut_size = 0
total_p2 = 0
for i in range(knn_graph.shape[0]):
total_p2 += counter[partition[i]]
for j in range(knn_graph.shape[1]):
if partition[i] != partition[knn_graph[i][j]]:
cut_size += 1
print float(cut_size) / float(knn_graph.shape[0] * knn_graph.shape[1])
print float(total_p2) / float(knn_graph.shape[0]), float(total_p2) / (float(knn_graph.shape[0])**2)