Skip to content

Commit

Permalink
Fix test data in time_sequence_prediction (pytorch#186)
Browse files Browse the repository at this point in the history
Previously the training data input[:3] is incorrectly taken as the test data. Change the input for prediction to data[:3].
  • Loading branch information
PeterChe1990 authored and soumith committed Jul 21, 2017
1 parent 10b22dc commit a4e6972
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion time_sequence_prediction/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def forward(self, input, future = 0):
data = torch.load('traindata.pt')
input = Variable(torch.from_numpy(data[3:, :-1]), requires_grad=False)
target = Variable(torch.from_numpy(data[3:, 1:]), requires_grad=False)
test_input = Variable(torch.from_numpy(data[:3, :-1]), requires_grad=False)
test_target = Variable(torch.from_numpy(data[:3, 1:]), requires_grad=False)
# build the model
seq = Sequence()
seq.double()
Expand All @@ -61,7 +63,9 @@ def closure():
optimizer.step(closure)
# begin to predict
future = 1000
pred = seq(input[:3], future = future)
pred = seq(test_input, future = future)
loss = criterion(pred[:, :-future], test_target)
print('test loss:', loss.data.numpy()[0])
y = pred.data.numpy()
# draw the result
plt.figure(figsize=(30,10))
Expand Down

0 comments on commit a4e6972

Please sign in to comment.