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

Class BayesianOptimizer

modAL/models/learners.py:305–429  ·  view source on GitHub ↗

This class is an abstract model of a Bayesian optimizer algorithm. Args: estimator: The estimator to be used in the Bayesian optimization. (For instance, a GaussianProcessRegressor.) query_strategy: Function providing the query strategy for Bayesian optimization

Source from the content-addressed store, hash-verified

303
304
305class BayesianOptimizer(ActiveLearner):
306 """
307 This class is an abstract model of a Bayesian optimizer algorithm.
308
309 Args:
310 estimator: The estimator to be used in the Bayesian optimization. (For instance, a
311 GaussianProcessRegressor.)
312 query_strategy: Function providing the query strategy for Bayesian optimization,
313 for instance, modAL.acquisitions.max_EI.
314 X_training: Initial training samples, if available.
315 y_training: Initial training labels corresponding to initial training samples.
316 bootstrap_init: If initial training data is available, bootstrapping can be done during the first training.
317 Useful when building Committee models with bagging.
318 **fit_kwargs: keyword arguments.
319
320 Attributes:
321 estimator: The estimator to be used in the Bayesian optimization.
322 query_strategy: Function providing the query strategy for Bayesian optimization.
323 X_training: If the model hasn't been fitted yet it is None, otherwise it contains the samples
324 which the model has been trained on.
325 y_training: The labels corresponding to X_training.
326 X_max: argmax of the function so far.
327 y_max: Max of the function so far.
328
329 Examples:
330
331 >>> import numpy as np
332 >>> from functools import partial
333 >>> from sklearn.gaussian_process import GaussianProcessRegressor
334 >>> from sklearn.gaussian_process.kernels import Matern
335 >>> from modAL.models import BayesianOptimizer
336 >>> from modAL.acquisition import optimizer_PI, optimizer_EI, optimizer_UCB, max_PI, max_EI, max_UCB
337 >>>
338 >>> # generating the data
339 >>> X = np.linspace(0, 20, 1000).reshape(-1, 1)
340 >>> y = np.sin(X)/2 - ((10 - X)**2)/50 + 2
341 >>>
342 >>> # assembling initial training set
343 >>> X_initial, y_initial = X[150].reshape(1, -1), y[150].reshape(1, -1)
344 >>>
345 >>> # defining the kernel for the Gaussian process
346 >>> kernel = Matern(length_scale=1.0)
347 >>>
348 >>> tr = 0.1
349 >>> PI_tr = partial(optimizer_PI, tradeoff=tr)
350 >>> PI_tr.__name__ = 'PI, tradeoff = %1.1f' % tr
351 >>> max_PI_tr = partial(max_PI, tradeoff=tr)
352 >>>
353 >>> acquisitions = zip(
354 ... [PI_tr, optimizer_EI, optimizer_UCB],
355 ... [max_PI_tr, max_EI, max_UCB],
356 ... )
357 >>>
358 >>> for acquisition, query_strategy in acquisitions:
359 ... # initializing the optimizer
360 ... optimizer = BayesianOptimizer(
361 ... estimator=GaussianProcessRegressor(kernel=kernel),
362 ... X_training=X_initial, y_training=y_initial,

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…