Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

FanovaImportanceEvaluator mutates study.trials[-1].distributions when a parameter has dynamic range #23

Open
sgrubas opened this issue Feb 23, 2024 · 1 comment

Comments

@sgrubas
Copy link

sgrubas commented Feb 23, 2024

Hello,
Thank you for your great work!

I ran into an issue with using FanovaImportanceEvaluator. For some reason, it changes the last trial of a study when the search space of a parameter depends on another parameter. See the code snippet below:

import optuna
from optuna_fast_fanova import FanovaImportanceEvaluator
optuna.logging.set_verbosity(optuna.logging.WARNING)

def test_objective(trial):
    x = trial.suggest_float('x', 1, 4)
    y = trial.suggest_float('y', x, 5)
    return x**2 + y**2
    

test_study = optuna.create_study(study_name="Test", direction='minimize')
test_study.optimize(test_objective, n_trials=100, show_progress_bar=True)

importances = optuna.importance.get_param_importances(test_study, evaluator=FanovaImportanceEvaluator())
for trial in test_study.trials:
    if trial.distributions.keys() != trial.params.keys():
        print(trial)

The output:

FrozenTrial(number=99, state=TrialState.COMPLETE, values=[3.7186055946265806], 
datetime_start=datetime.datetime(2024, 2, 22, 18, 43, 50, 977310), 
datetime_complete=datetime.datetime(2024, 2, 22, 18, 43, 50, 981316), 
params={'x': 1.3032071826948155, 'y': 1.4213573208729824}, user_attrs={}, system_attrs={}, intermediate_values={}, 
distributions={'x': FloatDistribution(high=4.0, log=False, low=1.0, step=None)}, trial_id=99, value=None)

P.S. Usage of the default evaluator evaluator=None does not give this issue.

@sgrubas sgrubas changed the title FanovaImportanceEvaluator mutates study.trials[-1].distributions when a parameter's search space depends on another FanovaImportanceEvaluator mutates study.trials[-1].distributions when a parameter has dynamic range Feb 23, 2024
@sgrubas
Copy link
Author

sgrubas commented Feb 23, 2024

A follow-up question.
Currently, by default, Optuna does not properly calculate parameters importance, it skips those with dynamic ranges (the reproducible code is exactly as I attached above). This issue has been raised quite a few times and has not been implemented yet in Optuna (stale and closed issue example optuna/optuna#1856).
I am wondering if it is possible to resolve it at least in your FanovaImportanceEvaluator, so that the importances are calculated for all the parameters including those with dynamic ranges.

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant