Skip to content

Commit

Permalink
Merge 81f4dd5 into d978ccd
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Saves committed Feb 10, 2024
2 parents d978ccd + 81f4dd5 commit c29a812
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
76 changes: 76 additions & 0 deletions smt/applications/tests/test_mixed_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,82 @@ def test_mixed_homo_hyp_3D_PLS_cate(self):
self.assertTrue((np.abs(np.sum(np.array(sm.predict_values(xt) - yt)))) < 1e-6)
self.assertTrue((np.abs(np.sum(np.array(sm.predict_variances(xt) - 0)))) < 1e-6)

def test_compound_hetero_noise_auto(self):
xt1 = np.array([[0, 0.0], [0, 2.0], [0, 4.0]])
xt2 = np.array([[1, 0.0], [1, 2.0], [1, 3.0]])
xt3 = np.array([[2, 1.0], [2, 2.0], [2, 4.0]])

xt = np.concatenate((xt1, xt2, xt3), axis=0)
xt[:, 1] = xt[:, 1].astype(np.float64)
yt1 = np.array([0.0, 9.0, 16.0])
yt2 = np.array([0.0, -4, -13.0])
yt3 = np.array([-10, 3, 11.0])
yt = np.concatenate((yt1, yt2, yt3), axis=0)

design_space = DesignSpace(
[
CategoricalVariable(["Blue", "Red", "Green"]),
# OrdinalVariable([0,1,2]),
FloatVariable(0, 4),
]
)

# Surrogate
sm = MixedIntegerKrigingModel(
surrogate=KRG(
design_space=design_space,
categorical_kernel=MixIntKernelType.COMPOUND_SYMMETRY,
theta0=[1e-1],
corr="squar_exp",
n_start=20,
eval_noise=True,
# noise0 = [1.0,0.1,10,0.01,1.0,0.1,10,0.01,10],
use_het_noise=True,
hyper_opt="Cobyla",
),
)
sm.set_training_values(xt, yt)
sm.train()

# DOE for validation
n = 100
x_cat1 = []
x_cat2 = []
x_cat3 = []

for i in range(n):
x_cat1.append(0)
x_cat2.append(1)
x_cat3.append(2)

x_cont = np.linspace(0.0, 4.0, n)
x1 = np.concatenate(
(np.asarray(x_cat1).reshape(-1, 1), x_cont.reshape(-1, 1)), axis=1
)
x2 = np.concatenate(
(np.asarray(x_cat2).reshape(-1, 1), x_cont.reshape(-1, 1)), axis=1
)
x3 = np.concatenate(
(np.asarray(x_cat3).reshape(-1, 1), x_cont.reshape(-1, 1)), axis=1
)

y1 = sm.predict_values(x1)
y2 = sm.predict_values(x2)
y3 = sm.predict_values(x3)

# estimated variance
s2_1 = sm.predict_variances(x1)
s2_2 = sm.predict_variances(x2)
s2_3 = sm.predict_variances(x3)

self.assertEqual(
np.array_equal(
np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]),
sm._surrogate.optimal_noise,
),
True,
)

def test_mixed_homo_gaussian_3D_ord_cate(self):
xt = np.array([[0.5, 0, 5], [2, 3, 4], [5, 2, -1], [-2, 4, 0.5]])
yt = np.array([[0.0], [3], [1.0], [1.5]])
Expand Down
14 changes: 12 additions & 2 deletions smt/surrogate_models/krg_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,18 @@ def _new_train(self):
if not self.options["eval_noise"]:
self.optimal_noise = np.array(self.options["noise0"])
elif self.options["use_het_noise"]:
X = self.training_points[None][0][0]
y = self.training_points[None][0][1]
# Center and scale X and y
(
self.X_norma,
self.y_norma,
self.X_offset,
self.y_mean,
self.X_scale,
self.y_std,
) = standardization(X, y)

# hetGP works with unique design variables when noise variance are not given
(
self.X_norma,
Expand Down Expand Up @@ -871,7 +883,6 @@ def _reduced_likelihood_function(self, theta):
noise = tmp_var[-1]
if not (self.is_continuous):
dx = self.D

if self.options["categorical_kernel"] == MixIntKernelType.CONT_RELAX:
if "MFK" in self.name:
if (
Expand Down Expand Up @@ -920,7 +931,6 @@ def _reduced_likelihood_function(self, theta):
r = self._correlation_types[self.options["corr"]](theta, self.D).reshape(
-1, 1
)

R = np.eye(self.nt) * (1.0 + nugget + noise)
R[self.ij[:, 0], self.ij[:, 1]] = r[:, 0]
R[self.ij[:, 1], self.ij[:, 0]] = r[:, 0]
Expand Down

0 comments on commit c29a812

Please sign in to comment.