-
Notifications
You must be signed in to change notification settings - Fork 1
/
Params.py
183 lines (148 loc) · 5.67 KB
/
Params.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
import argparse
from utils.util import get_logger
import os
import yaml
import datetime
def read_name(config_path):
nameList = config_path.split('/')
allName = nameList[-1]
nameList = allName.split('.')
return nameList[0]
def genPath(path_str, date):
return path_str+date+'/'
def print_args(args):
log_level = 'INFO'
if not os.path.exists(args.logdir):
os.makedirs(args.logdir)
logger = get_logger(args.logdir, __name__, 'info_{}.log'.format(args.name), level=log_level)
logger.info(args.config)
# logger.info(args.dist_thr)
return logger
def arg4config():
parser = argparse.ArgumentParser(description='Model Params')
parser.add_argument('--config', default='./config/BikeNYC/BikeNYC.yaml', type=str)
args = parser.parse_args()
config_path = args.config
return config_path
class ParamConfig:
# def __init__(self):
config_path = arg4config()
print('config: {}'.format(config_path))
with open(config_path, 'r', encoding='utf-8') as y:
config = yaml.safe_load(y)
# control:
model = config['control']['model']
testonly = True if config['control']['testonly'] else False
device = config['control']['device']
date = config['control']['date']
name = read_name(config_path)
mdir = genPath(config['control']['mdir'], date)
logdir = genPath(config['control']['logdir'], date)
# data:
dataset = config['data']['dataset']
data_path = config['data']['data_path']
val_ratio = config['data']['val_ratio']
test_ratio = config['data']['test_ratio']
lag = config['data']['lag']
horizon = config['data']['horizon']
batch_size = config['data']['batch_size']
geo_graph = config['data']['geo_graph']
num_nodes = config['data']['num_nodes']
adj_filename = config['data']['adj_filename']
id_filename = config['data']['id_filename']
# training:
patience = config['training']['patience']
model_path = config['training']['model_path']
mae_thresh = config['training']['mae_thresh']
mape_thresh = config['training']['mape_thresh']
lr = config['training']['lr']
weight_decay = config['training']['weight_decay']
lr_decay_ratio = config['training']['lr_decay_ratio']
steps = config['training']['steps']
criterion = config['training']['criterion']
max_epoch = config['training']['max_epoch']
grad_norm = True if config['training']['grad_norm'] else False
#
popu_norm = True
mask_neg = True
scaler_norm = True
start_ori = datetime.datetime.strptime('2020-1-23',"%Y-%m-%d")
end_ori = datetime.datetime.strptime('2022-7-31',"%Y-%m-%d")
start_date = datetime.datetime.strptime('2020-3-1',"%Y-%m-%d")
end_date = datetime.datetime.strptime('2022-7-31',"%Y-%m-%d")
trend_flg = True if config['data']['trend_flg'] else False
use_saint_graph = True
graph_type = 'county' # TODO: county, state, hierCS
saint_batch_size = 600
saint_sample_type = 'random_walk'
saint_walk_length = 2
saint_shuffle_order = 'node_first'
## GIB
model_type='GAT'
num_features=1
num_classes=1
normalize=True
reparam_mode = config['model']['reparam_mode']
prior_mode= config['model']['prior_mode']
latent_size=16
sample_size=1
num_layers=2
# struct_dropout_mode=("DNsampling","Bernoulli",0.1,0.5,"norm",2)
struct_dropout_mode_dict = {0: ("Nsampling",'Bernoulli',0.1,0.5,"norm"), 1: ("DNsampling","Bernoulli",0.1,0.5,"norm",2), 2: ("standard",0.6)}
struct_dropout_mode= struct_dropout_mode_dict[config['model']['struct_dropout_mode']]
dropout=True,
val_use_mean=True
reparam_all_layers=(-2,)
with_relu = True
head = config['model']['head']
# gsat
learn_edge_att = True
extractor_drop = 0.5
use_edge_attr = True
gib_drop = config['model']['gib_drop'] # defalt 0.3
fix_r = False
decay_interval = 10
decay_r = 0.1
final_r = 0.5
init_r = 0.9
#
d_model = 16
hidden_size = 128
d_model_temp = 128
d_model_spat = 64
only_spat = True if config['model']['only_spat'] else False
beta1 = config['model']['beta1']
beta2 = config['model']['beta2']
# abl
spat_gsat = True if config['model']['spat_gsat'] else False
temp_gsat = True if config['model']['temp_gsat'] else False
# try:
# dist_thr = config['dist_thr']
# except:
# dist_thr = 2
dist_thr = config.get('model').get('dist_thr', 10000)
print('dist thr *************************', dist_thr)
view_dim_spat = 128
view_dim_temp = config.get('model').get('view_dim_temp', 512) # default: 512
add_mask = True
view_num = config['model']['view_num']
cr = config['model']['cr']
cr_init = config['model']['cr_init']
cl_temp = config['model']['cl_temp']
is_anneal = True if config['model']['is_anneal'] else False
sim_spat_coeff_init = config['model']['sim_spat_coeff_init']
sim_spat_coeff = config['model']['sim_spat_coeff']
sim_temp_coeff_init = config['model']['sim_temp_coeff_init']
sim_temp_coeff = config['model']['sim_temp_coeff']
loss_mode = config['model']['loss_mode']
mem_size = config['model']['mem_size']
dynamic = True if config['model']['dynamic'] else False
kld_spat_coeff_init = config['model']['kld_spat_coeff_init']
kld_spat_coeff = config['model']['kld_spat_coeff']
kld_temp_coeff_init = config['model']['kld_temp_coeff_init']
kld_temp_coeff = config['model']['kld_temp_coeff']
is_anneal_kld = True if config['model']['is_anneal_kld'] else False
debug = True if config['model']['debug'] else False
non_node = True if config['model']['non_node'] else False
args = ParamConfig()
logger = print_args(args)