Skip to content

GESMR-GA

GESMR_GA

GESMR_GA(population_size: int, solution: Solution, num_groups: int = 1, fitness_shaping_fn: Callable = identity_fitness_shaping_fn, metrics_fn: Callable = metrics_fn)

Bases: PopulationBasedAlgorithm

Group Elite Selection of Mutation Rates (GESMR).

Genetic algorithm that co-evolves one mutation standard deviation per group of population members. ask keeps the best stored member unchanged and fills the rest of the population with members drawn from the better half of the stored population, perturbed by Gaussian noise scaled with the standard deviation of their group. tell stores the evaluated candidates, ranks the groups by the best fitness improvement of their members, and resamples and perturbs the group standard deviations from the best ranked ones.

Parameters:

  • population_size (int) –

    Number of candidate solutions sampled and evaluated per generation. population_size - 1 must be divisible by num_groups.

  • 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.

  • num_groups (int, default: 1 ) –

    Number of groups with their own mutation standard deviation. All members except the first are split evenly into these groups.

  • 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.

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, population: Population, fitness: Fitness, params: Params) -> State

Initialize the algorithm state from an evaluated population.

Parameters:

  • key (Array) –

    PRNG key.

  • population (Population) –

    Initial population, a PyTree with the structure of solution and a leading population axis on every leaf.

  • fitness (Fitness) –

    Raw fitness of the initial population. Lower is better. NaN values mark failed evaluations and never become the best 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_best_solution

get_best_solution(state: State) -> Solution

Return the best member of the stored population as a solution PyTree.

This is the member with the lowest shaped fitness in the current population; the best solution seen over the whole run is kept in state.best_solution. Unlike state.best_solution, this does not skip NaN fitness values.

get_population

get_population(state: State) -> Population

Return the stored population as a PyTree with a leading population axis.