Ejemplo n.º 1
0
def test_crossentropy_sphere():
    optimizer = crossentropy.CrossEntropy(32, population_size=20)
    optimizer.optimize(problems.sphere_binary,
                       max_iterations=1000,
                       logging_func=lambda *args: optimize._print_fitnesses(
                           *args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 2
0
def test_gsa_sphere():
    optimizer = GSA(2, [-5.0] * 2, [5.0] * 2)
    optimizer.optimize(problems.sphere_real,
                       max_iterations=1000,
                       logging_func=lambda *args: optimize._print_fitnesses(
                           *args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 3
0
def test_genalg_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    optimizer = genalg.GenAlg(examplefunctions.ackley, 32, 
                              decode_func=examplefunctions.ackley_binary)
    optimizer._logging_func = lambda x, y, z : optimize._print_fitnesses(x, y, z, frequency=100)
    optimizer.optimize()
    assert optimizer.solution_found
Ejemplo n.º 4
0
def test_genalg_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    optimizer = GenAlg(32)
    optimizer.optimize(problems.ackley_binary,
                       logging_func=lambda *args: optimize._print_fitnesses(
                           *args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 5
0
def test_crossentropy_sphere():
    optimizer = crossentropy.CrossEntropy(32, population_size=20)
    optimizer.optimize(
        problems.sphere_binary,
        max_iterations=1000,
        logging_func=
        lambda *args: optimize._print_fitnesses(*args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 6
0
def test_gsa_sphere():
    optimizer = GSA(2, [-5.0] * 2, [5.0] * 2)
    optimizer.optimize(
        problems.sphere_real,
        max_iterations=1000,
        logging_func=
        lambda *args: optimize._print_fitnesses(*args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 7
0
def test_gsa_sphere():
    optimizer = gsa.GSA(examplefunctions.sphere,
                        2, [-5.0] * 2, [5.0] * 2,
                        max_iterations=1000,
                        decode_func=examplefunctions.decode_real)
    optimizer._logging_func = lambda x, y, z: optimize._print_fitnesses(
        x, y, z, frequency=100)
    optimizer.optimize()
    assert optimizer.solution_found
Ejemplo n.º 8
0
def test_gsa_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    optimizer = GSA(2, [-5.0] * 2, [5.0] * 2)
    optimizer.optimize(problems.ackley_real,
                       max_iterations=1000,
                       logging_func=lambda *args: optimize._print_fitnesses(
                           *args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 9
0
def test_genalg_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    optimizer = GenAlg(32)
    optimizer.optimize(
        problems.ackley_binary,
        logging_func=
        lambda *args: optimize._print_fitnesses(*args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 10
0
def test_gsa_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    optimizer = GSA(2, [-5.0] * 2, [5.0] * 2)
    optimizer.optimize(
        problems.ackley_real,
        max_iterations=1000,
        logging_func=
        lambda *args: optimize._print_fitnesses(*args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 11
0
def test_crossentropy_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    # NOTE: since crossentropy is not very effective, we give it simpler problems
    optimizer = crossentropy.CrossEntropy(32, population_size=20)
    optimizer.optimize(problems.sphere_binary,
                       max_iterations=1000,
                       logging_func=lambda *args: optimize._print_fitnesses(
                           *args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 12
0
def test_gsa_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    optimizer = gsa.GSA(examplefunctions.ackley,
                        2, [-5.0] * 2, [5.0] * 2,
                        max_iterations=1000,
                        decode_func=examplefunctions.decode_real)
    optimizer._logging_func = lambda x, y, z: optimize._print_fitnesses(
        x, y, z, frequency=100)
    optimizer.optimize()
    assert optimizer.solution_found
Ejemplo n.º 13
0
def test_crossentropy_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    # NOTE: since crossentropy is not very effective, we give it simpler problems
    optimizer = crossentropy.CrossEntropy(32, population_size=20)
    optimizer.optimize(
        problems.sphere_binary,
        max_iterations=1000,
        logging_func=
        lambda *args: optimize._print_fitnesses(*args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 14
0
def test_crossentropy_sphere():
    optimizer = crossentropy.CrossEntropy(
        examplefunctions.sphere,
        32,
        population_size=20,
        max_iterations=1000,
        decode_func=examplefunctions.ackley_binary)
    optimizer._logging_func = lambda x, y, z: optimize._print_fitnesses(
        x, y, z, frequency=100)
    optimizer.optimize()
    assert optimizer.solution_found
Ejemplo n.º 15
0
def test_crossentropy_problems():
    # Attempt to solve various problems
    # Assert that the optimizer can find the solutions
    # NOTE: since crossentropy is not very effective, we give it simpler problems
    optimizer = crossentropy.CrossEntropy(
        examplefunctions.sphere,
        32,
        population_size=20,
        max_iterations=1000,
        decode_func=examplefunctions.ackley_binary)
    optimizer._logging_func = lambda x, y, z: optimize._print_fitnesses(
        x, y, z, frequency=100)
    optimizer.optimize()
    print(1.0 / optimizer.best_fitness)
    assert optimizer.solution_found
Ejemplo n.º 16
0
def test_metaoptimize_genalg():
    optimizer = genalg.GenAlg(examplefunctions.ackley, 32, 
                              decode_func=examplefunctions.ackley_binary)
    optimizer._logging_func = lambda x, y, z : optimize._print_fitnesses(x, y, z, frequency=100)
    prev_hyperparameters = optimizer._get_hyperparameters()

    # Test without metaoptimize, save iterations to solution
    optimizer.optimize()
    iterations_to_solution = optimizer.iteration

    # Test with metaoptimize, assert that iterations to solution is lower
    optimizer.optimize_hyperparameters(smoothing=1, _meta_optimizer=genalg.GenAlg(None, None, 1, 1))
    optimizer.optimize()

    assert optimizer._get_hyperparameters() != prev_hyperparameters
    #assert optimizer.iteration < iterations_to_solution # Improvements are made
Ejemplo n.º 17
0
def test_metaoptimize_gsa():
    optimizer = gsa.GSA(examplefunctions.ackley,
                        2, [-5.0] * 2, [5.0] * 2,
                        max_iterations=1000,
                        decode_func=examplefunctions.decode_real)
    optimizer._logging_func = lambda x, y, z: optimize._print_fitnesses(
        x, y, z, frequency=100)
    prev_hyperparameters = optimizer._get_hyperparameters()

    # Test without metaoptimize, save iterations to solution
    optimizer.optimize()
    iterations_to_solution = optimizer.iteration

    # Test with metaoptimize, assert that iterations to solution is lower
    optimizer.optimize_hyperparameters(smoothing=1,
                                       _meta_optimizer=genalg.GenAlg(
                                           None, None, 1, 1))
    optimizer.optimize()

    assert optimizer._get_hyperparameters() != prev_hyperparameters
Ejemplo n.º 18
0
def test_genalg_sphere():
    optimizer = genalg.GenAlg(examplefunctions.sphere, 32, 
                              decode_func=examplefunctions.ackley_binary)
    optimizer._logging_func = lambda x, y, z : optimize._print_fitnesses(x, y, z, frequency=100)
    optimizer.optimize()
    assert optimizer.solution_found
Ejemplo n.º 19
0
def _check_optimizer(optimizer):
    optimizer.optimize(problems.sphere_binary,
                       logging_func=lambda *args: optimize._print_fitnesses(
                           *args, frequency=100))
    assert optimizer.solution_found
Ejemplo n.º 20
0
def _check_optimizer(optimizer):
    optimizer.optimize(
        problems.sphere_binary,
        logging_func=
        lambda *args: optimize._print_fitnesses(*args, frequency=100))
    assert optimizer.solution_found