Ejemplo n.º 1
0
def test_moe_rest_1():
    moe_url = os.environ.get('MOE_API_URL', 'http://ERROR-sdjssfssdbsdf.com')
    try:
        request.urlopen(moe_url)
    except error.URLError:
        raise nose.SkipTest(
            'No available MOE REST API endpoint (set with '
            'MOE_API_URL environment variable)')

    searchspace = SearchSpace()
    searchspace.add_float('x', -10, 10)
    searchspace.add_float('y', 1, 10, warp='log')
    searchspace.add_int('z', -10, 10)
    searchspace.add_enum('w', ['opt1', 'opt2'])

    history = [(searchspace.rvs(), np.random.random(), 'SUCCEEDED')
               for _ in range(4)]
    params = MOE(url=moe_url).suggest(history, searchspace)
    for k, v in iteritems(params):
        assert k in searchspace.variables
        if isinstance(searchspace[k], EnumVariable):
            assert v in searchspace[k].choices
        elif isinstance(searchspace[k], FloatVariable):
            assert searchspace[k].min <= v <= searchspace[k].max
        elif isinstance(searchspace[k], IntVariable):
            assert searchspace[k].min <= v <= searchspace[k].max
        else:
            assert False
Ejemplo n.º 2
0
def test_2_2():
    s = SearchSpace()
    s.add_int('a', 0, 3)
    values = [
        pyll.stochastic.sample(s['a'].to_hyperopt()) for _ in xrange(200)
    ]
    _run_chi2_test(values, bin_edges=range(5))
Ejemplo n.º 3
0
def test_check_repeated_params():
    searchspace = SearchSpace()
    searchspace.add_enum('x', [1, 2])
    searchspace.add_jump('y', min=3, max=4, num=2)

    history = []
    grid_search1 = GridSearch()
    for _ in range(4):
        params = grid_search1.suggest(history, searchspace)
        history.append((params, 0.0, 'SUCCEEDED'))

    grid_search2 = GridSearch()
    for _ in range(4):
        params = grid_search2.suggest(history, searchspace)
        assert grid_search2.is_repeated_suggestion(params, history)

    history = []
    grid_search3 = GridSearch()
    for _ in range(4):
        params = grid_search3.suggest(history, searchspace)
        history.append((params, 0.0, 'FAILED'))

    grid_search4 = GridSearch()
    for _ in range(4):
        params = grid_search4.suggest(history, searchspace)
        assert not grid_search4.is_repeated_suggestion(params, history)
Ejemplo n.º 4
0
def test_4_1():
    s = SearchSpace()
    s.add_enum('c', [True, False])

    values = [s.rvs()['c'] for _ in range(100)]
    assert all(v in [True, False] for v in values)
    _run_chi2_test(np.array(values, dtype=int), bin_edges=range(3))
Ejemplo n.º 5
0
def test_4_1():
    s = SearchSpace()
    s.add_enum('c', [True, False])

    values = [s.rvs()['c'] for _ in range(100)]
    assert all(v in [True, False] for v in values)
    _run_chi2_test(np.array(values, dtype=int), bin_edges=range(3))
Ejemplo n.º 6
0
def test_3_1():
    s = SearchSpace()
    s.add_float('b', -2, 2)

    values = [s.rvs()['b'] for _ in range(100)]
    assert all(-2 < v < 2 for v in values)
    _run_chi2_test(values, bin_edges=np.linspace(-2, 2, 10))
Ejemplo n.º 7
0
def test_3_1():
    s = SearchSpace()
    s.add_float('b', -2, 2)

    values = [s.rvs()['b'] for _ in range(100)]
    assert all(-2 < v < 2 for v in values)
    _run_chi2_test(values, bin_edges=np.linspace(-2, 2, 10))
Ejemplo n.º 8
0
def test_3_2():
    s = SearchSpace()
    s.add_float('b', -2, 2)

    values = [pyll.stochastic.sample(s['b'].to_hyperopt())
              for _ in xrange(100)]
    assert all(-2 < v < 2 for v in values)
    _run_chi2_test(values, bin_edges=np.linspace(-2, 2, 10))
Ejemplo n.º 9
0
def test_grid():
    searchspace = SearchSpace()
    searchspace.add_enum('x', [1, 2])
    searchspace.add_jump('y', min=3, max=4, num=2)
    grid_search = GridSearch()
    suggestions = [grid_search.suggest([], searchspace) for _ in range(4)]
    suggestions = [(s['x'], s['y']) for s in suggestions]
    assert suggestions == [(1, 3), (1, 4), (2, 3), (2, 4)], "Didn't examine whole space correctly"
