Skip to content

Commit

Permalink
if not(self.is_continuous): ... else ... modified by: if self.is_cont…
Browse files Browse the repository at this point in the history
…inuous: ... else ...
  • Loading branch information
RemyCharayron committed Oct 11, 2023
1 parent d9c3afd commit 2a95131
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions smt/applications/mfk.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
)
from smt.utils.misc import standardization

# from smt.utils.design_space import unfold_x

from smt.surrogate_models.krg_based import compute_n_param


Expand Down Expand Up @@ -243,7 +241,7 @@ def _new_train_init(self):
X = self.X
y = self.y

if not (self.is_continuous):
if self.is_continuous:
(
_,
_,
Expand All @@ -252,9 +250,7 @@ def _new_train_init(self):
self.X_scale,
self.y_std,
) = standardization(np.concatenate(xt, axis=0), np.concatenate(yt, axis=0))
_, self.cat_features = compute_X_cont(
np.concatenate(xt, axis=0), self.design_space
)
self.cat_features = [False] * np.shape(np.concatenate(xt, axis=0))[1]
else:
(
_,
Expand All @@ -264,7 +260,9 @@ def _new_train_init(self):
self.X_scale,
self.y_std,
) = standardization(np.concatenate(xt, axis=0), np.concatenate(yt, axis=0))
self.cat_features = [False] * np.shape(np.concatenate(xt, axis=0))[1]
_, self.cat_features = compute_X_cont(
np.concatenate(xt, axis=0), self.design_space
)

nlevel = self.nlvl

Expand Down Expand Up @@ -478,7 +476,13 @@ def _predict_intermediate_values(self, X, lvl, descale=True):
f0 = self._regression_types[self.options["poly"]](X)

beta = self.optimal_par[0]["beta"]
if not (self.is_continuous):
if self.is_continuous:
dx = self._differences(X, Y=self.X_norma_all[0])
d = self._componentwise_distance(dx)
r_ = self._correlation_types[self.options["corr"]](
self.optimal_theta[0], d
).reshape(n_eval, self.nt_all[0])
else:
_, x_is_acting = self.design_space.correct_get_acting(X_usc)
_, y_is_acting = self.design_space.correct_get_acting(self.X[0])
dx = gower_componentwise_distances(
Expand Down Expand Up @@ -520,12 +524,6 @@ def _predict_intermediate_values(self, X, lvl, descale=True):
cat_kernel=self.options["categorical_kernel"],
x=X_usc,
).reshape(n_eval, self.nt_all[0])
else:
dx = self._differences(X, Y=self.X_norma_all[0])
d = self._componentwise_distance(dx)
r_ = self._correlation_types[self.options["corr"]](
self.optimal_theta[0], d
).reshape(n_eval, self.nt_all[0])

gamma = self.optimal_par[0]["gamma"]

Expand All @@ -537,7 +535,13 @@ def _predict_intermediate_values(self, X, lvl, descale=True):

g = self._regression_types[self.options["rho_regr"]](X)

if not (self.is_continuous):
if self.is_continuous:
dx = self._differences(X, Y=self.X_norma_all[i])
d = self._componentwise_distance(dx)
r_ = self._correlation_types[self.options["corr"]](
self.optimal_theta[i], d
).reshape(n_eval, self.nt_all[i])
else:
_, x_is_acting = self.design_space.correct_get_acting(X_usc)
_, y_is_acting = self.design_space.correct_get_acting(self.X[i])
dx = gower_componentwise_distances(
Expand Down Expand Up @@ -580,13 +584,6 @@ def _predict_intermediate_values(self, X, lvl, descale=True):
x=X_usc,
).reshape(n_eval, self.nt_all[i])

else:
dx = self._differences(X, Y=self.X_norma_all[i])
d = self._componentwise_distance(dx)
r_ = self._correlation_types[self.options["corr"]](
self.optimal_theta[i], d
).reshape(n_eval, self.nt_all[i])

f = np.vstack((g.T * mu[:, i - 1], f0.T))
beta = self.optimal_par[i]["beta"]
gamma = self.optimal_par[i]["gamma"]
Expand Down Expand Up @@ -669,7 +666,13 @@ def predict_variances_all_levels(self, X, is_acting=None):
beta = self.optimal_par[0]["beta"]
Ft = solve_triangular(C, F, lower=True)

if not (self.is_continuous):
if self.is_continuous:
dx = self._differences(X, Y=self.X_norma_all[0])
d = self._componentwise_distance(dx)
r_ = self._correlation_types[self.options["corr"]](
self.optimal_theta[0], d
).reshape(n_eval, self.nt_all[0])
else:
_, y_is_acting = self.design_space.correct_get_acting(self.X[0])
_, x_is_acting = self.design_space.correct_get_acting(X)
dx = gower_componentwise_distances(
Expand Down Expand Up @@ -711,12 +714,6 @@ def predict_variances_all_levels(self, X, is_acting=None):
cat_kernel=self.options["categorical_kernel"],
x=X,
).reshape(n_eval, self.nt_all[0])
else:
dx = self._differences(X, Y=self.X_norma_all[0])
d = self._componentwise_distance(dx)
r_ = self._correlation_types[self.options["corr"]](
self.optimal_theta[0], d
).reshape(n_eval, self.nt_all[0])

gamma = self.optimal_par[0]["gamma"]

Expand Down Expand Up @@ -744,7 +741,13 @@ def predict_variances_all_levels(self, X, is_acting=None):

g = self._regression_types[self.options["rho_regr"]](X)

if not (self.is_continuous):
if self.is_continuous:
dx = self._differences(X, Y=self.X_norma_all[i])
d = self._componentwise_distance(dx)
r_ = self._correlation_types[self.options["corr"]](
self.optimal_theta[i], d
).reshape(n_eval, self.nt_all[i])
else:
_, y_is_acting = self.design_space.correct_get_acting(self.X[i])
_, x_is_acting = self.design_space.correct_get_acting(X)
dx = gower_componentwise_distances(
Expand Down Expand Up @@ -786,12 +789,7 @@ def predict_variances_all_levels(self, X, is_acting=None):
cat_kernel=self.options["categorical_kernel"],
x=X,
).reshape(n_eval, self.nt_all[i])
else:
dx = self._differences(X, Y=self.X_norma_all[i])
d = self._componentwise_distance(dx)
r_ = self._correlation_types[self.options["corr"]](
self.optimal_theta[i], d
).reshape(n_eval, self.nt_all[i])


f = np.vstack((g.T * mu[:, i - 1], f0.T))

Expand Down

0 comments on commit 2a95131

Please sign in to comment.