bayeso.wrappers.wrappers_bo_class¶
It defines a wrapper class for Bayesian optimization.
-
class
bayeso.wrappers.wrappers_bo_class.
BayesianOptimization
(range_X: numpy.ndarray, fun_target: Callable, num_iter: int, str_surrogate: str = 'gp', str_cov: str = 'matern52', str_acq: str = 'ei', normalize_Y: bool = True, use_ard: bool = True, prior_mu: Optional[Callable] = None, str_initial_method_bo: str = 'sobol', str_sampling_method_ao: str = 'sobol', str_optimizer_method_gp: str = 'BFGS', str_optimizer_method_tp: str = 'SLSQP', str_optimizer_method_bo: str = 'L-BFGS-B', str_mlm_method: str = 'regular', str_modelselection_method: str = 'ml', num_samples_ao: int = 100, debug: bool = False)¶ Bases:
object
It is a wrapper class for Bayesian optimization. A function for optimizing fun_target runs a single round of Bayesian optimization with an iteration budget num_iter.
Parameters: - range_X (numpy.ndarray) – a search space. Shape: (d, 2).
- fun_target (callable) – a target function.
- num_iter (int.) – an iteration budget for Bayesian optimization.
- str_surrogate (str., optional) – the name of surrogate model.
- str_cov (str., optional) – the name of covariance function.
- str_acq (str., optional) – the name of acquisition function.
- normalize_Y (bool., optional) – a flag for normalizing outputs.
- use_ard (bool., optional) – a flag for automatic relevance determination.
- prior_mu (NoneType, or callable, optional) – None, or a prior mean function.
- str_initial_method_bo (str., optional) – the name of initialization method for sampling initial examples in Bayesian optimization.
- str_sampling_method_ao (str., optional) – the name of sampling method for acquisition function optimization.
- 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_mlm_method (str., optional) – the name of marginal likelihood maximization method for Gaussian process regression.
- str_modelselection_method (str., optional) – the name of model selection method for Gaussian process regression.
- num_samples_ao (int., optional) – the number of samples for acquisition function optimization. If a local search method (e.g., L-BFGS-B) is selected for acquisition function optimization, it is employed.
- debug (bool., optional) – a flag for printing log messages.
-
_get_model_bo_gp
()¶ It returns an object of bayeso.bo.bo_w_gp.BO_w_GP.
Returns: an object of Bayesian optimization. Return type: bayeso.bo.bo_w_gp.BOwGP
-
_get_model_bo_tp
()¶ It returns an object of bayeso.bo.bo_w_tp.BO_w_TP.
Returns: an object of Bayesian optimization. Return type: bayeso.bo.bo_w_tp.BOwTP
-
_get_model_bo_trees
()¶ It returns an object of bayeso.bo.bo_w_trees.BO_w_Trees.
Returns: an object of Bayesian optimization. Return type: bayeso.bo.bo_w_trees.BOwTrees
-
_get_next_best_sample
(next_sample: numpy.ndarray, X: numpy.ndarray, next_samples: numpy.ndarray, acq_vals: numpy.ndarray) → numpy.ndarray¶ It returns the next best sample in terms of acquisition function values.
Parameters: - next_sample (np.ndarray) – the next sample acquired.
- X (np.ndarray) – the samples evaluated so far.
- next_samples (np.ndarray) – the candidates of the next sample.
- acq_vals (np.ndarray) – the values of acquisition function over next_samples.
Returns: the next best sample. Shape: (d, ).
Return type: numpy.ndarray
Raises: AssertionError
-
optimize
(num_init: int, seed: Optional[int] = None) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]¶ It returns the optimization results and times consumed, given the number of initial samples num_init and a random seed seed.
Parameters: - num_init (int.) – the number of initial samples.
- seed (NoneType or int., optional) – None, or a random seed.
Returns: a tuple of acquired samples, their function values, overall times consumed per iteration, time consumed in modeling Gaussian process regression, and time consumed in acquisition function optimization. Shape: ((num_init + num_iter, d), (num_init + num_iter, 1), (num_init + num_iter, ), (num_iter, ), (num_iter, )), or ((num_init + num_iter, m, d), (num_init + num_iter, m, 1), (num_init + num_iter, ), (num_iter, ), (num_iter, )), where d is a dimensionality of the problem we are solving and m is a cardinality of sets.
Return type: (numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray)
Raises: AssertionError
-
optimize_single_iteration
(X: numpy.ndarray, Y: numpy.ndarray) → Tuple[numpy.ndarray, dict]¶ It returns the optimization result and time consumed of single iteration, given X and Y.
Parameters: - X (numpy.ndarray) – inputs. Shape: (n, d) or (n, m, d).
- Y (numpy.ndarray) – outputs. Shape: (n, 1).
Returns: a tuple of the next sample and information dictionary.
Return type: (numpy.ndarray, dict.)
Raises: AssertionError, NotImplementedError
-
optimize_with_all_initial_information
(X: numpy.ndarray, Y: numpy.ndarray) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]¶ It returns the optimization results and times consumed, given inital inputs X and their corresponding outputs Y.
Parameters: - X (numpy.ndarray) – initial inputs. Shape: (n, d) or (n, m, d).
- Y (numpy.ndarray) – initial outputs. Shape: (n, 1).
Returns: a tuple of acquired samples, their function values, overall times consumed per iteration, time consumed in modeling Gaussian process regression, and time consumed in acquisition function optimization. Shape: ((n + num_iter, d), (n + num_iter, 1), (num_iter, ), (num_iter, ), (num_iter, )), or ((n + num_iter, m, d), (n + num_iter, m, 1), (num_iter, ), (num_iter, ), (num_iter, )).
Return type: (numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray)
Raises: AssertionError
-
optimize_with_initial_inputs
(X: numpy.ndarray) → Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]¶ It returns the optimization results and times consumed, given inital inputs X.
Parameters: X (numpy.ndarray) – initial inputs. Shape: (n, d) or (n, m, d). Returns: a tuple of acquired samples, their function values, overall times consumed per iteration, time consumed in modeling Gaussian process regression, and time consumed in acquisition function optimization. Shape: ((n + num_iter, d), (n + num_iter, 1), (n + num_iter, ), (num_iter, ), (num_iter, )), or ((n + num_iter, m, d), (n + num_iter, m, 1), (n + num_iter, ), (num_iter, ), (num_iter, )). Return type: (numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray) Raises: AssertionError
-
print_info
(num_init, seed)¶