Dynamic Mode Decomposition (DMD)

Many problems we counter can be reduced to the equation form of

DMD was introduced in the early 2010s and has since gained popularity in various scientific and engineering disciplines. The key idea is to measure and approximate below equation by finding map A.

then the problem is reduced to familar eigen value eigen vector (DMD mode). What’s the potential problems with this approach? It would be high dimensionality problem, and the solution is always to reduce deimensionality by SVD

Note in final step, elevate dimensionality back to high but the U inverse is swapped by W now. But DMD modes are not orthogonal, lastly,

Now ask chatGPT to write sample codes to simulate a sine wave data patten and then apply DMD:

from scipy.linalg import svd

import numpy as np
import matplotlib.pyplot as plt

# Assuming y is your data array and x is the time array
y = y.reshape(-1, 1) # Reshape y to a 2D column vector

# Create lagged data matrices for DMD
X = y[:-1] # Data at time t
Y = y[1:] # Data at time t+1

# Compute the SVD of X
U, S, Vh = svd(X, full_matrices=False)

# Rank truncation for DMD (choose rank r)
r = 2 # example rank
U_r = U[:, :r]
S_r = np.diag(S)[:r, :r]
Vh_r = Vh[:r, :]

# Compute the DMD matrix (Atilde)
Atilde = U_r.T @ Y @ Vh_r.T @ np.linalg.inv(S_r)

# Compute the eigenvalues and eigenvectors of Atilde
eigvals, eigvecs = np.linalg.eig(Atilde)

# Calculate the DMD modes
DMD_modes = U_r @ eigvecs

# Plot the DMD mode (assuming the first mode is of interest)
plt.figure(figsize=(12, 8))
plt.subplot(2, 1, 1)
plt.plot(x, y, label='Original Sine Wave', color='blue', linewidth=2)
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.title('Original Sine Wave')
plt.grid(True)
plt.legend()

plt.subplot(2, 1, 2)
plt.plot(x[:-1], DMD_modes[:, 0].real, label='DMD Mode', color='red', linewidth=2)
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.title('DMD Mode')
plt.grid(True)
plt.legend()

# Show the plots
plt.tight_layout()
plt.show()

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.