Skip to content

Commit

Permalink
adding self loops related docs and tests for functions in cluster.py (
Browse files Browse the repository at this point in the history
#7261)

* added self-loops notes

* added test_self_loops_square_clustering

* style fix

* style fix
  • Loading branch information
Schefflera-Arboricola committed Feb 3, 2024
1 parent d769e3b commit ea6942f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions networkx/algorithms/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ def transitivity(G):
out : float
Transitivity
Notes
-----
Self loops are ignored.
Examples
--------
>>> G = nx.complete_graph(5)
Expand Down Expand Up @@ -581,6 +585,8 @@ def generalized_degree(G, nodes=None):
Notes
-----
Self loops are ignored.
In a network of N nodes, the highest triangle multiplicity an edge can have
is N-2.
Expand Down
6 changes: 6 additions & 0 deletions networkx/algorithms/tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@ def test_peng_square_clustering(self):
G = nx.Graph([(1, 2), (1, 3), (2, 4), (3, 4), (3, 5), (3, 6)])
assert nx.square_clustering(G, [1])[1] == 1 / 3

def test_self_loops_square_clustering(self):
G = nx.path_graph(5)
assert nx.square_clustering(G) == {0: 0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0}
G.add_edges_from([(0, 0), (1, 1), (2, 2)])
assert nx.square_clustering(G) == {0: 1, 1: 0.5, 2: 0.2, 3: 0.0, 4: 0}


class TestAverageClustering:
@classmethod
Expand Down

0 comments on commit ea6942f

Please sign in to comment.