Skip to content

Commit

Permalink
Merge 4966d75 into 8fc434b
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Saves committed Mar 1, 2024
2 parents 8fc434b + 4966d75 commit b3cb582
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 51 deletions.
14 changes: 10 additions & 4 deletions smt/applications/mfk.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ def _new_train_init(self):
_, self.cat_features = compute_X_cont(
np.concatenate(xt, axis=0), self.design_space
)
self.X_offset[self.cat_features] *= 0
self.X_scale[self.cat_features] *= 0
self.X_scale[self.cat_features] += 1

nlevel = self.nlvl

Expand Down Expand Up @@ -761,7 +764,9 @@ def predict_variances_all_levels(self, X, is_acting=None):
sigma2 = self.optimal_par[0]["sigma2"] / self.y_std**2
MSE[:, 0] = sigma2 * (
# 1 + self.optimal_noise_all[0] - (r_t ** 2).sum(axis=0) + (u_ ** 2).sum(axis=0)
1 - (r_t**2).sum(axis=0) + (u_**2).sum(axis=0)
1
- (r_t**2).sum(axis=0)
+ (u_**2).sum(axis=0)
)

# Calculate recursively kriging variance at level i
Expand Down Expand Up @@ -845,16 +850,17 @@ def predict_variances_all_levels(self, X, is_acting=None):
Q_ = (np.dot((yt - np.dot(Ft, beta)).T, yt - np.dot(Ft, beta)))[0, 0]
MSE[:, i] = (
# sigma2_rho * MSE[:, i - 1]
+Q_
/ (2 * (self.nt_all[i] - p - q))
+Q_ / (2 * (self.nt_all[i] - p - q))
# * (1 + self.optimal_noise_all[i] - (r_t ** 2).sum(axis=0))
* (1 - (r_t**2).sum(axis=0))
+ sigma2 * (u_**2).sum(axis=0)
)
else:
MSE[:, i] = sigma2 * (
# 1 + self.optimal_noise_all[i] - (r_t ** 2).sum(axis=0) + (u_ ** 2).sum(axis=0)
1 - (r_t**2).sum(axis=0) + (u_**2).sum(axis=0)
1
- (r_t**2).sum(axis=0)
+ (u_**2).sum(axis=0)
) # + sigma2_rho * MSE[:, i - 1]
if self.options["propagate_uncertainty"]:
MSE[:, i] = MSE[:, i] + sigma2_rho * MSE[:, i - 1]
Expand Down
6 changes: 3 additions & 3 deletions smt/applications/mixed_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ def __init__(
)
and self._surrogate.options["categorical_kernel"] is None
):
self._surrogate.options[
"categorical_kernel"
] = MixIntKernelType.HOMO_HSPHERE
self._surrogate.options["categorical_kernel"] = (
MixIntKernelType.HOMO_HSPHERE
)
warnings.warn(
"Using MixedIntegerSurrogateModel integer model with Continuous Relaxation is not supported. \
Switched to homoscedastic hypersphere kernel instead."
Expand Down
18 changes: 9 additions & 9 deletions smt/applications/tests/test_mixed_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,26 +1316,26 @@ def test_hierarchical_variables_NN(self):
sm.predict_values(
np.array(
[
[0, -1, -2, 8, 0, 2, 0, 0],
[1, -1, -2, 16, 1, 2, 1, 0],
[2, -1, -2, 32, 2, 2, 1, -2],
[0, -1, -2, 0, 0, 2, 0, 0],
[1, -1, -2, 1, 1, 2, 1, 0],
[2, -1, -2, 2, 2, 2, 1, -2],
]
)
)[:, 0],
sm.predict_values(
np.array(
[
[0, -1, -2, 8, 0, 2, 10, 10],
[1, -1, -2, 16, 1, 2, 1, 10],
[2, -1, -2, 32, 2, 2, 1, -2],
[0, -1, -2, 0, 0, 2, 10, 10],
[1, -1, -2, 1, 1, 2, 1, 10],
[2, -1, -2, 2, 2, 2, 1, -2],
]
)
)[:, 0],
)
self.assertTrue(
np.linalg.norm(
sm.predict_values(np.array([[0, -1, -2, 8, 0, 2, 0, 0]]))
- sm.predict_values(np.array([[0, -1, -2, 8, 0, 12, 10, 10]]))
sm.predict_values(np.array([[0, -1, -2, 0, 0, 2, 0, 0]]))
- sm.predict_values(np.array([[0, -1, -2, 0, 0, 12, 10, 10]]))
)
> 1e-8
)
Expand Down Expand Up @@ -1789,7 +1789,7 @@ def test_compound_hetero_noise_auto(self):
)

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]])
xt = np.array([[0, 5, 0], [2, 4, 3], [4, -1, 2], [2, 0.5, 1]])
yt = np.array([[0.0], [3], [1.0], [1.5]])
design_space = DesignSpace(
[
Expand Down
8 changes: 5 additions & 3 deletions smt/surrogate_models/genn.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ def _train(self):
beta1=self.options["beta1"],
beta2=self.options["beta2"],
epochs=self.options["num_epochs"],
batch_size=None
if self.options["mini_batch_size"] < 0
else self.options["mini_batch_size"],
batch_size=(
None
if self.options["mini_batch_size"] < 0
else self.options["mini_batch_size"]
),
max_iter=self.options["num_iterations"],
is_backtracking=self.options["is_backtracking"],
is_verbose=self.options["is_print"],
Expand Down
20 changes: 10 additions & 10 deletions smt/surrogate_models/krg_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,16 +718,16 @@ def _matrix_data_corr(
d_cont = d[:, np.logical_not(cat_features)]
if self.options["corr"] == "squar_sin_exp":
if self.options["categorical_kernel"] != MixIntKernelType.GOWER:
theta_cont_features[
-len([self.design_space.is_cat_mask]) :
] = np.atleast_2d(
np.array([True] * len([self.design_space.is_cat_mask]))
).T
theta_cat_features[1][
-len([self.design_space.is_cat_mask]) :
] = np.atleast_2d(
np.array([False] * len([self.design_space.is_cat_mask]))
).T
theta_cont_features[-len([self.design_space.is_cat_mask]) :] = (
np.atleast_2d(
np.array([True] * len([self.design_space.is_cat_mask]))
).T
)
theta_cat_features[1][-len([self.design_space.is_cat_mask]) :] = (
np.atleast_2d(
np.array([False] * len([self.design_space.is_cat_mask]))
).T
)

theta_cont = theta[theta_cont_features[:, 0]]
r_cont = _correlation_types[corr](theta_cont, d_cont)
Expand Down
8 changes: 4 additions & 4 deletions smt/surrogate_models/tests/test_surrogate_model_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_mixed_gower_krg(self):
sm.train()

# DOE for validation
x = np.linspace(0, 5, 5)
x = np.linspace(0, 4, 5)
y = sm.predict_values(x)

plt.plot(xt, yt, "o", label="data")
Expand Down Expand Up @@ -725,9 +725,9 @@ def df_dx(x):
genn.options["hidden_layer_sizes"] = [6, 6]
genn.options["alpha"] = 0.1
genn.options["lambd"] = 0.1
genn.options[
"gamma"
] = 1.0 # 1 = gradient-enhanced on, 0 = gradient-enhanced off
genn.options["gamma"] = (
1.0 # 1 = gradient-enhanced on, 0 = gradient-enhanced off
)
genn.options["num_iterations"] = 1000
genn.options["is_backtracking"] = True
genn.options["is_normalize"] = False
Expand Down
Loading

0 comments on commit b3cb582

Please sign in to comment.