def IS(l,u,y,q): 
    """
    calculation of the Interval Score
    
    l:  left interval limit
    u:  right interval limit
    y:  argument of IS
    q:  quantile level corresponding to limits
    
    Output
    IS value in y for given l,u,q
    """
    if y<l:
        return 2*(l-y) + q*(u-l) 
    elif y>u:
        return 2*(y-u) + q*(u-l) 
    else:
        return q*(u-l)