From 3e4da441bba0f7f9461f11fe3dc944079bd686c1 Mon Sep 17 00:00:00 2001
From: Farid Mohammadi <farid.mohammadi@iws.uni-stuttgart.de>
Date: Wed, 19 Oct 2022 16:23:27 +0200
Subject: [PATCH] [examples] update scripts.

---
 examples/OHagan-function/test_OHagan.py        | 18 ++++++------------
 examples/borehole/borehole.py                  | 11 +++++++++--
 examples/borehole/test_borehole.py             | 17 ++++++-----------
 examples/ishigami/test_ishigami.py             | 11 ++---------
 .../model-comparison/test_model_comparison.py  | 17 +----------------
 examples/pollution/test_pollution.py           |  3 +--
 examples/pollution/test_valid_pollution.py     |  6 ++----
 7 files changed, 27 insertions(+), 56 deletions(-)

diff --git a/examples/OHagan-function/test_OHagan.py b/examples/OHagan-function/test_OHagan.py
index 4715ecc52..2fc629d34 100644
--- a/examples/OHagan-function/test_OHagan.py
+++ b/examples/OHagan-function/test_OHagan.py
@@ -1,7 +1,8 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 """
-This test deals with the surrogate modeling of a Ishigami function.
+This test deals with the surrogate modeling of O'Hagan function with 15
+parameters.
 
 You will see how to:
     Check the quality of your regression model
@@ -30,6 +31,7 @@ sys.path.append("../../src/bayesvalidrox/")
 from pylink.pylink import PyLinkForwardModel
 from surrogate_models.inputs import Input
 from surrogate_models.surrogate_models import MetaModel
+from surrogate_models.meta_model_engine import MetaModelEngine
 from post_processing.post_processing import PostProcessing
 from bayes_inference.bayes_inference import BayesInference
 from bayes_inference.discrepancy import Discrepancy
@@ -87,11 +89,6 @@ if __name__ == "__main__":
     # 9)EBL: Emperical Bayesian Learning
     MetaModelOpts.pce_reg_method = 'FastARD'
 
-    # Bootstraping
-    # 1) normal 2) fast
-    MetaModelOpts.bootstrap_method = 'fast'
-    MetaModelOpts.n_bootstrap_itrs = 1#00
-
     # Specify the max degree to be compared by the adaptive algorithm:
     # The degree with the lowest Leave-One-Out cross-validation (LOO)
     # error (or the highest score=1-LOO)estimator is chosen as the final
@@ -99,7 +96,7 @@ if __name__ == "__main__":
     MetaModelOpts.pce_deg = 7
 
     # q-quasi-norm 0<q<1 (default=1)
-    MetaModelOpts.pce_q_norm = 0.5
+    MetaModelOpts.pce_q_norm = 0.65
 
     # Print summary of the regression results
     # MetaModelOpts.verbose = True
@@ -116,10 +113,10 @@ if __name__ == "__main__":
     # Sampling methods
     # 1) random 2) latin_hypercube 3) sobol 4) halton 5) hammersley 6) korobov
     # 7) chebyshev(FT) 8) grid(FT) 9) nested_grid(FT) 10)user
-    MetaModelOpts.ExpDesign.sampling_method = 'user'
+    MetaModelOpts.ExpDesign.sampling_method = 'latin_hypercube'
 
     # Provide the experimental design object with a hdf5 file
-    MetaModelOpts.ExpDesign.hdf5_file = 'ExpDesign_OHagan_orig.hdf5'
+    # MetaModelOpts.ExpDesign.hdf5_file = 'ExpDesign_OHagan_orig.hdf5'
 
     # Sequential experimental design (needed only for sequential ExpDesign)
     MetaModelOpts.ExpDesign.n_new_samples = 1
@@ -166,9 +163,6 @@ if __name__ == "__main__":
         'Z': np.load("data/valid_outputs.npy")
         }
     # >>>>>>>>>>>>>>>>>>>>>> Build Surrogate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-    # Adaptive sparse arbitrary polynomial chaos expansion
-    # PCEModel = MetaModelOpts.create_metamodel()
-    from surrogate_models.meta_model_engine import MetaModelEngine
     meta_model_engine = MetaModelEngine(MetaModelOpts)
     meta_model_engine.run()
     PCEModel = meta_model_engine.MetaModel
diff --git a/examples/borehole/borehole.py b/examples/borehole/borehole.py
index 43dd71f21..b2a0dcd4a 100644
--- a/examples/borehole/borehole.py
+++ b/examples/borehole/borehole.py
@@ -1,9 +1,16 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 """
-Created on Mon Nov 19 08:56:21 2018
+Author: Farid Mohammadi, M.Sc.
+E-Mail: farid.mohammadi@iws.uni-stuttgart.de
+Department of Hydromechanics and Modelling of Hydrosystems (LH2)
+Institute for Modelling Hydraulic and Environmental Systems (IWS), University
+of Stuttgart, www.iws.uni-stuttgart.de/lh2/
+Pfaffenwaldring 61
+70569 Stuttgart
+
+Created on Mon Sep 12 2022
 
