(self, label_index, unlabel_index, model=None, epsilon=0.5, **kwargs)
return [(selected_ins, selected_lab)]
Select a subset from the unlabeled set, return the selected instance and label.

        Parameters
        ----------
        label_index: {list, np.ndarray, MultiLabelIndexCollection}
            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, MultiLabelIndexCollection}
            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.

        model: LabelRankingModel (optional, default=None)
            A trained model used to predict unlabeled data.
            If None is passed, it will re-train a LabelRanking model.

        epsilon: float, optional (default=0.5)
            The threshold to avoid zero-division.

        Returns
        -------
        selected_ins_lab_pair: list
            A list of tuples that contains the indexes of selected instance-label pairs.
Select a subset from the unlabeled set, return the selected instance and label.
Select a subset from the unlabeled set return the selected instance and label .
def select(self, label_index, unlabel_index, model=None, epsilon=0.5, **kwargs):
        """Select a subset from the unlabeled set, return the selected instance and label.

        Parameters
        ----------
        label_index: {list, np.ndarray, MultiLabelIndexCollection}
            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, MultiLabelIndexCollection}
            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.

        model: LabelRankingModel (optional, default=None)
            A trained model used to predict unlabeled data.
            If None is passed, it will re-train a LabelRanking model.

        epsilon: float, optional (default=0.5)
            The threshold to avoid zero-division.

        Returns
        -------
        selected_ins_lab_pair: list
            A list of tuples that contains the indexes of selected instance-label pairs.
        """
        if len(unlabel_index) <= 1:
            return unlabel_index
        unlabel_index = self._check_multi_label_ind(unlabel_index)
        label_index = self._check_multi_label_ind(label_index)

        unlab_data, _, data_ind = get_Xy_in_multilabel(index=unlabel_index, X=self.X, y=self.y)
        W = unlabel_index.get_matrix_mask(mat_shape=self.y.shape, fill_value=1, sparse=False)
        if model is not None:
            assert isinstance(model, LabelRankingModel), 'Model for selection must be LabelRanking model in ' \
                                                         'AUDI algorithm. Try to pass model=None to use the ' \
                                                         'default model'
            self._lr_model = model
            if not self._lr_model._init_flag:   # not trained
                lab_data, lab_lab, _ = get_Xy_in_multilabel(index=label_index, X=self.X, y=self.y)
                self._lr_model.fit(lab_data, lab_lab)
        else:
            # select instance by LCI
            lab_data, lab_lab, _ = get_Xy_in_multilabel(index=label_index, X=self.X, y=self.y)
            self._lr_model.fit(lab_data, lab_lab)
        pres, labels = self._lr_model.predict(unlab_data)
        avgP = np.mean(np.sum(self.y[label_index.get_unbroken_instances(), :] == 1, axis=1))
        insvals = -np.abs((np.sum(labels == 1, axis=1) - avgP) / np.fmax(np.sum(W[data_ind, :] == 1, axis=1), epsilon))
        selected_ins = np.argmin(insvals)

        # last line in pres is the predict value of dummy label
        # select label by calculating the distance between each label with dummy label

        # set the known entries to inf
        pres_mask = np.asarray(1 - W[data_ind], dtype=bool)
        pres_tmp = pres[:, 0:-1]
        pres_tmp[pres_mask] = np.NINF
        pres[:, 0:-1] = pres_tmp
        sel_ins_label_mask = pres_mask[selected_ins]

        dis = np.abs(pres[selected_ins, 0:-1] - pres[selected_ins, -1])
        selected_lab = np.argmin(dis)
        if sel_ins_label_mask[selected_lab]:
            # select a labeled entry
            argsorted_dis = np.argsort(dis) # ascent
            for dis_ind in argsorted_dis:
                if not sel_ins_label_mask[dis_ind]:
                    selected_lab = dis_ind
                    break
        selected_ins = data_ind[selected_ins]

        return [(selected_ins, selected_lab)]
def select ( self , label_index , unlabel_index , model = None , epsilon = 0.5 , * * kwargs ) : if len ( unlabel_index ) <= 1 : return unlabel_index unlabel_index = self . _check_multi_label_ind ( unlabel_index ) label_index = self . _check_multi_label_ind ( label_index ) unlab_data , _ , data_ind = get_Xy_in_multilabel ( index = unlabel_index , X = self . X , y = self . y ) W = unlabel_index . get_matrix_mask ( mat_shape = self . y . shape , fill_value = 1 , sparse = False ) if model is not None : assert isinstance ( model , LabelRankingModel ) , 'Model for selection must be LabelRanking model in ' 'AUDI algorithm. Try to pass model=None to use the ' 'default model' self . _lr_model = model if not self . _lr_model . _init_flag : # not trained lab_data , lab_lab , _ = get_Xy_in_multilabel ( index = label_index , X = self . X , y = self . y ) self . _lr_model . fit ( lab_data , lab_lab ) else : # select instance by LCI lab_data , lab_lab , _ = get_Xy_in_multilabel ( index = label_index , X = self . X , y = self . y ) self . _lr_model . fit ( lab_data , lab_lab ) pres , labels = self . _lr_model . predict ( unlab_data ) avgP = np . mean ( np . sum ( self . y [ label_index . get_unbroken_instances ( ) , : ] == 1 , axis = 1 ) ) insvals = - np . abs ( ( np . sum ( labels == 1 , axis = 1 ) - avgP ) / np . fmax ( np . sum ( W [ data_ind , : ] == 1 , axis = 1 ) , epsilon ) ) selected_ins = np . argmin ( insvals ) # last line in pres is the predict value of dummy label # select label by calculating the distance between each label with dummy label # set the known entries to inf pres_mask = np . asarray ( 1 - W [ data_ind ] , dtype = bool ) pres_tmp = pres [ : , 0 : - 1 ] pres_tmp [ pres_mask ] = np . NINF pres [ : , 0 : - 1 ] = pres_tmp sel_ins_label_mask = pres_mask [ selected_ins ] dis = np . abs ( pres [ selected_ins , 0 : - 1 ] - pres [ selected_ins , - 1 ] ) selected_lab = np . argmin ( dis ) if sel_ins_label_mask [ selected_lab ] : # select a labeled entry argsorted_dis = np . argsort ( dis ) # ascent for dis_ind in argsorted_dis : if not sel_ins_label_mask [ dis_ind ] : selected_lab = dis_ind break selected_ins = data_ind [ selected_ins ] return [ ( selected_ins , selected_lab ) ]