optuna.pruners.ThresholdPruner
- class optuna.pruners.ThresholdPruner(lower=None, upper=None, n_warmup_steps=0, interval_steps=1)[源代码]
Pruner to detect outlying metrics of the trials.
Prune if a metric exceeds upper threshold, falls behind lower threshold or reaches
nan
.示例
from optuna import create_study from optuna.pruners import ThresholdPruner from optuna import TrialPruned def objective_for_upper(trial): for step, y in enumerate(ys_for_upper): trial.report(y, step) if trial.should_prune(): raise TrialPruned() return ys_for_upper[-1] def objective_for_lower(trial): for step, y in enumerate(ys_for_lower): trial.report(y, step) if trial.should_prune(): raise TrialPruned() return ys_for_lower[-1] ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2] ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1] study = create_study(pruner=ThresholdPruner(upper=1.0)) study.optimize(objective_for_upper, n_trials=10) study = create_study(pruner=ThresholdPruner(lower=0.0)) study.optimize(objective_for_lower, n_trials=10)
- Args
- lower:
A minimum value which determines whether pruner prunes or not. If an intermediate value is smaller than lower, it prunes.
- upper:
A maximum value which determines whether pruner prunes or not. If an intermediate value is larger than upper, it prunes.
- n_warmup_steps:
Pruning is disabled if the step is less than the given number of warmup steps.
- interval_steps:
Interval in number of steps between the pruning checks, offset by the warmup steps. If no value has been reported at the time of a pruning check, that particular check will be postponed until a value is reported. Value must be at least 1.
Methods
prune
(study, trial)Judge whether the trial should be pruned based on the reported values.
- 参数
- 返回类型
None
- prune(study, trial)[源代码]
Judge whether the trial should be pruned based on the reported values.
Note that this method is not supposed to be called by library users. Instead,
optuna.trial.Trial.report()
andoptuna.trial.Trial.should_prune()
provide user interfaces to implement pruning mechanism in an objective function.- 参数
study (optuna.study.Study) – Study object of the target study.
trial (optuna.trial._frozen.FrozenTrial) – FrozenTrial object of the target trial. Take a copy before modifying this object.
- 返回
A boolean value representing whether the trial should be pruned.
- 返回类型