[FEAT] Fast Fourier Transform Losses#1465
Open
SkyeGunasekaran wants to merge 2 commits intoNixtla:mainfrom
Open
[FEAT] Fast Fourier Transform Losses#1465SkyeGunasekaran wants to merge 2 commits intoNixtla:mainfrom
SkyeGunasekaran wants to merge 2 commits intoNixtla:mainfrom
Conversation
|
|
1 similar comment
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description: Integration of Fourier-Domain Loss Functions
Overview
This PR introduces a suite of frequency-domain loss functions and a flexible
MixedFFTLossutility. These additions allow the model to optimize for spectral density and periodic structures, which provides a more robust loss function to trend and seasonality vs direct pointwise prediction errors.Fourier Loss Suite
I have implemented three core frequency-domain losses based on the magnitude spectrum of the Real Discrete Fourier Transform (RFFT):
FFTMAELoss: Mean Absolute Error in frequency space.FFTMSELoss: Mean Squared Error in frequency space.FFTRMSELoss: Root Mean Squared Error in frequency space.These losses operate on the magnitude spectrum$|F(y)|$ which ensures the loss remains real-valued, focuses on the power distribution of seasonal and trend components rather than exact point-in-time alignment.
Hybrid Optimization (
MixedFFTLoss)To balance point-wise accuracy with structural frequency alignment, I added
MixedFFTLoss. This allows for a composite objective function. This function provides the best balance for real-world use cases:Key Features:
normparameter to ensure loss stability across varying sequence lengths (BasePointLossinterface to seamlessly integrate with existing loss functions in the repository.Testing
Tests are located in
tests/test_losses/test_fft_losses.pyand run via PyTest. Each of the four loss classes (FFTMAELoss,FFTMSELoss,FFTRMSELoss,MixedFFTLoss) has four dedicated test cases:yandy_hat; asserts loss is exactly zero.[B, H, N]tensors withN > 1outputs; asserts the result is positive, finite, and — for RMSE — equal to the square root of the corresponding MSE loss.MixedFFTLossraisesTypeErrorfor invalid loss type pairings.1e-8and1e8) withnorm=Trueand asserts noNaNorInfvalues are produced.All tests pass locally; note
torchandpytestare required to run tests.Source