Esempio n. 1
0
    def test_generate(self):
        d1 = ContinuousDomain(uniform, path='a', loc=0.0, scale=1.0)
        d2 = DiscreteDomain(list(range(1000)), path='b')

        # Test with one continuous domain
        m = self.__model_class__(domains=[d1])
        for _ in range(1000):
            p = m.generate()
            assert 'a' in p
            assert p['a'] >= 0 and p['a'] < 1

        # Test with one discrete domain
        m = self.__model_class__(domains=[d2])
        for _ in range(1000):
            p = m.generate()
            assert 'b' in p
            assert p['b'] >= 0 and p['b'] < 1000

        # Test with one continuous and one discrete domain
        m = self.__model_class__(domains=[d1, d2])
        for _ in range(1000):
            p = m.generate()
            assert 'a' in p
            assert p['a'] >= 0 and p['a'] < 1
            assert 'b' in p
            assert p['b'] >= 0 and p['b'] < 1000

        # Test with one continuous and one discrete domain within one sublevel
        d1.path = 'A/a'
        d2.path = 'A/b'
        m = self.__model_class__(domains=[d1, d2])
        for _ in range(1000):
            p = m.generate()
            assert 'A' in p
            assert 'a' in p['A']
            assert p['A']['a'] >= 0 and p['A']['a'] < 1
            assert 'b' in p['A']
            assert p['A']['b'] >= 0 and p['A']['b'] < 1000

        # Test with one continuous and one discrete domain within two sublevels
        d1.path = 'B/a'
        d2.path = 'A/b'
        m = self.__model_class__(domains=[d1, d2])
        for _ in range(1000):
            p = m.generate()
            assert 'A' in p
            assert 'B' in p
            assert 'a' in p['B']
            assert p['B']['a'] >= 0 and p['B']['a'] < 1
            assert 'b' in p['A']
            assert p['A']['b'] >= 0 and p['A']['b'] < 1000
Esempio n. 2
0
    def test_generate(self):
        d1 = ContinuousDomain(uniform, path='a', loc=-100.0, scale=100.0)
        d2 = DiscreteDomain([i for i in range(-100, 0)] +
                            [i for i in range(1, 101)], path='b')

        # Test with one continuous domain
        m = self.__model_class__(domains=[d1])
        for _ in range(1000):
            p = m()[-1]
            m.add_result(Result(m, loss=p['a']**2, values=Value(p['a'], d1)))
            assert 'a' in p
            assert p['a'] >= -100.0 and p['a'] < 100

        # Test with one continuous domain
        m = self.__model_class__(domains=[d2])
        for _ in range(1000):
            p = m()[-1]
            m.add_result(Result(m, loss=p['b']**2, values=Value(p['b'], d2)))
            assert 'b' in p
            assert p['b'] >= -100 and p['b'] <= 100

        # Test with one continuous and one discrete domain
        m = self.__model_class__(domains=[d1, d2])
        for _ in range(1000):
            p = m()[-1]
            m.add_result(Result(m, loss=p['a'] * p['b'],
                                values=[Value(p['a'], d1), Value(p['b'], d2)]))
            assert 'a' in p
            # assert p['a'] >= -100 and p['a'] < 100
            assert 'b' in p
            assert p['b'] >= -100 and p['b'] <= 100
Esempio n. 3
0
def choice(choices):
    """Random selection from an arbitrary set of values.

    This domain performs randint sampling from a set of aarbitrary values,
    allowing for randomly selecting strings, tuples, arbitrary collections of
    numbers, etc.

    Parameters
    ----------
    choices : list
        List of values to choose from.

    Returns
    -------
    domain : `pyrameter.DiscreteDomain`
    """
    return DiscreteDomain(choices)
Esempio n. 4
0
def randint(lo, hi, step=1):
    """Uniform distribution over a sequence of integers.

    The distribution is over the integer sequence [``lo``, ``hi``) with step
    ``step`` spacing.

    Parameters
    ----------
    lo : int
        Lower bound of the sequence.
    hi : int
        Upper bound of the sequence.
    step : int, optional
        Step between members of the sequence.

    Returns
    -------
    domain : `pyrameter.DiscreteDomain`
    """
    return DiscreteDomain(list(range(lo, hi, step)))
Esempio n. 5
0
def log2_randint(lo, hi, step=1):
    """Log 2-scaled uniform distribution over a sequence of integers.

    The distribution is over the integer sequence [``lo``, ``hi``) with step
    ``step`` spacing. Sampled values ``x`` are scaled by ``2**x`` before
    being returned.

    Parameters
    ----------
    lo : int
        Lower bound of the sequence.
    hi : int
        Upper bound of the sequence.
    step : int, optional
        Step between members of the sequence.

    Returns
    -------
    domain : `pyrameter.DiscreteDomain`
    """
    return DiscreteDomain([log2(i) for i in range(lo, hi, step)])