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: Perform one step of policy optimization given one batch of samples.
  
  Args:
      itr (int): Iteration number.
      episodes (garage.EpisodeBatch): Episodes collected using the
          current policy.
  
  Returns:
      float: The average return of epoch cycle.
docstr_tok: ["Perform","one","step","of","policy","optimization","given","one","batch","of","samples",".","Args",":","itr","(","int",")",":","Iteration","number",".","episodes","(","garage.EpisodeBatch",")",":","Episodes","collected","using","the","current","policy",".","Returns",":","float",":","The","average","return","of","epoch","cycle","."]
code: def _train_once(self, itr, episodes):
      """Perform one step of policy optimization given one batch of samples.
  
      Args:
          itr (int): Iteration number.
          episodes (garage.EpisodeBatch): Episodes collected using the
              current policy.
  
      Returns:
          float: The average return of epoch cycle.
  
      """
      # -- Stage: Run and calculate performance of the algorithm
      undiscounted_returns = log_performance(
          itr, episodes, discount=self._discount
      )
      self._episode_reward_mean.extend(undiscounted_returns)
      tabular.record(
          "Extras/EpisodeRewardMean", np.mean(self._episode_reward_mean)
      )
      average_return = np.mean(undiscounted_returns)
  
      epoch = itr // self._n_samples
      i_sample = itr - epoch * self._n_samples
  
      tabular.record("Epoch", epoch)
      tabular.record("# Sample", i_sample)
      rtn = average_return
      self._all_returns.append(average_return)
  
      if (itr + 1) % self._n_samples == 0:
          avg_rtns = np.array(self._all_returns)
          self._es.tell(self._all_params, -avg_rtns)
          self.policy.set_param_values(self._es.best.get()[0])
  
          # Clear for next epoch
          rtn = max(self._all_returns)
          self._all_returns.clear()
          self._all_params = self._sample_params()
  
      self._cur_params = self._all_params[
          (i_sample + 1) % self._n_samples
      ]
      self.policy.set_param_values(self._cur_params)
  
      logger.log(tabular)
      return rtn
  
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 4 for calling the CMAES obj's underlying member method code with example usage: obj._train_once(itr, episodes) and returns: rtn