optuna.trial.create_trial

optuna.trial.create_trial(*, state=TrialState.COMPLETE, value=None, values=None, params=None, distributions=None, user_attrs=None, system_attrs=None, intermediate_values=None)[源代码]

Create a new FrozenTrial.

示例

import optuna
from optuna.distributions import CategoricalDistribution
from optuna.distributions import UniformDistribution

trial = optuna.trial.create_trial(
    params={"x": 1.0, "y": 0},
    distributions={
        "x": UniformDistribution(0, 10),
        "y": CategoricalDistribution([-1, 0, 1]),
    },
    value=5.0,
)

assert isinstance(trial, optuna.trial.FrozenTrial)
assert trial.value == 5.0
assert trial.params == {"x": 1.0, "y": 0}

参见

See add_trial() for how this function can be used to create a study from existing trials.

备注

Please note that this is a low-level API. In general, trials that are passed to objective functions are created inside optimize().

备注

When state is TrialState.COMPLETE, the following parameters are required: * params * distributions * value or values

参数
返回

Created trial.

引发

ValueError – If both value and values are specified.

返回类型

optuna.trial._frozen.FrozenTrial

备注

Added in v2.0.0 as an experimental feature. The interface may change in newer versions without prior notice. See https://github.com/optuna/optuna/releases/tag/v2.0.0.