PyDMD / PyDMD

Python Dynamic Mode Decomposition

Home Page:https://pydmd.github.io/PyDMD/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plot_summary for Hankel and Hodmd

mtezzele opened this issue · comments

Describe the bug
The method plot_summary when used with HODMD or Hankel DMD produces an IndexError

To Reproduce
Use it for example in tutorial 6

Output

--> 635         t[idx], s_var[idx], "o", c=mode_colors[i], ms=8, mec="k"
    636     )
    638 # Plots 2-3: Plot the eigenvalues (discrete-time and continuous-time).
    639 # Scale marker sizes to reflect the amount of variance captured.
    640 max_marker_size = 10

IndexError: index 1 is out of bounds for axis 0 with size 1

@mtezzele I will investigate this asap

Thank you!

Hi @mtezzele! Apologies that it took a while for me to get to this, but I've tracked the issue down and it turns out that the major issue is the fact that for a given model dmd, the plot_summary function accesses dmd.snapshots in order to compute the singular value spectrum of the data, which is fine in most cases. However, for HankelDMD models, the model's snapshots are typically low-dimensional and oftentimes time series (like in the case of Tutorial 6), in which case a very limited number of singular values can be computed from the original snapshots.

What I think I'll do in order to fix this is I'll make it so that in the event that a HankelDMD model is passed to the method, it will use the time-delay data matrix (which I believe is currently called the ho_snapshots in the code) in order to compute the singular values of the data. I'll also implement a safeguard that checks the number of computed singular values (in case of the event that a very low-dimensional data matrix, say a $2 \times n$ data matrix, is passed to a non-HankelDMD model and very few singular values can be computed).

There's also another tiny bug in plot_summary that I intend on fixing (an index-out-of-bounds error that is thrown if the method attempts to plot more than 50 eigenvalues), so I'll put all of these edits into a single PR. Thank you for catching this issue! :)

Sounds great, thanks! Feel free to refactor some names if they are not clear. HankelDMD and HODMD had some errors in the initial implementation...