Recommend a versatile and easy-to-implement loss function
Description
Hi there,
I am writing to introduce a loss function tailored for time-series forecasting proposed in FreDF. The source code is provided in https://github.com/Master-PLC/FreDF. Nevertheless, you can ignore the released repo and directly implement FreDF through two lines of code as follows.
# The canonical temporal loss
loss_tmp = ((outputs-batch_y)**2).mean()
# The proposed frequency loss
loss_feq = (torch.fft.rfft(outputs, dim=1) - torch.fft.rfft(batch_y, dim=1)).abs().mean()
# Note. The frequency loss can be used individually or fused with the temporal loss using finetuned relative weights. Both witness performance gains, see the ablation study in our paper.
The efficacy of the loss function has been investigated through extensive experiments in this study. I recognized that there is a losses module in NeuralForecast so I guess it would be helpful to include this plain and effective method.
Use case
No response
Thanks for the suggestion! Are you (one of) the authors?
I like the simplicity - as I understand your loss function is a weighted sum of the plain mean squared error loss and the mean absolute error of the forecast error in the frequency domain?
I'll have to read the paper to understand the design decisions, in the meantime feel free to open a PR implementing your loss, I'd be happy to review.
Yes, I am the first author of this paper. Thank you so much for your appreciation on the simplicity -- we truly appreciate it! Your understanding is absolutely correct that it can be implemented via a weighted sum of (1) the plain MSE in the time domain and (2) the MAE in the frequency domain. The frequency domain is acquired via torch.fft.rfft.