Shourya Bose commited on
Commit
4cc7625
β€’
1 Parent(s): 881bc20

updated models for L=512

Browse files
This view is limited to 50 files because it contains too many changes. Β  See raw diff
Files changed (50) hide show
  1. README.md +4 -5
  2. model_kwargs.py +11 -0
  3. models/Autoformer.py +3 -0
  4. models/Informer.py +3 -0
  5. models/LSTM.py +2 -0
  6. models/LSTNet.py +2 -1
  7. models/PatchTST.py +382 -0
  8. models/TimesNet.py +3 -0
  9. models/Transformer.py +3 -0
  10. weights/{autoformer_L_96_T_4_HET.pth β†’ Autoformer_L_512_T_48_HET.pth} +2 -2
  11. weights/{autoformer_L_96_T_4_HOM.pth β†’ Autoformer_L_512_T_48_HOM.pth} +2 -2
  12. weights/{autoformer_L_96_T_48_HET.pth β†’ Autoformer_L_512_T_4_HET.pth} +1 -1
  13. weights/{autoformer_L_96_T_48_HOM.pth β†’ Autoformer_L_512_T_4_HOM.pth} +1 -1
  14. weights/Autoformer_L_512_T_96_HET.pth +3 -0
  15. weights/Autoformer_L_512_T_96_HOM.pth +3 -0
  16. weights/Informer_L_512_T_48_HET.pth +3 -0
  17. weights/Informer_L_512_T_48_HOM.pth +3 -0
  18. weights/{informer_L_96_T_48_HET.pth β†’ Informer_L_512_T_4_HET.pth} +1 -1
  19. weights/{informer_L_96_T_48_HOM.pth β†’ Informer_L_512_T_4_HOM.pth} +1 -1
  20. weights/Informer_L_512_T_96_HET.pth +3 -0
  21. weights/Informer_L_512_T_96_HOM.pth +3 -0
  22. weights/{lstm_L_96_T_48_HET.pth β†’ LSTM_L_512_T_48_HET.pth} +2 -2
  23. weights/{lstm_L_96_T_48_HOM.pth β†’ LSTM_L_512_T_48_HOM.pth} +2 -2
  24. weights/{lstm_L_96_T_4_HET.pth β†’ LSTM_L_512_T_4_HET.pth} +2 -2
  25. weights/{lstm_L_96_T_4_HOM.pth β†’ LSTM_L_512_T_4_HOM.pth} +2 -2
  26. weights/LSTM_L_512_T_96_HET.pth +3 -0
  27. weights/LSTM_L_512_T_96_HOM.pth +3 -0
  28. weights/LSTNet_L_512_T_48_HET.pth +3 -0
  29. weights/LSTNet_L_512_T_48_HOM.pth +3 -0
  30. weights/LSTNet_L_512_T_4_HET.pth +3 -0
  31. weights/LSTNet_L_512_T_4_HOM.pth +3 -0
  32. weights/LSTNet_L_512_T_96_HET.pth +3 -0
  33. weights/LSTNet_L_512_T_96_HOM.pth +3 -0
  34. weights/PatchTST_L_512_T_48_HET.pth +3 -0
  35. weights/PatchTST_L_512_T_48_HOM.pth +3 -0
  36. weights/PatchTST_L_512_T_4_HET.pth +3 -0
  37. weights/PatchTST_L_512_T_4_HOM.pth +3 -0
  38. weights/PatchTST_L_512_T_96_HET.pth +3 -0
  39. weights/PatchTST_L_512_T_96_HOM.pth +3 -0
  40. weights/TimesNet_L_512_T_48_HET.pth +3 -0
  41. weights/TimesNet_L_512_T_48_HOM.pth +3 -0
  42. weights/TimesNet_L_512_T_4_HET.pth +3 -0
  43. weights/TimesNet_L_512_T_4_HOM.pth +3 -0
  44. weights/TimesNet_L_512_T_96_HET.pth +3 -0
  45. weights/TimesNet_L_512_T_96_HOM.pth +3 -0
  46. weights/Transformer_L_512_T_48_HET.pth +3 -0
  47. weights/Transformer_L_512_T_48_HOM.pth +3 -0
  48. weights/{transformer_L_96_T_48_HET.pth β†’ Transformer_L_512_T_4_HET.pth} +1 -1
  49. weights/{transformer_L_96_T_48_HOM.pth β†’ Transformer_L_512_T_4_HOM.pth} +1 -1
  50. weights/Transformer_L_512_T_96_HET.pth +3 -0
README.md CHANGED
@@ -1,20 +1,19 @@
1
  ---
2
  license: cc
3
  ---
4
-
5
  ## About
6
 
