Skip to content

Commit

Permalink
rename of compute_rms_error() to compute_relative_error()
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine-Averland committed Dec 16, 2024
1 parent a8ab303 commit 61f93b9
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 129 deletions.
14 changes: 7 additions & 7 deletions smt/applications/tests/test_mfk.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from smt.applications.mfk import MFK, NestedLHS
from smt.problems import Sphere, TensorProduct
from smt.sampling_methods import LHS, FullFactorial
from smt.utils.misc import compute_rms_error
from smt.utils.misc import compute_relative_error
from smt.utils.silence import Silence
from smt.utils.sm_test_case import SMTestCase

Expand Down Expand Up @@ -84,8 +84,8 @@ def test_mfk(self):
with Silence():
sm.train()

t_error = compute_rms_error(sm)
e_error = compute_rms_error(sm, xe, ye)
t_error = compute_relative_error(sm)
e_error = compute_relative_error(sm, xe, ye)

self.assert_error(t_error, 0.0, 1)
self.assert_error(e_error, 0.0, 1)
Expand Down Expand Up @@ -123,10 +123,10 @@ def test_mfk_derivs(self):
with Silence():
sm.train()

t_error = compute_rms_error(sm)
e_error = compute_rms_error(sm, xe, ye)
e_error0 = compute_rms_error(sm, xe, dye[0], 0)
e_error1 = compute_rms_error(sm, xe, dye[1], 1)
t_error = compute_relative_error(sm)
e_error = compute_relative_error(sm, xe, ye)
e_error0 = compute_relative_error(sm, xe, dye[0], 0)
e_error1 = compute_relative_error(sm, xe, dye[1], 1)

