smetric.py 770 B

123456789101112131415161718192021222324252627282930
  1. import networkx as nx
  2. __all__ = ["s_metric"]
  3. @nx._dispatchable
  4. def s_metric(G):
  5. """Returns the s-metric [1]_ 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`.
  8. Parameters
  9. ----------
  10. G : graph
  11. The graph used to compute the s-metric.
  12. Returns
  13. -------
  14. s : float
  15. The s-metric of the graph.
  16. References
  17. ----------
  18. .. [1] Lun Li, David Alderson, John C. Doyle, and Walter Willinger,
  19. Towards a Theory of Scale-Free Graphs:
  20. Definition, Properties, and Implications (Extended Version), 2005.
  21. https://arxiv.org/abs/cond-mat/0501169
  22. """
  23. return float(sum(G.degree(u) * G.degree(v) for (u, v) in G.edges()))