"from scipy.optimize import linear_sum_assignment as linear_assignment\n",
"import scipy.special as ss\n",
"import pandas as pd\n",
"import matplotlib.colors as mcolors\n",
"import random\n",
"import collections\n",
"\n",
"def structural_pattern_int(statistics):\n",
"\"\"\"return the structural pattern of a graph for integer nodal statistics:\n",
" # input is the dictionary of values (node, measure value)\n",
" # return a dictionary having as key the values in statistics codomain and as values the orbit/class (as set of nodes) \n",
"\"\"\"\n",
"\n",
" measure=dict(statistics)\n",
" # input is the dictionary of values (node, measure value)\n",
" # compute the orbits, return a dictionary with key all taken measure value and object the set of nodes\n",
"\n",
" orbit_set={}\n",
" for m in set(measure.values()):\n",
" orbit_set[m]=set([k for k,v in measure.items() if v==m])\n",
"\n",
" return orbit_set\n",
"\n",
"def structural_pattern(statistics,epsilon):\n",
"\"\"\"return the structural pattern of a graph for dense nodal statistics:\n",
" # input is the dictionary of values (node, measure value) and epsilon which corresponds to the number of significativ digit to be used for the values comparison\n",
" # return a dictionary having as key the values in statistics codomain and as values the orbit/class (as set of nodes) \n",
"\"\"\"\n",
"\n",
" epsilon = \"{:.\"+str(epsilon)+\"}\"\n",
" measure=dict(statistics)\n",
" #input is the dictionary of values (node, measure value)\n",
" #compute the orbits, return a dictionary with key all taken measure value and object the set of nodes\n",
" orbit_set={}\n",
" for m in set(measure.values()):\n",
" orbit_set[epsilon.format(float(m))]=set([k for k,v in measure.items() if epsilon.format(float(v))==epsilon.format(float(m))])\n",
"\"\"\" convert a dataset of adjacency matrices to one of structural pattern associated to the collection of statistics in statistics,\n",
" available statistics are \"d\" degree,\"b\" betweenness centrality,\"cc\" clustering coefficient,cs\" closeness centrality,\"s\" second order centrality\n",
"\"\"\" convert a dataset of graphs to one of structural pattern associated to the given list of statistics\n",
" available statistics are \"d\" degree,\"b\" betweenness centrality,\"cc\" clustering coefficient,cs\" closeness centrality,\"s\" second order centrality\n",
"\"\"\" evaluate the orthogonality of the collection of statistics on a given dataset, dataset can be either adjacency dataset or graph dataset\n",
" available statistics are \"d\" degree,\"b\" betweenness centrality,\"cc\" clustering coefficient,cs\" closeness centrality,\"s\" second order centrality\n",
"\"\"\" evaluate the orthogonality of the given collection of statistics at different sparsity level, dataset is a correlation matrices dataset, return the mean orthogonality score and the std orthogonality \n",
" available statistics are \"d\" degree,\"b\" betweenness centrality,\"cc\" clustering coefficient,cs\" closeness centrality,\"s\" second order centrality\n",
"\"\"\"dataset is dataset of structural_pattern_dataset at an already fixed sparsity and associated with previously given collection of statistics,\n",
" input is a dictionary with keys (class,subject) and values the structural pattern, \n",
" return a dictionary whose keys are the class in the dataset and values is a dictionary keyd by nodes and values are nodal percentage participation in non trivial class \n",
"\"\"\"\n",
"\n",
" counting_dataset = {}\n",
"\n",
" for classe in set([k[0] for k in orbits_dataset.keys()]):\n",
" counting_classe={}\n",
"\n",
" for i in range(num_region):\n",
" counting_classe[i]=0\n",
"\n",
" all_classe=[orb for k,orb in list(structural_pattern_dataset.items()) if k[0]==classe]\n",