Skip to content

Learned ES

LearnedES

LearnedES(population_size: int, solution: Solution, params: PyTree | None = None, params_path: str | None = None, fitness_shaping_fn: Callable = identity_fitness_shaping_fn, metrics_fn: Callable = metrics_fn)

Bases: DistributionBasedAlgorithm

Learned Evolution Strategy (LES).

Samples the population from a diagonal Gaussian. In tell, a meta-learned attention network turns fitness features into recombination weights and a meta-learned MLP turns evolution paths into per-dimension learning rates for the mean and the standard deviation.

Parameters:

  • population_size (int) –

    Number of candidate solutions sampled and evaluated per generation.

  • solution (Solution) –

    Example solution PyTree. Only its structure and leaf shapes are used: they set the number of search dimensions and how flat search vectors are unravelled into the PyTrees returned by ask.

  • params (PyTree | None, default: None ) –

    Meta-learned network parameters, a PyTree with the entries recomb_weights and lrate_modulation. Takes precedence over params_path.

  • params_path (str | None, default: None ) –

    Path to a pickle file holding the network parameters, used if params is None. If both are None, the checkpoint shipped with evosax is loaded.

  • fitness_shaping_fn (Callable, default: identity_fitness_shaping_fn ) –

    Function (population, fitness, state, params) -> shaped_fitness applied to the raw fitness in tell before the algorithm update. See evosax.core.fitness_shaping.

  • metrics_fn (Callable, default: metrics_fn ) –

    Function (key, population, fitness, state, params) -> metrics evaluated in tell; its output is returned alongside the new state.

Warning

Pickle loading can execute arbitrary code. Only pass trusted files to params_path.

Note

This is an independent reimplementation which does not use the same meta-trained checkpoint used to generate the results in the paper. The results may therefore differ from the ones shown in the paper.

References

default_params property

default_params: Any

Default hyperparameters of the algorithm.

Returns a Params dataclass. Use params.replace(...) to override individual hyperparameters before passing it to init, ask and tell.

init

init(key: Array, mean: Solution, params: Params) -> State

Initialize the algorithm state from an initial mean.

Parameters:

  • key (Array) –

    PRNG key.

  • mean (Solution) –

    Initial mean of the search distribution, a PyTree with the structure of solution.

  • params (Params) –

    Algorithm hyperparameters, e.g. default_params.

Returns:

  • State –

    The initial algorithm state.

ask

ask(key: Array, state: Any, params: Any) -> tuple[Population, Any]

Ask for a population of candidate solutions to evaluate.

Parameters:

  • key (Array) –

    PRNG key.

  • state (Any) –

    Current algorithm state.

  • params (Any) –

    Algorithm hyperparameters.

Returns:

  • tuple[Population, Any] –

    A tuple (population, state). population is a PyTree with the structure of solution and a leading axis of size population_size.

tell

tell(key: Array, population: Population, fitness: Fitness, state: Any, params: Any) -> tuple[Any, Metrics]

Update the algorithm state with the fitness of a population.

Parameters:

  • key (Array) –

    PRNG key.

  • population (Population) –

    Population returned by ask.

  • fitness (Fitness) –

    Fitness of each population member, shape (population_size,). Lower is better. NaN values mark failed evaluations and never become the best solution.

  • state (Any) –

    Algorithm state returned by ask.

  • params (Any) –

    Algorithm hyperparameters.

Returns:

  • tuple[Any, Metrics] –

    A tuple (state, metrics) with the updated state and the output of metrics_fn.

get_mean

get_mean(state: State) -> Solution

Return the mean of the search distribution as a solution PyTree.