Skip to content

Commit

Permalink
use Y (state + inp) instead of X for swdmdc
Browse files Browse the repository at this point in the history
use the pinv if inv fails
  • Loading branch information
EthanJamesLew committed Apr 19, 2024
1 parent d04d862 commit 13b2e52
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions autokoopman/estimator/koopman.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def wdmdc(X, Xp, U, r, W):
U, Sigma, V = np.linalg.svd(Y, False)
U, Sigma, V = U[:, :r], np.diag(Sigma)[:r, :r], V.conj().T[:, :r]

# get the transformation
# get the transformation
try:
Atilde = Yp @ V @ np.linalg.inv(Sigma) @ U.conj().T
Expand Down Expand Up @@ -84,7 +85,7 @@ def swdmdc(X, Xp, U, r, Js, W):

# SW-eDMD objective
weights_obj = np.vstack([(np.abs(J) @ w)[:n_obs] for J, w in zip(Js, W)]).T
P = sf * cp.multiply(weights_obj, Xp[:, :n_obs].T - K @ X[:, :n_obs].T)
P = sf * cp.multiply(weights_obj, Yp[:, :n_obs].T - K @ Y[:, :n_obs].T)
# add regularization
objective = cp.Minimize(cp.sum_squares(P) + 1E-4 * 1.0 / (n_obs**2) * cp.norm(K, "fro"))

Expand Down Expand Up @@ -217,20 +218,9 @@ def fit_gradient(
if weights is None:
self._A, self._B = dmdc(G, Gp, U.T if U is not None else U, self.rank)
else:
# TODO: change this condition to be more accurate
if False: # len(weights[0].shape) == 1:
self._A, self._B = wdmdc(
G, Gp, U.T if U is not None else U, self.rank, weights
)
else:
self._A, self._B = swdmdc(
G,
Gp,
U.T if U is not None else U,
self.rank,
[self.obs.obs_grad(xi) for xi in X.T],
weights,
)
self._A, self._B = wdmdc(
G, Gp, U.T if U is not None else U, self.rank, weights
)
self._has_input = U is not None

@property
Expand Down

0 comments on commit 13b2e52

Please sign in to comment.