0

我的代码:

import optuna


def objective(trial):
    x = trial.suggest_float('x', -100.0, 100.0)
    y = trial.suggest_float('y', -100.0, 100.0)
    return x**2 + y**2

study = optuna.create_study(sampler=optuna.samplers.CmaEsSampler(x0={'x':0,'y':0}))
study.optimize(objective, n_trials=100,show_progress_bar=True)

然后输出

[I 2021-04-23 01:45:02,653] Trial 0 finished with value: 6714.428295151254 and parameters: {'x': 63.88749911037144, 'y': 51.310971074162524}. Best is trial 0 with value: 6714.428295151254.
[I 2021-04-23 01:45:02,663] Trial 1 finished with value: 1135.0978476605947 and parameters: {'x': 29.936795325284184, 'y': 15.45594168314043}. Best is trial 1 with value: 1135.0978476605947.
[I 2021-04-23 01:45:02,681] Trial 2 finished with value: 3149.451283583515 and parameters: {'x': 25.743779033527815, 'y': -49.866914128071016}. Best is trial 1 with value: 1135.0978476605947.

为什么算法不按照我给的x0做初值

4

1 回答 1

0

x0 不是参数建议,它由 cmaes 采样器后面的库使用。

x0:
            A dictionary of an initial parameter values for CMA-ES. By default, the mean of ``low``
            and ``high`` for each distribution is used. Note that ``x0`` is sampled uniformly
            within the search space domain for each restart if you specify ``restart_strategy``
            argument.

https://optuna.readthedocs.io/en/stable/_modules/optuna/samplers/_cmaes.html#CmaEsSampler

于 2021-10-23T11:36:26.267 回答