-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp_sd.py
56 lines (45 loc) · 1.69 KB
/
exp_sd.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
#
# Run performance measurement experiments
#
# Runs the performance experiment on all datasets in data/datasets/perf_*.
#
# Usage:
# python exp_perf.py cfgs/exp_perf/bkt.json data/results-perf
#
import subprocess
import glob
import os
import sys
import json
def main():
cfg_path = sys.argv[1]
output_dir = sys.argv[2]
variant = sys.argv[3]
use_embeddings = sys.argv[4] == '1'
datasets = [os.path.basename(p).replace('.csv','') for p in
glob.glob("data/datasets/sd_*_%s.csv" % variant)]
datasets = sorted(datasets, key=lambda d: int(d.split('_')[1]))
os.makedirs(output_dir, exist_ok=True)
cfg_name = os.path.basename(cfg_path).replace('.json', '')
if use_embeddings:
cfg_name = cfg_name + '-rep'
with open(cfg_path, 'r') as f:
cfg = json.load(f)
for dataset in datasets:
if os.path.exists("%s/%s_%s.csv"%(output_dir, cfg_name, dataset)):
print("Ignoring %s because results already exist" % dataset)
continue
embedding_path = "./data/datasets/%s.embeddings.npy" % (dataset.replace('_'+variant,''))
print(cfg_name, dataset, embedding_path)
output_path = "%s/%s_%s.csv" % (output_dir, cfg_name, dataset)
command = ['python', cfg['script'], cfg_path, dataset, output_path]
if use_embeddings:
command += [embedding_path]
subprocess.call(command)
exp_cfg_path = output_path.replace('.csv', '.json')
if use_embeddings:
cfg['problem_feature_mat_path'] = embedding_path
with open(exp_cfg_path, 'w') as f:
json.dump(cfg, f, indent=4)
if __name__ == "__main__":
main()