def trimmed(f, x, margin=1):
    """
    Apply function `f` to all values of array_like `x` where `0 < x < 1`.
    For values of `x` that are 0 or 1, we return minimum / maximum of all values 
    of f for internal points, minus / plus margin.
    
    Useful in combination with logodds for future visualization 
    (i.e. values minimum - margin and maximum + margin correspond to -∞ and +∞)
    """
   
    x = x.copy()
    
    assert ((x >= 0) & (x <= 1)).all()
    
    internal_points = (x != 0) & (x != 1)
    x[internal_points] = f(x[internal_points])
    f_max = x[internal_points].max()
    f_min = x[internal_points].min()
    x[x == 1] = f_max + margin
    x[x == 0] = f_min - margin
    return x