def make_space(backend='ConfigSapce'): space = Space(backend=backend) optim = space.categorical('optimizer', ['sgd', 'adam']) sgd_lr = space.loguniform('optimizer.lr', 1, 2, quantization=0.01) sgd_lr.enable_if(either(eq(optim, 'adam'), eq(optim, 'sgd'))) sgd_lr.forbid_equal(1) return space
def test_categorical(backend): space = Space(backend=backend) space.categorical('cat', ['a', 'b', 'c']) space.categorical('caw', a=0.2, b=0.1, c=0.7) space.categorical('cad', dict(a=0.2, b=0.1, c=0.7)) print(space.sample())
from sspace import Space, either, eq import json if __name__ == '__main__': space = Space(backend='ConfigSpace') optim = space.categorical('optimizer', ['sgd', 'adam']) sgd_lr = space.loguniform('optimizer.lr', 1, 2, quantization=0.01) sgd_lr.enable_if(either(eq(optim, 'adam'), eq(optim, 'sgd'))) sgd_lr.forbid_equal(1) for sample in space.sample(2): print(sample) print(json.dumps(space.serialize(), indent=2))