Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/networkx/algorithms/smetric.py: 40%
10 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-10-20 07:00 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-10-20 07:00 +0000
1import networkx as nx
3__all__ = ["s_metric"]
6@nx._dispatch
7def s_metric(G, **kwargs):
8 """Returns the s-metric [1]_ of graph.
10 The s-metric is defined as the sum of the products ``deg(u) * deg(v)``
11 for every edge ``(u, v)`` in `G`.
13 Parameters
14 ----------
15 G : graph
16 The graph used to compute the s-metric.
17 normalized : bool (optional)
18 Normalize the value.
20 .. deprecated:: 3.2
22 The `normalized` keyword argument is deprecated and will be removed
23 in the future
25 Returns
26 -------
27 s : float
28 The s-metric of the graph.
30 References
31 ----------
32 .. [1] Lun Li, David Alderson, John C. Doyle, and Walter Willinger,
33 Towards a Theory of Scale-Free Graphs:
34 Definition, Properties, and Implications (Extended Version), 2005.
35 https://arxiv.org/abs/cond-mat/0501169
36 """
37 # NOTE: This entire code block + the **kwargs in the signature can all be
38 # removed when the deprecation expires.
39 # Normalized is always False, since all `normalized=True` did was raise
40 # a NotImplementedError
41 if kwargs:
42 # Warn for `normalize`, raise for any other kwarg
43 if "normalized" in kwargs:
44 import warnings
46 warnings.warn(
47 "\n\nThe `normalized` keyword is deprecated and will be removed\n"
48 "in the future. To silence this warning, remove `normalized`\n"
49 "when calling `s_metric`.\n\n"
50 "The value of `normalized` is ignored.",
51 DeprecationWarning,
52 stacklevel=3,
53 )
54 else:
55 # Typical raising behavior for Python when kwarg not recognized
56 raise TypeError(
57 f"s_metric got an unexpected keyword argument '{list(kwargs.keys())[0]}'"
58 )
60 return float(sum(G.degree(u) * G.degree(v) for (u, v) in G.edges()))