I am building a conditional GAN for time series forecasting. My dataset consists of multivariate time series data, including historical gold prices and historical USD prices as features. My goal is to forecast the next day’s gold prices.
The forward function in the generator takes the following inputs:
X[16,10,2] -> [batch_size, time_steps, features_no(gold, USD)]` `nosie[16,32] -> [batch_size, noise_size]` While the out put should be ` y[16,1].
I am unsure about the correct way to concatenate the noise and the input 𝑋 before passing the output to an LSTM unit.
Here is my attempts:
class Generator_LSTM_LEVY(nn.Module):
def __init__(self, hidden_dim, feature_no, time_steps):
super().__init__()
# LSTM Unit
self.lstm = nn.LSTM(self.input_dim + noise_size, self.hidden_dim,self.layer_dim,
batch_first=True,bidirectional=True)
def forward(self, x, noise, batch_size): # x = [64, 10, 2]
noise_exp = noise.unsqueeze(1).expand(-1, self.time_steps, self.output_dim)
x_n = torch.cat((x, noise_exp), dim=1)
out, (hn, cn) = self.lstm(x_n, (h0, c0))
# Reshaping the outputs in the shape of (batch_size, seq_length, hidden_size)
# so that it can fit into the fully connected layer
out = out[:, -1, :]
#.....
return out
I got error message that
RuntimeError: The expanded size of the tensor (1) must match the existing size (32) at
non-singleton dimension 2. Target sizes: [-1, 10, 1]. Tensor sizes: [16, 1, 32]
Additionaly, I’m not sure if this a meaningful way to do so or not.
Can you please help? any insights will be highly appreciated.