diff --git a/smt/applications/tests/test_mixed_integer.py b/smt/applications/tests/test_mixed_integer.py index c368b413d..5cc20d162 100644 --- a/smt/applications/tests/test_mixed_integer.py +++ b/smt/applications/tests/test_mixed_integer.py @@ -1059,7 +1059,7 @@ def test_hierarchical_design_space_example_all_categorical_decreed(self): sm.train() y_s = sm.predict_values(Xt)[:, 0] _pred_RMSE = np.linalg.norm(y_s - Yt) / len(Yt) - self.assertLess(_pred_RMSE, 1e-3) + self.assertLess(_pred_RMSE, 1e-6) y_sv = sm.predict_variances(Xt)[:, 0] _var_RMSE = np.linalg.norm(y_sv) / len(Yt) self.assertLess(_var_RMSE, 1e-6) diff --git a/smt/surrogate_models/krg_based.py b/smt/surrogate_models/krg_based.py index ebd1d2e08..cf56906bd 100644 --- a/smt/surrogate_models/krg_based.py +++ b/smt/surrogate_models/krg_based.py @@ -481,6 +481,7 @@ def _new_train(self): _, ) = standardization(X2.copy(), y.copy()) D, _ = cross_distances(self.X2_norma) + D = np.abs(D) self.Lij, self.n_levels = cross_levels( X=self.X_train, ij=self.ij, design_space=self.design_space ) @@ -985,19 +986,7 @@ def _reduced_likelihood_function(self, theta): X2 - self.X2_offset ) / self.X2_scale dx, _ = cross_distances(self.X2_norma[str(self._lvl)]) - else: - X2, _, _ = self.design_space.unfold_x( - self.training_points[None][0][0] - ) - ( - self.X2_norma, - _, - self.X2_offset, - _, - self.X2_scale, - _, - ) = standardization(X2, self.training_points[None][0][1]) - dx, _ = cross_distances(self.X2_norma) + try: r = self._matrix_data_corr( corr=self.options["corr"], @@ -1012,6 +1001,7 @@ def _reduced_likelihood_function(self, theta): cat_kernel=self.options["categorical_kernel"], kplsk_second_loop=self.kplsk_second_loop, ).reshape(-1, 1) + if np.isnan(r).any(): return reduced_likelihood_function_value, par except FloatingPointError: @@ -1580,7 +1570,7 @@ def _predict_init(self, x, is_acting): if self.options["categorical_kernel"] == MixIntKernelType.CONT_RELAX: Xpred, _, _ = self.design_space.unfold_x(x) Xpred_norma = (Xpred - self.X2_offset) / self.X2_scale - dx = differences(Xpred_norma, Y=self.X2_norma.copy()) + dx = np.abs(differences(Xpred_norma, Y=self.X2_norma.copy())) if ( "n_comp" not in self.options._dict.keys() @@ -1598,8 +1588,10 @@ def _predict_init(self, x, is_acting): is_acting_y=self.is_acting_train, mixint_type=MixIntKernelType.GOWER, ) - if np.any(self.design_space.is_conditionally_acting): - dx[:, np.logical_not(self.unfolded_cat)] = dnum / self.X_scale + if np.any(self.design_space.is_conditionally_acting): + dx[:, np.logical_not(self.unfolded_cat)] = ( + dnum / self.X2_scale[np.logical_not(self.unfolded_cat)] + ) Lij, _ = cross_levels( X=x, ij=ij, design_space=self.design_space, y=self.X_train ) @@ -1680,7 +1672,6 @@ def _predict_values(self, x: np.ndarray, is_acting=None) -> np.ndarray: # Initialization if not (self.is_continuous): x, is_acting, n_eval, ij, Lij, dx = self._predict_init(x, is_acting) - r = self._matrix_data_corr( corr=self.options["corr"], design_space=self.design_space, diff --git a/smt/utils/kriging.py b/smt/utils/kriging.py index ee3b9835d..6b3a38214 100644 --- a/smt/utils/kriging.py +++ b/smt/utils/kriging.py @@ -302,9 +302,8 @@ def gower_componentwise_distances( Z_num = Z[:, ~cat_features] z_num_is_acting = z_is_acting[:, ~cat_features] num_is_decreed = is_decreed[~cat_features] - X_num_out = Z_num[x_index,] - Y_num_out = Z_num[y_index,] num_bounds = design_space.get_num_bounds()[~cat_features, :] + Z_scale = 1 if num_bounds.shape[0] > 0: Z_offset = num_bounds[:, 0] Z_max = num_bounds[:, 1] @@ -327,15 +326,7 @@ def gower_componentwise_distances( y, hierarchical_kernel, ) - D_num_out, _ = compute_D_num( - X_num_out, - Y_num_out, - x_num_is_acting, - y_num_is_acting, - num_is_decreed, - y, - hierarchical_kernel, - ) + D_num_out = D_num * Z_scale D = np.concatenate((D_cat, D_num), axis=1) * 0 D[:, np.logical_not(cat_features)] = D_num D[:, cat_features] = D_cat