physbo.search.discrete_multi package

Module contents

class physbo.search.discrete_multi.History(num_objectives)[source]

Bases: object

export_pareto_front()[source]
export_valid()[source]

Export the valid (successfully evaluated) observations.

Returns:

  • actions (numpy.ndarray) – Indexes of the actions of the valid observations.

  • fx (numpy.ndarray) – Objective values of the valid observations (N_valid x num_objectives).

load(filename)[source]
save(filename)[source]
show_search_results_mo(N, disp_pareto_set=False)[source]
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, time_total=None, time_update_predictor=None, time_get_action=None, time_run_simulator=None)[source]
class physbo.search.discrete_multi.Policy(test_X, num_objectives, comm=None, config=None, initial_data=None, rng=None)[source]

Bases: Policy

Multi objective Bayesian optimization with discrete search space

Parameters:
  • test_X (numpy.ndarray or physbo.Variable) – The set of candidates. Each row vector represents the feature vector of each search candidate.

  • config (SetConfig object (physbo.misc.SetConfig))

  • initial_data (tuple[np.ndarray, np.ndarray]) – The initial training datasets. The first elements is the array of actions and the second is the array of value of objective functions

  • comm (MPI.Comm, optional) – MPI Communicator

  • rng (None, "legacy", int, or numpy.random.Generator, optional) – Random number generator specification (default: “legacy”). None or “legacy” uses the global numpy.random state and is bit-compatible with the historical behavior. An int seed or a Generator switches to a policy-owned generator whose state is stored on the policy (and thus included when the policy is pickled). Under MPI, pass the same specification on all ranks.

Performing Bayesian optimization by using multi 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_list (list of predictor objects, optional) – The predictor objects.

  • 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) – EHVI, HVPI, TS, or a callable called positionally as score(predictor_list, training, test, pareto) returning a numpy.ndarray of shape (test.X.shape[0],), with larger values preferred. pareto is self.history.pareto and must be treated as read-only; marginal scores do not update it with virtual data. Empty test data skips the callable. Under MPI, the callable evaluates local points and must not perform collective communication.

  • 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.

  • optimizer (optimizer object, optional) – This is for compatibility with the range-based Policies.

  • unify_method (callable, optional) – This is for compatibility with the unified-optimization Policies.

  • ard (bool, optional) – If True, use Automatic Relevance Determination (ARD) for the Gaussian kernel. Default is False.

Returns:

history

Return type:

history object (physbo.search.discrete_multi.results.history)

get_kernel_length_scale()[source]

Return the Gaussian kernel length scale(s) for each objective.

Returns:

List of length num_objectives; each element is the length scale(s) for that objective’s GP, or None if not available.

Return type:

list of numpy.ndarray or None

get_permutation_importance(n_perm: int, split_features_parallel=False)[source]

Calculate permutation importance of models

Parameters:
  • n_perm (int) – The number of permutations

  • split_features_parallel (bool) – If true, split features in parallel.

Returns:

  • importance_mean (numpy.ndarray) – importance_mean (num_parameters, num_objectives)

  • importance_std (numpy.ndarray) – importance_std (num_parameters, num_objectives)

get_post_fcov(xs, diag=True)[source]

Calculate covariance of predictors (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, num_objectives) if diag=true, (num_points, num_points, num_objectives) if diag=false.

Return type:

numpy.ndarray

get_post_fmean(xs)[source]

Calculate mean value of predictors (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, num_objectives).

Return type:

numpy.ndarray

get_score(mode, actions=None, xs=None, predictor_list=None, training_list=None, pareto=None, parallel=True, alpha=1)[source]

Calculate multi-objective scores (acquisition function).

Parameters:
  • mode (str or callable) – EHVI, HVPI, TS, or a callable called positionally as mode(predictor_list, training, test, pareto) 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 self.TS_candidate_num apply only to string modes.

  • actions (array of int, optional) – Candidate indices to evaluate. If neither actions nor xs is given, evaluate candidates not yet searched.

  • xs (physbo.Variable or numpy.ndarray, optional) – Input parameters to calculate scores.

  • predictor_list (list of predictor objects, optional) – Predictors for each objective. Defaults to self.predictor_list.

  • training_list (physbo.Variable, optional) – Training dataset containing all objectives. Defaults to self.training.

  • pareto (Pareto, optional) – Passed unchanged when provided; otherwise self.history.pareto is used. Treat it as read-only. Marginal scores use the observed history’s Pareto front without adding virtual observations.

  • parallel (bool) – Calculate scores in parallel by MPI (default: True).

  • alpha (float) – Posterior sampling scale for string “TS” (default: 1). Ignored for callable modes.

Returns:

f – Acquisition scores of shape (num_points,).

Return type:

numpy.ndarray

Raises:

RuntimeError – If both actions and xs are given.

Notes

When parallel is True, all ranks must receive the same input. To supply separate local inputs, set parallel=False and gather results yourself.

load(file_history, file_training_list=None, file_predictor_list=None)[source]

Loading files about history, training and predictor.

See save for the difference from the checkpoint API (save_checkpoint / load_checkpoint).

Parameters:
  • file_history (str) – The name of the file that stores the information of the history.

  • file_training (str) – The name of the file that stores the training dataset.

  • file_predictor (str) – The name of the file that stores the predictor dataset.

load_predictor_list(file_name)[source]
load_training_list(file_name)[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_list=None, file_predictor_list=None)[source]

Saving history, training and predictor into the corresponding files.

This persists the search results in a portable form (the files can be loaded by runs with a different number of MPI processes). To suspend and later resume an execution bit-exactly (including the random number generator state), use save_checkpoint / load_checkpoint instead.

Parameters:
  • file_history (str) – The name of the file that stores the information of the history.

  • file_training (str) – The name of the file that stores the training dataset.

  • file_predictor (str) – The name of the file that stores the predictor dataset.

save_predictor_list(file_name)[source]
save_training_list(file_name)[source]
write(action, t, X=None, 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:
  • action (numpy.ndarray) – Indexes of actions.

  • t (numpy.ndarray) – N dimensional array (1D) or N x k 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. A non-finite value (NaN or +-Inf) marks a failed evaluation: the action is recorded in the history and consumed, but the observation is excluded from the training data and the best-value tracking.

  • X (numpy.ndarray) – N x d dimensional matrix. Each row of X denotes the d-dimensional feature vector 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.

Note

In this function, (X, t, Z) is added to the training data set (self.training), but not yet to predictor (self.predictor). self.newdata means such data. To add (X, t, Z) to the predictor, call self._update_predictor() after self.write().