(self, indexes)
return sup_info, costs
Query function in multi-label setting

        In multi-label setting, a query index is a tuple.
        A single index should only have 1 element (example_index, ) to query all _labels or
        2 elements (example_index, [label_indexes]) to query specific _labels.
        A list of index can be provided.

        Parameters
        ----------
        indexes: list or tuple or int
            index to query, if only one index to query (batch_size = 1),a tuple or an int is expected.
            e.g., in 10 class classification setting, queried_index = (1, [3,4])
            means query the 2nd instance's 4th,5th _labels.
            some legal single index _examples:
            queried_index = (1, [3,4])
            queried_index = (1, [3])
            queried_index = (1, 3)
            queried_index = (1, (3))
            queried_index = (1, (3,4))
            queried_index = (1, )   # query all _labels

            One or more indexes could be provided.

        Returns
        -------
        sup_info: list
            supervised information of queried index.

        costs: list
            corresponding costs produced by query.
Query function in multi-label setting
Query function in multi - label setting
def query_by_index(self, indexes):
        """Query function in multi-label setting

        In multi-label setting, a query index is a tuple.
        A single index should only have 1 element (example_index, ) to query all _labels or
        2 elements (example_index, [label_indexes]) to query specific _labels.
        A list of index can be provided.

        Parameters
        ----------
        indexes: list or tuple or int
            index to query, if only one index to query (batch_size = 1),a tuple or an int is expected.
            e.g., in 10 class classification setting, queried_index = (1, [3,4])
            means query the 2nd instance's 4th,5th _labels.
            some legal single index _examples:
            queried_index = (1, [3,4])
            queried_index = (1, [3])
            queried_index = (1, 3)
            queried_index = (1, (3))
            queried_index = (1, (3,4))
            queried_index = (1, )   # query all _labels

            One or more indexes could be provided.

        Returns
        -------
        sup_info: list
            supervised information of queried index.

        costs: list
            corresponding costs produced by query.
        """
        # check validity of the given indexes
        indexes = check_index_multilabel(indexes)

        # prepare queried _labels
        sup_info = []
        costs = []
        for k in indexes:
            # k is a tuple with 2 elements
            k_len = len(k)
            if k_len != 1 and k_len != 2:
                raise ValueError(
                    "A single index should only have 1 element (example_index, ) to query all _labels or"
                    "2 elements (example_index, [label_indexes]) to query specific _labels. But found %d in %s" %
                    (len(k), str(k)))
            example_ind = k[0]
            if k_len == 1:
                label_ind = [i for i in range(self._label_shape[1])]
            else:
                if isinstance(k[1], collections.Iterable):
                    label_ind = [i for i in k[1] if 0 <= i < self._label_shape[1]]
                else:
                    assert (0 <= k[1] < self._label_shape[1])
                    label_ind = [k[1]]

            # fetch data
            if example_ind in self._ind2all.keys():
                if self._cost_flag:
                    sup_info.append(self._ind2all[example_ind][0][label_ind])
                    costs.append(self._ind2all[example_ind][1][label_ind])
                else:
                    sup_info.append(self._ind2all[example_ind][label_ind])
                    costs.append(np.ones(len(label_ind)))
            else:
                self._do_missing(k)
        return sup_info, costs
def query_by_index ( self , indexes ) : # check validity of the given indexes indexes = check_index_multilabel ( indexes ) # prepare queried _labels sup_info = [ ] costs = [ ] for k in indexes : # k is a tuple with 2 elements k_len = len ( k ) if k_len != 1 and k_len != 2 : raise ValueError ( "A single index should only have 1 element (example_index, ) to query all _labels or" "2 elements (example_index, [label_indexes]) to query specific _labels. But found %d in %s" % ( len ( k ) , str ( k ) ) ) example_ind = k [ 0 ] if k_len == 1 : label_ind = [ i for i in range ( self . _label_shape [ 1 ] ) ] else : if isinstance ( k [ 1 ] , collections . Iterable ) : label_ind = [ i for i in k [ 1 ] if 0 <= i < self . _label_shape [ 1 ] ] else : assert ( 0 <= k [ 1 ] < self . _label_shape [ 1 ] ) label_ind = [ k [ 1 ] ] # fetch data if example_ind in self . _ind2all . keys ( ) : if self . _cost_flag : sup_info . append ( self . _ind2all [ example_ind ] [ 0 ] [ label_ind ] ) costs . append ( self . _ind2all [ example_ind ] [ 1 ] [ label_ind ] ) else : sup_info . append ( self . _ind2all [ example_ind ] [ label_ind ] ) costs . append ( np . ones ( len ( label_ind ) ) ) else : self . _do_missing ( k ) return sup_info , costs