LSTM time-series prediction

  1. Why is the input and target built on opposite indexes? I mean the -1 and 1 in the following lines
    input = Variable(torch.from_numpy(data[3:, :-1]), requires_grad=False)
    target = Variable(torch.from_numpy(data[3:, 1:]), requires_grad=False)

  2. I’m trying to modify the example so the result would be the a prediction not of the future sine values but rather the angle in radians that caused the specific sine value. Doing this as an exercise. the point is that sin values are ambiguous since the same value can have different originating angles in different quadrants, thus the need to know what was the sin value before the current one in-order to predict the future values.
    I thought it can be a good time series classification example. I save the orignal angle values used int he generator script

import numpy as np
import torch

np.random.seed(2)

T = 20
L = 1000
N = 100

x = np.empty((N, L), ‘int64’)
x[:] = np.array(range(L)) + np.random.randint(-4 * T, 4 * T, N).reshape(N, 1)
vals = x / 1.0 / T
data = np.sin(vals).astype(‘float64’)

save the labels to be used as target values later on

torch.save(vals,open(‘labels.pt’,‘wb’))
torch.save(data, open(‘traindata.pt’, ‘wb’))

…and then i use them as target in the train script after normalizing them to 0-2*pi values

“”“
input value between 0 - 360 deg
”""
def deg2norm(self,deg):
#return ((deg % (2 * math.pi)) - math.pi) / math.pi
return deg % (2 * math.pi)

"""
    Create a vector of the expected result who values are a notion of 0-360 degrees
    Due to ML constraints the values need to be in the range of -1..1
"""
def createTarget(self, data):
    # Push all the values intot he positive spectrum of 0 - 360 
    # From angle perspective 
    delta = (round(abs(np.min(data[:]))) + 1) * (2 * math.pi)
    val = data + delta
    return self.deg2norm(val)

labels = torch.load('labels.pt')
labelsTarget = seq.createTarget(labels)

target = Variable(torch.from_numpy(labelsTarget[3:]), requires_grad=False)

alas the net prediction fails although the loss function results are OK

Any idea ?