[Python] Optuna sample fixed parameter depending on another parameter

Discussão em 'Python' iniciado por Stack, Fevereiro 3, 2025.

  1. Stack

    Stack Membro Participativo

    In my setting I have an abstract situation like the following, which shall only function as an example case:

    base = trial.suggest_int(1, 3)
    power = trial.suggest_int(1, 10)
    # value = base ** power


    As when the base == 1 the power parameter becomes irrelevant and I would like to fix it to 1.

    For example:

    base = trial.suggest_int("base", 1, 3)
    if base == 1:
    # Different distribution! But still inside the other.
    power = trial.suggest_int("power", 1, 1)
    else:
    power = trial.suggest_int("power", 1, 10)


    While this works it creates later problems in the form of ValueErrors because the underlying distributions are not the same.


    How can I suggest a fixed value with the same parameter name that depends on another value that is sampled within the trial?

    Continue reading...

Compartilhe esta Página