-
Notifications
You must be signed in to change notification settings - Fork 2
/
model_config.py
162 lines (152 loc) · 5.85 KB
/
model_config.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
import torch
models_map = {
'ARIMA_NN': ("models.ARIMA_NN.ARIMA_NN", {
"hidden_channels": 1,
"p": 5,
"d": 1,
"q": 0
}),
'SVR_NN': ("models.SVR_NN.SVR_NN", {
"hidden_channels": 1,
"kernel": "rbf",
"degree": 3,
"C": 1.0,
"epsilon": 0.1
}),
'GCN_GRU': ("models.GCN_GRU.GCN_GRU", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_GRU_BI': ("models.GCN_GRU_BI.GCN_GRU_BI", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_GRU_TeacherForcing': ("models.GCN_GRU_TeacherForcing.GCN_GRU_TeacherForcing", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_GRU_BI_Attention': ("models.GCN_GRU_BI_Attention.GCN_GRU_BI_Attention", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_GRU_BI_Multi_Attention': ("models.GCN_GRU_BI_Multi_Attention.GCN_GRU_BI_Multi_Attention", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_LSTM': ("models.GCN_LSTM.GCN_LSTM", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_LSTM_Peepholes': ("models.GCN_LSTM_Peepholes.GCN_LSTM_Peepholes", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_LSTM_TeacherForcing': ("models.GCN_LSTM_TeacherForcing.GCN_LSTM_TeacherForcing", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_LSTM_BI': ("models.GCN_LSTM_BI.GCN_LSTM_BI", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_LSTM_BI_TeacherForcing': ("models.GCN_LSTM_BI_TeacherForcing.GCN_LSTM_BI_TeacherForcing", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_LSTM_BI_Attention': ("models.GCN_LSTM_BI_Attention.GCN_LSTM_BI_Attention", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_LSTM_BI_Multi_Attention': ("models.GCN_LSTM_BI_Multi_Attention.GCN_LSTM_BI_Multi_Attention", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_rnn_layers": 3,
"dropout": 0,
}),
'GCN_LSTM_BI_Multi_Attention_Weather': ("models.GCN_LSTM_BI_Multi_Attention_Weather.GCN_LSTM_BI_Multi_Attention_Weather", {
"in_channels": None,
"hidden_channels": 64,
"num_gcn_layers": 64,
"num_rnn_layers": 3,
"dropout": 0,
"num_lags": 8,
}),
'GCN_LSTM_BI_Multi_Attention_Weather_Separate': ("models.GCN_LSTM_BI_Multi_Attention_Weather_Separate.GCN_LSTM_BI_Multi_Attention_Weather_Separate", {
"in_channels": None,
"hidden_channels": 64,
"num_gcn_layers": 64,
"num_rnn_layers": 3,
"dropout": 0,
"num_lags": 8,
}),
'GCN_Transformer': ("models.GCN_Transformer.GCN_Transformer", {
"in_channels": None,
"hidden_channels": 32,
"num_gcn_layers": 16,
"num_transformer_layers": 3,
"dropout": 0,
})
}
def init_model(model_type, train_data, num_predictions, dropout=0):
model_path, default_params = models_map[model_type]
model_module, model_name = model_path.rsplit('.', 1)
model_class = getattr(__import__(model_module, fromlist=[model_name]), model_name)
# Set in_channels to the number of input features
if "in_channels" in default_params:
default_params["in_channels"] = train_data.size(1)
if "speed_channels" in default_params:
default_params["speed_channels"] = train_data.size(1)
if "temp_channels" in default_params:
default_params["temp_channels"] = train_data.size(1)
default_params["num_predictions"] = num_predictions
# Merge default params from models_map with provided params, with the latter taking precedence
params = {
**default_params # Overwrite values from models_map with provided values
}
# Print params for debugging purposes
print(f"Parameters being used: {params}")
model = model_class(**params)
# Post-processing for specific models
if model_type == 'ARIMA_NN':
train_data = train_data.to(dtype=torch.float32)
numpy_train_data = train_data.numpy()
model.arima.fit(numpy_train_data)
elif model_type == 'SVR':
train_data = train_data.to(dtype=torch.float32)
numpy_train_data = train_data.numpy()
model.svr.fit(numpy_train_data)
return model