Skip to content

Commit

Permalink
Fix noisy categorical PLS bug (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Saves authored Jul 10, 2023
1 parent e4e35ce commit 899b7d0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
40 changes: 40 additions & 0 deletions smt/applications/tests/test_mixed_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,46 @@ def test_mixed_CR_2D(self):

self.assertEqual(np.shape(y), (105, 1))

def test_mixed_CR_PLS_noisy_2D(self):
xt = np.array([[0, 5], [2, -1], [4, 0.5]])
yt = np.array([[0.0], [1.0], [1.5]])
design_space = DesignSpace(
[
CategoricalVariable(["0.0", "1.0", " 2.0", "3.0", "4.0"]),
FloatVariable(-5, 5),
]
)
# Surrogate
sm = MixedIntegerKrigingModel(
surrogate=KPLS(
n_comp=1,
eval_noise=True,
design_space=design_space,
theta0=[1e-2],
categorical_kernel=MixIntKernelType.CONT_RELAX,
corr="abs_exp",
),
)
sm.set_training_values(xt, yt)
sm.train()

# DOE for validation
x = np.linspace(0, 4, 5)
x2 = np.linspace(-5, 5, 21)
x1 = []
for element in itertools.product(x, x2):
x1.append(np.array(element))
x_pred = np.array(x1)

y = sm.predict_values(x_pred)
yvar = sm.predict_variances(x_pred)

# prediction are correct on known points
self.assertTrue(np.abs(np.sum(np.array([y[20], y[50], y[95]]) - yt)) < 1e-6)
self.assertTrue(np.abs(np.sum(np.array([yvar[20], yvar[50], yvar[95]]))) < 1e-6)

self.assertEqual(np.shape(y), (105, 1))

def test_mixed_homo_gaussian_2D(self):
xt = np.array([[0, 5], [2, -1], [4, 0.5]])
yt = np.array([[0.0], [1.0], [1.5]])
Expand Down
4 changes: 2 additions & 2 deletions smt/surrogate_models/krg_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,8 @@ def _reduced_likelihood_function(self, theta):
if self.options["use_het_noise"]:
noise = self.optimal_noise
if self.options["eval_noise"] and not self.options["use_het_noise"]:
theta = tmp_var[0 : self.D.shape[1]]
noise = tmp_var[self.D.shape[1] :]
theta = tmp_var[0:-1]
noise = tmp_var[-1]
if not (self.is_continuous):
dx = self.D
r = self._matrix_data_corr(
Expand Down

0 comments on commit 899b7d0

Please sign in to comment.