Class or Function Names
- TPESampler
APIs
TPESampler(...)- This is Optuna’s TPE sampler with support for
categorical_distance_func. categorical_distance_func: A mapping from categorical parameter names to distance functions. Each function receives two choices and returns a non-negative distance.
- This is Optuna’s TPE sampler with support for
Example
import optuna
import optunahub
module = optunahub.load_module(package="samplers/tpe_cat_distance")
def hamming_distance(x: str, y: str) -> float:
return float(x != y)
sampler = module.TPESampler(
categorical_distance_func={"optimizer": hamming_distance},
)
study = optuna.create_study(sampler=sampler)
def objective(trial):
optimizer = trial.suggest_categorical("optimizer", ["adam", "sgd"])
return float(optimizer != "adam")
study.optimize(objective, n_trials=20)
Categorical distance
This package is based on the Optuna 5.1.0.dev TPESampler and restores categorical-distance
support using the Optuna 4.9 implementation as a behavioral reference.
Others
See the documentation for more details.
- Package
- samplers/tpe_cat_distance
- Author
- Optuna team
- License
- MIT License
- Verified Optuna version
- 5.1.0.dev
- Last update
- 2026-11-11
- Discussions & Issues
- Create a discussion
- Create a bug report