Datasets:
Download code/stats.py from double-blind-anonymous/go-mo-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/datasets/double-blind-anonymous/go-mo-dataset/resolve/main/code/stats.py
- Command line
-
hf download hf://datasets/double-blind-anonymous/go-mo-dataset/code/stats.py
-
curl -L -o stats.py https://huggingface.co/datasets/double-blind-anonymous/go-mo-dataset/resolve/main/code/stats.py
1.73 kB
| import networkx as nx | |
| import numpy as np | |
| def print_graph_stats(G): | |
| n = G.number_of_nodes() | |
| m = G.number_of_edges() | |
| print(f"Number of nodes: {n}") | |
| print(f"Number of edges: {m}") | |
| if n == 0: | |
| print("Average degree: 0.0") | |
| print("Connectivity (weak or strong): False") | |
| print("Is connected as undirected graph: False") | |
| print("Number of weakly connected components: 0") | |
| print("Number of strongly connected components: 0") | |
| print("Number of isolated nodes: 0") | |
| return | |
| # Average degree via m/n | |
| avg_deg = m / n | |
| print(f"Average degree: {avg_deg}") | |
| # Connectivity checks for directed graphs | |
| is_weak = nx.is_weakly_connected(G) | |
| is_strong = nx.is_strongly_connected(G) | |
| print(f"Connectivity (weak or strong): {is_weak or is_strong}") | |
| # Undirected connectivity can raise on empty graphs; guard with try/except just in case | |
| try: | |
| und_connected = nx.is_connected(G.to_undirected(as_view=True)) | |
| except Exception: | |
| und_connected = False | |
| print(f"Is connected as undirected graph: {und_connected}") | |
| print(f"Number of weakly connected components: {nx.number_weakly_connected_components(G)}") | |
| print(f"Number of strongly connected components: {nx.number_strongly_connected_components(G)}") | |
| print(f"Number of isolated nodes: {len(list(nx.isolates(G)))}") | |
| def audit_adj(adj: np.ndarray): | |
| has_self = np.all(np.diag(adj) > 0) # check self-loops | |
| sym = np.allclose(adj, adj.T, atol=1e-8) | |
| deg = adj.sum(1) | |
| isolated = np.sum(deg==0) | |
| return {"n":adj.shape[0], "m":int(adj.sum()), "sym":sym, "self_loops":has_self, | |
| "avg_deg":float(deg.mean()), "isolated_nodes":int(isolated)} |