Search code examples
pythonoptuna

Force one specific set of parameters into the sampled batch


I am trying to test different set of parameters in a ML algorithm using Optuna.

The automatic sampling of Optuna is very useful, but is there any way to force one specific set of parameters into the proposed batch defined by Optuna?

For example if I have a x,y parameters:

def objective(trial)
   x = trial.suggest_uniform('x', -10, 10)
   y = trial.suggest_uniform('x', -5, 5)
   return (x+y-2)**2
study = optuna.create_study(study_name='study_name')
study.optimize(objective, n_trials=10)

I would also like to define one set of x=0.1, y=0.2 into the automatic generated one. Is this possible?

It could be interesting to compare the "intuitive" values of some ML algorithm with other values.


Solution

  • Yes. One way to do this would be to use a FixedTrial, which would show you the result of your intuitive guess.

    print(objective(optuna.trial.FixedTrial({'x': 0.1, 'y': 0.2})))