From b7761ac301f7299fd1acb2f8fce1c3e7cd6cf8a7 Mon Sep 17 00:00:00 2001
From: kohlhaasrebecca <rebecca.kohlhaas@outlook.com>
Date: Fri, 2 Aug 2024 10:27:25 +0200
Subject: [PATCH] Small fixes from renaming parameters

---
 .../example_analytical_function.py             | 18 +++++++++---------
 .../post_processing/post_processing.py         |  2 +-
 src/bayesvalidrox/surrogate_models/engine.py   |  3 ++-
 .../surrogate_models/input_space.py            |  1 +
 .../surrogate_models/polynomial_chaos.py       |  1 +
 5 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/examples/analytical-function/example_analytical_function.py b/examples/analytical-function/example_analytical_function.py
index 30ff3fac4..ceed4a5d6 100644
--- a/examples/analytical-function/example_analytical_function.py
+++ b/examples/analytical-function/example_analytical_function.py
@@ -106,7 +106,7 @@ if __name__ == "__main__":
     # 7)OMP: Orthogonal Matching Pursuit
     # 8)VBL: Variational Bayesian Learning
     # 9)EBL: Emperical Bayesian Learning
-    MetaModelOpts.pce_reg_method = 'FastARD'
+    MetaModelOpts._pce_reg_method = 'FastARD'
 
     # Bootstraping
     # 1) normal 2) fast
@@ -117,10 +117,10 @@ if __name__ == "__main__":
     # The degree with the lowest Leave-One-Out cross-validation (LOO)
     # error (or the highest score=1-LOO)estimator is chosen as the final
     # metamodel. pce_deg accepts degree as a scalar or a range.
-    MetaModelOpts.pce_deg = 12
+    MetaModelOpts._pce_deg = 12
 
     # q-quasi-norm 0<q<1 (default=1)
-    MetaModelOpts.pce_q_norm = 0.85 if ndim < 5 else 0.5
+    MetaModelOpts._pce_q_norm = 0.85 if ndim < 5 else 0.5
 
     # Print summary of the regression results
     # MetaModelOpts.verbose = True
@@ -239,17 +239,17 @@ if __name__ == "__main__":
     # Compute the moments and compare with the Monte-Carlo reference
     # TODO: generalize the moment calculation
     #if MetaModelOpts.meta_model_type != 'GPE':
-    #    PostPCE.plot_moments()
+    PostPCE.plot_moments()
 
     # Plot the evolution of the KLD,BME, and Modified LOOCV error
-    if MetaModelOpts.ExpDesign.method == 'sequential':
-        refBME_KLD = np.load("data/refBME_KLD_"+str(ndim)+".npy")
-        PostPCE.plot_seq_design_diagnostics(refBME_KLD)
+    #if MetaModelOpts.ExpDesign.method == 'sequential':
+    #    refBME_KLD = np.load("data/refBME_KLD_"+str(ndim)+".npy")
+    #    PostPCE.plot_seq_design_diagnostics(refBME_KLD)
 
     # Plot the sobol indices
     # TODO: generalize this by using moment calculation(?)
-    if MetaModelOpts.meta_model_type != 'GPE':
-        total_sobol = PostPCE.sobol_indices()
+    #if MetaModelOpts.meta_model_type != 'GPE':
+    total_sobol = PostPCE.sobol_indices()
 
     # =====================================================
     # ========  Bayesian inference with Emulator ==========
diff --git a/src/bayesvalidrox/post_processing/post_processing.py b/src/bayesvalidrox/post_processing/post_processing.py
index eaffdff27..361a2c5f6 100644
--- a/src/bayesvalidrox/post_processing/post_processing.py
+++ b/src/bayesvalidrox/post_processing/post_processing.py
@@ -573,7 +573,7 @@ class PostProcessing:
         PCEModel = self.MetaModel
         basis_dict = PCEModel._basis_dict
         coeffs_dict = PCEModel._coeffs_dict
-        n_params = PCEModel.n_params
+        n_params = PCEModel.ndim
         max_order = np.max(PCEModel._pce_deg)
         sobol_cell_b = {}
         total_sobol_b = {}
diff --git a/src/bayesvalidrox/surrogate_models/engine.py b/src/bayesvalidrox/surrogate_models/engine.py
index 92e5dbf66..f2c4eafa8 100644
--- a/src/bayesvalidrox/surrogate_models/engine.py
+++ b/src/bayesvalidrox/surrogate_models/engine.py
@@ -105,8 +105,9 @@ class Engine:
 
         # Prepare X samples 
         # For training the surrogate use ExpDesign.X_tr, ExpDesign.X is for the model to run on 
+        # TODO: set to some more general value, chech how much this is needed!
         if self.emulator:
-            maxdeg = np.max(MetaModel.pce_deg)
+            maxdeg = np.max(MetaModel._pce_deg)
         else:
             maxdeg = 1
         ExpDesign.generate_ED(ExpDesign.n_init_samples,
diff --git a/src/bayesvalidrox/surrogate_models/input_space.py b/src/bayesvalidrox/surrogate_models/input_space.py
index b6a675fd3..1a28c7e1c 100644
--- a/src/bayesvalidrox/surrogate_models/input_space.py
+++ b/src/bayesvalidrox/surrogate_models/input_space.py
@@ -42,6 +42,7 @@ class InputSpace:
         self.poly_types = None
         self.prior_space = None
         self.raw_data = None
+        self.n_init_samples = None
 
         # Init 
         self.check_valid_inputs()
diff --git a/src/bayesvalidrox/surrogate_models/polynomial_chaos.py b/src/bayesvalidrox/surrogate_models/polynomial_chaos.py
index a704c8c9c..0f921e052 100644
--- a/src/bayesvalidrox/surrogate_models/polynomial_chaos.py
+++ b/src/bayesvalidrox/surrogate_models/polynomial_chaos.py
@@ -244,6 +244,7 @@ class PCE(MetaModel):
         self.parallel = parallel
         
         # TODO: other option: rebuild every time
+        self.CollocationPoints = X
         if self._deg_array is None:
             self.build_metamodel(n_init_samples=X.shape[1])
 
-- 
GitLab