My dataset is composed of different particle trajectories over time [x(t), y(t)]. Each trajectory has a different length from another and my goal is to perform pointwise regression, i.e. estimate a continuous value a(t) for each time step. Thus if my input is of dimension [batch_size, sequence_length, trajectory_coordinates] I expect my output to be something like [batch_size, sequence_length, 1].
So far, I have trained an architecture composed of:
- Convolutional module
- Self-attention module
- Feedforward module
Because of the different lengths of the inputs, I apply a zero-padding on it and I feed the correponding masks altogether with the inputs. As loss, I mainly adopted MAE and MSE.
When training, the model clearly tends to learn the median/mean value of all the dataset ( all the particles and all the values for each time). Here an example of the performance of the algorithm:
The red-dashed line is the ground truth of a(t). The black line is the output of the model for a(t). The blue line is the average over all particles and time steps of the ground truth available.
As it can be noticed, the model is completely incapable of detecting neither a correct value or a change in the property of interest.
I think that there might be some mistake either on the choice of the loss or in implementing it in the code.
In the script, I first declare the loss (in this case MAE) without any form of reduction since I have some nan values that come from the masking.
criterion = nn.L1Loss(reduction='none')
Then, in the training cycle, I calculate the loss. Recall that output (and labels) are objects of size [batch_size, sequence_length, 1]. Then I sum all the non-nan values and average by the number of elements that are not nan.
loss = criterion(output, labels)
final_loss = torch.nansum(loss).float() / key_masks.count_nonzero()
I believe that I am making a mistake by implicitly averaging over the time steps.
Do you have any solution to recommend?
Little Wing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.