physbo.search.discrete_multi.policy module

class physbo.search.discrete_multi.policy.policy(test_X, num_objectives, comm=None, config=None, initial_data=None)[source]

Bases: physbo.search.discrete.policy.policy

Performing Bayesian optimization.

Parameters
  • training (physbo.variable) – Training dataset.

  • max_num_probes (int) – Maximum number of searching process by Bayesian optimization.

  • num_search_each_probe (int) – Number of searching by Bayesian optimization at each process.

  • predictor (predictor object) – Base class is defined in physbo.predictor. If None, blm_predictor is defined.

  • is_disp (bool) – If true, process messages are outputted.

  • simulator (callable) – Callable (function or object with __call__) Here, action is an integer which represents the index of the candidate.

  • score (str) – The type of aquision funciton. TS (Thompson Sampling), EI (Expected Improvement) and PI (Probability of Improvement) are available.

  • interval (int) – 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) – The number of basis function. If you choose 0, ordinary Gaussian process run.

Returns

history

Return type

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

get_post_fcov(xs)[source]

Calculate covariance of predictor (post distribution)

get_post_fmean(xs)[source]

Calculate mean value of predictor (post distribution)

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

Calcualte score (acquisition function)

Parameters
  • mode (str) – The type of aquisition funciton. TS, EI and PI are available. These functions are defined in score.py.

  • actions (array of int) – actions to calculate score

  • 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 will be used.

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

Returns

f – Score defined in each mode.

Return type

float or list of float

Raises

RuntimeError – If both actions and xs are given

Notes

When neither actions nor xs are given, scores for actions not yet searched will be calculated.

When parallel is True, it is assumed that the function receives the same input (actions or 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_list=None, file_predictor_list=None)[source]

Loading files about history, training and predictor.

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]
new_data_list: List[Optional[physbo.variable.variable]]

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.

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)[source]

Writing history (update history, not output to a file).

Parameters
  • action (numpy.ndarray) – Indexes of actions.

  • t (numpy.ndarray) – N dimensional array. The negative energy of each search candidate (value of the objective function to be optimized).

  • X (numpy.ndarray) – N x d dimensional matrix. Each row of X denotes the d-dimensional feature vector of each search candidate.