# Path: tensorflow_model_remediation/min_diff/losses/absolute_correlation_loss.py
# _EPSILON = 1.0e-7
# class AbsoluteCorrelationLoss(base_loss.MinDiffLoss):
#   def __init__(self, name: Optional[str] = None,
#                enable_summary_histogram: Optional[bool] = True):
#   def call(
#       self,
#       sensitive_group_labels: types.TensorType,
#       y_pred: types.TensorType,
#       sample_weight: Optional[types.TensorType] = None) -> types.TensorType:


import tensorflow as tf
from tensorflow_model_remediation.min_diff.losses import absolute_correlation_loss as loss_lib
          sess.run(loss_value)

  def testAllZeroWeights(self):
    loss_fn = loss_lib.AbsoluteCorrelationLoss()
    membership = tf.constant([[1.0], [0.0], [1.0], [0.0], [1.0]])
    predictions = tf.constant([[0.12], [0.7], [0.2], [0.86], [0.32]])
    sample_weights = tf.constant([[0.0], [0.0], [0.0], [0.0], [0.0]])

    loss_value = loss_fn(membership, predictions, sample_weights)
    self.assertAllClose(0, loss_value)

  def testGradients(self):
    loss_fn = loss_lib.AbsoluteCorrelationLoss()
    variables = tf.constant([[0.1], [0.3], [0.5], [0.7], [0.9]])
    membership = tf.constant([[1.0], [0.0], [1.0], [0.0], [1.0]])
    sample_weights = tf.constant([[1.0], [2.0], [2.5], [1.2], [0.9]])

    with tf.GradientTape() as tape:
      tape.watch(variables)
      predictions = variables * 3  # arbitrary linear operation.
      loss_value = loss_fn(membership, predictions, sample_weights)

    gradients = tape.gradient(loss_value, variables)
    # Assert that gradient computations are non trivial and do not change based
    # on loss implementation.
    expected_gradients = [[0.5481868], [-1.2328656], [1.1707227], [-0.83559656],
                          [0.34955233]]
    self.assertAllClose(expected_gradients, gradients)

  def testGradientsWithAllZeroWeights(self):

# Path: tensorflow_model_remediation/min_diff/losses/absolute_correlation_loss.py
# _EPSILON = 1.0e-7
# class AbsoluteCorrelationLoss(base_loss.MinDiffLoss):
#   def __init__(self, name: Optional[str] = None,
#                enable_summary_histogram: Optional[bool] = True):
#   def call(
#       self,
#       sensitive_group_labels: types.TensorType,
#       y_pred: types.TensorType,
#       sample_weight: Optional[types.TensorType] = None) -> types.TensorType:


# Path: tensorflow_model_remediation/min_diff/losses/absolute_correlation_loss_test.py
import tensorflow as tf
from tensorflow_model_remediation.min_diff.losses import absolute_correlation_loss as loss_lib

          sess.run(loss_value)

  def testAllZeroWeights(self):
    loss_fn = loss_lib.AbsoluteCorrelationLoss()
    membership = tf.constant([[1.0], [0.0], [1.0], [0.0], [1.0]])
    predictions = tf.constant([[0.12], [0.7], [0.2], [0.86], [0.32]])
    sample_weights = tf.constant([[0.0], [0.0], [0.0], [0.0], [0.0]])

    loss_value = loss_fn(membership, predictions, sample_weights)
    self.assertAllClose(0, loss_value)

  def testGradients(self):
    loss_fn = loss_lib.AbsoluteCorrelationLoss()
    variables = tf.constant([[0.1], [0.3], [0.5], [0.7], [0.9]])
    membership = tf.constant([[1.0], [0.0], [1.0], [0.0], [1.0]])
    sample_weights = tf.constant([[1.0], [2.0], [2.5], [1.2], [0.9]])

    with tf.GradientTape() as tape:
      tape.watch(variables)
      predictions = variables * 3  # arbitrary linear operation.
      loss_value = loss_fn(membership, predictions, sample_weights)

    gradients = tape.gradient(loss_value, variables)
    # Assert that gradient computations are non trivial and do not change based
    # on loss implementation.
    expected_gradients = [[0.5481868], [-1.2328656], [1.1707227], [-0.83559656],
                          [0.34955233]]
    self.assertAllClose(expected_gradients, gradients)

  def testGradientsWithAllZeroWeights(self):

    loss_fn = loss_lib.AbsoluteCorrelationLoss()