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

Method test_optimizer_UCB

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

Source from the content-addressed store, hash-verified

327 )
328
329 def test_optimizer_UCB(self):
330 for n_samples in range(1, 100):
331 mean = np.random.rand(n_samples, )
332 std = np.random.rand(n_samples, )
333 beta = np.random.rand()
334
335 # 1. fitted estimator
336 mock_estimator = mock.MockEstimator(
337 predict_return=(mean, std)
338 )
339 optimizer = modAL.models.learners.BayesianOptimizer(
340 estimator=mock_estimator)
341 true_UCB = mean + beta*std
342
343 np.testing.assert_almost_equal(
344 true_UCB,
345 modAL.acquisition.optimizer_UCB(
346 optimizer, np.random.rand(n_samples, 2), beta)
347 )
348
349 # 2. unfitted estimator
350 mock_estimator = mock.MockEstimator(fitted=False)
351 optimizer = modAL.models.learners.BayesianOptimizer(
352 estimator=mock_estimator)
353 true_UCB = np.zeros(shape=(len(mean), 1)) + \
354 beta * np.ones(shape=(len(mean), 1))
355
356 np.testing.assert_almost_equal(
357 true_UCB,
358 modAL.acquisition.optimizer_UCB(
359 optimizer, np.random.rand(n_samples, 2), beta)
360 )
361
362 def test_selection(self):
363 for n_samples in range(1, 100):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected