Skip to content

SV-CMA-ES

SV_CMA_ES

SV_CMA_ES(population_size: int, num_populations: int, solution: Solution, kernel: Callable = kernel_rbf, fitness_shaping_fn: Callable = weights_fitness_shaping_fn, metrics_fn: Callable = metrics_fn)

Bases: SV_ES, CMA_ES

Stein Variational CMA-ES (SV-CMA-ES).

Runs num_populations CMA-ES search distributions in parallel. The mean update of each distribution adds the gradient of the kernel between the means, scaled by params.alpha, to the CMA-ES step.

Parameters:

  • population_size (int) –

    Number of candidate solutions sampled per search distribution in each generation.

  • num_populations (int) –

    Number of search distributions run in parallel.

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

  • kernel (Callable, default: kernel_rbf ) –

    Function (x, y, params) -> similarity between the means of two search distributions. See evosax.core.kernel.

  • fitness_shaping_fn (Callable, default: weights_fitness_shaping_fn ) –

    Function (population, fitness, state, params) -> shaped_fitness applied per search distribution 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 per search distribution 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, means: Solution, params: Params) -> State

Initialize the algorithm state from one initial mean per distribution.

Parameters:

  • key (Array) –

    PRNG key.

  • means (Solution) –

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

  • params (Params) –

    Algorithm hyperparameters, e.g. default_params.

Returns:

  • State –

    The initial algorithm state.

ask

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

Ask for a population of candidate solutions to evaluate.

Parameters:

  • key (Array) –

    PRNG key.

  • state (State) –

    Current algorithm state.

  • params (Params) –

    Algorithm hyperparameters.

Returns:

  • tuple[Population, State] –

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

tell

tell(key: Array, population: Population, fitness: Fitness, state: State, params: Params) -> tuple[State, 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 (num_populations * population_size,). Lower is better.

  • state (State) –

    Algorithm state returned by ask.

  • params (Params) –

    Algorithm hyperparameters.

Returns:

  • tuple[State, Metrics] –

    A tuple (state, metrics) with the updated state and the output of metrics_fn for each search distribution.

get_mean

get_mean(state: State) -> Solution

Return the means of all search distributions as a PyTree.

Every leaf has a leading axis of size num_populations.