Exemplo n.º 1
0
def test_custom_centroids(use_kd_tree):
    centroids = np.array([[-0.25, -0.25], [0.25, 0.25]])
    archive = CVTArchive(centroids.shape[0], [(-1, 1), (-1, 1)],
                         custom_centroids=centroids,
                         use_kd_tree=use_kd_tree)
    archive.initialize(solution_dim=3)
    assert archive.samples is None
    assert (archive.centroids == centroids).all()
Exemplo n.º 2
0
def _cvt_archive():
    """Deterministically created CVTArchive."""
    archive = CVTArchive(100, [(-1, 1), (-1, 1)],
                         samples=1000,
                         use_kd_tree=True,
                         seed=42)
    archive.initialize(solution_dim=2)
    _add_uniform_sphere(archive, (-1, 1), (-1, 1))
    return archive
Exemplo n.º 3
0
def _long_cvt_archive():
    """Same as above, but the behavior space is longer in one direction."""
    archive = CVTArchive(100, [(-2, 2), (-1, 1)],
                         samples=1000,
                         use_kd_tree=True,
                         seed=42)
    archive.initialize(solution_dim=2)
    _add_uniform_sphere(archive, (-2, 2), (-1, 1))
    return archive
Exemplo n.º 4
0
    def setup():
        archive = CVTArchive(1000, [(-1, 1), (-1, 1)],
                             samples=20_000,
                             use_kd_tree=use_kd_tree)
        archive.initialize(solutions.shape[1])

        # Let numba compile.
        archive.add(solutions[0], objective_values[0], behavior_values[0])

        return (archive,), {}
Exemplo n.º 5
0
def benchmark_get_10k_random_elites(use_kd_tree, benchmark, benchmark_data_10k):
    n, solutions, objective_values, behavior_values = benchmark_data_10k
    archive = CVTArchive(1000, [(-1, 1), (-1, 1)],
                         samples=20_000,
                         use_kd_tree=use_kd_tree)
    archive.initialize(solutions.shape[1])
    for i in range(n):
        archive.add(solutions[i], objective_values[i], behavior_values[i])

    @benchmark
    def get_elites():
        for i in range(n):
            sol, obj, beh = archive.get_random_elite()
Exemplo n.º 6
0
def benchmark_as_pandas_2000_items(benchmark):
    bins = 2000
    archive = CVTArchive(bins, [(-1, 1), (-1, 1)],
                         use_kd_tree=True,
                         samples=50_000)
    archive.initialize(10)

    for x, y in archive.centroids:
        sol = np.random.random(10)
        sol[0] = x
        sol[1] = y
        archive.add(sol, 1.0, np.array([x, y]))

    # Archive should be full.
    assert len(archive.as_pandas()) == bins

    benchmark(archive.as_pandas)
Exemplo n.º 7
0
 def init():
     archive = CVTArchive(1000, [(-1, 1), (-1, 1)],
                          samples=20_000,
                          use_kd_tree=use_kd_tree)
     archive.initialize(solution_dim=2)
Exemplo n.º 8
0
 def setup(bins, use_kd_tree):
     nonlocal archive
     archive = CVTArchive(bins, [(-1, 1), (-1, 1)],
                          custom_centroids=ref_archives[bins].centroids,
                          use_kd_tree=use_kd_tree)
     archive.initialize(solutions.shape[1])