def forward(self, x, lengths, pis, mus, sigmas, rhos, epsilon=1e-08):
    (batch_size, seq_len, M) = pis.size()
    x = x.view(batch_size, seq_len, 1, 2).repeat(1, 1, M, 1)
    sigma_prods = torch.prod(sigmas, dim=3)
    sigma_sq = torch.pow(sigmas, 2)
    x_center = ((x - mus) / sigmas)
    Z = (torch.sum((x_center * x_center), dim=3) - ((2 * rhos) * torch.prod(x_center, dim=3)))
    rho_sq = (1 - (rhos * rhos))
    denom = (((2 * np.pi) * sigma_prods) * torch.sqrt(rho_sq))
    probs = (torch.exp(((- Z) / (2 * rho_sq))) / denom)
    probs = torch.sum((F.softmax(pis, dim=(- 1)) * probs), dim=(- 1))
    log_probs = (torch.log((probs + epsilon)) * lengths)
    loss = (- torch.mean(log_probs))
    return loss
def forward(self, x, lengths, pis, mus, sigmas, rhos, epsilon=1e-08):
    (batch_size, seq_len, M) = pis.size()
    x = x.view(batch_size, seq_len, 1, 2).repeat(1, 1, M, 1)
    sigma_prods = torch.prod(sigmas, dim=3)
    sigma_sq = torch.pow(sigmas, 2)
    x_center = ((x - mus) / sigmas)
    Z = (torch.sum((x_center * x_center), dim=3) - ((2 * rhos) * torch.prod(x_center, dim=3)))
    rho_sq = (1 - (rhos * rhos))
    denom = (((2 * np.pi) * sigma_prods) * torch.sqrt(rho_sq))
    probs = (torch.exp(((- Z) / (2 * rho_sq))) / denom)
    probs = torch.sum((F.softmax(pis, dim=(- 1)) * probs), dim=(- 1))
    log_probs = (torch.log((probs + epsilon)) * lengths)
    loss = (- torch.mean(log_probs))
    return loss