-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphynetpy_sample.py
More file actions
47 lines (39 loc) · 1.38 KB
/
Copy pathphynetpy_sample.py
File metadata and controls
47 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# PhyNetPy Sample Code - Basic Network Analysis
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
# Create a simple network
G = nx.Graph()
G.add_edges_from([
('A', 'B'), ('B', 'C'), ('C', 'D'),
('D', 'A'), ('A', 'C'), ('B', 'D')
])
print("=== Basic Network Analysis ===")
print(f"Number of nodes: {G.number_of_nodes()}")
print(f"Number of edges: {G.number_of_edges()}")
print(f"Nodes: {list(G.nodes())}")
print(f"Edges: {list(G.edges())}")
# Calculate basic metrics
density = nx.density(G)
avg_clustering = nx.average_clustering(G)
print(f"\nNetwork Metrics:")
print(f"- Density: {density:.3f}")
print(f"- Average clustering: {avg_clustering:.3f}")
# Degree analysis
degrees = dict(G.degree())
print(f"\nDegree sequence: {list(degrees.values())}")
print(f"Average degree: {sum(degrees.values()) / len(degrees):.2f}")
# Centrality measures
print(f"\n=== Centrality Analysis ===")
degree_cent = nx.degree_centrality(G)
betweenness_cent = nx.betweenness_centrality(G)
closeness_cent = nx.closeness_centrality(G)
print("Degree Centrality:")
for node, cent in sorted(degree_cent.items()):
print(f" Node {node}: {cent:.3f}")
print("\nBetweenness Centrality:")
for node, cent in sorted(betweenness_cent.items()):
print(f" Node {node}: {cent:.3f}")
print("\nCloseness Centrality:")
for node, cent in sorted(closeness_cent.items()):
print(f" Node {node}: {cent:.3f}")