def tf_loss(self, states, internals, actions, terminal, reward, next_states, next_internals, update, reference=None):
<EOL>loss_per_instance = self.fn_loss_per_instance(<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>update=update,<EOL>reference=reference<EOL>)<EOL>updated = self.memory.update_batch(loss_per_instance=loss_per_instance)<EOL>with tf.control_dependencies(control_inputs=(updated,)):<EOL><INDENT>loss = tf.reduce_mean(input_tensor=loss_per_instance, axis=<NUM_LIT:0>)<EOL>if '<STR_LIT>' in self.summary_labels:<EOL><INDENT>tf.contrib.summary.scalar(name='<STR_LIT>', tensor=loss)<EOL><DEDENT>losses = self.fn_regularization_losses(states=states, internals=internals, update=update)<EOL>if len(losses) > <NUM_LIT:0>:<EOL><INDENT>loss += tf.add_n(inputs=[losses[name] for name in sorted(losses)])<EOL>if '<STR_LIT>' in self.summary_labels:<EOL><INDENT>for name in sorted(losses):<EOL><INDENT>tf.contrib.summary.scalar(name=('<STR_LIT>' + name), tensor=losses[name])<EOL><DEDENT><DEDENT><DEDENT>if '<STR_LIT>' in self.summary_labels or '<STR_LIT>' in self.summary_labels:<EOL><INDENT>tf.contrib.summary.scalar(name='<STR_LIT>', tensor=loss)<EOL><DEDENT>return loss<EOL><DEDENT>
Creates the TensorFlow operations for calculating the full loss of a batch.

Args:
    states: Dict of state tensors.
    internals: List of prior internal state tensors.
    actions: Dict of action tensors.
    terminal: Terminal boolean tensor.
    reward: Reward tensor.
    next_states: Dict of successor state tensors.
    next_internals: List of posterior internal state tensors.
    update: Boolean tensor indicating whether this call happens during an update.
    reference: Optional reference tensor(s), in case of a comparative loss.

Returns:
    Loss tensor.