Skip to content

Optimizers

Custom optimizers for evolutionary algorithms.

This module provides custom optimization algorithms that are not available in optax. These optimizers are designed specifically for evolutionary algorithms and can be used as drop-in replacements for optax optimizers in evosax algorithms.

ScaleByClipUpState

Bases: NamedTuple

State of the scale_by_clipup transformation.

Attributes:

  • velocity (Updates) –

    Current, clipped velocity.

  • count (Array) –

    Number of updates applied so far.

scale_by_clipup

scale_by_clipup(max_velocity_ratio: float = 2.0, momentum: float = 0.9) -> optax.GradientTransformation

Core ClipUp gradient scaling transformation.

This transformation implements the core ClipUp steps:

  1. Update velocity with momentum.
  2. Clip velocity if its norm exceeds max_velocity_ratio.
  3. Return the clipped velocity as updates.

Parameters:

  • max_velocity_ratio (float, default: 2.0 ) –

    Maximum velocity magnitude before learning rate scaling.

  • momentum (float, default: 0.9 ) –

    Momentum coefficient (decay rate for velocity).

Returns:

  • GradientTransformation –

    An optax.GradientTransformation that computes the clipped velocity direction.

Note

This does not apply gradient normalization, which should be handled by a preceding transformation (e.g. optax.normalize_by_update_norm()), nor the learning rate, which should be handled by a following transformation (e.g. optax.scale_by_learning_rate(learning_rate)). Use clipup for the complete optimizer.

clipup

clipup(learning_rate: float, max_velocity: float = 0.1, momentum: float = 0.9, eps: float = 1e-08) -> optax.GradientTransformation

ClipUp optimizer.

This transformation implements the ClipUp steps:

  1. Normalize the gradient globally.
  2. Apply momentum to update the velocity.
  3. Clip the velocity if its norm exceeds max_velocity / learning_rate.
  4. Return the clipped velocity as updates.
  5. Scale by learning_rate.

Parameters:

  • learning_rate (float) –

    Learning rate to scale the updates.

  • max_velocity (float, default: 0.1 ) –

    Maximum step size magnitude (||updates|| <= max_velocity).

  • momentum (float, default: 0.9 ) –

    Momentum coefficient.

  • eps (float, default: 1e-08 ) –

    Small constant to prevent division by zero.

Returns:

  • GradientTransformation –

    An optax.GradientTransformation representing the ClipUp optimizer.

References
  • Toklu et al. (2020), "ClipUp: A Simple and Powerful Optimizer for Distribution-based Policy Evolution"