qpots.function

class qpots.function.Function(name: str | None = None, dim: int = 2, nobj: int = 2, custom_func: Callable[[Tensor], Tensor] | None = None, bounds: Tensor | None = None, cons: Callable[[Tensor], Tensor] | None = None)[source]

Bases: object

Interface for multi-objective test functions.

This class provides an abstraction over BoTorch test functions and allows for user-defined objective functions. It supports retrieving function bounds and constraints when available.

__init__(name: str | None = None, dim: int = 2, nobj: int = 2, custom_func: Callable[[Tensor], Tensor] | None = None, bounds: Tensor | None = None, cons: Callable[[Tensor], Tensor] | None = None)[source]

Initialize a test function for multi-objective optimization.

Parameters:
  • name (str, optional) – Name of the predefined test function (case-insensitive). If None, a custom function must be provided.

  • dim (int) – Dimensionality of the input space. Defaults to 2.

  • nobj (int) – Number of objectives for the test function. Defaults to 2.

  • custom_func (Callable, optional) – A user-defined function that takes a tensor X as input and returns an output tensor. If provided, name is ignored.

  • bounds (Tensor, optional) – A tensor specifying the lower and upper bounds for the function. Required if using a custom function.

  • cons (Callable, optional) – A constraint function that maps inputs to constraint values.

Raises:

ValueError – If a custom function is provided but bounds is not specified. If an unknown function name is provided.

evaluate(X: Tensor) Tensor[source]

Evaluate the test function or custom function on input X.

Parameters:

X (Tensor) – A tensor of shape (n, dim), where n is the number of points and dim is the input dimension.

Returns:

A tensor of shape (n, nobj) containing the function outputs.

Return type:

Tensor

get_bounds() Tensor[source]

Retrieve the bounds for the function.

Returns:

A tensor containing the lower and upper bounds for each input dimension.

Return type:

Tensor

get_cons() Callable | None[source]

Retrieve the constraint function for the test function.

Returns:

The constraint function if available; otherwise, None.

Return type:

Callable or None