forked from vanderschaarlab/mlforhealthlabpub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_deephit.py
100 lines (78 loc) · 2.5 KB
/
test_deephit.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
'''
Example/Test script for pategan.
'''
import sys
import os
import argparse
import json
from pathlib import Path
import initpath_alg
initpath_alg.init_sys_path()
import utilmlab
def init_arg():
parser = argparse.ArgumentParser()
parser.add_argument('--exe', help='python interpreter to use')
parser.add_argument('--it', default=10000, type=int)
parser.add_argument("--itout", type=int)
parser.add_argument("--itrs", type=int)
parser.add_argument('--projdir')
parser.add_argument('-o')
return parser.parse_args()
if __name__ == '__main__':
args = init_arg()
proj_dir = utilmlab.get_proj_dir() \
if args.projdir is None else args.projdir
alg = 'deephit'
if args.exe is not None:
python_exe = args.exe
else:
python_exe = 'python' if sys.version_info[0] < 3 else 'python3'
niter = args.it
version = 1
if args.o is None:
odir = '{}/result/{}/v_{}/h_{}'.format(
proj_dir,
alg,
version,
os.environ['HOSTNAME'] if 'HOSTNAME' in os.environ else 'unknown')
else:
odir = args.o
utilmlab.ensure_dir(odir)
logger = utilmlab.init_logger(odir, 'log_test_{}.txt'.format(alg))
result_lst = []
dataset_lst = [
{
'dataset': 'SYNTHETIC',
}
]
script = Path('{}/alg/deephit/main_RandomSearch.py'.format(proj_dir))
script_ana = Path('{}/alg/deephit/summarize_results.py'.format(proj_dir))
for args_d in dataset_lst:
cmd_arg = ' '.join([
'--{} {}'.format(el, args_d[el]) for el in args_d.keys()])
dataset = args_d['dataset']
odir = '{}/dataset_{}'.format(
odir,
dataset)
utilmlab.ensure_dir(odir)
utilmlab.exe_cmd(
logger,
'{} {} {} {} {} {} {}'.format(
python_exe,
script,
cmd_arg,
'--it {}'.format(niter),
'-o {}'.format(odir),
'--itout {}'.format(
args.itout) if args.itout is not None else '',
'--itrs {}'.format(
args.itrs) if args.itrs is not None else ''))
utilmlab.exe_cmd(
logger,
'{} {} {} {} {}'.format(
python_exe,
script_ana,
cmd_arg,
'-o {}'.format(odir),
'--itout {}'.format(
args.itout) if args.itout is not None else ''))