class_docstr: Tests for discrete_policy_gradient op.
class_docstr_tok: ["Tests","for","discrete_policy_gradient","op","."]
code: def testLoss(self):
      with self.test_session() as sess:
          policy_logits = tf.constant(
              [[0, 1], [0, 1], [1, 1], [0, 100]], dtype=tf.float32
          )
          action_values = tf.constant([0, 1, 2, 1], dtype=tf.float32)
          actions = tf.constant([0, 0, 1, 1], dtype=tf.int32)
          loss = pg_ops.discrete_policy_gradient(
              policy_logits, actions, action_values
          )
          self.assertEqual(loss.get_shape(), tf.TensorShape(4))
  
          # Calculate the targets with:
          #     loss = action_value*(-logits[action] + log(sum_a(exp(logits[a]))))
          #  The final case (with large logits), runs out of precision and gets
          #  truncated to 0, but isn't `nan`.
          self.assertAllClose(
              sess.run(loss), [0, 1.313262, 1.386294, 0]
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  import numpy
  from six.moves import xrange
  import tensorflow.compat.v1
  import tree
  from trfl import discrete_policy_gradient_ops
label_desc: Use image node_id 1 for calling the DiscretePolicyGradientTest obj's underlying member method code with example usage: obj.testLoss() without return types