From f18ea5aab2285232fbf7393b5afa738a75a2e7b5 Mon Sep 17 00:00:00 2001 From: kohlhaasrebecca <rebecca.kohlhaas@outlook.com> Date: Thu, 2 May 2024 14:30:51 +0200 Subject: [PATCH] Add _y_hat_prev for adaptive tradeoff scheme --- .../example_analytical_function_testSequential.py | 3 ++- src/bayesvalidrox/surrogate_models/engine.py | 1 + src/bayesvalidrox/surrogate_models/sequential_design.py | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/analytical-function/example_analytical_function_testSequential.py b/examples/analytical-function/example_analytical_function_testSequential.py index dcbf7dcc8..9abb57ef6 100644 --- a/examples/analytical-function/example_analytical_function_testSequential.py +++ b/examples/analytical-function/example_analytical_function_testSequential.py @@ -238,6 +238,7 @@ if __name__ == "__main__": - exploration = 'Voronoi' creates mismatching numbers of candidates and weights - exploration = 'loocv' needs MetaModel.create_ModelError, which does not exist - exploration = 'dual annealing' restricted in what it allows as exploitation methods + - tradeoff = 'adaptive' perhaps not possible in the first AL iteration? The following combinations are running through: - BayesActDesign quite fast @@ -253,7 +254,7 @@ if __name__ == "__main__": tradeoff_schemes = [None, 'equal', 'epsilon-decreasing', 'adaptive'] #sampling_method = ['random', 'latin-hypercube', 'sobol', 'halton', # 'hammersley', 'chebyshev', 'grid'] - exploration_schemes = ['Voronoi', 'random', 'latin-hypercube', 'LOOCV', + exploration_schemes = ['Voronoi', 'global_mc', 'random', 'latin-hypercube', 'LOOCV', 'dual annealing'] exploration_schemes = ['random', 'dual annealing'] exploitation_schemes = ['BayesOptDesign', 'BayesActDesign', 'VarOptDesign', diff --git a/src/bayesvalidrox/surrogate_models/engine.py b/src/bayesvalidrox/surrogate_models/engine.py index 54f6bd888..08b3a05d1 100644 --- a/src/bayesvalidrox/surrogate_models/engine.py +++ b/src/bayesvalidrox/surrogate_models/engine.py @@ -488,6 +488,7 @@ class Engine: # self.MetaModel.ExpDesignFlag = 'sequential' # TODO: this is only a fix, remove as soon as possible to # avoid circular dependencies! + self.SeqDesign._y_hat_prev = self._y_hat_prev if self.ExpDesign.exploit_method.lower() == 'bayesoptdesign': self.SeqDesign.engine = self Xnew, updatedPrior = self.SeqDesign.choose_next_sample(TotalSigma2, diff --git a/src/bayesvalidrox/surrogate_models/sequential_design.py b/src/bayesvalidrox/surrogate_models/sequential_design.py index 1a3591a6c..72779f022 100644 --- a/src/bayesvalidrox/surrogate_models/sequential_design.py +++ b/src/bayesvalidrox/surrogate_models/sequential_design.py @@ -597,6 +597,11 @@ class SequentialDesign: mseError = mean_squared_error(pce_y, y) # Mean squared CV - error for last design point + # TODO: _y_hat_prev is only calculated after the first sequential + # iteration scheme! Either work around this, or calculate + # anyway. + if self._y_hat_prev is None: + raise AttributeError('Adaptive tradeoff scheme cannot be used in the first sequential iteration!') pce_y_prev = np.array(list(self._y_hat_prev.values()))[:, 0] mseCVError = mean_squared_error(pce_y_prev, y) -- GitLab