physbo.search.utility module
Utility helpers for the search module.
This module collects helpers used across the search policies:
Simulatorwraps a test function so it can be called by action index.make_grid()builds a grid of candidate points for a discrete search.plot_pareto_front()andplot_pareto_front_all()visualize the Pareto front stored in a multi-objective history.the remaining
show_*/is_learninghelpers format progress messages and drive the search loop.
- class physbo.search.utility.Simulator(test_X, test_function, negate=False)[ソース]
ベースクラス:
objectSimulator class wrapping the test function for discrete search space.
- パラメータ:
test_X (numpy.ndarray) -- The test points. Each row is a candidate.
test_function (physbo.test_functions.base.TestFunction) -- The test function.
negate (bool, default=False) -- If True, the test function value is negated before returning.
- physbo.search.utility.is_learning(n, interval)[ソース]
Decide whether to (re)learn the hyperparameters at search step
n.- パラメータ:
n (int) -- Zero-based index of the current search step.
interval (int) --
Hyperparameter learning interval.
interval == 0: learn only at the first step (n == 0).interval > 0: learn everyintervalsteps.interval < 0: never learn.
- 戻り値:
True if hyperparameters should be learned at this step.
- 戻り値の型:
bool
- physbo.search.utility.length_vector(t)[ソース]
Return the number of elements of
t.- パラメータ:
t (array-like or scalar) -- Input object.
- 戻り値:
len(t)iftis sized, otherwise 1 (treatingtas a scalar).- 戻り値の型:
int
- physbo.search.utility.make_grid(min_X: list[float] | ndarray, max_X: list[float] | ndarray, num_X: int | list[int] | ndarray, constraint=None) ndarray[ソース]
Make a grid of points in the search space.
- パラメータ:
min_X (np.ndarray | list[float] | float) -- Minimum value of search space for each dimension
max_X (np.ndarray | list[float] | float) -- Maximum value of search space for each dimension
num_X (int | list[int] | np.ndarray) -- Number of points in each dimension
- 戻り値:
The grid of points in the search space The output is a numpy array of shape (N, d), where N is the number of points and d is the dimension of the search space
- 戻り値の型:
np.ndarray
- 例外:
ValueError -- If min_X and max_X have different number of dimensions If num_X has different number of dimensions from min_X and max_X
- physbo.search.utility.plot_pareto_front(history, x=0, y=1, steps_begin=0, steps_end=None, ax=None, xlim=None, ylim=None, grid=True, style_common: dict = {}, style_pareto_front: dict = {}, style_dominated: dict = {})[ソース]
Plot the Pareto front of the history in the projection to the (x, y)-plane (objective x and y).
- パラメータ:
history (History) -- The history of the search.
x (int, default=0) -- The index of the objective to plot on the x-axis.
y (int, default=1) -- The index of the objective to plot on the y-axis.
steps_begin (int, default=0) -- The index (inclusive) of the step to begin plotting.
steps_end (int, optional) -- The index (exclusive) of the step to end plotting. If None, plot until the end.
ax (matplotlib.axes.Axes, optional) -- The axes to plot on. If None, a new figure is created.
xlim (tuple, optional) -- The x-axis limits. If None, the limits are determined automatically.
ylim (tuple, optional) -- The y-axis limits. If None, the limits are determined automatically.
grid (bool, default=True) -- Whether to plot the grid.
style_common (dict, optional) -- The common setting for plotting the points.
style_pareto_front (dict, optional) -- The setting for plotting the Pareto front.
style_dominated (dict, optional) -- The setting for plotting the dominated points.
Note
Items in style_* are passed to the scatter method of matplotlib.pyplot.
For each item, style_pareto_front and style_dominated are higher priority than style_common.
By default, the marker is "o".
By default, the color is "blue" for dominated points and "red" for Pareto front.
- physbo.search.utility.plot_pareto_front_all(history, steps_begin=0, steps_end=None, ax=None, xlim=None, ylim=None, grid=True, style_common: dict = {}, style_pareto_front: dict = {}, style_dominated: dict = {})[ソース]
Plot the Pareto front of the history for all pairs of objectives.
- パラメータ:
history (History) -- The history of the search.
steps_begin (int, optional) -- The index (inclusive) of the step to begin plotting. If None, plot from the beginning.
steps_end (int, optional) -- The index (exclusive) of the step to end plotting. If None, plot until the end.
ax (matplotlib.axes.Axes, optional) -- The axes to plot on. If None, a new figure is created.
xlim (tuple, optional) -- The x-axis limits. If None, the limits are determined automatically.
ylim (tuple, optional) -- The y-axis limits. If None, the limits are determined automatically.
grid (bool, default=True) -- Whether to plot the grid.
style_common (dict, optional) -- The common setting for plotting the points.
style_pareto_front (dict, optional) -- The setting for plotting the Pareto front.
style_dominated (dict, optional) -- The setting for plotting the dominated points.
Note
Items in style_* are passed to the scatter method of matplotlib.pyplot.
For each item, style_pareto_front and style_dominated are higher priority than style_common.
By default, the marker is "o".
By default, the color is "blue" for dominated points and "red" for Pareto front.
- physbo.search.utility.show_interactive_mode(simulator, history)[ソース]
Print a message when an interactive search session starts.
The message is shown only at the very first step (empty history) of an interactive run, i.e. when no simulator is provided.
- パラメータ:
simulator (callable or None) -- The simulator, or None for interactive mode.
history (History) -- The search history.
- physbo.search.utility.show_search_results(history, N)[ソース]
Print a summary of the last
Nsingle-objective search steps.- パラメータ:
history (History) -- The search history.
N (int) -- Number of most recent steps to display. Capped at the total number of searches performed so far.
- physbo.search.utility.show_search_results_mo(history, N, disp_pareto_set=False)[ソース]
Print a summary of the last
Nmulti-objective search steps.- パラメータ:
history (History) -- The multi-objective search history.
N (int) -- Number of most recent steps to display. Capped at the total number of searches performed so far.
disp_pareto_set (bool, default=False) -- If True, also display the current Pareto set.
- physbo.search.utility.show_start_message_multi_search(N, score=None)[ソース]
Print the header announcing a multiple-probe search step.
- パラメータ:
N (int) -- Zero-based index of the current search round; the printed index is
N + 1.score (str, optional) -- Name of the acquisition function. If None,
"random"is shown.