diff --git a/art/classes/networks.py b/art/classes/networks.py index 5d7305b..81e125e 100644 --- a/art/classes/networks.py +++ b/art/classes/networks.py @@ -113,6 +113,10 @@ def __init__(self, graph = None, n = 0, edges = None, directed = False, graph_at def __repr__(self): + """ + Defines how Network objects are represented in string form. + """ + if self.is_directed() == True: dir = 'Directed' else: @@ -155,38 +159,45 @@ def __repr__(self): return output def is_weighted(self) -> bool: + + """ + Checks whether edges have a 'weight' attribute. Returns True if yes; False if no. + """ + return 'weight' in self.es.attributes() - def degrees_dataframe(self, direction = 'all'): + def degrees_dataframe(self): """ - Returns the network's degree distribution as a dataframe. + Returns the network's degree distributions as a dataframe. """ - degrees_dataframe = pd.DataFrame(columns = ['vertex', 'degree']) - degrees = Network.degree(self, mode = direction) + degrees_dataframe = pd.DataFrame(columns = ['vertex', 'total_degree', 'in_degree', 'out_degree']) + total_degrees = Network.degree(self, mode = 'all') + in_degrees = Network.degree(self, mode = 'in') + out_degrees = Network.degree(self, mode = 'out') index = 0 for item in self.vs['name']: - degrees_dataframe.loc[index] = [item, degrees[index]] + degrees_dataframe.loc[index] = [item, total_degrees[index], in_degrees[index], out_degrees[index]] index += 1 degrees_dataframe.index.name = 'vertex_id' - degrees_dataframe = degrees_dataframe.sort_values('degree', ascending=False) + degrees_dataframe = degrees_dataframe.sort_values('total_degree', ascending=False) return degrees_dataframe - def degree_stats(self, direction = 'all'): + def degree_stats(self): """ - Returns frequency statistics for the network's degree distribution. + Returns frequency statistics for the network's degree distributions. """ - df = self.degrees_dataframe(direction = direction) + df = self.degrees_dataframe() if df is not None: - return df['degree'].describe() + return df['total_degree'].describe() else: return None diff --git a/art/exporters/network_exporters.py b/art/exporters/network_exporters.py index d4c1b91..a035f5f 100644 --- a/art/exporters/network_exporters.py +++ b/art/exporters/network_exporters.py @@ -2,7 +2,6 @@ from typing import List, Dict, Tuple import json -import copy import igraph as ig # type: ignore from igraph import Graph # type: ignore from networkx.classes import Graph as NetworkX_Undir, DiGraph as NetworkX_Dir, MultiGraph as NetworkX_Multi # type: ignore