定义 x , y ∈ ( − 10 , 10 ) x,y\in(-10, 10) x,y∈(−10,10),求 f ( x ) = ( x + y ) 2 f(x)=(x+y)^2 f(x)=(x+y)2取得最大值时, x , y x,y x,y的取值?
import optuna
def objective(trial):
x = trial.suggest_uniform(‘x’, -10, 10)
y = trial.suggest_uniform(‘y’, -10, 10)
return (x + y) ** 2
study = optuna.create_study(direction=‘maximize’)
study.optimize(objective, n_trials=100)
print(study.best_params)
print(study.best_value)