« Back to top page

AutoSampler

This sampler automatically chooses an appropriate built-in sampler for the provided objective function.

Abstract

This package automatically selects an appropriate sampler for the provided search space based on the developers’ recommendation.

Class or Function Names

  • AutoSampler

This sampler currently accepts only seed and constraints_func. constraints_func enables users to handle constraints along with the objective function. These arguments follow the same convention as the other samplers, so please take a look at the reference.

Installation

This sampler requires optional dependencies of Optuna.

$ pip install optunahub cmaes torch scipy

Note that since we may update the implementation of AutoSampler, it is highly encouraged to use the latest version of Optuna.

Example

import optuna
import optunahub


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


module = optunahub.load_module(package="samplers/auto_sampler")
study = optuna.create_study(sampler=module.AutoSampler())
study.optimize(objective, n_trials=300)

Test

To execute the tests for AutoSampler, please run the following commands. The test file is provided in the package.

pip install pytest
pytest package/samplers/auto_sampler/tests/
Package
samplers/auto_sampler
Author
Optuna Team
License
MIT License
Verified Optuna version
  • 4.1.0
Last update
2024-10-31