I’m trying to predict one step ahead, given three variables, predict the next three. My data is a list of lists like this:
[[0.700915, 0.72822, 1.0389610389610389]
[0.700015, 0.728785, 1.0410864778482825]
[0.70193, 0.72722, 1.0360332359462092]
[0.70165, 0.727505, 1.0368442608078055]
[0.70768, 0.734015, 1.0372099053545962]
[0.703005, 0.72807, 1.0356523315123114]
[0.70084, 0.72651, 1.0366239232068997]
[0.702125, 0.72727, 1.0358132428723101]
[0.702295, 0.72743, 1.0357917851353522]
[0.701025, 0.726365, 1.0361513195387053]]
I’m attempting to use the basic RNN example, but can’t even convert a single line to a tensor. Tensors just make no sense to me.
Using:
class RNN(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super(RNN, self).__init__()
self.hidden_size = hidden_size
self.i2h = nn.Linear(input_size + hidden_size, hidden_size)
self.i2o = nn.Linear(input_size + hidden_size, output_size)
self.softmax = nn.LogSoftmax()
def forward(self, input, hidden):
combined = torch.cat((input, hidden), 1)
hidden = self.i2h(combined)
output = self.i2o(combined)
output = self.softmax(output)
return output, hidden
def initHidden(self):
return Variable(torch.zeros(1, self.hidden_size))
def nnModel(dataset):
for row in dataset[:10]:
print(row[1:])
n_hidden = 56
rnn = RNN(3, n_hidden, 2)
for row in dataset:
dRow = np.asarray(row[1:])
input = Variable(torch.from_numpy(dRow))
hidden = Variable(torch.zeros(1, n_hidden))
output, next_hidden = rnn(input, hidden)
print("Output: ", output)
break
Gives me this error.
Traceback (most recent call last):
File "fxDataset2.py", line 181, in <module>
nnModel(dataset)
File "fxDataset2.py", line 156, in nnModel
output, next_hidden = rnn(input, hidden)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 206, in __call__
result = self.forward(*input, **kwargs)
File "fxDataset2.py", line 134, in forward
combined = torch.cat((input, hidden), 1)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/variable.py", line 841, in cat
return Concat(dim)(*iterable)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/_functions/tensor.py", line 309, in forward
self.input_sizes = [i.size(self.dim) for i in inputs]
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/_functions/tensor.py", line 309, in <listcomp>
self.input_sizes = [i.size(self.dim) for i in inputs]
RuntimeError: dimension 1 out of range of 1D tensor at /b/wheel/pytorch-src/torch/lib/TH/generic/THTensor.c:24
Are there any simpler tutorials for PyTorch, or someone who can tell me how to turn a list of three numbers into a tensor?