From 6048baadae87abd5721b2487a4b52cdc3e008b51 Mon Sep 17 00:00:00 2001
From: Farid Mohammadi <farid.mohammadi@iws.uni-stuttgart.de>
Date: Mon, 12 Sep 2022 09:21:49 +0200
Subject: [PATCH] [surrogate] remove float16 to preserve the correct
 computation.

---
 .../surrogate_models/eval_rec_rule.py         |  2 +-
 .../surrogate_models/surrogate_models.py      | 19 ++++++++++---------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/bayesvalidrox/surrogate_models/eval_rec_rule.py b/src/bayesvalidrox/surrogate_models/eval_rec_rule.py
index 730a3818d..b583c7eb2 100644
--- a/src/bayesvalidrox/surrogate_models/eval_rec_rule.py
+++ b/src/bayesvalidrox/surrogate_models/eval_rec_rule.py
@@ -183,7 +183,7 @@ def eval_univ_basis(x, max_deg, poly_types, apoly_coeffs=None):
     """
     # Initilize the output array
     n_samples, n_params = x.shape
-    univ_vals = np.zeros((n_samples, n_params, max_deg+1), dtype=np.float16)
+    univ_vals = np.zeros((n_samples, n_params, max_deg+1))
 
     for i in range(n_params):
 
diff --git a/src/bayesvalidrox/surrogate_models/surrogate_models.py b/src/bayesvalidrox/surrogate_models/surrogate_models.py
index e82f7b3f9..341ecf566 100644
--- a/src/bayesvalidrox/surrogate_models/surrogate_models.py
+++ b/src/bayesvalidrox/surrogate_models/surrogate_models.py
@@ -197,7 +197,7 @@ class MetaModel():
         # Define an array containing the degrees
         n_samples, ndim = CollocationPoints.shape
         self.deg_array = self.__select_degree(ndim, n_samples)
-        print("deg_array:", self.deg_array)
+
         # Generate all basis indices
         self.allBasisIndices = self.auto_vivification()
         for deg in self.deg_array:
@@ -305,7 +305,7 @@ class MetaModel():
                 else:
                     self.univ_p_val = univ_p_val[b_indices]
                     if parallel and (not fast_bootstrap or b_i == 0):
-                        out = Parallel(n_jobs=-1, backend='loky')(
+                        out = Parallel(n_jobs=-1, backend='multiprocessing')(
                             delayed(self.adaptive_regression)(X_train_b,
                                                               target[:, idx],
                                                               idx)
@@ -601,7 +601,7 @@ class MetaModel():
                 )
 
         # Preallocate the Psi matrix for performance
-        psi = np.ones((n_samples, n_terms), dtype=np.float16)
+        psi = np.ones((n_samples, n_terms))
         # Assemble the Psi matrix
         for m in range(basis_indices.shape[1]):
             aa = np.where(basis_indices[:, m] > 0)[0]
@@ -748,7 +748,7 @@ class MetaModel():
 
         """
 
-        NrSamples, n_params = ED_X.shape
+        n_samples, n_params = ED_X.shape
         # Initialization
         qAllCoeffs, AllCoeffs = {}, {}
         qAllIndices_Sparse, AllIndices_Sparse = {}, {}
@@ -967,8 +967,8 @@ class MetaModel():
         # Build the projection matrix
         PsiTPsi = np.dot(psi_sparse.T, psi_sparse)
 
-        if np.linalg.cond(PsiTPsi) > 1e-12 and \
-           np.linalg.cond(PsiTPsi) < 1/sys.float_info.epsilon:
+        if np.linalg.cond(PsiTPsi) > 1e-12: #and \
+           # np.linalg.cond(PsiTPsi) < 1/sys.float_info.epsilon:
             # faster
             M = sp.linalg.solve(PsiTPsi,
                                 sp.sparse.eye(PsiTPsi.shape[0]).toarray())
@@ -1199,6 +1199,7 @@ class MetaModel():
             samples,
             method='user'
             )
+        # print(samples)
 
         # Compute univariate bases for the given samples
         if self.meta_model_type.lower() != 'gpe':
@@ -1223,8 +1224,8 @@ class MetaModel():
             std_pred = {}
             for output, values in model_dict.items():
 
-                mean = np.empty((len(samples), len(values)), dtype=np.float16)
-                std = np.empty((len(samples), len(values)), dtype=np.float16)
+                mean = np.empty((len(samples), len(values)))
+                std = np.empty((len(samples), len(values)))
                 idx = 0
                 for in_key, InIdxValues in values.items():
 
@@ -1235,7 +1236,7 @@ class MetaModel():
                         y_mean, y_std = gp.predict(X_T, return_std=True)
 
                     else:
-                        # Perdiction with PCE or pcekriging
+                        # Perdiction with PCE
                         # Assemble Psi matrix
                         basis = self.basis_dict[f'b_{b_i+1}'][output][in_key]
                         psi = self.create_psi(basis, univ_p_val)
-- 
GitLab