Пример #1
0
def distractor():
    """
    This is a nasty function: it has a max in a spike near -10, and a long
    asymptote that is easy to find, but guides hill-climbing approaches away
    from the true max.

    The second peak is at x=-10.
    The prior mean is 0.
    """

    x = hp.uniform('x', -15, 15)
    f1 = old_div(1.0, (1.0 + scope.exp(-x)))    # climbs rightward from 0.0 to 1.0
    f2 = 2 * scope.exp(-(x + 10) ** 2)  # bump with height 2 at (x=-10)
    return {'loss': -f1 - f2, 'status': base.STATUS_OK}
Пример #2
0
def gauss_wave():
    """
    Essentially, this is a high-frequency sinusoidal function plus a broad quadratic.
    One variable controls the position along the curve.
    The binary variable determines whether the sinusoidal is shifted by pi.

    So there are actually two maxima in this problem, it's just one is more
    probable.  The tricky thing here is dealing with the fact that there are two
    variables and one is discrete.

    """

    x = hp.uniform("x", -20, 20)
    t = hp.choice("curve", [x, x + np.pi])
    f1 = scope.sin(t)
    f2 = 2 * scope.exp(-((old_div(t, 5.0)) ** 2))
    return {"loss": -(f1 + f2), "status": base.STATUS_OK}
Пример #3
0
def gauss_wave():
    """
    Essentially, this is a high-frequency sinusoidal function plus a broad quadratic.
    One variable controls the position along the curve.
    The binary variable determines whether the sinusoidal is shifted by pi.

    So there are actually two maxima in this problem, it's just one is more
    probable.  The tricky thing here is dealing with the fact that there are two
    variables and one is discrete.

    """

    x = hp.uniform('x', -20, 20)
    t = hp.choice('curve', [x, x + np.pi])
    f1 = scope.sin(t)
    f2 = 2 * scope.exp(-(old_div(t, 5.0)) ** 2)
    return {'loss': - (f1 + f2), 'status': base.STATUS_OK}
Пример #4
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.
    """

    rng = np.random.RandomState(123)
    var = .1
    x = hp.uniform('x', -20, 20)
    amp = hp.uniform('amp', 0, 1)
    t = (scope.normal(0, var, rng=rng) + 2 * scope.exp(-(old_div(x, 5.0)) ** 2))
    return {'loss': - hp.choice('hf', [t, t + scope.sin(x) * amp]),
            'loss_variance': var, 'status': base.STATUS_OK}
Пример #5
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.
    """

    rng = np.random.default_rng(123)
    var = 0.1
    x = hp.uniform("x", -20, 20)
    amp = hp.uniform("amp", 0, 1)
    t = scope.normal(0, var, rng=rng) + 2 * scope.exp(-((old_div(x, 5.0))**2))
    return {
        "loss": -hp.choice("hf", [t, t + scope.sin(x) * amp]),
        "loss_variance": var,
        "status": base.STATUS_OK,
    }