MCPcopy Create free account
hub / github.com/modAL-python/modAL / TestBayesianOptimizer

Class TestBayesianOptimizer

tests/core_tests.py:1226–1368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1224
1225
1226class TestBayesianOptimizer(unittest.TestCase):
1227 def test_set_max(self):
1228 # case 1: the estimator is not fitted yet
1229 regressor = mock.MockEstimator()
1230 learner = modAL.models.learners.BayesianOptimizer(estimator=regressor)
1231 self.assertEqual(-np.inf, learner.y_max)
1232
1233 # case 2: the estimator is fitted already
1234 for n_samples in range(1, 100):
1235 X = np.random.rand(n_samples, 2)
1236 y = np.random.rand(n_samples, )
1237 max_val = np.max(y)
1238
1239 regressor = mock.MockEstimator()
1240 learner = modAL.models.learners.BayesianOptimizer(
1241 estimator=regressor,
1242 X_training=X, y_training=y
1243 )
1244 np.testing.assert_almost_equal(max_val, learner.y_max)
1245
1246 def test_set_new_max(self):
1247 for n_reps in range(100):
1248 # case 1: the learner is not fitted yet
1249 for n_samples in range(1, 10):
1250 X = np.random.rand(n_samples, 3)
1251 y = np.random.rand(n_samples)
1252 max_idx = np.argmax(y)
1253 regressor = mock.MockEstimator()
1254 learner = modAL.models.learners.BayesianOptimizer(
1255 estimator=regressor)
1256 learner._set_max(X, y)
1257 np.testing.assert_equal(learner.X_max, X[max_idx])
1258 np.testing.assert_equal(learner.y_max, y[max_idx])
1259
1260 # case 2: new value is not a maximum
1261 for n_samples in range(1, 10):
1262 X = np.random.rand(n_samples, 2)
1263 y = np.random.rand(n_samples)
1264
1265 regressor = mock.MockEstimator()
1266 learner = modAL.models.learners.BayesianOptimizer(
1267 estimator=regressor,
1268 X_training=X, y_training=y
1269 )
1270
1271 X_new = np.random.rand()
1272 y_new = y - np.random.rand()
1273 X_old_max = learner.X_max
1274 y_old_max = learner.y_max
1275 learner._set_max(X_new, y_new)
1276 np.testing.assert_equal(X_old_max, learner.X_max)
1277 np.testing.assert_equal(y_old_max, learner.y_max)
1278
1279 # case 3: new value is a maximum
1280 for n_samples in range(1, 10):
1281 X = np.random.rand(n_samples, 2)
1282 y = np.random.rand(n_samples)
1283

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…