|
| 1 | +import numpy as np |
| 2 | +import pytest |
| 3 | + |
| 4 | +from autoemulate.history_matching import history_matching |
| 5 | + |
| 6 | + |
| 7 | +@pytest.fixture |
| 8 | +def sample_data_2d(): |
| 9 | + pred_mean = np.array([[1.0, 1.1], [2.0, 2.1], [3.0, 3.1], [4.0, 4.1], [5.0, 5.1]]) |
| 10 | + pred_std = np.array([[0.1, 0.1], [0.2, 0.2], [0.3, 0.3], [0.4, 0.4], [0.5, 0.5]]) |
| 11 | + pred_var = np.square(pred_std) |
| 12 | + expectations = (pred_mean, pred_var) |
| 13 | + obs = [(1.5, 0.1), (2.5, 0.2)] |
| 14 | + return expectations, obs |
| 15 | + |
| 16 | + |
| 17 | +@pytest.fixture |
| 18 | +def sample_data_1d(): |
| 19 | + pred_mean = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) |
| 20 | + pred_std = np.array([0.1, 0.2, 0.3, 0.4, 0.5]) |
| 21 | + pred_var = np.square(pred_std) |
| 22 | + expectations = (pred_mean, pred_var) |
| 23 | + obs = [1.5, 10] |
| 24 | + return expectations, obs |
| 25 | + |
| 26 | + |
| 27 | +def test_history_matching_1d(sample_data_1d): |
| 28 | + expectations, obs = sample_data_1d |
| 29 | + result = history_matching(expectations=expectations, obs=obs, threshold=1.0) |
| 30 | + assert "NROY" in result # Ensure the key exists in the result |
| 31 | + assert isinstance(result["NROY"], list) # Validate that NROY is a list |
| 32 | + assert len(result["NROY"]) > 0 # Ensure the list is not empty |
| 33 | + |
| 34 | + |
| 35 | +def test_history_matching_threshold_1d(sample_data_1d): |
| 36 | + expectations, obs = sample_data_1d |
| 37 | + result = history_matching(expectations=expectations, obs=obs, threshold=0.5) |
| 38 | + assert "NROY" in result |
| 39 | + assert isinstance(result["NROY"], list) |
| 40 | + assert len(result["NROY"]) <= len(expectations[0]) |
| 41 | + |
| 42 | + |
| 43 | +def test_history_matching_2d(sample_data_2d): |
| 44 | + expectations, obs = sample_data_2d |
| 45 | + result = history_matching(expectations=expectations, obs=obs, threshold=1.0) |
| 46 | + assert "NROY" in result # Ensure the key exists in the result |
| 47 | + assert isinstance(result["NROY"], list) # Validate that NROY is a list |
| 48 | + assert len(result["NROY"]) > 0 # Ensure the list is not empty |
| 49 | + |
| 50 | + |
| 51 | +def test_history_matching_threshold_2d(sample_data_2d): |
| 52 | + expectations, obs = sample_data_2d |
| 53 | + result = history_matching(expectations=expectations, obs=obs, threshold=0.5) |
| 54 | + assert "NROY" in result |
| 55 | + assert isinstance(result["NROY"], list) |
| 56 | + assert len(result["NROY"]) <= len(expectations[0]) |
0 commit comments