def extreme_points_area(x):
    """Compute area within extreme points divided by total rectangular area.

    Parameters
    ----------
    x : array-like, shape = (n_samples)
        Data samples, where n_samples is the number of samples.

    Returns
    -------
    p_area : percentage of total area corresponding to are within
        extreme points.
    """
    n = len(x)

    pos_min = np.argmin(x)
    pos_max = np.argmax(x)

    x_iter = x[1:-1]
    if len(x_iter):
        xinit = 0
        xmin = pos_min
        xmax = pos_max
        xlast = n

        yinit = x[0]
        ymin = x[pos_min]
        ymax = x[pos_max]
        ylast = x[-1]

        triangle1 = np.array([[xinit, xmin, xmax],
                              [yinit, ymin, ymax], [1, 1, 1]])
        triangle2 = np.array([[xmin, xmax, xlast],
                              [ymin, ymax, ylast], [1, 1, 1]])

        area_1 = 0.5 * np.abs(np.linalg.det(triangle1))
        area_2 = 0.5 * np.abs(np.linalg.det(triangle2))
        sum_area = area_1 + area_2

        p_area = sum_area / ((ymax - ymin) * n)
    else:
        p_area = 0

    return p_area
Compute area within extreme points divided by total rectangular area.

    Parameters
    ----------
    x : array-like, shape = (n_samples)
        Data samples, where n_samples is the number of samples.

    Returns
    -------
    p_area : percentage of total area corresponding to are within
        extreme points.
    
optbinning/binning/auto_monotonic.py