-
Notifications
You must be signed in to change notification settings - Fork 7
/
args.py
executable file
·276 lines (260 loc) · 7.58 KB
/
args.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
import argparse
def str2bool(x):
if x == "true" or x == "True":
return True
else:
return False
def get_args():
parser = argparse.ArgumentParser(
description="Spatiotemporal GNN for readmission prediction"
)
# general args
parser.add_argument(
"--save_dir",
type=str,
default=None,
help="Directory to save the outputs and checkpoints.",
)
parser.add_argument(
"--load_model_path",
type=str,
default=None,
help="Model checkpoint to start training/testing from.",
)
parser.add_argument(
"--do_train",
default=True,
type=str2bool,
help="Whether perform training.",
)
parser.add_argument(
"--gpu_id",
default=0,
type=int,
help="Which GPU to use? If None, use default GPU.",
)
parser.add_argument("--rand_seed", type=int, default=123, help="Random seed.")
parser.add_argument(
"--patience",
type=int,
default=10,
help="Number of patience epochs before early stopping.",
)
# data args
parser.add_argument(
"--demo_file",
type=str,
help="Cohort file with demographics and imaging information.",
)
parser.add_argument(
"--edge_ehr_file", type=str, help="Preprocessed EHR features for edges."
)
parser.add_argument(
"--ehr_feature_file",
type=str,
help="Preprocessed EHR features for nodes features.",
)
parser.add_argument(
"--img_feature_dir", type=str, help="Dir to extracted CXR features."
)
parser.add_argument(
"--edge_top_perc",
default=None,
type=float,
help="Top percentage edges to be kept.",
)
parser.add_argument(
"--use_gauss_kernel",
default=False,
type=str2bool,
help="Whether or not to use thresholded Gaussian kernel for edges",
)
parser.add_argument(
"--max_seq_len_img",
type=int,
default=9,
help="Maximum sequence length for images.",
)
parser.add_argument(
"--max_seq_len_ehr",
type=int,
default=9,
help="Maximum sequence length for ehr.",
)
parser.add_argument(
"--sim_measure",
type=str,
default="euclidean",
choices=("cosine", "euclidean"),
help="Which similarity measure?",
)
parser.add_argument(
"--edge_modality",
type=str,
nargs="+",
default=["demo"],
help="Modalities used for constructing edges.",
)
parser.add_argument(
"--feature_type",
default="imaging",
choices=("imaging", "non-imaging", "multimodal"),
type=str,
help="Feature modality",
)
parser.add_argument(
"--ehr_types",
default=["demo", "icd", "lab", "med"],
nargs="+",
type=str,
help="Sources of EHR for node features.",
)
# model args
parser.add_argument(
"--model_name",
type=str,
default="stgnn",
choices=(
"stgnn",
"graphsage",
"joint_fusion",
),
help="Name of the model.",
)
parser.add_argument(
"--ehr_encoder_name",
type=str,
default=None,
choices=("embedder", None),
help="Name of ehr encoder.",
)
parser.add_argument(
"--cat_emb_dim",
type=int,
default=1,
help="Embedding dimension for categorical variables.",
)
parser.add_argument(
"--hidden_dim", type=int, default=64, help="Hidden size of GCN layers."
)
parser.add_argument(
"--joint_hidden",
nargs="+",
type=int,
default=[128],
help="List of hidden dims for joint fusion model.",
)
parser.add_argument(
"--num_gcn_layers", type=int, default=1, help="Number of GCN layers."
)
parser.add_argument(
"--g_conv",
type=str,
default="graphsage",
choices=("graphsage"),
help="Type of GRU layers.",
)
parser.add_argument(
"--num_rnn_layers", type=int, default=1, help="Number of RNN (GRU) layers."
)
parser.add_argument(
"--rnn_hidden_dim", type=int, default=64, help="Hidden size of RNN layers."
)
parser.add_argument(
"--add_bias",
type=str2bool,
default=True,
help="Whether to add bias to GraphGRU cell.",
)
parser.add_argument(
"--num_classes",
type=int,
default=1,
help="Number of output class. 1 for binary classification.",
)
parser.add_argument("--dropout", type=float, default=0.0, help="Dropout proba.")
parser.add_argument(
"--activation_fn",
type=str,
choices=("relu", "elu"),
default="relu",
help="Activation function name.",
)
parser.add_argument(
"--aggregator_type",
type=str,
default="mean",
choices=("mean", "gcn", "pool", "lstm"),
help="Aggregator type. For GraphSAGE only.",
)
parser.add_argument(
"--final_pool",
type=str,
default="last",
choices=("last", "mean", "max", "cat"),
help="How to pool time step results?",
)
parser.add_argument(
"--t_model",
type=str,
default="gru",
choices=("gru"),
help="Which temporal model to use?",
)
# training args
parser.add_argument("--lr", type=float, default=1e-3, help="learning rate")
parser.add_argument("--num_epochs", type=int, default=50, help="Number of epochs.")
parser.add_argument(
"--eval_every", type=int, default=1, help="Evaluate on dev set every x epoch."
)
parser.add_argument(
"--metric_name",
type=str,
default="F1",
choices=("F1", "acc", "loss", "auroc", "aupr"),
help="Name of dev metric to determine best checkpoint.",
)
parser.add_argument("--l2_wd", type=float, default=5e-4, help="L2 weight decay.")
parser.add_argument(
"--pos_weight",
type=float,
nargs="+",
default=1,
help="Positive class weight or list of class weights to weigh the loss function.",
)
parser.add_argument(
"--thresh_search",
type=str2bool,
default=True,
help="Whether or not to perform threshold search on validation set.",
)
parser.add_argument(
"--train_batch_size", type=int, default=64, help="Training batch size."
)
parser.add_argument(
"--test_batch_size", type=int, default=64, help="Test batch size."
)
parser.add_argument("--num_workers", type=int, default=8, help="Number of workers.")
parser.add_argument(
"--which_img",
type=str,
default="last",
choices=("last", "mean", "all"),
help="Which image to use for the patient for non-temporal models.",
)
args = parser.parse_args()
# which metric to maximize
if args.metric_name == "loss":
# Best checkpoint is the one that minimizes loss
args.maximize_metric = False
elif args.metric_name in ("F1", "acc", "auroc", "aupr"):
# Best checkpoint is the one that maximizes F1 or acc
args.maximize_metric = True
else:
raise ValueError('Unrecognized metric name: "{}"'.format(args.metric_name))
# must provide load_model_path if testing only
if (args.load_model_path is None) and (not (args.do_train)):
raise ValueError(
"For prediction only, please provide trained model checkpoint in argument load_model_path."
)
return args