Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@

def densification(g: nx.digraph) -> float:
"""Return densification constant in NetworkX directed graph."""
return math.log(nx.number_of_edges(g), nx.number_of_nodes(g))
n = nx.number_of_nodes(g)
if n <= 1:
return 0.0
e = nx.number_of_edges(g)
if e == 0:
return 0.0
return math.log(e, n)


def diameter(g: nx.digraph) -> int:
"""Return effective 90% diameter in NetworkX directed graph."""
if nx.number_of_nodes(g) == 0:
return 0
largest_strongly_connected_component = g.subgraph(
max(nx.strongly_connected_components(g), key=len)
)
Expand All @@ -22,16 +30,19 @@ def diameter(g: nx.digraph) -> int:

def largest_connected_component(g: nx.digraph) -> float:
"""Return the scaled size of the largest strongly connected component in NetworkX directed graph."""
n = nx.number_of_nodes(g)
if n == 0:
return 0.0
largest_strongly_connected_component = g.subgraph(
max(nx.strongly_connected_components(g), key=len)
)
return nx.number_of_nodes(
largest_strongly_connected_component
) / nx.number_of_nodes(g)
return nx.number_of_nodes(largest_strongly_connected_component) / n


def max_adjacency(g: nx.digraph) -> float:
"""Return the largest eigenvalue of the adjacency matrix in NetworkX directed graph."""
if nx.number_of_nodes(g) == 0:
return 0.0
return max(nx.adjacency_spectrum(g))


Expand Down
Loading