leap_ec.contrib.transfer package

Submodules

leap_ec.contrib.transfer.sequential module

Experimental algorithms for sequential evolutionary transfer.

This module provides general mechanisms that allow an algorithm to learn from experience on past problems, and to reuse that experience on future problems.

class leap_ec.contrib.transfer.sequential.PopulationSeedingRepertoire(initialize, algorithm, repfile=None)

Bases: object

A repertoire method that works by seeding the population with individuals that were successful on past problems.

This works by injecting an initialize function into the wrapped algorithm’s parameterization. During training, we inject a standard initializer (i.e. that create a random population), but when applying the repertoire, we use a special initializer that draws individuals from the repertoire’s memory.

Parameters
  • initialize – a standard initializer to create random populations during training.

  • algorithm – the wrapped algorithm, which should take an initialize argument.

  • repfile – an optional path to save the repertoire’s memory to.

apply(problem, **kwargs)

Solve a new problem by injecting the all the individuals from the repertoire into the new initial population.

build_repertoire(problems, problem_kwargs)

Train the repertoire on a set of problems.

The best solution found on each problem will be saved into the repertoire.

export(path)

Write the repertoire of saved individuals out to a CSV file.

class leap_ec.contrib.transfer.sequential.Repertoire

Bases: ABC

Abstract definition of a ‘repertoire’ algorithm for evolutionary transfer.

A repertoire is a wrapper for an algorithm that can be trained on a set of problems, from which is learns and encodes some form of memory, which can be applied to new problems.

abstract apply(problem, algorithm)

Apply the repertoire to a new problem.

Parameters
  • problem – the Problem to solve.

  • algorithm – the algorithm to apply.

abstract build_repertoire(problems, initialize, algorithm)

Train the repertoire on a set of problems.

Parameters
  • problems – a list of Problems to train on.

  • initialize – a function that generates a population.

  • algorithm – an algorithm function, which may be parameterized with an initialize function.

leap_ec.contrib.transfer.sequential.initialize_seeded(initialize, seed_pop)

A population initializer that injects a fixed list of seed individuals into the population, and fills the remaining space with newly generated individuals.

>>> import numpy as np
>>> from leap_ec.real_rep.initializers import create_real_vector
>>> random_init = create_real_vector(bounds=[[0, 0]] * 2)
>>> init = initialize_seeded(random_init, [np.array([5.0, 5.0]), np.array([4.5, -6])])
>>> [init() for _ in range(5)]
[array([5., 5.]), array([ 4.5, -6. ]), array([0., 0.]), array([0., 0.]), array([0., 0.])]

Module contents