Skip to content

Commit 96a40cf

Browse files
committed
add fallback method to swedmdc
add clipping to sensitivities
1 parent 305d8cf commit 96a40cf

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

autokoopman/estimator/koopman.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def swdmdc(X, Xp, U, r, Js, W):
8585
K = cp.Variable((n_obs, n_obs + n_inps))
8686

8787
# SW-eDMD objective
88-
weights_obj = np.vstack([(np.abs(J) @ w) for J, w in zip(Js, W)]).T
88+
weights_obj = np.vstack([(np.clip(np.abs(J), 0.0, 1.0) @ w) for J, w in zip(Js, W)]).T
8989
P = sf * cp.multiply(weights_obj, Yp.T - K @ Y.T)
9090
# add regularization
9191
objective = cp.Minimize(cp.sum_squares(P) + 1E-4 * 1.0 / (n_obs**2) * cp.norm(K, "fro"))
@@ -97,15 +97,15 @@ def swdmdc(X, Xp, U, r, Js, W):
9797
prob = cp.Problem(objective, constraints)
9898

9999
# solve for the SW-eDMD Koopman operator
100-
_ = prob.solve(solver=cp.CLARABEL)
101-
#_ = prob.solve(solver=cp.ECOS)
102-
103-
# backup case
104-
if K.value is None:
105-
# give a warning about the optimization failure
100+
try:
101+
_ = prob.solve(solver=cp.CLARABEL)
102+
#_ = prob.solve(solver=cp.ECOS)
103+
if K.value is None:
104+
raise Exception("SW-eDMD (cvxpy) Optimization failed to converge.")
105+
except:
106106
warnings.warn("SW-eDMD (cvxpy) Optimization failed to converge. Switching to unweighted DMDc.")
107-
return dmdc(X, Xp, U, r)
108-
107+
return dmdc(X, Xp, U, r)
108+
109109
# get the transformation
110110
Atilde = K.value
111111
return Atilde[:, :state_size], Atilde[:, state_size:]

0 commit comments

Comments
 (0)