Skip to content

Commit

Permalink
adapting code for empirical graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
lisette-espin committed Apr 26, 2023
1 parent 26fa88b commit 42d2a80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion netin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
in social networks.
"""

__version__ = '1.0.5.9'
__version__ = '1.0.5.9.1'

from netin import generators
from netin.generators import *
Expand Down
14 changes: 11 additions & 3 deletions netin/generators/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,15 +754,23 @@ def get_node_metadata_as_dataframe(self, include_graph_metadata: bool = False, n
-------
pd.DataFrame
dataframe with the metadata of the nodes
Notes
-----
Column `class_label` is a binary column indicating whether the node belongs to the minority class.
"""
cols = ['node', 'class_label']
cols = ['node', 'class_label', 'real_label', 'source']

obj = {'node': self.node_list,
'class_label': [self.get_class_label(n) for n in self.node_list]}
'class_label': [const.MAJORITY_LABEL if self.get_class_label(n) == self.get_majority_label() else const.MINORITY_LABEL for n in self.node_list],
'real_label': [self.get_class_label(n) for n in self.node_list],
'source': 'model' if 'empirical' not in self.graph else 'data'}

# include graph metadata
if include_graph_metadata:
n = self.number_of_nodes()
newcols = [c for c in self.graph.keys() if c not in ['class_attribute', 'class_values', 'class_labels']]
newcols = [c for c in self.graph.keys() if c not in ['class_attribute', 'class_values',
'class_labels']]
obj.update({c: self.graph[c] for c in newcols})
cols.extend(newcols)

Expand Down
8 changes: 6 additions & 2 deletions netin/viz/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
import seaborn as sns
from matplotlib import rc
from collections import Counter

from netin.generators.graph import Graph
from netin.stats.distributions import fit_power_law
Expand Down Expand Up @@ -101,7 +102,9 @@ class label e.g., M or m for majority and minority
-------
color: str
color for the class label
"""

if ylabel in MINORITY_CURVE and class_label is None:
return COLOR_MINORITY

Expand Down Expand Up @@ -458,7 +461,8 @@ def plot_distribution(data: Union[pd.DataFrame, List[pd.DataFrame]],
total = df[_col_name].sum() if common_norm else group[_col_name].sum()
xs, ys = get_x_y_from_df_fnc(group, _col_name, total)
plot = ax.scatter if scatter else ax.plot
plot(xs, ys, label=class_label, color=_get_class_label_color(class_label, xy_fnc_name), **kwargs)
plot(xs, ys, label=class_label, color=_get_class_label_color(class_label=class_label,
ylabel=xy_fnc_name), **kwargs)

if hline_fnc:
hline_fnc(ax.axhline, group)
Expand Down Expand Up @@ -789,7 +793,7 @@ def plot_powerlaw_fit(data: Union[pd.DataFrame, List[pd.DataFrame]], col_name: U
discrete = group_nonzero[_col_name].dtype == np.int64
fit = fit_power_law(group_nonzero.loc[:, _col_name].values, discrete=discrete, verbose=verbose)

color = _get_class_label_color(class_label)
color = _get_class_label_color(class_label=class_label)

efnc = fit.plot_ccdf if kind == "ccdf" else fit.plot_cdf if kind == 'cdf' else fit.plot_pdf
fnc = fit.power_law.plot_ccdf if kind == "ccdf" else fit.power_law.plot_cdf if kind == 'cdf' \
Expand Down

0 comments on commit 42d2a80

Please sign in to comment.