Skip to content

add FreDF loss combining time-domain MSE and frequency-domain MAE#1563

Open
DresdenGman wants to merge 3 commits into
Nixtla:mainfrom
DresdenGman:feat/fredf-loss
Open

add FreDF loss combining time-domain MSE and frequency-domain MAE#1563
DresdenGman wants to merge 3 commits into
Nixtla:mainfrom
DresdenGman:feat/fredf-loss

Conversation

@DresdenGman

Copy link
Copy Markdown

Following up on #1301 — implements the FreDF loss proposed by Lin et al. (2023).

FreDF combines time-domain MSE with frequency-domain MAE via torch.fft.rfft, weighted by a tunable alpha parameter (default 0.5). When alpha=0 it reduces to pure MSE; when alpha=1 it reduces to pure frequency-domain MAE.

Added FreDF to all in losses/pytorch.py, inheriting BasePointLoss to stay consistent with the existing loss API.

Closes #1301

@CLAassistant

CLAassistant commented Jun 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@marcopeix

Copy link
Copy Markdown
Contributor

@DresdenGman thanks for the contribution! Could you add a few tests in neuralforecast/tests/test_losses/test_pytorch.py please. Especially for when alpha is 0 and 1, that will validate the implementation is sound. Thanks!

@DresdenGman

Copy link
Copy Markdown
Author

Added three tests in test_pytorch.py: alpha=0 (reduces to MSE), alpha=1 (reduces to frequency-domain MAE), and perfect forecast gives zero loss for any alpha.

@marcopeix marcopeix left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DresdenGman, see my comment. Seems like you're adding an entirely new test file, but you should modify the existing test file.

assert len(check.quantiles) == 5


def test_fredf_alpha0_equals_mse():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are good, but it seems like the entire file is new. That's not right. You should modify the existing file: https://github.com/Nixtla/neuralforecast/blob/main/tests/test_losses/test_pytorch.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recommend a versatile and easy-to-implement loss function

3 participants