optuna.pruners.SuccessiveHalvingPruner

class optuna.pruners.SuccessiveHalvingPruner(min_resource='auto', reduction_factor=4, min_early_stopping_rate=0, bootstrap_count=0)[source]

非同期逐次半減法アルゴリズムを用いたプルーナー

Successive Halving は、複数の設定の中から最適なものを選択するバンディットベースのアルゴリズムです。このクラスは非同期版の逐次半減法を実装しています。詳細な説明については、 Asynchronous Successive Halving の論文を参照してください。

注意: このクラスでは、論文中で \(R\) と表記されている最大リソースのパラメータは考慮されません。試行に割り当てられる最大リソースは、通常、目的関数内で制限されます(例: simple_pruning.pystep 数、 chainer_integration.pyEPOCH 数)。

See also

report() を参照してください。

使用例

SuccessiveHalvingPruner を使用して目的関数を最小化します。

import numpy as np
from sklearn.datasets import load_iris
from sklearn.linear_model import SGDClassifier
from sklearn.model_selection import train_test_split

import optuna

X, y = load_iris(return_X_y=True)
X_train, X_valid, y_train, y_valid = train_test_split(X, y)
classes = np.unique(y)


def objective(trial):
    alpha = trial.suggest_float("alpha", 0.0, 1.0)
    clf = SGDClassifier(alpha=alpha)
    n_train_iter = 100

    for step in range(n_train_iter):
        clf.partial_fit(X_train, y_train, classes=classes)

        intermediate_value = clf.score(X_valid, y_valid)
        trial.report(intermediate_value, step)

        if trial.should_prune():
            raise optuna.TrialPruned()

    return clf.score(X_valid, y_valid)


study = optuna.create_study(
    direction="maximize", pruner=optuna.pruners.SuccessiveHalvingPruner()
)
study.optimize(objective, n_trials=20)
Parameters:
  • min_resource (str | int) –

    試行に割り当てる最小リソースを指定するパラメータ(論文中では \(r\) と表記) デフォルト値は ‘auto’ で、最初の試行が完了するまでに必要なステップ数に基づいて決定されます。

    試行は \(\mathsf{min}\_\mathsf{resource} \times \mathsf{reduction}\_\mathsf{factor}^{ \mathsf{min}\_\mathsf{early}\_\mathsf{stopping}\_\mathsf{rate}}\) ステップ(最初の段の完了時点)まで実行されるまでは削除されません。最初の段を完了した試行は、 その時点での全試行の上位 \({1 \over \mathsf{reduction}\_\mathsf{factor}}\) の割合に入る場合のみ次の段に昇格します(それ以外の場合は削除されます)。 競争に勝利した場合、次の完了時点(\(\mathsf{min}\_\mathsf{resource} \times \mathsf{reduction}\_\mathsf{factor}^{ (\mathsf{min}\_\mathsf{early}\_\mathsf{stopping}\_\mathsf{rate} + \mathsf{rung})}\) ステップ)まで実行され、同じ手順が繰り返されます。

    Note

    最後の中間値のステップ数が試行ごとに異なる可能性がある場合、min_resource に最小ステップ数を手動で指定してください。

  • reduction_factor (int) – 昇格可能な試行の削減率を指定するパラメータ(論文中では \(\eta\) と表記) 各段の完了時点で、約 \({1 \over \mathsf{reduction}\_\mathsf{factor}}\) の割合の試行が昇格されます。

  • min_early_stopping_rate (int) – 最小早期停止率を指定するパラメータ(論文中では \(s\) と表記)

  • bootstrap_count (int) – 次の段への昇格を検討する前に、完了する必要がある試行の最小数

メソッド

prune(study, trial)

Judge whether the trial should be pruned based on the reported values.

prune(study, trial)[source]

報告された値に基づいて、試行を剪定すべきかどうかを判定します。

このメソッドはライブラリの利用者が直接呼び出すものではありません。代わりに、 optuna.trial.Trial.report()optuna.trial.Trial.should_prune() が 目的関数内で剪定機構を実装するためのインターフェースを提供します。

Parameters:
  • study (Study) – 対象のスタディオブジェクト

  • trial (FrozenTrial) – 対象のトライアルオブジェクト(FrozenTrial) このオブジェクトを変更する前に、必ずコピーを作成してください。

Returns:

トライアルを剪定すべきかどうかを示す真偽値

Return type:

bool