-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelicality.py
48 lines (34 loc) · 1.35 KB
/
helicality.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
import json
import os
MAIN_DIR = "/Users/sripathisridhar/Documents/GitHub/embedding-bio"
def helicality(file_path):
'''
Compute helicality from a JSON file containing a dict of Euclidean losses, store in new JSON file
Inputs
-----
file_path : Path to JSON file containing Euclidean losses
Returns
-----
None
'''
losses_dict = {}
with open(file_path, "r") as f:
losses_dict = json.load(f)
helicality_dict = {k : 1.0 / loss for k, loss in losses_dict.items()}
file_name = os.path.splitext(file_path)[0]
dataset_name = file_name.split("_")[0]
with open("{}_helicality.json".format(dataset_name), "w") as f:
json.dump(helicality_dict, f)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("dataset", help="name of dataset [TinySOL, NTVow, ENST]")
args = parser.parse_args()
if args.dataset.lower() not in ["tinysol", "ntvow", "enst"]:
raise ValueError("invalid argument")
elif args.dataset.lower() == "tinysol":
helicality(os.path.join(MAIN_DIR, "TinySOL_euclideanLosses.json"))
elif args.dataset.lower() == "ntvow":
helicality(os.path.join(MAIN_DIR, "NTVow_euclideanLosses.json"))
else:
helicality(os.path.join(MAIN_DIR, "ENST-drums-public_euclideanLosses.json"))