コード例 #1
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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'
コード例 #2
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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())
コード例 #3
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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())
コード例 #4
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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())
コード例 #5
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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())
コード例 #6
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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())
コード例 #7
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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())
コード例 #8
0
ファイル: test_space.py プロジェクト: Delaunay/sample-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())
コード例 #9
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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())
コード例 #10
0
ファイル: test_space.py プロジェクト: Delaunay/sample-space
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
コード例 #11
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))
コード例 #12
0
ファイル: scratch.py プロジェクト: bouthilx/sample-space
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')])]