#6874·optuna

# `categorical_distance_func` removal leaves categorical TPE with no similarity generalization and no Hub replacement

Author: thomasATbayerCreated Sep 29, 2026Updated Sep 30, 2026
Labelsbug

Expected behavior

categorical_distance_func removal leaves categorical TPE with no similarity generalization and no Hub replacement

Summary

v5.0.0 removed categorical_distance_func from TPESampler (#6783). The 4.9.0 release notes said this "advanced feature will be migrated to OptunaHub in the future" — but as of v5.0.0 no Hub package provides it. There is currently no supported path at all for domain-aware categorical distances, on any Optuna version going forward.

Why this matters for categorical data

Without a distance function, TPE's categorical kernel is one-hot: an observation puts mass only on the exact choice seen, and similar-but-unseen choices get nothing but prior mass. With the Gaussian distance kernel, mass generalizes across similar choices. Measured on the same observations [a, a, c] over choices [a, b, c], where b is similar to a and c is dissimilar to both:

observed stock 5.0 (no distance) 4.x distance kernel
a [0.71, 0.14, 0.14] — stuck on a [0.41, 0.41, 0.18] — generalizes to similar b
c [0.14, 0.14, 0.71] [0.23, 0.23, 0.54] — correctly stays on c

Any discrete space with a meaningful similarity — materials, hardware configurations, feature-engineering operators, grouped hyperparameters — loses the ability to generalize across related choices, which is precisely where model-based optimization beats random search on categorical spaces.

The Hub gap (surveyed Sep 2026)

  • tpe_union_multivariate vendors its own distance-aware estimator, but targets Optuna 4.7 with a different (union-space) algorithm — not a drop-in migration.
  • hierarchical_tpe merely forwards categorical_distance_func to core TPESampler, so it is broken on 5.0 in exactly the same way.
  • Nothing else in the registry mentions categorical distances.

Environment

  • Optuna version: 5.0.0
  • Python version: 3.12

Environment

Environment

  • Optuna version: 5.0.0
  • Python version: 3.12

Error messages, stack traces, or logs

bash
Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File ".../optuna/_convert_positional_args.py", line 127, in converter_wrapper
    return func(**kwargs)  # type: ignore[call-arg]
           ^^^^^^^^^^^^^^
TypeError: TPESampler.__init__() got an unexpected keyword argument 'categorical_distance_func'

Steps to reproduce

import optuna

def objective(trial): x = trial.suggest_categorical("x", ["a", "b", "c"]) return float(x == "a")

sampler = optuna.samplers.TPESampler( categorical_distance_func={"x": lambda a, b: 0.0 if a == b else 1.0}, seed=0, ) study = optuna.create_study(sampler=sampler) study.optimize(objective, n_trials=10)