本文整理匯總了Python中networkx.transitivity方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.transitivity方法的具體用法?Python networkx.transitivity怎麽用?Python networkx.transitivity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.transitivity方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_k5
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def test_k5(self):
G = nx.complete_graph(5)
assert_equal(nx.transitivity(G),1.0)
G.remove_edge(1,2)
assert_equal(nx.transitivity(G),0.875)
# def test_clustering_transitivity(self):
# # check that weighted average of clustering is transitivity
# G = nx.complete_graph(5)
# G.remove_edge(1,2)
# t1=nx.transitivity(G)
# (cluster_d2,weights)=nx.clustering(G,weights=True)
# trans=[]
# for v in G.nodes():
# trans.append(cluster_d2[v]*weights[v])
# t2=sum(trans)
# assert_almost_equal(abs(t1-t2),0)
示例2: test_k5
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def test_k5(self):
G = nx.complete_graph(5)
assert_equal(nx.transitivity(G), 1.0)
G.remove_edge(1, 2)
assert_equal(nx.transitivity(G), 0.875)
# def test_clustering_transitivity(self):
# # check that weighted average of clustering is transitivity
# G = nx.complete_graph(5)
# G.remove_edge(1,2)
# t1=nx.transitivity(G)
# (cluster_d2,weights)=nx.clustering(G,weights=True)
# trans=[]
# for v in G.nodes():
# trans.append(cluster_d2[v]*weights[v])
# t2=sum(trans)
# assert_almost_equal(abs(t1-t2),0)
示例3: _set_omega
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def _set_omega(self):
"""
Calculating the graph level clustering coefficient.
"""
self._omega = nx.transitivity(self._graph)
示例4: transitivity
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def transitivity(G):
r"""Compute graph transitivity, the fraction of all possible triangles
present in G.
Possible triangles are identified by the number of "triads"
(two edges with a shared vertex).
The transitivity is
.. math::
T = 3\frac{\#triangles}{\#triads}.
Parameters
----------
G : graph
Returns
-------
out : float
Transitivity
Examples
--------
>>> G = nx.complete_graph(5)
>>> print(nx.transitivity(G))
1.0
"""
triangles=0 # 6 times number of triangles
contri=0 # 2 times number of connected triples
for v,d,t in _triangles_and_degree_iter(G):
contri += d*(d-1)
triangles += t
if triangles==0: # we had no triangles or possible triangles
return 0.0
else:
return triangles/float(contri)
示例5: test_transitivity
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def test_transitivity(self):
G = nx.Graph()
assert_equal(nx.transitivity(G),0.0)
示例6: test_path
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def test_path(self):
G = nx.path_graph(10)
assert_equal(nx.transitivity(G),0.0)
示例7: test_cubical
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def test_cubical(self):
G = nx.cubical_graph()
assert_equal(nx.transitivity(G),0.0)
示例8: transitivity
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def transitivity(G):
r"""Compute graph transitivity, the fraction of all possible triangles
present in G.
Possible triangles are identified by the number of "triads"
(two edges with a shared vertex).
The transitivity is
.. math::
T = 3\frac{\#triangles}{\#triads}.
Parameters
----------
G : graph
Returns
-------
out : float
Transitivity
Examples
--------
>>> G = nx.complete_graph(5)
>>> print(nx.transitivity(G))
1.0
"""
triangles = sum(t for v, d, t, _ in _triangles_and_degree_iter(G))
contri = sum(d * (d - 1) for v, d, t, _ in _triangles_and_degree_iter(G))
return 0 if triangles == 0 else triangles / contri
示例9: test_transitivity
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def test_transitivity(self):
G = nx.Graph()
assert_equal(nx.transitivity(G), 0.0)
示例10: test_path
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def test_path(self):
G = nx.path_graph(10)
assert_equal(nx.transitivity(G), 0.0)
示例11: test_cubical
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import transitivity [as 別名]
def test_cubical(self):
G = nx.cubical_graph()
assert_equal(nx.transitivity(G), 0.0)