-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconf.py
executable file
·201 lines (187 loc) · 9.97 KB
/
conf.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
from models import *
from numgraph import simple_grid_coo
from datasets import diffusion_functions, traffic_ablation_names
def get_conf(input_dim, output_dim, time_dim):
for lr in [1e-2, 1e-3, 1e-4]:
for wd in [1e-2, 1e-3]:
for epsilon in [0.001, 0.01, 0.1, 0.5, 1.]:
for hidden in [64, 32] if time_dim is not None else [None, 8]:
for activ_fun in ['tanh', 'relu', None]:
for time_aggr in ['concat', 'add'] if time_dim is not None else [None]:
if time_dim is not None:
t_hiddens = [time_dim // 2] if time_aggr == 'concat' else [hidden]
else:
t_hiddens = [None]
for t_hidden in t_hiddens:
for norm in [True, False]:
for K in [1,2] if time_dim is not None else [5]:
for use_previous_state in [True, False]:
readout = hidden != None
yield {
'model': {
'input_dim': input_dim,
'output_dim': output_dim,
'hidden_dim': hidden,
'input_time_dim': time_dim,
'hidden_time_dim': t_hidden,
'time_aggr': time_aggr,
'readout': readout,
'K': K,
'normalization': norm,
'epsilon': epsilon,
'activ_fun': activ_fun,
'use_previous_state': use_previous_state,
'bias': True
},
'optim': {
'lr': lr,
'weight_decay': wd
}
}
def get_conf_ablation(input_dim, output_dim, time_dim):
yield {
'model': {
'input_dim': input_dim,
'output_dim': output_dim,
'hidden_dim': 8,
'input_time_dim': time_dim,
'hidden_time_dim': None,
'time_aggr': None,
'readout': True,
'K': 5,
'normalization': False,
'epsilon': 0.5,
'activ_fun': 'tanh',
'use_previous_state': False,
'bias': True
},
'optim': {
'lr': 0.0001,
'weight_decay': 0.001
}
}
def get_conf_baseline(model_name, input_dim, output_dim, time_dim):
for lr in [1e-2, 1e-3, 1e-4]:
for wd in [1e-2, 1e-3]:
for hidden in [64, 32] if time_dim is not None else [None, 8]:
for activ_fun in ['tanh', 'relu', None]:
for time_aggr in ['concat', 'add'] if time_dim is not None else [None]:
if time_dim is not None:
t_hiddens = [time_dim // 2] if time_aggr == 'concat' else [hidden]
else:
t_hiddens = [None]
for t_hidden in t_hiddens:
for iterate in [True, False]:
readout = hidden != None
conf = {
'model': {
'input_dim': input_dim,
'output_dim': output_dim,
'hidden_dim': hidden,
'activ_fun': activ_fun,
'input_time_dim': time_dim,
'hidden_time_dim': t_hidden,
'time_aggr': time_aggr,
'readout': readout,
'iterate': iterate,
},
'optim': {
'lr': lr,
'weight_decay': wd
}
}
if model_name in ['DCRNN', 'GCRN_LSTM', 'GCRN_GRU']:
for k in [1,2] if time_dim is not None else [2,5]:
conf['model']['K'] = k
if model_name in ['GCRN_LSTM', 'GCRN_GRU']:
for norm in ['sym']: #, None, 'rw']:
conf['model']['normalization'] = norm
yield conf
else:
yield conf
else:
assert model_name in ['TGCN', 'A3TGCN']
yield conf
def get_conf_node(model_name, input_dim, output_dim, time_dim):
for lr in [1e-2, 1e-3, 1e-4]:
for wd in [1e-2, 1e-3]:
for epsilon in [0.001, 0.01, 0.1, 0.5, 1.]:
for hidden in [64, 32] if time_dim is not None else [None, 8]:
for activ_fun in ['tanh', 'relu', None]:
for time_aggr in ['concat', 'add'] if time_dim is not None else [None]:
if time_dim is not None:
t_hiddens = [time_dim // 2] if time_aggr == 'concat' else [hidden]
else:
t_hiddens = [None]
for t_hidden in t_hiddens:
readout = hidden != None
for torchdyn_method in [True, False]:
conf = {
'model': {
'input_dim': input_dim,
'output_dim': output_dim,
'hidden_dim': hidden,
'activ_fun': activ_fun,
'input_time_dim': time_dim,
'hidden_time_dim': t_hidden,
'time_aggr': time_aggr,
'readout': readout,
'epsilon': epsilon,
'torchdyn_method': torchdyn_method
},
'optim': {
'lr': lr,
'weight_decay': wd
}
}
if model_name == 'NDCN':
conf['model']['cached'] = True
yield conf
elif model_name == 'NODE':
for use_previous_state in [True, False]:
conf['model']['use_previous_state'] = use_previous_state
yield conf
else:
raise ValueError(f'{model_name} is not defined')
def get_data_config(name: str, single_spike: bool = False): # is one of dataset.DATA_NAMES
if name in diffusion_functions.keys():
h, w = 10, 7
conf = {
'num_nodes': h * w,
'generator': lambda _: simple_grid_coo(h, w, directed=False),
'num_initial_spikes': (h*w) // 3 if not single_spike else 1,
't_max': 1000,
'num_samples': 100,
'min_sample_distance': 1,
'diffusion_function': diffusion_functions[name],
'heat_spike': (10., 15.),
'cold_spike': (-15., -10.),
'prob_cold_spike': 0.4 if not single_spike else 0,
'step_size': 1e-3,
}
elif name in traffic_ablation_names:
conf = {}
else:
conf = {
'num_samples': lambda data_len: data_len // 3,
'min_sample_distance': 1,
}
return conf
our = lambda input_dim, output_dim, time_dim: get_conf(input_dim, output_dim, time_dim)
c0 = lambda input_dim, output_dim, time_dim: get_conf_baseline('DCRNN', input_dim, output_dim, time_dim)
c1 = lambda input_dim, output_dim, time_dim: get_conf_baseline('GCRN_LSTM', input_dim, output_dim, time_dim)
c2 = lambda input_dim, output_dim, time_dim: get_conf_baseline('GCRN_GRU', input_dim, output_dim, time_dim)
c3 = lambda input_dim, output_dim, time_dim: get_conf_baseline('TGCN', input_dim, output_dim, time_dim)
c4 = lambda input_dim, output_dim, time_dim: get_conf_baseline('A3TGCN', input_dim, output_dim, time_dim)
c5 = lambda input_dim, output_dim, time_dim: get_conf_node('NODE', input_dim, output_dim, time_dim)
c6 = lambda input_dim, output_dim, time_dim: get_conf_node('NDCN', input_dim, output_dim, time_dim)
MODEL_CONF = {
'TGODE': (our, TemporalGraphEuler), # Our method
'DCRNN': (c0, DCRNNModel),
'GCRN_LSTM': (c1, GCRN_LSTM_Model),
'GCRN_GRU': (c2, GCRN_GRU_Model),
'TGCN': (c3, TGCNModel),
'A3TGCN': (c4, A3TGCNModel),
'NODE': (c5, NeuralODE),
'NDCN': (c6, NDCN)
}