Skip to content

Commit 3acf2b1

Browse files
authored
Merge pull request PyDMD#475 from sichinaga/tutorial1-updates
Updated tutorial 1
2 parents dd8a431 + 7e4b2ca commit 3acf2b1

File tree

9 files changed

+491
-781
lines changed

9 files changed

+491
-781
lines changed

pydmd/bopdmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def compute_operator(self, H, t):
748748
"Consider re-adjusting your variable projection parameters "
749749
"with the varpro_opts_dict and consider setting verbose=True."
750750
)
751-
print(msg)
751+
warnings.warn(msg)
752752

753753
# If num_trials isn't a positive int, perform standard optimized dmd.
754754
if self._num_trials <= 0 or not isinstance(self._num_trials, int):
@@ -948,7 +948,7 @@ def __init__(
948948
init_alpha=None,
949949
proj_basis=None,
950950
num_trials=0,
951-
trial_size=0.2,
951+
trial_size=0.6,
952952
eig_sort="auto",
953953
eig_constraints=None,
954954
bag_warning=100,

pydmd/plotter.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ def plot_snapshots_2D(
535535
def plot_summary(
536536
dmd,
537537
*,
538+
d=1,
538539
continuous=False,
539540
snapshots_shape=None,
540541
index_modes=None,
@@ -567,6 +568,10 @@ def plot_summary(
567568
568569
:param dmd: DMD instance.
569570
:type dmd: pydmd.DMDBase
571+
:param d: Number of delays applied to the data passed to the DMD instance.
572+
If `d` is greater than 1, then each plotted mode will be the average
573+
mode taken across all `d` delays.
574+
:type d: int
570575
:param continuous: Whether or not the eigenvalues of the given DMD instance
571576
are continuous-time. If `False`, the eigenvalues are assumed to be the
572577
discrete-time eigenvalues. If `True`, the eigenvalues are taken to be
@@ -715,6 +720,15 @@ def plot_summary(
715720
disc_eigs = lead_eigs
716721
cont_eigs = np.log(lead_eigs) / dt
717722

723+
# Get mode averages across delays if time-delay was used.
724+
if d > 1:
725+
lead_modes = np.average(
726+
lead_modes.reshape(
727+
d, lead_modes.shape[0] // d, lead_modes.shape[1]
728+
),
729+
axis=0,
730+
)
731+
718732
# Compute the singular values of the data matrix.
719733
if isinstance(dmd, HankelDMD):
720734
# Use time-delay data matrix to compute singular values.

pydmd/preprocessing/pre_post_processing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ def __getattribute__(self, name):
7979
return object.__getattribute__(self._pre_post_processed_dmd, name)
8080
return None
8181

82+
@property
83+
def pre_post_processed_dmd(self):
84+
"""
85+
Return the pre/post-processed DMD instance.
86+
87+
:return: decorated DMD instance.
88+
:rtype: pydmd.DMDBase
89+
"""
90+
return self._pre_post_processed_dmd
91+
8292
@property
8393
def modes_activation_bitmask(self):
8494
return self._pre_post_processed_dmd.modes_activation_bitmask

tests/test_bopdmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,4 @@ def relative_error(x, x_true):
361361
bopdmd_error = relative_error(bopdmd.A, expected_A)
362362
bop_success += bopdmd_error < optdmd_error
363363

364-
assert bop_success >= 0.75 * test_trials
364+
assert bop_success >= 0.7 * test_trials

tutorials/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ An additional PDF tutorial ([DSWeb contest winner](https://dsweb.siam.org/The-Ma
66

77
| Name | Description | PyDMD used classes |
88
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|-----------------------|
9-
| Tutorial1&#160;[[.ipynb](tutorial1/tutorial-1-dmd.ipynb),&#160;[.py](tutorial1/tutorial-1-dmd.py),&#160;[.html](http://pydmd.github.io/PyDMD/tutorial1dmd.html)] | basic usage of standard DMD | `pydmd.DMD` |
9+
| Tutorial1&#160;[[.ipynb](tutorial1/tutorial-1-dmd.ipynb),&#160;[.py](tutorial1/tutorial-1-dmd.py),&#160;[.html](http://pydmd.github.io/PyDMD/tutorial1dmd.html)] | Analyzing real, simple data sets with PyDMD | `pydmd.DMD`, `pydmd.BOPDMD` |
1010
| Tutorial2&#160;[[.ipynb](tutorial2/tutorial-2-adv-dmd.ipynb),&#160;[.py](tutorial2/tutorial-2-adv-dmd.py),&#160;[.html](http://pydmd.github.io/PyDMD/tutorial2advdmd.html)] | advanced features of standard DMD | `pydmd.DMD` |
1111
| Tutorial3&#160;[[.ipynb](tutorial3/tutorial-3-mrdmd.ipynb),&#160;[.py](tutorial3/tutorial-3-mrdmd.py),&#160;[.html](http://pydmd.github.io/PyDMD/tutorial3mrdmd.html)] | multi-resolution DMD for transient phenomena | `pydmd.MrDMD` |
1212
| Tutorial4&#160;[[.ipynb](tutorial4/tutorial-4-cdmd.ipynb),&#160;[.py](tutorial4/tutorial-4-cdmd.py),&#160;[.html](http://pydmd.github.io/PyDMD/tutorial4cdmd.html)] | compress DMD for computation speedup | `pydmd.CDMD` |

tutorials/tutorial1/tutorial-1-dmd.ipynb

100755100644
Lines changed: 449 additions & 78 deletions
Large diffs are not rendered by default.

tutorials/tutorial1/tutorial-1-dmd.py

Lines changed: 0 additions & 145 deletions
This file was deleted.

tutorials/tutorial18/tutorial-18-lando.ipynb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,20 @@
291291
}
292292
],
293293
"source": [
294-
"t1 = time.time()\n",
295-
"edmd = EDMD(\n",
296-
" svd_rank=18,\n",
297-
" kernel_metric=\"poly\",\n",
298-
" kernel_params={\"degree\": 3, \"coef0\": 1.0, \"gamma\": 1.0},\n",
299-
")\n",
300-
"edmd.fit(X)\n",
301-
"t2 = time.time()\n",
302-
"print(\"EDMD Fitting Time: {}\".format(t2 - t1))\n",
303-
"\n",
304-
"edmd_recon = edmd.reconstructed_data.real\n",
305-
"plot_lorenz_reconstruction(X, edmd_recon, \"EDMD reconstruction\", \"tab:orange\")"
294+
"# Note: This cell may take a while to run (approximately 10 minutes).\n",
295+
"\n",
296+
"# t1 = time.time()\n",
297+
"# edmd = EDMD(\n",
298+
"# svd_rank=18,\n",
299+
"# kernel_metric=\"poly\",\n",
300+
"# kernel_params={\"degree\": 3, \"coef0\": 1.0, \"gamma\": 1.0},\n",
301+
"# )\n",
302+
"# edmd.fit(X)\n",
303+
"# t2 = time.time()\n",
304+
"# print(\"EDMD Fitting Time: {}\".format(t2 - t1))\n",
305+
"\n",
306+
"# edmd_recon = edmd.reconstructed_data.real\n",
307+
"# plot_lorenz_reconstruction(X, edmd_recon, \"EDMD reconstruction\", \"tab:orange\")"
306308
]
307309
},
308310
{

0 commit comments

Comments
 (0)