class_docstr: Wrapper around a replay buffer in order to use HER.
  This implementation is inspired by to the one found in https://github.com/NervanaSystems/coach/.
  
  :param replay_buffer: (ReplayBuffer)
  :param n_sampled_goal: (int) The number of artificial transitions to generate for each actual transition
  :param goal_selection_strategy: (GoalSelectionStrategy) The method that will be used to generate
      the goals for the artificial transitions.
  :param wrapped_env: (HERGoalEnvWrapper) the GoalEnv wrapped using HERGoalEnvWrapper,
      that enables to convert observation to dict, and vice versa
class_docstr_tok: ["Wrapper","around","a","replay","buffer","in","order","to","use","HER",".","This","implementation","is","inspired","by","to","the","one","found","in","https",":","\/\/github.com\/NervanaSystems\/coach\/",".",":","param","replay_buffer",":","(","ReplayBuffer",")",":","param","n_sampled_goal",":","(","int",")","The","number","of","artificial","transitions","to","generate","for","each","actual","transition",":","param","goal_selection_strategy",":","(","GoalSelectionStrategy",")","The","method","that","will","be","used","to","generate","the","goals","for","the","artificial","transitions",".",":","param","wrapped_env",":","(","HERGoalEnvWrapper",")","the","GoalEnv","wrapped","using","HERGoalEnvWrapper",",","that","enables","to","convert","observation","to","dict",",","and","vice","versa"]
docstr: Sample artificial goals and store transition of the current
  episode in the replay buffer.
  This method is called only after each end of episode.
docstr_tok: ["Sample","artificial","goals","and","store","transition","of","the","current","episode","in","the","replay","buffer",".","This","method","is","called","only","after","each","end","of","episode","."]
code: def _store_episode(self):
      """
      Sample artificial goals and store transition of the current
      episode in the replay buffer.
      This method is called only after each end of episode.
      """
      # For each transition in the last episode,
      # create a set of artificial transitions
      for transition_idx, transition in enumerate(
          self.episode_transitions
      ):
          obs_t, action, reward, obs_tp1, done, info = transition
  
          # Add to the replay buffer
          self.replay_buffer.add(obs_t, action, reward, obs_tp1, done)
  
          # We cannot sample a goal from the future in the last step of an episode
          if (
              transition_idx == len(self.episode_transitions) - 1
              and self.goal_selection_strategy
              == GoalSelectionStrategy.FUTURE
          ):
              break
  
          # Sampled n goals per transition, where n is `n_sampled_goal`
          # this is called k in the paper
          sampled_goals = self._sample_achieved_goals(
              self.episode_transitions, transition_idx
          )
          # For each sampled goals, store a new transition
          for goal in sampled_goals:
              # Copy transition to avoid modifying the original one
              obs, action, reward, next_obs, done, info = copy.deepcopy(
                  transition
              )
  
              # Convert concatenated obs to dict, so we can update the goals
              obs_dict, next_obs_dict = map(
                  self.env.convert_obs_to_dict, (obs, next_obs)
              )
  
              # Update the desired goal in the transition
              obs_dict["desired_goal"] = goal
              next_obs_dict["desired_goal"] = goal
  
              # Update the reward according to the new desired goal
              reward = self.env.compute_reward(
                  next_obs_dict["achieved_goal"], goal, info
              )
              # Can we use achieved_goal == desired_goal?
              done = False
  
              # Transform back to ndarrays
              obs, next_obs = map(
                  self.env.convert_dict_to_obs,
                  (obs_dict, next_obs_dict),
              )
  
              # Add artificial transition to the replay buffer
              self.replay_buffer.add(
                  obs, action, reward, next_obs, done
              )
  
file_path: stable-baselines/stable_baselines/her/replay_buffer.py
imports: import copy
  from enum import Enum
  import numpy
label_desc: Use image node_id 8 for calling the HindsightExperienceReplayWrapper obj's underlying member method code with example usage: obj._store_episode() without return types