#NEWLINE# def cluster( self , load_func , distance_f , density_threshold , distance_threshold , dc = None , auto_select_dc = False ) : #NEWLINE# #INDENT# '\n\t\tCluster the data\n\n\t\tArgs:\n\t\t    load_func          : load func to load data\n\t\t    distance_f         : distance data file\n\t\t    dc                 : local density threshold, call select_dc if dc is None\n\t\t    density_threshold  : local density threshold for choosing cluster center\n\t\t    distance_threshold : min distance threshold for choosing cluster center\n\t\t    autoselect_dc      : auto select dc or not\n\n\t\tReturns:\n\t\t    local density vector, min_distance vector, nearest neighbor vector\n\t\t' #NEWLINE# assert ( not ( ( dc != None ) and auto_select_dc ) ) #NEWLINE# ( distances , max_dis , min_dis , max_id , rho ) = self . local_density ( load_func , distance_f , dc = dc , auto_select_dc = auto_select_dc ) #NEWLINE# ( delta , nneigh ) = min_distance ( max_id , max_dis , distances , rho ) #NEWLINE# logger . info ( 'PROGRESS: start cluster' ) #NEWLINE# ( cluster , ccenter ) = ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# for ( idx , ( ldensity , mdistance , nneigh_item ) ) in enumerate ( zip ( rho , delta , nneigh ) ) : #NEWLINE# #INDENT# if ( idx == 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( ( ldensity >= density_threshold ) and ( mdistance >= distance_threshold ) ) : #NEWLINE# #INDENT# ccenter [ idx ] = idx #NEWLINE# cluster [ idx ] = idx #NEWLINE# #UNINDENT# #UNINDENT# for ( idx , ( ldensity , mdistance , nneigh_item ) ) in enumerate ( zip ( rho , delta , nneigh ) ) : #NEWLINE# #INDENT# if ( ( idx == 0 ) or ( idx in ccenter ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( nneigh_item in cluster ) : #NEWLINE# #INDENT# cluster [ idx ] = cluster [ nneigh_item ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cluster [ idx ] = ( - 1 ) #NEWLINE# #UNINDENT# if ( ( idx % ( min_dis / 10 ) ) == 0 ) : #NEWLINE# #INDENT# logger . info ( ( 'PROGRESS: at index #%i' % idx ) ) #NEWLINE# #UNINDENT# #UNINDENT# ( self . cluster , self . ccenter ) = ( cluster , ccenter ) #NEWLINE# self . distances = distances #NEWLINE# self . max_id = max_id #NEWLINE# logger . info ( 'PROGRESS: ended' ) #NEWLINE# return ( rho , delta , nneigh )