(multilabel_index, label_index, label_tree, y_true)
return multilabel_index
Complete instance-label information according to hierarchy in the label-tree.
    
    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.

    multilabel_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.

    label_tree: np.ndarray
        The hierarchical relationships among data features.
        if node_i is the parent of node_j , then label_tree(i,j)=1

    y_true: 2D array, optional (default=None)
        Label matrix of the whole dataset. It is a reference which will not use additional memory.
        shape [n_samples, n_classes]
    
    Returns
    -------
    selected_ins_lab_pair: list
        A list of tuples that contains the indexes of selected instance-label pairs.
Complete instance-label information according to hierarchy in the label-tree.
    
    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.
Complete instance - label information according to hierarchy in the label - tree . 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 .
def hierarchical_multilabel_mark(multilabel_index, label_index, label_tree, y_true):
    """"Complete instance-label information according to hierarchy in the label-tree.
    
    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.

    multilabel_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.

    label_tree: np.ndarray
        The hierarchical relationships among data features.
        if node_i is the parent of node_j , then label_tree(i,j)=1

    y_true: 2D array, optional (default=None)
        Label matrix of the whole dataset. It is a reference which will not use additional memory.
        shape [n_samples, n_classes]
    
    Returns
    -------
    selected_ins_lab_pair: list
        A list of tuples that contains the indexes of selected instance-label pairs. 
    """
    # try to convert the indexes
    if not isinstance(multilabel_index, MultiLabelIndexCollection):
        try:
            if isinstance(multilabel_index[0], tuple):
                container = MultiLabelIndexCollection(multilabel_index, np.shape(y_true)[1])
            else:
                container = MultiLabelIndexCollection.construct_by_1d_array(multilabel_index, label_mat_shape=np.shape(y_true))
        except:
            raise ValueError(
                "Please pass a 1d array of indexes or MultiLabelIndexCollection (column major, "
                "start from 0) 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 label.")
        multilabel_index = copy.deepcopy(container)
    
    if not isinstance(label_index, MultiLabelIndexCollection):
        try:
            if isinstance(label_index[0], tuple):
                container = MultiLabelIndexCollection(label_index, np.shape(y_true)[1])
            else:
                container = MultiLabelIndexCollection.construct_by_1d_array(label_index, label_mat_shape=np.shape(y_true))
        except:
            raise ValueError(
                "Please pass a 1d array of indexes or MultiLabelIndexCollection (column major, "
                "start from 0) 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 label.")
        label_index = copy.deepcopy(container)
    
    n_classes = multilabel_index._label_size
    assert(np.shape(label_tree)[0] == n_classes and np.shape(label_tree)[1] == n_classes)

    add_label_index = MultiLabelIndexCollection(label_size=n_classes)
      
    for instance_label_pair in multilabel_index:
        i_instance = instance_label_pair[0]
        j_label = instance_label_pair[1]
        if y_true[instance_label_pair] == 1:
            for descent_label in range(n_classes):
                if label_tree[j_label][descent_label] == 1:
                    if (not (i_instance, descent_label) in label_index):
                        add_label_index.update((i_instance, descent_label))   
        elif y_true[instance_label_pair] == -1:
            for parent_label in range(n_classes):
                if label_tree[parent_label][j_label] == 1:
                    if (not (i_instance, parent_label) in label_index):
                        add_label_index.update((i_instance, parent_label))

    for i in add_label_index:
        if not i in multilabel_index:
            multilabel_index.update(i)
    return multilabel_index
def hierarchical_multilabel_mark ( multilabel_index , label_index , label_tree , y_true ) : # try to convert the indexes if not isinstance ( multilabel_index , MultiLabelIndexCollection ) : try : if isinstance ( multilabel_index [ 0 ] , tuple ) : container = MultiLabelIndexCollection ( multilabel_index , np . shape ( y_true ) [ 1 ] ) else : container = MultiLabelIndexCollection . construct_by_1d_array ( multilabel_index , label_mat_shape = np . shape ( y_true ) ) except : raise ValueError ( "Please pass a 1d array of indexes or MultiLabelIndexCollection (column major, " "start from 0) 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 label." ) multilabel_index = copy . deepcopy ( container ) if not isinstance ( label_index , MultiLabelIndexCollection ) : try : if isinstance ( label_index [ 0 ] , tuple ) : container = MultiLabelIndexCollection ( label_index , np . shape ( y_true ) [ 1 ] ) else : container = MultiLabelIndexCollection . construct_by_1d_array ( label_index , label_mat_shape = np . shape ( y_true ) ) except : raise ValueError ( "Please pass a 1d array of indexes or MultiLabelIndexCollection (column major, " "start from 0) 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 label." ) label_index = copy . deepcopy ( container ) n_classes = multilabel_index . _label_size assert ( np . shape ( label_tree ) [ 0 ] == n_classes and np . shape ( label_tree ) [ 1 ] == n_classes ) add_label_index = MultiLabelIndexCollection ( label_size = n_classes ) for instance_label_pair in multilabel_index : i_instance = instance_label_pair [ 0 ] j_label = instance_label_pair [ 1 ] if y_true [ instance_label_pair ] == 1 : for descent_label in range ( n_classes ) : if label_tree [ j_label ] [ descent_label ] == 1 : if ( not ( i_instance , descent_label ) in label_index ) : add_label_index . update ( ( i_instance , descent_label ) ) elif y_true [ instance_label_pair ] == - 1 : for parent_label in range ( n_classes ) : if label_tree [ parent_label ] [ j_label ] == 1 : if ( not ( i_instance , parent_label ) in label_index ) : add_label_index . update ( ( i_instance , parent_label ) ) for i in add_label_index : if not i in multilabel_index : multilabel_index . update ( i ) return multilabel_index