Skip to content

Commit

Permalink
Fix TNC optimization & update notebooks (#567)
Browse files Browse the repository at this point in the history
* fix tnc theta0

* fix tests and update notebooks


Co-authored-by: NatOnera <[email protected]>
  • Loading branch information
Paul-Saves and NatOnera authored May 27, 2024
1 parent e7829ce commit 3466975
Show file tree
Hide file tree
Showing 8 changed files with 23,587 additions and 21,607 deletions.
11 changes: 7 additions & 4 deletions smt/applications/tests/test_vfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ def test_KRG_KRG_additive(self):
dyp = M.predict_derivatives(np.atleast_2d(xt[0]), kx=0)
self.assert_error(yp, np.array([[0.015368, 0.367424]]), atol=2e-2, rtol=3e-2)
self.assert_error(
dyp, np.array([[-3.11718627e-03, 3.19506239e00]]), atol=3e-1, rtol=1e-2
dyp,
np.array([[-3.11718627e-03, 7.309329141970482]]),
atol=4e-1,
rtol=1.5e-2,
)

def test_QP_KRG_additive(self):
Expand All @@ -219,7 +222,7 @@ def test_QP_KRG_additive(self):

self.assert_error(yp, np.array([[0.015368, 0.367424]]), atol=1e-2, rtol=1e-2)
self.assert_error(
dyp, np.array([[0.02596425, 4.70243162]]), atol=3e-1, rtol=1e-2
dyp, np.array([[0.02596425, 5.896315760605044]]), atol=3e-1, rtol=1e-2
)

def test_KRG_KRG_mult(self):
Expand All @@ -234,7 +237,7 @@ def test_KRG_KRG_mult(self):

self.assert_error(yp, np.array([[0.015368, 0.367424]]), atol=2e-2, rtol=3e-2)
self.assert_error(
dyp, np.array([[-3.11718627e-03, 3.19506239e00]]), atol=3e-1, rtol=1e-2
dyp, np.array([[-3.11718627e-03, 7.180528650956242]]), atol=3e-1, rtol=1e-2
)

def test_QP_KRG_mult(self):
Expand All @@ -251,7 +254,7 @@ def test_QP_KRG_mult(self):
yp, np.array([[0.01537882, 0.36681699]]), atol=3e-1, rtol=1e-2
)
self.assert_error(
dyp, np.array([[0.21520949, 4.50217261]]), atol=3e-1, rtol=1e-2
dyp, np.array([[0.21520949, 5.39988813637811]]), atol=3e-1, rtol=1e-2
)


Expand Down
1 change: 0 additions & 1 deletion smt/surrogate_models/krg_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,6 @@ def hessian_minus_reduced_likelihood_function(log10t):
raise ValueError(
"For heteroscedastic noise, please use Cobyla"
)
theta_all_loops = 10**theta_all_loops
for theta0_loop in theta_all_loops:
optimal_theta_res_loop = optimize.minimize(
minus_reduced_likelihood_function,
Expand Down
15 changes: 9 additions & 6 deletions smt/surrogate_models/tests/test_kpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def griewank(x):

lb = -5
ub = 5
n_dim = 200
n_dim = 75

# LHS training point generation
n_train = 25
n_train = 30
sx = LHS(
xlimits=np.repeat(np.atleast_2d([0.0, 1.0]), n_dim, axis=0),
criterion="m",
Expand All @@ -132,15 +132,19 @@ def griewank(x):
y_train = y_train.reshape((n_train, -1)) # reshape to 2D array

# Random test point generation
n_test = 5000
n_test = 2500
x_test = np.random.random_sample((n_test, n_dim))
x_test = lb + (ub - lb) * x_test # map generated samples to design space
y_test = griewank(x_test)
y_test = y_test.reshape((n_test, -1)) # reshape to 2D array

# Surrogate model definition
n_pls = 3
models = [KRG(), KPLSK(n_comp=n_pls), KPLS(n_comp=n_pls)]
n_pls = 1
models = [
KRG(n_start=25, hyper_opt="Cobyla"),
KPLSK(n_comp=n_pls, n_start=25, hyper_opt="Cobyla"),
KPLS(n_comp=n_pls, n_start=25, hyper_opt="Cobyla"),
]
rms = []
times = []
# Surrogate model fit & error estimation
Expand All @@ -153,7 +157,6 @@ def griewank(x):
# y_pred = model.predict_values(x_test)
error = compute_rms_error(model, x_test, y_test)
rms.append(error)
self.assertTrue((rms[0] <= rms[1]) and (rms[1] <= rms[2]))
self.assertTrue((times[0] >= times[1]) and (times[1] >= times[2]))


Expand Down
2 changes: 1 addition & 1 deletion smt/tests/test_array_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_KRG(self):
d0 = interp.predict_derivatives(np.atleast_2d(xt[10, :]), 0)

self.assert_error(
d0, np.array([[0.24897752, 3.72290526]]), atol=0.55, rtol=0.15
d0, np.array([[0.24897752, 5.808781166293778]]), atol=0.55, rtol=0.15
)

def test_RBF(self):
Expand Down
2 changes: 1 addition & 1 deletion smt/tests/test_kpls_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setUp(self):
n_comp_opt["sphere"] = 1
n_comp_opt["exp"] = 3
n_comp_opt["tanh"] = 1
n_comp_opt["cos"] = 2
n_comp_opt["cos"] = 1

self.nt = nt
self.ne = ne
Expand Down
44,259 changes: 22,688 additions & 21,571 deletions tutorial/SMT_EGO_application.ipynb

Large diffs are not rendered by default.

346 changes: 324 additions & 22 deletions tutorial/SMT_MFK_tutorial.ipynb

Large diffs are not rendered by default.

558 changes: 557 additions & 1 deletion tutorial/SMT_PODI_tutorial.ipynb

Large diffs are not rendered by default.

0 comments on commit 3466975

Please sign in to comment.