Skip to content

Commit

Permalink
fix bug in test generation of traj lengths, update deepkoopman call of
Browse files Browse the repository at this point in the history
next step traj
  • Loading branch information
EthanJamesLew committed Mar 20, 2024
1 parent 633f42b commit 02ba932
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion autokoopman/estimator/deepkoopman.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def _get_loss(mseloss, l1loss, x, xn, y, yn, xr, Xn):
for step_size in range(1, self.rollout_steps + 1):
# upload to GPU and normalize the data
# NOTE: this is expensive :(
X, Xn, U = trajs.n_step_matrices(step_size)
X, Xn, U, _ = trajs.n_step_matrices(step_size)
X = torch.tensor(X.T, dtype=torch.float32).to(self.device)
Xn = torch.tensor(Xn.T, dtype=torch.float32).to(self.device)
U = (
Expand Down
10 changes: 4 additions & 6 deletions test/unit_test/test_autokoopman.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def test_autokoopman(obs, opt, cost, normalize):
sp = 0.1
ivs = np.random.uniform(low=-2.0, high=2.0, size=(20, 2))
t_ends = [np.random.random() + 1.0 for idx in range(len(ivs))]
lengths = [int(t_end // sp) for t_end in t_ends]
training_data = UniformTimeTrajectoriesData(
{
idx: fhn.solve_ivp(
Expand All @@ -45,7 +44,7 @@ def test_autokoopman(obs, opt, cost, normalize):
# produce scoring weights if the cost is weighted
if cost == "weighted":
scoring_weights = {
idx: np.ones((length,)) * 0.01 for idx, length in enumerate(lengths)
idx: np.ones(len(traj.states)) * 0.01 for idx, traj in training_data._trajs.items()
}
else:
scoring_weights = None
Expand Down Expand Up @@ -86,8 +85,7 @@ def test_autokoopman_np(obs, opt, cost, normalize):
# given issue #29, let's make these differently sized
sp = 0.1
ivs = np.random.uniform(low=-2.0, high=2.0, size=(20, 2))
t_ends = [np.random.random() + 1.0 for idx in range(len(ivs))]
lengths = [int(t_end // sp) for t_end in t_ends]
t_ends = [1.5 for idx in range(len(ivs))]
training_data = UniformTimeTrajectoriesData(
{
idx: fhn.solve_ivp(
Expand All @@ -102,15 +100,15 @@ def test_autokoopman_np(obs, opt, cost, normalize):
# produce scoring weights if the cost is weighted
if cost == "weighted":
scoring_weights = {
idx: np.ones((length,)) * 0.01 for idx, length in enumerate(lengths)
idx: np.ones((len(t.states),)) * 0.01 for idx, t in training_data._trajs.items()
}
else:
scoring_weights = None

# put into numpy arrays for testing
training_data_np = []
scoring_weights_np = []
for name in training_data.traj_names:
for name in range(len(ivs)):
training_data_np.append(training_data[name].states)
if scoring_weights is not None:
scoring_weights_np.append(scoring_weights[name])
Expand Down

0 comments on commit 02ba932

Please sign in to comment.