本文整理汇总了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