MOBO package¶
Submodules¶
MOBO.BO module¶
-
class
MOBO.BO.
BayesianOptimizationProblem
(mogp)¶ Bases:
object
pyGMO wrapper for gaussian process regression
-
fitness
(x)¶
-
get_bounds
()¶
-
get_nobj
()¶
-
set_bounds
(bounds)¶
-
-
class
MOBO.BO.
MultiObjectiveBayesianOptimization
¶ Bases:
object
-
run_kmeans
(n_clusters=8, init='k-means++', n_init=10, max_iter=300, tol=0.0001, precompute_distances='auto', verbose=0, random_state=None, copy_x=True, n_jobs=1)¶ clustering parate front solutions by k-means
Parameters: - n_clusters (int) – optional, default 8 The number of clusters to form as well as the number of centroids to generate.
- init – (‘k-means++’, ‘random’ or an ndarray) Method for initialization, defaults to ‘k-means++’: ‘k-means++’ : selects initial cluster centers for k-mean clustering in a smart way to speed up convergence. See section Notes in k_init for more details. ‘random’: choose k observations (rows) at random from data for the initial centroids. If an ndarray is passed, it should be of shape (n_clusters, n_features) and gives the initial centers.
- n_init (int) – default 10 Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia.
- max_iter (int) – default 300 Maximum number of iterations of the k-means algorithm for a single run.
- tol – float, default: 1e-4 Relative tolerance with regards to inertia to declare convergence
- precompute_distances – {‘auto’, True, False} Precompute distances (faster but takes more memory). ‘auto’ : do not precompute distances if n_samples * n_clusters > 12 million. This corresponds to about 100MB overhead per job using double precision. True : always precompute distances False : never precompute distances
- verbose – int, default 0 Verbosity mode.
- random_state – int, RandomState instance or None (default) Determines random number generation for centroid initialization. Use an int to make the randomness deterministic.
- copy_x – boolean, optional When pre-computing distances it is more numerically accurate to center the data first. If copy_x is True (default), then the original data is not modified, ensuring X is C-contiguous. If False, the original data is modified, and put back before the function returns, but small numerical differences may be introduced by subtracting and then adding the data mean, in this case it will also not ensure that data is C-contiguous which may cause a significant slowdown.
- n_jobs – int or None, optional (default=None)
The number of jobs to use for the computation.
This works by computing each of the n_init runs in parallel.
None
means 1 unless in ajoblib.parallel_backend
context.-1
means using all processors. - algorithm – “auto”, “full” or “elkan”, default=”auto” K-means algorithm to use. The classical EM-style algorithm is “full”. The “elkan” variation is more efficient by using the triangle inequality, but currently doesn’t support sparse data. “auto” chooses “elkan” for dense data and “full” for sparse data.
Examples:
mobo = MOBO.MultiObjectiveBayesianOptimization() mobo.set_train_data(x_observed, y_observed) mobo.train_GPModel()
-
run_mobo
(func=None, args=[], n_dv=0, n_obj_cons=0, n_init_lhs_samples=24, n_iter=10, n_new_ind=16, ga_pop_size=100, ga_gen=50, n_cons=0, mutation=0.03)¶ runs multi-objective bayesian optimization
Parameters: - func – multi objective function you want to minimize. y = f(x, agrs=[]) 0 <= x[i] <=1
- args (list) – parameters for the function.
- n_dv (int) – number of design variabels
- n_obj (int) – number of objective functions n_init_lhs_sampling (int): initial population of bayesian optimization
- n_iter (int) – number of iteration of bayesian optimization n_new_ind (int): number of new indivisuals in each iteration.
- ga_pop_size (int) – population size of multi objective genetic algorithm (NSGA2) ga_pop_size must be multiply number of four.
- ga_gen (int) – generation number of multi objective genetic algorithm (NSGA2)
- n_cons (int) – number of constraints functions
-
run_moead
(size=48, gen=100)¶ runs multi-objective genetic algorithm using gaussian process regression. objective function is Expected Improvement. :param size: population size (default=48) :type size: int :param gen: generation size (default=100) :type gen: int
Examples:
mobo = MOBO.MultiObjectiveBayesianOptimization() mobo.set_train_data(x_observed, y_observed) mobo.train_GPModel()
-
run_moga
(size=48, gen=100, m=0.03)¶ runs multi-objective genetic algorithm using gaussian process regression. objective function is Expected Improvement. :param size: population size (default=48) :type size: int :param gen: generation size (default=100) :type gen: int
Examples:
mobo = MOBO.MultiObjectiveBayesianOptimization() mobo.set_train_data(x_observed, y_observed) mobo.train_GPModel()
-
set_number_of_cpu_core
(n_multiprocessing=4)¶ sets number of cpu cores you use in multi-objective EI calculation (default all cpu) Examples:
cpu = 4 mobo.set_number_of_cpu_core(cpu)
-
set_optimum_direction
(direction_list)¶ Parameters: direction_list (list) – list of 1 and -1 which expresses the direction of optimum Examples:
direction_list = [-1, 1, -1] mobo.set_optimum_direction(direction_list)
-
set_train_data
(x_observed, y_observed, n_cons=0)¶ Parameters: - x_observed – np.array (n_samples, n_params)
- y_observed – np.array (n_samples, n_obj + n_cons)
Example:
mobo = MOBO.MultiObjectiveBayesianOptimization() mobo.set_train_data(x_observed, y_observed)
-
train_GPModel
(kernel=Matern(length_scale=1, nu=1.5))¶ Examples:
mobo = MOBO.MultiObjectiveBayesianOptimization() mobo.set_train_data(x_observed, y_observed) mobo.train_GPModel()
-
MOBO.GP module¶
-
class
MOBO.GP.
GaussianProcess
¶ Bases:
object
Multi-Objective Gaussian Process core class
Note
Set parameters first before train
(https://thuijskens.github.io/2016/12/29/bayesian-optimisation/)
Example:
mogp = MOBO.GaussianProcess() mogp.set_train_data(x_observed, y_observed) mogp.train() x = np.array([[-5, -5]]) print(mogp.predict(x)) x = np.array([[-4.9, -4.9]]) print(mogp.expected_improvement(x))
-
constrained_EI
(x)¶ uses probability of g(x) <= 0. g > 0 is infeasible.
-
expected_hypervolume_improvement
(x)¶ Expected hypervolume improvement function.
Note
under construction!
-
expected_improvement
(x)¶ Expected improvement function.
Parameters: x (array-like) – shape = [n_samples, n_params] Examples:
x = np.array([[-4.9, -4.9]]) ei = mogp.expected_improvement(x) print(ei)
-
predict_original_coor
(x)¶ Note
use it after training
Parameters: x – np.array, size = [n_input, n_params] Returns: mean and std size = [2, n_obj] Return type: mu, sigma (float or list) Example:
x = np.array([-5, -5]) mu, sigma = mogp.predict(x) print(mu, sigma)
-
predict_standarize_value
(x)¶ Note
use it after training
Parameters: x – np.array, size = [n_input, n_params] Returns: mean and std size = [2, n_obj] Return type: mu, sigma (float or list) Example:
x = np.array([-5, -5]) mu, sigma = mogp.predict(x) print(mu, sigma)
-
probability_of_feasibility
(x)¶ calculates the probability of feasibility. uses probability of g(x) <= 0. g > 0 is infeasible.
-
set_number_of_cpu_core
(n_multiprocessing)¶
-
set_optimum_direction
(direction_list)¶ Parameters: - direction_list (list) – list of 1 and -1
- expresses the direction of optimum (which) –
Examples:
direction_list = [-1, 1, -1] mogp.set_optimum_direction(direction_list)
-
set_train_data
(x_observed, y_observed, n_cons=0)¶ Parameters: - x_observed – np.array (n_samples, n_params)
- y_observed – np.array (n_samples, n_obj)
Example:
mogp = MOBO.GaussianProcess() mogp.set_train_data(x_observed, y_observed)
-
train
(kernel=Matern(length_scale=1, nu=1.5))¶ trains Gaussian process for regression
Note
multi-objective optimization (n_obj > 1) is also available.
Parameters: kernel – kernel implemented in sklearn.gp (default: gp.kernels.Matern()) Example:
mogp = MOBO.GaussianProcess() mogp.set_train_data(x_observed, y_observed) mogp.train()
-
wrapper_mp
(i_obj)¶
-
-
class
MOBO.GP.
MpHelper
(cls, mtd_name)¶ Bases:
object
helper function for multiprocessing to call class method
Note
japanese site http://aflc.hatenablog.com/entry/20110825/1314366131