Ejemplo n.º 10
0
def test_4_2():
    s = SearchSpace()
    s.add_enum('c', [True, False])

    values = [pyll.stochastic.sample(s['c'].to_hyperopt())
              for _ in xrange(100)]
    assert all(v in [True, False] for v in values)
    _run_chi2_test(np.array(values, dtype=int), bin_edges=range(3))
Ejemplo n.º 11
0
def test_3_2():
    s = SearchSpace()
    s.add_float('b', -2, 2)

    values = [pyll.stochastic.sample(s['b'].to_hyperopt())
              for _ in xrange(100)]
    assert all(-2 < v < 2 for v in values)
    _run_chi2_test(values, bin_edges=np.linspace(-2, 2, 10))
Ejemplo n.º 12
0
def test_4_2():
    s = SearchSpace()
    s.add_enum('c', [True, False])

    values = [pyll.stochastic.sample(s['c'].to_hyperopt())
              for _ in xrange(100)]
    assert all(v in [True, False] for v in values)
    _run_chi2_test(np.array(values, dtype=int), bin_edges=range(3))
Ejemplo n.º 13
0
def test_5_2():
    s = SearchSpace()
    s.add_float('a', 1e-5, 1, warp='log')

    bin_edges = np.logspace(np.log10(s['a'].min), np.log10(s['a'].max), num=5)
    values = [pyll.stochastic.sample(s['a'].to_hyperopt())
              for _ in xrange(100)]

    _run_chi2_test(values, bin_edges)
Ejemplo n.º 14
0
def test_5_2():
    s = SearchSpace()
    s.add_float('a', 1e-5, 1, warp='log')

    bin_edges = np.logspace(np.log10(s['a'].min), np.log10(s['a'].max), num=5)
    values = [pyll.stochastic.sample(s['a'].to_hyperopt())
              for _ in xrange(100)]

    _run_chi2_test(values, bin_edges)
Ejemplo n.º 15
0
def test_5_1():
    s = SearchSpace()
    s.add_float('a', 1e-5, 1, warp='log')

    n_bins = 10
    n_samples = 1000

    bin_edges = np.logspace(np.log10(s['a'].min), np.log10(s['a'].max),
                            num=n_bins+1)
    values = [s.rvs()['a'] for _ in xrange(n_samples)]

    _run_chi2_test(values, bin_edges)
Ejemplo n.º 16
0
def test_5_1():
    s = SearchSpace()
    s.add_float('a', 1e-5, 1, warp='log')

    n_bins = 10
    n_samples = 1000

    bin_edges = np.logspace(np.log10(s['a'].min), np.log10(s['a'].max),
                            num=n_bins+1)
    values = [s.rvs()['a'] for _ in xrange(n_samples)]

    _run_chi2_test(values, bin_edges)
Ejemplo n.º 17
0
def our_x2_iterates(n_iters=100):
    history = []
    searchspace = SearchSpace()
    searchspace.add_float('x', -10, 10)
    random = np.random.RandomState(0)

    # note the switch of sign, because _our_ function hyperopt_tpe is
    # a maximizer, not a minimizer
    fn = lambda params: -params['x']**2

    for i in range(n_iters):
        params = HyperoptTPE(seed=random).suggest(history, searchspace)
        history.append((params, fn(params), 'SUCCEEDED'))

    return np.array([h[0]['x'] for h in history])
Ejemplo n.º 18
0
def our_x2_iterates(n_iters=100):
    history = []
    searchspace = SearchSpace()
    searchspace.add_float('x', -10, 10)
    random = np.random.RandomState(0)

    # note the switch of sign, because _our_ function hyperopt_tpe is
    # a maximizer, not a minimizer
    def fn(params):
        return -params['x']**2

    for i in range(n_iters):
        params = HyperoptTPE(seed=random).suggest(history, searchspace)
        history.append((params, fn(params), 'SUCCEEDED'))

    return np.array([h[0]['x'] for h in history])
Ejemplo n.º 19
0
def test_gp():
    searchspace = SearchSpace()
    searchspace.add_float('x', -10, 10)
    searchspace.add_float('y', 1, 10, warp='log')
    searchspace.add_int('z', -10, 10)
    searchspace.add_enum('w', ['opt1', 'opt2'])

    history = [(searchspace.rvs(), np.random.random(), 'SUCCEEDED')
               for _ in range(4)]
    params = GP().suggest(history, searchspace)
    for k, v in iteritems(params):
        assert k in searchspace.variables
        if isinstance(searchspace[k], EnumVariable):
            assert v in searchspace[k].choices
        elif isinstance(searchspace[k], FloatVariable):
            assert searchspace[k].min <= v <= searchspace[k].max
        elif isinstance(searchspace[k], IntVariable):
            assert searchspace[k].min <= v <= searchspace[k].max
        else:
            assert False
