Guest User

Untitled

a guest
Dec 10th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. class TimeSeriesNNModel(nn.Module):
  2. def __init__(self):
  3. super(TimeSeriesNNModel, self).__init__()
  4. self.lstm1 = nn.LSTM(input_size=14, hidden_size=50, num_layers=1)
  5. self.lstm2 = nn.LSTM(input_size=50, hidden_size=25, num_layers=1)
  6. self.linear = nn.Linear(in_features=25, out_features=1)
  7.  
  8. self.h_t1 = None
  9. self.c_t1 = None
  10. self.h_t2 = None
  11. self.c_t2 = None
  12.  
  13. def initialize_model(self):
  14. self.h_t1 = torch.rand(1, 1, 50, dtype=torch.double)
  15. self.c_t1 = torch.rand(1, 1, 50, dtype=torch.double)
  16. self.h_t2 = torch.rand(1, 1, 25, dtype=torch.double)
  17. self.c_t2 = torch.rand(1, 1, 25, dtype=torch.double)
  18.  
  19. def forward(self, input_data, future=0):
  20. outputs = []
  21. self.initialize_model()
  22.  
  23. output = None
  24. for i, input_t in enumerate(input_data.chunk(input_data.size(1), dim=1)):
  25. self.h_t1, self.c_t1 = self.lstm1(input_t, (self.h_t1, self.c_t1))
  26. self.h_t2, self.c_t2 = self.lstm2(self.h_t1, (self.h_t2, self.c_t2))
  27. output = self.linear(self.h_t2)
  28. outputs += [output]
  29.  
  30. outputs = torch.stack(outputs, 1).squeeze(2)
  31. return outputs
Add Comment
Please, Sign In to add comment