Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TimeSeriesNNModel(nn.Module):
- def __init__(self):
- super(TimeSeriesNNModel, self).__init__()
- self.lstm1 = nn.LSTM(input_size=14, hidden_size=50, num_layers=1)
- self.lstm2 = nn.LSTM(input_size=50, hidden_size=25, num_layers=1)
- self.linear = nn.Linear(in_features=25, out_features=1)
- self.h_t1 = None
- self.c_t1 = None
- self.h_t2 = None
- self.c_t2 = None
- def initialize_model(self):
- self.h_t1 = torch.rand(1, 1, 50, dtype=torch.double)
- self.c_t1 = torch.rand(1, 1, 50, dtype=torch.double)
- self.h_t2 = torch.rand(1, 1, 25, dtype=torch.double)
- self.c_t2 = torch.rand(1, 1, 25, dtype=torch.double)
- def forward(self, input_data, future=0):
- outputs = []
- self.initialize_model()
- output = None
- for i, input_t in enumerate(input_data.chunk(input_data.size(1), dim=1)):
- self.h_t1, self.c_t1 = self.lstm1(input_t, (self.h_t1, self.c_t1))
- self.h_t2, self.c_t2 = self.lstm2(self.h_t1, (self.h_t2, self.c_t2))
- output = self.linear(self.h_t2)
- outputs += [output]
- outputs = torch.stack(outputs, 1).squeeze(2)
- return outputs
Add Comment
Please, Sign In to add comment