7
  This repository provides model weights to run load forecasting models trained on ComStock datasets. The companion dataset repository is [this](https://huggingface.co/datasets/APPFL/Illinois_load_datasets). The model definitions are present in the `models` directory. The corresponding trained model weights are present in the `weights` directory. The corresponding model keyword arguments (as a function of a provided `lookback` and `lookahead`) can be imported from the file `model_kwargs.py`.
8
 
9
- Note that `lookback` is denoted by `L` and `lookahead` by `T` in the weights directory. We provide weights for the following `(L,T)` pairs: `(96,4)`, `(96,48)`, and `(96,96)`.
10
 
11
  ## Data
12
 
13
- When using the companion [dataset](https://huggingface.co/datasets/APPFL/Illinois_load_datasets), the following points must be noted (see the dataset for more information on configuring the data loaders):
14
 
15
  - All models accept normalized inputs and produce normalized outputs, i.e. set `normalize = True` when generating the datasets.
16
- - For Transformer, Autoformer, Informer, and TimesNet set `transformer = True`, while for LSTM and LSTNet, set `transformer = False`.
17
 
18
  ## Credits
19
 
20
- Some model definitions have been adapted from the code provided in the [TSLib Library](https://github.com/thuml/Time-Series-Library).
 
1
  ---
2
  license: cc
3
  ---
 
4
  ## About
5
 
6
  This repository provides model weights to run load forecasting models trained on ComStock datasets. The companion dataset repository is [this](https://huggingface.co/datasets/APPFL/Illinois_load_datasets). The model definitions are present in the `models` directory. The corresponding trained model weights are present in the `weights` directory. The corresponding model keyword arguments (as a function of a provided `lookback` and `lookahead`) can be imported from the file `model_kwargs.py`.
7
 
8
+ Note that `lookback` is denoted by `L` and `lookahead` by `T` in the weights directory. We provide weights for the following `(L,T)` pairs: `(512,4)`, `(512,48)`, and `(512,96)`, and for `HOM`ogenous and `HET`erogenous datasets.
9
 
10
  ## Data
11
 
12
+ When using the companion [dataset](https://huggingface.co/datasets/APPFL/Illinois_load_datasets), the following points must be noted (see the page for more information on configuring the data loaders):
13
 
14
  - All models accept normalized inputs and produce normalized outputs, i.e. set `normalize = True` when generating the datasets.
15
+ - For Transformer, Autoformer, Informer, and TimesNet set `transformer = True`, while for LSTM, LSTNet, and PatchTST set `transformer = False`.
16
 
17
  ## Credits
18
 
19
+ Some model definitions have been adapted from the code provided in the [TSLib Library](https://github.com/thuml/Time-Series-Library).
model_kwargs.py CHANGED
@@ -52,4 +52,15 @@ lstnet_kwargs = lambda lookback,lookahead:{
52
  'conv1_out_channels':8*4,
53
  'conv1_kernel_height':3*4,
54
  'recc1_out_channels':32*4
 
 
 
 
 
 
 
 
 
 
 
55
  }
 
52
  'conv1_out_channels':8*4,
53
  'conv1_kernel_height':3*4,
54
  'recc1_out_channels':32*4
55
+ }
56
+
57
+ patchtst_kwargs = lambda lookback,lookahead:{
58
+ 'enc_in': 6,
59
+ 'dec_in': 2,
60
+ 'c_out': 1,
61
+ 'pred_len': lookahead,
62
+ 'seq_len': lookback,
63
+ 'd_model': 32*4,
64
+ 'data_idx': [0,3,4,5,6,7],
65
+ 'time_idx': [1,2]
66
  }
models/Autoformer.py CHANGED
@@ -4,6 +4,9 @@ import torch.nn.functional as F
4
  import math
5
  import numpy as np
6
 
 
 
 
7
  class AutoCorrelation(nn.Module):
8
  """
9
  AutoCorrelation Mechanism with the following two phases:
 
4
  import math
5
  import numpy as np
6
 
7
+ # Modified from: https://github.com/thuml/Time-Series-Library
8
+ # Modified by Shourya Bose, shbose@ucsc.edu
9
+
10
  class AutoCorrelation(nn.Module):
11
  """
12
  AutoCorrelation Mechanism with the following two phases:
models/Informer.py CHANGED
@@ -5,6 +5,9 @@ from math import sqrt
5
  import numpy as np
6
  import torch.nn.functional as F
7
 
 
 
 
8
  class ConvLayer(nn.Module):
9
  def __init__(self, c_in):
10
  super(ConvLayer, self).__init__()
 
5
  import numpy as np
6
  import torch.nn.functional as F
7
 
8
+ # Modified from: https://github.com/thuml/Time-Series-Library
9
+ # Modified by Shourya Bose, shbose@ucsc.edu
10
+
11
  class ConvLayer(nn.Module):
12
  def __init__(self, c_in):
13
  super(ConvLayer, self).__init__()
models/LSTM.py CHANGED
@@ -2,6 +2,8 @@ import torch
2
  import torch.nn as nn
3
  from typing import Union, List, Tuple
4
 
 
 
5
  class LSTM(nn.Module):
6
 
7
  def __init__(
 
2
  import torch.nn as nn
3
  from typing import Union, List, Tuple
4
 
5
+ # Written by Shourya Bose, shbose@ucsc.edu
6
+
7
  class LSTM(nn.Module):
8
 
9
  def __init__(
models/LSTNet.py CHANGED
@@ -3,7 +3,8 @@ import torch.nn as nn
3
  import torch.nn.functional as F
4
  import numpy as np
5
 
6
- # https://github.com/gokulkarthik/LSTNet.pytorch/blob/master/LSTNet.py
 
7
 
8
  class LSTNet(nn.Module):
9
 
 
3
  import torch.nn.functional as F
4
  import numpy as np
5
 
6
+ # Modified from https://github.com/gokulkarthik/LSTNet.pytorch/blob/master/LSTNet.py
7
+ # Modified by Shourya Bose, shbose@ucsc.edu
8
 
9
  class LSTNet(nn.Module):
10
 
models/PatchTST.py ADDED
@@ -0,0 +1,382 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import nn
3
+ import torch.nn.functional as F
4
+ import math
5
+ from math import sqrt
6
+ import numpy as np
7
+
8
+ # Modified from: https://github.com/thuml/Time-Series-Library
9
+ # Modified by Shourya Bose, shbose@ucsc.edu
10
+
11
+ class PositionalEmbedding(nn.Module):
12
+ def __init__(self, d_model, max_len=5000):
13
+ super(PositionalEmbedding, self).__init__()
14
+ # Compute the positional encodings once in log space.
15
+ pe = torch.zeros(max_len, d_model).float()
16
+ pe.require_grad = False
17
+
18
+ position = torch.arange(0, max_len).float().unsqueeze(1)
19
+ div_term = (torch.arange(0, d_model, 2).float()
20
+ * -(math.log(10000.0) / d_model)).exp()
21
+
22
+ pe[:, 0::2] = torch.sin(position * div_term)
23
+ pe[:, 1::2] = torch.cos(position * div_term)
24
+
25
+ pe = pe.unsqueeze(0)
26
+ self.register_buffer('pe', pe)
27
+
28
+ def forward(self, x):
29
+ return self.pe[:, :x.size(1)]
30
+
31
+ class PatchEmbedding(nn.Module):
32
+ def __init__(self, d_model, patch_len, stride, padding, dropout):
33
+ super(PatchEmbedding, self).__init__()
34
+ # Patching
35
+ self.patch_len = patch_len
36
+ self.stride = stride
37
+ self.padding_patch_layer = nn.ReplicationPad1d((0, padding))
38
+
39
+ # Backbone, Input encoding: projection of feature vectors onto a d-dim vector space
40
+ self.value_embedding = nn.Linear(patch_len, d_model, bias=False)
41
+
42
+ # Positional embedding
43
+ self.position_embedding = PositionalEmbedding(d_model)
44
+
45
+ # Residual dropout
46
+ self.dropout = nn.Dropout(dropout)
47
+
48
+ def forward(self, x):
49
+ # do patching
50
+ n_vars = x.shape[1]
51
+ x = self.padding_patch_layer(x)
52
+ x = x.unfold(dimension=-1, size=self.patch_len, step=self.stride)
53
+ x = torch.reshape(x, (x.shape[0] * x.shape[1], x.shape[2], x.shape[3]))
54
+ # Input encoding
55
+ x = self.value_embedding(x) + self.position_embedding(x)
56
+ return self.dropout(x), n_vars
57
+
58
+ class AttentionLayer(nn.Module):
59
+ def __init__(self, attention, d_model, n_heads, d_keys=None,
60
+ d_values=None):
61
+ super(AttentionLayer, self).__init__()
62
+
63
+ d_keys = d_keys or (d_model // n_heads)
64
+ d_values = d_values or (d_model // n_heads)
65
+
66
+ self.inner_attention = attention
67
+ self.query_projection = nn.Linear(d_model, d_keys * n_heads)
68
+ self.key_projection = nn.Linear(d_model, d_keys * n_heads)
69
+ self.value_projection = nn.Linear(d_model, d_values * n_heads)
70
+ self.out_projection = nn.Linear(d_values * n_heads, d_model)
71
+ self.n_heads = n_heads
72
+
73
+ def forward(self, queries, keys, values, attn_mask, tau=None, delta=None):
74
+ B, L, _ = queries.shape
75
+ _, S, _ = keys.shape
76
+ H = self.n_heads
77
+
78
+ queries = self.query_projection(queries).view(B, L, H, -1)
79
+ keys = self.key_projection(keys).view(B, S, H, -1)
80
+ values = self.value_projection(values).view(B, S, H, -1)
81
+
82
+ out, attn = self.inner_attention(
83
+ queries,
84
+ keys,
85
+ values,
86
+ attn_mask,
87
+ tau=tau,
88
+ delta=delta
89
+ )
90
+ out = out.view(B, L, -1)
91
+
92
+ return self.out_projection(out), attn
93
+
94
+ class FullAttention(nn.Module):
95
+ def __init__(self, mask_flag=True, factor=5, scale=None, attention_dropout=0.1, output_attention=False):
96
+ super(FullAttention, self).__init__()
97
+ self.scale = scale
98
+ self.mask_flag = mask_flag
99
+ self.output_attention = output_attention
100
+ self.dropout = nn.Dropout(attention_dropout)
101
+
102
+ def forward(self, queries, keys, values, attn_mask, tau=None, delta=None):
103
+ B, L, H, E = queries.shape
104
+ _, S, _, D = values.shape
105
+ scale = self.scale or 1. / sqrt(E)
106
+
107
+ scores = torch.einsum("blhe,bshe->bhls", queries, keys)
108
+
109
+ if self.mask_flag:
110
+ if attn_mask is None:
111
+ attn_mask = TriangularCausalMask(B, L, device=queries.device)
112
+
113
+ scores.masked_fill_(attn_mask.mask, -np.inf)
114
+
115
+ A = self.dropout(torch.softmax(scale * scores, dim=-1))
116
+ V = torch.einsum("bhls,bshd->blhd", A, values)
117
+
118
+ if self.output_attention:
119
+ return V.contiguous(), A
120
+ else:
121
+ return V.contiguous(), None
122
+
123
+ class TriangularCausalMask():
124
+ def __init__(self, B, L, device="cpu"):
125
+ mask_shape = [B, 1, L, L]
126
+ with torch.no_grad():
127
+ self._mask = torch.triu(torch.ones(mask_shape, dtype=torch.bool), diagonal=1).to(device)
128
+
129
+ @property
130
+ def mask(self):
131
+ return self._mask
132
+
133
+ class FullAttention(nn.Module):
134
+ def __init__(self, mask_flag=True, factor=5, scale=None, attention_dropout=0.1, output_attention=False):
135
+ super(FullAttention, self).__init__()
136
+ self.scale = scale
137
+ self.mask_flag = mask_flag
138
+ self.output_attention = output_attention
139
+ self.dropout = nn.Dropout(attention_dropout)
140
+
141
+ def forward(self, queries, keys, values, attn_mask, tau=None, delta=None):
142
+ B, L, H, E = queries.shape
143
+ _, S, _, D = values.shape
144
+ scale = self.scale or 1. / sqrt(E)
145
+
146
+ scores = torch.einsum("blhe,bshe->bhls", queries, keys)
147
+
148
+ if self.mask_flag:
149
+ if attn_mask is None:
150
+ attn_mask = TriangularCausalMask(B, L, device=queries.device)
151
+
152
+ scores.masked_fill_(attn_mask.mask, -np.inf)
153
+
154
+ A = self.dropout(torch.softmax(scale * scores, dim=-1))
155
+ V = torch.einsum("bhls,bshd->blhd", A, values)
156
+
157
+ if self.output_attention:
158
+ return V.contiguous(), A
159
+ else:
160
+ return V.contiguous(), None
161
+
162
+ class AttentionLayer(nn.Module):
163
+ def __init__(self, attention, d_model, n_heads, d_keys=None,
164
+ d_values=None):
165
+ super(AttentionLayer, self).__init__()
166
+
167
+ d_keys = d_keys or (d_model // n_heads)
168
+ d_values = d_values or (d_model // n_heads)
169
+
170
+ self.inner_attention = attention
171
+ self.query_projection = nn.Linear(d_model, d_keys * n_heads)
172
+ self.key_projection = nn.Linear(d_model, d_keys * n_heads)
173
+ self.value_projection = nn.Linear(d_model, d_values * n_heads)
174
+ self.out_projection = nn.Linear(d_values * n_heads, d_model)
175
+ self.n_heads = n_heads
176
+
177
+ def forward(self, queries, keys, values, attn_mask, tau=None, delta=None):
178
+ B, L, _ = queries.shape
179
+ _, S, _ = keys.shape
180
+ H = self.n_heads
181
+
182
+ queries = self.query_projection(queries).view(B, L, H, -1)
183
+ keys = self.key_projection(keys).view(B, S, H, -1)
184
+ values = self.value_projection(values).view(B, S, H, -1)
185
+
186
+ out, attn = self.inner_attention(
187
+ queries,
188
+ keys,
189
+ values,
190
+ attn_mask,
191
+ tau=tau,
192
+ delta=delta
193
+ )
194
+ out = out.view(B, L, -1)
195
+
196
+ return self.out_projection(out), attn
197
+
198
+ class EncoderLayer(nn.Module):
199
+ def __init__(self, attention, d_model, d_ff=None, dropout=0.1, activation="relu"):
200
+ super(EncoderLayer, self).__init__()
201
+ d_ff = d_ff or 4 * d_model
202
+ self.attention = attention
203
+ self.conv1 = nn.Conv1d(in_channels=d_model, out_channels=d_ff, kernel_size=1)
204
+ self.conv2 = nn.Conv1d(in_channels=d_ff, out_channels=d_model, kernel_size=1)
205
+ self.norm1 = nn.LayerNorm(d_model)
206
+ self.norm2 = nn.LayerNorm(d_model)
207
+ self.dropout = nn.Dropout(dropout)
208
+ self.activation = F.relu if activation == "relu" else F.gelu
209
+
210
+ def forward(self, x, attn_mask=None, tau=None, delta=None):
211
+ new_x, attn = self.attention(
212
+ x, x, x,
213
+ attn_mask=attn_mask,
214
+ tau=tau, delta=delta
215
+ )
216
+ x = x + self.dropout(new_x)
217
+
218
+ y = x = self.norm1(x)
219
+ y = self.dropout(self.activation(self.conv1(y.transpose(-1, 1))))
220
+ y = self.dropout(self.conv2(y).transpose(-1, 1))
221
+
222
+ return self.norm2(x + y), attn
223
+
224
+
225
+ class Encoder(nn.Module):
226
+ def __init__(self, attn_layers, conv_layers=None, norm_layer=None):
227
+ super(Encoder, self).__init__()
228
+ self.attn_layers = nn.ModuleList(attn_layers)
229
+ self.conv_layers = nn.ModuleList(conv_layers) if conv_layers is not None else None
230
+ self.norm = norm_layer
231
+
232
+ def forward(self, x, attn_mask=None, tau=None, delta=None):
233
+ # x [B, L, D]
234
+ attns = []
235
+ if self.conv_layers is not None:
236
+ for i, (attn_layer, conv_layer) in enumerate(zip(self.attn_layers, self.conv_layers)):
237
+ delta = delta if i == 0 else None
238
+ x, attn = attn_layer(x, attn_mask=attn_mask, tau=tau, delta=delta)
239
+ x = conv_layer(x)
240
+ attns.append(attn)
241
+ x, attn = self.attn_layers[-1](x, tau=tau, delta=None)
242
+ attns.append(attn)
243
+ else:
244
+ for attn_layer in self.attn_layers:
245
+ x, attn = attn_layer(x, attn_mask=attn_mask, tau=tau, delta=delta)
246
+ attns.append(attn)
247
+
248
+ if self.norm is not None:
249
+ x = self.norm(x)
250
+
251
+ return x, attns
252
+
253
+ class Transpose(nn.Module):
254
+ def __init__(self, *dims, contiguous=False):
255
+ super().__init__()
256
+ self.dims, self.contiguous = dims, contiguous
257
+ def forward(self, x):
258
+ if self.contiguous: return x.transpose(*self.dims).contiguous()
259
+ else: return x.transpose(*self.dims)
260
+
261
+
262
+ class FlattenHead(nn.Module):
263
+ def __init__(self, n_vars, nf, target_window, head_dropout=0):
264
+ super().__init__()
265
+ self.n_vars = n_vars
266
+ self.flatten = nn.Flatten(start_dim=-2)
267
+ self.linear = nn.Linear(nf, target_window)
268
+ self.dropout = nn.Dropout(head_dropout)
269
+
270
+ def forward(self, x): # x: [bs x nvars x d_model x patch_num]
271
+ x = self.flatten(x)
272
+ x = self.linear(x)
273
+ x = self.dropout(x)
274
+ return x
275
+
276
+
277
+ class PatchTST(nn.Module):
278
+ """
279
+ Paper link: https://arxiv.org/pdf/2211.14730.pdf
280
+ """
281
+
282
+ def __init__(
283
+ self,
284
+ enc_in,
285
+ dec_in, # unused
286
+ c_out, # unused
287
+ pred_len,
288
+ seq_len,
289
+ d_model = 64,
290
+ patch_len = 16,
291
+ stride = 8,
292
+ data_idx = [0,3,4,5,6,7],
293
+ time_idx = [1,2],
294
+ output_attention = False,
295
+ factor = 3,
296
+ n_heads = 4,
297
+ d_ff = 512,
298
+ e_layers = 3,
299
+ activation = 'gelu',
300
+ dropout = 0.1
301
+ ):
302
+
303
+ #(self, configs, patch_len=16, stride=8):
304
+ """
305
+ patch_len: int, patch len for patch_embedding
306
+ stride: int, stride for patch_embedding
307
+ """
308
+ super().__init__()
309
+ self.seq_len = seq_len
310
+ self.pred_len = pred_len
311
+ self.data_idx = data_idx
312
+ self.time_idx = time_idx
313
+ self.dec_in = dec_in
314
+ padding = stride
315
+
316
+ # patching and embedding
317
+ self.patch_embedding = PatchEmbedding(
318
+ d_model, patch_len, stride, padding, dropout)
319
+
320
+ # Encoder
321
+ self.encoder = Encoder(
322
+ [
323
+ EncoderLayer(
324
+ AttentionLayer(
325
+ FullAttention(False, factor, attention_dropout=dropout,
326
+ output_attention=output_attention), d_model, n_heads),
327
+ d_model,
328
+ d_ff,
329
+ dropout=dropout,
330
+ activation=activation
331
+ ) for l in range(e_layers)
332
+ ],
333
+ norm_layer=nn.Sequential(Transpose(1,2), nn.BatchNorm1d(d_model), Transpose(1,2))
334
+ )
335
+
336
+ # Prediction Head
337
+ self.head_nf = d_model * \
338
+ int((seq_len - patch_len) / stride + 2)
339
+ self.head = FlattenHead(enc_in, self.head_nf,pred_len,
340
+ head_dropout=dropout)
341
+
342
+ def forecast(self, x_enc, x_mark_enc, x_dec, x_mark_dec):
343
+ # Normalization from Non-stationary Transformer
344
+ means = x_enc.mean(1, keepdim=True).detach()
345
+ x_enc = x_enc - means
346
+ stdev = torch.sqrt(
347
+ torch.var(x_enc, dim=1, keepdim=True, unbiased=False) + 1e-5)
348
+ x_enc /= stdev
349
+
350
+ # do patching and embedding
351
+ x_enc = x_enc.permute(0, 2, 1)
352
+ # u: [bs * nvars x patch_num x d_model]
353
+ enc_out, n_vars = self.patch_embedding(x_enc)
354
+
355
+ # Encoder
356
+ # z: [bs * nvars x patch_num x d_model]
357
+ enc_out, attns = self.encoder(enc_out)
358
+ # z: [bs x nvars x patch_num x d_model]
359
+ enc_out = torch.reshape(
360
+ enc_out, (-1, n_vars, enc_out.shape[-2], enc_out.shape[-1]))
361
+ # z: [bs x nvars x d_model x patch_num]
362
+ enc_out = enc_out.permute(0, 1, 3, 2)
363
+
364
+ # Decoder
365
+ dec_out = self.head(enc_out) # z: [bs x nvars x target_window]
366
+ dec_out = dec_out.permute(0, 2, 1)
367
+
368
+ # De-Normalization from Non-stationary Transformer
369
+ dec_out = dec_out * \
370
+ (stdev[:, 0, :].unsqueeze(1).repeat(1, self.pred_len, 1))
371
+ dec_out = dec_out + \
372
+ (means[:, 0, :].unsqueeze(1).repeat(1, self.pred_len, 1))
373
+ return dec_out
374
+
375
+ def forward(self, x, fut_time):
376
+
377
+ x_enc = x[:,:,self.data_idx]
378
+ x_mark_enc = x[:,:,self.time_idx]
379
+ x_dec = torch.zeros((fut_time.shape[0],fut_time.shape[1],self.dec_in),dtype=fut_time.dtype,device=fut_time.device)
380
+ x_mark_dec = fut_time
381
+
382
+ return self.forecast(x_enc,x_mark_enc,x_dec,x_mark_dec)[:,-1,[0]]
models/TimesNet.py CHANGED
@@ -4,6 +4,9 @@ import torch.nn.functional as F
4
  import torch.fft
5
  import math
6
 
 
 
 
7
  class Inception_Block_V1(nn.Module):
8
  def __init__(self, in_channels, out_channels, num_kernels=6, init_weight=True):
9
  super(Inception_Block_V1, self).__init__()
 
4
  import torch.fft
5
  import math
6
 
7
+ # Modified from: https://github.com/thuml/Time-Series-Library
8
+ # Modified by Shourya Bose, shbose@ucsc.edu
9
+
10
  class Inception_Block_V1(nn.Module):
11
  def __init__(self, in_channels, out_channels, num_kernels=6, init_weight=True):
12
  super(Inception_Block_V1, self).__init__()
models/Transformer.py CHANGED
@@ -5,6 +5,9 @@ import numpy as np
5
  import math
6
  from math import sqrt
7
 
 
 
 
8
  class TriangularCausalMask():
9
  def __init__(self, B, L, device="cpu"):
10
  mask_shape = [B, 1, L, L]
 
5
  import math
6
  from math import sqrt
7
 
8
+ # Modified from: https://github.com/thuml/Time-Series-Library
9
+ # Modified by Shourya Bose, shbose@ucsc.edu
10
+
11
  class TriangularCausalMask():
12
  def __init__(self, B, L, device="cpu"):
13
  mask_shape = [B, 1, L, L]
weights/{autoformer_L_96_T_4_HET.pth β†’ Autoformer_L_512_T_48_HET.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b6ef2bb0c2108017028fc57c70e3f9414f4abb07822ecfaf6d0387ad295a0d32
3
- size 5688349
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45b9ec43695627b47f4d26af2a2bbd9bb0bd2f0555f500285ee8cdb755a67f2e
3
+ size 5688555
weights/{autoformer_L_96_T_4_HOM.pth β†’ Autoformer_L_512_T_48_HOM.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1233196407b1b89c5f1c1aa69a330b9a11059d14502756c70158f020a29f43d1
3
- size 5688349
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b29d91943f51b0ef3e21e462a9916a6a98319fa05c980ecca8718c2eaf335cf3
3
+ size 5688555
weights/{autoformer_L_96_T_48_HET.pth β†’ Autoformer_L_512_T_4_HET.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:18a3294861900282c8d001143dd6e61052e294465ddc1b77968cff9464eff7b2
3
  size 5688452
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:467f7080dc13b7b35b480d87bc981fcd9de06c22b0b8462dc5bed7d5a4725b02
3
  size 5688452
weights/{autoformer_L_96_T_48_HOM.pth β†’ Autoformer_L_512_T_4_HOM.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a8ba4d9cc688f64e8456f27286eb2412b844162211a07dd5d93aa9baf13acd69
3
  size 5688452
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a691b1217ad12b7b478d6677d223cbe9ab83582d28d59aabee40634cb308c597
3
  size 5688452
weights/Autoformer_L_512_T_96_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7127100c4126c3ebd32a547d218fab794a670450bf9bba702578fe9151a45f3b
3
+ size 5688555
weights/Autoformer_L_512_T_96_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d895f416e621fe88ccc24b69ba535ae5143e05ebb7ef6cf44a78a92fc0c5e16d
3
+ size 5688555
weights/Informer_L_512_T_48_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c987dc635ab96659eaf591b3672d02a1e95411ff6b9ac6a83e67e327d70ef545
3
+ size 11244254
weights/Informer_L_512_T_48_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1061956b7c173c0563650f9a99db6b69de0d4c64c676aef361aadc2fb59da8cb
3
+ size 11244254
weights/{informer_L_96_T_48_HET.pth β†’ Informer_L_512_T_4_HET.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ab980f35a30ed0252b268184614bce5981a38d58de69270e8b71d546cf037e66
3
  size 11244096
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e074e56a4441c47c4c67785af771dbe0e043b334c2b2117c1c5dd8db19359119
3
  size 11244096
weights/{informer_L_96_T_48_HOM.pth β†’ Informer_L_512_T_4_HOM.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5de041c5b3e5476c5e21b2549ed9ef2e42f36ef87f03eb3ea7c8a65ad41f397e
3
  size 11244096
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:07df3cfeb077022ead1f47c781578622e1fcd3999aeff63bafd38039c6097898
3
  size 11244096
weights/Informer_L_512_T_96_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a63fe11c1736668086406b95596331c742ff161eae33d94196dda8bbc46f72c4
3
+ size 11244254
weights/Informer_L_512_T_96_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa6855565c1f3dfa5daef609be1e1d1870537d0a1037ee90b3d06b23e415f70e
3
+ size 11244254
weights/{lstm_L_96_T_48_HET.pth β†’ LSTM_L_512_T_48_HET.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:94291c5486572cee3c7cd2c8c1b7a7415ec97484ca06173cd3a86d500b006df0
3
- size 57534
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a2b46b8af8ed52a003dd4b7c1e4a0509292ed47baf8d82300303df5f2f204fc
3
+ size 57440
weights/{lstm_L_96_T_48_HOM.pth β†’ LSTM_L_512_T_48_HOM.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ff835cd72503995f91b3bf7cf2032a102f80472122304258da385d56e2d4e708
3
- size 57534
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca040e74faeb12f330047dca6dfd6dd0f9b3a8d37483a2cd201e796c509b8733
3
+ size 57440
weights/{lstm_L_96_T_4_HET.pth β†’ LSTM_L_512_T_4_HET.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4c054d857c774996eef3b0a01225d346bcae05e1cd1de18e88e5b1ea8ec7bca7
3
- size 57528
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7525980407e8716601da245733432ecaabf3715dfb4f19939ae94795877dc2dd
3
+ size 57434
weights/{lstm_L_96_T_4_HOM.pth β†’ LSTM_L_512_T_4_HOM.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6ee4c4e822c76f72ffda5df510cc938a3808af9e500bcf42746fbcbe53744ec9
3
- size 57528
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e853f575c76037be4840217ae2ea1246e64738acf8e5de7b89639fb386136bc
3
+ size 57434
weights/LSTM_L_512_T_96_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8cc82c8363c1ef17b78ac37a5bf2df2700157a9955ac464d2c3e6c101d31e434
3
+ size 57440
weights/LSTM_L_512_T_96_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62a1fb224f362a27d01a020e422bd7a35175e65fe47b5f84de09d1ac2ac1ddaf
3
+ size 57440
weights/LSTNet_L_512_T_48_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e609c6bcb4dddeaf55bef9f0677202fe0fd4d7e54fdb7db4229a5415fd161cfd
3
+ size 269938
weights/LSTNet_L_512_T_48_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6fb46f5ee71399e17c9e3fd3b3f8db8bb9165dc0053703d34c865b7674186983
3
+ size 269938
weights/LSTNet_L_512_T_4_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fe29739db58672c03d80e72c4d3487c8c7ec90cb3103345be322019e0e539363
3
+ size 269925
weights/LSTNet_L_512_T_4_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f0d17bafb745f4815fa3220fffec21ef2174acf496b6672c514fdd75f71a3e11
3
+ size 269925
weights/LSTNet_L_512_T_96_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2fb69b81d4a335e78accea202b2c3815d9be0d1122ad88816b13415abc9bd21
3
+ size 269938
weights/LSTNet_L_512_T_96_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca5f9e7018ed5528b8fda0ca7cd25b8f30afe542565937bf17f9e3796e752837
3
+ size 269938
weights/PatchTST_L_512_T_48_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fb5aa50f43f7a7002432f5a523b330a18f9f749b0795e9d5cc86cbc554cc4b1
3
+ size 6541627
weights/PatchTST_L_512_T_48_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d108041cecfc7cfb86fc1ed640be149d2d5a8e79eb3d38f399ec99de8015b325
3
+ size 6541627
weights/PatchTST_L_512_T_4_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:19cd45f09c45a9848e77976aadcb67587539a270f2d5dc6c1e2510684ef0daed
3
+ size 5099582
weights/PatchTST_L_512_T_4_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cce3f7b3a1f1a2c3177a22fea5f841d740af2dbfc84dc485f8f96cf0ad94ad66
3
+ size 5099582
weights/PatchTST_L_512_T_96_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8f49093c256c1a1e77a02a5d496daffe5abf1eefcbd98672f1fd1cfa7930c6b
3
+ size 8114683
weights/PatchTST_L_512_T_96_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2023748d0cfd6506be324878e5c60e59ff196d1d3fe57ff619fedcafa43be9d2
3
+ size 8114683
weights/TimesNet_L_512_T_48_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44fa3615ba3e63ff085ead60271bbb5b71e80b597e2ed11fb63d6ee30bf5dc08
3
+ size 5095208
weights/TimesNet_L_512_T_48_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5917eb643874cecd2a1bdfca8b739b746ca2f8afbbcb415abe3c33fa92fdb0d4
3
+ size 5095208
weights/TimesNet_L_512_T_4_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2ab7d8e70ebdc046297d0431c7d04fb80ac4bc594c25df98843eb391960a25f
3
+ size 5004874
weights/TimesNet_L_512_T_4_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:55f21a29e4f6832e6df6b674d30a412886d826927e7fa5c83705e4f9a9cae20c
3
+ size 5004874
weights/TimesNet_L_512_T_96_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f81d692ebc490aa6f8b0658b7d330405d3b6598a49eb886ff552642f869604b4
3
+ size 5193704
weights/TimesNet_L_512_T_96_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:db49db16f55702204c4e609976c1f24502287facaa7ccbe1bdd9213332c63a48
3
+ size 5193704
weights/Transformer_L_512_T_48_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f79f6cac43d6e7ea9bbce04f5a578111d345a88c1dd84a2badc811901087d3b8
3
+ size 10841738
weights/Transformer_L_512_T_48_HOM.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc94b53d1dc16a5cc192950ba5885ee00a1dd332425c623cd4b9f8ae5043e876
3
+ size 10841738
weights/{transformer_L_96_T_48_HET.pth β†’ Transformer_L_512_T_4_HET.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9880c6615410fe0beecb62b5744d94f18ea5d54aeaa360fc09bf1b854a383454
3
  size 10841594
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:135e67bd5fc9311cc835817be2e9daf41da59909b71771d8f7d3115bc1d0aaa6
3
  size 10841594
weights/{transformer_L_96_T_48_HOM.pth β†’ Transformer_L_512_T_4_HOM.pth} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:60fde291ab8a817e94efc6b285f3025fb90ee16279c2b148e68743b1edd91e57
3
  size 10841594
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8480ce975178bb82aa429faa2de0e827a7d3ad96416513d500afe858402a635a
3
  size 10841594
weights/Transformer_L_512_T_96_HET.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa315ca034ddf92ffda0269a961fcc6998b2dec2cacc71294feb0c44d1ba93d8
3
+ size 10841738