-@author: farid
 """
 import numpy as np
 
diff --git a/examples/borehole/test_borehole.py b/examples/borehole/test_borehole.py
index 3097b78bc..e28e9a30f 100644
--- a/examples/borehole/test_borehole.py
+++ b/examples/borehole/test_borehole.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 """
-This test deals with the surrogate modeling of a Ishigami function.
+This test deals with the surrogate modeling of a Borehole function.
 
 You will see how to:
     Check the quality of your regression model
@@ -15,7 +15,7 @@ of Stuttgart, www.iws.uni-stuttgart.de/lh2/
 Pfaffenwaldring 61
 70569 Stuttgart
 
-Created on Wed Jul 10 2019
+Created on Sep 12 2022
 
 """
 
@@ -33,6 +33,8 @@ from surrogate_models.surrogate_models import MetaModel
 from post_processing.post_processing import PostProcessing
 from bayes_inference.bayes_inference import BayesInference
 from bayes_inference.discrepancy import Discrepancy
+from surrogate_models.meta_model_engine import MetaModelEngine
+
 import matplotlib
 matplotlib.use('agg')
 
@@ -127,11 +129,6 @@ if __name__ == "__main__":
     # 9)EBL: Emperical Bayesian Learning
     MetaModelOpts.pce_reg_method = 'OMP'
 
-    # Bootstraping
-    # 1) normal 2) fast
-    MetaModelOpts.bootstrap_method = 'fast'
-    MetaModelOpts.n_bootstrap_itrs = 1#00
-
     # Specify the max degree to be compared by the adaptive algorithm:
     # The degree with the lowest Leave-One-Out cross-validation (LOO)
     # error (or the highest score=1-LOO)estimator is chosen as the final
@@ -163,7 +160,7 @@ if __name__ == "__main__":
 
     # Sequential experimental design (needed only for sequential ExpDesign)
     MetaModelOpts.ExpDesign.n_new_samples = 1
-    MetaModelOpts.ExpDesign.n_max_samples = 300  # 150
+    MetaModelOpts.ExpDesign.n_max_samples = 300
     MetaModelOpts.ExpDesign.mod_LOO_threshold = 1e-16
 
     # ------------------------------------------------
@@ -206,9 +203,7 @@ if __name__ == "__main__":
         'flow rate [m$^3$/yr]': np.load("data/valid_outputs.npy")
         }
     # >>>>>>>>>>>>>>>>>>>>>> Build Surrogate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-    # Adaptive sparse arbitrary polynomial chaos expansion
-    # PCEModel = MetaModelOpts.create_metamodel()
-    from surrogate_models.meta_model_engine import MetaModelEngine
+    # Use MetaModelEngine for sequential experimental design
     meta_model_engine = MetaModelEngine(MetaModelOpts)
     meta_model_engine.run()
     PCEModel = meta_model_engine.MetaModel
diff --git a/examples/ishigami/test_ishigami.py b/examples/ishigami/test_ishigami.py
index c7db9c4bf..313ad3828 100644
--- a/examples/ishigami/test_ishigami.py
+++ b/examples/ishigami/test_ishigami.py
@@ -30,6 +30,7 @@ sys.path.append("../../src/bayesvalidrox/")
 from pylink.pylink import PyLinkForwardModel
 from surrogate_models.inputs import Input
 from surrogate_models.surrogate_models import MetaModel
+from surrogate_models.meta_model_engine import MetaModelEngine
 from post_processing.post_processing import PostProcessing
 from bayes_inference.bayes_inference import BayesInference
 from bayes_inference.discrepancy import Discrepancy
@@ -94,11 +95,6 @@ if __name__ == "__main__":
     # 9)EBL: Emperical Bayesian Learning
     MetaModelOpts.pce_reg_method = 'BCS'
 
-    # Bootstraping
-    # 1) normal 2) fast
-    MetaModelOpts.bootstrap_method = 'fast'
-    MetaModelOpts.n_bootstrap_itrs = 100
-
     # Specify the max degree to be compared by the adaptive algorithm:
     # The degree with the lowest Leave-One-Out cross-validation (LOO)
     # error (or the highest score=1-LOO)estimator is chosen as the final
@@ -117,7 +113,7 @@ if __name__ == "__main__":
     MetaModelOpts.add_ExpDesign()
 
     # One-shot (normal) or Sequential Adaptive (sequential) Design
-    MetaModelOpts.ExpDesign.method = 'sequential'
+    MetaModelOpts.ExpDesign.method = 'normal'
     MetaModelOpts.ExpDesign.n_init_samples = 50
 
     # Sampling methods
@@ -171,9 +167,6 @@ if __name__ == "__main__":
     MetaModelOpts.valid_samples = np.load("data/valid_samples.npy")
     MetaModelOpts.valid_model_runs = {'Z': np.load("data/valid_outputs.npy")}
     # >>>>>>>>>>>>>>>>>>>>>> Build Surrogate <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
-    # Adaptive sparse arbitrary polynomial chaos expansion
-    # PCEModel = MetaModelOpts.create_metamodel()
-    from surrogate_models.meta_model_engine import MetaModelEngine
     meta_model_engine = MetaModelEngine(MetaModelOpts)
     meta_model_engine.run()
     PCEModel = meta_model_engine.MetaModel
diff --git a/examples/model-comparison/test_model_comparison.py b/examples/model-comparison/test_model_comparison.py
index b353cca28..d5f523871 100644
--- a/examples/model-comparison/test_model_comparison.py
+++ b/examples/model-comparison/test_model_comparison.py
@@ -254,22 +254,7 @@ if __name__ == "__main__":
         "cosine": NL4_MetaModel
         }
 
-    # Option I: MCMC inference method
-    mcmc_params = {
-        'n_steps': 1e5,
-        'n_walkers': 30,
-        'multiprocessing': False,
-        'verbose': False
-        }
-    opts_mcmc = {
-        "inference_method": "MCMC",
-        "mcmc_params": mcmc_params,
-        "Discrepancy": DiscrepancyOpts,
-        "emulator": True,
-        "plot_post_pred": True
-        }
-
-    # Option II: BME Bootstrap
+    # BME Bootstrap optuions
     opts_bootstrap = {
         "bootstrap": True,
         "n_samples": 10000,
diff --git a/examples/pollution/test_pollution.py b/examples/pollution/test_pollution.py
index cbb897481..f2de52e2c 100644
--- a/examples/pollution/test_pollution.py
+++ b/examples/pollution/test_pollution.py
@@ -21,7 +21,6 @@ import numpy as np
 import pandas as pd
 import joblib
 
-
 # import bayesvalidrox
 # Add BayesValidRox path
 import sys
@@ -142,7 +141,7 @@ if __name__ == "__main__":
 
     # One-shot (normal) or Sequential Adaptive (sequential) Design
     MetaModelOpts.ExpDesign.method = 'normal'
-    MetaModelOpts.ExpDesign.n_init_samples = 150  # 5*ndim
+    MetaModelOpts.ExpDesign.n_init_samples = 150
 
     # Sampling methods
     # 1) random 2) latin_hypercube 3) sobol 4) halton 5) hammersley 6) korobov
diff --git a/examples/pollution/test_valid_pollution.py b/examples/pollution/test_valid_pollution.py
index a19e7b6a0..e2aacbe5d 100644
--- a/examples/pollution/test_valid_pollution.py
+++ b/examples/pollution/test_valid_pollution.py
@@ -18,10 +18,8 @@ Created on Fri Aug 9 2019
 """
 
 import numpy as np
-import pandas as pd
 import joblib
 
-
 # import bayesvalidrox
 # Add BayesValidRox path
 import sys
@@ -129,7 +127,7 @@ 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 = np.arange(6)
+    MetaModelOpts.pce_deg = 6
 
     # q-quasi-norm 0<q<1 (default=1)
     # MetaModelOpts.pce_q_norm = 0.75
@@ -142,7 +140,7 @@ if __name__ == "__main__":
 
     # One-shot (normal) or Sequential Adaptive (sequential) Design
     MetaModelOpts.ExpDesign.method = 'normal'
-    MetaModelOpts.ExpDesign.n_init_samples = 150  # 5*ndim
+    MetaModelOpts.ExpDesign.n_init_samples = 150
 
     # Sampling methods
     # 1) random 2) latin_hypercube 3) sobol 4) halton 5) hammersley 6) korobov
-- 
GitLab