physbo.search.range_unified package
Module contents
- class physbo.search.range_unified.History(num_objectives, dim)[source]
Bases:
object- export_valid()[source]
Export the valid (successfully evaluated) observations.
- Returns:
X (numpy.ndarray) – Inputs of the valid observations (N_valid x dim).
fx (numpy.ndarray) – Objective values of the valid observations (N_valid x num_objectives).
- property time_get_action
- property time_run_simulator
- property time_total
- property time_update_predictor
- property valid_mask
Mask of valid observations (True) vs failed ones (False).
An observation is failed when any of its objective values is not finite (NaN or +-Inf). Failed observations are kept in the history but excluded from the training data and the Pareto front.
- Return type:
numpy.ndarray of bool, shape (total_num_search,)
- write(t, action_X, time_total=None, time_update_predictor=None, time_get_action=None, time_run_simulator=None)[source]
Overwrite fx and action_X by t and action_X.
- Parameters:
t (numpy.ndarray) – N dimensional array. The negative energy of each search candidate (value of the objective function to be optimized).
action_X (numpy.ndarray) – N x d dimensional array. The input of each search candidate.
time_total (numpy.ndarray) – N dimenstional array. The total elapsed time in each step. If None (default), filled by 0.0.
time_update_predictor (numpy.ndarray) – N dimenstional array. The elapsed time for updating predictor (e.g., learning hyperparemters) in each step. If None (default), filled by 0.0.
time_get_action (numpy.ndarray) – N dimenstional array. The elapsed time for getting next action in each step. If None (default), filled by 0.0.
time_run_simulator (numpy.ndarray) – N dimenstional array. The elapsed time for running the simulator in each step. If None (default), filled by 0.0.
- class physbo.search.range_unified.Policy(num_objectives, *, min_X=None, max_X=None, constraint=None, comm=None, config=None, initial_data=None, rng=None)[source]
Bases:
PolicyMulti objective Bayesian optimization with continuous search space
- Parameters:
num_objectives (int) – The number of objective functions.
min_X (numpy.ndarray) – The minimum value of each dimension of the search space.
max_X (numpy.ndarray) – The maximum value of each dimension of the search space.
constraint (callable, optional) – Inequality constraints on the search space, as in physbo.search.range.Policy: a function from an array of shape (N, d) to a boolean array of N elements (True for feasible points). Only feasible points are proposed. Not saved by save(); pickled by save_checkpoint(), so it must be picklable.
comm (MPI.Comm, optional) – MPI Communicator
config (SetConfig object (physbo.misc.SetConfig))
initial_data (tuple[np.ndarray, np.ndarray]) – The initial training datasets. The first element is the array of inputs and the second is the array of values of the objective functions, of shape (N, num_objectives). These points are not checked against the constraint.
rng (None, "legacy", int, or numpy.random.Generator, optional) – Random number generator specification (default: “legacy”). See physbo.search.discrete.Policy for details.
- bayes_search(training_list=None, max_num_probes=None, num_search_each_probe=1, predictor=None, is_disp=True, disp_pareto_set=False, simulator=None, score='EI', unify_method=None, interval=0, num_rand_basis=0, optimizer=None, ard=False, ucb_beta=1.0)[source]
Performing Bayesian optimization by using unified objective function
- Parameters:
training_list (list of physbo.Variable, optional) – The training datasets.
max_num_probes (int, optional) – The maximum number of searching process by Bayesian optimization.
num_search_each_probe (int, optional) – The number of searching by Bayesian optimization at each process.
predictor (predictor object, optional) – The predictor object.
is_disp (bool, optional) – If true, process messages are outputted.
disp_pareto_set (bool, optional) – If true, Pareto set is displayed.
simulator (callable, optional) – The simulator function.
score (str or callable) – TS, EI, PI, UCB, or a callable called positionally as
score(predictor, training, test)returning a numpy.ndarray of shape (test.X.shape[0],), with larger values preferred. Empty test data skips the callable. Under MPI, the callable evaluates local points and must not perform collective communication. training contains unified targets of shape (N, 1).interval (int, optional) – The interval number of learning the hyper parameter. If you set the negative value to interval, the hyper parameter learning is not performed. If you set zero to interval, the hyper parameter learning is performed only at the first step.
num_rand_basis (int, optional) – The number of basis function. If you choose 0, ordinary Gaussian process run.
unify_method (callable) – The unified objective function. It is a function or a callable object that maps a (N, num_objectives) numpy.ndarray of original objective functions to a (N, 1) numpy.ndarray of unified objective functions. See physbo.search.unify for examples.
optimizer (Optimizer object, optional) – Optimizer object for optimizing the acquisition function. If None, the default optimizer is used.
ard (bool, optional) – If True, use Automatic Relevance Determination (ARD) for the Gaussian kernel. Default is False.
ucb_beta (float) – Trade-off parameter between exploitation and exploration used for string “UCB”. The score is
fmean + ucb_beta * fstd. Default is 1.0; ignored for callable scores.
- Returns:
history
- Return type:
history object (physbo.search.range_unified.results.history)
- get_permutation_importance(n_perm: int, split_features_parallel=False)[source]
Calculating permutation importance of model
- Parameters:
n_perm (int) – number of permutations
split_features_parallel (bool) – If true, split features in parallel.
- Returns:
importance_mean (numpy.ndarray) – importance_mean
importance_std (numpy.ndarray) – importance_std
- get_post_fcov(xs, diag=True)[source]
Calculate covariance of predictor (post distribution)
- Parameters:
xs (physbo.Variable or np.ndarray) – input parameters to calculate covariance shape is (num_points, num_parameters)
diag (bool) – If true, only variances (diagonal elements) are returned.
- Returns:
fcov – Covariance matrix of the post distribution. Returned shape is (num_points) if diag=true, (num_points, num_points) if diag=false.
- Return type:
numpy.ndarray
- get_post_fmean(xs)[source]
Calculate mean value of predictor (post distribution)
- Parameters:
xs (physbo.Variable or np.ndarray) – input parameters to calculate mean value shape is (num_points, num_parameters)
- Returns:
fmean – Mean value of the post distribution. Returned shape is (num_points).
- Return type:
numpy.ndarray
- get_score(mode, *, xs=None, predictor=None, training=None, pareto=None, parallel=True, alpha=1, ucb_beta=1.0)[source]
Calculate score (acquisition function)
- Parameters:
mode (str or callable) – TS, EI, PI, UCB, or a callable called positionally as
mode(predictor, training, test)returning a numpy.ndarray of shape (test.X.shape[0],), with larger values preferred. Empty test data skips the callable but still participates in MPI gathering. The callable must not perform collective communication. alpha and ucb_beta apply only to string modes. training contains unified targets of shape (N, 1).xs (physbo.Variable or np.ndarray) – input parameters to calculate score
predictor (predictor object) – predictor used to calculate score. If not given, self.predictor will be used.
training (physbo.Variable) – Training dataset. If not given, self.training_unified will be used.
pareto (Pareto, optional) – Retained for API compatibility; unused for unified scoring.
parallel (bool) – Calculate scores in parallel by MPI (default: True)
alpha (float) – Tuning parameter which is used if mode = TS. In TS, multi variation is tuned as np.random.multivariate_normal(mean, cov*alpha**2, size).
ucb_beta (float) – Trade-off parameter between exploitation and exploration used for string “UCB”. The score is
fmean + ucb_beta * fstd. Default is 1.0; ignored for callable scores.
- Returns:
f – Acquisition scores of shape (num_points,).
- Return type:
numpy.ndarray
- Raises:
RuntimeError – If xs is not given
Notes
When parallel is True, it is assumed that the function receives the same input (xs) for all the ranks. If you want to split the input array itself, set parallel be False and merge results by yourself.
- load(file_history, file_training=None, file_predictor=None)[source]
Load the history, the training data and the predictor from files.
The constraint is not restored by load(); the policy keeps the one given to its constructor.
- random_search(max_num_probes, num_search_each_probe=1, simulator=None, is_disp=True, disp_pareto_set=False)[source]
Performing random search.
- Parameters:
max_num_probes (int) – Maximum number of random search process.
num_search_each_probe (int) – Number of search at each random search process.
simulator (callable) – Callable (function or object with
__call__) from action to t Here, action is an integer which represents the index of the candidate.is_disp (bool) – If true, process messages are outputted.
- Returns:
history
- Return type:
history object (physbo.search.discrete.results.history)
- save(file_history, file_training=None, file_predictor=None)[source]
Save the history, the training data and the predictor into files.
The constraint is not saved; give it to the constructor of the policy that loads the files.
- write(X, t, time_total=None, time_update_predictor=None, time_get_action=None, time_run_simulator=None)[source]
Writing history (update history, not output to a file).
- Parameters:
X (numpy.ndarray) – N x d dimensional matrix. Each row of X denotes the d-dimensional feature vector of each search candidate.
t (numpy.ndarray) – N dimensional array (1D) or N x 1 dimensional array (2D). The negative energy of each search candidate (value of the objective function to be optimized). Will be normalized to (N, 1) shape internally. All the values must be finite. Failed evaluations are not supported in continuous search spaces.
time_total (numpy.ndarray) – N dimenstional array. The total elapsed time in each step. If None (default), filled by 0.0.
time_update_predictor (numpy.ndarray) – N dimenstional array. The elapsed time for updating predictor (e.g., learning hyperparemters) in each step. If None (default), filled by 0.0.
time_get_action (numpy.ndarray) – N dimenstional array. The elapsed time for getting next action in each step. If None (default), filled by 0.0.
time_run_simulator (numpy.ndarray) – N dimenstional array. The elapsed time for running the simulator in each step. If None (default), filled by 0.0.
- Raises:
ValueError – If t contains a non-finite value (NaN or +-Inf). Nothing is written to the history in this case.