-
Notifications
You must be signed in to change notification settings - Fork 1
/
bcoz.py
112 lines (101 loc) · 5.47 KB
/
bcoz.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from argparse import Namespace, ArgumentParser
class Trad:
def __init__(self):
self.silent: bool = False
self.args: Namespace = self.parse_arguments()
def parse_arguments(self) -> Namespace:
parser = ArgumentParser(description=
'A Python library with implementation of algorithms '
'for performing causal discovery.')
parser.add_argument('-a', '--algorithm', action='store', type=str, required=True,
help='choose which algorithm to use',
choices=['bpc', 'eb', 'fas', 'fask', 'fask-concatenated', 'fci', 'fges', 'fges-mb',
'fofc', 'ftfc', 'gfci', 'glasso', 'imgs_cont', 'imgs_disc', 'lingam', 'mbfs',
'mgm', 'mimbuild', 'multi-fask', 'pc-all', 'r-skew', 'r-skew-e', 'r1', 'r2',
'r3', 'r4', 'rfci', 'rfci-bsc', 'skew', 'skew-e', 'ts-fci', 'ts-gfci', 'ts-imgs'])
parser.add_argument('-t', '--data_type', action='store', type=str, required=True,
help='tell me which data type the input data is',
choices=['continuous', 'covariance', 'discrete', 'mixed'])
parser.add_argument('-d', '--dataset', action='store', type=str, required=True, nargs='+',
help='dataset file path. Multiple files are separated by commas.')
parser.add_argument('--delimiter', action='store', type=str, default="comma",
help='Delimiter: colon, comma, pipe, semicolon, space, tab, whitespace',
choices=['colon', 'comma', 'pipe', 'semicolon', 'space', 'tab', 'whitespace'])
parser.add_argument('-o', '--out', action='store', type=str, help='Output directory')
parser.add_argument('--prefix', action='store', type=str, help='Output file name prefix')
parser.add_argument('--thread', action='store', type=int, help='Number threads')
parser.add_argument('--depth', action='store', type=int, default=-1, help='')
parser.add_argument('--significance', action='store', type=float, default=0.05, help='')
parser.add_argument('--seed', action='store', type=int, help='')
parser.add_argument('--num_nodes', action='store', type=int, default=5, help='')
parser.add_argument('--num_edges', action='store', type=int, default=5, help='')
parser.add_argument('--knowledge', action='store', type=str, help='')
parser.add_argument('--graphxml', action='store', type=str, help='')
parser.add_argument('--graphtxt', action='store', type=str, help='')
parser.add_argument('--initialgraphtxt', action='store', type=str, help='')
parser.add_argument('--covariance', action="store_true", help='')
parser.add_argument('--json_graph', action="store_true", help='Write out graph as json.')
parser.add_argument('--skip_validation', action="store_true", help='Skip validation')
parser.add_argument('--whitespace', action="store_true", help='')
parser.add_argument('--sample_prior', action='store', type=float, default=1.0, help='')
parser.add_argument('--structure_prior', action='store', type=float, default=1.0, help='')
parser.add_argument('--penalty_discount', action='store', type=float, default=1.0, help='')
parser.add_argument('--rfci', action="store_true", help='')
parser.add_argument('--nodsep', action="store_true", help='')
parser.add_argument('--silent', action="store_true", help='')
parser.add_argument('--condcorr', action="store_true", help='')
parser.add_argument('--verbose', action="store_true", help='')
args = parser.parse_args()
self.silent = args.silent
return args
def out_print(self, x: str):
if not self.silent:
print(x)
def load_data(self):
if not self.args.dataset:
raise AttributeError("No data file was specified.")
if not self.args.data_type:
raise AttributeError("No data type (continuous/discrete) was specified.")
self.out_print(f"Loading data from {self.args.dataset}.\n")
# TODO load data
def load_knowledge(self):
if not self.args.knowledge:
raise AttributeError("No knowledge file was specified.")
# TODO load knowledge
def run_algorithm(self):
if not self.args.dataset:
self.load_data()
if not self.args.knowledge:
self.load_knowledge()
algorithm = self.args.algorithm
if "pc" == algorithm:
runPc()
elif "fci" == algorithm:
runFci()
elif "fges" == algorithm:
runFges()
elif "fang" == algorithm:
runFang()
elif "pc.stable" == algorithm:
runPcStable()
elif "cpc" == algorithm:
runCpc()
elif "cfci" == algorithm:
runCfci()
elif "ccd" == algorithm:
runCcd()
elif "bayes_est" == algorithm:
runBayesEst()
elif "fofc" == algorithm:
runFofc()
elif "randomDag" == algorithm:
printRandomDag()
else:
TetradLogger.getInstance().reset()
TetradLogger.getInstance().removeOutputStream(System.out)
raise AttributeError("No algorithm was specified.")
def main():
trad = Trad()
trad.run_algorithm()
if __name__ == '__main__':
main()