bayeso.bo.bo_w_gp

It defines a class of Bayesian optimization with Gaussian process regression.

class bayeso.bo.bo_w_gp.BOwGP(range_X: ndarray, str_cov: str = 'matern52', str_acq: str = 'ei', normalize_Y: bool = True, use_ard: bool = True, prior_mu: Callable | None = None, str_optimizer_method_gp: str = 'BFGS', str_optimizer_method_bo: str = 'L-BFGS-B', str_modelselection_method: str = 'ml', str_exp: str = None, debug: bool = False)

Bases: BaseBO

It is a Bayesian optimization class with Gaussian process regression.

Parameters:
  • range_X (numpy.ndarray) – a search space. Shape: (d, 2).

  • str_cov (str., optional) – the name of covariance function.

  • str_acq (str., optional) – the name of acquisition function.

  • normalize_Y (bool., optional) – flag for normalizing outputs.

  • use_ard (bool., optional) – flag for automatic relevance determination.

  • prior_mu (NoneType, or callable, optional) – None, or prior mean function.

  • str_optimizer_method_gp (str., optional) – the name of optimization method for Gaussian process regression.

  • str_optimizer_method_bo (str., optional) – the name of optimization method for Bayesian optimization.

  • str_modelselection_method (str., optional) – the name of model selection method for Gaussian process regression.

  • str_exp (str., optional) – the name of experiment.

  • debug (bool., optional) – flag for printing log messages.

_abc_impl = <_abc._abc_data object>
_optimize(fun_negative_acquisition: Callable, str_sampling_method: str, num_samples: int, seed: int = None) Tuple[ndarray, ndarray]

It optimizes fun_negative_function with self.str_optimizer_method_bo. num_samples examples are determined by str_sampling_method, to start acquisition function optimization.

Parameters:
  • fun_negative_acquisition (callable) – negative acquisition function.

  • str_sampling_method (str.) – the name of sampling method.

  • num_samples (int.) – the number of samples.

  • seed (int., optional) – a random seed.

Returns:

tuple of next point to evaluate and all candidates determined by acquisition function optimization. Shape: ((d, ), (num_samples, d)).

Return type:

(numpy.ndarray, numpy.ndarray)

compute_acquisitions(X: ndarray, X_train: ndarray, Y_train: ndarray, cov_X_X: ndarray, inv_cov_X_X: ndarray, hyps: dict) ndarray

It computes acquisition function values over ‘X’, where X_train, Y_train, cov_X_X, inv_cov_X_X, and hyps are given.

Parameters:
  • X (numpy.ndarray) – inputs. Shape: (l, d) or (l, m, d).

  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).

  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).

  • cov_X_X (numpy.ndarray) – kernel matrix over X_train. Shape: (n, n).

  • inv_cov_X_X (numpy.ndarray) – kernel matrix inverse over X_train. Shape: (n, n).

  • hyps (dict.) – dictionary of hyperparameters.

Returns:

acquisition function values over X. Shape: (l, ).

Return type:

numpy.ndarray

Raises:

AssertionError

compute_posteriors(X_train: ndarray, Y_train: ndarray, X_test: ndarray, cov_X_X: ndarray, inv_cov_X_X: ndarray, hyps: dict) ndarray

It returns posterior mean and standard deviation functions over X_test.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).

  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).

  • X_test (numpy.ndarray) – inputs. Shape: (l, d) or (l, m, d).

  • cov_X_X (numpy.ndarray) – kernel matrix over X_train. Shape: (n, n).

  • inv_cov_X_X (numpy.ndarray) – kernel matrix inverse over X_train. Shape: (n, n).

  • hyps (dict.) – dictionary of hyperparameters for Gaussian process.

Returns:

posterior mean and standard deviation functions over X_test. Shape: ((l, ), (l, )).

Return type:

(numpy.ndarray, numpy.ndarray)

Raises:

AssertionError

optimize(X_train: ndarray, Y_train: ndarray, str_sampling_method: str = 'sobol', num_samples: int = 128, str_mlm_method: str = 'regular', seed: int = None) Tuple[ndarray, dict]

It computes acquired example, candidates of acquired examples, acquisition function values for the candidates, covariance matrix, inverse matrix of the covariance matrix, hyperparameters optimized, and execution times.

Parameters:
  • X_train (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).

  • Y_train (numpy.ndarray) – outputs. Shape: (n, 1).

  • str_sampling_method (str., optional) – the name of sampling method for acquisition function optimization.

  • num_samples (int., optional) – the number of samples.

  • str_mlm_method (str., optional) – the name of marginal likelihood maximization method for Gaussian process regression.

  • seed (int., optional) – a random seed.

Returns:

acquired example and dictionary of information. Shape: ((d, ), dict.).

Return type:

(numpy.ndarray, dict.)

Raises:

AssertionError