def squared_loss(y_hat, y):
    """
    Compute the squared loss of y_hat and y

    Parameters
    ----------
    y_hat : [tensor]
        the predictive value of the learning model
    y : [tensor]
        the real value of the learning model

    Returns
    -------
    [tensor]
        the squared loss of y_hat and y
    """
    # 'y_hat-y.view(y_hat.size())' is the original losses
    # **2 means square operation
    # devide by 2 to adapt the gradient compution
    # if you use the MSELoss instead, MSELoss did not divide by 2
    return (y_hat-y.view(y_hat.size()))**2/2