# 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/base_loss.py
# class MinDiffLoss(tf.keras.losses.Loss, abc.ABC):
#   def __init__(self,
#                membership_transform=None,
#                predictions_transform=None,
#                membership_kernel=None,
#                predictions_kernel=None,
#                name: Optional[str] = None,
#                enable_summary_histogram: Optional[bool] = True):
#   def __call__(self,
#                membership: types.TensorType,
#                predictions: types.TensorType,
#                sample_weight: Optional[types.TensorType] = None):
#   def _preprocess_inputs(
#       self,
#       membership: types.TensorType,
#       predictions: types.TensorType,
#       sample_weight: Optional[types.TensorType] = None
#   ) -> Tuple[types.TensorType, types.TensorType, types.TensorType]:
#   def _apply_kernels(
#       self, membership: types.TensorType, predictions: types.TensorType
#   ) -> Tuple[types.TensorType, types.TensorType]:
#   def call(self,
#            membership: types.TensorType,
#            predictions: types.TensorType,
#            sample_weight: Optional[types.TensorType] = None):
#   def _serialize_config(self, config):
#     def _serialize_value(key, value):
#   def get_config(self):
#   def _deserialize_config(cls, config):
#     def _deserialize_value(key, value):
#   def from_config(cls, config):
# def _validate_transform(transform: types.TensorTransformType,
#                         var_name: str) -> None:
# def _to_snake_case(name):
# 
# Path: tensorflow_model_remediation/min_diff/losses/loss_utils.py
# _STRING_TO_LOSS_DICT = {}
# def _register_loss_names(loss_class, names):
# def _get_loss(loss: Union[base_loss.MinDiffLoss, str],
#               loss_var_name: str = 'loss') -> base_loss.MinDiffLoss:
# 
# Path: tensorflow_model_remediation/min_diff/losses/mmd_loss.py
# class MMDLoss(base_loss.MinDiffLoss):
#   def __init__(self,
#                kernel="gaussian",
#                predictions_transform=None,
#                name: Optional[str] = None,
#                enable_summary_histogram: Optional[bool] = True):
#   def _preprocess(self,
#                   membership: types.TensorType,
#                   predictions: types.TensorType,
#                   sample_weight: Optional[types.TensorType] = None):
#   def _calculate_mean(self, predictions_kernel: types.TensorType,
#                       normed_weights: types.TensorType,
#                       pos_mask: types.TensorType, neg_mask):
#   def call(self,
#            membership: types.TensorType,
#            predictions: types.TensorType,
#            sample_weight: Optional[types.TensorType] = None):
#   def from_config(cls, config):


import tensorflow as tf
from tensorflow_model_remediation.min_diff.losses import absolute_correlation_loss as abscorrloss
from tensorflow_model_remediation.min_diff.losses import base_loss
from tensorflow_model_remediation.min_diff.losses import loss_utils as utils
from tensorflow_model_remediation.min_diff.losses import mmd_loss
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for loss_utils functions."""




class GetMinDiffLossTest(tf.test.TestCase):

  def testAcceptsNone(self):
    loss = utils._get_loss(None)
    self.assertIsNone(loss)

  def testForAbsoluteCorrelationLoss(self):
    loss = utils._get_loss('abs_corr')
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss = utils._get_loss('abS_coRr')  # Strangely capitalized.
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss = utils._get_loss('abs_corr_loss')  # Other accepted name.
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss = utils._get_loss('absolute_correlation')  # Other accepted name.
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss = utils._get_loss('absolute_correlation_loss')  # Other accepted name.
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss_name = 'custom_name'

# 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/base_loss.py
# class MinDiffLoss(tf.keras.losses.Loss, abc.ABC):
#   def __init__(self,
#                membership_transform=None,
#                predictions_transform=None,
#                membership_kernel=None,
#                predictions_kernel=None,
#                name: Optional[str] = None,
#                enable_summary_histogram: Optional[bool] = True):
#   def __call__(self,
#                membership: types.TensorType,
#                predictions: types.TensorType,
#                sample_weight: Optional[types.TensorType] = None):
#   def _preprocess_inputs(
#       self,
#       membership: types.TensorType,
#       predictions: types.TensorType,
#       sample_weight: Optional[types.TensorType] = None
#   ) -> Tuple[types.TensorType, types.TensorType, types.TensorType]:
#   def _apply_kernels(
#       self, membership: types.TensorType, predictions: types.TensorType
#   ) -> Tuple[types.TensorType, types.TensorType]:
#   def call(self,
#            membership: types.TensorType,
#            predictions: types.TensorType,
#            sample_weight: Optional[types.TensorType] = None):
#   def _serialize_config(self, config):
#     def _serialize_value(key, value):
#   def get_config(self):
#   def _deserialize_config(cls, config):
#     def _deserialize_value(key, value):
#   def from_config(cls, config):
# def _validate_transform(transform: types.TensorTransformType,
#                         var_name: str) -> None:
# def _to_snake_case(name):
# 
# Path: tensorflow_model_remediation/min_diff/losses/loss_utils.py
# _STRING_TO_LOSS_DICT = {}
# def _register_loss_names(loss_class, names):
# def _get_loss(loss: Union[base_loss.MinDiffLoss, str],
#               loss_var_name: str = 'loss') -> base_loss.MinDiffLoss:
# 
# Path: tensorflow_model_remediation/min_diff/losses/mmd_loss.py
# class MMDLoss(base_loss.MinDiffLoss):
#   def __init__(self,
#                kernel="gaussian",
#                predictions_transform=None,
#                name: Optional[str] = None,
#                enable_summary_histogram: Optional[bool] = True):
#   def _preprocess(self,
#                   membership: types.TensorType,
#                   predictions: types.TensorType,
#                   sample_weight: Optional[types.TensorType] = None):
#   def _calculate_mean(self, predictions_kernel: types.TensorType,
#                       normed_weights: types.TensorType,
#                       pos_mask: types.TensorType, neg_mask):
#   def call(self,
#            membership: types.TensorType,
#            predictions: types.TensorType,
#            sample_weight: Optional[types.TensorType] = None):
#   def from_config(cls, config):


# Path: tensorflow_model_remediation/min_diff/losses/loss_utils_test.py
import tensorflow as tf
from tensorflow_model_remediation.min_diff.losses import absolute_correlation_loss as abscorrloss
from tensorflow_model_remediation.min_diff.losses import base_loss
from tensorflow_model_remediation.min_diff.losses import loss_utils as utils
from tensorflow_model_remediation.min_diff.losses import mmd_loss

#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for loss_utils functions."""




class GetMinDiffLossTest(tf.test.TestCase):

  def testAcceptsNone(self):
    loss = utils._get_loss(None)
    self.assertIsNone(loss)

  def testForAbsoluteCorrelationLoss(self):
    loss = utils._get_loss('abs_corr')
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss = utils._get_loss('abS_coRr')  # Strangely capitalized.
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss = utils._get_loss('abs_corr_loss')  # Other accepted name.
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss = utils._get_loss('absolute_correlation')  # Other accepted name.
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss = utils._get_loss('absolute_correlation_loss')  # Other accepted name.
    self.assertIsInstance(loss, abscorrloss.AbsoluteCorrelationLoss)
    loss_name = 'custom_name'

    loss = utils._get_loss(abscorrloss.AbsoluteCorrelationLoss(loss_name))