def soft_threshold(x, threshold):
    """
    If abs(x) is less than or equal to threshold
    then return 0, else move the value towards
    0 by the threshold amount.
    """
    if x > threshold:
        val = x - threshold
    elif x < -threshold:
        val = x + threshold
    else:
        val = 0
    return val