Closed yiliu30 closed 10 months ago
from ConfigSpace import ConfigurationSpace
top_level = ConfigurationSpace({"model": ["A", "B"]})
model_a_space = ConfigurationSpace({"one": (1, 10), "two": ["red", "green", "blue"]})
model_b_space = ConfigurationSpace({"three": (0.0, 1.0), "four": ["purple", "black"]})
for value, space in [("A", model_a_space), ("B", model_b_space)]:
top_level.add_configuration_space(
prefix=f"model:{value}",
configuration_space=space,
parent_hyperparameter={"parent": top_level["model"], "value": value},
)
print(top_level)
Configuration space object:
Hyperparameters:
model, Type: Categorical, Choices: {A, B}, Default: A
model:A:one, Type: UniformInteger, Range: [1, 10], Default: 6
model:A:two, Type: Categorical, Choices: {red, green, blue}, Default: red
model:B:four, Type: Categorical, Choices: {purple, black}, Default: purple
model:B:three, Type: UniformFloat, Range: [0.0, 1.0], Default: 0.5
Conditions:
model:A:one | model == 'A'
model:A:two | model == 'A'
model:B:four | model == 'B'
model:B:three | model == 'B'
Hi @eddiebergman, thanks for your quick reply. However, the above answer does not yield a sample including configuration for both A and B.
For example, the first two samples only include the configuration for model B.
for cfg in top_level.sample_configuration(2):
print(cfg)
Configuration(values={
'model': 'B',
'model:B:four': 'purple',
'model:B:three': 0.3936342825147082,
})
Configuration(values={
'model': 'B',
'model:B:four': 'purple',
'model:B:three': 0.9810660152366504,
})
Did you want to select a config from either A or B or for both A and B. You can control this with the parent_hyperparameter=
value
Did you want to select a config from either A or B or for both A and B. You can control this with the
parent_hyperparameter=
value
Hi, I want to select a config for both A and B.
from ConfigSpace import ConfigurationSpace
top_level = ConfigurationSpace()
model_a_space = ConfigurationSpace({"one": (1, 10), "two": ["red", "green", "blue"]})
model_b_space = ConfigurationSpace({"three": (0.0, 1.0), "four": ["purple", "black"]})
for value, space in [("A", model_a_space), ("B", model_b_space)]:
top_level.add_configuration_space(
prefix=f"model:{value}",
configuration_space=space,
)
print(top_level)
Thank you for your guidance, it's really helpful :)
Following the example in advanced usage, if I need to generate the config for both model A and model B in a single Config, for example:
Could you provide guidance on implementing it? Thank you.