#NEWLINE# def get_clusters( self , method = 'leaf' , fill_background = False , **kwargs ) : #NEWLINE# #INDENT# '\n        Retrieve cluster labels from the level set tree. There are several ways\n        to do this with a level set tree, and a particular strategy can be\n        specified with the `method` parameter.\n\n        Parameters\n        ----------\n        method : {\'leaf\', \'first-k\', \'upper-level-set\', \'k-level\'}, optional\n            Method for obtaining cluster labels from the tree.\n\n            - \'leaf\': treat each leaf of the tree as a separate cluster.\n\n            - \'first-k\': find the first K non-overlapping clusters from the\n              roots of the tree.\n\n            - \'upper-level-set\': cluster by cutting the tree at a specified\n              density or mass level.\n\n            - \'k-level\': returns clusters at the lowest density level that has\n              k nodes.\n\n        fill_background : bool, optional\n            If True, a label of -1 is assigned to background points, i.e. those\n            instances not otherwise assigned to a high-density cluster. If\n            False, the background points are omitted from the output.\n\n        Other Parameters\n        ----------------\n        k : int\n            If `method` is \'first-k\' or \'k-level\', this is the desired number\n            of clusters.\n\n        threshold : float\n            If `method` is \'upper-level-set\', this is the threshold at which to\n            cut the tree.\n\n        form : {\'density\', \'mass\'}\n            If `method` is \'upper-level-set\', this is vertical scale which\n            \'threshold\' refers to.\n\n        Returns\n        -------\n        labels : 2-dimensional numpy array\n            Each row corresponds to an observation. The first column indicates\n            the index of the observation in the original data matrix, and the\n            second column is the index of the LST node to which the observation\n            belongs, *with respect to the clustering*. Note that the set of\n            observations in this "foreground" set is typically smaller than the\n            original dataset.\n\n        See Also\n        --------\n        debacl.utils.reindex_cluster_labels, get_leaf_nodes\n\n        Examples\n        --------\n        >>> X = numpy.random.rand(100, 2)\n        >>> tree = debacl.construct_tree(X, k=8, prune_threshold=5)\n        >>> labels = tree.get_clusters(method=\'leaf\')\n        ' #NEWLINE# if ( method == 'leaf' ) : #NEWLINE# #INDENT# labels = self . _leaf_cluster ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( method == 'first-k' ) : #NEWLINE# #INDENT# required = set ( [ 'k' ] ) #NEWLINE# if ( not set ( kwargs . keys ( ) ) . issuperset ( required ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Incorrect arguments for the first-k ' + 'cluster labeling method.' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# k = kwargs . get ( 'k' ) #NEWLINE# labels = self . _first_K_cluster ( k ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( method == 'upper-level-set' ) : #NEWLINE# #INDENT# required = set ( [ 'threshold' , 'form' ] ) #NEWLINE# if ( not set ( kwargs . keys ( ) ) . issuperset ( required ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Incorrect arguments for the upper-set ' + 'cluster labeling method.' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# threshold = kwargs . get ( 'threshold' ) #NEWLINE# form = kwargs . get ( 'form' ) #NEWLINE# labels = self . _upper_set_cluster ( threshold , form ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( method == 'k-level' ) : #NEWLINE# #INDENT# required = set ( [ 'k' ] ) #NEWLINE# if ( not set ( kwargs . keys ( ) ) . issuperset ( required ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Incorrect arguments for the k-level ' + 'cluster labeling method.' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# k = kwargs . get ( 'k' ) #NEWLINE# labels = self . _first_K_level_cluster ( k ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'Cluster labeling method not understood.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if fill_background : #NEWLINE# #INDENT# n = len ( self . density ) #NEWLINE# full_labels = _np . vstack ( ( _np . arange ( n ) , ( [ ( - 1 ) ] * n ) ) ) . T #NEWLINE# full_labels [ ( labels [ : , 0 ] , 1 ) ] = labels [ : , 1 ] #NEWLINE# labels = full_labels #NEWLINE# #UNINDENT# return labels