-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglinda.py
executable file
·74 lines (57 loc) · 2.2 KB
/
glinda.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
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/env python3
import os.path
from gLinDA.lib.config import Config
from gLinDA.lib.p2p import Runner
from gLinDA.lib.linda import LinDA
from gLinDA.lib.argument import Arguments
__version__ = "1.0.0"
class Wrapper:
"""
Basic wrapper that should initialize the LinDA call and the P2P network.
"""
def __init__(self, arguments, run: bool = True):
if arguments.test is None:
self.config = Config(arguments, check_sanity=run).get()
if run:
self.run()
else:
from gLinDA.lib.p2p_test import P2PIsolationTester
P2PIsolationTester(Config(arguments, check_sanity=False).get(), arguments.test)
def run(self):
if ("solo_mode" in self.config["P2P"] and self.config["P2P"]["solo_mode"]) or self.config["P2P"]["host"] is None:
return self.run_locally()
else:
return self.run_sl()
def run_locally(self):
results = LinDA.run_local(self.config["LINDA"])
self.export_result(results)
print(LinDA.display_results(results))
return results
def run_sl(self):
# calculate coefficients
coeffs = LinDA.run_sl(self.config["LINDA"])
# start and broadcast p2p network
p2p = Runner(self.config["P2P"])
replies = p2p.broadcast_obj(coeffs)
# Add own parameters to the replies
replies.update({0: coeffs})
results = LinDA.run_sl_avg(replies, self.config["LINDA"]["formula"], not self.config["LINDA"]["intersection"])
self.export_result(results)
print(LinDA.display_results(results))
return results
def export_result(self, results):
try:
if type(self.config["LINDA"]["output"]) is str and len(self.config["LINDA"]["output"]):
prefix = os.path.basename(self.config["LINDA"]["feature_table"])
prefix = prefix[:prefix.rfind(".")]
LinDA.export_results(results, self.config["LINDA"]["output"], prefix )
except:
print("Can not store results at the given path")
def main():
"""
Performs the argument parsing.
"""
parser = Arguments()
Wrapper(parser.get_args())
if __name__ == "__main__":
main()