Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix differential evolution #1150

Merged
merged 7 commits into from
Dec 5, 2024
Merged

Conversation

hadarshavit
Copy link

Fix for differential evolution acquisition function optimisation.
Fixing a bug that it didn't work when the configspace has categorical/integer hyperparameters.

@benjamc benjamc changed the base branch from main to development October 24, 2024 16:23
@benjamc
Copy link
Collaborator

benjamc commented Oct 24, 2024

Can you merge the current development branch into your branch?

@hadarshavit
Copy link
Author

Done

Copy link
Collaborator

@benjamc benjamc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle LGTM. Could you describe a bit more why we need this fix?
Why did it work before?

Oh and can you also update the CHANGELOG.md?
Thanks!

@hadarshavit
Copy link
Author

When using categorical hyperparameters differential evolution returned an exception.
For example, modifying the SVM example (examples/1_basics/2_svm_cv.py) to:

    initial_design = HyperparameterOptimizationFacade.get_initial_design(scenario, n_configs=5)
    acq_opt = DifferentialEvolution(classifier.configspace)

    # Now we use SMAC to find the best hyperparameters
    smac = HyperparameterOptimizationFacade(
        scenario,
        classifier.train,
        initial_design=initial_design,
        acquisition_maximizer=acq_opt,
        overwrite=True,  # If the run exists, we overwrite it; alternatively, we can continue from last state
    )

Results in:
ValueError: Got unexpected float value while trying to transform a vector representation into a value in ['linear' 'poly' 'rbf' 'sigmoid'].Expected integers but got [0.17368738] (dtype: float64)

The fix simply transforms float vectors (like the ones scipy's differential evolution outputs) to valid configs.
The test (tests/test_acquisition/test_maximizers.py) has a configspace of 2 float hyperparameters, and therefore passes.

@benjamc
Copy link
Collaborator

benjamc commented Nov 27, 2024

Can you add this as a test in test_maximizers.py? Then I'll merge
Thank you!

@benjamc benjamc added this to the v2.3 milestone Nov 27, 2024
@benjamc benjamc self-assigned this Nov 27, 2024
@benjamc benjamc added the fix label Nov 27, 2024
@benjamc benjamc added the bug label Dec 5, 2024
@benjamc benjamc merged commit 7042a94 into automl:development Dec 5, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants