plot_edf

optuna.visualization.plot_edf(study, *, target=None, target_name='Objective Value')[source]

绘制研究的目标值 EDF(经验分布函数)。

注意,在绘制 EDF 时只考虑已完成的试验。

注意

EDF 对于分析和改进搜索空间很有用。例如,您可以在论文 Designing Network Design Spaces 中看到 EDF 的实际用例。

注意

绘制的 EDF 假设目标函数的值符合目标空间上的均匀分布。

参数:
  • study (Study | Sequence[Study]) – 目标 Study 对象。如果要比较多个研究的 EDF,可以传入多个 Study。

  • target (Callable[[FrozenTrial], float] | None) –

    一个函数,用于指定要显示的值。如果为 None 并且 study 用于单目标优化,则绘制目标值。

    注意

    如果 study 用于多目标优化,请指定此参数。

  • target_name (str) – 要在轴标签上显示的目标名称。

返回值:

一个 plotly.graph_objects.Figure 对象。

返回类型:

Figure

以下代码片段展示了如何绘制 EDF。

import math

import optuna
from plotly.io import show


def ackley(x, y):
    a = 20 * math.exp(-0.2 * math.sqrt(0.5 * (x**2 + y**2)))
    b = math.exp(0.5 * (math.cos(2 * math.pi * x) + math.cos(2 * math.pi * y)))
    return -a - b + math.e + 20


def objective(trial, low, high):
    x = trial.suggest_float("x", low, high)
    y = trial.suggest_float("y", low, high)
    return ackley(x, y)


sampler = optuna.samplers.RandomSampler(seed=10)

# Widest search space.
study0 = optuna.create_study(study_name="x=[0,5), y=[0,5)", sampler=sampler)
study0.optimize(lambda t: objective(t, 0, 5), n_trials=500)

# Narrower search space.
study1 = optuna.create_study(study_name="x=[0,4), y=[0,4)", sampler=sampler)
study1.optimize(lambda t: objective(t, 0, 4), n_trials=500)

# Narrowest search space but it doesn't include the global optimum point.
study2 = optuna.create_study(study_name="x=[1,3), y=[1,3)", sampler=sampler)
study2.optimize(lambda t: objective(t, 1, 3), n_trials=500)

fig = optuna.visualization.plot_edf([study0, study1, study2])
show(fig)

脚本总运行时间: (0 分钟 0.877 秒)

由 Sphinx-Gallery 生成的画廊