import torch


def log_px_z(pred_logits, outcome):
    """
    Returns Bernoulli log probability.

    :param pred_logits: logits for outcome 1
    :param outcome: datapoint
    :return: log Bernoulli probability of outcome given logits in pred_logits
    """

    pred = pred_logits.view(pred_logits.size(0), -1)
    y = outcome.view(outcome.size(0), -1)
    return -torch.sum(torch.max(pred, torch.tensor(0., device=pred.device)) - pred * y +
                      torch.log(1 + torch.exp(-torch.abs(pred))), 1)