def tf_retrieve_indices(self, buffer_elements, priority_indices):
states = dict()<EOL>buffer_start = self.buffer_index - buffer_elements<EOL>buffer_end = self.buffer_index<EOL>for name in sorted(self.states_memory):<EOL><INDENT>buffer_state_memory = self.states_buffer[name]<EOL>buffer_states = buffer_state_memory[buffer_start:buffer_end]<EOL>memory_states = tf.gather(params=self.states_memory[name], indices=priority_indices)<EOL>states[name] = tf.concat(values=(buffer_states, memory_states), axis=<NUM_LIT:0>)<EOL><DEDENT>internals = dict()<EOL>for name in sorted(self.internals_memory):<EOL><INDENT>internal_buffer_memory = self.internals_buffer[name]<EOL>buffer_internals = internal_buffer_memory[buffer_start:buffer_end]<EOL>memory_internals = tf.gather(params=self.internals_memory[name], indices=priority_indices)<EOL>internals[name] = tf.concat(values=(buffer_internals, memory_internals), axis=<NUM_LIT:0>)<EOL><DEDENT>actions = dict()<EOL>for name in sorted(self.actions_memory):<EOL><INDENT>action_buffer_memory = self.actions_buffer[name]<EOL>buffer_action = action_buffer_memory[buffer_start:buffer_end]<EOL>memory_action = tf.gather(params=self.actions_memory[name], indices=priority_indices)<EOL>actions[name] = tf.concat(values=(buffer_action, memory_action), axis=<NUM_LIT:0>)<EOL><DEDENT>buffer_terminal = self.terminal_buffer[buffer_start:buffer_end]<EOL>priority_terminal = tf.gather(params=self.terminal_memory, indices=priority_indices)<EOL>terminal = tf.concat(values=(buffer_terminal, priority_terminal), axis=<NUM_LIT:0>)<EOL>buffer_reward = self.reward_buffer[buffer_start:buffer_end]<EOL>priority_reward = tf.gather(params=self.reward_memory, indices=priority_indices)<EOL>reward = tf.concat(values=(buffer_reward, priority_reward), axis=<NUM_LIT:0>)<EOL>if self.include_next_states:<EOL><INDENT>assert util.rank(priority_indices) == <NUM_LIT:1><EOL>next_priority_indices = (priority_indices + <NUM_LIT:1>) % self.capacity<EOL>next_buffer_start = (buffer_start + <NUM_LIT:1>) % self.buffer_size<EOL>next_buffer_end = (buffer_end + <NUM_LIT:1>) % self.buffer_size<EOL>next_states = dict()<EOL>for name in sorted(self.states_memory):<EOL><INDENT>buffer_state_memory = self.states_buffer[name]<EOL>buffer_next_states = buffer_state_memory[next_buffer_start:next_buffer_end]<EOL>memory_next_states = tf.gather(params=self.states_memory[name], indices=next_priority_indices)<EOL>next_states[name] = tf.concat(values=(buffer_next_states, memory_next_states), axis=<NUM_LIT:0>)<EOL><DEDENT>next_internals = dict()<EOL>for name in sorted(self.internals_memory):<EOL><INDENT>buffer_internal_memory = self.internals_buffer[name]<EOL>buffer_next_internals = buffer_internal_memory[next_buffer_start:next_buffer_end]<EOL>memory_next_internals = tf.gather(params=self.internals_memory[name], indices=next_priority_indices)<EOL>next_internals[name] = tf.concat(values=(buffer_next_internals, memory_next_internals), axis=<NUM_LIT:0>)<EOL><DEDENT>return dict(<EOL>states=states,<EOL>internals=internals,<EOL>actions=actions,<EOL>terminal=terminal,<EOL>reward=reward,<EOL>next_states=next_states,<EOL>next_internals=next_internals<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return dict(<EOL>states=states,<EOL>internals=internals,<EOL>actions=actions,<EOL>terminal=terminal,<EOL>reward=reward<EOL>)<EOL><DEDENT>
Fetches experiences for given indices by combining entries from buffer
which have no priorities, and entries from priority memory.

Args:
    buffer_elements: Number of buffer elements to retrieve
    priority_indices: Index tensor for priority memory

Returns: Batch of experiences