1
0
Fork 0
Old engine for Continuous Time Bayesian Networks. Superseded by reCTBN. 🐍 https://github.com/madlabunimib/PyCTBN
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PyCTBN/venv/share/doc/networkx-2.5/examples/basic/plot_properties.py

49 lines
986 B

"""
==========
Properties
==========
Compute some network properties for the lollipop graph.
"""
import matplotlib.pyplot as plt
from networkx import nx
G = nx.lollipop_graph(4, 6)
pathlengths = []
print("source vertex {target:length, }")
for v in G.nodes():
spl = dict(nx.single_source_shortest_path_length(G, v))
print(f"{v} {spl} ")
for p in spl:
pathlengths.append(spl[p])
print()
print(f"average shortest path length {sum(pathlengths) / len(pathlengths)}")
# histogram of path lengths
dist = {}
for p in pathlengths:
if p in dist:
dist[p] += 1
else:
dist[p] = 1
print()
print("length #paths")
verts = dist.keys()
for d in sorted(verts):
print(f"{d} {dist[d]}")
print(f"radius: {nx.radius(G)}")
print(f"diameter: {nx.diameter(G)}")
print(f"eccentricity: {nx.eccentricity(G)}")
print(f"center: {nx.center(G)}")
print(f"periphery: {nx.periphery(G)}")
print(f"density: {nx.density(G)}")
nx.draw(G, with_labels=True)
plt.show()