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

How to update/delete a Hyperparameter from ConfigSpace? #296

Open
Doglovesfish opened this issue Feb 9, 2023 · 1 comment
Open

How to update/delete a Hyperparameter from ConfigSpace? #296

Doglovesfish opened this issue Feb 9, 2023 · 1 comment

Comments

@Doglovesfish
Copy link

Doglovesfish commented Feb 9, 2023

1.I want to update a Hyperparameter from ConfigSpace. Is there any API to do update/delete a Hyperparameter from ConfigSpace?

2.I also found that add_hyperparameters can't override the existed Hyperparameter. If I want to change upper and lower, I have to do this like

    hp = cs.get_hyperparameter(hp_name)
    hp.lower = 180
    hp.upper = 181
    hp.default_value = 180

In this way, a bug might occur. The following code cannot be executed:

from ConfigSpace import ConfigurationSpace, ForbiddenEqualsClause
from ConfigSpace import UniformIntegerHyperparameter


def get_configspace():
    cs = ConfigurationSpace()
    hp_name = 'cpu_num'
    hp_a = UniformIntegerHyperparameter(hp_name, 1, 10, default_value=6)
    cs.add_hyperparameter(hp_a)

    # change cs
    hp = cs.get_hyperparameter(hp_name)
    hp.lower = 180
    hp.upper = 200
    hp.default_value = 190

    # check
    print(cs)
    print(cs["cpu_num"])

    config = cs.sample_configuration()
    print(config)

    forbidden_clause_a = ForbiddenEqualsClause(cs[hp_name], 181)
    cs.add_forbidden_clause(forbidden_clause_a)


if __name__ == '__main__':
    cs = get_configspace()

image

image

@eddiebergman
Copy link
Contributor

eddiebergman commented Jul 12, 2024

Yup, in general, mutating attributes directly with thing.attr = new_value is not supported as there is a lot of caching going on for sampling efficiency.

But no, unfortunately no API for deleting/updating a particular Hyperparameter. The issues around this mainly concern how to handle situations where other parameters/conditions/forbiddens depend on the hyperparameter being update/deleted.

The best way is to create a new ConfigurationSpace with required update/deletion, handling conditionals as required. Perhaps in the future we could provide some utility to help with this with strategies for how to deal with these conflicts, however this would not be an in-place operation and instead return you a new ConfigurationSpace.

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

No branches or pull requests

2 participants