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

Method test_set_new_max

tests/core_tests.py:1246–1295  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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
1284 regressor = mock.MockEstimator()
1285 learner = modAL.models.learners.BayesianOptimizer(
1286 estimator=regressor,
1287 X_training=X, y_training=y
1288 )
1289
1290 X_new = np.random.rand(n_samples, 2)
1291 y_new = y + np.random.rand()
1292 max_idx = np.argmax(y_new)
1293 learner._set_max(X_new, y_new)
1294 np.testing.assert_equal(X_new[max_idx], learner.X_max)
1295 np.testing.assert_equal(y_new[max_idx], learner.y_max)
1296
1297 def test_get_max(self):
1298 for n_samples in range(1, 100):

Callers

nothing calls this directly

Calls 1

_set_maxMethod · 0.95

Tested by

no test coverage detected