Skip to content

SV-OpenAI-ES

SV_Open_ES

SV_Open_ES(population_size: int, num_populations: int, solution: Solution, kernel: Callable = kernel_rbf, use_antithetic_sampling: bool = True, optimizer: GradientTransformation = optax.sgd(learning_rate=0.001), std_schedule: Callable = optax.constant_schedule(1.0), fitness_shaping_fn: Callable = centered_rank_fitness_shaping_fn, metrics_fn: Callable = metrics_fn)

Bases: SV_ES, Open_ES

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

Runs num_populations OpenAI-ES search distributions in parallel. The gradient estimates of all distributions are combined with Stein variational gradient descent: a kernel-weighted average of the gradients plus the kernel gradient between the means, scaled by params.alpha.

Parameters:

  • population_size (int) –

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

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

  • use_antithetic_sampling (bool, default: True ) –

    If True, sample perturbations in mirrored pairs (z, -z).

  • optimizer (GradientTransformation, default: sgd(learning_rate=0.001) ) –

    Optax optimizer applied per search distribution to the Stein variational gradient to update its mean.

  • std_schedule (Callable, default: constant_schedule(1.0) ) –

    Function mapping the generation counter to the standard deviation of the search distribution, e.g. an Optax schedule.

  • fitness_shaping_fn (Callable, default: centered_rank_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.