class_docstr: Covariance Matrix Adaptation Evolution Strategy.
  
  Note:
      The CMA-ES method can hardly learn a successful policy even for
      simple task. It is still maintained here only for consistency with
      original rllab paper.
  
  Args:
      env_spec (EnvSpec): Environment specification.
      policy (garage.np.policies.Policy): Action policy.
      sampler (garage.sampler.Sampler): Sampler.
      n_samples (int): Number of policies sampled in one epoch.
      discount (float): Environment reward discount.
      sigma0 (float): Initial std for param distribution.
class_docstr_tok: ["Covariance","Matrix","Adaptation","Evolution","Strategy",".","Note",":","The","CMA-ES","method","can","hardly","learn","a","successful","policy","even","for","simple","task",".","It","is","still","maintained","here","only","for","consistency","with","original","rllab","paper",".","Args",":","env_spec","(","EnvSpec",")",":","Environment","specification",".","policy","(","garage.np.policies.Policy",")",":","Action","policy",".","sampler","(","garage.sampler.Sampler",")",":","Sampler",".","n_samples","(","int",")",":","Number","of","policies","sampled","in","one","epoch",".","discount","(","float",")",":","Environment","reward","discount",".","sigma0","(","float",")",":","Initial","std","for","param","distribution","."]
docstr: Initialize variables and start training.
  
  Args:
      trainer (Trainer): Trainer is passed to give algorithm
          the access to trainer.step_epochs(), which provides services
          such as snapshotting and sampler control.
  
  Returns:
      float: The average return in last epoch cycle.
docstr_tok: ["Initialize","variables","and","start","training",".","Args",":","trainer","(","Trainer",")",":","Trainer","is","passed","to","give","algorithm","the","access","to","trainer.step_epochs","(",")",",","which","provides","services","such","as","snapshotting","and","sampler","control",".","Returns",":","float",":","The","average","return","in","last","epoch","cycle","."]
code: def train(self, trainer):
      """Initialize variables and start training.
  
      Args:
          trainer (Trainer): Trainer is passed to give algorithm
              the access to trainer.step_epochs(), which provides services
              such as snapshotting and sampler control.
  
      Returns:
          float: The average return in last epoch cycle.
  
      """
      init_mean = self.policy.get_param_values()
      self._es = cma.CMAEvolutionStrategy(
          init_mean, self._sigma0, {"popsize": self._n_samples}
      )
      self._all_params = self._sample_params()
      self._cur_params = self._all_params[0]
      self.policy.set_param_values(self._cur_params)
      self._all_returns = []
  
      # start actual training
      last_return = None
  
      for _ in trainer.step_epochs():
          for _ in range(self._n_samples):
              trainer.step_episode = trainer.obtain_episodes(
                  trainer.step_itr
              )
              last_return = self._train_once(
                  trainer.step_itr, trainer.step_episode
              )
              trainer.step_itr += 1
  
      return last_return
  
file_path: garage/src/garage/np/algos/cma_es.py
imports: import collections
  import cma
  from dowel import logger, tabular
  import numpy
  from garage import log_performance
  from garage.np.algos.rl_algorithm import RLAlgorithm
label_desc: Use image node_id 3 for calling the CMAES obj's underlying member method code with example usage: obj.train(trainer) and returns: last_return