class_docstr: Cross Entropy Method.
  
  CEM works by iteratively optimizing a gaussian distribution of policy.
  
  In each epoch, CEM does the following:
  1. Sample n_samples policies from a gaussian distribution of
     mean cur_mean and std cur_std.
  2. Collect episodes for each policy.
  3. Update cur_mean and cur_std by doing Maximum Likelihood Estimation
     over the n_best top policies in terms of return.
  
  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.
      best_frac (float): The best fraction.
      init_std (float): Initial std for policy param distribution.
      extra_std (float): Decaying std added to param distribution.
      extra_decay_time (float): Epochs that it takes to decay extra std.
class_docstr_tok: ["Cross","Entropy","Method",".","CEM","works","by","iteratively","optimizing","a","gaussian","distribution","of","policy",".","In","each","epoch",",","CEM","does","the","following",":","1",".","Sample","n_samples","policies","from","a","gaussian","distribution","of","mean","cur_mean","and","std","cur_std",".","2",".","Collect","episodes","for","each","policy",".","3",".","Update","cur_mean","and","cur_std","by","doing","Maximum","Likelihood","Estimation","over","the","n_best","top","policies","in","terms","of","return",".","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",".","best_frac","(","float",")",":","The","best","fraction",".","init_std","(","float",")",":","Initial","std","for","policy","param","distribution",".","extra_std","(","float",")",":","Decaying","std","added","to","param","distribution",".","extra_decay_time","(","float",")",":","Epochs","that","it","takes","to","decay","extra","std","."]
code: def __init__(
      self,
      env_spec,
      policy,
      sampler,
      n_samples,
      discount=0.99,
      init_std=1,
      best_frac=0.05,
      extra_std=1.0,
      extra_decay_time=100,
  ):
      self.policy = policy
      self.max_episode_length = env_spec.max_episode_length
  
      self._sampler = sampler
  
      self._best_frac = best_frac
      self._init_std = init_std
      self._extra_std = extra_std
      self._extra_decay_time = extra_decay_time
      self._episode_reward_mean = collections.deque(maxlen=100)
      self._env_spec = env_spec
      self._discount = discount
      self._n_samples = n_samples
  
      self._cur_std = None
      self._cur_mean = None
      self._cur_params = None
      self._all_returns = None
      self._all_params = None
      self._n_best = None
      self._n_params = None
  
file_path: garage/src/garage/np/algos/cem.py
imports: import collections
  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 1 to create a new CEM object from inherited base classes: RLAlgorithm with example: obj = CEM(env_spec, policy, sampler, n_samples, discount, init_std, best_frac, extra_std, extra_decay_time)