import tensorflow as tf


def triplet_loss(anchor, positive, negative, alpha=0.2, name='triplet_loss'):
  """Calculate the triplet loss according to the FaceNet paper.

  Args:
    anchor: 2-D `tensor` [batch_size, embedding_size], the embeddings for the anchor images.
    positive: 2-D `tensor` [batch_size, embedding_size], the embeddings for the positive images.
    negative: 2-D `tensor` [batch_size, embedding_size], the embeddings for the negative images.
    alpha: positive to negative triplet distance margin

  Returns:
    the triplet loss.
  """
  with tf.name_scope(name):
    pos_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, positive)), 1)
    neg_dist = tf.reduce_sum(tf.square(tf.subtract(anchor, negative)), 1)
    basic_loss = tf.add(tf.subtract(pos_dist, neg_dist), alpha)
    loss = tf.reduce_mean(tf.maximum(basic_loss, 0.0), 0)
  return loss


def decov_loss(xs, name='decov_loss'):
  """Decov loss as described in https://arxiv.org/pdf/1511.06068.pdf 'Reducing
  Overfitting In Deep Networks by Decorrelating Representation'.

  Args:
      xs: 4-D `tensor` [batch_size, height, width, channels], input

