diff --git a/ezyrb/pod.py b/ezyrb/pod.py index eb6ea7b0..b6712641 100755 --- a/ezyrb/pod.py +++ b/ezyrb/pod.py @@ -87,7 +87,7 @@ def _truncation(self, X, s): :return: the number of modes :rtype: int """ - if self.rank is 0: + if self.rank == 0: omega = lambda x: 0.56 * x**3 - 0.95 * x**2 + 1.82 * x + 1.43 beta = np.divide(*sorted(X.shape)) tau = np.median(s) * omega(beta) diff --git a/ezyrb/reducedordermodel.py b/ezyrb/reducedordermodel.py index c10fbc6c..3f69ee9c 100644 --- a/ezyrb/reducedordermodel.py +++ b/ezyrb/reducedordermodel.py @@ -3,6 +3,7 @@ """ import numpy as np import math +import copy from scipy.spatial import Delaunay @@ -74,8 +75,8 @@ def loo_error(self, norm=np.linalg.norm): remaining_index = db_range[:] remaining_index.remove(j) new_db = self.database[remaining_index] - rom = type(self)(new_db, self.reduction, - self.approximation).fit() + rom = type(self)(new_db, copy.deepcopy(self.reduction), + copy.deepcopy(self.approximation)).fit() error[j] = norm(self.database.snapshots[j] - rom.predict(self.database.parameters[j])) diff --git a/tests/test_k_neighbors_regressor.py b/tests/test_k_neighbors_regressor.py index b50fe3bd..05e70bc6 100644 --- a/tests/test_k_neighbors_regressor.py +++ b/tests/test_k_neighbors_regressor.py @@ -1,4 +1,5 @@ import numpy as np +import warnings from unittest import TestCase from ezyrb import KNeighborsRegressor, Database, POD, ReducedOrderModel @@ -58,12 +59,16 @@ def test_with_db_predict(self): def test_wrong1(self): # wrong number of params - with self.assertRaises(Exception): - reg = KNeighborsRegressor() - reg.fit([[1, 2], [6,], [8, 9]], [[1, 0], [20, 5], [8, 6]]) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) + with self.assertRaises(Exception): + reg = KNeighborsRegressor() + reg.fit([[1, 2], [6,], [8, 9]], [[1, 0], [20, 5], [8, 6]]) def test_wrong2(self): # wrong number of values - with self.assertRaises(Exception): - reg = KNeighborsRegressor() - reg.fit([[1, 2], [6,], [8, 9]], [[20, 5], [8, 6]]) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) + with self.assertRaises(Exception): + reg = KNeighborsRegressor() + reg.fit([[1, 2], [6,], [8, 9]], [[20, 5], [8, 6]]) diff --git a/tests/test_radius_neighbors_regressor.py b/tests/test_radius_neighbors_regressor.py index ea7b6ca2..b017f7be 100644 --- a/tests/test_radius_neighbors_regressor.py +++ b/tests/test_radius_neighbors_regressor.py @@ -1,4 +1,5 @@ import numpy as np +import warnings from unittest import TestCase from ezyrb import RadiusNeighborsRegressor, POD, Database, ReducedOrderModel @@ -58,12 +59,16 @@ def test_with_db_predict(self): def test_wrong1(self): # wrong number of params - with self.assertRaises(Exception): - reg = RadiusNeighborsRegressor() - reg.fit([[1, 2], [6,], [8, 9]], [[1, 0], [20, 5], [8, 6]]) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) + with self.assertRaises(Exception): + reg = RadiusNeighborsRegressor() + reg.fit([[1, 2], [6,], [8, 9]], [[1, 0], [20, 5], [8, 6]]) def test_wrong2(self): # wrong number of values - with self.assertRaises(Exception): - reg = RadiusNeighborsRegressor() - reg.fit([[1, 2], [6,], [8, 9]], [[20, 5], [8, 6]]) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=np.VisibleDeprecationWarning) + with self.assertRaises(Exception): + reg = RadiusNeighborsRegressor() + reg.fit([[1, 2], [6,], [8, 9]], [[20, 5], [8, 6]]) diff --git a/tests/test_reducedordermodel.py b/tests/test_reducedordermodel.py index f20ed730..7b7a1848 100644 --- a/tests/test_reducedordermodel.py +++ b/tests/test_reducedordermodel.py @@ -56,6 +56,15 @@ def test_loo_error(self): np.array([421.299091, 344.571787, 48.711501, 300.490491]), rtol=1e-4) + def test_loo_error_singular_values(self): + pod = POD() + rbf = RBF() + db = Database(param, snapshots.T) + rom = ROM(db, pod, rbf).fit() + valid_svalues = rom.reduction.singular_values + rom.loo_error() + np.testing.assert_allclose(valid_svalues, rom.reduction.singular_values) + def test_optimal_mu(self): pod = POD() rbf = RBF()