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

Method test_optimizer_PI

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

Source from the content-addressed store, hash-verified

255 modAL.acquisition.UCB(mean, std, 0)
256
257 def test_optimizer_PI(self):
258 for n_samples in range(1, 100):
259 mean = np.random.rand(n_samples, )
260 std = np.random.rand(n_samples, )
261 tradeoff = np.random.rand()
262 max_val = np.random.rand()
263
264 # 1. fitted estimator
265 mock_estimator = mock.MockEstimator(predict_return=(mean, std))
266 optimizer = modAL.models.learners.BayesianOptimizer(
267 estimator=mock_estimator)
268 optimizer._set_max([0], [max_val])
269 true_PI = ndtr((mean - max_val - tradeoff)/std)
270
271 np.testing.assert_almost_equal(
272 true_PI,
273 modAL.acquisition.optimizer_PI(
274 optimizer, np.random.rand(n_samples, 2), tradeoff)
275 )
276
277 # 2. unfitted estimator
278 mock_estimator = mock.MockEstimator(fitted=False)
279 optimizer = modAL.models.learners.BayesianOptimizer(
280 estimator=mock_estimator)
281 optimizer._set_max([0], [max_val])
282 true_PI = ndtr((np.zeros(shape=(len(mean), 1)) -
283 max_val - tradeoff) / np.ones(shape=(len(mean), 1)))
284
285 np.testing.assert_almost_equal(
286 true_PI,
287 modAL.acquisition.optimizer_PI(
288 optimizer, np.random.rand(n_samples, 2), tradeoff)
289 )
290
291 def test_optimizer_EI(self):
292 for n_samples in range(1, 100):

Callers

nothing calls this directly

Calls 1

_set_maxMethod · 0.95

Tested by

no test coverage detected