Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified custom model test #318

Merged
merged 4 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions ProcessOptimizer/tests/test_doe.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,32 +368,24 @@ def test_get_optimal_DOE(optimal_design_space, design_type):
assert factor_names == ["x1", "x2", "x3"]


def test_custom_model(optimal_design_space):
def test_custom_model(sample_space):
"""Test the get_optimal_DOE function with a custom model."""

custom_model = "x1 + x2 + x3 + x1:x2 + pow(x1, 2)"
custom_model = "x1 + x2 + x1:x2 + pow(x1, 2)"

design, factor_names = get_optimal_DOE(
optimal_design_space, 6, res=5, model=custom_model, seed=42
sample_space, 5, res=5, model=custom_model, seed=42
)
design_int = np.asarray(np.asarray(design[:, :2]), dtype=int)
design_str = np.asarray(design[:, 2], dtype=str)

expected_int = np.array([[60, 1],
[100, 1],
[100, 0],
[20, 1],
[20, 0],
[60, 0]])
expected_str = np.array(["A", "B", "A", "B", "A", "B"])

assert design.shape == (6, 3)
assert np.all(design[:, 0] >= 20) and np.all(design[:, 0] <= 100)
assert np.all(design[:, 1] >= 0) and np.all(design[:, 1] <= 1)
assert [entry in ["A", "B"] for entry in design[:, 2]]
assert factor_names == ["x1", "x2", "x3"]
np.testing.assert_array_almost_equal(design_int, expected_int)
np.testing.assert_array_equal(design_str, expected_str)

design = np.asarray(np.asarray(design[:, :2]), dtype=int)

expected = np.array([[10, 5], [10, -5], [0, 5], [5, -5], [0, -5]])

assert design.shape == (5, 2)
assert np.all(design[:, 0] >= 0) and np.all(design[:, 0] <= 10)
assert np.all(design[:, 1] >= -5) and np.all(design[:, 1] <= 5)
assert factor_names == ["x1", "x2"]
np.testing.assert_array_almost_equal(design, expected)


def test_get_optimal_DOE_default_budget(sample_space):
Expand Down
Loading