optuna.trial.FrozenTrial¶
-
class
optuna.trial.FrozenTrial(number: int, state: optuna.trial._state.TrialState, value: Optional[float], datetime_start: Optional[datetime.datetime], datetime_complete: Optional[datetime.datetime], params: Dict[str, Any], distributions: Dict[str, optuna.distributions.BaseDistribution], user_attrs: Dict[str, Any], system_attrs: Dict[str, Any], intermediate_values: Dict[int, float], trial_id: int)[source]¶ Status and results of a
Trial.This object has the same methods as
Trial, and it suggests best parameter values among performed trials. In contrast toTrial,FrozenTrialdoes not depend onStudy, and it is useful for deploying optimization results.Example
Re-evaluate an objective function with parameter values optimized study.
import optuna def objective(trial): x = trial.suggest_uniform("x", -1, 1) return x ** 2 study = optuna.create_study() study.optimize(objective, n_trials=3) assert objective(study.best_trial) == study.best_value
Note
Attributes are set in
optuna.Study.optimize(), but several attributes can be updated after the optimization. That means such attributes are overwritten by the re-evaluation if your objective updates attributes ofTrial.Example:
Overwritten attributes.
import copy import datetime import optuna def objective(trial): x = trial.suggest_uniform("x", -1, 1) # this user attribute always differs trial.set_user_attr("evaluation time", datetime.datetime.now()) return x ** 2 study = optuna.create_study() study.optimize(objective, n_trials=3) best_trial = study.best_trial best_trial_copy = copy.deepcopy(best_trial) # re-evaluate objective(best_trial) # the user attribute is overwritten by re-evaluation assert best_trial.user_attrs != best_trial_copy.user_attrs
Note
Please refer to
Trialfor details of methods and properties.-
number¶ Unique and consecutive number of
Trialfor eachStudy. Note that this field uses zero-based numbering.
-
state¶ TrialStateof theTrial.
-
params¶ Dictionary that contains suggested parameters.
-
user_attrs¶ Dictionary that contains the attributes of the
Trialset withoptuna.trial.Trial.set_user_attr().
-
intermediate_values¶ Intermediate objective values set with
optuna.trial.Trial.report().
Methods
report(value, step)Interface of report function.
set_system_attr(key, value)set_user_attr(key, value)Suggest whether the trial should be pruned or not.
suggest_categorical(name, choices)suggest_discrete_uniform(name, low, high, q)suggest_float(name, low, high, *[, step, log])suggest_int(name, low, high[, step, log])suggest_loguniform(name, low, high)suggest_uniform(name, low, high)Attributes
Dictionary that contains the distributions of
params.Return the elapsed time taken to complete the trial.
Return the maximum step of intermediate_values in the trial.
system_attrs-
property
duration¶ Return the elapsed time taken to complete the trial.
- Returns
The duration.
-
property
last_step¶ Return the maximum step of intermediate_values in the trial.
- Returns
The maximum step of intermediates.
-
report(value: float, step: int) → None[source]¶ Interface of report function.
Since
FrozenTrialis not pruned, this report function does nothing.See also
Please refer to
should_prune().- Parameters
value – A value returned from the objective function.
step – Step of the trial (e.g., Epoch of neural network training). Note that pruners assume that
stepstarts at zero. For example,MedianPrunersimply checks ifstepis less thann_warmup_stepsas the warmup mechanism.
-