Ejemplo n.º 1
0
def test_repeatable():
    u = scope.uniform(0, 1)
    aa = as_apply(dict(u=u, n=scope.normal(5, 0.1), l=[0, 1, scope.one_of(2, 3), u]))
    dd1 = sample(aa, np.random.RandomState(3))
    dd2 = sample(aa, np.random.RandomState(3))
    dd3 = sample(aa, np.random.RandomState(4))
    assert dd1 == dd2
    assert dd1 != dd3
Ejemplo n.º 2
0
def test_repeatable():
    u = scope.uniform(0, 1)
    aa = as_apply(
        dict(u=u, n=scope.normal(5, 0.1), l=[0, 1, scope.one_of(2, 3), u]))
    dd1 = sample(aa, np.random.RandomState(3))
    dd2 = sample(aa, np.random.RandomState(3))
    dd3 = sample(aa, np.random.RandomState(4))
    assert dd1 == dd2
    assert dd1 != dd3
Ejemplo n.º 3
0
def test_sample():
    u = scope.uniform(0, 1)
    aa = as_apply(dict(u=u, n=scope.normal(5, 0.1), l=[0, 1, scope.one_of(2, 3), u]))
    print aa
    dd = sample(aa, np.random.RandomState(3))
    assert 0 < dd["u"] < 1
    assert 4 < dd["n"] < 6
    assert dd["u"] == dd["l"][3]
    assert dd["l"][:2] == (0, 1)
    assert dd["l"][2] in (2, 3)
Ejemplo n.º 4
0
def test_sample():
    u = scope.uniform(0, 1)
    aa = as_apply(
        dict(u=u, n=scope.normal(5, 0.1), l=[0, 1, scope.one_of(2, 3), u]))
    print aa
    dd = sample(aa, np.random.RandomState(3))
    assert 0 < dd['u'] < 1
    assert 4 < dd['n'] < 6
    assert dd['u'] == dd['l'][3]
    assert dd['l'][:2] == (0, 1)
    assert dd['l'][2] in (2, 3)
Ejemplo n.º 5
0
def n_arms(N=2):
    """
    Each arm yields a reward from a different Gaussian.

    The correct arm is arm 0.

    """
    x = hp_choice('x', [0, 1])
    reward_mus = as_apply([-1] + [0] * (N - 1))
    reward_sigmas = as_apply([1] * N)
    return {'loss': scope.normal(reward_mus[x], reward_sigmas[x]),
            'loss_variance': 1.0}
Ejemplo n.º 6
0
def n_arms(N=2):
    """
    Each arm yields a reward from a different Gaussian.

    The correct arm is arm 0.

    """
    x = hp_choice('x', [0, 1])
    reward_mus = as_apply([-1] + [0] * (N - 1))
    reward_sigmas = as_apply([1] * N)
    return {
        'loss': scope.normal(reward_mus[x], reward_sigmas[x]),
        'loss_variance': 1.0
    }
Ejemplo n.º 7
0
def n_arms(N=2):
    """
    Each arm yields a reward from a different Gaussian.

    The correct arm is arm 0.

    """
    rng = np.random.RandomState(123)
    x = hp_choice('x', [0, 1])
    reward_mus = as_apply([-1] + [0] * (N - 1))
    reward_sigmas = as_apply([1] * N)
    return {
        'loss': scope.normal(reward_mus[x], reward_sigmas[x], rng=rng),
        'loss_variance': 1.0,
        'status': base.STATUS_OK
    }
Ejemplo n.º 8
0
def gauss_wave2():
    """
    Variant of the GaussWave problem in which noise is added to the score
    function, and there is an option to either have no sinusoidal variation, or
    a negative cosine with variable amplitude.

    Immediate local max is to sample x from spec and turn off the neg cos.
    Better solution is to move x a bit to the side, turn on the neg cos and turn
    up the amp to 1.
    """

    var = .1
    x = hp_uniform('x', -20, 20)
    amp = hp_uniform('amp', 0, 1)
    t = (scope.normal(0, var) + 2 * scope.exp(-(x / 5.0) ** 2))
    return {'loss': - hp_choice('hf', [t, t + scope.sin(x) * amp]),
            'loss_variance': var}
Ejemplo n.º 9
0
def gauss_wave2():
    """
    Variant of the GaussWave problem in which noise is added to the score
    function, and there is an option to either have no sinusoidal variation, or
    a negative cosine with variable amplitude.

    Immediate local max is to sample x from spec and turn off the neg cos.
    Better solution is to move x a bit to the side, turn on the neg cos and turn
    up the amp to 1.
    """

    var = .1
    x = hp_uniform('x', -20, 20)
    amp = hp_uniform('amp', 0, 1)
    t = (scope.normal(0, var) + 2 * scope.exp(-(x / 5.0)**2))
    return {
        'loss': -hp_choice('hf', [t, t + scope.sin(x) * amp]),
        'loss_variance': var
    }
Ejemplo n.º 10
0
def hp_normal(label, *args, **kwargs):
    if not isinstance(label, basestring):
        raise TypeError("require string label")
    return scope.float(scope.hyperopt_param(label, scope.normal(*args, **kwargs)))
Ejemplo n.º 11
0
def hp_normal(label, *args, **kwargs):
    return scope.float(
        scope.hyperopt_param(label, scope.normal(*args, **kwargs)))
Ejemplo n.º 12
0
def hp_normal(label, *args, **kwargs):
    if not isinstance(label, basestring):
        raise TypeError('require string label')
    return scope.float(
        scope.hyperopt_param(label, scope.normal(*args, **kwargs)))
Ejemplo n.º 13
0
def hp_normal(label, *args, **kwargs):
    return scope.float(
            scope.hyperopt_param(label,
                scope.normal(*args, **kwargs)))
Ejemplo n.º 14
0
def opt_q_uniform(target):
    x = hp_quniform('x', 1.01, 10, 1)
    return {'loss': (x - target)**2 + scope.normal(0, 1)}
Ejemplo n.º 15
0
def opt_q_uniform(target):
    x = hp_quniform('x', 1.01, 10, 1)
    return {'loss': (x - target) ** 2 + scope.normal(0, 1)}