smetric.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import networkx as nx
  2. __all__ = ["s_metric"]
  3. @nx._dispatch
  4. def s_metric(G, normalized=True):
  5. """Returns the s-metric of graph.
  6. The s-metric is defined as the sum of the products deg(u)*deg(v)
  7. for every edge (u,v) in G. If norm is provided construct the
  8. s-max graph and compute it's s_metric, and return the normalized
  9. s value
  10. Parameters
  11. ----------
  12. G : graph
  13. The graph used to compute the s-metric.
  14. normalized : bool (optional)
  15. Normalize the value.
  16. Returns
  17. -------
  18. s : float
  19. The s-metric of the graph.
  20. References
  21. ----------
  22. .. [1] Lun Li, David Alderson, John C. Doyle, and Walter Willinger,
  23. Towards a Theory of Scale-Free Graphs:
  24. Definition, Properties, and Implications (Extended Version), 2005.
  25. https://arxiv.org/abs/cond-mat/0501169
  26. """
  27. if normalized:
  28. raise nx.NetworkXError("Normalization not implemented")
  29. # Gmax = li_smax_graph(list(G.degree().values()))
  30. # return s_metric(G,normalized=False)/s_metric(Gmax,normalized=False)
  31. # else:
  32. return float(sum(G.degree(u) * G.degree(v) for (u, v) in G.edges()))