Python networkx.relaxed_caveman_graph() Examples
The following are 6
code examples of networkx.relaxed_caveman_graph().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: test_community.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
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)
Example #2
Source File: test_community.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #3
Source File: test_community.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
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)
Example #4
Source File: community.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 4 votes |
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
Example #5
Source File: community.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
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
Example #6
Source File: community.py From aws-kube-codesuite with Apache License 2.0 | 4 votes |
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