(self, label_index, unlabel_index)
return unlabel_index[ask_idx]
Select one unlabel-data at a time.
        Parameters
        ----------
        label_index: {list, np.ndarray, IndexCollection}
            The indexes of labeled samples. It should be a 1d array of indexes (column major, start from 0) or
            MultiLabelIndexCollection or a list of tuples with 2 elements, in which,
            the 1st element is the index of instance and the 2nd element is the index of labels.

        unlabel_index: {list, np.ndarray, IndexCollection}
            The indexes of unlabeled samples. It should be a 1d array of indexes (column major, start from 0) or
            MultiLabelIndexCollection or a list of tuples with 2 elements, in which,
            the 1st element is the index of instance and the 2nd element is the index of labels.
        Returns
        -------
        selected_ind: int
            The selected index.
Select one unlabel-data at a time.
        Parameters
        ----------
        label_index: {list, np.ndarray, IndexCollection}
            The indexes of labeled samples. It should be a 1d array of indexes (column major, start from 0) or
            MultiLabelIndexCollection or a list of tuples with 2 elements, in which,
            the 1st element is the index of instance and the 2nd element is the index of labels.
Select one unlabel - data at a time . Parameters ---------- label_index : { list np . ndarray IndexCollection } The indexes of labeled samples . It should be a 1d array of indexes ( column major start from 0 ) or MultiLabelIndexCollection or a list of tuples with 2 elements in which the 1st element is the index of instance and the 2nd element is the index of labels .
def sequential_select(self, label_index, unlabel_index):
        """
            Select one unlabel-data at a time.
        Parameters
        ----------
        label_index: {list, np.ndarray, IndexCollection}
            The indexes of labeled samples. It should be a 1d array of indexes (column major, start from 0) or
            MultiLabelIndexCollection or a list of tuples with 2 elements, in which,
            the 1st element is the index of instance and the 2nd element is the index of labels.

        unlabel_index: {list, np.ndarray, IndexCollection}
            The indexes of unlabeled samples. It should be a 1d array of indexes (column major, start from 0) or
            MultiLabelIndexCollection or a list of tuples with 2 elements, in which,
            the 1st element is the index of instance and the 2nd element is the index of labels.
        Returns
        -------
        selected_ind: int
            The selected index.
        """

        if isinstance(label_index, (list, np.ndarray)):
            label_index = IndexCollection(label_index)
        elif isinstance(label_index, MultiLabelIndexCollection):
            label_index = IndexCollection(label_index.get_unbroken_instances())
        elif not isinstance(label_index,IndexCollection):
            raise TypeError("index type error")
        if isinstance(unlabel_index, (list, np.ndarray)):
            unlabel_index = IndexCollection(unlabel_index)
        elif isinstance(unlabel_index, MultiLabelIndexCollection):
            unlabel_index = IndexCollection(unlabel_index.get_unbroken_instances())
        elif not isinstance(unlabel_index,IndexCollection):
            raise TypeError("index type error")
        
        if len(unlabel_index) <= 1:
            return list(unlabel_index)

        X_pool = self.X[unlabel_index]

        clf = _BinaryRelevance(self.base_clf)
        clf.train(self.X[label_index], self.y[label_index])
        real = clf.predict_real(X_pool)
        pred = clf.predict(X_pool)

        # Separation Margin
        pos = np.copy(real)
        pos[real <= 0] = np.inf
        neg = np.copy(real)
        neg[real >= 0] = -np.inf
        separation_margin = pos.min(axis=1) - neg.max(axis=1)
        uncertainty = 1. / separation_margin

        # Label Cardinality Inconsistency
        average_pos_lbl = self.y[label_index].mean(axis=0).sum()
        label_cardinality = np.sqrt((pred.sum(axis=1) - average_pos_lbl) ** 2)

        candidate_idx_set = set()
        for b in self.betas:
            # score shape = (len(X_pool), )
            score = uncertainty ** b * label_cardinality ** (1. - b)
            for idx in np.where(score == np.max(score))[0]:
                candidate_idx_set.add(idx)

        candidates = list(candidate_idx_set)

        approx_err = []
        for idx in candidates:
            br = _BinaryRelevance(self.base_clf)
            br.train(np.vstack((self.X[label_index], X_pool[idx])), np.vstack((self.y[label_index], pred[idx])))
            br_real = br.predict_real(X_pool)

            pos = np.copy(br_real)
            pos[br_real < 0] = 1
            pos = np.max((1. - pos), axis=1)
            pos = np.array([0 if i<0 else i for i in pos])

            neg = np.copy(br_real)
            neg[br_real > 0] = -1
            neg = np.max((1. + neg), axis=1)
            neg = np.array([0 if i<0 else i for i in neg])
            
            err = neg + pos

            approx_err.append(np.sum(err))

        choices = np.where(np.array(approx_err) == np.min(approx_err))[0]
        ask_idx = candidates[self.random_state_.choice(choices)]

        return unlabel_index[ask_idx]