Ejemplo n.º 20
0
def test_check_repeated_params():
    searchspace = SearchSpace()
    searchspace.add_enum('x', [1, 2])
    searchspace.add_jump('y', min=3, max=4, num=2)

    history = []
    grid_search1 = GridSearch()
    for _ in range(4):
        params = grid_search1.suggest(history, searchspace)
        history.append((params, 0.0, 'SUCCEEDED'))

    grid_search2 = GridSearch()
    for _ in range(4):
        params = grid_search2.suggest(history, searchspace)
        assert grid_search2.is_repeated_suggestion(params, history)

    history = []
    grid_search3 = GridSearch()
    for _ in range(4):
        params = grid_search3.suggest(history, searchspace)
        history.append((params, 0.0, 'FAILED'))

    grid_search4 = GridSearch()
    for _ in range(4):
        params = grid_search4.suggest(history, searchspace)
        assert not grid_search4.is_repeated_suggestion(params, history)
Ejemplo n.º 21
0
def test_grid():
    searchspace = SearchSpace()
    searchspace.add_enum('x', [1, 2])
    searchspace.add_jump('y', min=3, max=4, num=2)
    grid_search = GridSearch()
    suggestions = [grid_search.suggest([], searchspace) for _ in range(4)]
    suggestions = [(s['x'], s['y']) for s in suggestions]
    assert suggestions == [(1, 3), (1, 4), (2, 3),
                           (2, 4)], "Didn't examine whole space correctly"
Ejemplo n.º 22
0
def test_1():
    s = SearchSpace()
    s.add_int('a', 1, 2)
    s.add_float('b', 2, 3)
    s.add_enum('c', ['a', 'b', 'c'])

    assert s.n_dims == 3

    assert s['a'].min == 1
    assert s['a'].max == 2
    assert s['a'].name == 'a'

    assert s['b'].min == 2
    assert s['b'].max == 3
    assert s['b'].name == 'b'

    assert s['c'].choices == ['a', 'b', 'c']
    assert s['c'].name == 'c'
Ejemplo n.º 23
0
def test_1():
    s = SearchSpace()
    s.add_int('a', 1, 2)
    s.add_float('b', 2, 3)
    s.add_enum('c', ['a', 'b', 'c'])

    assert s.n_dims == 3

    assert s['a'].min == 1
    assert s['a'].max == 2
    assert s['a'].name == 'a'

    assert s['b'].min == 2
    assert s['b'].max == 3
    assert s['b'].name == 'b'

    assert s['c'].choices == ['a', 'b', 'c']
    assert s['c'].name == 'c'
Ejemplo n.º 24
0
def test_2_1():
    s = SearchSpace()
    s.add_int('a', 0, 3)

    values = [s.rvs()['a'] for _ in xrange(100)]
    _run_chi2_test(values, bin_edges=range(5))
Ejemplo n.º 25
0
def test_2_1():
    s = SearchSpace()
    s.add_int('a', 0, 3)

    values = [s.rvs()['a'] for _ in xrange(100)]
    _run_chi2_test(values, bin_edges=range(5))
Ejemplo n.º 26
0
def test_random():
    searchspace = SearchSpace()
    searchspace.add_float('x', -10, 10)
    random = np.random.RandomState(0)
    RandomSearch(seed=random).suggest([], searchspace)
Ejemplo n.º 27
0
def test_2_2():
    s = SearchSpace()
    s.add_int('a', 0, 3)
    values = [pyll.stochastic.sample(s['a'].to_hyperopt())
              for _ in xrange(200)]
    _run_chi2_test(values, bin_edges=range(5))
Ejemplo n.º 28
0
def test_gp():
    searchspace = SearchSpace()
    searchspace.add_float('x', -10, 10)
    searchspace.add_float('y', 1, 10, warp='log')
    searchspace.add_int('z', -10, 10)
    searchspace.add_enum('w', ['opt1', 'opt2'])

    history = [(searchspace.rvs(), np.random.random(), 'SUCCEEDED')
               for _ in range(4)]

    params = GP().suggest(history, searchspace)
    for k, v in iteritems(params):
        assert k in searchspace.variables
        if isinstance(searchspace[k], EnumVariable):
            assert v in searchspace[k].choices
        elif isinstance(searchspace[k], FloatVariable):
            assert searchspace[k].min <= v <= searchspace[k].max
        elif isinstance(searchspace[k], IntVariable):
            assert searchspace[k].min <= v <= searchspace[k].max
        else:
            assert False
Ejemplo n.º 29
0
def test_random():
    searchspace = SearchSpace()
    searchspace.add_float('x', -10, 10)
    random = np.random.RandomState(0)
    RandomSearch(seed=random).suggest([], searchspace)