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

Method test_optimizer_EI

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

Source from the content-addressed store, hash-verified

289 )
290
291 def test_optimizer_EI(self):
292 for n_samples in range(1, 100):
293 mean = np.random.rand(n_samples, )
294 std = np.random.rand(n_samples, )
295 tradeoff = np.random.rand()
296 max_val = np.random.rand()
297
298 # 1. fitted estimator
299 mock_estimator = mock.MockEstimator(
300 predict_return=(mean, std)
301 )
302 optimizer = modAL.models.learners.BayesianOptimizer(
303 estimator=mock_estimator)
304 optimizer._set_max([0], [max_val])
305 true_EI = (mean - optimizer.y_max - tradeoff) * ndtr((mean - optimizer.y_max - tradeoff) / std) \
306 + std * norm.pdf((mean - optimizer.y_max - tradeoff) / std)
307
308 np.testing.assert_almost_equal(
309 true_EI,
310 modAL.acquisition.optimizer_EI(
311 optimizer, np.random.rand(n_samples, 2), tradeoff)
312 )
313
314 # 2. unfitted estimator
315 mock_estimator = mock.MockEstimator(fitted=False)
316 optimizer = modAL.models.learners.BayesianOptimizer(
317 estimator=mock_estimator)
318 optimizer._set_max([0], [max_val])
319 true_EI = (np.zeros(shape=(len(mean), 1)) - optimizer.y_max - tradeoff) * ndtr((np.zeros(shape=(len(mean), 1)) - optimizer.y_max - tradeoff) / np.ones(shape=(len(mean), 1))) \
320 + np.ones(shape=(len(mean), 1)) * norm.pdf((np.zeros(shape=(len(mean), 1)
321 ) - optimizer.y_max - tradeoff) / np.ones(shape=(len(mean), 1)))
322
323 np.testing.assert_almost_equal(
324 true_EI,
325 modAL.acquisition.optimizer_EI(
326 optimizer, np.random.rand(n_samples, 2), tradeoff)
327 )
328
329 def test_optimizer_UCB(self):
330 for n_samples in range(1, 100):

Callers

nothing calls this directly

Calls 1

_set_maxMethod · 0.95

Tested by

no test coverage detected