class_docstr: Tests for DP-enabled binary class heads.
docstr: Tests loss() returns per-example losses.
docstr_tok: ["Tests","loss","(",")","returns","per-example","losses","."]
code: def testLoss(self):
      """Tests loss() returns per-example losses."""
  
      head = binary_class_head.DPBinaryClassHead()
      features = {"feature_a": np.full((4), 1.0)}
      labels = np.array([[1.0], [1.0], [1.0], [0.0]])
      logits = np.full((4, 1), 0.5)
  
      actual_loss = head.loss(labels, logits, features)
      expected_loss = tf.nn.sigmoid_cross_entropy_with_logits(
          labels=labels, logits=logits
      )
  
      self.assertEqual(actual_loss.shape, [4, 1])
  
      if tf.executing_eagerly():
          self.assertEqual(actual_loss.shape, [4, 1])
          self.assertAllClose(actual_loss, expected_loss)
          return
  
      self.assertAllClose(expected_loss, self.evaluate(actual_loss))
  
file_path: privacy/tensorflow_privacy/privacy/estimators/binary_class_head_test.py
imports: import numpy
  import tensorflow
  from tensorflow_privacy.privacy.estimators import binary_class_head
  from tensorflow_privacy.privacy.estimators import test_utils
  from tensorflow_privacy.privacy.optimizers.dp_optimizer_keras import DPKerasSGDOptimizer
  from tensorflow_estimator.python.estimator import estimator
label_desc: Use image node_id 1 for calling the DPBinaryClassHeadTest obj's underlying member method code with example usage: obj.testLoss() without return types