def retrace_from_action_log_probs(
    behaviour_action_log_probs,
    target_action_log_probs,
    discounts,
    rewards,
    q_values,
    values,
    bootstrap_value,
    lambda_=1.,
    name="retrace_from_action_log_probs"):
  """Constructs Q/Retrace ops.

  This is an implementation of Retrace. In the description of the arguments
  the notation is as follows: `T` refers to the sequence size over which
  the return is calculated, finally `B` denotes the batch size.

  Args:
    behaviour_action_log_probs: Log-probabilities. Shape [T, B].
    target_action_log_probs: Log-probabilities for target policy. Shape [T, B]
    discounts: Also called pcontinues. Discount encountered when following
      the behaviour policy. Shape [T, B].
    rewards: A tensor containing rewards generated by following the behaviour
      policy. Shape [T, B].
    q_values: Q-function estimates wrt. the target policy. Shape [T, B].
    values: Value function estimates wrt. the target policy. Shape [T, B].
    bootstrap_value: Value function estimate at time `T`. Shape [B].
    lambda_: Mix between 1-step (lambda_=0) and n-step (lambda_=1).
    name: The name scope that all qtrace ops will be created in.

  Returns:
    A `QTraceReturns` namedtuple containing:

        * qs: The Retrace regression/policy gradient targets.
          Can be used to calculate estimates of the advantage for policy
          gradients or as regression target for Q-value functions. Shape [T, B].
        * importance_weights: Importance sampling weights. Shape [T, B].
        * log_importance_weights: Importance sampling weights. Shape [T, B].
        * truncated_importance_weights: Called c_t in the paper. Shape [T, B].
        * deltas: Shape [T, B]
        * vs_minus_q_xs: Q-Retrace targets - Q(x_s, u_s). Shape [T, B].
  """
  # Turn arguments to tensors.
  behaviour_action_log_probs = tf.convert_to_tensor(
      behaviour_action_log_probs, dtype=tf.float32)
  target_action_log_probs = tf.convert_to_tensor(
      target_action_log_probs, dtype=tf.float32)
  values = tf.convert_to_tensor(values, dtype=tf.float32)
  q_values = tf.convert_to_tensor(q_values, dtype=tf.float32)
  bootstrap_value = tf.convert_to_tensor(bootstrap_value, dtype=tf.float32)
  discounts = tf.convert_to_tensor(discounts, dtype=tf.float32)
  rewards = tf.convert_to_tensor(rewards, dtype=tf.float32)

  # Make sure tensor ranks are as expected.
  behaviour_action_log_probs.get_shape().assert_has_rank(2)
  target_action_log_probs.get_shape().assert_has_rank(2)
  values.get_shape().assert_has_rank(2)
  q_values.get_shape().assert_has_rank(2)
  bootstrap_value.get_shape().assert_has_rank(1)
  discounts.get_shape().assert_has_rank(2)
  rewards.get_shape().assert_has_rank(2)

  with tf.name_scope(
      name,
      values=[
          behaviour_action_log_probs, target_action_log_probs, discounts,
          rewards, q_values, values, bootstrap_value
      ]):
    log_rhos = target_action_log_probs - behaviour_action_log_probs
    return retrace_from_importance_weights(
        log_rhos=log_rhos,
        discounts=discounts,
        rewards=rewards,
        q_values=q_values,
        values=values,
        bootstrap_value=bootstrap_value,
        lambda_=lambda_)
Constructs Q/Retrace ops.

  This is an implementation of Retrace. In the description of the arguments
  the notation is as follows: `T` refers to the sequence size over which
  the return is calculated, finally `B` denotes the batch size.

  Args:
    behaviour_action_log_probs: Log-probabilities. Shape [T, B].
    target_action_log_probs: Log-probabilities for target policy. Shape [T, B]
    discounts: Also called pcontinues. Discount encountered when following
      the behaviour policy. Shape [T, B].
    rewards: A tensor containing rewards generated by following the behaviour
      policy. Shape [T, B].
    q_values: Q-function estimates wrt. the target policy. Shape [T, B].
    values: Value function estimates wrt. the target policy. Shape [T, B].
    bootstrap_value: Value function estimate at time `T`. Shape [B].
    lambda_: Mix between 1-step (lambda_=0) and n-step (lambda_=1).
    name: The name scope that all qtrace ops will be created in.

  Returns:
    A `QTraceReturns` namedtuple containing:

        * qs: The Retrace regression/policy gradient targets.
          Can be used to calculate estimates of the advantage for policy
          gradients or as regression target for Q-value functions. Shape [T, B].
        * importance_weights: Importance sampling weights. Shape [T, B].
        * log_importance_weights: Importance sampling weights. Shape [T, B].
        * truncated_importance_weights: Called c_t in the paper. Shape [T, B].
        * deltas: Shape [T, B]
        * vs_minus_q_xs: Q-Retrace targets - Q(x_s, u_s). Shape [T, B].
  
trfl/continuous_retrace_ops.py