def log_stability(x):
    """Log-stability for computing loss

    :param x: Input value
    :type x: float
    :return: Scaled value where :math:`\\hat{x} \\in (0, 1)`
    :rtype: float
    """
    if x == 0:
        return 10e-9
    elif x == 1:
        return 1.0-10e-9
    else:
        return x