I want suggest ratio in Optuna.
The ratio is X_1, X_2, ..., X_k
bounded to ∑X_i = 1
and 0 <= X_i <= 1
for all i
.
Optuna doesn't offer Dirichlet distribution.
I tried this but it doesn't work.
def objective(trial):
k = 10
ratios = np.zeros(k)
residual = 1
for i in range(k - 1):
ratios[i] = trial.suggest_float(f'ratio_{i}', 0, residual)
residual -= ratios[i]
# ratios[k - 1] = trial.suggest_float(f'ratio_{k - 1}', residual, residual)
ratios[k - 1] = residual
return np.log(ratios).sum()
study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=20)
And I tried this and finished without any errors. However, this is inconsistent because degree of freedom is k - 1
for the bound but suggest k
times.
def objective(trial):
k = 10
ratios = np.zeros(k)
for i in range(k):
ratios[i] = trial.suggest_float(f'ratio_{i}', 0, 1)
ratios /= ratios.sum()
return np.log(ratios).sum()
study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=20)
How can I suggest ratio or multiple variables with bound?
This is a simple example so it's differentiable but I need variables in more complex objective.
question from:
https://stackoverflow.com/questions/65713063/how-to-suggest-multivariate-of-ratio-with-bound-in-optuna 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…