MathEXLab / PySPOD

A Python package for spectral proper orthogonal decomposition (SPOD).
https://mathexlab.github.io/PySPOD/
MIT License
97 stars 29 forks source link

How to reconstruct original data with Pyspod, in the time domain? #15

Closed bva99 closed 2 years ago

bva99 commented 3 years ago

I am trying to apply spectral POD to a mean-normalized data matrix Q(t,x)∈ℝN×M, where N is the number of variables times the number of spatial grid points and M is the number of snapshots.

In classical POD, we find the K modes Ψ(x)∈ℝN×K, either through the eigenvectors of the covariance matrix or of the correlation matrix, and then define the time-amplitudes A(t)∈ℝK×M that approximates Q via A=Ψt Q.

Thus, the reconstructed (mean-normalized) data in classical POD is =Ψ A

But this is not clear to me in SPOD. Specifically, I have two main questions on using Pyspod, which I believe are missing in the tutorials:

1) How does one obtain the equivalent (spectral?)matrix  in SPOD? Is there one matrix for each frequency fk?

I imagine it would be Âk=Ψ̂tk k

2) How do I get the approximation of in the time domain, once I have the equivalent reconstructed matrix in the frequency domain?

Do I need to perform a "block inverse FFT"?

PS.: I really wish Github supported LateX notation hahaha

mengaldo commented 3 years ago

@bva99 thank you for the note. I am trying to get that implemented shortly. To answer your questions, yes, that is what you need to do, and there is a paper about to appear from @olivertschmidt that will explain that in detail.

The steps to follow are:

1.) for every frequency: A=Ψt W Q. 2.) q(k) = (1 / W) ifft(q(k, freq)), for every block (k).

If you want to implement that in PySPOD and ask for a pull request, please do, following these guidelines:

  1. open a new issue describing the bug you intend to fix or the feature you want to add.
  2. fork the project and open your own branch related to the issue you just opened, and call the branch fix/name-of-the-issue if it is a bug fix, or feature/name-of-the-issue if you are adding a feature.
  3. ensure to use 4 spaces tabs for formatting the code.
  4. if you add a feature, it should be accompanied by relevant tests to ensure it functions correctly, while the code continue to be developed.
  5. commit your changes with a self-explanatory commit message.
  6. push your commits and submit a pull request. Please, remember to rebase properly in order to maintain a clean, linear git history.
mengaldo commented 2 years ago

@bva99 this is now present in the main branch of the code. You can check the code in spod_base.py, methods: reconstruct_data and reconstruct_data_freq. These two methods follow: Frequency–time analysis, low-rank reconstruction and denoising of turbulent flows using SPOD

In the updated library we also added learning the SPOD latent space (the time coefficients) using a long-short term memory (LSTM) network for forecasting purposes. You can refer to this preprint if interested:
Neural-network learning of SPOD latent dynamics