(self, unlabel_index, predict, batch_size=1)
Select indexes from the unlabel_index for querying.

        Parameters
        ----------
        unlabel_index: {list, np.ndarray, IndexCollection}
            The indexes of unlabeled samples. Should be one-to-one
            correspondence to the prediction matrix.

        predict: 2d array, shape [n_samples, n_classes]
            The probabilistic prediction matrix for the unlabeled set.

        batch_size: int, optional (default=1)
            Selection batch size.

        Returns
        -------
        selected_idx: list
            The selected indexes which is a subset of unlabel_index.
Select indexes from the unlabel_index for querying.
Select indexes from the unlabel_index for querying .
def select_by_prediction_mat(self, unlabel_index, predict, batch_size=1):
        """Select indexes from the unlabel_index for querying.

        Parameters
        ----------
        unlabel_index: {list, np.ndarray, IndexCollection}
            The indexes of unlabeled samples. Should be one-to-one
            correspondence to the prediction matrix.

        predict: 2d array, shape [n_samples, n_classes]
            The probabilistic prediction matrix for the unlabeled set.

        batch_size: int, optional (default=1)
            Selection batch size.

        Returns
        -------
        selected_idx: list
            The selected indexes which is a subset of unlabel_index.
        """
        assert (batch_size > 0)
        assert (isinstance(unlabel_index, collections.Iterable))
        unlabel_index = np.asarray(unlabel_index)
        if len(unlabel_index) <= batch_size:
            return unlabel_index

        pv = np.asarray(predict)  # predict value
        spv = np.shape(pv)  # shape of predict value

        if self.measure == 'distance_to_boundary':
            assert (len(spv) in [1, 2])
            if len(spv) == 2:
                if spv[1] != 1:
                    raise Exception('1d or 2d with 1 column array is expected, but received: \n%s' % str(pv))
                else:
                    pv = np.absolute(np.array(pv).flatten())
            else:
                pv = np.absolute(pv)
            return unlabel_index[nsmallestarg(pv, batch_size)]

        if len(spv) != 2 or spv[1] == 1:
            raise Exception('2d array with the shape [n_samples, n_classes]'
                            ' is expected, but received shape: \n%s' % str(spv))

        if self.measure == 'entropy':
            # calc entropy
            pv[pv <= 0] = 1e-06  # avoid zero division
            entro = [-np.sum(vec * np.log(vec+1e-9)) for vec in pv]
            assert (len(np.shape(entro)) == 1)
            return unlabel_index[nlargestarg(entro, batch_size)]

        if self.measure == 'margin':
            # calc margin
            pat = np.partition(pv, (spv[1] - 2, spv[1] - 1), axis=1)
            pat = pat[:, spv[1] - 2] - pat[:, spv[1] - 1]
            return unlabel_index[nlargestarg(pat, batch_size)]

        if self.measure == 'least_confident':
            # calc least_confident
            pat = np.partition(pv, spv[1] - 1, axis=1)
            pat = 1 - pat[:, spv[1] - 1]
            return unlabel_index[nlargestarg(pat, batch_size)]
def select_by_prediction_mat ( self , unlabel_index , predict , batch_size = 1 ) : assert ( batch_size > 0 ) assert ( isinstance ( unlabel_index , collections . Iterable ) ) unlabel_index = np . asarray ( unlabel_index ) if len ( unlabel_index ) <= batch_size : return unlabel_index pv = np . asarray ( predict ) # predict value spv = np . shape ( pv ) # shape of predict value if self . measure == 'distance_to_boundary' : assert ( len ( spv ) in [ 1 , 2 ] ) if len ( spv ) == 2 : if spv [ 1 ] != 1 : raise Exception ( '1d or 2d with 1 column array is expected, but received: \n%s' % str ( pv ) ) else : pv = np . absolute ( np . array ( pv ) . flatten ( ) ) else : pv = np . absolute ( pv ) return unlabel_index [ nsmallestarg ( pv , batch_size ) ] if len ( spv ) != 2 or spv [ 1 ] == 1 : raise Exception ( '2d array with the shape [n_samples, n_classes]' ' is expected, but received shape: \n%s' % str ( spv ) ) if self . measure == 'entropy' : # calc entropy pv [ pv <= 0 ] = 1e-06 # avoid zero division entro = [ - np . sum ( vec * np . log ( vec + 1e-9 ) ) for vec in pv ] assert ( len ( np . shape ( entro ) ) == 1 ) return unlabel_index [ nlargestarg ( entro , batch_size ) ] if self . measure == 'margin' : # calc margin pat = np . partition ( pv , ( spv [ 1 ] - 2 , spv [ 1 ] - 1 ) , axis = 1 ) pat = pat [ : , spv [ 1 ] - 2 ] - pat [ : , spv [ 1 ] - 1 ] return unlabel_index [ nlargestarg ( pat , batch_size ) ] if self . measure == 'least_confident' : # calc least_confident pat = np . partition ( pv , spv [ 1 ] - 1 , axis = 1 ) pat = 1 - pat [ : , spv [ 1 ] - 1 ] return unlabel_index [ nlargestarg ( pat , batch_size ) ]