import torch


def SNRPSA(s,s_hat):
    """Computes the SNR_PSA as proposed in [1], with no compression and a saturation value of 20

    References
    ----------
    .. [1] Erdogan, Hakan, and Takuya Yoshioka. "Investigations on Data Augmentation and Loss Functions
    for Deep Learning Based Speech-Background Separation." Interspeech. 2018.

    Parameters:
        s: list of targets of any shape, with len(x) = #sources
        s_hat: list of corresponding estimates
    """
    EPS = torch.finfo(s[0].dtype).eps
    den = [x_hat - x for x, x_hat in zip(s, s_hat)]
    prima = [-10 * torch.log10((x ** 2).sum()/(xa ** 2).sum() + EPS) for x, xa in zip(s, den)]
    clipping = [20*torch.tanh(x/20) for x in prima]
    return torch.stack(clipping).sum()/len(clipping)