class_docstr: A wrapper around evosax's CMA-ES.
  Implementation: https://github.com/RobertTLange/evosax/blob/main/evosax/strategies/cma_es.py
  Reference: Hansen & Ostermeier (2008) - http://www.cmap.polytechnique.fr/~nikolaus.hansen/cmaartic.pdf
class_docstr_tok: ["A","wrapper","around","evosax","'s","CMA-ES",".","Implementation",":","https",":","\/\/github.com\/RobertTLange\/evosax\/blob\/main\/evosax\/strategies\/cma_es.py","Reference",":","Hansen","&","Ostermeier","(","2008",")","-","http",":","\/\/www.cmap.polytechnique.fr\/~nikolaus.hansen\/cmaartic.pdf"]
docstr: Initialization function.
  
  Args:
      param_size - Parameter size.
      pop_size - Population size.
      elite_ratio - Population elite fraction used for gradient estimate.
      init_stdev - Initial scale of istropic part of covariance.
      w_decay - L2 weight regularization coefficient.
      seed - Random seed for parameters sampling.
      logger - Logger.
docstr_tok: ["Initialization","function",".","Args",":","param_size","-","Parameter","size",".","pop_size","-","Population","size",".","elite_ratio","-","Population","elite","fraction","used","for","gradient","estimate",".","init_stdev","-","Initial","scale","of","istropic","part","of","covariance",".","w_decay","-","L2","weight","regularization","coefficient",".","seed","-","Random","seed","for","parameters","sampling",".","logger","-","Logger","."]
code: def __init__(
      self,
      param_size: int,
      pop_size: int,
      elite_ratio: float = 0.5,
      init_stdev: float = 0.1,
      w_decay: float = 0.0,
      seed: int = 0,
      logger: logging.Logger = None,
  ):
      """Initialization function.
  
      Args:
          param_size - Parameter size.
          pop_size - Population size.
          elite_ratio - Population elite fraction used for gradient estimate.
          init_stdev - Initial scale of istropic part of covariance.
          w_decay - L2 weight regularization coefficient.
          seed - Random seed for parameters sampling.
          logger - Logger.
      """
  
      # Delayed importing of evosax
  
      if sys.version_info.minor < 7:
          print(
              "evosax, which is needed by CMA-ES, requires python>=3.7"
          )
          print("  please consider upgrading your Python version.")
          sys.exit(1)
  
      try:
          import evosax
      except ModuleNotFoundError:
          print("You need to install evosax for its CMA-ES:")
          print("  pip install evosax")
          sys.exit(1)
  
      # Set up object variables.
  
      if logger is None:
          self.logger = create_logger(name="CMA_ES")
      else:
          self.logger = logger
  
      self.param_size = param_size
      self.pop_size = abs(pop_size)
      self.elite_ratio = elite_ratio
      self.rand_key = jax.random.PRNGKey(seed=seed)
  
      # Instantiate evosax's ARS strategy
      self.es = evosax.CMA_ES(
          popsize=pop_size,
          num_dims=param_size,
          elite_ratio=elite_ratio,
      )
  
      # Set hyperparameters according to provided inputs
      self.es_params = self.es.default_params.replace(
          sigma_init=init_stdev
      )
  
      # Initialize the evolution strategy state
      self.rand_key, init_key = jax.random.split(self.rand_key)
      self.es_state = self.es.initialize(init_key, self.es_params)
  
      # By default evojax assumes maximization of fitness score!
      # Evosax, on the other hand, minimizes!
      self.fit_shaper = evosax.FitnessShaper(
          w_decay=w_decay, maximize=True
      )
  
file_path: evojax/evojax/algo/cma_evosax.py
imports: import sys
  import logging
  from typing import Union
  import numpy
  import jax
  import jax.numpy
  from evojax.algo.base import NEAlgorithm
  from evojax.util import create_logger
label_desc: Use image node_id 1 to create a new CMA_ES object from inherited base classes: NEAlgorithm with example: obj = CMA_ES(param_size, pop_size, elite_ratio, init_stdev, w_decay, seed, logger)