Skip to content

Commit 458b16a

Browse files
committed
store singular values in BOPDMD when using fit_econ and update plot_summary accordingly
1 parent c0de217 commit 458b16a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pydmd/bopdmd.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,9 @@ def fit_econ(self, s, V, t):
15661566
# Fit the data.
15671567
self._b = self.operator.compute_operator(snp.T, self._time)
15681568

1569+
# Store the singular values
1570+
self.singular_values = s
1571+
15691572
return self
15701573

15711574
def forecast(self, t):

pydmd/plotter.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,10 @@ def plot_summary(
650650
sizes of all other eigenvalues are then scaled according to eigenvalue
651651
significance.
652652
:type max_eig_ms: int
653-
:param max_sval_plot: Maximum number of singular values to plot.
653+
:param max_sval_plot: Maximum number of singular values to plot. If the DMD
654+
instance was fitted via the `fit_econ` method, the maximum number of
655+
singular values that can be plotted is determined by the length of the
656+
array of singular values passed to `fit_econ`.
654657
:type max_sval_plot: int
655658
:param title_fontsize: Fontsize used for subplot titles.
656659
:type title_fontsize: int
@@ -781,7 +784,14 @@ def plot_summary(
781784
else:
782785
# Use input data matrix to compute singular values.
783786
snp = dmd.snapshots
784-
s = np.linalg.svd(snp, full_matrices=False, compute_uv=False)
787+
if snp is not None:
788+
s = np.linalg.svd(snp, full_matrices=False, compute_uv=False)
789+
else:
790+
try:
791+
s = dmd.singular_values
792+
except AttributeError as e:
793+
msg = "Snapshots and singular values are not available."
794+
raise ValueError(msg) from e
785795
# Compute the percent of data variance captured by each singular value.
786796
s_var = s * (100 / np.sum(s))
787797
s_var = s_var[:max_sval_plot]

0 commit comments

Comments
 (0)