Class PatientPruner
- Namespace
- OptunaSharp.Pruners
- Assembly
- OptunaSharp.dll
Pruner which wraps another pruner with tolerance.
Port of optuna/pruners/_patient.py: PatientPruner (experimental since 2.8.0).
This pruner monitors intermediate values in a trial and prunes the trial if the improvement in the intermediate values after a patience period is less than a threshold.
The pruner handles NaN values in the following manner:
- If all intermediate values before or during the patient period are NaN, the trial will not be pruned.
- During the pruning calculations, NaN values are ignored. Only valid numeric values are considered.
public class PatientPruner : BasePruner
- Inheritance
-
PatientPruner
- Inherited Members
Constructors
PatientPruner(BasePruner?, int, double)
Configures the report-history tolerance required before allowing a wrapped pruning decision.
public PatientPruner(BasePruner? wrappedPruner, int patience, double minDelta = 0)
Parameters
wrappedPrunerBasePrunerWrapped pruner to perform pruning when PatientPruner allows a trial to be pruned. If it is
null, this pruner is equivalent to early-stopping taken the intermediate values in the individual trial.patienceintPruning is disabled until the objective doesn't improve for
patienceconsecutive steps.minDeltadoubleTolerance value to check whether or not the objective improves. Must be non-negative.
Exceptions
- ValueError
Patience or the minimum improvement tolerance is negative.
Methods
Prune(Study, FrozenTrial)
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, Report(double, long) and ShouldPrune() provide user interfaces to implement pruning mechanism in an objective function.
public override bool Prune(Study study, FrozenTrial trial)
Parameters
studyStudyStudy object of the target study.
trialFrozenTrialFrozenTrial object of the target trial. Take a copy before modifying this object.
Returns
- bool
A boolean value representing whether the trial should be pruned.
Exceptions
- RuntimeError
The study has multiple objectives and the pruning rule requests its scalar direction.
- Exception
The wrapped pruner fails; its exception propagates once the patience rule permits pruning.