PyDMD icon indicating copy to clipboard operation
PyDMD copied to clipboard

Fixed bug in building convolution windows for mrCOSTS

Open klapo opened this issue 1 year ago • 8 comments

Hi all,

I found a small bug in how mrCOSTS builds it convolution windows and performed window rounding. The long story short was that I didn't correctly adapt the original MATLAB indexing for python. This pull request fixes that issue.

Summary of changes:

  • Convolution windows had MATLAB style indexing and not python. As a result the windows did not peak at the right place.
  • Similarly, the window rounding was asymmetric.
  • Causes slight reduction in the reconstructed error in the toy data example.
  • b amplitudes now fall along PSD of the input data, fixing a lingering issue in the mrCOSTS fit and giving it more diagnostic power.
  • Fixed the mrCOSTS tests not correctly tearing down.

Thanks for taking a look! Karl

klapo avatar May 27 '24 14:05 klapo

Just as a public note, the lv_kern function still returns an asymmetric kerning ((np.arange(0, window_length) - window_length - 1) should be (np.arange(0, window_length) - window_length + 1) ). Unfortunately, making the window symmetric seems to reduce the fit quality in testing, so I am just accepting that this is a weird idiosyncrasy of the method for the time being.

klapo avatar Jun 30 '24 08:06 klapo

I managed to break everything.

The tutorial tests failing is Notebook 2 (Advanced DMD) because scipy.integrate.trapz wasn't found. The most recent release of scipy removed .trapz in favor or .trapezoid (https://docs.scipy.org/doc/scipy/release/1.14.0-notes.html). Do we want to pin the scipy version to be >=1.14 and update the call to the non-deprecated version?

klapo avatar Jun 30 '24 09:06 klapo

I think the unit tests broke because I did os.chdir(tmp_path) in the mrCOSTS unit tests. Then the other tests were pointing to the wrong directory when it came time for them to load the test data. I don't have the internet connection to download the test extras so I'm testing this directly here on github instead of locally.

klapo avatar Jun 30 '24 09:06 klapo

I managed to break everything.

The tutorial tests failing is Notebook 2 (Advanced DMD) because scipy.integrate.trapz wasn't found. The most recent release of scipy removed .trapz in favor or .trapezoid (https://docs.scipy.org/doc/scipy/release/1.14.0-notes.html). Do we want to pin the scipy version to be >=1.14 and update the call to the non-deprecated version?

Thank you for pointing this out. @fandreuz @ndem0 @sichinaga Should we add a try/else since version 1.14 is the latest one? I don't want to limit the current users. IMHO we can impose the version after 1 or 2 new versions. What do you think?

mtezzele avatar Jul 01 '24 15:07 mtezzele

@mtezzele I propose to keep only the new version, scipy.integrate.trapezoid has been around for 4 years: https://github.com/scipy/scipy/blob/v1.6.0/scipy/integrate/_quadrature.py

fandreuz avatar Jul 01 '24 18:07 fandreuz

@mtezzele I propose to keep only the new version, scipy.integrate.trapezoid has been around for 4 years: https://github.com/scipy/scipy/blob/v1.6.0/scipy/integrate/_quadrature.py

Ok, so we can enforce scipy >= version_of_4_years_ago instead of the current one, which is quite new. What do you think?

mtezzele avatar Jul 01 '24 21:07 mtezzele

@mtezzele I propose to keep only the new version, scipy.integrate.trapezoid has been around for 4 years: https://github.com/scipy/scipy/blob/v1.6.0/scipy/integrate/_quadrature.py

Ok, so we can enforce scipy >= version_of_4_years_ago instead of the current one, which is quite new. What do you think?

Yes looks good! You want to do it? Otherwise I'll open a PR

fandreuz avatar Jul 01 '24 21:07 fandreuz

@mtezzele I propose to keep only the new version, scipy.integrate.trapezoid has been around for 4 years: https://github.com/scipy/scipy/blob/v1.6.0/scipy/integrate/_quadrature.py

Ok, so we can enforce scipy >= version_of_4_years_ago instead of the current one, which is quite new. What do you think?

Yes looks good! You want to do it? Otherwise I'll open a PR

Go ahead please! Thank you very much!

mtezzele avatar Jul 01 '24 22:07 mtezzele

Let me know if I can merge this PR

mtezzele avatar Jul 02 '24 21:07 mtezzele

I believe so. Thank you to everyone!

klapo avatar Jul 03 '24 09:07 klapo