optunahub.benchmarks.BaseProblem

class optunahub.benchmarks.BaseProblem[source]

Base class for optimization problems.

__call__(trial: Trial) float | Sequence[float][source]

Objective function for Optuna. By default, this method calls evaluate() with the parameters defined in search_space.

Parameters:

trial – Optuna trial object.

Returns:

The objective value or a sequence of the objective values for multi-objective optimization.

abstract property directions: list[StudyDirection]

Return the optimization directions.

Returns:

List of optuna.study.StudyDirection.

Example

@property
def directions(self) -> list[optuna.study.StudyDirection]:
    return [optuna.study.StudyDirection.MINIMIZE]
evaluate(params: dict[str, Any]) float | Sequence[float][source]

Evaluate the objective function.

Parameters:

params – Dictionary of input parameters.

Returns:

The objective value or a sequence of the objective values for multi-objective optimization.

Example

def evaluate(self, params: dict[str, Any]) -> float:
    x = params["x"]
    y = params["y"]
    return x ** 2 + y
property search_space: dict[str, BaseDistribution]

Return the search space.

Returns:

Dictionary of search space. Each dictionary element consists of the parameter name and distribution (see optuna.distributions).

Example

@property
def search_space(self) -> dict[str, optuna.distributions.BaseDistribution]:
    return {
        "x": optuna.distributions.FloatDistribution(low=0, high=1),
        "y": optuna.distributions.CategoricalDistribution(choices=[0, 1, 2]),
    }