-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto_sh.py
165 lines (135 loc) · 5.9 KB
/
auto_sh.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
import subprocess
import itertools
import os
import time
# This is design for python 2.6
if __name__ == "__main__":
mem = 8 # memory in Gb
sh_time = 48 # time in hour
task_name = "fhn_1D" # name of the task
conda_path = "/ifs/scratch/c2b2/ip_lab/zw2504/miniconda3/bin/"
env_name = "vismc"
execution_path = "/ifs/scratch/c2b2/ip_lab/zw2504/"
py_script_path = "/ifs/scratch/c2b2/ip_lab/zw2504/VISMC/SMC_supreme/runner_flag.py"
sh_name = "run"
params_dict = {}
# --------------------- training hyperparameters --------------------- #
params_dict["Dx"] = [2]
params_dict["Dy"] = [1]
params_dict["Di"] = [1]
params_dict["n_particles"] = [64]
params_dict["batch_size"] = [1]
params_dict["lr"] = [5e-4]
params_dict["epoch"] = [600]
params_dict["seed"] = [0]
# --------------------- data set parameters --------------------- #
params_dict["generateTrainingData"] = [False]
params_dict["datadir"] = ["/ifs/scratch/c2b2/ip_lab/zw2504/VISMC/data/fhn/[1,0]_obs_cov_0.01/"]
# "/ifs/scratch/c2b2/ip_lab/zw2504/VISMC/data/fitzhughnagumo/"
# "/ifs/scratch/c2b2/ip_lab/zw2504/VISMC/data/fhn/[1,0]_obs_cov_0.01/"
# "/ifs/scratch/c2b2/ip_lab/zw2504/VISMC/data/fhn/changing/"
params_dict["datadict"] = ["datadict"]
params_dict["isPython2"] = [False]
params_dict["time"] = [200]
params_dict["n_train"] = [200]
params_dict["n_test"] = [40]
# --------------------- model parameters --------------------- #
# Feed-Forward Network (FFN)
params_dict["q0_layers"] = [[64]]
params_dict["q1_layers"] = [[64]]
params_dict["q2_layers"] = [[64]]
params_dict["f_layers"] = [[64]]
params_dict["g_layers"] = [[64]]
params_dict["q0_sigma_init"] = [5]
params_dict["q1_sigma_init"] = [5]
params_dict["q2_sigma_init"] = [5]
params_dict["f_sigma_init"] = [5]
params_dict["g_sigma_init"] = [5]
params_dict["q0_sigma_min"] = [1]
params_dict["q1_sigma_min"] = [1]
params_dict["q2_sigma_min"] = [1]
params_dict["f_sigma_min"] = [1]
params_dict["g_sigma_min"] = [1]
# Normalizing Flow (NF)
params_dict["q1_flow_layers"] = [2]
params_dict["f_flow_layers"] = [2]
params_dict["flow_sample_num"] = [25]
params_dict["flow_type"] = ["MAF"]
# bidirectional RNN
params_dict["y_smoother_Dhs"] = [[32]]
params_dict["X0_smoother_Dhs"] = [[32]]
# --------------------- SSM flags --------------------- #
params_dict["use_bootstrap"] = [True]
params_dict["q_uses_true_X"] = [False]
params_dict["use_2_q"] = [True]
params_dict["use_input"] = [False]
params_dict["poisson_emission"] = [False]
params_dict["flow_transition"] = [True]
# --------------------- FFN flags --------------------- #
params_dict["use_residual"] = [False]
params_dict["output_cov"] = [False]
params_dict["diag_cov"] = [False]
params_dict["dropout_rate"] = [0.0]
# --------------------- TFS flags --------------------- #
params_dict["TFS"] = [True]
params_dict["TFS_use_diff_q0"] = [True]
# --------------------- FFBS flags --------------------- #
params_dict["FFBS"] = [False]
params_dict["smoothing_perc_factor"] = [1]
params_dict["FFBS_to_learn"] = [True]
# --------------------- smoother flags --------------------- #
params_dict["smooth_obs"] = [False]
params_dict["X0_use_separate_RNN"] = [True]
params_dict["use_stack_rnn"] = [True]
# --------------------- training flags --------------------- #
params_dict["early_stop_patience"] = [200]
params_dict["lr_reduce_patience"] = [40]
params_dict["lr_reduce_factor"] = [0.7]
params_dict["min_lr"] = [2e-5, 1e-5, 5e-6]
params_dict["clip_norm"] = [10.0]
# --------------------- printing and data saving params --------------------- #
params_dict["print_freq"] = [5]
params_dict["save_trajectory"] = [True]
params_dict["save_y_hat"] = [True]
params_dict["MSE_steps"] = [30]
params_dict["saving_num"] = [30]
params_dict["lattice_shape"] = [[25, 25]] # [25, 25] or [10, 10, 5]
params_dict["save_tensorboard"] = [False]
params_dict["save_model"] = [False]
# --------------------- parameters part ends --------------------- #
param_keys = list(params_dict.keys())
param_values = list(params_dict.values())
param_vals_permutation = list(itertools.product(*param_values))
for i, param_vals in enumerate(param_vals_permutation):
args = ""
arg_dict = {}
for param_name, param_val in zip(param_keys, param_vals):
if isinstance(param_val, list):
param_val = ",".join([str(x) for x in param_val])
arg_dict[param_name] = param_val
args += "--{0}={1} ".format(param_name, param_val)
# some ad hoc way to define rslt_dir_name, feel free to delete/comment out it
rslt_dir_name = "fhn/"
rslt_dir_name += arg_dict["datadir"].split("/")[-2]
if arg_dict["TFS"]:
rslt_dir_name += "/TFS"
elif arg_dict["FFBS"]:
rslt_dir_name += "/FFBS"
elif arg_dict["smooth_obs"]:
rslt_dir_name += "/RNN"
else:
rslt_dir_name += "/filtering"
args += "--rslt_dir_name={0}".format(rslt_dir_name)
# create shell script
with open(sh_name, "w") as f:
f.write("#!/bin/bash\n")
f.write("#$ -l mem={0}G,time={1}:: -S /bin/bash -N {2} -j y -cwd\n".format(mem, sh_time, task_name))
f.write("cd {0}\n".format(conda_path))
f.write("source activate {0}\n".format(env_name))
f.write("cd {0}\n".format(execution_path))
f.write("python {0} {1}\n".format(py_script_path, args))
f.write("cd {0}\n".format(conda_path))
f.write("source deactivate")
# execute the shell script
subprocess.Popen("qsub {0}".format(sh_name), shell=True)
time.sleep(2)