def mdl_numeric(x, y, accuracy):
    x_unique = list(np.unique(x))
    if len(x_unique) == 1:
        return None
    indices = x.argsort()  # sort numeric attribute
    x, y = x[indices], y[indices]  # save sorted features with sorted labels

    right_dist = np.bincount(y)
    dummy_class = np.array([len(right_dist)])
    class_indices = right_dist.nonzero()[0]
    right_dist = right_dist[class_indices]
    left_dist = np.zeros(len(class_indices))
    y_dist = Counter(dict(zip(class_indices, right_dist)))

    diffs = np.nonzero(y[:-1] != y[1:])[0] + 1  # different neighbor classes have value True
    if accuracy > 0:
        diffs = np.array([diffs[i] for i in range(1, len(diffs)) if diffs[i] - diffs[i - 1] > accuracy],
                         dtype=np.int32) if len(diffs) > 15 else diffs
    intervals = np.array((np.concatenate(([0], diffs[:-1])), diffs)).T

    dist = [Counter(dict(zip(class_indices, np.bincount(np.concatenate((dummy_class, y[i:j])))[class_indices]))) for
            i, j in intervals]

    prior_mdl = calc_mdl(dist, y_dist)
    max_mdl, max_i = 0, 0

    for i in range(1, len(dist)):
        # iter 0: take first distribution
        dist0_x = dist[:i]
        dist0_y = np.sum(dist0_x)
        post_mdl0 = calc_mdl(dist0_x, dist0_y)

        # iter 0: take the other distributions without first
        dist1_x = dist[i:]
        dist1_y = np.sum(dist1_x)
        post_mdl1 = calc_mdl(dist1_x, dist1_y)
        coef = np.true_divide([sum(dist0_y.values()), sum(dist1_y.values())], len(x))

        mdl_val = prior_mdl - np.dot(coef, [post_mdl0, post_mdl1])  # calculate mdl
        if mdl_val > max_mdl:
            max_mdl, max_i = mdl_val, i

    max_i, max_j = intervals[max_i]
    if x[max_i] == x[max_j]:
        ind = x_unique.index(x[max_i])
        mean = np.mean((x[1 if ind == 0 else ind - 1], x[ind]))
    else:
        mean = np.mean((x[max_i], x[max_j]))
    return (max_mdl, [mean, mean])
dataset/ETHPy150Open romanorac/discomll/discomll/ensemble/core/measures.py/mdl_numeric/original