Merge pull request #797 from optuna/fix-preferential-continuous-check

[Preferential] Fix enumerability check in PreferentialGPSampler
This commit is contained in:
c-bata
2024-02-07 08:55:09 +09:00
committed by GitHub
+5 -2
View File
@@ -389,7 +389,10 @@ class PreferentialGPSampler(optuna.samplers.BaseSampler):
def get_all_possible_params(dist: optuna.distributions.BaseDistribution) -> list[Any]:
if isinstance(dist, CategoricalDistribution):
return list(dist.choices)
elif isinstance(dist, (IntDistribution, FloatDistribution)):
elif (
isinstance(dist, (IntDistribution, FloatDistribution))
and dist.step is not None
):
return list(np.arange(dist.low, dist.high, dist.step))
else:
return []
@@ -401,7 +404,7 @@ class PreferentialGPSampler(optuna.samplers.BaseSampler):
is_all_discrete = all(
len(possible_params) > 0 for possible_params in all_possible_params.values()
)
search_space_size = np.prod(
search_space_size = math.prod( # Don't use np.prod to avoid overflow
[len(possible_params) for possible_params in all_possible_params.values()]
)
# TODO(contramundum53): Fix this arbitrarily chosen limit.