From 75f1a6b10e4d98ab6b3ed661fd01e9d63bc2a3fe Mon Sep 17 00:00:00 2001 From: Farid Mohammadi <farid.mohammadi@iws.uni-stuttgart.de> Date: Wed, 3 Aug 2022 10:53:43 +0200 Subject: [PATCH] [surrogate] handle the case with all zero outputs. --- .../surrogate_models/surrogate_models.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/bayesvalidrox/surrogate_models/surrogate_models.py b/src/bayesvalidrox/surrogate_models/surrogate_models.py index 722221d74..5194a95b4 100644 --- a/src/bayesvalidrox/surrogate_models/surrogate_models.py +++ b/src/bayesvalidrox/surrogate_models/surrogate_models.py @@ -701,22 +701,11 @@ class MetaModel(): # The first column must be kept (For mean calculations) nnz_idx = np.nonzero(clf_poly.coef_)[0] - # if len(nnz_idx) == 0 or nnz_idx[0] != 0: - # nnz_idx = np.insert(np.nonzero(clf_poly.coef_)[0], 0, 0) - # # Remove the zero entries for Bases and PSI if need be - # if sparsity: - # sparse_basis_indices = basis_indices.toarray()[nnz_idx] - # else: - # sparse_basis_indices = basis_indices[nnz_idx] - # sparse_X = X[:, nnz_idx] - - # # Store the coefficients of the regression model - # clf_poly.fit(sparse_X, y) - # coeffs = clf_poly.coef_ - # This is for the case where all outputs are zero, thereby # all coefficients are zero - nnz_idx = np.nonzero(clf_poly.coef_)[0] + if len(nnz_idx) == 0 or nnz_idx[0] != 0: + nnz_idx = np.insert(np.nonzero(clf_poly.coef_)[0], 0, 0) + if sparsity: sparse_basis_indices = basis_indices.toarray()[nnz_idx] else: -- GitLab