Exemplo n.º 1
0
def make_big_space(backend='ConfigSpace'):
    def make_subspace(sspace):
        sspace.uniform('uniform_float', 0, 1)
        sspace.loguniform('loguniform_float', 2, 3)
        sspace.normal('normal_float', 0, 1)
        sspace.lognormal('lognormal_float', 2, 3)

        sspace.uniform('uniform_float_q', 0, 1, quantization=0.01)
        sspace.loguniform('loguniform_float_q', 2, 3, quantization=0.01)
        sspace.normal('normal_float_q', 0, 1, quantization=0.01)
        sspace.lognormal('lognormal_float_q', 2, 1, quantization=0.01)

        sspace.uniform('uniform_int', 0, 1, discrete=True)
        sspace.loguniform('loguniform_int', 2, 3, discrete=True)
        sspace.normal('normal_int', 0, 1, discrete=True)
        sspace.lognormal('lognormal_int', 2, 3, discrete=True)

        sspace.choices('choices', ['a', 'b', 'c', 'd'])
        sspace.ordinal('ordinal', ['a', 'b', 'c', 'd'])

        sspace.variable('epoch')
        sspace.identity('uid')

        return sspace

    space = Space(backend=backend)
    make_subspace(space)
    make_subspace(space.subspace('sub'))
    return space
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def test_conditions_or():
    space = Space('ConfigSpace')

    a = space.normal('a', 1, 2, quantization=0.01)
    b = space.normal('b', 1, 2, quantization=0.01)
    b.enable_if(either(eq(a, 1), ne(a, 2)))
    print(space.sample())
Exemplo n.º 4
0
def test_forbid_and():
    space = Space('ConfigSpace')

    a = space.uniform('a', 1, 2, quantization=0.01)
    a.forbid_equal(1)
    a.forbid_in([1, 2])
    print(space.sample())
Exemplo n.º 5
0
def test_conditions_in():
    space = Space('ConfigSpace')

    a = space.normal('a', 1, 2, quantization=0.01)
    b = space.normal('b', 1, 2, quantization=0.01)
    b.enable_if(contains(a, [1, 1.5, 2]))
    print(space.sample())
Exemplo n.º 6
0
def test_conditions_and():
    space = Space('ConfigSpace')

    a = space.normal('a', 1, 2, quantization=0.01)
    b = space.normal('b', 1, 2, quantization=0.01)
    b.enable_if(both(gt(a, 1), lt(a, 2)))
    print(space.sample())
Exemplo n.º 7
0
def test_conditions(condition):
    space = Space('ConfigSpace')

    a = space.normal('a', 1, 2, quantization=0.01)
    b = space.normal('b', 1, 2, quantization=0.01)
    b.enable_if(condition(a, 1.5))
    print(space.sample())
Exemplo n.º 8
0
def test_subspace(backend):
    space = Space(backend=backend)

    space.normal('a', 1, 2, quantization=0.01)
    subspace = space.subspace('b')
    subspace.normal('a', 1, 2, quantization=0.01)

    print(space.sample())
Exemplo n.º 9
0
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())
Exemplo n.º 10
0
def test_ordinal(backend):
    space = Space(backend=backend)

    try:
        space.ordinal('ord', ['a', 'b', 'c'])

        print(space.sample())
        print(space.sample())
        print(space.sample())
    except NotImplementedError:
        assert backend == 'Orion'
Exemplo n.º 11
0
def test_uniform(backend):
    space = Space(backend=backend)

    for discrete in [True, False]:
        for log in [True, False]:
            for q in [None, 0.01, 1]:
                space.uniform(f'a_{discrete}_{log}_{q}', 1, 2,
                              discrete=discrete,
                              log=log,
                              quantization=q)

    print(space.sample())
Exemplo n.º 12
0
def test_normal(backend):
    for discrete in [True, False]:
        for log in [True, False]:
            for q in [None, 0.01, 1]:
                space = Space(backend=backend)

                space.normal(f'a_{discrete}_{log}_{q}',
                             loc=1, scale=2,
                             discrete=discrete,
                             log=log,
                             quantization=q)

                try:
                    print(space.sample())
                except NotImplementedError:
                    assert backend == 'Orion' and log is True
Exemplo n.º 13
0
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))
Exemplo n.º 14
0
from sspace import Space


space = Space()
space.uniform('lr', 0, 1)
space.ordinal('epoch', [1, 2, 3])


s1 = space.sample(seed=0)
s2 = space.sample(seed=1)
s1p = space.sample(seed=0)


print(s1)
print(s2)
print(s1p)

# [OrderedDict([('epoch', 1), ('optimizer', 'adam')])]
# [OrderedDict([('epoch', 2), ('optimizer', 'adam')])]
# [OrderedDict([('epoch', 1), ('optimizer', 'adam')])]