if print_output:
print(
Expand Down
6 changes: 3 additions & 3 deletions smt/applications/tests/test_mfk_1fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from smt.applications.mfk import MFK
from smt.problems import TensorProduct
from smt.sampling_methods import LHS
from smt.utils.misc import compute_rms_error
from smt.utils.misc import compute_relative_error
from smt.utils.silence import Silence
from smt.utils.sm_test_case import SMTestCase

Expand Down Expand Up @@ -53,8 +53,8 @@ def test_mfk_1fidelity(self):
with Silence():
sm.train()

t_error = compute_rms_error(sm)
e_error = compute_rms_error(sm, xv, yv)
t_error = compute_relative_error(sm)
e_error = compute_relative_error(sm, xv, yv)

self.assert_error(t_error, 0.0, 3e-3)
self.assert_error(e_error, 0.0, 3e-3)
Expand Down
10 changes: 5 additions & 5 deletions smt/applications/tests/test_mfkpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from smt.applications.mfkpls import MFKPLS
from smt.problems import Sphere, TensorProduct
from smt.sampling_methods import LHS, FullFactorial
from smt.utils.misc import compute_rms_error
from smt.utils.misc import compute_relative_error
from smt.utils.silence import Silence
from smt.utils.sm_test_case import SMTestCase

Expand Down Expand Up @@ -79,8 +79,8 @@ def test_mfkpls(self):
with Silence():
sm.train()

t_error = compute_rms_error(sm)
e_error = compute_rms_error(sm, xe, ye)
t_error = compute_relative_error(sm)
e_error = compute_relative_error(sm, xe, ye)

self.assert_error(t_error, 0.0, 1.5)
self.assert_error(e_error, 0.0, 1.5)
Expand Down Expand Up @@ -127,8 +127,8 @@ def test_mfkpls_derivs(self):
with Silence():
sm.train()

e_error0 = compute_rms_error(sm, xe, dye[0], 0)
e_error1 = compute_rms_error(sm, xe, dye[1], 1)
e_error0 = compute_relative_error(sm, xe, dye[0], 0)
e_error1 = compute_relative_error(sm, xe, dye[1], 1)

self.assert_error(e_error0, 0.0, 1e-1)
self.assert_error(e_error1, 0.0, 1e-1)
Expand Down
14 changes: 7 additions & 7 deletions smt/applications/tests/test_mfkplsk.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from smt.applications.mfkplsk import MFKPLSK
from smt.problems import Sphere, TensorProduct
from smt.sampling_methods import LHS, FullFactorial
from smt.utils.misc import compute_rms_error
from smt.utils.misc import compute_relative_error
from smt.utils.silence import Silence
from smt.utils.sm_test_case import SMTestCase

Expand Down Expand Up @@ -79,8 +79,8 @@ def test_mfkplsk(self):
with Silence():
sm.train()

t_error = compute_rms_error(sm)
e_error = compute_rms_error(sm, xe, ye)
t_error = compute_relative_error(sm)
e_error = compute_relative_error(sm, xe, ye)

self.assert_error(t_error, 0.0, 1.5)
self.assert_error(e_error, 0.0, 1.5)
Expand Down Expand Up @@ -130,10 +130,10 @@ def test_mfkplsk_derivs(self):
with Silence():
sm.train()

_t_error = compute_rms_error(sm)
_e_error = compute_rms_error(sm, xe, ye)
e_error0 = compute_rms_error(sm, xe, dye[0], 0)
e_error1 = compute_rms_error(sm, xe, dye[1], 1)
_t_error = compute_relative_error(sm)
_e_error = compute_relative_error(sm, xe, ye)
e_error0 = compute_relative_error(sm, xe, dye[0], 0)
e_error1 = compute_relative_error(sm, xe, dye[1], 1)

self.assert_error(e_error0, 0.0, 1e-1)
self.assert_error(e_error1, 0.0, 1e-1)
Expand Down
12 changes: 6 additions & 6 deletions smt/applications/tests/test_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from smt.problems import Branin, LpNorm
from smt.sampling_methods import LHS, FullFactorial
from smt.surrogate_models import RMTB, RMTC
from smt.utils.misc import compute_rms_error
from smt.utils.misc import compute_relative_error
from smt.utils.sm_test_case import SMTestCase


Expand Down Expand Up @@ -64,7 +64,7 @@ def test_1d_50(self):
xe = np.random.sample(self.ne)
ye = self.function_test_1d(xe)

rms_error = compute_rms_error(moe, xe, ye)
rms_error = compute_relative_error(moe, xe, ye)
self.assert_error(rms_error, 0.0, 3e-1)

self.assertRaises(RuntimeError, lambda: moe.predict_variances(xe))
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_1d_50_var(self):
xe = np.random.sample(self.ne)
ye = self.function_test_1d(xe)

rms_error = compute_rms_error(moe, xe, ye)
rms_error = compute_relative_error(moe, xe, ye)
self.assert_error(rms_error, 0.0, 3e-1)

moe.predict_variances(xe)
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_1d_50_surrogate_model(self):
xe = np.random.sample(self.ne)
ye = self.function_test_1d(xe)

rms_error = compute_rms_error(moe, xe, ye)
rms_error = compute_relative_error(moe, xe, ye)
self.assert_error(rms_error, 0.0, 3e-1)

self.assertRaises(RuntimeError, lambda: moe.predict_variances(xe))
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_norm1_2d_200(self):
xe = sampling(self.ne)
ye = prob(xe)

rms_error = compute_rms_error(moe, xe, ye)
rms_error = compute_relative_error(moe, xe, ye)
self.assert_error(rms_error, 0.0, 1e-1)

if TestMOE.plot:
Expand Down Expand Up @@ -273,7 +273,7 @@ def test_branin_2d_200(self):
xe = sampling(self.ne)
ye = prob(xe)

rms_error = compute_rms_error(moe, xe, ye)
rms_error = compute_relative_error(moe, xe, ye)
self.assert_error(rms_error, 0.0, 1e-1)

if TestMOE.plot:
Expand Down
4 changes: 2 additions & 2 deletions smt/applications/tests/test_vfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from smt.problems import WaterFlow, WaterFlowLFidelity
from smt.sampling_methods import LHS
from smt.utils.misc import compute_rms_error
from smt.utils.misc import compute_relative_error
from smt.utils.silence import Silence
from smt.utils.sm_test_case import SMTestCase

Expand Down Expand Up @@ -111,7 +111,7 @@ def test_vfm(self):
)

