Skip to content

Commit

Permalink
example: multi-armed bandit samplers.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota717 committed Sep 25, 2024
1 parent 1301fdb commit b728e4e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions package/samplers/multi_armed_bandit/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import optuna
import optunahub


if __name__ == "__main__":
module = optunahub.load_module(
package="samplers/multi_armed_bandit",
)
sampler = module.MultiArmedBanditSampler()

def objective(trial: optuna.Trial) -> float:
x = trial.suggest_categorical("arm_1", [1, 2, 3])
y = trial.suggest_categorical("arm_2", [1, 2])

return x + y

study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=20)

print(study.best_trial.value, study.best_trial.params)

0 comments on commit b728e4e

Please sign in to comment.