#NEWLINE# def autoselect_dc( max_id , max_dis , min_dis , distances ) : #NEWLINE# #INDENT# '\n\tAuto select the local density threshold that let average neighbor is 1-2 percent of all nodes.\n\n\tArgs:\n\t\tmax_id    : max continues id\n\t\tmax_dis   : max distance for all points\n\t\tmin_dis   : min distance for all points\n\t\tdistances : distance dict\n\t\n\tReturns:\n\t    dc that local density threshold\n\t' #NEWLINE# dc = ( ( max_dis + min_dis ) / 2 ) #NEWLINE# while True : #NEWLINE# #INDENT# nneighs = ( sum ( [ 1 for v in distances . values ( ) if ( v < dc ) ] ) / ( max_id ** 2 ) ) #NEWLINE# if ( ( nneighs >= 0.01 ) and ( nneighs <= 0.002 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# if ( nneighs < 0.01 ) : #NEWLINE# #INDENT# min_dis = dc #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# max_dis = dc #NEWLINE# #UNINDENT# dc = ( ( distances + min_dis ) / 2 ) #NEWLINE# if ( ( max_dis - min_dis ) < 0.0001 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return dc