From 1dcac61165a5e66021f7b286e26bdb24a77386ec Mon Sep 17 00:00:00 2001 From: faridm69 <faridmohammadi69@gmail.com> Date: Thu, 1 Oct 2020 15:51:42 +0200 Subject: [PATCH] [tests] made minor changes. --- .../surrogate_models/surrogate_models.py | 2 +- .../Test_AnalyticalFunction.py | 52 +++++++++---------- .../Co2BenchmarkTest/Test_CO2Benchmark.py | 6 +-- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/BayesValidRox/surrogate_models/surrogate_models.py b/BayesValidRox/surrogate_models/surrogate_models.py index 791b6dff8..89dc2fca3 100644 --- a/BayesValidRox/surrogate_models/surrogate_models.py +++ b/BayesValidRox/surrogate_models/surrogate_models.py @@ -988,7 +988,7 @@ class Metamodel: for deg in self.DegreeArray: if deg not in np.fromiter(self.allBasisIndices.keys(), dtype=float): - self.allBasisIndices = self.AutoVivification() + # self.allBasisIndices = self.AutoVivification() # Generate the polynomial basis indices for qidx, q in enumerate(self.q): self.allBasisIndices[str(deg)][str(q)] = self.PolyBasisIndices(degree=deg, q=q) diff --git a/BayesValidRox/tests/AnalyticalFunction/Test_AnalyticalFunction.py b/BayesValidRox/tests/AnalyticalFunction/Test_AnalyticalFunction.py index e90372b1f..43dce8c45 100755 --- a/BayesValidRox/tests/AnalyticalFunction/Test_AnalyticalFunction.py +++ b/BayesValidRox/tests/AnalyticalFunction/Test_AnalyticalFunction.py @@ -89,7 +89,7 @@ if __name__ == "__main__": # Select if you want to preserve the spatial/temporal depencencies MetaModelOpts.DimRedMethod = 'PCA' - MetaModelOpts.varPCAThreshold = 100 #99.999 + # MetaModelOpts.varPCAThreshold = 100 #99.999 # Select your metamodel method # 1) PCE (Polynomial Chaos Expansion) 2) GPE (Gaussian Process Emulator) @@ -104,16 +104,16 @@ if __name__ == "__main__": # 1)OLS: Ordinary Least Square 2)BRR: Bayesian Ridge Regression # 3)LARS: Least angle regression 4)ARD: Bayesian ARD Regression # 5)FastARD: Fast Bayesian ARD Regression - MetaModelOpts.RegMethod = 'ARD' + MetaModelOpts.RegMethod = 'FastARD' # 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 # metamodel. - MetaModelOpts.MinPceDegree = 3 - MetaModelOpts.MaxPceDegree = 8 + MetaModelOpts.MinPceDegree = 1 + MetaModelOpts.MaxPceDegree = 12 # q-quasi-norm 0<q<1 (default=1) - MetaModelOpts.q = 0.6 if ndim<5 else 0.8 #np.linspace(0.3,0.8, 3) + MetaModelOpts.q = 1.0 if ndim<5 else 0.85 #np.linspace(0.3,0.8, 3) # Print summary of the regression results # MetaModelOpts.DisplayFlag = True @@ -127,7 +127,7 @@ if __name__ == "__main__": # One-shot (normal) or Sequential Adaptive (sequential) Design MetaModelOpts.ExpDesign.Method = 'sequential' - NrofInitSamples = 50 #50 + NrofInitSamples = 2*ndim #50 MetaModelOpts.ExpDesign.NrSamples = NrofInitSamples # Sampling methods @@ -141,7 +141,7 @@ if __name__ == "__main__": # Sequential experimental design (needed only for sequential ExpDesign) MetaModelOpts.ExpDesign.NrofNewSample = 1 - MetaModelOpts.ExpDesign.MaxNSamples = 100 #150 + MetaModelOpts.ExpDesign.MaxNSamples = 150 #150 MetaModelOpts.ExpDesign.ModifiedLOOThreshold = 1e-16 # Defining the measurement error, if it's known a priori @@ -160,10 +160,10 @@ if __name__ == "__main__": # ------------------------------------------------ # ------- Sequential Design configuration -------- # ------------------------------------------------ - MetaModelOpts.adaptVerbose = True + # MetaModelOpts.adaptVerbose = True # 1) 'None' 2) 'equal' 3)'epsilon-decreasing' 4) 'adaptive' - MetaModelOpts.ExpDesign.TradeOffScheme = 'epsilon-decreasing' - # MetaModelOpts.ExpDesign.nReprications = 2 + MetaModelOpts.ExpDesign.TradeOffScheme = 'None' + # MetaModelOpts.ExpDesign.nReprications = 20 # -------- Exploration ------ #1)'Voronoi' 2)'random' 3)'latin_hypercube' 4)'LOOCV' 5)'dual annealing' MetaModelOpts.ExpDesign.ExploreMethod = 'random' @@ -172,22 +172,22 @@ if __name__ == "__main__": MetaModelOpts.ExpDesign.MaxFunItr = 200 # Use when 'Voronoi' or 'random' or 'latin_hypercube' chosen - MetaModelOpts.ExpDesign.NCandidate = 5000 #500 + MetaModelOpts.ExpDesign.NCandidate = 400 #5000 MetaModelOpts.ExpDesign.NrofCandGroups = 8 # -------- Exploitation ------ # 1)'BayesOptDesign' 2)'BayesActDesign' 3)'VarOptDesign' 4)'alphabetic' # 5)'Space-filling' - MetaModelOpts.ExpDesign.ExploitMethod = 'VarOptDesign' + MetaModelOpts.ExpDesign.ExploitMethod = 'BayesActDesign' # BayesOptDesign -> when data is available # 1)DKL (Kullback-Leibler Divergence) 2)DPP (D-Posterior-percision) # 3)APP (A-Posterior-percision) # ['DKL', 'BME', 'infEntropy'] - # MetaModelOpts.ExpDesign.UtilityFunction = 'DKL' + MetaModelOpts.ExpDesign.UtilityFunction = 'DKL' # VarBasedOptDesign -> when data is not available # Only with Vornoi >>> 1)Entropy 2)EIGF, 3)LOOCV - MetaModelOpts.ExpDesign.UtilityFunction = 'Entropy' #['EIGF', 'Entropy', 'LOOCV'] + # MetaModelOpts.ExpDesign.UtilityFunction = 'EIGF' #['EIGF', 'Entropy', 'LOOCV'] # alphabetic # 1)D-Opt (D-Optimality) 2)A-Opt (A-Optimality) @@ -233,9 +233,10 @@ if __name__ == "__main__": #===================================================== BayesOpts = BayesInference(PCEModel) BayesOpts.emulator = True + BayesOpts.PlotPostPred = True # BME Bootstrap - # BayesOpts.Bootstrap = False + # BayesOpts.Bootstrap = True # BayesOpts.BootstrapItrNr = 10 # BayesOpts.BootstrapNoise = 0.05 @@ -243,10 +244,6 @@ if __name__ == "__main__": BayesOpts.SamplingMethod = 'MCMC' BayesOpts.MCMCnwalkers = 100 # BayesOpts.MCMCnSteps = 500 - BayesOpts.MultiProcessMCMC = False - - - BayesOpts.PlotPostPred = True # ----- Define the discrepancy model ------- obsData = pd.DataFrame(Model.Observations, columns=Model.Output.Names) @@ -259,18 +256,20 @@ if __name__ == "__main__": BayesOpts.Discrepancy = DiscrepancyOpts - Bayes_PCE = BayesOpts.create_Inference() - sys.exit('STOP!!') + Bayes_PCE = BayesOpts.create_Inference() + # sys.exit('STOP!!') #===================================================== #====== Bayesian inference with Forward Model ======== #===================================================== - if ndim < 7: + if ndim < 7: + PCEModel.ModelObj.Name = 'OrigAnalyticFunc' + BayesOptsModel = BayesInference(PCEModel) BayesOptsModel.emulator = False - BayesOptsModel.NrofSamples = 100000 + BayesOptsModel.NrofSamples = 1000000 # Evaluation of forward model predictions for the samples used for PCEModel - BayesOptsModel.Samples = Bayes_PCE.Samples + # BayesOptsModel.Samples = Bayes_PCE.Samples # BayesOptsModel.SamplingMethod = 'MCMC' # Bootstrap for BME calulations @@ -279,7 +278,7 @@ if __name__ == "__main__": BayesOptsModel.BootstrapNoise = 0.05 BayesOptsModel.PlotPostDist = True - BayesOptsModel.PlotPostPred = True + BayesOptsModel.PlotPostPred = False # ----- Define the discrepancy model ------- @@ -292,8 +291,7 @@ if __name__ == "__main__": BayesOptsModel.Discrepancy = DiscrepancyOpts Bayes_Model = BayesOptsModel.create_Inference() - - + #===================================================== #============== Save class objects ================= #===================================================== diff --git a/BayesValidRox/tests/Co2BenchmarkTest/Test_CO2Benchmark.py b/BayesValidRox/tests/Co2BenchmarkTest/Test_CO2Benchmark.py index 0f831e63b..e42f82f13 100755 --- a/BayesValidRox/tests/Co2BenchmarkTest/Test_CO2Benchmark.py +++ b/BayesValidRox/tests/Co2BenchmarkTest/Test_CO2Benchmark.py @@ -122,9 +122,9 @@ if __name__ == "__main__": # error (or the highest score=1-LOO)estimator is chosen as the final # metamodel. MetaModelOpts.MinPceDegree = 1 - MetaModelOpts.MaxPceDegree = 4 + MetaModelOpts.MaxPceDegree = 10 # q-quasi-norm 0<q<1 (default=1) - MetaModelOpts.q = 1.0 + MetaModelOpts.q = 0.8 # Print summary of the regression results # MetaModelOpts.DisplayFlag = True @@ -138,7 +138,7 @@ if __name__ == "__main__": # One-shot (normal) or Sequential Adaptive (sequential) Design MetaModelOpts.ExpDesign.Method = 'sequential' - initNSamples = 2 #20 + initNSamples = 5 #20 MetaModelOpts.ExpDesign.NrSamples = initNSamples # Sampling methods -- GitLab