Skip to content

Commit

Permalink
switch to a harder problem for example
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanJamesLew committed Apr 13, 2024
1 parent 5e2254c commit b08476e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions notebooks/weighted-cost-func.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"sys.path.append(\"..\")\n",
"# this is the convenience function\n",
"from autokoopman import auto_koopman\n",
"import autokoopman as ak"
"import autokoopman as ak\n",
"\n",
"np.random.seed(1234)"
]
},
{
Expand All @@ -50,7 +52,7 @@
"\n",
"# add garbage states -- we will weight these values to zero\n",
"training_data = ak.TrajectoriesData({\n",
" key: ak.Trajectory(t.times, np.hstack([t.states, np.random.rand(len(t.states), 3)]), t.inputs) for key, t in training_data._trajs.items()\n",
" key: ak.Trajectory(t.times, np.hstack([t.states, np.random.rand() * np.ones((len(t.states), 3))]), t.inputs) for key, t in training_data._trajs.items()\n",
"})"
]
},
Expand Down Expand Up @@ -88,8 +90,8 @@
" #w = np.sum(traj.abs().states, axis=1)\n",
" #w = 1/(traj.abs().states+1.0)\n",
" w = np.ones(traj.states.shape)\n",
" w[:, -3:] = 0.0\n",
" w[:, 0] = 1.0\n",
" w[:, -3:] = 1.0\n",
" w[:, :2] = 1.0\n",
" weights.append(w)\n",
"\n",
" # weight garbage trajectory to zero\n",
Expand Down Expand Up @@ -131,11 +133,11 @@
" 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=20, # maximum number of observables to try\n",
" n_obs=40, # 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",
" rank=(1, 200, 40) # rank range (start, stop, step) DMD hyperparameter\n",
" n_splits=None, # k-folds validation for tuning, helps stabilize the scoring\n",
" rank=(20, 21, 1) # rank range (start, stop, step) DMD hyperparameter\n",
")"
]
},
Expand Down Expand Up @@ -163,11 +165,12 @@
" 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=20, # maximum number of observables to try\n",
" n_obs=40, # 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",
" rank=(1, 200, 40) # rank range (start, stop, step) DMD hyperparameter\n",
" lengthscale=(0.1, 1.0),\n",
" rank=(20, 21, 1) # rank range (start, stop, step) DMD hyperparameter\n",
")"
]
},
Expand Down Expand Up @@ -195,7 +198,7 @@
"tend = 7.0\n",
"\n",
"# simulate using the learned model\n",
"iv = [0.5, 0.5, 0.0, 0.0, 0.0]\n",
"iv = [0.5, 0.5, 0.5, 0.5, 0.5]\n",
"trajectory = model.solve_ivp(\n",
" initial_state=iv,\n",
" tspan=(0.0, tend, 0.0),\n",
Expand Down

0 comments on commit b08476e

Please sign in to comment.