diff --git a/setup.py b/setup.py index 0c87d12226adca325aa8a45994d1bb3d4955ac10..67c3841a246a76d76099fd7d959a3745449c7fd3 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name = "impetuous-gfa", - version = "0.40.2", + version = "0.40.3", author = "Richard Tjörnhammar", author_email = "richard.tjornhammar@gmail.com", description = "Impetuous Quantification, a Statistical Learning library for Humans : Alignments, Clustering, Enrichments and Group Analysis", diff --git a/src/impetuous/hierarchical.py b/src/impetuous/hierarchical.py index 280b6fc27e13e91f1bc116878619fe44cd6d55a3..8f7abcd0495500ade90e3df20774a171e459ec62 100755 --- a/src/impetuous/hierarchical.py +++ b/src/impetuous/hierarchical.py @@ -116,7 +116,7 @@ def HierarchicalEnrichment ( def calculate_hierarchy_matrix ( data_frame = None , distance_matrix = None , bVerbose = False ) : - info__ = """ This is the saiga you are looking for """ + info__ = """ This is the saiga/pelican/panda you are looking for """ from impetuous.clustering import connectivity , absolute_coordinates_to_distance_matrix import operator if not operator.xor( data_frame is None , distance_matrix is None ) : @@ -138,15 +138,21 @@ def calculate_hierarchy_matrix ( data_frame = None , print ( distance_matrix ) uco_v = sorted(list(set(distance_matrix.reshape(-1)))) - hierarchy_matrix = None hsers = [] level_distance_lookup = {} for icut in range(len(uco_v)) : cutoff = uco_v[icut] - clusternames , nclustercontacts = connectivity ( distance_matrix , cutoff , + # clustercontacts : clusterid to particleid + # clustercontent : clusterid to number of particles in range + clustercontent , clustercontacts = connectivity ( distance_matrix , cutoff , bVerbose=bVerbose ) - pid2clusterid = nclustercontacts[:,0] - level_distance_lookup['level'+str(icut)] = [ icut , cutoff ] + # + # internal ordering is a range so this does not need to be a dict + pid2clusterid = clustercontacts[:,0] + if icut==10 and False: + print(clustercontent,clustercontacts,np.mean(clustercontent)) + exit(1) + level_distance_lookup['level'+str(icut)] = [ icut , cutoff , np.mean(clustercontent) ] hser = pd.Series(pid2clusterid,name='level'+str(icut),index=range(len(distance_matrix))) hsers.append(hser) if len(set(hser.values))==1: @@ -158,19 +164,21 @@ def calculate_hierarchy_matrix ( data_frame = None , names = range(len(distance_matrix)) res_df = pd.DataFrame ( hsers ) res_df .columns = names + + hierarchy_matrix = res_df if bVerbose: print () print ("TAKE NOTE THAT THE CLUSTER INDEXING BETWEEN LEVELS MIGHT NOT BE THE SAME") print ("YOU HAVE TO USE THE CLUSTER ID NUMBERS ACROSS A LEVEL TO DEDUCE WHICH PARTICLES") print ("BELONG TOGETHER IN A CLUSTER. THAT IS: I.E. CLUSTER 0 ON LEVEL 12 MIGHT NOT CORRESPOND") print ("TO CLUSTER 0 ON LEVEL 13. THE CALCULATED CLUSTER MATRIX IS: ") - print ( res_df ) + print ( hierarchy_matrix ) print ("AND THESE ARE THE DISTANCES THE HIERARCHY LEVELS CORRESPOND TO:" ) print ( level_distance_lookup ) - return ( res_df , level_distance_lookup ) - + return ( hierarchy_matrix , level_distance_lookup ) + if __name__ == '__main__': - + print ( "hierarchy matrix test" ) R = np.random.rand(90).reshape(30,3) P = np.zeros(90).reshape(30,3) @@ -186,11 +194,18 @@ if __name__ == '__main__': M,L = calculate_hierarchy_matrix ( pdf ) print ( M ) - from impetuous.visualisation import * - X,Y = [],[] + X,Y,W,Z = [],[],[],[] for item in L.items(): X.append(item[1][1]) + W.append(item[1][1]) + Z.append(item[1][2]) Y.append(len(set(M.loc[item[0]].values))) from bokeh.plotting import show - show ( bscatter(X,Y,title='cluster coordination function') ) + # + # SHOW THE COODINATION AND SEGREGATION FUNCTIONS + # BOTH ARE WELL KNOWN FROM STATISTICAL PHYSICS + show ( plotter( [X,W] , [Y,Z] , + [nice_colors[0],nice_colors[2]] , + legends = ['segregation','coordination'], + axis_labels = ['distance','Number']) ) diff --git a/src/impetuous/visualisation.py b/src/impetuous/visualisation.py index ce946b57d74169d1903c7d6ab6431175b862f80b..d04e42b4551da4776a4284647dbf566601c3b76a 100644 --- a/src/impetuous/visualisation.py +++ b/src/impetuous/visualisation.py @@ -77,7 +77,7 @@ def bscatter ( X , Y , additional_dictionary=None , title='' , color='#ff0000' , return( p ) -def plotter ( x = np.random.rand(10) , y = np.random.rand(10) , colors = '#ff0000' , +def plotter ( x = np.random.rand(10) , y = np.random.rand(10) , colors = '#ff0000' , title='', legends=None, axis_labels = None, bSave = False, name='scatter.html' ): from bokeh.plotting import output_file, show, save @@ -91,7 +91,7 @@ def plotter ( x = np.random.rand(10) , y = np.random.rand(10) , colors = '#ff000 x_ , y_ , color = x[i] , y[i] , colors[i] if list_typecheck([legends,axis_labels],'list',all): label = legends[i] - p = bscatter( x_ , y_ , color = color , p = p , legend_label = label , axis_labels=axis_labels ) + p = bscatter( x_ , y_ , color = color , p = p , legend_label = label , axis_labels=axis_labels ) else : p = bscatter( x_ , y_ , color = color , p = p ) outp ( p )