def sequential_select ( self , label_index , unlabel_index ) : if isinstance ( label_index , ( list , np . ndarray ) ) : label_index = IndexCollection ( label_index ) elif isinstance ( label_index , MultiLabelIndexCollection ) : label_index = IndexCollection ( label_index . get_unbroken_instances ( ) ) elif not isinstance ( label_index , IndexCollection ) : raise TypeError ( "index type error" ) if isinstance ( unlabel_index , ( list , np . ndarray ) ) : unlabel_index = IndexCollection ( unlabel_index ) elif isinstance ( unlabel_index , MultiLabelIndexCollection ) : unlabel_index = IndexCollection ( unlabel_index . get_unbroken_instances ( ) ) elif not isinstance ( unlabel_index , IndexCollection ) : raise TypeError ( "index type error" ) if len ( unlabel_index ) <= 1 : return list ( unlabel_index ) X_pool = self . X [ unlabel_index ] clf = _BinaryRelevance ( self . base_clf ) clf . train ( self . X [ label_index ] , self . y [ label_index ] ) real = clf . predict_real ( X_pool ) pred = clf . predict ( X_pool ) # Separation Margin pos = np . copy ( real ) pos [ real <= 0 ] = np . inf neg = np . copy ( real ) neg [ real >= 0 ] = - np . inf separation_margin = pos . min ( axis = 1 ) - neg . max ( axis = 1 ) uncertainty = 1. / separation_margin # Label Cardinality Inconsistency average_pos_lbl = self . y [ label_index ] . mean ( axis = 0 ) . sum ( ) label_cardinality = np . sqrt ( ( pred . sum ( axis = 1 ) - average_pos_lbl ) ** 2 ) candidate_idx_set = set ( ) for b in self . betas : # score shape = (len(X_pool), ) score = uncertainty ** b * label_cardinality ** ( 1. - b ) for idx in np . where ( score == np . max ( score ) ) [ 0 ] : candidate_idx_set . add ( idx ) candidates = list ( candidate_idx_set ) approx_err = [ ] for idx in candidates : br = _BinaryRelevance ( self . base_clf ) br . train ( np . vstack ( ( self . X [ label_index ] , X_pool [ idx ] ) ) , np . vstack ( ( self . y [ label_index ] , pred [ idx ] ) ) ) br_real = br . predict_real ( X_pool ) pos = np . copy ( br_real ) pos [ br_real < 0 ] = 1 pos = np . max ( ( 1. - pos ) , axis = 1 ) pos = np . array ( [ 0 if i < 0 else i for i in pos ] ) neg = np . copy ( br_real ) neg [ br_real > 0 ] = - 1 neg = np . max ( ( 1. + neg ) , axis = 1 ) neg = np . array ( [ 0 if i < 0 else i for i in neg ] ) err = neg + pos approx_err . append ( np . sum ( err ) ) choices = np . where ( np . array ( approx_err ) == np . min ( approx_err ) ) [ 0 ] ask_idx = candidates [ self . random_state_ . choice ( choices ) ] return unlabel_index [ ask_idx ]