(cls, C, force=False)
Entropy discretization on a sorted C.

        :param C: (N, K) array of class distributions.
Entropy discretization on a sorted C.
Entropy discretization on a sorted C .
def _entropy_discretize_sorted(cls, C, force=False):
        """
        Entropy discretization on a sorted C.

        :param C: (N, K) array of class distributions.

        """
        E, ES1, ES2 = cls._entropy_cuts_sorted(C)
        # TODO: Also get the left right distribution counts from
        # entropy_cuts_sorted,

        # Note the + 1
        if len(E) == 0:
            return []
        cut_index = np.argmin(E) + 1

        # Distribution of classed in S1, S2 and S
        S1_c = np.sum(C[:cut_index], axis=0)
        S2_c = np.sum(C[cut_index:], axis=0)
        S_c = S1_c + S2_c

        ES = cls._entropy1(np.sum(C, axis=0))
        ES1, ES2 = ES1[cut_index - 1], ES2[cut_index - 1]

        # Information gain of the best split
        Gain = ES - E[cut_index - 1]
        # Number of different classes in S, S1 and S2
        k = float(np.sum(S_c > 0))
        k1 = float(np.sum(S1_c > 0))
        k2 = float(np.sum(S2_c > 0))

        assert k > 0
        delta = np.log2(3 ** k - 2) - (k * ES - k1 * ES1 - k2 * ES2)
        N = float(np.sum(S_c))

        if N > 1 and Gain > np.log2(N - 1) / N + delta / N:
            # Accept the cut point and recursively split the subsets.
            left, right = [], []
            if k1 > 1 and cut_index > 1:
                left = cls._entropy_discretize_sorted(C[:cut_index, :])
            if k2 > 1 and cut_index < len(C) - 1:
                right = cls._entropy_discretize_sorted(C[cut_index:, :])
            return left + [cut_index] + [i + cut_index for i in right]
        elif force:
            return [cut_index]
        else:
            return []
def _entropy_discretize_sorted ( cls , C , force = False ) : E , ES1 , ES2 = cls . _entropy_cuts_sorted ( C ) # TODO: Also get the left right distribution counts from # entropy_cuts_sorted, # Note the + 1 if len ( E ) == 0 : return [ ] cut_index = np . argmin ( E ) + 1 # Distribution of classed in S1, S2 and S S1_c = np . sum ( C [ : cut_index ] , axis = 0 ) S2_c = np . sum ( C [ cut_index : ] , axis = 0 ) S_c = S1_c + S2_c ES = cls . _entropy1 ( np . sum ( C , axis = 0 ) ) ES1 , ES2 = ES1 [ cut_index - 1 ] , ES2 [ cut_index - 1 ] # Information gain of the best split Gain = ES - E [ cut_index - 1 ] # Number of different classes in S, S1 and S2 k = float ( np . sum ( S_c > 0 ) ) k1 = float ( np . sum ( S1_c > 0 ) ) k2 = float ( np . sum ( S2_c > 0 ) ) assert k > 0 delta = np . log2 ( 3 ** k - 2 ) - ( k * ES - k1 * ES1 - k2 * ES2 ) N = float ( np . sum ( S_c ) ) if N > 1 and Gain > np . log2 ( N - 1 ) / N + delta / N : # Accept the cut point and recursively split the subsets. left , right = [ ] , [ ] if k1 > 1 and cut_index > 1 : left = cls . _entropy_discretize_sorted ( C [ : cut_index , : ] ) if k2 > 1 and cut_index < len ( C ) - 1 : right = cls . _entropy_discretize_sorted ( C [ cut_index : , : ] ) return left + [ cut_index ] + [ i + cut_index for i in right ] elif force : return [ cut_index ] else : return [ ]