physbo.test_functions.base module
- class physbo.test_functions.base.TestFunction(nobj: int, dim: int, min_X: ndarray | list[float] | float, max_X: ndarray | list[float] | float, test_maximizer: bool = True, name: str | None = None)[source]
Bases:
ABCAbstract class for test functions.
Test functions are used to evaluate the performance of the optimization algorithms.
Note
Each test function is implemented in the same sense (minimization or maximization) as in the reference it follows, so that
fand the docstring can be compared with the literature directly. A subclass declares its sense by the class attribute_is_maximization(Falseby default, i.e., minimization).test_maximizerselects the sense of the returned values: withtest_maximizer=True(the default) the values returned by__call__and the reference box always describe a maximization problem (as PHYSBO maximizes objectives), and withtest_maximizer=Falsethey always describe a minimization problem. The sign is flipped only when the declared sense and the requested sense differ.- Parameters:
nobj (int) – Number of objectives.
dim (int) – Number of dimensions.
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.
test_maximizer (bool, default=True) – If True, the returned values describe a maximization problem (for testing a maximization problem solver such as PHYSBO). If False, they describe a minimization problem.
name (str | None, default=None) – Name of the test function. If None, the class name is used.
- constraint(x: ndarray) ndarray[source]
Evaluate the constraint function at the given point.
- Parameters:
x (np.ndarray) – The point at which to evaluate the constraint function. x is a numpy array of shape (n, d), where n is the number of points and d is the dimension of the input space.
- Returns:
The boolean values indicating whether the point is valid or not. The output value is a numpy array of shape (n,), where n is the number of points.
- Return type:
np.ndarray
- property dim: int
Get the number of dimensions of the test function.
- Returns:
The number of dimensions of the test function d.
- Return type:
int
- abstractmethod f(x: ndarray) ndarray[source]
Evaluate the test function at the given point.
fis written in the sense of the reference (see_is_maximization); the conversion to the requested sense is done by__call__.- Parameters:
x (np.ndarray) – The point at which to evaluate the test function. x is a numpy array of shape (n, d), where n is the number of points and d is the dimension of the input space.
- Returns:
f – The value of the test function at the given point. The output value is a numpy array of shape (n, k), where k is the number of objectives.
- Return type:
np.ndarray
- property is_maximization: bool
Whether the test function is defined as a maximization problem in its reference.
This describes how
fis written, not the sense of the returned values (which is selected bytest_maximizer).- Returns:
True if the original problem is a maximization problem.
- Return type:
bool
- make_grid(num_X: int | list[int] | ndarray) ndarray[source]
Make a grid of points in the search space.
- Parameters:
num_X (int | list[int] | np.ndarray) – Number of points in each dimension.
- Returns:
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.
- Return type:
np.ndarray
- property max_X: ndarray
Get the maximum values of the search space of the test function.
- Returns:
The maximum value of the test function for each dimension.
- Return type:
np.ndarray
- property min_X: ndarray
Get the minimum values of the search space of the test function.
- Returns:
The minimum value of the test function for each dimension.
- Return type:
np.ndarray
- property name: str
Get the name of the test function.
- Returns:
The name of the test function.
- Return type:
str
- property nobj: int
Get the number of objectives of the test function.
- Returns:
The number of objectives of the test function k.
- Return type:
int
- set_name(name: str)[source]
Set the name of the test function.
- Parameters:
name (str) – The name of the test function.
- property test_maximizer: bool
Whether the returned values describe a maximization problem.
- Returns:
True if
__call__returns values of a maximization problem.- Return type:
bool