import torch


def computeAdversarialLosses(discriminator,discriminatorX, x, x1, y, y1):
    """
    This function is used to compute the adversarial losses
    for the discriminator and the generator
    The equations are Equation(7)(8)(9) in Chp6
    :param discriminator:
    :param x:
    :param x1:
    :param y:
    :param y1:
    :return:
    """

    dx = discriminatorX(x)
    dx1 = discriminatorX(x1)
    dy = discriminator(y)
    dy1 = discriminator(y1)

    ad = torch.mean(dx) - torch.mean(dx1) + \
         torch.mean(dy) - torch.mean(dy1)

    ag = torch.mean(dx1) + torch.mean(dy1)

    return ad, ag