Skip to content

Commit

Permalink
parallelize the cvxpy code
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanJamesLew committed Apr 13, 2024
1 parent a456fe9 commit 0cb9ddb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions autokoopman/estimator/koopman.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def swdmdc(X, Xp, U, r, Js, W):
K = cp.Variable((n_obs, n_obs))

# SW-eDMD objective
objective = cp.Minimize(sum([
cp.sum_squares(sf * cp.multiply((np.abs(J) @ w)[:n_obs], (xpi[:n_obs] - K @ xi[:n_obs]))) for J, w, xpi, xi in zip(Js, W, Xp, X)
]))
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)
objective = cp.Minimize(cp.sum_squares(P))

# unconstrained problem
constraints = None
Expand Down
4 changes: 2 additions & 2 deletions notebooks/weighted-cost-func.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
" learning_weights=weights, # weight the eDMD algorithm objectives\n",
" scoring_weights=weights, # pass weights as required for cost_func=\"weighted\"\n",
" opt=\"grid\", # grid search to find best hyperparameters\n",
" n_obs=30, # maximum number of observables to try\n",
" n_obs=10, # maximum number of observables to try\n",
" max_opt_iter=200, # maximum number of optimization iterations\n",
" grid_param_slices=5, # for grid search, number of slices for each parameter\n",
" n_splits=5, # k-folds validation for tuning, helps stabilize the scoring\n",
Expand Down Expand Up @@ -156,7 +156,7 @@
" learning_weights=None, # don't use eDMD weighting\n",
" scoring_weights=weights, # pass weights as required for cost_func=\"weighted\"\n",
" opt=\"grid\", # grid search to find best hyperparameters\n",
" n_obs=30, # maximum number of observables to try\n",
" n_obs=10, # maximum number of observables to try\n",
" max_opt_iter=200, # maximum number of optimization iterations\n",
" grid_param_slices=5, # for grid search, number of slices for each parameter\n",
" n_splits=5, # k-folds validation for tuning, helps stabilize the scoring\n",
Expand Down

0 comments on commit 0cb9ddb

Please sign in to comment.