How to use the mlopt.optimization.GreedyOptimizer function in mlopt

To help you get started, we’ve selected a few mlopt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pklauke / mlopt / tests / test_greedy_optimizer.py View on Github external
def test_init_correct_dimensions_best_coords_glob():
    """Test if the initialized best coordinates of all particles combined have the correct dimensions."""
    optimizer = GreedyOptimizer(func=opt_func, maximize=False)

    params = {'x': (-1, 1), 'y': (-1, 1)}
    optimizer.init(params=params, random_state=1)

    assert optimizer.coords.shape == (2,)
github pklauke / mlopt / tests / test_greedy_optimizer.py View on Github external
def test_update_monotonic_best_score_glob_maximize():
    """Test if the greedy optimizer monotonically converges for maximization problems."""
    optimizer = GreedyOptimizer(func=opt_func_inv, maximize=True)

    params = {'x': (-1, 1), 'y': (-1, 1)}
    optimizer.init(params=params, random_state=1)

    scores = [optimizer.score]
    for i in range(100):
        optimizer.update(params)
        scores.append(optimizer.score)

    assert all(scores[i+1] >= scores[i] for i in range(len(scores)-1))
github pklauke / mlopt / tests / test_greedy_optimizer.py View on Github external
def test_init_correct_dimensions_best_score_glob():
    """Test if the initialized best score has the correct dimension."""
    optimizer = GreedyOptimizer(func=opt_func, maximize=False)

    params = {'x': (-1, 1), 'y': (-1, 1)}
    optimizer.init(params=params, random_state=1)
    print('best score', optimizer.score)
    assert np.shape(optimizer.score) == ()
github pklauke / mlopt / tests / test_greedy_optimizer.py View on Github external
def test_update_monotonic_best_score_glob_minimize():
    """Test if the greedy optimizer monotonically converges for minimization problems."""
    optimizer = GreedyOptimizer(func=opt_func, maximize=False)

    params = {'x': (-1, 1), 'y': (-1, 1)}
    optimizer.init(params=params, random_state=1)

    scores = [optimizer.score]
    for i in range(100):
        optimizer.update(params)
        scores.append(optimizer.score)

    assert all(scores[i+1] <= scores[i] for i in range(len(scores)-1))
github pklauke / mlopt / tests / test_greedy_optimizer.py View on Github external
def test_coord_history_correct_dimension():
    """Test if the saved particles coordinate history has the correct dimensions."""
    optimizer = GreedyOptimizer(func=opt_func, maximize=False)

    params = {'x': (-1, 1), 'y': (-1, 1)}
    optimizer.optimize(params, iterations=20)

    history = optimizer.coords_history

    assert len(history) == 21