physbo.search.range package
Module contents
- class physbo.search.range.History(dim: int)[ソース]
ベースクラス:
object
- export_all_sequence_best_fx()[ソース]
Export all fx and actions at each sequence. (The total number of data is total_num_research.)
- 戻り値:
best_fx (numpy.ndarray)
best_actions (numpy.ndarray)
- export_sequence_best_fx()[ソース]
Export best fx and X at each sequence (each call of write function).
- 戻り値:
best_fx (numpy.ndarray (num_runs)) -- The best fx at each sequence.
best_X (numpy.ndarray (num_runs, dim)) -- The best X at each sequence.
- load(filename)[ソース]
Load the information of the history.
- パラメータ:
filename (str) -- The name of the file which stores the information of the history
- save(filename)[ソース]
Save the information of the history.
- パラメータ:
filename (str) -- The name of the file which stores the information of the history
- property time_get_action
- property time_run_simulator
- property time_total
- property time_update_predictor
- write(t, action_X, time_total=None, time_update_predictor=None, time_get_action=None, time_run_simulator=None)[ソース]
Overwrite fx and action_X by t and action_X.
- パラメータ:
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.Policy(*, min_X=None, max_X=None, config=None, initial_data=None, comm=None)[ソース]
ベースクラス:
object
Single objective Bayesian optimization with continuous search space
- パラメータ:
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.
config (SetConfig object (physbo.misc.SetConfig))
initial_data (tuple[np.ndarray, np.ndarray]) -- The initial training datasets. The first elements is the array of inputs and the second is the array of values of objective functions
comm (MPI.Comm, optional) -- MPI Communicator
- bayes_search(training=None, max_num_probes=None, num_search_each_probe=1, predictor=None, is_disp=True, simulator=None, score='TS', interval=0, num_rand_basis=0, optimizer=None)[ソース]
Performing Bayesian optimization.
- パラメータ:
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.
optimizer (Optimizer object) -- Optimizer object for optimizing the acquisition function. If None, the default optimizer is used.
- 戻り値:
history
- 戻り値の型:
history object (physbo.search.discrete.results.history)
- get_post_fcov(xs, diag=True)[ソース]
Calculate covariance of predictor (post distribution)
- パラメータ:
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.
- 戻り値:
fcov -- Covariance matrix of the post distribution. Returned shape is (num_points) if diag=true, (num_points, num_points) if diag=false.
- 戻り値の型:
numpy.ndarray
- get_post_fmean(xs)[ソース]
Calculate mean value of predictor (post distribution)
- パラメータ:
xs (physbo.Variable or np.ndarray) -- input parameters to calculate mean value shape is (num_points, num_parameters)
- 戻り値:
fmean -- Mean value of the post distribution. Returned shape is (num_points).
- 戻り値の型:
numpy.ndarray
- get_score(mode, *, xs=None, predictor=None, training=None, parallel=True, alpha=1)[ソース]
Calcualte score (acquisition function)
- パラメータ:
mode (str) -- The type of aquisition funciton. TS, EI and PI are available. These functions are defined in score.py.
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).
- 戻り値:
f -- Score defined in each mode.
- 戻り値の型:
float or list of float
- 例外:
RuntimeError -- If both actions and xs are given
メモ
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=None, file_predictor=None)[ソース]
Loading files about history, training and predictor.
- パラメータ:
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.
- random_search(max_num_probes, num_search_each_probe=1, simulator=None, is_disp=True)[ソース]
Performing random search.
- パラメータ:
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.
- 戻り値:
history
- 戻り値の型:
history object (physbo.search.discrete.results.history)
- save(file_history, file_training=None, file_predictor=None)[ソース]
Saving history, training and predictor into the corresponding files.
- パラメータ:
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.
- set_seed(seed)[ソース]
Setting a seed parameter for np.random.
- パラメータ:
seed (int) -- seed number
-------
- write(X, t, time_total=None, time_update_predictor=None, time_get_action=None, time_run_simulator=None)[ソース]
Writing history (update history, not output to a file).
- パラメータ:
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. The negative energy of each search candidate (value of the objective function to be optimized).
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.