From 7460dbec8a7a42b52d734d035a4a135a0d19faae Mon Sep 17 00:00:00 2001 From: kohlhaasrebecca <rebecca.kohlhaas@outlook.com> Date: Wed, 17 Jul 2024 15:30:48 +0200 Subject: [PATCH] Removed voronoi from useable exploration types See issue #46, voronoi exploration was removed for v1.1.0, but should be reactivated in future releases. The corresponding tests were changed accordingly. --- .../surrogate_models/sequential_design.py | 8 ++++++++ tests/test_MetaModel.py | 3 +-- tests/test_SequentialDesign.py | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/bayesvalidrox/surrogate_models/sequential_design.py b/src/bayesvalidrox/surrogate_models/sequential_design.py index f4669a7f2..347d9ac78 100644 --- a/src/bayesvalidrox/surrogate_models/sequential_design.py +++ b/src/bayesvalidrox/surrogate_models/sequential_design.py @@ -278,6 +278,9 @@ class SequentialDesign: # ToDo: Move this if/else into its own function called "do_exploration", which should select the # exploration samples, and assign exploration scores. We should send it explore_score, for if/else stmts # ToDo: Check if explore_scores can be nan, and remove them from any score normalization + if explore_method.lower() == 'voronoi': + raise AttributeError('Exploration with voronoi currently not supported!') + #print('WARNING: Exploration with Voronoi ') if explore_method.lower() == 'loocv': # ----------------------------------------------------------------- # TODO: LOOCV model construnction based on Feng et al. (2020) @@ -530,12 +533,17 @@ class SequentialDesign: temp = totalScore.copy() temp[np.isnan(totalScore)] = -np.inf # Since we are maximizing sorted_idxtotalScore = np.argsort(temp)[::-1] + print(sorted_idxtotalScore) + print(n_new_samples) bestIdx = sorted_idxtotalScore[:n_new_samples] + if type(bestIdx) is int: + bestIdx = [bestIdx] # select the requested number of samples if explore_method.lower() == 'voronoi': Xnew = np.zeros((n_new_samples, ndim)) for i, idx in enumerate(bestIdx): + print(explore.closestPoints) X_can = explore.closestPoints[idx] # Calculate the maxmin score for the region of interest diff --git a/tests/test_MetaModel.py b/tests/test_MetaModel.py index bf6c3c39c..f7a300e8e 100644 --- a/tests/test_MetaModel.py +++ b/tests/test_MetaModel.py @@ -769,8 +769,7 @@ def test_adaptive_regression_fewsamples() -> None: with pytest.raises(AttributeError) as excinfo: mm.adaptive_regression(outputs, 0) - assert str( - excinfo.value) == ('There are too few samples for the corrected loo-cv error. Fit surrogate on at least as ' + assert str(excinfo.value) == ('There are too few samples for the corrected loo-cv error. Fit surrogate on at least as ' 'many samples as parameters to use this') diff --git a/tests/test_SequentialDesign.py b/tests/test_SequentialDesign.py index fe9ad5338..5d713e747 100644 --- a/tests/test_SequentialDesign.py +++ b/tests/test_SequentialDesign.py @@ -298,9 +298,14 @@ def test_choose_next_sample_vor_space() -> None: engine.start_engine() seqDes = SequentialDesign(mm, mod, expdes, engine) seqDes.out_names = ['Z'] - x, nan = seqDes.choose_next_sample() - assert x.shape[0] == 1 and x.shape[1] == 1 + #x, nan = seqDes.choose_next_sample() + #assert x.shape[0] == 1 and x.shape[1] == 1 + + # TODO: removed this functionality for v1.1.0 + with pytest.raises(AttributeError) as excinfo: + x, nan = seqDes.choose_next_sample() + assert str(excinfo.value) == ('Exploration with voronoi currently not supported!') def test_choose_next_sample_latin_space() -> None: """ @@ -581,7 +586,11 @@ def test_choose_next_sample_vor_BODMI() -> None: # seqDes.choose_next_sample(sigma2=None, n_candidates=5, var='DKL') sigma2Dict = {'Z': np.array([0.05])} sigma2Dict = pd.DataFrame(sigma2Dict, columns=['Z']) - seqDes.choose_next_sample(sigma2=sigma2Dict, var=expdes.util_func) + + # TODO: removed this functionality for v1.1.0 + with pytest.raises(AttributeError) as excinfo: + seqDes.choose_next_sample(sigma2=sigma2Dict, var=expdes.util_func) + assert str(excinfo.value) == ('Exploration with voronoi currently not supported!') -- GitLab