import torch


def dictionary_loss(dictionary, activity, x):
    """
    Get dictionary reconstruction loss

    Args:
        dictionary (torch tensor): dictionary
        activity (torch tensor): activity
        x (torch tensor): input tensor

    Returns:
        torch tensor: reconstruction loss
    """
    return torch.mean(0.5*torch.square(torch.einsum('ij,kj->ki', dictionary, activity) - x))