我的代码:
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做初值