optunahub.benchmarks.BaseProblem
- class optunahub.benchmarks.BaseProblem[source]
优化问题的基类。
- __call__(trial: Trial) float | Sequence[float] [source]
Optuna 的目标函数。默认情况下,此方法使用在
search_space
中定义的参数调用evaluate()
。- 参数:
trial – Optuna trial 对象。
- 返回值:
对于多目标优化,返回目标值或目标值序列。
- abstract property directions: list[StudyDirection]
返回优化方向。
- 返回值:
一个 optuna.study.StudyDirection 的列表。
示例
@property def directions(self) -> list[optuna.study.StudyDirection]: return [optuna.study.StudyDirection.MINIMIZE]
- evaluate(params: dict[str, Any]) float | Sequence[float] [source]
评估目标函数。
- 参数:
params – 输入参数字典。
- 返回值:
对于多目标优化,返回目标值或目标值序列。
示例
def evaluate(self, params: dict[str, Any]) -> float: x = params["x"] y = params["y"] return x ** 2 + y
- property search_space: dict[str, BaseDistribution]
返回搜索空间。
- 返回值:
搜索空间的字典。每个字典元素包含参数名称和分布(参见 optuna.distributions)。
示例
@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]), }