Exemplo n.º 1
0
def test_process_params():
    from EvoDAG.utils import RandomParameterSearch
    from EvoDAG import EvoDAG
    rs = RandomParameterSearch(npoints=1)
    args = [x for x in rs][0]
    evo = EvoDAG(**rs.process_params(args))
    params = evo.get_params()
    for k, v in args.items():
        if k in params:
            print(v, params[k])
            if hasattr(params[k], '__name__'):
                assert v == params[k].__name__
            else:
                assert v == params[k]
Exemplo n.º 2
0
def test_params():
    from EvoDAG.utils import RandomParameterSearch
    rs = RandomParameterSearch(npoints=734)
    l = np.unique([x['random_generations'] for x in rs])
    assert len(l) == 2
    l = np.unique([x['population_class'] for x in rs])
    assert len(l) == 2
Exemplo n.º 3
0
def test_constraints2():
    from EvoDAG.utils import RandomParameterSearch
    params = dict(popsize=[100, 1000],
                  population_class=['Generational', 'SteadyState'],
                  early_stopping_rounds=[100, 1000])
    rs = RandomParameterSearch(params=params, npoints=32, training_size=70)
    args = [x for x in rs if x['population_class'] == 'Generational']
    assert len(args) == 1
Exemplo n.º 4
0
def test_iter_params():
    from EvoDAG.utils import RandomParameterSearch
    params = dict(popsize=[100, 1000],
                  population_class=['SteadyState'],
                  early_stopping_rounds=[50, 1000])
    rs = RandomParameterSearch(params=params, npoints=5)
    args = [x for x in rs]
    assert len(args) == 4
Exemplo n.º 5
0
def test_random_parameter_search_len():
    from itertools import product
    from EvoDAG.utils import RandomParameterSearch
    params = {'a': [1, 2, 3], 'b': [-1, -2], 'c': ['a', 'b', 'c', 'd', 'e']}
    rs = RandomParameterSearch(params=params)
    params = sorted(params.items())
    a = product(*[x[1] for x in params])
    assert len([x for x in a]) == len(rs)
Exemplo n.º 6
0
def test_popsize_constraint():
    from EvoDAG.utils import RandomParameterSearch
    params = dict(popsize=[100, 1000],
                  population_class=['Generational', 'SteadyState'],
                  early_stopping_rounds=[100, 1000])
    rs = RandomParameterSearch(params=params, npoints=32, training_size=70)
    popsize = [x['popsize'] for x in rs]
    r = [x for x in popsize if x > 70]
    assert len(r) == 0
Exemplo n.º 7
0
def test_process_params():
    from EvoDAG.utils import RandomParameterSearch
    from EvoDAG import EvoDAG
    rs = RandomParameterSearch(npoints=1)
    args = [x for x in rs][0]
    evo = EvoDAG(**rs.process_params(args))
    params = evo.get_params()
    for k, v in args.items():
        if k in params:
            if k == 'generations':
                v = np.inf
            print(k, v, params[k])
            if isinstance(v, list):
                for a, b in zip(v, params[k]):
                    assert a == b.__name__
            elif hasattr(params[k], '__name__'):
                assert v == params[k].__name__
            else:
                assert v == params[k]
Exemplo n.º 8
0
def test_random_parameter_search_getitem():
    from itertools import product
    from EvoDAG.utils import RandomParameterSearch
    params = {'a': [1, 2, 3], 'b': [-1, -2], 'c': ['a', 'b', 'c', 'd', 'e']}
    rs = RandomParameterSearch(params=params)
    params = sorted(params.items())
    a = product(*[x[1] for x in params])
    for k, v in enumerate(a):
        v1 = [x[1] for x in sorted(rs[k].items())]
        print(v, v1)
        assert np.all([x == y for x, y in zip(v, v1)])
Exemplo n.º 9
0
def test_HGeneration_pr_variable():
    import json
    from EvoDAG.utils import RandomParameterSearch
    from EvoDAG import EvoDAG
    get_remote_data()
    params = json.loads(open('evodag.params').read())
    params['population_class'] = 'HGenerational'
    params['pr_variable'] = 1.0
    kw = RandomParameterSearch.process_params(params)
    y = cl.copy()
    try:
        EvoDAG(**kw).fit(X, y)
    except AssertionError:
        return
    assert False
Exemplo n.º 10
0
def test_HGeneration():
    import json
    import gzip
    import pickle
    from EvoDAG.utils import RandomParameterSearch
    from EvoDAG import EvoDAG

    get_remote_data()
    params = json.loads(open('evodag.params').read())
    try:
        with gzip.open('train.sp') as fpt:
            X = pickle.load(fpt)
            y = pickle.load(fpt)
    except ValueError:
        return
    params['population_class'] = 'HGenerational'
    kw = RandomParameterSearch.process_params(params)
    gp = EvoDAG(**kw).fit(X, y)
    assert gp
Exemplo n.º 11
0
def test_parameter_grid_results():
    from EvoDAG.utils import RandomParameterSearch
    a = RandomParameterSearch()
    assert len([x for x in a]) == 1468