本文整理匯總了Python中networkx.relaxed_caveman_graph方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.relaxed_caveman_graph方法的具體用法?Python networkx.relaxed_caveman_graph怎麽用?Python networkx.relaxed_caveman_graph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類networkx
的用法示例。
在下文中一共展示了networkx.relaxed_caveman_graph方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_relaxed_caveman_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import relaxed_caveman_graph [as 別名]
def test_relaxed_caveman_graph():
G = nx.relaxed_caveman_graph(4,3,0)
assert_equal(len(G),12)
assert_equal(len(G.nodes()),12)
G = nx.relaxed_caveman_graph(4,3,1)
assert_equal(len(G),12)
assert_equal(len(G.nodes()),12)
G = nx.relaxed_caveman_graph(4,3,0.5)
assert_equal(len(G),12)
assert_equal(len(G.edges()),12)
示例2: test_relaxed_caveman_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import relaxed_caveman_graph [as 別名]
def test_relaxed_caveman_graph():
G = nx.relaxed_caveman_graph(4, 3, 0)
assert_equal(len(G), 12)
G = nx.relaxed_caveman_graph(4, 3, 1)
assert_equal(len(G), 12)
G = nx.relaxed_caveman_graph(4, 3, 0.5)
assert_equal(len(G), 12)
G = nx.relaxed_caveman_graph(4, 3, 0.5, seed=42)
assert_equal(len(G), 12)
示例3: test_relaxed_caveman_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import relaxed_caveman_graph [as 別名]
def test_relaxed_caveman_graph():
G = nx.relaxed_caveman_graph(4, 3, 0)
assert_equal(len(G), 12)
G = nx.relaxed_caveman_graph(4, 3, 1)
assert_equal(len(G), 12)
G = nx.relaxed_caveman_graph(4, 3, 0.5)
assert_equal(len(G), 12)
示例4: relaxed_caveman_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import relaxed_caveman_graph [as 別名]
def relaxed_caveman_graph(l, k, p, seed=None):
"""Return a relaxed caveman graph.
A relaxed caveman graph starts with ``l`` cliques of size ``k``. Edges are
then randomly rewired with probability ``p`` to link different cliques.
Parameters
----------
l : int
Number of groups
k : int
Size of cliques
p : float
Probabilty of rewiring each edge.
seed : int,optional
Seed for random number generator(default=None)
Returns
-------
G : NetworkX Graph
Relaxed Caveman Graph
Raises
------
NetworkXError:
If p is not in [0,1]
Examples
--------
>>> G = nx.relaxed_caveman_graph(2, 3, 0.1, seed=42)
References
----------
.. [1] Santo Fortunato, Community Detection in Graphs,
Physics Reports Volume 486, Issues 3-5, February 2010, Pages 75-174.
http://arxiv.org/abs/0906.0612
"""
if not seed is None:
random.seed(seed)
G = nx.caveman_graph(l, k)
nodes = G.nodes()
G.name = "relaxed_caveman_graph (%s,%s,%s)" % (l, k, p)
for (u, v) in G.edges():
if random.random() < p: # rewire the edge
x = random.choice(nodes)
if G.has_edge(u, x):
continue
G.remove_edge(u, v)
G.add_edge(u, x)
return G
示例5: relaxed_caveman_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import relaxed_caveman_graph [as 別名]
def relaxed_caveman_graph(l, k, p, seed=None):
"""Returns a relaxed caveman graph.
A relaxed caveman graph starts with `l` cliques of size `k`. Edges are
then randomly rewired with probability `p` to link different cliques.
Parameters
----------
l : int
Number of groups
k : int
Size of cliques
p : float
Probabilty of rewiring each edge.
seed : integer, random_state, or None (default)
Indicator of random number generation state.
See :ref:`Randomness<randomness>`.
Returns
-------
G : NetworkX Graph
Relaxed Caveman Graph
Raises
------
NetworkXError:
If p is not in [0,1]
Examples
--------
>>> G = nx.relaxed_caveman_graph(2, 3, 0.1, seed=42)
References
----------
.. [1] Santo Fortunato, Community Detection in Graphs,
Physics Reports Volume 486, Issues 3-5, February 2010, Pages 75-174.
https://arxiv.org/abs/0906.0612
"""
G = nx.caveman_graph(l, k)
nodes = list(G)
for (u, v) in G.edges():
if seed.random() < p: # rewire the edge
x = seed.choice(nodes)
if G.has_edge(u, x):
continue
G.remove_edge(u, v)
G.add_edge(u, x)
return G
示例6: relaxed_caveman_graph
# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import relaxed_caveman_graph [as 別名]
def relaxed_caveman_graph(l, k, p, seed=None):
"""Return a relaxed caveman graph.
A relaxed caveman graph starts with `l` cliques of size `k`. Edges are
then randomly rewired with probability `p` to link different cliques.
Parameters
----------
l : int
Number of groups
k : int
Size of cliques
p : float
Probabilty of rewiring each edge.
seed : int,optional
Seed for random number generator(default=None)
Returns
-------
G : NetworkX Graph
Relaxed Caveman Graph
Raises
------
NetworkXError:
If p is not in [0,1]
Examples
--------
>>> G = nx.relaxed_caveman_graph(2, 3, 0.1, seed=42)
References
----------
.. [1] Santo Fortunato, Community Detection in Graphs,
Physics Reports Volume 486, Issues 3-5, February 2010, Pages 75-174.
https://arxiv.org/abs/0906.0612
"""
if seed is not None:
random.seed(seed)
G = nx.caveman_graph(l, k)
nodes = list(G)
for (u, v) in G.edges():
if random.random() < p: # rewire the edge
x = random.choice(nodes)
if G.has_edge(u, x):
continue
G.remove_edge(u, v)
G.add_edge(u, x)
return G