# Prediction of the validation points
rms_error = compute_rms_error(vfm, xtest, ytest)
rms_error = compute_relative_error(vfm, xtest, ytest)
self.assert_error(rms_error, 0.0, 3e-1)

@staticmethod
Expand Down
46 changes: 23 additions & 23 deletions smt/examples/run_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from smt.problems import NdimRobotArm, Sphere
from smt.sampling_methods import LHS
from smt.surrogate_models import GEKPLS, KPLS, KPLSK, KRG, LS, QP, DesignSpace
from smt.utils.misc import compute_rms_error
from smt.utils.misc import compute_relative_error

try:
from smt.surrogate_models import IDW, RBF, RMTB, RMTC
Expand Down Expand Up @@ -65,7 +65,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("LS, err: " + str(compute_rms_error(t, xtest, ytest)))
print("LS, err: " + str(compute_relative_error(t, xtest, ytest)))

if plot_status:
k, m = 0, 0
Expand Down Expand Up @@ -95,7 +95,7 @@
"LS, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand All @@ -119,7 +119,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("QP, err: " + str(compute_rms_error(t, xtest, ytest)))
print("QP, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(4, 3)
Expand Down Expand Up @@ -148,7 +148,7 @@
"QP, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand All @@ -173,7 +173,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("Kriging, err: " + str(compute_rms_error(t, xtest, ytest)))
print("Kriging, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(4, 3)
Expand Down Expand Up @@ -202,7 +202,7 @@
"Kriging, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand Down Expand Up @@ -230,7 +230,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("KPLS, err: " + str(compute_rms_error(t, xtest, ytest)))
print("KPLS, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(4, 3)
Expand Down Expand Up @@ -258,7 +258,7 @@
"KPLS, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand All @@ -285,7 +285,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("KPLS + abs exp, err: " + str(compute_rms_error(t, xtest, ytest)))
print("KPLS + abs exp, err: " + str(compute_relative_error(t, xtest, ytest)))


########### The KPLSK model
Expand All @@ -299,7 +299,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("KPLSK, err: " + str(compute_rms_error(t, xtest, ytest)))
print("KPLSK, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(4, 3)
Expand Down Expand Up @@ -328,7 +328,7 @@
"KPLSK, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand Down Expand Up @@ -364,7 +364,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("GEKPLS1, err: " + str(compute_rms_error(t, xtest, ytest)))
print("GEKPLS1, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(4, 3)
Expand Down Expand Up @@ -393,7 +393,7 @@
"GEKPLS1, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand Down Expand Up @@ -429,7 +429,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("GEKPLS2, err: " + str(compute_rms_error(t, xtest, ytest)))
print("GEKPLS2, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(4, 3)
Expand Down Expand Up @@ -458,7 +458,7 @@
"GEKPLS2, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand All @@ -482,7 +482,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("IDW, err: " + str(compute_rms_error(t, xtest, ytest)))
print("IDW, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
plt.figure()
plt.plot(ytest, ytest, "-.")
Expand All @@ -501,7 +501,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("RBF, err: " + str(compute_rms_error(t, xtest, ytest)))
print("RBF, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(4, 3)
Expand Down Expand Up @@ -529,7 +529,7 @@
"RBF, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand Down Expand Up @@ -585,7 +585,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("RMTB, err: " + str(compute_rms_error(t, xtest, ytest)))
print("RMTB, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(3, 2)
Expand Down Expand Up @@ -616,7 +616,7 @@
"RMTB, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand Down Expand Up @@ -648,7 +648,7 @@

# Prediction of the validation points
y = t.predict_values(xtest)
print("RMTC, err: " + str(compute_rms_error(t, xtest, ytest)))
print("RMTC, err: " + str(compute_relative_error(t, xtest, ytest)))
if plot_status:
k, m = 0, 0
f, axarr = plt.subplots(3, 2)
Expand Down Expand Up @@ -679,7 +679,7 @@
"RMTC, err of the "
+ str(i)
+ "-th derivative: "
+ str(compute_rms_error(t, xtest, ydtest[:, i], kx=i))
+ str(compute_relative_error(t, xtest, ydtest[:, i], kx=i))
)

if plot_status:
Expand Down
Loading

0 comments on commit 61f93b9

Please sign in to comment.