Skip to content

Commit

Permalink
relative error in loo_error method
Browse files Browse the repository at this point in the history
  • Loading branch information
ndem0 committed May 27, 2022
1 parent 767a924 commit 858e490
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions ezyrb/reducedordermodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,16 @@ def loo_error(self, *args, norm=np.linalg.norm, **kwargs):
db_range = list(range(len(self.database)))

for j in db_range:
remaining_index = db_range[:]
remaining_index.remove(j)
new_db = self.database[remaining_index]
indeces = np.array([True] * len(self.database))
indeces[j] = False

new_db = self.database[indeces]
test_db = self.database[~indeces]
rom = type(self)(new_db, copy.deepcopy(self.reduction),
copy.deepcopy(self.approximation)).fit(
*args, **kwargs)

error[j] = norm(self.database.snapshots[j] -
rom.predict(self.database.parameters[j]))
error[j] = rom.test_error(test_db)

return error

Expand Down
6 changes: 3 additions & 3 deletions tests/test_reducedordermodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_loo_error_01(self):
err = rom.loo_error()
np.testing.assert_allclose(
err,
np.array([421.299091, 344.571787, 48.711501, 300.490491]),
np.array([0.540029, 1.211744, 0.271776, 0.919509]),
rtol=1e-4)

def test_loo_error_02(self):
Expand All @@ -188,7 +188,7 @@ def test_loo_error_02(self):
err = rom.loo_error(normalizer=False)
np.testing.assert_allclose(
err[0],
np.array(498.703803),
np.array(0.639247),
rtol=1e-3)

def test_loo_error_singular_values(self):
Expand All @@ -206,5 +206,5 @@ def test_optimal_mu(self):
db = Database(param, snapshots.T)
rom = ROM(db, pod, rbf).fit()
opt_mu = rom.optimal_mu()
np.testing.assert_allclose(opt_mu, [[-0.17687147, -0.21820951]],
np.testing.assert_allclose(opt_mu, [[-0.046381, -0.15578 ]],
rtol=1e-4)

0 comments on commit 858e490

Please sign in to comment.