def test_reset_classification(make_random_dataset): """Make sure the reset of the reclassification status works as expected.""" X, _ = make_random_dataset # pylint: disable=invalid-name palinstance = PALBase(X, ["model"], 3) lows = np.zeros((100, 3)) highs = np.zeros((100, 3)) means = np.full((100, 3), 1) palinstance._means = means palinstance.std = np.full((100, 3), 0.1) pareto_optimal = np.array([False] * 98 + [True, True]) sampled = np.array([[False] * 3, [False] * 3, [False] * 3, [False] * 3]) unclassified = np.array([True] * 98 + [False, False]) palinstance.rectangle_lows = lows palinstance.rectangle_ups = highs palinstance.sampled = sampled palinstance.pareto_optimal = pareto_optimal palinstance.unclassified = unclassified palinstance._reset_classification() assert palinstance.number_unclassified_points == len(X) assert palinstance.number_pareto_optimal_points == 0 assert palinstance.number_discarded_points == 0
def test_augment_design_space(make_random_dataset): """Testing the basic functionality of the augmentation method Does NOT test the re-classification step, which needs a model""" X, _ = make_random_dataset # pylint: disable=invalid-name X_augmented = np.vstack([X, X]) # pylint: disable=invalid-name palinstance = PALBase(X, ["model"], 3) # Iteration count to low with pytest.raises(ValueError): palinstance.augment_design_space(X_augmented) palinstance.iteration = 2 # Incorrect shape with pytest.raises(AssertionError): palinstance.augment_design_space(X_augmented[:, 2]) with pytest.raises(ValueError): palinstance.augment_design_space(X_augmented[:, :2]) # Mock that we already ran that lows = np.zeros((100, 3)) highs = np.zeros((100, 3)) means = np.full((100, 3), 1) palinstance._means = means palinstance.std = np.full((100, 3), 0.1) pareto_optimal = np.array([False] * 98 + [True, True]) sampled = np.array([[False] * 3, [False] * 3, [False] * 3, [False] * 3]) unclassified = np.array([True] * 98 + [False, False]) palinstance.rectangle_lows = lows palinstance.rectangle_ups = highs palinstance.sampled = sampled palinstance.pareto_optimal = pareto_optimal palinstance.unclassified = unclassified # As we do not have a model, we cannot test the classification palinstance.augment_design_space(X_augmented, clean_classify=False) assert palinstance.number_discarded_points == 0 assert palinstance.number_pareto_optimal_points == 2 assert palinstance.number_unclassified_points == 298 assert palinstance.number_sampled_points == 0 assert palinstance.number_design_points == 300 assert len(palinstance.means) == 300 assert len(palinstance.std) == 300
def test_sample(make_random_dataset): """Test the sampling""" X, _ = make_random_dataset # pylint:disable=invalid-name palinstance = PALBase(X, ["model"], 4) lows = np.array([ [0.0, 0.0, 0.0, 0.0], [-1.0, -1.0, -1.0, -1.0], [-2.0, -2.0, -2.0, -2.0], [2.0, 2.0, 2.0, 2.0], ]) highs = np.array([ [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [2.0, 2.0, 2.0, 2.0], ]) means = np.array([[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]) palinstance._means = means pareto_optimal = np.array([False, False, True, True]) sampled = np.array([[False] * 4, [False] * 4, [False] * 4, [False] * 4]) unclassified = np.array([True, True, False, False]) palinstance.rectangle_lows = lows palinstance.rectangle_ups = highs palinstance.sampled = sampled palinstance.pareto_optimal = pareto_optimal palinstance.unclassified = unclassified sampled_idx = palinstance.sample() assert sampled_idx == 2 pareto_optimal = np.array([False, False, True, True]) sampled = np.array([[False] * 4, [False] * 4, [False] * 4, [False] * 4]) unclassified = np.array([True, True, False, False]) palinstance.sampled = sampled palinstance.pareto_optimal = pareto_optimal palinstance.unclassified = unclassified sampled_idx = palinstance.sample() assert sampled_idx == 2 pareto_optimal = np.array([False, False, True, True]) sampled = np.array([[False] * 4, [False] * 4, [True] * 4, [False] * 4]) unclassified = np.array([True, True, False, False]) palinstance.sampled = sampled palinstance.pareto_optimal = pareto_optimal palinstance.unclassified = unclassified sampled_idx = palinstance.sample() assert sampled_idx == 1 pareto_optimal = np.array([False, False, False, True]) sampled = np.array([[False] * 4, [False] * 4, [True] * 4, [False] * 4]) unclassified = np.array([True, True, False, False]) palinstance.sampled = sampled palinstance.pareto_optimal = pareto_optimal palinstance.unclassified = unclassified sampled_idx = palinstance.sample() assert sampled_idx == 1