import torch


def lp_gamma_nll(log_alpha, log_beta, target):
    """
    Negative log-likelihood of a log-parametrized gamma distribution
    """
    # Log-Likelihood = α log(β) - log(Γ(α)) + (α-1) log(x) - βx\
    alpha = torch.exp(log_alpha)
    beta = torch.exp(log_beta)
    ll = alpha * log_beta \
        - torch.lgamma(alpha) \
        + (alpha - 1) * torch.log(target + 1e-3) \
        - beta * target
    return -torch.mean(ll)