diff --git a/netbone/compare.py b/netbone/compare.py index 5d59704768004e91c9433749843735cea2189e65..4d0f510a53a6ea0ee6b01995d267e8d9d1cd998c 100644 --- a/netbone/compare.py +++ b/netbone/compare.py @@ -5,6 +5,7 @@ from netbone.filters import threshold_filter, boolean_filter from pandas import DataFrame from scipy.stats import kstest + class Compare: def __init__(self): self.network = nx.Graph() @@ -36,10 +37,9 @@ class Compare: elif "threshold" in filter.__name__: self.value_name = 'P-value' - def properties(self): if self.filter == boolean_filter: - self.filter_values = [0]*len(self.backbones) + self.filter_values = [0] * len(self.backbones) if self.filter_values == []: raise Exception('Please enter the filter values.') @@ -58,13 +58,11 @@ class Compare: for property in self.props: props_arrays[property].append(self.props[property](self.network, extracted_backbone)) - for property in self.props: results[property] = props_arrays[property] return results - def properties_progression(self): if self.filter == boolean_filter: raise Exception('Cann\'t apply the boolean filter in this function.') @@ -92,27 +90,29 @@ class Compare: props_res[res].index.name = self.value_name return props_res - - def distribution_ks_statistic(self, name, method, increasing=True): + def distribution_ks_statistic(self, name, increasing=True): if self.filter == boolean_filter: - self.filter_values = [0]*len(self.backbones) + self.filter_values = [0] * len(self.backbones) if self.filter_values == []: raise Exception('Please enter the filter values.') + dist = dict() + ks_statistics = pd.DataFrame(index=[backbone.name for backbone in self.backbones]) - values0 = method(self.network) + values0 = self.props[property](self.network) dist['Original'] = cumulative_dist(name, 'Original', values0, increasing) - vals = [0] - for i, backbone in enumerate(self.backbones): + + for property in self.props: + dist_values = dict() + vals = [] + for i, backbone in enumerate(self.backbones): extracted_backbone = self.filter(backbone, value=self.filter_values[i], narrate=False) - values1 = method(extracted_backbone) - dist[backbone.name] = cumulative_dist(name, extracted_backbone.name, values1, increasing) + values1 = self.props[property](extracted_backbone) + dist_values[backbone.name] = cumulative_dist(name, extracted_backbone.name, values1, increasing) vals.append(kstest(values0, values1)[0]) - ks_statistics = pd.DataFrame(index=['Original'] + [backbone.name for backbone in self.backbones]) - ks_statistics['KS Statistic'] = vals + # ks_statistics = pd.DataFrame(index=['Original'] + [backbone.name for backbone in self.backbones]) + dist[property] = dist_values + ks_statistics[property] = vals return ks_statistics, dist - - - diff --git a/netbone/visualize.py b/netbone/visualize.py index 9459f08be376251b3336cafc17b7607655d66164..58d5aa280dee931de47e9e3a8879d160fb36497c 100644 --- a/netbone/visualize.py +++ b/netbone/visualize.py @@ -178,7 +178,6 @@ class ComplexRadar(): def plot_radar(graph_properties, title): # Prepare data - graph_properties =graph_properties min_max_per_variable = graph_properties.describe().T[['min', 'max']] min_max_per_variable['min'] = min_max_per_variable['min'].apply(lambda x: int(x)) min_max_per_variable['max'] = min_max_per_variable['max'].apply(lambda x: x)#math.ceil(x) @@ -217,36 +216,39 @@ def plot_radar(graph_properties, title): fig.savefig(title + ' properties', bbox_inches='tight', dpi=300) -def plot_distribution(df, title): +def plot_distribution(dist, title): sns.set(font_scale = 1) sns.set_style('darkgrid') sns.set_palette(colors) - fig, axs = plt.subplots(1, 1, figsize=(5,5)) ############################################################################################################################# - axs.tick_params(axis='x', which="both", bottom=True) - axs.tick_params(axis='y', which="both", left=True) + for z, prop in enumerate(dist): + fig, axs = plt.subplots(1, 1, figsize=(5,5)) + axs.tick_params(axis='x', which="both", bottom=True) + axs.tick_params(axis='y', which="both", left=True) + df = dist[prop] + for i, method in enumerate(df): + axs.loglog(df[method].index, df[method][df[method].columns[0]], marker=m[i], markersize=3, linestyle='none', label=method, color=colors[i]) - for i, method in enumerate(df): - axs.loglog(df[method].index, df[method][df[method].columns[0]], marker=m[i], markersize=3, linestyle='none', label=method, color=colors[i]) + axs.spines['bottom'].set_color('0.3') + axs.spines['top'].set_color('0.3') + axs.spines['right'].set_color('0.3') + axs.spines['left'].set_color('0.3') - axs.spines['bottom'].set_color('0.3') - axs.spines['top'].set_color('0.3') - axs.spines['right'].set_color('0.3') - axs.spines['left'].set_color('0.3') + axs.set_xlabel(df[method].index.name) + axs.set_ylabel('P') - axs.set_xlabel(df[method].index.name) - axs.set_ylabel('P') + axs.legend(loc='center left', bbox_to_anchor=(1.04,0.5)) + fig.suptitle(title) + + # plt.tight_layout() + plt.show() + fig.savefig(title +'-'+ prop +'-dist', bbox_inches='tight', dpi=300) - axs.legend(loc='center left', bbox_to_anchor=(1.04,0.5)) - fig.suptitle(title) - # plt.tight_layout() - plt.show() - fig.savefig(title + '-dist', bbox_inches='tight', dpi=300) def plot_progression(graphs, title):