Skip to content

Commit

Permalink
Merge pull request #147 from ndem0/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
ndem0 committed Apr 7, 2021
2 parents 281bfaf + 4a3a3e6 commit 5a708a7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ezyrb/pod.py
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions ezyrb/reducedordermodel.py
Expand Up @@ -3,6 +3,7 @@
"""
import numpy as np
import math
import copy
from scipy.spatial import Delaunay


Expand Down Expand Up @@ -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]))
Expand Down
17 changes: 11 additions & 6 deletions 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
Expand Down Expand Up @@ -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]])
17 changes: 11 additions & 6 deletions 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
Expand Down Expand Up @@ -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]])
9 changes: 9 additions & 0 deletions tests/test_reducedordermodel.py
Expand Up @@ -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()
Expand Down

0 comments on commit 5a708a7

Please sign in to comment.