Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self.length_ratio for energy compensation #1

Closed
Hank0626 opened this issue Mar 4, 2024 · 5 comments
Closed

self.length_ratio for energy compensation #1

Hank0626 opened this issue Mar 4, 2024 · 5 comments

Comments

@Hank0626
Copy link

Hank0626 commented Mar 4, 2024

I've been reviewing the code in the FITS repository, and I'd like to discuss the handling of the temporal length of the tensor low_xy. Specifically, I am referring to this line:

low_xy=low_xy * self.length_ratio # compemsate the length change

My understanding is that this line performs a scalar multiplication of the tensor low_xy, but it does not seem to alter its temporal length. It appears to me that the adjustment of the temporal length of low_xy is actually handled by a different section of the code, as shown here:

low_specxy = torch.zeros([low_specxy_.size(0),int((self.seq_len+self.pred_len)/2+1),low_specxy_.size(2)],dtype=low_specxy_.dtype).to(low_specxy_.device)

I believe this interpolation is where the temporal length change is compensated for. Could you please confirm if my understanding is correct, or provide further clarification if I've misunderstood the code's functionality?

Thank you for your time and for the work on this project.

@VEWOXIC
Copy link
Owner

VEWOXIC commented Mar 13, 2024

Thanks for asking.

As you mentioned, the Line 52 is just to create a placeholder for the spectrum of interpolated time series. As you can see, we just create a new zero tensor of the specified shape. It involves no scaling and energy compensation.

However, in Line 55, we perform the scaling to compensate the amplitude change caused by the changing of time series length. Specifically, in spectral analysis, amplitude is usually proportional to the number of times a frequency component appears in the signal. The Fourier transform, an energy-conserving transformation, redistributes the energy of a time-domain signal into the frequency domain. As the signal length increases (here, the number of cycles), the energy (or amplitude) of the same frequency component increases because this frequency component occurs more frequently in the signal. For instance, a Fourier transform of a 100-point segment (5 cycles) of a sine wave with a period of 20 points would result in a peak at frequency 5 with an amplitude of 250, but transforming a 200-point segment (10 cycles) would yield a peak at frequency 10 with an amplitude of 500. Compensation for this energy increase due to sequence length is achieved by multiplying by a scalar, namely (output length/input length).

Hope above explanation can address your question. You may also write a simple Python script to test this claim.

@VEWOXIC
Copy link
Owner

VEWOXIC commented Mar 13, 2024

Hi, I have updated the misleading comment in Line 55, please check.

@Hank0626
Copy link
Author

Thanks! it is clear to me now.

@Hank0626
Copy link
Author

Hank0626 commented Mar 13, 2024

By the way, the following two lines of code confuse me:

low_specx[:,self.dominance_freq:]=0 # LPF

low_specx = low_specx[:,0:self.dominance_freq,:] # LPF

I think the code in line 42 is meaningless due to the fact that the value in line 43 only takes the frequency before self.dominance_freq.

@VEWOXIC
Copy link
Owner

VEWOXIC commented Mar 13, 2024

Yeah, seems so. Anyway, I did not change it if it works properly XD.

If there is no further question, I will close this issue.

@VEWOXIC VEWOXIC closed this as completed Mar 13, 2024
@VEWOXIC VEWOXIC pinned this issue May 25, 2024
@VEWOXIC VEWOXIC changed the title Clarification Needed on Temporal Length Adjustment in low_xy self.length_ratio for energy compensation Aug 16, 2024
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

No branches or pull requests

2 participants