我正在尝试使用 Optuna 对我的模型进行超参数调整。
我被困在一个我想定义具有对数正态/正态分布的搜索空间的地方。在hyperopt
使用中是可能的hp.lognormal
。suggest_
是否可以使用现有api 的组合来定义这样的空间Optuna
?
我正在尝试使用 Optuna 对我的模型进行超参数调整。
我被困在一个我想定义具有对数正态/正态分布的搜索空间的地方。在hyperopt
使用中是可能的hp.lognormal
。suggest_
是否可以使用现有api 的组合来定义这样的空间Optuna
?
您也许可以利用suggest_float(..., 0, 1)
(ie U(0, 1)) 的逆变换,因为 Optuna 目前不suggest_
直接为这两个分布提供变体。这个例子可能是一个起点https://gist.github.com/hvy/4ef02ee2945fe50718c71953e1d6381d
请在下面找到代码
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm
from scipy.special import erfcinv
import optuna
def objective(trial):
# Suggest from U(0, 1) with Optuna.
x = trial.suggest_float("x", 0, 1)
# Inverse transform into normal.
y0 = norm.ppf(x, loc=0, scale=1)
# Inverse transform into lognormal.
y1 = np.exp(-np.sqrt(2) * erfcinv(2 * x))
return y0, y1
if __name__ == "__main__":
n_objectives = 2 # Normal and lognormal.
study = optuna.create_study(
sampler=optuna.samplers.RandomSampler(),
# Could be "maximize". Does not matter for this demonstration.
directions=["minimize"] * n_objectives,
)
study.optimize(objective, n_trials=10000)
fig, axs = plt.subplots(n_objectives)
for i in range(n_objectives):
axs[i].hist(list(t.values[i] for t in study.trials), bins=100)
plt.show()