Esempio n. 1
0
def test_runs_bayes_runs2():
    np.random.seed(73)
    bs = bayes.BayesianSearch()
    r1 = Run('b', 'finished', {
        'v1': {
            'value': 7
        },
        'v2': {
            'value': 6
        }
    }, {'zloss': 1.2}, [
        {
            'loss': 1.2
        },
    ])
    r2 = Run('b', 'finished', {
        'v1': {
            'value': 1
        },
        'v2': {
            'value': 8
        }
    }, {'loss': 0.4}, [])
    # need two (non running) runs before we get a new set of parameters
    runs = [r1, r2]
    sweep = {'config': sweep_config_2params, 'runs': runs}
    params, info = bs.next_run(sweep)
    assert params['v1']['value'] == 2 and params['v2']['value'] == 9
Esempio n. 2
0
def test_runs_bayes():
    np.random.seed(73)
    bs = bayes.BayesianSearch()
    runs = []
    sweep = {'config': sweep_config_2params, 'runs': runs}
    params, info = bs.next_run(sweep)
    assert params['v1']['value'] == 7 and params['v2']['value'] == 6
Esempio n. 3
0
 def to_class(config):
     method = config.get('method')
     if method is None:
         raise ValueError('config missing required "method" field.')
     method = method.lower()
     if method == 'grid':
         return grid_search.GridSearch()
     elif method == 'bayes':
         return bayes_search.BayesianSearch()
     elif method == 'random':
         return random_search.RandomSearch()
     raise ValueError('method "%s" is not supported' % config['method'])
Esempio n. 4
0
def test_runs_bayes_runs2_missingmetric():
    np.random.seed(73)
    bs = bayes.BayesianSearch()
    r1 = Run('b', 'finished', {
        'v1': {
            'value': 7
        },
        'v2': {
            'value': 5
        }
    }, {'xloss': 0.2}, [])
    runs = [r1, r1]
    sweep = {'config': sweep_config_2params, 'runs': runs}
    params, info = bs.next_run(sweep)
    assert params['v1']['value'] == 1 and params['v2']['value'] == 1
def test_runs_bayes_nan():
    np.random.seed(73)
    bs = bayes.BayesianSearch()
    r1 = Run('b', 'finished', {
        'v1': {
            'value': 7
        },
        'v2': {
            'value': 6
        }
    }, {}, [
        {
            'loss': float('NaN')
        },
    ])
    r2 = Run('b', 'finished', {
        'v1': {
            'value': 1
        },
        'v2': {
            'value': 8
        }
    }, {'loss': float('NaN')}, [])
    r3 = Run('b', 'finished', {
        'v1': {
            'value': 2
        },
        'v2': {
            'value': 3
        }
    }, {}, [
        {
            'loss': 'NaN'
        },
    ])
    r4 = Run('b', 'finished', {
        'v1': {
            'value': 4
        },
        'v2': {
            'value': 5
        }
    }, {'loss': 'NaN'}, [])
    # need two (non running) runs before we get a new set of parameters
    runs = [r1, r2, r3, r4]
    sweep = {'config': sweep_config_2params, 'runs': runs}
    params, info = bs.next_run(sweep)
    assert params['v1']['value'] == 10 and params['v2']['value'] == 2
Esempio n. 6
0
def test_runs_bayes_categorical_list():
    np.random.seed(73)
    bs = bayes.BayesianSearch()
    r1 = Run('b', 'finished', {
        'v1': {
            'value': [3, 4]
        },
        'v2': {
            'value': 5
        }
    }, {'acc': 0.2}, [])
    runs = [r1, r1]
    sweep = {'config': sweep_config_2params_categorical, 'runs': runs}
    params, info = bs.next_run(sweep)
    assert params['v1']['value'] == [(7, 8), ['9', [10, 11]]
                                     ] and params['v2']['value'] == 1